Skip to content

Commit 492c01f

Browse files
committed
fmt
1 parent 7347fae commit 492c01f

8 files changed

Lines changed: 85 additions & 54 deletions

File tree

cmd/v2/test_ssa_backends.v

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,17 @@ fn main() {
127127
}
128128
os.rm(gen_output_path) or {}
129129
// 60s timeout to catch infinite loops in ARM64-generated code
130-
gen_cmd := if os.exists('/opt/homebrew/bin/timeout') || os.exists('/usr/bin/timeout') {
131-
'timeout 60 ${cmd} > ${gen_output_path} 2>&1'
130+
has_timeout := os.exists('/opt/homebrew/bin/timeout') || os.exists('/usr/bin/timeout')
131+
has_gtimeout := os.exists('/opt/homebrew/bin/gtimeout') || os.exists('/usr/bin/gtimeout')
132+
timeout_cmd := if has_timeout {
133+
'timeout'
134+
} else if has_gtimeout {
135+
'gtimeout'
136+
} else {
137+
''
138+
}
139+
gen_cmd := if timeout_cmd != '' {
140+
'${timeout_cmd} 60 ${cmd} > ${gen_output_path} 2>&1'
132141
} else {
133142
'${cmd} > ${gen_output_path} 2>&1'
134143
}

vlib/v2/gen/cleanc/cleanc.v

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ mut:
3131
cur_fn_returned_idents map[string]bool
3232
active_generic_types map[string]types.Type
3333
// Comptime $for field iteration state
34-
comptime_field_var string // variable name (e.g., 'field')
35-
comptime_field_name string // current field name (e.g., 'id')
36-
comptime_field_type string // current field C type name
34+
comptime_field_var string // variable name (e.g., 'field')
35+
comptime_field_name string // current field name (e.g., 'id')
36+
comptime_field_type string // current field C type name
3737
comptime_field_raw_type types.Type = types.Struct{} // raw types.Type for comptime checks
38-
comptime_field_attrs []string // current field attributes
39-
comptime_field_idx int // current field index
40-
comptime_val_var string // the struct variable being decoded (e.g., 'val')
41-
comptime_val_type string // C type of val (e.g., 'Slack')
38+
comptime_field_attrs []string // current field attributes
39+
comptime_field_idx int // current field index
40+
comptime_val_var string // the struct variable being decoded (e.g., 'val')
41+
comptime_val_type string // C type of val (e.g., 'Slack')
4242

4343
fixed_array_fields map[string]bool
4444
fixed_array_field_elem map[string]string
@@ -85,25 +85,25 @@ mut:
8585
resolved_module_names map[string]string // per-function cache for resolve_module_name
8686
cached_env_scopes map[string]voidptr // cache of env_scope results (avoids repeated locking)
8787

88-
const_exprs map[string]string // const name → C expression string (for inlining)
89-
const_types map[string]string // const name → C type string
90-
runtime_const_targets map[string]bool // module-scoped consts initialized in __v_init_consts_*
91-
used_fn_keys map[string]bool
92-
force_emit_fn_names map[string]bool // function C names that must be emitted regardless of mark_used
93-
export_fn_names map[string]string // V-qualified name → export name (from @[export:] attribute)
94-
called_fn_names map[string]bool
95-
generic_spec_index map[string][]string // fn_name → matching keys in env.generic_types
96-
late_generic_specs map[string][]map[string]types.Type // additional comptime-discovered specs
97-
anon_fn_defs []string // lifted anonymous function definitions
98-
late_struct_defs []string // struct definitions discovered during pass 5 codegen
99-
pending_late_body_keys map[string]bool // body_keys in late_struct_defs but not yet flushed to g.sb
100-
late_generic_str_instances []string // c_names of late generic struct instances needing str macro check
101-
pass5_start_pos int // position in sb where pass 5 starts
102-
deferred_m_includes []string // Objective-C .m file #include lines deferred until after type definitions
103-
spawned_fns map[string]bool // spawn wrapper names already emitted
104-
spawn_wrapper_defs []string // spawn wrapper struct + function definitions
105-
emitted_trampolines map[string]bool // bound method trampoline names already emitted
106-
trampoline_defs []string // bound method trampoline definitions
88+
const_exprs map[string]string // const name → C expression string (for inlining)
89+
const_types map[string]string // const name → C type string
90+
runtime_const_targets map[string]bool // module-scoped consts initialized in __v_init_consts_*
91+
used_fn_keys map[string]bool
92+
force_emit_fn_names map[string]bool // function C names that must be emitted regardless of mark_used
93+
export_fn_names map[string]string // V-qualified name → export name (from @[export:] attribute)
94+
called_fn_names map[string]bool
95+
generic_spec_index map[string][]string // fn_name → matching keys in env.generic_types
96+
late_generic_specs map[string][]map[string]types.Type // additional comptime-discovered specs
97+
anon_fn_defs []string // lifted anonymous function definitions
98+
late_struct_defs []string // struct definitions discovered during pass 5 codegen
99+
pending_late_body_keys map[string]bool // body_keys in late_struct_defs but not yet flushed to g.sb
100+
late_generic_str_instances []string // c_names of late generic struct instances needing str macro check
101+
pass5_start_pos int // position in sb where pass 5 starts
102+
deferred_m_includes []string // Objective-C .m file #include lines deferred until after type definitions
103+
spawned_fns map[string]bool // spawn wrapper names already emitted
104+
spawn_wrapper_defs []string // spawn wrapper struct + function definitions
105+
emitted_trampolines map[string]bool // bound method trampoline names already emitted
106+
trampoline_defs []string // bound method trampoline definitions
107107
// @[live] hot code reloading
108108
live_fns []LiveFnInfo // @[live] functions detected during code generation
109109
live_source_file string // source file containing @[live] functions
@@ -116,16 +116,16 @@ mut:
116116
// a list of (suffix, bindings) pairs for each distinct concrete instantiation.
117117
// E.g. [("json2__ValueInfo", {T: ValueInfo}), ("json2__StructFieldInfo", {T: StructFieldInfo})]
118118
generic_struct_instances map[string][]GenericStructInstance
119-
c_file_fn_keys map[string]bool // fn_key -> emitted from a .c.v file, so plain .v fallback should be skipped
120-
typedef_c_types map[string]bool // C struct names with @[typedef] attribute (emit without 'struct' prefix)
121-
blocked_fn_keys map[string]bool // worker-only fn keys reserved to other pass5 chunks
122-
cached_vhash string // cached git short hash for @VHASH/@VCURRENTHASH
119+
c_file_fn_keys map[string]bool // fn_key -> emitted from a .c.v file, so plain .v fallback should be skipped
120+
typedef_c_types map[string]bool // C struct names with @[typedef] attribute (emit without 'struct' prefix)
121+
blocked_fn_keys map[string]bool // worker-only fn keys reserved to other pass5 chunks
122+
cached_vhash string // cached git short hash for @VHASH/@VCURRENTHASH
123123
}
124124

