commit 32eb8cc9003ad975e4128ff987bd92ab4222a52a (tree)
parent 22d61bfd49734290ceb15323a0557d6a5fb6977b
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Thu, 26 Feb 2026 04:29:36 +0000
intern_pool: fix enum_tag to store ty + int_val pair
The enum_tag IP key was incorrectly storing a single InternPoolIndex
when it should store a struct with both the enum type and the integer
tag value. Add hash, equality, typeOf, and verbose printing support.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/stage0/intern_pool.c b/stage0/intern_pool.c
@@ -71,6 +71,10 @@ static uint32_t ipHashKey(const InternPoolKey* key) {
case IP_KEY_ENUM_LITERAL:
h = ipHashCombine(h, key->data.enum_literal);
break;
+ case IP_KEY_ENUM_TAG:
+ h = ipHashCombine(h, key->data.enum_tag.ty);
+ h = ipHashCombine(h, key->data.enum_tag.int_val);
+ break;
case IP_KEY_FLOAT: {
uint64_t fbits;
memcpy(&fbits, &key->data.float_val.val, sizeof(fbits));
@@ -143,6 +147,9 @@ static bool ipKeysEqual(const InternPoolKey* a, const InternPoolKey* b) {
return a->data.tuple_type == b->data.tuple_type;
case IP_KEY_ENUM_LITERAL:
return a->data.enum_literal == b->data.enum_literal;
+ case IP_KEY_ENUM_TAG:
+ return a->data.enum_tag.ty == b->data.enum_tag.ty
+ && a->data.enum_tag.int_val == b->data.enum_tag.int_val;
case IP_KEY_FLOAT:
return a->data.float_val.ty == b->data.float_val.ty
&& memcmp(&a->data.float_val.val, &b->data.float_val.val,
@@ -804,6 +811,9 @@ InternPoolIndex ipTypeOf(const InternPool* ip, InternPoolIndex index) {
case IP_KEY_ENUM_LITERAL:
return IP_INDEX_ENUM_LITERAL_TYPE;
+ case IP_KEY_ENUM_TAG:
+ return key.data.enum_tag.ty;
+
case IP_KEY_PTR_NAV:
return key.data.ptr_nav.ty;
diff --git a/stage0/intern_pool.h b/stage0/intern_pool.h
@@ -341,7 +341,10 @@ typedef struct {
InternPoolIndex err;
InternPoolIndex error_union;
uint32_t enum_literal; // string index
- InternPoolIndex enum_tag;
+ struct {
+ InternPoolIndex ty; // enum type IP index
+ InternPoolIndex int_val; // integer tag value IP index
+ } enum_tag;
InternPoolIndex empty_enum_value;
struct {
InternPoolIndex ty;
diff --git a/stage0/verbose_intern_pool.c b/stage0/verbose_intern_pool.c
@@ -117,6 +117,10 @@ void verboseIpPrint(FILE* out, const InternPool* ip) {
case IP_KEY_ENUM_LITERAL:
fprintf(out, " str_idx=%u", key.data.enum_literal);
break;
+ case IP_KEY_ENUM_TAG:
+ fprintf(out, " ty=%u int=%u", key.data.enum_tag.ty,
+ key.data.enum_tag.int_val);
+ break;
case IP_KEY_FLOAT:
fprintf(out, " ty=%u val=%g", key.data.float_val.ty,
key.data.float_val.val);