value: hash extern functions

Closes #12766
This commit is contained in:
Veikka Tuominen 2022-09-09 15:34:43 +03:00
parent 930f904aaa
commit 6f6b14621d
2 changed files with 17 additions and 3 deletions

View File

@ -2391,12 +2391,15 @@ pub const Value = extern union {
union_obj.val.hash(active_field_ty, hasher, mod);
},
.Fn => {
const func: *Module.Fn = val.castTag(.function).?.data;
// Note that his hashes the *Fn rather than the *Decl. This is
// Note that his hashes the *Fn/*ExternFn rather than the *Decl. This is
// to differentiate function bodies from function pointers.
// This is currently redundant since we already hash the zig type tag
// at the top of this function.
std.hash.autoHash(hasher, func);
if (val.castTag(.function)) |func| {
std.hash.autoHash(hasher, func.data);
} else if (val.castTag(.extern_fn)) |func| {
std.hash.autoHash(hasher, func.data);
} else unreachable;
},
.Frame => {
@panic("TODO implement hashing frame values");

View File

@ -358,3 +358,14 @@ test "nested generic function" {
try expect(@typeInfo(@TypeOf(S.g)).Fn.is_generic);
try S.foo(u32, S.bar, 123);
}
test "extern function used as generic parameter" {
const S = struct {
extern fn foo() void;
extern fn bar() void;
inline fn baz(comptime _: anytype) type {
return struct {};
}
};
try expect(S.baz(S.foo) != S.baz(S.bar));
}