| author | |
| committer | |
| log | 3f2a4720b1ef057215c8240b3a377c523ee63e94 |
| tree | afd14ff8780da15e9b240dc2612d86083b49a81a |
| parent | b03d34429d059dc3f6056d7f780dc623c96523b4 |
* 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 { |
| 751 | 751 | }; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | /// This returns an InternPool.Index even when the value is not a function. | |
| 754 | 755 | pub fn getOwnedFunctionIndex(decl: Decl) InternPool.Index { |
| 755 | 756 | return if (decl.owns_tv) decl.val.toIntern() else .none; |
| 756 | 757 | } |
| ... | ... | @@ -4978,7 +4979,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 4978 | 4979 | decl.has_align = has_align; |
| 4979 | 4980 | decl.has_linksection_or_addrspace = has_linksection_or_addrspace; |
| 4980 | 4981 | decl.zir_decl_index = @as(u32, @intCast(decl_sub_index)); |
| 4981 | if (decl.getOwnedFunctionIndex() != .none) { | |
| 4982 | if (decl.getOwnedFunction(mod) != null) { | |
| 4982 | 4983 | switch (comp.bin_file.tag) { |
| 4983 | 4984 | .coff, .elf, .macho, .plan9 => { |
| 4984 | 4985 | // TODO Look into detecting when this would be unnecessary by storing enough state |
src/Sema.zig+3-3| ... | ... | @@ -7140,7 +7140,7 @@ fn analyzeCall( |
| 7140 | 7140 | |
| 7141 | 7141 | if (should_memoize and is_comptime_call) { |
| 7142 | 7142 | 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); | |
| 7144 | 7144 | |
| 7145 | 7145 | // Transform ad-hoc inferred error set types into concrete error sets. |
| 7146 | 7146 | const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned); |
| ... | ... | @@ -7157,7 +7157,7 @@ fn analyzeCall( |
| 7157 | 7157 | } |
| 7158 | 7158 | |
| 7159 | 7159 | 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); | |
| 7161 | 7161 | const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned); |
| 7162 | 7162 | break :res2 Air.internedToRef(result_transformed); |
| 7163 | 7163 | } |
| ... | ... | @@ -18319,7 +18319,7 @@ fn analyzeRet( |
| 18319 | 18319 | // add the error tag to the inferred error set of the in-scope function, so |
| 18320 | 18320 | // that the coercion below works correctly. |
| 18321 | 18321 | 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) { | |
| 18323 | 18323 | try sema.addToInferredErrorSet(uncasted_operand); |
| 18324 | 18324 | } |
| 18325 | 18325 | 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( |
| 1424 | 1424 | // detect the default subsystem. |
| 1425 | 1425 | for (exports) |exp| { |
| 1426 | 1426 | const exported_decl = mod.declPtr(exp.exported_decl); |
| 1427 | if (exported_decl.getOwnedFunctionIndex() == .none) continue; | |
| 1427 | if (exported_decl.getOwnedFunction(mod) == null) continue; | |
| 1428 | 1428 | const winapi_cc = switch (self.base.options.target.cpu.arch) { |
| 1429 | 1429 | .x86 => std.builtin.CallingConvention.Stdcall, |
| 1430 | 1430 | else => std.builtin.CallingConvention.C, |
src/type.zig+1-1| ... | ... | @@ -2238,7 +2238,7 @@ pub const Type = struct { |
| 2238 | 2238 | var ty = starting_ty; |
| 2239 | 2239 | |
| 2240 | 2240 | while (true) switch (ty.toIntern()) { |
| 2241 | .anyerror_type => { | |
| 2241 | .anyerror_type, .adhoc_inferred_error_set_type => { | |
| 2242 | 2242 | // TODO revisit this when error sets support custom int types |
| 2243 | 2243 | return .{ .signedness = .unsigned, .bits = 16 }; |
| 2244 | 2244 | }, |
src/value.zig+5| ... | ... | @@ -262,6 +262,11 @@ pub const Value = struct { |
| 262 | 262 | return ip.getOrPutTrailingString(gpa, len); |
| 263 | 263 | } |
| 264 | 264 | |
| 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 | ||
| 265 | 270 | pub fn intern(val: Value, ty: Type, mod: *Module) Allocator.Error!InternPool.Index { |
| 266 | 271 | if (val.ip_index != .none) return (try mod.getCoerced(val, ty)).toIntern(); |
| 267 | 272 | switch (val.tag()) { |