Skip to content

Commit 2007e3a

Browse files
committed
v3: compare complete fallback input sets
1 parent 6d89baa commit 2007e3a

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

vlib/v/builder/c_error_report.v

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,10 @@ pub fn take_external_v3_report_from_env() ?ExternalCErrorBugReport {
474474
return report
475475
}
476476

477-
// matches_v3_fallback_inputs confirms that every source V3 recorded was parsed from the
478-
// same bytes by the stable compiler. Report paths are never opened: they are compared
479-
// only with canonical paths belonging to the stable parser's own AST files.
477+
// matches_v3_fallback_inputs confirms that the stable compiler parsed the same set of
478+
// project sources from the same bytes that V3 recorded. Report paths are never opened:
479+
// they are compared only with canonical paths belonging to the stable parser's own AST
480+
// files.
480481
fn (b &Builder) matches_v3_fallback_inputs(report ExternalCErrorBugReport) bool {
481482
if report.kind == external_v3_notice_only_kind {
482483
return true
@@ -485,11 +486,27 @@ fn (b &Builder) matches_v3_fallback_inputs(report ExternalCErrorBugReport) bool
485486
return false
486487
}
487488
mut stable_digests := map[string]string{}
489+
vlib_root := os.real_path(os.join_path(b.pref.vroot, 'vlib')).trim_right(os.path_separator)
488490
for file in b.parsed_files {
489491
if file.path == '' || file.source_digest == '' {
490492
continue
491493
}
492-
stable_digests[os.real_path(file.path)] = file.source_digest
494+
path := os.real_path(file.path)
495+
// Mirror macos_v3_fallback_report_sources: V1 and V3 intentionally parse
496+
// different bundled compiler-support files, so compare only caller/project and
497+
// installed-module inputs.
498+
if path == vlib_root || path.starts_with(vlib_root + os.path_separator) {
499+
continue
500+
}
501+
if previous := stable_digests[path] {
502+
if previous != file.source_digest {
503+
return false
504+
}
505+
}
506+
stable_digests[path] = file.source_digest
507+
}
508+
if stable_digests.len != report.input_digests.len {
509+
return false
493510
}
494511
for path, v3_digest in report.input_digests {
495512
if stable_digests[path] != v3_digest {

vlib/v/builder/c_error_report_test.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,24 @@ fn test_external_v3_report_env_round_trip() {
375375
}
376376

377377
fn test_v3_fallback_input_verification_uses_stable_parser_digests() {
378-
path := os.real_path(@FILE)
378+
vroot := os.real_path(@VEXEROOT)
379+
path := os.real_path(os.join_path(os.temp_dir(), 'v3_retry_input_main.v'))
379380
parsed_digest := sha256.hexhash('the exact stable parser bytes')
380381
b := &Builder{
382+
pref: &pref.Preferences{
383+
vroot: vroot
384+
}
381385
parsed_files: [
382386
&ast.File{
383387
path: path
384388
source_digest: parsed_digest
385389
},
390+
// Bundled vlib support files intentionally differ between V1 and V3 and are
391+
// excluded from both input sets.
392+
&ast.File{
393+
path: os.join_path(vroot, 'vlib', 'builtin', 'builtin.v')
394+
source_digest: sha256.hexhash('stable compiler builtin')
395+
},
386396
]
387397
}
388398
matching := ExternalCErrorBugReport{
@@ -404,6 +414,17 @@ fn test_v3_fallback_input_verification_uses_stable_parser_digests() {
404414
os.join_path(os.dir(path), 'not-parsed.v'): parsed_digest
405415
}
406416
})
417+
mut b_with_extra_input := &Builder{
418+
pref: &pref.Preferences{
419+
vroot: vroot
420+
}
421+
parsed_files: b.parsed_files.clone()
422+
}
423+
b_with_extra_input.parsed_files << &ast.File{
424+
path: os.join_path(os.dir(path), 'added-after-v3-failed.v')
425+
source_digest: sha256.hexhash('new stable-only input')
426+
}
427+
assert !b_with_extra_input.matches_v3_fallback_inputs(matching)
407428
assert !b.matches_v3_fallback_inputs(ExternalCErrorBugReport{
408429
...matching
409430
input_digests_complete: false

0 commit comments

Comments
 (0)