Skip to content

Commit 7e1a0e7

Browse files
committed
v2: lots of ssa/builder fixes; make arm64 and ssac pass all tests
1 parent 41d9d85 commit 7e1a0e7

31 files changed

Lines changed: 5848 additions & 871 deletions

‎cmd/tools/vast2/vast2.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn main() {
7272
checker.check_files(ast_files)
7373

7474
// Transform
75-
mut trans := transformer.Transformer.new(ast_files, env)
75+
mut trans := transformer.Transformer.new_with_pref(ast_files, env, &prefs)
7676
transformed_files := trans.transform_files(ast_files)
7777

7878
// Write post-transformation AST (only user files)

‎cmd/v2/test_ssa_backends.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
vroot := os.dir(@VEXE)
1515
v2_source := os.join_path(vroot, 'cmd', 'v2', 'v2.v')
1616
v2_binary := os.join_path(vroot, 'cmd', 'v2', 'v2')
17-
build_res := os.execute('${@VEXE} ${v2_source} -o ${v2_binary}')
17+
build_res := os.execute('${@VEXE} -gc none ${v2_source} -o ${v2_binary}')
1818
if build_res.exit_code != 0 {
1919
eprintln('Error: Failed to build v2')
2020
eprintln(build_res.output)
@@ -52,7 +52,7 @@ fn main() {
5252

5353
// Run v2 with selected backend
5454
println('[*] Running v2 -backend ${backend} ${input_file}...')
55-
mut backend_flags := '-backend ${backend}'
55+
mut backend_flags := '-gc none -backend ${backend}'
5656
if backend == 'cleanc' {
5757
// cleanc needs full per-run codegen for this suite right now.
5858
backend_flags += ' -nomarkused -nocache'
@@ -90,7 +90,7 @@ fn main() {
9090
// Run Reference (v run test.v)
9191
println('[*] Running reference: ${@VEXE} -enable-globals run ${input_file}...')
9292
os.rm(ref_output_path) or {}
93-
ref_cmd := '${@VEXE} -n -w -enable-globals run ${input_file} > ${ref_output_path} 2>&1'
93+
ref_cmd := '${@VEXE} -gc none -n -w -enable-globals run ${input_file} > ${ref_output_path} 2>&1'
9494
ref_res := os.execute(ref_cmd)
9595
ref_out := os.read_file(ref_output_path) or { '' }
9696
os.rm(ref_output_path) or {}

‎cmd/v2/test_v2_self.sh‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,30 @@ v3_bin="${script_dir}/v3"
1010
v4_bin="${script_dir}/v4"
1111
v5_bin="${script_dir}/v5"
1212

13-
v1_compiler="${V:-${repo_root}/v}"
13+
preferred_v1_compiler="${HOME}/code/v/v"
14+
v1_compiler="${V:-${preferred_v1_compiler}}"
15+
if [[ ! -x "${v1_compiler}" ]]; then
16+
v1_compiler="${repo_root}/v"
17+
fi
1418
if [[ ! -x "${v1_compiler}" ]]; then
1519
echo "FAILURE: v1 compiler not found or not executable: ${v1_compiler}"
1620
exit 1
1721
fi
1822

1923
# Build v2 with v1.
2024
rm -f "${v2_bin}" "${v3_bin}" "${v3_bin}.c" "${v4_bin}" "${v4_bin}.c" "${v5_bin}" "${v5_bin}.c"
21-
"${v1_compiler}" -o "${v2_bin}" "${v2_source}"
25+
"${v1_compiler}" -gc none -o "${v2_bin}" "${v2_source}"
2226

2327
# Use v2 to compile itself to v3 (using cleanc backend).
24-
"${v2_bin}" -o "${v3_bin}" -backend cleanc "${v2_source}"
28+
"${v2_bin}" -gc none -o "${v3_bin}" -backend cleanc "${v2_source}"
2529

2630
echo "SUCCESS: v2 successfully compiled itself to v3"
2731
echo "v3 binary size: $(ls -lh "${v3_bin}" | awk '{print $5}')"
2832

29-
"${v3_bin}" -realloc -o "${v4_bin}" -backend cleanc "${v2_source}"
33+
"${v3_bin}" -gc none -o "${v4_bin}" -backend cleanc "${v2_source}"
3034
printf '\nV4 compiled\n\n'
3135

32-
"${v4_bin}" -o "${v5_bin}" -backend cleanc "${v2_source}"
36+
"${v4_bin}" -gc none -o "${v5_bin}" -backend cleanc "${v2_source}"
3337
printf '\nV5 compiled\n\n'
3438

3539
# Test that v3 runs and produces expected output.

‎vlib/gx/text.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module gx
55
import gg
66

77
// TODO: remove these, and use the enum everywhere
8-
pub const align_left = HorizontalAlign.left
9-
pub const align_right = HorizontalAlign.right
8+
pub const align_left = gg.HorizontalAlign.left
9+
pub const align_right = gg.HorizontalAlign.right
1010

1111
pub type TextCfg = gg.TextCfg

‎vlib/os/file_le_be.c.v‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ fn swap_bytes[T](input T) T {
109109
return input
110110
} $else $if T is i8 {
111111
return input
112-
} $else $if T is byte {
113-
return input
114112
} $else $if T is u16 {
115113
return swap_bytes_u16(input)
116114
} $else $if T is u32 {
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module os
22

33
pub struct C.dirent {
4-
d_name [256]char
4+
d_ino u64
5+
d_seekoff u64
6+
d_reclen u16
7+
d_namlen u16
8+
d_type u8
9+
d_name [256]char
510
}

‎vlib/strconv/atou.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn atou_common_check(s string) !int {
3838
// s is string to parse, max is respective types max value.
3939
@[direct_array_access]
4040
fn atou_common(s string, type_max u64) !u64 {
41-
mut start_idx := atou_common_check(s)!
41+
mut start_idx := int(atou_common_check(s)!)
4242
mut x := u64(0)
4343
mut underscored := false
4444
for i in start_idx .. s.len {

‎vlib/strings/builder.c.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn (mut b Builder) write(data []u8) !int {
107107
if data.len == 0 {
108108
return 0
109109
}
110-
b << data
110+
unsafe { b.push_many(data.data, data.len) }
111111
return data.len
112112
}
113113

‎vlib/v2/builder/builder.v‎

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn (mut b Builder) build(files []string) {
8787

8888
// Transform AST (flag enum desugaring, etc.)
8989
transform_start := sw.elapsed()
90-
mut trans := transformer.Transformer.new(b.files, b.env)
90+
mut trans := transformer.Transformer.new_with_pref(b.files, b.env, b.pref)
9191
b.files = trans.transform_files(b.files)
9292
transform_time := time.Duration(sw.elapsed() - transform_start)
9393
print_time('Transform', transform_time)
@@ -223,8 +223,13 @@ fn (b &Builder) is_cmd_v2_self_build() bool {
223223
if b.user_files.len != 1 {
224224
return false
225225
}
226+
// Avoid path normalization here: during bootstraps, some intermediate
227+
// compilers can still have unstable path helpers.
226228
path := b.user_files[0].replace('\\', '/')
227-
return path.ends_with('/cmd/v2/v2.v') || path.ends_with('cmd/v2/v2.v') || path == 'v2.v'
229+
if path == 'v2.v' || path.ends_with('/v2.v') {
230+
return true
231+
}
232+
return path.ends_with('/cmd/v2/v2.v') || path.ends_with('cmd/v2/v2.v')
228233
}
229234

230235
fn (mut b Builder) gen_ssa_c() {
@@ -247,7 +252,11 @@ fn (mut b Builder) gen_ssa_c() {
247252
print_time('SSA Build', time.Duration(sw.elapsed() - stage_start))
248253

249254
stage_start = sw.elapsed()
250-
if os.getenv('V2_SSA_OPT') != '0' {
255+
mut use_ssa_opt := os.getenv('V2_SSA_OPT') != '0'
256+
if b.is_cmd_v2_self_build() {
257+
use_ssa_opt = false
258+
}
259+
if use_ssa_opt {
251260
optimize.optimize(mut mod)
252261
}
253262
print_time('SSA Optimize', time.Duration(sw.elapsed() - stage_start))
@@ -299,54 +308,13 @@ fn (mut b Builder) gen_ssa_c() {
299308
}
300309
cc_res := os.execute(cc_cmd)
301310
if cc_res.exit_code != 0 {
302-
eprintln('warning: ssa c backend compilation failed, falling back to cleanc backend')
303-
ssa_snapshot := output_name + '.ssa.c'
304-
os.cp(c_file, ssa_snapshot) or {}
311+
eprintln('error: ssa c backend compilation failed')
305312
lines := cc_res.output.split_into_lines()
306313
limit := if lines.len < 20 { lines.len } else { 20 }
307314
for line in lines[..limit] {
308315
eprintln(line)
309316
}
310-
mut fallback_args := []string{}
311-
fallback_args << os.quoted_path(os.args[0])
312-
fallback_args << '-backend cleanc'
313-
fallback_args << '-nomarkused'
314-
fallback_args << '-nocache'
315-
if b.pref.show_cc {
316-
fallback_args << '-showcc'
317-
}
318-
if b.pref.stats {
319-
fallback_args << '-stats'
320-
}
321-
if b.pref.print_parsed_files {
322-
fallback_args << '-print-parsed-files'
323-
}
324-
if b.pref.skip_builtin {
325-
fallback_args << '--skip-builtin'
326-
}
327-
if b.pref.skip_imports {
328-
fallback_args << '--skip-imports'
329-
}
330-
if b.pref.skip_type_check {
331-
fallback_args << '--skip-type-check'
332-
}
333-
if output_name.len > 0 {
334-
fallback_args << '-o ${os.quoted_path(output_name)}'
335-
}
336-
for user_file in b.user_files {
337-
fallback_args << os.quoted_path(user_file)
338-
}
339-
fallback_cmd := fallback_args.join(' ')
340-
fallback_res := os.execute(fallback_cmd)
341-
if fallback_res.exit_code != 0 {
342-
eprintln('error: cleanc fallback failed')
343-
eprintln(fallback_res.output)
344-
exit(1)
345-
}
346-
if fallback_res.output.len > 0 {
347-
println(fallback_res.output)
348-
}
349-
return
317+
exit(1)
350318
}
351319
print_time('CC', time.Duration(sw.elapsed() - cc_start))
352320

‎vlib/v2/builder/cache_headers.v‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ fn (b &Builder) can_use_cached_core_headers() bool {
191191
}
192192

193193
fn (b &Builder) can_use_cached_module_bundle(cache_name string, module_paths []string, cc string, cc_flags string) bool {
194-
obj_path := os.join_path(b.core_cache_dir(), '${cache_name}.o')
195-
stamp_path := os.join_path(b.core_cache_dir(), '${cache_name}.stamp')
194+
obj_file := cache_name + '.o'
195+
stamp_file := cache_name + '.stamp'
196+
obj_path := os.join_path(b.core_cache_dir(), obj_file)
197+
stamp_path := os.join_path(b.core_cache_dir(), stamp_file)
196198
if !os.exists(obj_path) || !os.exists(stamp_path) {
197199
return false
198200
}

0 commit comments

Comments
 (0)