Skip to content

Commit 0cea9e0

Browse files
committed
Merge remote-tracking branch 'origin/master' into v3-default-linux-fallback-reports
# Conflicts: # cmd/v/macos_v3_args.c.v # cmd/v/macos_v3_darwin.c.v # vlib/v3/transform/transform_parallel_notd_v3_no_parallel.v
2 parents 72a4763 + 4fbc55a commit 0cea9e0

30 files changed

Lines changed: 1028 additions & 785 deletions

cmd/tools/vtest-self.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ const skip_on_ubuntu_musl = [
295295
'vlib/orm/orm_serial_attribute_test.v',
296296
'vlib/orm/orm_option_subselect_test.v',
297297
'vlib/orm/orm_func_test.v',
298+
'vlib/orm/orm_module_table_prefix/orm_module_table_prefix_test.v',
298299
'vlib/orm/orm_where_in_test.v',
299300
'vlib/sokol/gfx/gfx_test.v', // sokol_app.h needs GL/gl.h, not installed in the musl Docker image
300301
'vlib/v/gen/c/sql_assert_temp_var_test.v', // sqlite header dependency pulls in glibc sys/cdefs.h on musl-gcc

cmd/v/macos_v3_args.c.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ fn macos_v3_non_compilation_command(command string) bool {
1919
'interpret', 'get', 'translate']
2020
}
2121

22+
// is_macos_v3_compiler_bootstrap reports whether `normalized_path` targets the
23+
// `vlib/v3/v3.v` compiler bootstrap, which must build with the compatibility
24+
// compiler rather than the embedded V3 driver. It matches the repo-relative path
25+
// and any path ending in it, and also resolves a bare `v3.v` (for example when
26+
// invoked from inside `vlib/v3`) through its real path, so the bootstrap is
27+
// recognized regardless of the working directory. Both dispatch gates rely on
28+
// it, so keep the detection in one place to stop them drifting.
29+
@[markused]
30+
fn is_macos_v3_compiler_bootstrap(normalized_path string) bool {
31+
if normalized_path == 'vlib/v3/v3.v' || normalized_path.ends_with('/vlib/v3/v3.v') {
32+
return true
33+
}
34+
// Only a file literally named `v3.v` can be the bootstrap; skip the real-path
35+
// resolution (a filesystem lookup) for every other compilation target.
36+
if os.base(normalized_path) != 'v3.v' {
37+
return false
38+
}
39+
real_path := os.real_path(normalized_path).replace('\\', '/').trim_right('/')
40+
return real_path == 'vlib/v3/v3.v' || real_path.ends_with('/vlib/v3/v3.v')
41+
}
42+
2243
// macos_v3_force_requested reports whether `-new-compiler` should hand this
2344
// invocation to the embedded V3 compiler. It gates on `-old-compiler`
2445
// precedence, options/modes V3 cannot honor yet, and whether the command is an
@@ -53,7 +74,7 @@ fn macos_v3_explicit_compilation_requested(command string, prefs &pref.Preferenc
5374
}
5475
normalized_path := prefs.path.replace('\\', '/').trim_right('/')
5576
if is_macos_v3_vroot_path(normalized_path, 'cmd/v', true)
56-
|| is_macos_v3_vroot_path(normalized_path, 'vlib/v3/v3.v', false) {
77+
|| is_macos_v3_compiler_bootstrap(normalized_path) {
5778
return false
5879
}
5980
return command in ['run', 'build'] || prefs.is_script || os.is_dir(prefs.path)

cmd/v/macos_v3_test.v

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,47 @@ fn test_macos_v3_relevant_command_selects_user_compilation_and_tests() {
243243
}
244244
}
245245

