authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-09 15:34:43+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-15 00:48:47+03:00
log6f6b14621d5a0935d39295d21b5ffad2197f0e2f
tree317d12067bc2cb1e2952fcc6f1509ed5edbccb30
parent930f904aaa7d591d86a8c3216526711be95fcc17

value: hash extern functions

Closes #12766

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

src/value.zig+6-3
......@@ -2391,12 +2391,15 @@ pub const Value = extern union {
23912391 union_obj.val.hash(active_field_ty, hasher, mod);
23922392 },
23932393 .Fn => {
2394 const func: *Module.Fn = val.castTag(.function).?.data;
2395 // Note that his hashes the *Fn rather than the *Decl. This is
2394 // Note that his hashes the *Fn/*ExternFn rather than the *Decl. This is
23962395 // to differentiate function bodies from function pointers.
23972396 // This is currently redundant since we already hash the zig type tag
23982397 // at the top of this function.
2399 std.hash.autoHash(hasher, func);
2398 if (val.castTag(.function)) |func| {
2399 std.hash.autoHash(hasher, func.data);
2400 } else if (val.castTag(.extern_fn)) |func| {
2401 std.hash.autoHash(hasher, func.data);
2402 } else unreachable;
24002403 },
24012404 .Frame => {
24022405 @panic("TODO implement hashing frame values");
test/behavior/generics.zig+11
......@@ -358,3 +358,14 @@ test "nested generic function" {
358358 try expect(@typeInfo(@TypeOf(S.g)).Fn.is_generic);
359359 try S.foo(u32, S.bar, 123);
360360}
361
362test "extern function used as generic parameter" {
363 const S = struct {
364 extern fn foo() void;
365 extern fn bar() void;
366 inline fn baz(comptime _: anytype) type {
367 return struct {};
368 }
369 };
370 try expect(S.baz(S.foo) != S.baz(S.bar));
371}