authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-17 17:47:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log3f2a4720b1ef057215c8240b3a377c523ee63e94
treeafd14ff8780da15e9b240dc2612d86083b49a81a
parentb03d34429d059dc3f6056d7f780dc623c96523b4

compiler: fix branch regressions

* getOwnedFunctionIndex no longer checks if the value is actually a function. * The callsites to `intern` that I added want to avoid the `getCoerced` call, so I added `intern2`. * Adding to inferred error sets should not happen if the destination error set is not the inferred error set of the current Sema instance. * adhoc_inferred_error_set_type can be seen by the backend. Treat it like anyerror.

5 files changed, 12 insertions(+), 6 deletions(-)

src/Module.zig+2-1
......@@ -751,6 +751,7 @@ pub const Decl = struct {
751751 };
752752 }
753753
754 /// This returns an InternPool.Index even when the value is not a function.
754755 pub fn getOwnedFunctionIndex(decl: Decl) InternPool.Index {
755756 return if (decl.owns_tv) decl.val.toIntern() else .none;
756757 }
......@@ -4978,7 +4979,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
49784979 decl.has_align = has_align;
49794980 decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
49804981 decl.zir_decl_index = @as(u32, @intCast(decl_sub_index));
4981 if (decl.getOwnedFunctionIndex() != .none) {
4982 if (decl.getOwnedFunction(mod) != null) {
49824983 switch (comp.bin_file.tag) {
49834984 .coff, .elf, .macho, .plan9 => {
49844985 // TODO Look into detecting when this would be unnecessary by storing enough state
src/Sema.zig+3-3
......@@ -7140,7 +7140,7 @@ fn analyzeCall(
71407140
71417141 if (should_memoize and is_comptime_call) {
71427142 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, "");
7143 const result_interned = try result_val.intern(sema.fn_ret_ty, mod);
7143 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
71447144
71457145 // Transform ad-hoc inferred error set types into concrete error sets.
71467146 const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
......@@ -7157,7 +7157,7 @@ fn analyzeCall(
71577157 }
71587158
71597159 if (try sema.resolveMaybeUndefVal(result)) |result_val| {
7160 const result_interned = try result_val.intern(sema.fn_ret_ty, mod);
7160 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
71617161 const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
71627162 break :res2 Air.internedToRef(result_transformed);
71637163 }
......@@ -18319,7 +18319,7 @@ fn analyzeRet(
1831918319 // add the error tag to the inferred error set of the in-scope function, so
1832018320 // that the coercion below works correctly.
1832118321 const mod = sema.mod;
18322 if (sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion) {
18322 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion) {
1832318323 try sema.addToInferredErrorSet(uncasted_operand);
1832418324 }
1832518325 const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, src, .{ .is_ret = true }) catch |err| switch (err) {
src/link/Coff.zig+1-1
......@@ -1424,7 +1424,7 @@ pub fn updateDeclExports(
14241424 // detect the default subsystem.
14251425 for (exports) |exp| {
14261426 const exported_decl = mod.declPtr(exp.exported_decl);
1427 if (exported_decl.getOwnedFunctionIndex() == .none) continue;
1427 if (exported_decl.getOwnedFunction(mod) == null) continue;
14281428 const winapi_cc = switch (self.base.options.target.cpu.arch) {
14291429 .x86 => std.builtin.CallingConvention.Stdcall,
14301430 else => std.builtin.CallingConvention.C,
src/type.zig+1-1
......@@ -2238,7 +2238,7 @@ pub const Type = struct {
22382238 var ty = starting_ty;
22392239
22402240 while (true) switch (ty.toIntern()) {
2241 .anyerror_type => {
2241 .anyerror_type, .adhoc_inferred_error_set_type => {
22422242 // TODO revisit this when error sets support custom int types
22432243 return .{ .signedness = .unsigned, .bits = 16 };
22442244 },
src/value.zig+5
......@@ -262,6 +262,11 @@ pub const Value = struct {
262262 return ip.getOrPutTrailingString(gpa, len);
263263 }
264264
265 pub fn intern2(val: Value, ty: Type, mod: *Module) Allocator.Error!InternPool.Index {
266 if (val.ip_index != .none) return val.ip_index;
267 return intern(val, ty, mod);
268 }
269
265270 pub fn intern(val: Value, ty: Type, mod: *Module) Allocator.Error!InternPool.Index {
266271 if (val.ip_index != .none) return (try mod.getCoerced(val, ty)).toIntern();
267272 switch (val.tag()) {