Commented the workaround with links to issues, and put it behind a build flag.

This commit is contained in:
Krzysztof Furman
2026-06-13 09:53:43 +01:00
parent b05d459a13
commit 15deb7a118
3 changed files with 23 additions and 2 deletions

View File

@@ -520,8 +520,17 @@ gb_internal u64 type_hash_canonical_type(Type *type) {
type_writer_make_hasher(&w, &w.hash_ctx);
write_type_to_canonical_string(&w, type);
u64 hash = typeid_hash_context_fini(&w.hash_ctx);
hash &= 0x7fffffffffffffffull;
hash = hash ? hash : 1;
if (build_context.webkit_switch_workaround) {
// Clear the top bit so every `typeid` is in [1, 2^63). A `switch` over a
// typeid (e.g. a type switch over `any` in core:fmt) then has a case-value
// span < 2^63. WebKit's B3/OMG wasm JIT computes a switch's value range as
// a signed i64 (max - min); a span >= 2^63 overflows and makes it build a
// pathologically-sized jump table, OOM-crashing the tab.
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=317022
// Odin issue/PR: https://github.com/odin-lang/Odin/issues/6810
hash &= 0x7fffffffffffffffull;
hash = hash ? hash : 1;
}
type->canonical_hash.store(hash, std::memory_order_relaxed);