Skip to content

Commit 87e0339

Browse files
committed
v2: new clean ssa and ssac
1 parent fced8de commit 87e0339

23 files changed

Lines changed: 3261 additions & 15752 deletions

File tree

‎GNUmakefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ MAC := 1
4141
TCCOS := macos
4242
ifeq ($(shell expr $(shell uname -r | cut -d. -f1) \<= 15), 1)
4343
LEGACY := 1
44-
CFLAGS += "-I$(LEGACYLIBS)/include/LegacySupport"
4544
endif
4645
endif
4746

‎cmd/tools/modules/testing/common.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
541541

542542
ts.benchmark.step()
543543
tls_bench.step()
544-
if produces_file_output && !ts.build_tools && (!should_be_built || abs_path in ts.skip_files) {
544+
if !ts.build_tools && (!should_be_built || abs_path in ts.skip_files) {
545545
ts.benchmark.skip()
546546
tls_bench.skip()
547547
if !hide_skips {

‎cmd/tools/vtest-all.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn get_all_commands() []Command {
105105
rmfile: 'hhww.c'
106106
}
107107
res << Command{
108-
line: '${vexe} -silent test vlib/builtin'
108+
line: '${vexe} test vlib/builtin'
109109
okmsg: 'V can test vlib/builtin'
110110
}
111111
res << Command{

‎vlib/v/gen/c/cgen.v‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ mut:
164164
inside_global_decl bool
165165
inside_interface_deref bool
166166
inside_assign_fn_var bool
167-
outer_tmp_var string // tmp var from outer context (e.g. from stmts_with_tmp_var) to be used by nested if/match expressions
168167
last_tmp_call_var []string
169168
last_if_option_type ast.Type // stores the expected if type on nested if expr
170169
loop_depth int
@@ -2357,7 +2356,6 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
23572356
g.set_current_pos_as_last_stmt_pos()
23582357
g.skip_stmt_pos = true
23592358
mut is_noreturn := false
2360-
mut is_if_expr_with_tmp := false
23612359
if stmt in [ast.Return, ast.BranchStmt] {
23622360
is_noreturn = true
23632361
} else if stmt is ast.ExprStmt {
@@ -2366,24 +2364,15 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
23662364
is_array_fixed_init = true
23672365
ret_type = stmt.expr.typ
23682366
}
2369-
if stmt.expr is ast.IfExpr && g.is_autofree && !g.inside_if_option
2370-
&& !g.inside_if_result {
2371-
is_if_expr_with_tmp = true
2372-
g.outer_tmp_var = tmp_var
2373-
}
23742367
}
2375-
if !is_noreturn && !is_if_expr_with_tmp {
2368+
if !is_noreturn {
23762369
if is_array_fixed_init {
23772370
g.write('memcpy(${tmp_var}, (${g.styp(ret_type)})')
23782371
} else {
23792372
g.write('${tmp_var} = ')
23802373
}
23812374
}
23822375
g.stmt(stmt)
2383-
// Reset outer_tmp_var after processing
2384-
if is_if_expr_with_tmp {
2385-
g.outer_tmp_var = ''
2386-
}
23872376
if is_array_fixed_init {
23882377
lines := g.go_before_last_stmt().trim_right('; \n')
23892378
g.writeln('${lines}, sizeof(${tmp_var}));')
@@ -4440,22 +4429,6 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
44404429
}
44414430
}
44424431
if node.expr_type == 0 {
4443-
// Handle comptime type selector T.name when inside comptime context
4444-
if node.field_name == 'name' && node.expr is ast.Ident {
4445-
ident := node.expr as ast.Ident
4446-
if g.table.cur_fn != unsafe { nil } && g.table.cur_fn.generic_names.len > 0 {
4447-
for i, gname in g.table.cur_fn.generic_names {
4448-
if gname == ident.name {
4449-
if i < g.table.cur_concrete_types.len {
4450-
g.type_name(g.table.cur_concrete_types[i])
4451-
} else {
4452-
g.write('_S("${ident.name}")')
4453-
}
4454-
return
4455-
}
4456-
}
4457-
}
4458-
}
44594432
g.checker_bug('unexpected SelectorExpr.expr_type = 0', node.pos)
44604433
}
44614434

‎vlib/v/gen/c/fn.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
10011001
} else {
10021002
''
10031003
}
1004-
if (gen_or || gen_keep_alive) && node.return_type != 0 {
1004+
if gen_or || gen_keep_alive {
10051005
mut ret_typ := node.return_type
10061006
if g.table.sym(ret_typ).kind == .alias {
10071007
unaliased_type := g.table.unaliased_type(ret_typ)
@@ -1064,7 +1064,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
10641064
} else {
10651065
g.fn_call(node)
10661066
}
1067-
if gen_or && node.return_type != 0 {
1067+
if gen_or {
10681068
g.or_block(tmp_opt, node.or_block, node.return_type)
10691069
mut unwrapped_typ := node.return_type.clear_option_and_result()
10701070
if g.table.sym(unwrapped_typ).kind == .alias {
@@ -1109,7 +1109,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
11091109
}
11101110
}
11111111
}
1112-
} else if gen_keep_alive && node.return_type != 0 {
1112+
} else if gen_keep_alive {
11131113
if node.return_type == ast.void_type {
11141114
g.write('\n ${cur_line}')
11151115
} else {

‎vlib/v/gen/c/if.v‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,15 @@ fn (mut g Gen) needs_conds_order(node ast.IfExpr) bool {
181181
}
182182

183183
fn (mut g Gen) if_expr(node ast.IfExpr) {
184-
use_outer_tmp := g.outer_tmp_var != ''
185-
saved_outer_tmp_var := g.outer_tmp_var
186-
if use_outer_tmp {
187-
g.outer_tmp_var = ''
188-
}
189-
190184
// For simple if expressions we can use C's `?:`
191185
// `if x > 0 { 1 } else { 2 }` => `(x > 0)? (1) : (2)`
192186
// For if expressions with multiple statements or another if expression inside, it's much
193187
// easier to use a temp var, than do C tricks with commas, introduce special vars etc
194188
// (as it used to be done).
195189
// Always use this in -autofree, since ?: can have tmp expressions that have to be freed.
196-
needs_tmp_var := g.inside_if_option || g.need_tmp_var_in_if(node) || use_outer_tmp
190+
needs_tmp_var := g.inside_if_option || g.need_tmp_var_in_if(node)
197191
needs_conds_order := g.needs_conds_order(node)
198-
tmp := if use_outer_tmp {
199-
// Use the tmp var from outer context (e.g. from stmts_with_tmp_var)
200-
saved_outer_tmp_var
201-
} else if g.inside_if_option || (node.typ != ast.void_type && needs_tmp_var) {
192+
tmp := if g.inside_if_option || (node.typ != ast.void_type && needs_tmp_var) {
202193
g.new_tmp_var()
203194
} else {
204195
''
@@ -276,8 +267,7 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
276267
}
277268
cur_line = g.go_before_last_stmt()
278269
g.empty_line = true
279-
if tmp != '' && !use_outer_tmp {
280-
// Only declare the tmp var if it's not from outer context
270+
if tmp != '' {
281271
if node.typ == ast.void_type && g.last_if_option_type != 0 {
282272
// nested if on return stmt
283273
g.write2(g.styp(g.unwrap_generic(g.last_if_option_type)), ' ')

‎vlib/v/gen/c/str_intp.v‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ fn (mut g Gen) get_default_fmt(ftyp ast.Type, typ ast.Type) u8 {
4949
fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, string) {
5050
mut base := 0 // numeric base
5151
mut upper_case := false // set uppercase for the result string
52-
mut typ := if i < node.expr_types.len {
53-
g.unwrap_generic(node.expr_types[i])
54-
} else {
55-
ast.string_type
56-
}
52+
mut typ := g.unwrap_generic(node.expr_types[i])
5753
if node.exprs[i].is_auto_deref_var() {
5854
typ = typ.deref()
5955
}
@@ -196,11 +192,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, s
196192
fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
197193
expr := node.exprs[i]
198194
fmt := fmts[i]
199-
typ := if i < node.expr_types.len {
200-
g.unwrap_generic(node.expr_types[i])
201-
} else {
202-
ast.string_type
203-
}
195+
typ := g.unwrap_generic(node.expr_types[i])
204196
typ_sym := g.table.sym(typ)
205197
if g.comptime.inside_comptime_for && expr is ast.SelectorExpr && expr.field_name == 'name'
206198
&& expr.expr is ast.TypeOf {
@@ -342,10 +334,8 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
342334
for i, mut expr in node_.exprs {
343335
mut field_typ := if mut expr is ast.Ident && g.is_comptime_for_var(expr) {
344336
g.comptime.comptime_for_field_type
345-
} else if i < node_.expr_types.len {
346-
node_.expr_types[i]
347337
} else {
348-
ast.void_type
338+
node_.expr_types[i]
349339
}
350340
if g.comptime.inside_comptime_for && mut expr is ast.SelectorExpr {
351341
if expr.expr is ast.TypeOf && expr.field_name == 'name' {
@@ -375,11 +365,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
375365
}
376366
}
377367
} else {
378-
if i >= node_.expr_types.len {
379-
node_.expr_types << field_typ
380-
} else {
381-
node_.expr_types[i] = field_typ
382-
}
368+
node_.expr_types[i] = field_typ
383369
}
384370
}
385371
g.write2('builtin__str_intp(', node.vals.len.str())

‎vlib/v/scanner/scanner.v‎

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@ const num_sep = `_`
2020
const b_lf = 10
2121
const b_cr = 13
2222
const backslash = `\\`
23-
const digit_table = get_digit_table()
24-
const letter_table = get_letter_table()
25-
26-
@[direct_array_access]
27-
fn get_digit_table() [256]bool {
28-
mut res := [256]bool{}
29-
for c in 0 .. 256 {
30-
res[c] = u8(c).is_digit()
31-
}
32-
return res
33-
}
34-
35-
@[direct_array_access]
36-
fn get_letter_table() [256]bool {
37-
mut res := [256]bool{}
38-
for c in 0 .. 256 {
39-
res[c] = u8(c).is_letter()
40-
}
41-
return res
42-
}
4323

4424
@[minify]
4525
pub struct Scanner {
@@ -293,7 +273,6 @@ fn (s &Scanner) num_lit(start int, end int) string {
293273
}
294274
}
295275

296-
@[direct_array_access]
297276
fn (mut s Scanner) ident_bin_number() string {
298277
mut has_wrong_digit := false
299278
mut first_wrong_digit_pos := 0
@@ -309,7 +288,7 @@ fn (mut s Scanner) ident_bin_number() string {
309288
s.error('cannot use `_` consecutively')
310289
}
311290
if !c.is_bin_digit() && c != num_sep {
312-
if (!digit_table[c] && !letter_table[c]) || s.is_inside_string || s.is_nested_string {
291+
if (!c.is_digit() && !c.is_letter()) || s.is_inside_string || s.is_nested_string {
313292
break
314293
} else if !has_wrong_digit {
315294
has_wrong_digit = true
@@ -353,7 +332,7 @@ fn (mut s Scanner) ident_hex_number() string {
353332
s.error('cannot use `_` consecutively')
354333
}
355334
if !c.is_hex_digit() && c != num_sep {
356-
if !letter_table[c] || s.is_inside_string || s.is_nested_string {
335+
if !c.is_letter() || s.is_inside_string || s.is_nested_string {
357336
break
358337
} else if !has_wrong_digit {
359338
has_wrong_digit = true
@@ -378,7 +357,6 @@ fn (mut s Scanner) ident_hex_number() string {
378357
return number
379358
}
380359

381-
@[direct_array_access]
382360
fn (mut s Scanner) ident_oct_number() string {
383361
mut has_wrong_digit := false
384362
mut first_wrong_digit_pos := 0
@@ -394,7 +372,7 @@ fn (mut s Scanner) ident_oct_number() string {
394372
s.error('cannot use `_` consecutively')
395373
}
396374
if !c.is_oct_digit() && c != num_sep {
397-
if (!digit_table[c] && !letter_table[c]) || s.is_inside_string || s.is_nested_string {
375+
if (!c.is_digit() && !c.is_letter()) || s.is_inside_string || s.is_nested_string {
398376
break
399377
} else if !has_wrong_digit {
400378
has_wrong_digit = true
@@ -431,8 +409,8 @@ fn (mut s Scanner) ident_dec_number() string {
431409
if c == num_sep && s.text[s.pos - 1] == num_sep {
432410
s.error('cannot use `_` consecutively')
433411
}
434-
if !digit_table[c] && c != num_sep {
435-
if !letter_table[c] || c in [`e`, `E`] || s.is_inside_string || s.is_nested_string {
412+
if !c.is_digit() && c != num_sep {
413+
if !c.is_letter() || c in [`e`, `E`] || s.is_inside_string || s.is_nested_string {
436414
break
437415
} else if !has_wrong_digit {
438416
has_wrong_digit = true
@@ -453,14 +431,14 @@ fn (mut s Scanner) ident_dec_number() string {
453431
s.pos++
454432
if s.pos < s.text.len {
455433
// 5.5, 5.5.str()
456-
if digit_table[s.text[s.pos]] {
434+
if s.text[s.pos].is_digit() {
457435
for s.pos < s.text.len {
458436
c := s.text[s.pos]
459-
if !digit_table[c] {
460-
if !letter_table[c] || c in [`e`, `E`] || s.is_inside_string
437+
if !c.is_digit() {
438+
if !c.is_letter() || c in [`e`, `E`] || s.is_inside_string
461439
|| s.is_nested_string {
462440
// 5.5.str()
463-
if c == `.` && s.pos + 1 < s.text.len && letter_table[s.text[s.pos + 1]] {
441+
if c == `.` && s.pos + 1 < s.text.len && s.text[s.pos + 1].is_letter() {
464442
call_method = true
465443
}
466444
break
@@ -478,14 +456,14 @@ fn (mut s Scanner) ident_dec_number() string {
478456
s.pos--
479457
} else if s.text[s.pos] in [`e`, `E`] {
480458
// 5.e5
481-
} else if letter_table[s.text[s.pos]] {
459+
} else if s.text[s.pos].is_letter() {
482460
// 5.str()
483461
call_method = true
484462
s.pos--
485463
} else {
486464
// 5.
487465
mut symbol_length := 0
488-
for i := s.pos - 2; i > 0 && digit_table[s.text[i - 1]]; i-- {
466+
for i := s.pos - 2; i > 0 && s.text[i - 1].is_digit(); i-- {
489467
symbol_length++
490468
}
491469
float_symbol := s.text[s.pos - 2 - symbol_length..s.pos - 1]
@@ -503,10 +481,10 @@ fn (mut s Scanner) ident_dec_number() string {
503481
}
504482
for s.pos < s.text.len {
505483
c := s.text[s.pos]
506-
if !digit_table[c] {
507-
if !letter_table[c] || s.is_inside_string || s.is_nested_string {
484+
if !c.is_digit() {
485+
if !c.is_letter() || s.is_inside_string || s.is_nested_string {
508486
// 5e5.str()
509-
if c == `.` && s.pos + 1 < s.text.len && letter_table[s.text[s.pos + 1]] {
487+
if c == `.` && s.pos + 1 < s.text.len && s.text[s.pos + 1].is_letter() {
510488
call_method = true
511489
}
512490
break
@@ -735,7 +713,7 @@ pub fn (mut s Scanner) text_scan() token.Token {
735713
s.is_inter_start = false
736714
}
737715
return s.new_token(.name, name, name.len)
738-
} else if digit_table[c] || (c == `.` && digit_table[nextc]) {
716+
} else if c.is_digit() || (c == `.` && nextc.is_digit()) {
739717
// `123`, `.123`
740718
if !s.is_inside_string {
741719
// In C ints with `0` prefix are octal (in V they're decimal), so discarding heading zeros is needed.
@@ -745,7 +723,7 @@ pub fn (mut s Scanner) text_scan() token.Token {
745723
}
746724
mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped
747725
// for 0b, 0o, 0x the heading zero shouldn't be jumped
748-
if start_pos == s.text.len || (c == `0` && !digit_table[s.text[start_pos]]) {
726+
if start_pos == s.text.len || (c == `0` && !s.text[start_pos].is_digit()) {
749727
prefix_zero_num--
750728
}
751729
s.pos += prefix_zero_num // jump these zeros
@@ -1287,7 +1265,7 @@ pub fn (mut s Scanner) ident_string() string {
12871265
s.u32_escapes_pos << s.pos - 1
12881266
}
12891267
// Unknown escape sequence
1290-
if !util.is_escape_sequence(c) && !digit_table[c] && c != `\n` {
1268+
if !util.is_escape_sequence(c) && !c.is_digit() && c != `\n` {
12911269
s.error('`${c.ascii_str()}` unknown escape sequence')
12921270
}
12931271
}
@@ -1631,7 +1609,7 @@ pub fn (mut s Scanner) ident_char() string {
16311609
s.error_with_pos('invalid character literal, use \`\\n\` instead', lspos)
16321610
} else if c.len > len {
16331611
ch := c[c.len - 1]
1634-
if !util.is_escape_sequence(ch) && !digit_table[ch] {
1612+
if !util.is_escape_sequence(ch) && !ch.is_digit() {
16351613
s.error('`${ch.ascii_str()}` unknown escape sequence')
16361614
}
16371615
}

0 commit comments

Comments
 (0)