aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/std/Target.zig3
-rw-r--r--lib/std/enums.zig3
-rw-r--r--lib/std/fmt.zig3
-rw-r--r--lib/std/meta.zig6
-rw-r--r--lib/std/unicode.zig3
-rw-r--r--lib/std/zig/AstGen.zig30
-rw-r--r--lib/std/zig/Zir.zig12
7 files changed, 41 insertions, 19 deletions
diff --git a/lib/std/Target.zig b/lib/std/Target.zig
index 4f616eefd2..842442e37b 100644
--- a/lib/std/Target.zig
+++ b/lib/std/Target.zig
@@ -1317,7 +1317,8 @@ pub const Cpu = struct {
for (decls, 0..) |decl, i| {
array[i] = &@field(cpus, decl.name);
}
- return &array;
+ const finalized = array;
+ return &finalized;
}
};
diff --git a/lib/std/enums.zig b/lib/std/enums.zig
index 79c69c8510..c00bf52aa6 100644
--- a/lib/std/enums.zig
+++ b/lib/std/enums.zig
@@ -41,7 +41,8 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi
for (&result, fields) |*r, f| {
r.* = @enumFromInt(f.value);
}
- return &result;
+ const final = result;
+ return &final;
}
}
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
index df8397fb93..37c9f77fec 100644
--- a/lib/std/fmt.zig
+++ b/lib/std/fmt.zig
@@ -1829,7 +1829,8 @@ pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [cou
var buf: [count(fmt, args):0]u8 = undefined;
_ = bufPrint(&buf, fmt, args) catch unreachable;
buf[buf.len] = 0;
- return &buf;
+ const final = buf;
+ return &final;
}
}
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index da0f629748..3ad2c2de13 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -465,7 +465,8 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
var names: [fieldInfos.len][:0]const u8 = undefined;
// This concat can be removed with the next zig1 update.
for (&names, fieldInfos) |*name, field| name.* = field.name ++ "";
- break :blk &names;
+ const final = names;
+ break :blk &final;
};
}
@@ -506,7 +507,8 @@ pub fn tags(comptime T: type) *const [fields(T).len]T {
for (fieldInfos, 0..) |field, i| {
res[i] = @field(T, field.name);
}
- break :blk &res;
+ const final = res;
+ break :blk &final;
};
}
diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig
index 8a26c3383e..9d1f52fb2d 100644
--- a/lib/std/unicode.zig
+++ b/lib/std/unicode.zig
@@ -1358,7 +1358,8 @@ pub fn utf8ToUtf16LeStringLiteral(comptime utf8: []const u8) *const [calcUtf16Le
var utf16le: [len:0]u16 = [_:0]u16{0} ** len;
const utf16le_len = utf8ToUtf16Le(&utf16le, utf8[0..]) catch |err| @compileError(err);
assert(len == utf16le_len);
- break :blk &utf16le;
+ const final = utf16le;
+ break :blk &final;
};
}
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig
index 1bbfc2001e..2cab0fe7ca 100644
--- a/lib/std/zig/AstGen.zig
+++ b/lib/std/zig/AstGen.zig
@@ -8296,22 +8296,27 @@ fn localVarRef(
});
}
- const ptr_inst = if (num_namespaces_out != 0) try tunnelThroughClosure(
- gz,
- ident,
- num_namespaces_out,
- .{ .ref = local_ptr.ptr },
- .{ .token = local_ptr.token_src },
- ) else local_ptr.ptr;
-
switch (ri.rl) {
.ref, .ref_coerced_ty => {
+ const ptr_inst = if (num_namespaces_out != 0) try tunnelThroughClosure(
+ gz,
+ ident,
+ num_namespaces_out,
+ .{ .ref = local_ptr.ptr },
+ .{ .token = local_ptr.token_src },
+ ) else local_ptr.ptr;
local_ptr.used_as_lvalue = true;
return ptr_inst;
},
else => {
- const loaded = try gz.addUnNode(.load, ptr_inst, ident);
- return rvalueNoCoercePreRef(gz, ri, loaded, ident);
+ const val_inst = if (num_namespaces_out != 0) try tunnelThroughClosure(
+ gz,
+ ident,
+ num_namespaces_out,
+ .{ .ref_load = local_ptr.ptr },
+ .{ .token = local_ptr.token_src },
+ ) else try gz.addUnNode(.load, local_ptr.ptr, ident);
+ return rvalueNoCoercePreRef(gz, ri, val_inst, ident);
},
}
}
@@ -8390,6 +8395,7 @@ fn tunnelThroughClosure(
/// The value being captured.
value: union(enum) {
ref: Zir.Inst.Ref,
+ ref_load: Zir.Inst.Ref,
decl_val: Zir.NullTerminatedString,
decl_ref: Zir.NullTerminatedString,
},
@@ -8400,7 +8406,8 @@ fn tunnelThroughClosure(
},
) !Zir.Inst.Ref {
switch (value) {
- .ref => |v| if (v.toIndex() == null) return v, // trivia value; do not need tunnel
+ .ref => |v| if (v.toIndex() == null) return v, // trivial value; do not need tunnel
+ .ref_load => |v| assert(v.toIndex() != null), // there are no constant pointer refs
.decl_val, .decl_ref => {},
}
@@ -8433,6 +8440,7 @@ fn tunnelThroughClosure(
// captures as required, starting with the outermost namespace.
const root_capture = Zir.Inst.Capture.wrap(switch (value) {
.ref => |v| .{ .instruction = v.toIndex().? },
+ .ref_load => |v| .{ .instruction_load = v.toIndex().? },
.decl_val => |str| .{ .decl_val = str },
.decl_ref => |str| .{ .decl_ref = str },
});
diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig
index f196155a1f..8aa4c0c8c5 100644
--- a/lib/std/zig/Zir.zig
+++ b/lib/std/zig/Zir.zig
@@ -3058,20 +3058,23 @@ pub const Inst = struct {
/// Represents a single value being captured in a type declaration's closure.
pub const Capture = packed struct(u32) {
- tag: enum(u2) {
+ tag: enum(u3) {
/// `data` is a `u16` index into the parent closure.
nested,
/// `data` is a `Zir.Inst.Index` to an instruction whose value is being captured.
instruction,
+ /// `data` is a `Zir.Inst.Index` to an instruction representing an alloc whose contents is being captured.
+ instruction_load,
/// `data` is a `NullTerminatedString` to a decl name.
decl_val,
/// `data` is a `NullTerminatedString` to a decl name.
decl_ref,
},
- data: u30,
+ data: u29,
pub const Unwrapped = union(enum) {
nested: u16,
instruction: Zir.Inst.Index,
+ instruction_load: Zir.Inst.Index,
decl_val: NullTerminatedString,
decl_ref: NullTerminatedString,
};
@@ -3085,6 +3088,10 @@ pub const Inst = struct {
.tag = .instruction,
.data = @intCast(@intFromEnum(inst)),
},
+ .instruction_load => |inst| .{
+ .tag = .instruction_load,
+ .data = @intCast(@intFromEnum(inst)),
+ },
.decl_val => |str| .{
.tag = .decl_val,
.data = @intCast(@intFromEnum(str)),
@@ -3099,6 +3106,7 @@ pub const Inst = struct {
return switch (cap.tag) {
.nested => .{ .nested = @intCast(cap.data) },
.instruction => .{ .instruction = @enumFromInt(cap.data) },
+ .instruction_load => .{ .instruction_load = @enumFromInt(cap.data) },
.decl_val => .{ .decl_val = @enumFromInt(cap.data) },
.decl_ref => .{ .decl_ref = @enumFromInt(cap.data) },
};