sema: remove dead builtin/target special cases from field access

Remove dead code in zirFieldValComptime and zirFieldPtr that handled
@import("builtin") field access via strcmp("builtin") + strcmp("target").
These blocks were guarded by obj_ip == VOID_VALUE which no longer
matches for builtin imports (DECL_VAL now resolves to CG struct type).

The normal namespace lookup path (via ensureNavValUpToDate →
resolveCgBuiltinField) handles CG builtin field access correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-28 17:40:32 +00:00
parent a35a70ad16
commit f38841024c

View File

@@ -9386,45 +9386,6 @@ static AirInstRef zirFieldValComptime(
= sema->code.inst_datas[obj_inst].str_tok.start;
const char* import_path = findDeclImportPath(sema, decl_name_idx);
if (import_path) {
// Special handling for @import("builtin") — the
// compiler-generated builtin module with target info.
// Look up the field in the cg builtin namespace.
if (strcmp(import_path, "builtin") == 0
&& s_cg_builtin_ns_idx != UINT32_MAX) {
uint32_t field_nav
= findNavInNamespace(s_cg_builtin_ns_idx, field_name);
if (field_nav != UINT32_MAX) {
// For "target", return the ptr_nav (pointer to the
// target value) rather than the type. This enables
// comptime method calls like
// target.cCallingConvention() where the evaluator
// needs a pointer, not a type.
// Track it so the comptime evaluator can resolve
// field accesses on the target value.
if (strcmp(field_name, "target") == 0) {
const Nav* tn = ipGetNav(field_nav);
if (tn->resolved_type != IP_INDEX_NONE) {
InternPoolIndex ptr_ty
= internPtrConst(tn->resolved_type);
InternPoolKey pk;
memset(&pk, 0, sizeof(pk));
pk.tag = IP_KEY_PTR_NAV;
pk.data.ptr_nav.ty = ptr_ty;
pk.data.ptr_nav.nav = field_nav;
InternPoolIndex pn = ipIntern(sema->ip, pk);
return AIR_REF_FROM_IP(pn);
}
}
// Lazily resolve CG builtin fields
// (is_test, object_format, link_mode).
InternPoolIndex val
= resolveCgBuiltinField(field_nav, field_name);
if (val == IP_INDEX_NONE)
val = ensureNavValUpToDate(field_nav);
if (val != IP_INDEX_NONE)
return AIR_REF_FROM_IP(val);
}
}
Ast import_ast;
Zir import_zir = loadImportZir(
sema->source_dir, import_path, &import_ast);
@@ -9465,56 +9426,6 @@ static AirInstRef zirFieldPtr(Sema* sema, SemaBlock* block, uint32_t inst) {
// Cross-module comptime pointer resolution.
// When the object is from a cross-module import (decl_ref of
// @import), load the imported module's ZIR and resolve the field.
// This handles patterns like:
// @import("builtin").target → ptr_nav(target)
// Ported from zirFieldValComptime cross-module path, adapted for
// pointer (field_ptr) context.
if (AIR_REF_IS_IP(obj) && block->is_comptime) {
InternPoolIndex obj_ip = AIR_REF_TO_IP(obj);
if (obj_ip == IP_INDEX_VOID_VALUE && obj_ref >= ZIR_REF_START_INDEX
&& sema->source_dir) {
uint32_t obj_inst = obj_ref - ZIR_REF_START_INDEX;
ZirInstTag obj_tag = sema->code.inst_tags[obj_inst];
if (obj_tag == ZIR_INST_DECL_VAL || obj_tag == ZIR_INST_DECL_REF) {
uint32_t decl_name_idx
= sema->code.inst_datas[obj_inst].str_tok.start;
const char* import_path
= findDeclImportPath(sema, decl_name_idx);
if (import_path && strcmp(import_path, "builtin") == 0
&& s_cg_builtin_ns_idx != UINT32_MAX) {
uint32_t field_nav
= findNavInNamespace(s_cg_builtin_ns_idx, field_name);
if (field_nav != UINT32_MAX) {
if (strcmp(field_name, "target") == 0) {
const Nav* tn = ipGetNav(field_nav);
if (tn->resolved_type != IP_INDEX_NONE) {
InternPoolIndex ptr_ty
= internPtrConst(tn->resolved_type);
InternPoolKey pk;
memset(&pk, 0, sizeof(pk));
pk.tag = IP_KEY_PTR_NAV;
pk.data.ptr_nav.ty = ptr_ty;
pk.data.ptr_nav.nav = field_nav;
InternPoolIndex pn = ipIntern(sema->ip, pk);
return AIR_REF_FROM_IP(pn);
}
}
InternPoolIndex val = ensureNavValUpToDate(field_nav);
if (val != IP_INDEX_NONE) {
InternPoolIndex ptr_ty = internPtrConst(val);
InternPoolKey pk;
memset(&pk, 0, sizeof(pk));
pk.tag = IP_KEY_PTR_NAV;
pk.data.ptr_nav.ty = ptr_ty;
pk.data.ptr_nav.nav = field_nav;
return AIR_REF_FROM_IP(ipIntern(sema->ip, pk));
}
}
}
}
}
}
// Comptime: if the operand IS a struct type (its type is `type`),
// look up the field in the type's namespace. This handles patterns
// like @import("builtin").target where the import resolves to a