| ... | @@ -4376,8 +4376,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -4376,8 +4376,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4376 | if (zcu.intern_pool.isFuncBody(val)) { | 4376 | if (zcu.intern_pool.isFuncBody(val)) { |
| 4377 | const ty: Type = .fromInterned(zcu.intern_pool.typeOf(val)); | 4377 | const ty: Type = .fromInterned(zcu.intern_pool.typeOf(val)); |
| 4378 | if (try ty.fnHasRuntimeBitsSema(pt)) { | 4378 | if (try ty.fnHasRuntimeBitsSema(pt)) { |
| 4379 | try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = val })); | 4379 | const orig_fn_index = zcu.intern_pool.unwrapCoercedFunc(val); |
| 4380 | try zcu.ensureFuncBodyAnalysisQueued(val); | 4380 | try sema.addReferenceEntry(block, src, .wrap(.{ .func = orig_fn_index })); |
| | 4381 | try zcu.ensureFuncBodyAnalysisQueued(orig_fn_index); |
| 4381 | } | 4382 | } |
| 4382 | } | 4383 | } |
| 4383 | | 4384 | |
| ... | @@ -5589,16 +5590,21 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5589,16 +5590,21 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5589 | } | 5590 | } |
| 5590 | | 5591 | |
| 5591 | try sema.ensureMemoizedStateResolved(src, .panic); | 5592 | try sema.ensureMemoizedStateResolved(src, .panic); |
| 5592 | try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.get(.@"panic.call")); | 5593 | const panic_fn_index = zcu.builtin_decl_values.get(.@"panic.call"); |
| 5593 | | | |
| 5594 | const panic_fn = Air.internedToRef(zcu.builtin_decl_values.get(.@"panic.call")); | | |
| 5595 | | | |
| 5596 | const opt_usize_ty = try pt.optionalType(.usize_type); | 5594 | const opt_usize_ty = try pt.optionalType(.usize_type); |
| 5597 | const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{ | 5595 | const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{ |
| 5598 | .ty = opt_usize_ty.toIntern(), | 5596 | .ty = opt_usize_ty.toIntern(), |
| 5599 | .val = .none, | 5597 | .val = .none, |
| 5600 | } }))); | 5598 | } }))); |
| 5601 | try sema.callBuiltin(block, src, panic_fn, .auto, &.{ coerced_msg, null_ret_addr }, .@"@panic"); | 5599 | // `callBuiltin` also calls `addReferenceEntry` to the function body for us. |
| | 5600 | try sema.callBuiltin( |
| | 5601 | block, |
| | 5602 | src, |
| | 5603 | .fromIntern(panic_fn_index), |
| | 5604 | .auto, |
| | 5605 | &.{ coerced_msg, null_ret_addr }, |
| | 5606 | .@"@panic", |
| | 5607 | ); |
| 5602 | } | 5608 | } |
| 5603 | | 5609 | |
| 5604 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5610 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -7567,8 +7573,9 @@ fn analyzeCall( | ... | @@ -7567,8 +7573,9 @@ fn analyzeCall( |
| 7567 | ref_func: { | 7573 | ref_func: { |
| 7568 | const runtime_func_val = try sema.resolveValue(runtime_func) orelse break :ref_func; | 7574 | const runtime_func_val = try sema.resolveValue(runtime_func) orelse break :ref_func; |
| 7569 | if (!ip.isFuncBody(runtime_func_val.toIntern())) break :ref_func; | 7575 | if (!ip.isFuncBody(runtime_func_val.toIntern())) break :ref_func; |
| 7570 | try sema.addReferenceEntry(block, call_src, .wrap(.{ .func = runtime_func_val.toIntern() })); | 7576 | const orig_fn_index = ip.unwrapCoercedFunc(runtime_func_val.toIntern()); |
| 7571 | try zcu.ensureFuncBodyAnalysisQueued(runtime_func_val.toIntern()); | 7577 | try sema.addReferenceEntry(block, call_src, .wrap(.{ .func = orig_fn_index })); |
| | 7578 | try zcu.ensureFuncBodyAnalysisQueued(orig_fn_index); |
| 7572 | } | 7579 | } |
| 7573 | | 7580 | |
| 7574 | const call_tag: Air.Inst.Tag = switch (modifier) { | 7581 | const call_tag: Air.Inst.Tag = switch (modifier) { |
| ... | @@ -26383,23 +26390,27 @@ fn explainWhyTypeIsNotPacked( | ... | @@ -26383,23 +26390,27 @@ fn explainWhyTypeIsNotPacked( |
| 26383 | /// instructions. This function ensures the panic function will be available to | 26390 | /// instructions. This function ensures the panic function will be available to |
| 26384 | /// be called during that time. | 26391 | /// be called during that time. |
| 26385 | fn preparePanicId(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !void { | 26392 | fn preparePanicId(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !void { |
| | 26393 | const zcu = sema.pt.zcu; |
| | 26394 | |
| 26386 | // If the backend doesn't support `.panic_fn`, it doesn't want us to lower the panic handlers. | 26395 | // If the backend doesn't support `.panic_fn`, it doesn't want us to lower the panic handlers. |
| 26387 | // The backend will transform panics into traps instead. | 26396 | // The backend will transform panics into traps instead. |
| 26388 | if (sema.pt.zcu.backendSupportsFeature(.panic_fn)) { | 26397 | if (!zcu.backendSupportsFeature(.panic_fn)) return; |
| 26389 | _ = try sema.getPanicIdFunc(src, panic_id); | 26398 | |
| 26390 | } | 26399 | const fn_index = try sema.getPanicIdFunc(src, panic_id); |
| | 26400 | const orig_fn_index = zcu.intern_pool.unwrapCoercedFunc(fn_index); |
| | 26401 | try sema.addReferenceEntry(null, src, .wrap(.{ .func = orig_fn_index })); |
| | 26402 | try zcu.ensureFuncBodyAnalysisQueued(orig_fn_index); |
| 26391 | } | 26403 | } |
| 26392 | | 26404 | |
| 26393 | fn getPanicIdFunc(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !InternPool.Index { | 26405 | fn getPanicIdFunc(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !InternPool.Index { |
| 26394 | const zcu = sema.pt.zcu; | 26406 | const zcu = sema.pt.zcu; |
| 26395 | try sema.ensureMemoizedStateResolved(src, .panic); | 26407 | try sema.ensureMemoizedStateResolved(src, .panic); |
| 26396 | const panic_func = zcu.builtin_decl_values.get(panic_id.toBuiltin()); | 26408 | const panic_fn_index = zcu.builtin_decl_values.get(panic_id.toBuiltin()); |
| 26397 | try zcu.ensureFuncBodyAnalysisQueued(panic_func); | | |
| 26398 | switch (sema.owner.unwrap()) { | 26409 | switch (sema.owner.unwrap()) { |
| 26399 | .@"comptime", .nav_ty, .nav_val, .type, .memoized_state => {}, | 26410 | .@"comptime", .nav_ty, .nav_val, .type, .memoized_state => {}, |
| 26400 | .func => |owner_func| zcu.intern_pool.funcSetHasErrorTrace(owner_func, true), | 26411 | .func => |owner_func| zcu.intern_pool.funcSetHasErrorTrace(owner_func, true), |
| 26401 | } | 26412 | } |
| 26402 | return panic_func; | 26413 | return panic_fn_index; |
| 26403 | } | 26414 | } |
| 26404 | | 26415 | |
| 26405 | fn addSafetyCheck( | 26416 | fn addSafetyCheck( |
| ... | @@ -31143,6 +31154,11 @@ fn addReferenceEntry( | ... | @@ -31143,6 +31154,11 @@ fn addReferenceEntry( |
| 31143 | referenced_unit: AnalUnit, | 31154 | referenced_unit: AnalUnit, |
| 31144 | ) !void { | 31155 | ) !void { |
| 31145 | const zcu = sema.pt.zcu; | 31156 | const zcu = sema.pt.zcu; |
| | 31157 | const ip = &zcu.intern_pool; |
| | 31158 | switch (referenced_unit.unwrap()) { |
| | 31159 | .func => |f| assert(ip.unwrapCoercedFunc(f) == f), // for `.{ .func = f }`, `f` must be uncoerced |
| | 31160 | else => {}, |
| | 31161 | } |
| 31146 | if (!zcu.comp.incremental and zcu.comp.reference_trace == 0) return; | 31162 | if (!zcu.comp.incremental and zcu.comp.reference_trace == 0) return; |
| 31147 | const gop = try sema.references.getOrPut(sema.gpa, referenced_unit); | 31163 | const gop = try sema.references.getOrPut(sema.gpa, referenced_unit); |
| 31148 | if (gop.found_existing) return; | 31164 | if (gop.found_existing) return; |
| ... | @@ -31329,8 +31345,9 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, block: *Block, src: LazySrcLoc, nav_i | ... | @@ -31329,8 +31345,9 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, block: *Block, src: LazySrcLoc, nav_i |
| 31329 | const nav_val = zcu.navValue(nav_index); | 31345 | const nav_val = zcu.navValue(nav_index); |
| 31330 | if (!ip.isFuncBody(nav_val.toIntern())) return; | 31346 | if (!ip.isFuncBody(nav_val.toIntern())) return; |
| 31331 | | 31347 | |
| 31332 | try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = nav_val.toIntern() })); | 31348 | const orig_fn_index = ip.unwrapCoercedFunc(nav_val.toIntern()); |
| 31333 | try zcu.ensureFuncBodyAnalysisQueued(nav_val.toIntern()); | 31349 | try sema.addReferenceEntry(block, src, .wrap(.{ .func = orig_fn_index })); |
| | 31350 | try zcu.ensureFuncBodyAnalysisQueued(orig_fn_index); |
| 31334 | } | 31351 | } |
| 31335 | | 31352 | |
| 31336 | fn analyzeRef( | 31353 | fn analyzeRef( |
| ... | @@ -34963,8 +34980,9 @@ fn resolveInferredErrorSet( | ... | @@ -34963,8 +34980,9 @@ fn resolveInferredErrorSet( |
| 34963 | } | 34980 | } |
| 34964 | // In this case we are dealing with the actual InferredErrorSet object that | 34981 | // In this case we are dealing with the actual InferredErrorSet object that |
| 34965 | // corresponds to the function, not one created to track an inline/comptime call. | 34982 | // corresponds to the function, not one created to track an inline/comptime call. |
| 34966 | try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = func_index })); | 34983 | const orig_func_index = ip.unwrapCoercedFunc(func_index); |
| 34967 | try pt.ensureFuncBodyUpToDate(func_index); | 34984 | try sema.addReferenceEntry(block, src, .wrap(.{ .func = orig_func_index })); |
| | 34985 | try pt.ensureFuncBodyUpToDate(orig_func_index); |
| 34968 | } | 34986 | } |
| 34969 | | 34987 | |
| 34970 | // This will now have been resolved by the logic at the end of `Zcu.analyzeFnBody` | 34988 | // This will now have been resolved by the logic at the end of `Zcu.analyzeFnBody` |