aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-30 00:47:55 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-30 00:47:55 -0700
commitc21f046a8b019c42aa0dbb0fb9c592b590edf977 (patch)
tree96c7f602f08b00c9cabdd699f8f678de215e50c5 /src/Module.zig
parent05947ea870f95ab90a75e174079492f546baaf72 (diff)
downloadzig-c21f046a8b019c42aa0dbb0fb9c592b590edf977.tar.gz
zig-c21f046a8b019c42aa0dbb0fb9c592b590edf977.zip
Sema: enhance is_non_err to be comptime more often
* Sema: store the precomputed monomorphed_funcs hash inside Module.Fn. This is important because it may be accessed when resizing monomorphed_funcs while this Fn has already been added to the set, but does not have the owner_decl, comptime_args, or other fields populated yet. * Sema: in `analyzeIsNonErr`, take advantage of the AIR tag being `wrap_errunion_payload` to infer that `is_non_err` is comptime true without performing any error set resolution. - Also add some code to check for empty inferred error sets in this function. If necessary we do resolve the inferred error set. * Sema: queue full type resolution of payload type when `wrap_errunion_payload` AIR instruction is emitted. This ensures the backend may check the alignment of it. * Sema: resolveTypeFully now additionally resolves comptime-only status. closes #11306
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/Module.zig b/src/Module.zig
index ce93e091fd..3bc763103b 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -146,8 +146,6 @@ const MonomorphedFuncsSet = std.HashMapUnmanaged(
);
const MonomorphedFuncsContext = struct {
- target: Target,
-
pub fn eql(ctx: @This(), a: *Fn, b: *Fn) bool {
_ = ctx;
return a == b;
@@ -155,25 +153,8 @@ const MonomorphedFuncsContext = struct {
/// Must match `Sema.GenericCallAdapter.hash`.
pub fn hash(ctx: @This(), key: *Fn) u64 {
- var hasher = std.hash.Wyhash.init(0);
-
- // The generic function Decl is guaranteed to be the first dependency
- // of each of its instantiations.
- const generic_owner_decl = key.owner_decl.dependencies.keys()[0];
- const generic_func: *const Fn = generic_owner_decl.val.castTag(.function).?.data;
- std.hash.autoHash(&hasher, generic_func);
-
- // This logic must be kept in sync with the logic in `analyzeCall` that
- // computes the hash.
- const comptime_args = key.comptime_args.?;
- const generic_ty_info = generic_owner_decl.ty.fnInfo();
- for (generic_ty_info.param_types) |param_ty, i| {
- if (generic_ty_info.paramIsComptime(i) and param_ty.tag() != .generic_poison) {
- comptime_args[i].val.hash(param_ty, &hasher, ctx.target);
- }
- }
-
- return hasher.final();
+ _ = ctx;
+ return key.hash;
}
};
@@ -1427,6 +1408,12 @@ pub const Fn = struct {
/// determine param names rather than redundantly storing them here.
param_names: []const [:0]const u8,
+ /// Precomputed hash for monomorphed_funcs.
+ /// This is important because it may be accessed when resizing monomorphed_funcs
+ /// while this Fn has already been added to the set, but does not have the
+ /// owner_decl, comptime_args, or other fields populated yet.
+ hash: u64,
+
/// Relative to owner Decl.
lbrace_line: u32,
/// Relative to owner Decl.