authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-18 06:28:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-18 16:41:54-07:00
logc9858f833c2e1d5ef414af7e01d465baa88ef9cc
tree1abc39e35044723c47f1c5a566bfaa545ac9703f
parentb75d86027d589be632a831ec55565230818dc4ef

stage2: fix building stage3 in release mode

Previously, comptime function calls could cause a crash in the hash function due to a lazy value depending on an unresolved type.

2 files changed, 30 insertions(+), 3 deletions(-)

src/Module.zig+1-1
......@@ -205,7 +205,7 @@ pub const MemoizedCall = struct {
205205
206206 // The generic function Decl is guaranteed to be the first dependency
207207 // of each of its instantiations.
208 std.hash.autoHash(&hasher, @ptrToInt(key.func));
208 std.hash.autoHash(&hasher, key.func);
209209
210210 // This logic must be kept in sync with the logic in `analyzeCall` that
211211 // computes the hash.
src/Sema.zig+29-2
......@@ -5012,7 +5012,12 @@ fn analyzeCall(
50125012 // parameter or return type.
50135013 return error.GenericPoison;
50145014 },
5015 else => {},
5015 else => {
5016 // Needed so that lazy values do not trigger
5017 // assertion due to type not being resolved
5018 // when the hash function is called.
5019 try sema.resolveLazyValue(&child_block, arg_src, arg_val);
5020 },
50165021 }
50175022 should_memoize = should_memoize and !arg_val.canMutateComptimeVarState();
50185023 memoized_call_key.args[arg_i] = .{
......@@ -5039,7 +5044,12 @@ fn analyzeCall(
50395044 // parameter or return type.
50405045 return error.GenericPoison;
50415046 },
5042 else => {},
5047 else => {
5048 // Needed so that lazy values do not trigger
5049 // assertion due to type not being resolved
5050 // when the hash function is called.
5051 try sema.resolveLazyValue(&child_block, arg_src, arg_val);
5052 },
50435053 }
50445054 should_memoize = should_memoize and !arg_val.canMutateComptimeVarState();
50455055 memoized_call_key.args[arg_i] = .{
......@@ -21601,6 +21611,23 @@ pub fn resolveFnTypes(
2160121611 }
2160221612}
2160321613
21614/// Make it so that calling hash() and eql() on `val` will not assert due
21615/// to a type not having its layout resolved.
21616fn resolveLazyValue(
21617 sema: *Sema,
21618 block: *Block,
21619 src: LazySrcLoc,
21620 val: Value,
21621) CompileError!void {
21622 switch (val.tag()) {
21623 .lazy_align => {
21624 const ty = val.castTag(.lazy_align).?.data;
21625 return sema.resolveTypeLayout(block, src, ty);
21626 },
21627 else => return,
21628 }
21629}
21630
2160421631pub fn resolveTypeLayout(
2160521632 sema: *Sema,
2160621633 block: *Block,