Skip to content

Commit c2b03d7

Browse files
committed
Merge branch 'master' into loongarch64
2 parents e3ff592 + 3ce8d19 commit c2b03d7

File tree

11 files changed

+55
-66
lines changed

11 files changed

+55
-66
lines changed

lib/init/build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
2929
// to our consumers. We must give it a name because a Zig package can expose
3030
// multiple modules and consumers will need to be able to specify which
3131
// module they want to access.
32-
const mod = b.addModule(".NAME", .{
32+
const mod = b.addModule("_NAME", .{
3333
// The root source file is the "entry point" of this module. Users of
3434
// this module will only be able to access public declarations contained
3535
// in this file, which means that if you have declarations that you
@@ -59,7 +59,7 @@ pub fn build(b: *std.Build) void {
5959
// If neither case applies to you, feel free to delete the declaration you
6060
// don't need and to put everything under a single module.
6161
const exe = b.addExecutable(.{
62-
.name = ".NAME",
62+
.name = "_NAME",
6363
.root_module = b.createModule(.{
6464
// b.createModule defines a new module just like b.addModule but,
6565
// unlike b.addModule, it does not expose the module to consumers of
@@ -74,12 +74,12 @@ pub fn build(b: *std.Build) void {
7474
// List of modules available for import in source files part of the
7575
// root module.
7676
.imports = &.{
77-
// Here ".NAME" is the name you will use in your source code to
78-
// import this module (e.g. `@import(".NAME")`). The name is
77+
// Here "_NAME" is the name you will use in your source code to
78+
// import this module (e.g. `@import("_NAME")`). The name is
7979
// repeated because you are allowed to rename your imports, which
8080
// can be extremely useful in case of collisions (which can happen
8181
// importing modules from different packages).
82-
.{ .name = ".NAME", .module = mod },
82+
.{ .name = "_NAME", .module = mod },
8383
},
8484
}),
8585
});

lib/init/build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = .LITNAME,
9+
.name = ._NAME,
1010
// This is a [Semantic Version](https://semver.org/).
1111
// In a future version of Zig it will be used for package deduplication.
1212
.version = "0.0.0",
@@ -25,7 +25,7 @@
2525
.fingerprint = .FINGERPRINT, // Changing this has security and trust implications.
2626
// Tracks the earliest Zig version that the package considers to be a
2727
// supported use case.
28-
.minimum_zig_version = ".ZIGVER",
28+
.minimum_zig_version = "_ZIGVER",
2929
// This field is optional.
3030
// Each dependency must either provide a `url` and `hash`, or a `path`.
3131
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.

lib/init/src/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const std = @import("std");
2-
const _LITNAME = @import(".NAME");
2+
const _NAME = @import(".NAME");
33

44
pub fn main() !void {
55
// Prints to stderr, ignoring potential errors.
66
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
7-
try .NAME.advancedPrint();
7+
try _NAME.bufferedPrint();
88
}
99

1010
test "simple test" {

lib/init/src/root.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! By convention, root.zig is the root source file when making a library.
22
const std = @import("std");
33

4-
pub fn advancedPrint() !void {
4+
pub fn bufferedPrint() !void {
55
// Stdout is for the actual output of your application, for example if you
66
// are implementing gzip, then only the compressed bytes should be sent to
77
// stdout, not any debugging messages.
88
const stdout_file = std.io.getStdOut().writer();
9+
// Buffering can improve performance significantly in print-heavy programs.
910
var bw = std.io.bufferedWriter(stdout_file);
1011
const stdout = bw.writer();
1112

lib/std/zig/Parse.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,9 +2774,9 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index {
27742774
else => {
27752775
const main_token = p.nextToken();
27762776
const period = p.eatToken(.period);
2777-
if (period == null) try p.warnExpected(.period);
2777+
if (period == null) return p.failExpected(.period);
27782778
const identifier = p.eatToken(.identifier);
2779-
if (identifier == null) try p.warnExpected(.identifier);
2779+
if (identifier == null) return p.failExpected(.identifier);
27802780
return try p.addNode(.{
27812781
.tag = .error_value,
27822782
.main_token = main_token,

lib/std/zig/llvm/ir.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ pub const MetadataBlock = struct {
10641064
pub const Subrange = struct {
10651065
pub const ops = [_]AbbrevOp{
10661066
.{ .literal = @intFromEnum(MetadataCode.SUBRANGE) },
1067-
.{ .literal = 0b10 }, // is distinct | version
1067+
.{ .literal = 0 | (2 << 1) }, // is distinct | version
10681068
MetadataAbbrev, // count
10691069
MetadataAbbrev, // lower bound
10701070
.{ .literal = 0 }, // upper bound

lib/std/zig/parser_test.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6280,7 +6280,6 @@ test "recovery: invalid global error set access" {
62806280
\\}
62816281
, &[_]Error{
62826282
.expected_token,
6283-
.expected_token,
62846283
});
62856284
}
62866285

src/Zcu/PerThread.zig

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,34 +4373,29 @@ pub fn addDependency(pt: Zcu.PerThread, unit: AnalUnit, dependee: InternPool.Dep
43734373
/// codegen thread, depending on whether the backend supports `Zcu.Feature.separate_thread`.
43744374
pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, out: *@import("../link.zig").ZcuTask.LinkFunc.SharedMir) void {
43754375
const zcu = pt.zcu;
4376-
if (runCodegenInner(pt, func_index, air)) |mir| {
4376+
const success: bool = if (runCodegenInner(pt, func_index, air)) |mir| success: {
43774377
out.value = mir;
4378-
out.status.store(.ready, .release);
4379-
} else |err| switch (err) {
4380-
error.OutOfMemory => {
4381-
zcu.comp.setAllocFailure();
4382-
out.status.store(.failed, .monotonic);
4383-
},
4384-
error.CodegenFail => {
4385-
zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav);
4386-
out.status.store(.failed, .monotonic);
4387-
},
4388-
error.NoLinkFile => {
4389-
assert(zcu.comp.bin_file == null);
4390-
out.status.store(.failed, .monotonic);
4391-
},
4392-
error.BackendDoesNotProduceMir => {
4393-
const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);
4394-
switch (backend) {
4378+
break :success true;
4379+
} else |err| success: {
4380+
switch (err) {
4381+
error.OutOfMemory => zcu.comp.setAllocFailure(),
4382+
error.CodegenFail => zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav),
4383+
error.NoLinkFile => assert(zcu.comp.bin_file == null),
4384+
error.BackendDoesNotProduceMir => switch (target_util.zigBackend(
4385+
zcu.root_mod.resolved_target.result,
4386+
zcu.comp.config.use_llvm,
4387+
)) {
43954388
else => unreachable, // assertion failure
43964389
.stage2_spirv64,
43974390
.stage2_llvm,
43984391
=> {},
4399-
}
4400-
out.status.store(.failed, .monotonic);
4401-
},
4402-
}
4403-
zcu.comp.link_task_queue.mirReady(zcu.comp, out);
4392+
},
4393+
}
4394+
break :success false;
4395+
};
4396+
// release `out.value` with this store; synchronizes with acquire loads in `link`
4397+
out.status.store(if (success) .ready else .failed, .release);
4398+
zcu.comp.link_task_queue.mirReady(zcu.comp, func_index, out);
44044399
if (zcu.pending_codegen_jobs.rmw(.Sub, 1, .monotonic) == 1) {
44054400
// Decremented to 0, so all done.
44064401
zcu.codegen_prog_node.end();

src/link.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ pub const ZcuTask = union(enum) {
12491249
.update_line_number,
12501250
=> {},
12511251
.link_func => |link_func| {
1252-
switch (link_func.mir.status.load(.monotonic)) {
1252+
switch (link_func.mir.status.load(.acquire)) {
12531253
.pending => unreachable, // cannot deinit until MIR done
12541254
.failed => {}, // MIR not populated so doesn't need freeing
12551255
.ready => link_func.mir.value.deinit(zcu),
@@ -1453,7 +1453,7 @@ pub fn doZcuTask(comp: *Compilation, tid: usize, task: ZcuTask) void {
14531453
const fqn_slice = ip.getNav(nav).fqn.toSlice(ip);
14541454
const nav_prog_node = comp.link_prog_node.start(fqn_slice, 0);
14551455
defer nav_prog_node.end();
1456-
switch (func.mir.status.load(.monotonic)) {
1456+
switch (func.mir.status.load(.acquire)) {
14571457
.pending => unreachable,
14581458
.ready => {},
14591459
.failed => return,

src/link/Queue.zig

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ state: union(enum) {
6464
finished,
6565
/// The link thread is not running or queued, because it is waiting for this MIR to be populated.
6666
/// Once codegen completes, it must call `mirReady` which will restart the link thread.
67-
wait_for_mir: *ZcuTask.LinkFunc.SharedMir,
67+
wait_for_mir: InternPool.Index,
6868
},
6969

7070
/// In the worst observed case, MIR is around 50 times as large as AIR. More typically, the ratio is
@@ -113,20 +113,20 @@ pub fn start(q: *Queue, comp: *Compilation) void {
113113

114114
/// Called by codegen workers after they have populated a `ZcuTask.LinkFunc.SharedMir`. If the link
115115
/// thread was waiting for this MIR, it can resume.
116-
pub fn mirReady(q: *Queue, comp: *Compilation, mir: *ZcuTask.LinkFunc.SharedMir) void {
116+
pub fn mirReady(q: *Queue, comp: *Compilation, func_index: InternPool.Index, mir: *ZcuTask.LinkFunc.SharedMir) void {
117117
// We would like to assert that `mir` is not pending, but that would race with a worker thread
118118
// potentially freeing it.
119119
{
120120
q.mutex.lock();
121121
defer q.mutex.unlock();
122122
switch (q.state) {
123123
.finished, .running => return,
124-
.wait_for_mir => |wait_for| if (wait_for != mir) return,
124+
.wait_for_mir => |wait_for| if (wait_for != func_index) return,
125125
}
126126
// We were waiting for `mir`, so we will restart the linker thread.
127127
q.state = .running;
128128
}
129-
assert(mir.status.load(.monotonic) != .pending);
129+
assert(mir.status.load(.acquire) != .pending);
130130
comp.thread_pool.spawnWgId(&comp.link_task_wait_group, flushTaskQueue, .{ q, comp });
131131
}
132132

@@ -170,8 +170,8 @@ pub fn enqueueZcu(q: *Queue, comp: *Compilation, task: ZcuTask) Allocator.Error!
170170
.finished => if (q.pending_prelink_tasks != 0) return,
171171
}
172172
// Restart the linker thread, unless it would immediately be blocked
173-
if (task == .link_func and task.link_func.mir.status.load(.monotonic) == .pending) {
174-
q.state = .{ .wait_for_mir = task.link_func.mir };
173+
if (task == .link_func and task.link_func.mir.status.load(.acquire) == .pending) {
174+
q.state = .{ .wait_for_mir = task.link_func.func };
175175
return;
176176
}
177177
q.state = .running;
@@ -243,12 +243,12 @@ fn flushTaskQueue(tid: usize, q: *Queue, comp: *Compilation) void {
243243
if (task != .link_func) break :pending;
244244
const status_ptr = &task.link_func.mir.status;
245245
// First check without the mutex to optimize for the common case where MIR is ready.
246-
if (status_ptr.load(.monotonic) != .pending) break :pending;
246+
if (status_ptr.load(.acquire) != .pending) break :pending;
247247
q.mutex.lock();
248248
defer q.mutex.unlock();
249-
if (status_ptr.load(.monotonic) != .pending) break :pending;
249+
if (status_ptr.load(.acquire) != .pending) break :pending;
250250
// We will stop for now, and get restarted once this MIR is ready.
251-
q.state = .{ .wait_for_mir = task.link_func.mir };
251+
q.state = .{ .wait_for_mir = task.link_func.func };
252252
q.flush_safety.unlock();
253253
return;
254254
}
@@ -273,6 +273,7 @@ const std = @import("std");
273273
const assert = std.debug.assert;
274274
const Allocator = std.mem.Allocator;
275275
const Compilation = @import("../Compilation.zig");
276+
const InternPool = @import("../InternPool.zig");
276277
const link = @import("../link.zig");
277278
const PrelinkTask = link.PrelinkTask;
278279
const ZcuTask = link.ZcuTask;

src/main.zig

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7290,34 +7290,27 @@ const Templates = struct {
72907290
new_line = false;
72917291
}
72927292
}
7293+
72937294
if (templates.strip and contents[i] == '\n') {
72947295
new_line = true;
7295-
} else if (contents[i] == '_') {
7296-
if (std.mem.startsWith(u8, contents[i..], "_LITNAME")) {
7297-
try templates.buffer.appendSlice(root_name);
7298-
i += "_LITNAME".len;
7299-
continue;
7300-
}
7301-
} else if (contents[i] == '.') {
7302-
if (std.mem.startsWith(u8, contents[i..], ".LITNAME")) {
7303-
try templates.buffer.append('.');
7296+
} else if (contents[i] == '_' or contents[i] == '.') {
7297+
// Both '_' and '.' are allowed because depending on the context
7298+
// one prefix will be valid, while the other might not.
7299+
if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) {
73047300
try templates.buffer.appendSlice(root_name);
7305-
i += ".LITNAME".len;
7301+
i += "_NAME".len;
73067302
continue;
7307-
} else if (std.mem.startsWith(u8, contents[i..], ".NAME")) {
7308-
try templates.buffer.appendSlice(root_name);
7309-
i += ".NAME".len;
7310-
continue;
7311-
} else if (std.mem.startsWith(u8, contents[i..], ".FINGERPRINT")) {
7303+
} else if (std.mem.startsWith(u8, contents[i + 1 ..], "FINGERPRINT")) {
73127304
try templates.buffer.writer().print("0x{x}", .{fingerprint.int()});
7313-
i += ".FINGERPRINT".len;
7305+
i += "_FINGERPRINT".len;
73147306
continue;
7315-
} else if (std.mem.startsWith(u8, contents[i..], ".ZIGVER")) {
7307+
} else if (std.mem.startsWith(u8, contents[i + 1 ..], "ZIGVER")) {
73167308
try templates.buffer.appendSlice(build_options.version);
7317-
i += ".ZIGVER".len;
7309+
i += "_ZIGVER".len;
73187310
continue;
73197311
}
73207312
}
7313+
73217314
try templates.buffer.append(contents[i]);
73227315
i += 1;
73237316
}

0 commit comments

Comments
 (0)