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 {...@@ -2391,12 +2391,15 @@ pub const Value = extern union {
2391 union_obj.val.hash(active_field_ty, hasher, mod);2391 union_obj.val.hash(active_field_ty, hasher, mod);
2392 },2392 },
2393 .Fn => {2393 .Fn => {
2394 const func: *Module.Fn = val.castTag(.function).?.data;2394 // Note that his hashes the *Fn/*ExternFn rather than the *Decl. This is
2395 // Note that his hashes the *Fn rather than the *Decl. This is
2396 // to differentiate function bodies from function pointers.2395 // to differentiate function bodies from function pointers.
2397 // This is currently redundant since we already hash the zig type tag2396 // This is currently redundant since we already hash the zig type tag
2398 // at the top of this function.2397 // 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;
2400 },2403 },
2401 .Frame => {2404 .Frame => {
2402 @panic("TODO implement hashing frame values");2405 @panic("TODO implement hashing frame values");
test/behavior/generics.zig+11
...@@ -358,3 +358,14 @@ test "nested generic function" {...@@ -358,3 +358,14 @@ test "nested generic function" {
358 try expect(@typeInfo(@TypeOf(S.g)).Fn.is_generic);358 try expect(@typeInfo(@TypeOf(S.g)).Fn.is_generic);
359 try S.foo(u32, S.bar, 123);359 try S.foo(u32, S.bar, 123);
360}360}
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}