v / vlib / v2 / gen / cleanc / pass5_worker_test.v
54 lines · 47 sloc · 2.08 KB · 7134f481ebb818f54fc8da194d9a0453ced1a75e
Raw
1module cleanc
2
3fn test_pass5_worker_clones_global_type_lookup() {
4 mut g := Gen.new([])
5 g.global_var_types['main__settings'] = 'main__Settings'
6 mut worker := g.new_pass5_worker([], 0)
7 assert worker.global_var_types['main__settings'] == 'main__Settings'
8 g.global_var_types['main__settings'] = 'main__OtherSettings'
9 assert worker.global_var_types['main__settings'] == 'main__Settings'
10}
11
12fn test_specialized_receiver_method_index_tracks_ambiguity() {
13 mut g := Gen.new([])
14 g.fn_return_types['Box_T_i32__get'] = 'int'
15 g.remember_specialized_fn_base('Box_T_i32__get')
16 got := g.resolve_specialized_receiver_method('Box', 'get') or { '' }
17 assert got == 'Box_T_i32__get'
18
19 g.fn_return_types['Box_T_string__get'] = 'string'
20 g.remember_specialized_fn_base('Box_T_string__get')
21 if _ := g.resolve_specialized_receiver_method('Box', 'get') {
22 assert false
23 } else {
24 assert true
25 }
26}
27
28// When a file is split across pass-5 workers, a non-owning worker blocks the
29// file's fns but must still emit its own assigned slice. The owner-scoped bypass
30// allows exactly the fns owned by the slice's file (explicit_slice_file) and
31// nothing transitively reached from another file.
32fn test_explicit_slice_emit_allows_is_scoped_to_owning_file() {
33 mut g := Gen.new([])
34 g.fn_owner_file['fn_foo'] = 3 // foo is owned by file 3
35 g.fn_owner_file['fn_bar'] = 5 // bar is owned by a different file
36 g.blocked_fn_keys['fn_foo'] = true
37 g.blocked_fn_keys['fn_bar'] = true
38
39 // Not in an explicit slice: nothing is unblocked.
40 assert !g.explicit_slice_emit_allows('fn_foo')
41 assert !g.explicit_slice_emit_allows('fn_bar')
42
43 // Emitting file 3's slice: only file 3's fns are unblocked.
44 g.explicit_slice_active = true
45 g.explicit_slice_file = 3
46 assert g.explicit_slice_emit_allows('fn_foo')
47 assert !g.explicit_slice_emit_allows('fn_bar') // owned by file 5 -> stays blocked
48 assert !g.explicit_slice_emit_allows('fn_unknown') // no recorded owner -> blocked
49
50 // Switching to file 5's slice flips which fn is allowed.
51 g.explicit_slice_file = 5
52 assert !g.explicit_slice_emit_allows('fn_foo')
53 assert g.explicit_slice_emit_allows('fn_bar')
54}
55