From bdfeaeee73e27fa8f832c250befa12f4ba3edae6 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 14 Jan 2025 08:21:08 -0300 Subject: [PATCH] optmize --- vlib/v/ast/ast.v | 1 + vlib/v/checker/fn.v | 6 ++++++ vlib/v/gen/c/fn.v | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index bc348cda9f20f4..355234d4f048e2 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -861,6 +861,7 @@ pub mut: pos token.Pos should_be_ptr bool // fn expects a ptr for this arg // tmp_name string // for autofree + ct_expr bool // true, when the expression is a comptime/generic expression } // function return statement diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 47f4dd13747a06..1c0d64d842baeb 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1456,6 +1456,9 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. if func.params.len == 0 { continue } + if !c.inside_recheck { + call_arg.ct_expr = c.comptime.is_comptime(call_arg.expr) + } if !func.is_variadic && has_decompose { c.error('cannot have parameter after array decompose', node.pos) } @@ -2383,6 +2386,9 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool) } else { method.params[i + 1].typ } + if !c.inside_recheck { + arg.ct_expr = c.comptime.is_comptime(arg.expr) + } // If initialize a generic struct with short syntax, // need to get the parameter information from the original generic method if is_method_from_embed && arg.expr is ast.StructInit { diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 2e61e6c046a19b..7bfb5f2f295770 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2577,7 +2577,7 @@ fn (mut g Gen) keep_alive_call_postgen(node ast.CallExpr, tmp_cnt_save int) { @[inline] fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang ast.Language, is_smartcast bool) { - arg_typ := if g.comptime.is_comptime(arg.expr) { + arg_typ := if arg.ct_expr { g.unwrap_generic(g.type_resolver.get_type(arg.expr)) } else { g.unwrap_generic(arg.typ)