125125
struct GenericStructInstance {
126-
params_key string // e.g. "json2__ValueInfo" — unique key per instantiation
126+
params_key string // e.g. "json2__ValueInfo" — unique key per instantiation
127127
bindings map[string]types.Type // e.g. {T: ValueInfo}
128-
c_name string // full C struct name, e.g. "json2__Node_T_json2__StructFieldInfo"
128+
c_name string // full C struct name, e.g. "json2__Node_T_json2__StructFieldInfo"
129129
}
130130

131131
struct LiveFnInfo {

vlib/v2/gen/cleanc/fn.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn (mut g Gen) discover_comptime_generic_specs() {
718718
for key, spec_list in g.env.generic_types {
719719
for spec in spec_list {
720720
for param_name, concrete_type in spec {
721-
if concrete_type is types.Struct {
721+
if concrete_type is types.Struct {
722722
struct_type := concrete_type as types.Struct
723723
if struct_type.fields.len == 0 {
724724
continue
@@ -3812,7 +3812,8 @@ fn (mut g Gen) call_expr(lhs ast.Expr, args []ast.Expr) {
38123812
mut embedded_receiver_owner := ''
38133813
call_args << args
38143814
if lhs is ast.Ident {
3815-
if lhs.name.contains('get_or_panic') || (lhs.name.contains('get') && lhs.name.contains('ui_TextBox')) {
3815+
if lhs.name.contains('get_or_panic')
3816+
|| (lhs.name.contains('get') && lhs.name.contains('ui_TextBox')) {
38163817
eprintln('[DBG call_expr IDENT] name=${lhs.name}')
38173818
}
38183819
name = sanitize_fn_ident(lhs.name)

vlib/v2/gen/cleanc/stmt.v

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ fn (mut g Gen) gen_stmt(node ast.Stmt) {
5252
is_call := node.expr is ast.CallExpr
5353
is_ident := node.expr is ast.Ident
5454
C.fprintf(C.stderr, c'[gen_stmt/ExprStmt] valid=%d comptime=%d if=%d call=%d ident=%d\n',
55-
if expr_has_valid_data(node.expr) { 1 } else { 0 },
56-
if is_comptime { 1 } else { 0 },
57-
if is_if { 1 } else { 0 },
58-
if is_call { 1 } else { 0 },
59-
if is_ident { 1 } else { 0 })
55+
if expr_has_valid_data(node.expr) { 1 } else { 0 }, if is_comptime {
56+
1
57+
} else {
58+
0
59+
}, if is_if { 1 } else { 0 }, if is_call { 1 } else { 0 }, if is_ident {
60+
1
61+
} else {
62+
0
63+
})
6064
}
6165
if !expr_has_valid_data(node.expr) {
6266
return

vlib/v2/gen/cleanc/types.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,8 @@ fn (mut g Gen) get_comptime_selector_type(node ast.SelectorExpr) string {
28402840
// field.name.str → char*, field.name.len → int
28412841
if node.lhs is ast.SelectorExpr {
28422842
inner := node.lhs as ast.SelectorExpr
2843-
if inner.lhs is ast.Ident && inner.lhs.name == g.comptime_field_var && inner.rhs.name == 'name' {
2843+
if inner.lhs is ast.Ident && inner.lhs.name == g.comptime_field_var
2844+
&& inner.rhs.name == 'name' {
28442845
match rhs_name {
28452846
'str' { return 'char*' }
28462847
'len' { return 'int' }
@@ -3085,7 +3086,9 @@ fn (mut g Gen) get_raw_type_inner(node ast.Expr) ?types.Type {
30853086
if lhs_type is types.SumType {
30863087
if narrowed_c := g.get_expr_type_from_env(node.lhs) {
30873088
if narrowed_type := g.resolve_c_type_to_raw(narrowed_c) {
3088-
if field_type := selector_struct_field_type_from_type(narrowed_type, node.rhs.name) {
3089+
if field_type := selector_struct_field_type_from_type(narrowed_type,
3090+
node.rhs.name)
3091+
{
30893092
return field_type
30903093
}
30913094
}

vlib/v2/transformer/fn.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,9 @@ fn (mut t Transformer) transform_fn_decl(decl ast.FnDecl) ast.FnDecl {
956956
}
957957

958958
fn (mut t Transformer) transform_call_expr(expr ast.CallExpr) ast.Expr {
959-
if (t.cur_fn_name_str == 'get' || t.cur_fn_name_str == 'get_or_panic') && expr.lhs.name() != 'snprintf' && expr.lhs.name() != 'memdup' && expr.lhs.name() != 'malloc' {
959+
if (t.cur_fn_name_str == 'get' || t.cur_fn_name_str == 'get_or_panic')
960+
&& expr.lhs.name() != 'snprintf' && expr.lhs.name() != 'memdup'
961+
&& expr.lhs.name() != 'malloc' {
960962
is_ga := expr.lhs is ast.GenericArgs
961963
is_gaoi := expr.lhs is ast.GenericArgOrIndexExpr
962964
is_sel := expr.lhs is ast.SelectorExpr

vlib/v2/transformer/if.v

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,17 +1070,27 @@ fn (mut t Transformer) resolve_comptime_if_stmts(node ast.IfExpr) []ast.Stmt {
10701070
// checks (key_is/not_is) that need to be resolved by the backend.
10711071
fn (t &Transformer) can_eval_comptime_cond(cond ast.Expr) bool {
10721072
match cond {
1073-
ast.Ident { return true }
1074-
ast.PrefixExpr { return t.can_eval_comptime_cond(cond.expr) }
1073+
ast.Ident {
1074+
return true
1075+
}
1076+
ast.PrefixExpr {
1077+
return t.can_eval_comptime_cond(cond.expr)
1078+
}
10751079
ast.InfixExpr {
10761080
if cond.op == .key_is || cond.op == .not_is {
10771081
return false
10781082
}
10791083
return t.can_eval_comptime_cond(cond.lhs) && t.can_eval_comptime_cond(cond.rhs)
10801084
}
1081-
ast.PostfixExpr { return true }
1082-
ast.ParenExpr { return t.can_eval_comptime_cond(cond.expr) }
1083-
else { return false }
1085+
ast.PostfixExpr {
1086+
return true
1087+
}
1088+
ast.ParenExpr {
1089+
return t.can_eval_comptime_cond(cond.expr)
1090+
}
1091+
else {
1092+
return false
1093+
}
10841094
}
10851095
}
10861096

vlib/v2/types/checker.v

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4294,11 +4294,13 @@ fn (mut c Checker) ident(ident ast.Ident) Object {
42944294
if ident.name in ['typeof', 'sizeof', 'isreftype'] {
42954295
return Type(FnType{
42964296
return_type: Type(Struct{
4297-
name: '__typeof_result'
4298-
fields: [Field{
4299-
name: 'name'
4300-
typ: Type(string_)
4301-
}]
4297+
name: '__typeof_result'
4298+
fields: [
4299+
Field{
4300+
name: 'name'
4301+
typ: Type(string_)
4302+
},
4303+
]
43024304
})
43034305
})
43044306
}

0 commit comments

Comments
 (0)