aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-06-02 18:49:40 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:59 -0700
commite23b0a01e6357252eb2c08a83eff9169ce49042c (patch)
tree86742fd9ad29116eddc61c1e093ae8155a435fb4 /src/Module.zig
parent6a15fc87ad62ec0509017c960f6983ce1493c31d (diff)
downloadzig-e23b0a01e6357252eb2c08a83eff9169ce49042c.tar.gz
zig-e23b0a01e6357252eb2c08a83eff9169ce49042c.zip
InternPool: fix yet more key lifetime issues
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 9d58029cb5..c1d6b8157a 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5448,7 +5448,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
defer comptime_mutable_decls.deinit();
const fn_ty = decl.ty;
- const fn_ty_info = mod.typeToFunc(fn_ty).?;
var sema: Sema = .{
.mod = mod,
@@ -5459,7 +5458,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
.owner_decl_index = decl_index,
.func = func,
.func_index = func_index.toOptional(),
- .fn_ret_ty = fn_ty_info.return_type.toType(),
+ .fn_ret_ty = mod.typeToFunc(fn_ty).?.return_type.toType(),
.owner_func = func,
.owner_func_index = func_index.toOptional(),
.branch_quota = @max(func.branch_quota, Sema.default_branch_quota),
@@ -5499,7 +5498,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
// This could be a generic function instantiation, however, in which case we need to
// map the comptime parameters to constant values and only emit arg AIR instructions
// for the runtime ones.
- const runtime_params_len = @intCast(u32, fn_ty_info.param_types.len);
+ const runtime_params_len = @intCast(u32, mod.typeToFunc(fn_ty).?.param_types.len);
try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len);
try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType`
try sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body);
@@ -5525,7 +5524,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
sema.inst_map.putAssumeCapacityNoClobber(inst, arg);
total_param_index += 1;
continue;
- } else fn_ty_info.param_types[runtime_param_index].toType();
+ } else mod.typeToFunc(fn_ty).?.param_types[runtime_param_index].toType();
const opt_opv = sema.typeHasOnePossibleValue(param_ty) catch |err| switch (err) {
error.NeededSourceLocation => unreachable,
@@ -5623,7 +5622,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
// Crucially, this happens *after* we set the function state to success above,
// so that dependencies on the function body will now be satisfied rather than
// result in circular dependency errors.
- sema.resolveFnTypes(mod.typeToFunc(fn_ty).?) catch |err| switch (err) {
+ sema.resolveFnTypes(fn_ty) catch |err| switch (err) {
error.NeededSourceLocation => unreachable,
error.GenericPoison => unreachable,
error.ComptimeReturn => unreachable,
@@ -6378,9 +6377,9 @@ pub fn populateTestFunctions(
for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {
const test_decl = mod.declPtr(test_decl_index);
- // Protects test_decl_name from being invalidated during call to intern() below.
- try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(test_decl.name).len + 10);
- const test_decl_name = ip.stringToSlice(test_decl.name);
+ // TODO: write something like getCoercedInts to avoid needing to dupe
+ const test_decl_name = try gpa.dupe(u8, ip.stringToSlice(test_decl.name));
+ defer gpa.free(test_decl_name);
const test_name_decl_index = n: {
const test_name_decl_ty = try mod.arrayType(.{
.len = test_decl_name.len,