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,
|
name_span: Span,
|
||||||
type_annotation: ?*Node,
|
type_annotation: ?*Node,
|
||||||
value: ?*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
|
/// `extern`-global form `g : T extern [LIB] ["csym"];` — a reference to a
|
||||||
/// global defined elsewhere (external linkage, resolved at link time). The
|
/// global defined elsewhere (external linkage, resolved at link time).
|
||||||
/// new extern-named surface; distinct from the legacy `#foreign` path above.
|
|
||||||
/// `extern_lib` is the optional source-library reference and `extern_name`
|
/// `extern_lib` is the optional source-library reference and `extern_name`
|
||||||
/// the optional symbol-name override (mirroring foreign_lib/foreign_name, so
|
/// the optional symbol-name override.
|
||||||
/// `extern` fully supersedes `#foreign`). Parsed in Phase 0.1; not consumed
|
|
||||||
/// by the var-decl path until Phase 1.2.
|
|
||||||
is_extern: bool = false,
|
is_extern: bool = false,
|
||||||
extern_lib: ?[]const u8 = null,
|
extern_lib: ?[]const u8 = null,
|
||||||
extern_name: ?[]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.
|
// Foreign / extern globals reference a symbol defined in libSystem etc.
|
||||||
// (`_NSConcreteStackBlock : *void #foreign;` or `… : *void extern;`). The C
|
// (`_NSConcreteStackBlock : *void #foreign;` or `… : *void extern;`). The C
|
||||||
// symbol name is the optional override (`extern_name`/`foreign_name`) or the
|
// symbol name is the optional override (`extern_name`) or the sx name itself.
|
||||||
// sx name itself.
|
const sym_name = vd.extern_name orelse vd.name;
|
||||||
const sym_name = vd.extern_name orelse vd.foreign_name orelse vd.name;
|
|
||||||
const name_id = self.module.types.internString(sym_name);
|
const name_id = self.module.types.internString(sym_name);
|
||||||
const init_val = self.globalInitValue(vd, var_ty);
|
const init_val = self.globalInitValue(vd, var_ty);
|
||||||
const gid = self.module.addGlobal(.{
|
const gid = self.module.addGlobal(.{
|
||||||
@@ -1124,13 +1123,13 @@ pub fn registerTopLevelGlobal(self: *Lowering, vd: *const ast.VarDecl) void {
|
|||||||
.ty = var_ty,
|
.ty = var_ty,
|
||||||
.init_val = init_val,
|
.init_val = init_val,
|
||||||
.is_const = false,
|
.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 });
|
self.putGlobal(self.current_source_file, vd.name, .{ .id = gid, .ty = var_ty });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize a top-level global's initializer into a static `ConstantValue`.
|
/// 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
|
/// payload — they default to zero/extern at link, which is correct. An
|
||||||
/// identifier initializer that names a module constant is materialized from
|
/// identifier initializer that names a module constant is materialized from
|
||||||
/// the recorded constant (`K : A : 42; g : A = K;` → 42); a
|
/// 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
|
/// is rejected with a diagnostic rather than silently zero-initialized — a
|
||||||
/// global has no run site for a dynamic initializer.
|
/// global has no run site for a dynamic initializer.
|
||||||
pub fn globalInitValue(self: *Lowering, vd: *const ast.VarDecl, var_ty: TypeId) ?inst_mod.ConstantValue {
|
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;
|
const v = vd.value orelse return null;
|
||||||
return switch (v.data) {
|
return switch (v.data) {
|
||||||
.undef_literal => .zeroinit,
|
.undef_literal => .zeroinit,
|
||||||
|
|||||||
Reference in New Issue
Block a user