refactor(ffi-linkage): Phase 9.1c — delete dead VarDecl legacy foreign fields
VarDecl carried BOTH the legacy is_foreign/foreign_lib/foreign_name AND the new is_extern/extern_lib/extern_name (parallel forms coalesced during the migration). The global #foreign parse path now rejects, so the legacy trio is write-dead and read in only 3 coalescing sites (decl.zig). Simplified those readers (vd.extern_name orelse vd.name; vd.is_extern) and deleted the dead fields. Build confirms no other setter/reader. Snapshot-neutral; suite green (646/444). Remaining linkage (9.1): foreign_expr (25, still built by c_import.zig auto-synth) + ForeignClassDecl.is_foreign (runtime-class, → 9.2). Runtime-class family (9.2, Decision 5) is the big remaining src/ rename.
This commit is contained in:
10
src/ast.zig
10
src/ast.zig
@@ -361,16 +361,10 @@ pub const VarDecl = struct {
|
||||
name_span: Span,
|
||||
type_annotation: ?*Node,
|
||||
value: ?*Node,
|
||||
is_foreign: bool = false,
|
||||
foreign_lib: ?[]const u8 = null,
|
||||
foreign_name: ?[]const u8 = null,
|
||||
/// `extern`-global form `g : T extern [LIB] ["csym"];` — a reference to a
|
||||
/// global defined elsewhere (external linkage, resolved at link time). The
|
||||
/// new extern-named surface; distinct from the legacy `#foreign` path above.
|
||||
/// global defined elsewhere (external linkage, resolved at link time).
|
||||
/// `extern_lib` is the optional source-library reference and `extern_name`
|
||||
/// the optional symbol-name override (mirroring foreign_lib/foreign_name, so
|
||||
/// `extern` fully supersedes `#foreign`). Parsed in Phase 0.1; not consumed
|
||||
/// by the var-decl path until Phase 1.2.
|
||||
/// the optional symbol-name override.
|
||||
is_extern: bool = false,
|
||||
extern_lib: ?[]const u8 = null,
|
||||
extern_name: ?[]const u8 = null,
|
||||
|
||||
@@ -1114,9 +1114,8 @@ pub fn registerTopLevelGlobal(self: *Lowering, vd: *const ast.VarDecl) void {
|
||||
};
|
||||
// Foreign / extern globals reference a symbol defined in libSystem etc.
|
||||
// (`_NSConcreteStackBlock : *void #foreign;` or `… : *void extern;`). The C
|
||||
// symbol name is the optional override (`extern_name`/`foreign_name`) or the
|
||||
// sx name itself.
|
||||
const sym_name = vd.extern_name orelse vd.foreign_name orelse vd.name;
|
||||
// symbol name is the optional override (`extern_name`) or the sx name itself.
|
||||
const sym_name = vd.extern_name orelse vd.name;
|
||||
const name_id = self.module.types.internString(sym_name);
|
||||
const init_val = self.globalInitValue(vd, var_ty);
|
||||
const gid = self.module.addGlobal(.{
|
||||
@@ -1124,13 +1123,13 @@ pub fn registerTopLevelGlobal(self: *Lowering, vd: *const ast.VarDecl) void {
|
||||
.ty = var_ty,
|
||||
.init_val = init_val,
|
||||
.is_const = false,
|
||||
.is_extern = vd.is_foreign or vd.is_extern,
|
||||
.is_extern = vd.is_extern,
|
||||
});
|
||||
self.putGlobal(self.current_source_file, vd.name, .{ .id = gid, .ty = var_ty });
|
||||
}
|
||||
|
||||
/// Serialize a top-level global's initializer into a static `ConstantValue`.
|
||||
/// Foreign globals (extern symbol) and value-less declarations carry no
|
||||
/// Extern globals (external symbol) and value-less declarations carry no
|
||||
/// payload — they default to zero/extern at link, which is correct. An
|
||||
/// identifier initializer that names a module constant is materialized from
|
||||
/// the recorded constant (`K : A : 42; g : A = K;` → 42); a
|
||||
@@ -1138,7 +1137,7 @@ pub fn registerTopLevelGlobal(self: *Lowering, vd: *const ast.VarDecl) void {
|
||||
/// is rejected with a diagnostic rather than silently zero-initialized — a
|
||||
/// global has no run site for a dynamic initializer.
|
||||
pub fn globalInitValue(self: *Lowering, vd: *const ast.VarDecl, var_ty: TypeId) ?inst_mod.ConstantValue {
|
||||
if (vd.is_foreign or vd.is_extern) return null;
|
||||
if (vd.is_extern) return null;
|
||||
const v = vd.value orelse return null;
|
||||
return switch (v.data) {
|
||||
.undef_literal => .zeroinit,
|
||||
|
||||
Reference in New Issue
Block a user