246+
fn test_macos_v3_compiler_bootstrap_is_detected_from_any_cwd() {
247+
// Repo-relative and absolute spellings are recognized directly.
248+
assert is_macos_v3_compiler_bootstrap('vlib/v3/v3.v')
249+
assert is_macos_v3_compiler_bootstrap('/home/user/v/vlib/v3/v3.v')
250+
// Non-bootstrap targets stay on the V3 path.
251+
assert !is_macos_v3_compiler_bootstrap('main.v')
252+
assert !is_macos_v3_compiler_bootstrap('cmd/v')
253+
assert !is_macos_v3_compiler_bootstrap('some/other/place/v3.v')
254+
255+
// A bare `v3.v` invoked from inside vlib/v3 must resolve to the bootstrap so
256+
// it builds with the compatibility compiler instead of the embedded V3 driver.
257+
// Use an isolated <tmp>/vlib/v3/v3.v so this exercises the real-path
258+
// resolution unconditionally, independent of where this test file lives.
259+
root := os.join_path(os.real_path(os.vtmp_dir()), 'macos_v3_bootstrap_${os.getpid()}')
260+
v3_dir := os.join_path(root, 'vlib', 'v3')
261+
other_dir := os.join_path(root, 'elsewhere')
262+
os.rmdir_all(root) or {}
263+
os.mkdir_all(v3_dir) or { panic(err) }
264+
os.mkdir_all(other_dir) or { panic(err) }
265+
defer {
266+
os.rmdir_all(root) or {}
267+
}
268+
os.write_file(os.join_path(v3_dir, 'v3.v'), 'module main\n') or { panic(err) }
269+
os.write_file(os.join_path(other_dir, 'v3.v'), 'module main\n') or { panic(err) }
270+
271+
saved := os.getwd()
272+
defer {
273+
os.chdir(saved) or {}
274+
}
275+
os.chdir(v3_dir) or { panic(err) }
276+
bare := is_macos_v3_compiler_bootstrap('v3.v')
277+
dotted := is_macos_v3_compiler_bootstrap('./v3.v')
278+
// A bare `v3.v` that is not under vlib/v3 must stay on the V3 path.
279+
os.chdir(other_dir) or { panic(err) }
280+
non_bootstrap := is_macos_v3_compiler_bootstrap('v3.v')
281+
os.chdir(saved) or {}
282+
assert bare
283+
assert dotted
284+
assert !non_bootstrap
285+
}
286+
246287
fn test_macos_v3_dispatch_allows_the_implicit_gc_default() {
247288
$if macos {
248289
implicit_gc, _ := pref.parse_args_and_show_errors([], ['', 'main.v'], false)

vlib/db/pg/pg_escape_literal_test.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// vtest build: started_postgres?
12
module main
23

34
import db.pg

vlib/io/buffered_reader_test.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ fn test_read_handles_eof_with_unread_data() {
244244
}
245245

246246
fn test_read_line_handles_eof_with_unread_data() {
247-
b := rand.bytes(8)!
247+
// Keep the payload delimiter-free; random bytes can contain `\n` and make
248+
// read_line correctly return a shorter first line.
249+
b := 'abcdefgh'.bytes()
248250
data := arrays.concat(b, `\n`)
249251
mut br := new_one_byte_buffered_reader(data, 16)
250252
mut p := br.peek(10)!

vlib/sync/mutex_zero_value_darwin_test.c.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// vtest build: macos
12
import sync
23

34
struct MutexHolder {

vlib/v/gen/c/cgen.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13632,6 +13632,11 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
1363213632
return '{0}'
1363313633
}
1363413634
.thread {
13635+
// Windows uses a struct for typed thread handles, while untyped Windows
13636+
// handles and POSIX pthread_t values are scalar types.
13637+
if g.pref.os == .windows && g.styp(typ) != '__v_thread' {
13638+
return '{0}'
13639+
}
1363513640
return '0'
1363613641
}
1363713642
.alias {

vlib/v/gen/c/struct.v

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,18 @@ fn (mut g Gen) struct_init_field_default(field_unwrap_typ ast.Type, sfield &ast.
12971297

12981298
if sfield.expected_type.has_flag(.option) && field_unwrap_typ.has_flag(.option)
12991299
&& g.styp(sfield.expected_type) != g.styp(field_unwrap_typ) {
1300-
g.expr_opt_with_cast(sfield.expr, field_unwrap_typ, sfield.expected_type)
1300+
expr_base_typ := g.table.unaliased_type(field_unwrap_typ.clear_flag(.option))
1301+
expected_base_typ := g.table.unaliased_type(sfield.expected_type.clear_flag(.option))
1302+
expr_base_sym := g.table.final_sym(expr_base_typ)
1303+
expected_base_sym := g.table.final_sym(expected_base_typ)
1304+
if expr_base_typ == expected_base_typ
1305+
|| (expr_base_sym.kind == .function && expected_base_sym.kind == .function) {
1306+
// Alias-equivalent payloads have the same representation. Clone the complete
1307+
// option so `none` and error state are preserved along with the payload.
1308+
g.expr_opt_with_alias(sfield.expr, field_unwrap_typ, sfield.expected_type)
1309+
} else {
1310+
g.expr_opt_with_cast(sfield.expr, field_unwrap_typ, sfield.expected_type)
1311+
}
13011312
} else if (sfield.expected_type.has_flag(.option) && !field_unwrap_typ.has_flag(.option))
13021313
|| (sfield.expected_type.has_flag(.result) && !field_unwrap_typ.has_flag(.result)) {
13031314
g.expr_with_opt(sfield.expr, field_unwrap_typ, sfield.expected_type)

vlib/v/tests/gnu_make_tcc_fallback_test.v

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ printf "%s\\n" "\$*" >> ${os.quoted_path(rsync_trace)}
140140
archive=0
141141
delete_destination=0
142142
exclude_root_github=0
143+
exclude_root_git=0
143144
while [ "\$#" -gt 0 ]; do
144145
case "\$1" in
145146
-a)
@@ -154,6 +155,10 @@ while [ "\$#" -gt 0 ]; do
154155
exclude_root_github=1
155156
shift
156157
;;
158+
--exclude=/.git|--exclude=/.git/)
159+
exclude_root_git=1
160+
shift
161+
;;
157162
--)
158163
shift
159164
break
@@ -195,12 +200,12 @@ for source_path in "\$@"; do
195200
case "\$source_path" in
196201
*/)
197202
mkdir -p -- "\$destination_path"
198-
if [ "\$exclude_root_github" = 1 ]; then
203+
if [ "\$exclude_root_github" = 1 ] || [ "\$exclude_root_git" = 1 ]; then
199204
for source_entry in "\${source_path}".[!.]* "\${source_path}"..?* "\${source_path}"*; do
200205
if [ ! -e "\$source_entry" ] && [ ! -L "\$source_entry" ]; then
201206
continue
202207
fi
203-
if [ "\${source_entry##*/}" = ".github" ]; then
208+
if { [ "\$exclude_root_github" = 1 ] && [ "\${source_entry##*/}" = ".github" ]; } || { [ "\$exclude_root_git" = 1 ] && [ "\${source_entry##*/}" = ".git" ]; }; then
204209
continue
205210
fi
206211
cp -a -- "\$source_entry" "\$destination_path/"
@@ -254,14 +259,16 @@ fi
254259
assert trace_lines[i].starts_with('${option_prefix}${operation}'), trace_lines.str()
255260
}
256261
rsync_lines := (os.read_file(rsync_trace) or { panic(err) }).trim_space().split_into_lines()
257-
assert rsync_lines.len == 7, rsync_lines.str()
258-
assert rsync_lines[0].starts_with('-a thirdparty/tcc/ '), rsync_lines.str()
259-
assert rsync_lines[1].starts_with('-a --delete --exclude=/.github/ '), rsync_lines.str()
260-
assert rsync_lines[2].contains('thirdparty/tcc.original/.git/'), rsync_lines.str()
261-
assert rsync_lines[3].contains('thirdparty/tcc.original/lib/libgc'), rsync_lines.str()
262-
assert rsync_lines[4].contains('thirdparty/tcc.original/lib/build'), rsync_lines.str()
263-
assert rsync_lines[5].contains('thirdparty/tcc.original/README.md'), rsync_lines.str()
264-
assert rsync_lines[6].ends_with('/build.sh'), rsync_lines.str()
262+
assert rsync_lines.len == 8, rsync_lines.str()
263+
assert rsync_lines[0].starts_with('-a --exclude=/.git --exclude=/.git/ thirdparty/tcc/ '), rsync_lines.str()
264+
265+
assert rsync_lines[1].starts_with('-a thirdparty/tcc/ '), rsync_lines.str()
266+
assert rsync_lines[2].starts_with('-a --delete --exclude=/.github/ '), rsync_lines.str()
267+
assert rsync_lines[3].contains('thirdparty/tcc.original/.git/'), rsync_lines.str()
268+
assert rsync_lines[4].contains('thirdparty/tcc.original/lib/libgc'), rsync_lines.str()
269+
assert rsync_lines[5].contains('thirdparty/tcc.original/lib/build'), rsync_lines.str()
270+
assert rsync_lines[6].contains('thirdparty/tcc.original/README.md'), rsync_lines.str()
271+
assert rsync_lines[7].ends_with('/build.sh'), rsync_lines.str()
265272
assert os.execute('${os.quoted_path(os.join_path(tcc_dir, 'tcc.exe'))} --version').output.trim_space() == 'source-test-tcc'
266273
staged_source_workflow := os.join_path(root, 'tinycc', 'thirdparty', 'tcc', '.github',
267274
'workflows', 'preserve.yml')

vlib/v3/driver/driver.v

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,9 +4457,16 @@ fn monomorph_cache_semantic_signature(a &flat.FlatAst, source_files []string) st
44574457
file_ids << idx
44584458
}
44594459
}
4460-
file_ids.sort_with_compare(fn [a] (left &int, right &int) int {
4461-
return a.nodes[*left].value.compare(a.nodes[*right].value)
4462-
})
4460+
// Keep the self-hosting path capture-free so V can be built with `-no-closures`.
4461+
for i in 1 .. file_ids.len {
4462+
value := file_ids[i]
4463+
mut j := i
4464+
for j > 0 && a.nodes[file_ids[j - 1]].value > a.nodes[value].value {
4465+
file_ids[j] = file_ids[j - 1]
4466+
j--
4467+
}
4468+
file_ids[j] = value
4469+
}
44634470
for idx in file_ids {
44644471
hash = c_hash_monomorph_node(hash, a, flat.NodeId(idx), cacheable_strings,
44654472
declaration_attributes)

0 commit comments

Comments
 (0)