diff options
author | edef <edef@edef.eu> | 2024-10-15T21·59+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2024-10-16T00·16+0000 |
commit | a833703dab8c4ef271cb8ae11df2ca5fa46c7343 (patch) | |
tree | 67154ba3585129423fd45e7fc83d22a72ad3e6e9 | |
parent | ca1e628c8573fe4f054af510918b81a378d7eb9a (diff) |
refactor(tvix/eval/builtin-macros): use match block for f.block r/8812
These nested ifs are a bit confusing, a match block makes this cleaner. Change-Id: I256fd0bc921fbf2e60ad0f6e1ea51c2e0fb00317 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12628 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/eval/builtin-macros/src/lib.rs | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/tvix/eval/builtin-macros/src/lib.rs b/tvix/eval/builtin-macros/src/lib.rs index 5cc9807f54fe..9b14aee44605 100644 --- a/tvix/eval/builtin-macros/src/lib.rs +++ b/tvix/eval/builtin-macros/src/lib.rs @@ -281,31 +281,45 @@ pub fn builtins(args: TokenStream, item: TokenStream) -> TokenStream { let ty = &arg.ty; let ident = &arg.name; - if arg.strict { - if arg.catch { - f.block = Box::new(parse_quote_spanned! {arg.span=> { - let #ident: #ty = tvix_eval::generators::request_force(&co, values.pop() - .expect("Tvix bug: builtin called with incorrect number of arguments")).await; + f.block = Box::new(match arg { + BuiltinArgument { + strict: true, + catch: true, + .. + } => parse_quote_spanned! { + arg.span => { + let #ident: #ty = tvix_eval::generators::request_force( + &co, values.pop().expect("Tvix bug: builtin called with incorrect number of arguments") + ).await; #block - }}); - } else { - f.block = Box::new(parse_quote_spanned! {arg.span=> { - let #ident: #ty = tvix_eval::generators::request_force(&co, values.pop() - .expect("Tvix bug: builtin called with incorrect number of arguments")).await; + } + }, + BuiltinArgument { + strict: true, + catch: false, + .. + } => parse_quote_spanned! { + arg.span => { + let #ident: #ty = tvix_eval::generators::request_force( + &co, values.pop().expect("Tvix bug: builtin called with incorrect number of arguments") + ).await; if #ident.is_catchable() { return Ok(#ident); } #block - }}); - } - } else { - f.block = Box::new(parse_quote_spanned! {arg.span=> { - let #ident: #ty = values.pop() - .expect("Tvix bug: builtin called with incorrect number of arguments"); - - #block - }}) - } + } + }, + BuiltinArgument { + strict: false, + catch: _, + .. + } => parse_quote_spanned! { + arg.span => { + let #ident: #ty = values.pop().expect("Tvix bug: builtin called with incorrect number of arguments"); + #block + } + }, + }); } let fn_name = f.sig.ident.clone(); |