Merge pull request #6974 from tf2spi/6967-improve-type-hashing

Ensure identical types have same hash
This commit is contained in:
Jeroen van Rijn
2026-07-07 19:17:39 +02:00
committed by GitHub

View File

@@ -516,9 +516,17 @@ gb_internal u64 type_hash_canonical_type(Type *type) {
return prev_hash;
}
// NOTE(tf2spi): Unwrap type aliases similar to are_types_identical*
Type *type_unaliased = type;
if (type->kind == Type_Named) {
Entity *e = type->Named.type_name;
if (e->TypeName.is_type_alias) {
type_unaliased = type->Named.base;
}
}
TypeWriter w = {};
type_writer_make_hasher(&w, &w.hash_ctx);
write_type_to_canonical_string(&w, type);
write_type_to_canonical_string(&w, type_unaliased);
u64 hash = typeid_hash_context_fini(&w.hash_ctx);
if (build_context.webkit_switch_workaround) {
// Clear the top bit so every `typeid` is in [1, 2^63). A `switch` over a