From cd147942e481543d0b48a0149666ce64b4ca8820 Mon Sep 17 00:00:00 2001 From: agra Date: Mon, 15 Jun 2026 08:46:59 +0300 Subject: [PATCH] =?UTF-8?q?refactor(ffi-linkage):=20Phase=209.1c=20?= =?UTF-8?q?=E2=80=94=20delete=20dead=20VarDecl=20legacy=20foreign=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/ast.zig | 10 ++-------- src/ir/lower/decl.zig | 11 +++++------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/ast.zig b/src/ast.zig index a9cec29..2e029a5 100644 --- a/src/ast.zig +++ b/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, diff --git a/src/ir/lower/decl.zig b/src/ir/lower/decl.zig index 7ee8327..e1f4225 100644 --- a/src/ir/lower/decl.zig +++ b/src/ir/lower/decl.zig @@ -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,