sema: add internStrLit, STR handler, Pass 1b ipForceIntern
Add string literal interning for comptime ZIR_INST_STR handling: - internStrLit() creates 4 IP entries (type_array_big, bytes, type_pointer, ptr_uav) matching Zig's addStrLit + uavRef. - Wire into STR instruction handler in comptime context. Fix Pass 1b type_pointer deduplication: use ipForceIntern instead of internPtrConst to match Zig's sharded IP behavior where dedup doesn't happen across shards. Add ipForceIntern to intern_pool (bypasses dedup, always creates new entry). Also add verbose_intern_pool output for ptr_uav entries. Reduces neghf2 IP gap from ~63 to 54 entries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -729,6 +729,12 @@ InternPoolIndex ipIntern(InternPool* ip, InternPoolKey key) {
|
||||
return new_index;
|
||||
}
|
||||
|
||||
InternPoolIndex ipForceIntern(InternPool* ip, InternPoolKey key) {
|
||||
uint32_t new_index = ip->items_len;
|
||||
ipAppendItem(ip, key);
|
||||
return new_index;
|
||||
}
|
||||
|
||||
InternPoolKey ipIndexToKey(const InternPool* ip, InternPoolIndex index) {
|
||||
InternPoolKey key;
|
||||
memset(&key, 0, sizeof(key));
|
||||
|
||||
@@ -458,6 +458,7 @@ typedef struct {
|
||||
InternPool ipInit(void);
|
||||
void ipDeinit(InternPool* ip);
|
||||
InternPoolIndex ipIntern(InternPool* ip, InternPoolKey key);
|
||||
InternPoolIndex ipForceIntern(InternPool* ip, InternPoolKey key);
|
||||
InternPoolKey ipIndexToKey(const InternPool* ip, InternPoolIndex index);
|
||||
InternPoolIndex ipTypeOf(const InternPool* ip, InternPoolIndex index);
|
||||
|
||||
|
||||
1691
stage0/sema.c
1691
stage0/sema.c
File diff suppressed because it is too large
Load Diff
@@ -291,6 +291,15 @@ typedef struct Sema {
|
||||
// File index into s_loaded_modules[] for this sema's module.
|
||||
// Set by analyzeNavValC / semaAnalyze. UINT32_MAX = unknown.
|
||||
uint32_t file_idx;
|
||||
// Comptime return alloc tracking for result-location function evaluation.
|
||||
// Used by zirRetPtr/zirRetLoad/zirOptEuBasePtrInit/zirStoreNode in
|
||||
// comptime context. Set by comptimeFieldCall.
|
||||
// Ported from Sema.zig ComptimeAlloc / retPtrComptime.
|
||||
InternPoolIndex comptime_ret_ptr; // ptr_comptime_alloc IP index
|
||||
InternPoolIndex comptime_ret_val; // stored return value
|
||||
InternPoolIndex comptime_inner_type; // inner type after optional unwrap
|
||||
InternPoolIndex comptime_field_type; // union field type for struct init
|
||||
uint32_t comptime_field_idx; // union field index for struct init
|
||||
} Sema;
|
||||
|
||||
#define SEMA_DEFAULT_BRANCH_QUOTA 1000
|
||||
|
||||
@@ -114,6 +114,10 @@ void verboseIpPrint(FILE* out, const InternPool* ip) {
|
||||
key.data.int_type.signedness ? 'i' : 'u',
|
||||
key.data.int_type.bits);
|
||||
break;
|
||||
case IP_KEY_ARRAY_TYPE:
|
||||
fprintf(out, " len=%" PRIu64 " child=%u", key.data.array_type.len,
|
||||
key.data.array_type.child);
|
||||
break;
|
||||
case IP_KEY_STRUCT_TYPE:
|
||||
fprintf(out, " hash=%u", key.data.struct_type);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user