From 43d679b1b94e45347075260f0c1a7d9d35b47c3d Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 5 Jan 2025 05:04:31 -0300 Subject: [PATCH] cgen: cleanup comptime checks (#23372) --- vlib/v/gen/c/assign.v | 2 +- vlib/v/gen/c/str_intp.v | 1 - vlib/v/type_resolver/generic_resolver.v | 4 ++-- vlib/v/type_resolver/type_resolver.v | 5 +++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 609dadb5e71e49..88fc9abb91a144 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -372,7 +372,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { g.assign_ct_type = var_type } } else if val is ast.InfixExpr && val.op in [.plus, .minus, .mul, .div, .mod] - && g.comptime.is_comptime(val.left) { + && val.left_ct_expr { ctyp := g.unwrap_generic(g.type_resolver.get_type(val.left)) if ctyp != ast.void_type { ct_type_var := g.comptime.get_ct_type_var(val.left) diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index d21e04c2c787a2..7459056cda8bb2 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -231,7 +231,6 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) { } fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { - // fn (mut g Gen) str_int2(node ast.StringInterLiteral) { inside_interface_deref_old := g.inside_interface_deref g.inside_interface_deref = true defer { diff --git a/vlib/v/type_resolver/generic_resolver.v b/vlib/v/type_resolver/generic_resolver.v index 305cdbd21394c7..457c8a52340005 100644 --- a/vlib/v/type_resolver/generic_resolver.v +++ b/vlib/v/type_resolver/generic_resolver.v @@ -17,10 +17,10 @@ pub fn (mut ct TypeResolver) unwrap_generic_expr(expr ast.Expr, default_typ ast. return expr.typ } ast.InfixExpr { - if ct.info.is_comptime(expr.left) { + if expr.left_ct_expr { return ct.resolver.unwrap_generic(ct.get_type(expr.left)) } - if ct.info.is_comptime(expr.right) { + if expr.right_ct_expr { return ct.resolver.unwrap_generic(ct.get_type(expr.right)) } return default_typ diff --git a/vlib/v/type_resolver/type_resolver.v b/vlib/v/type_resolver/type_resolver.v index 484d28583c808b..2e4cd38fbf03e5 100644 --- a/vlib/v/type_resolver/type_resolver.v +++ b/vlib/v/type_resolver/type_resolver.v @@ -207,12 +207,13 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type { } else if node is ast.ParExpr && t.info.is_comptime(node.expr) { return t.get_type(node.expr) } else if node is ast.InfixExpr { - if !node.left.is_literal() && t.info.is_comptime(node.left) { + if node.left_ct_expr { return t.get_type(node.left) - } else if !node.right.is_literal() && t.info.is_comptime(node.right) { + } else if node.right_ct_expr { return t.get_type(node.right) } } else if node is ast.CastExpr && node.typ.has_flag(.generic) { + // T(expr) return t.resolver.unwrap_generic(node.typ) } return ast.void_type