diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-04-18 06:28:49 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-04-18 16:41:54 -0700 |
| commit | c9858f833c2e1d5ef414af7e01d465baa88ef9cc (patch) | |
| tree | 1abc39e35044723c47f1c5a566bfaa545ac9703f /src | |
| parent | b75d86027d589be632a831ec55565230818dc4ef (diff) | |
| download | zig-c9858f833c2e1d5ef414af7e01d465baa88ef9cc.tar.gz zig-c9858f833c2e1d5ef414af7e01d465baa88ef9cc.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Module.zig | 2 | ||||
| -rw-r--r-- | src/Sema.zig | 31 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/Module.zig b/src/Module.zig index 53c72ccec2..95ae55feb8 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -205,7 +205,7 @@ pub const MemoizedCall = struct { // The generic function Decl is guaranteed to be the first dependency // of each of its instantiations. - std.hash.autoHash(&hasher, @ptrToInt(key.func)); + std.hash.autoHash(&hasher, key.func); // This logic must be kept in sync with the logic in `analyzeCall` that // computes the hash. diff --git a/src/Sema.zig b/src/Sema.zig index 8789f0589e..a3eef2dc86 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5012,7 +5012,12 @@ fn analyzeCall( // parameter or return type. return error.GenericPoison; }, - else => {}, + else => { + // Needed so that lazy values do not trigger + // assertion due to type not being resolved + // when the hash function is called. + try sema.resolveLazyValue(&child_block, arg_src, arg_val); + }, } should_memoize = should_memoize and !arg_val.canMutateComptimeVarState(); memoized_call_key.args[arg_i] = .{ @@ -5039,7 +5044,12 @@ fn analyzeCall( // parameter or return type. return error.GenericPoison; }, - else => {}, + else => { + // Needed so that lazy values do not trigger + // assertion due to type not being resolved + // when the hash function is called. + try sema.resolveLazyValue(&child_block, arg_src, arg_val); + }, } should_memoize = should_memoize and !arg_val.canMutateComptimeVarState(); memoized_call_key.args[arg_i] = .{ @@ -21601,6 +21611,23 @@ pub fn resolveFnTypes( } } +/// Make it so that calling hash() and eql() on `val` will not assert due +/// to a type not having its layout resolved. +fn resolveLazyValue( + sema: *Sema, + block: *Block, + src: LazySrcLoc, + val: Value, +) CompileError!void { + switch (val.tag()) { + .lazy_align => { + const ty = val.castTag(.lazy_align).?.data; + return sema.resolveTypeLayout(block, src, ty); + }, + else => return, + } +} + pub fn resolveTypeLayout( sema: *Sema, block: *Block, |
