refactor(ffi-linkage): Phase 9.2b-fix — use is_extern (not new is_reference) for the runtime-class ref flag

Per user feedback: don't introduce new terminology. The RuntimeClassDecl
reference-vs-define flag (set by the postfix 'extern' modifier, == old prefix
'#foreign #objc_class') is named is_extern, matching the keyword that drives it
and the existing is_extern on VarDecl/IR. Renamed is_reference→is_extern,
is_reference_eff→is_extern_eff; updated the field comment. Snapshot-neutral; green.
This commit is contained in:
agra
2026-06-15 09:06:19 +03:00
parent d27be42a93
commit a15a868391
9 changed files with 34 additions and 34 deletions

View File

@@ -389,7 +389,7 @@ test "lower: objcDefinedStateStructType collects user-declared fields" {
.foreign_path = "SxFoo",
.runtime = .objc_class,
.members = &members,
.is_reference = false,
.is_extern = false,
.is_main = false,
};
@@ -421,7 +421,7 @@ test "lower: objcDefinedStateStructType handles empty field set" {
.foreign_path = "SxEmpty",
.runtime = .objc_class,
.members = &.{},
.is_reference = false,
.is_extern = false,
.is_main = false,
};
@@ -453,7 +453,7 @@ test "lower: objcDefinedStateStructType skips non-field members" {
.foreign_path = "SxMixed",
.runtime = .objc_class,
.members = &members,
.is_reference = false,
.is_extern = false,
.is_main = false,
};
@@ -481,7 +481,7 @@ test "lower: objcTypeEncodingFromSignature emits @ for Obj-C class pointers" {
.foreign_path = "NSString",
.runtime = .objc_class,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSString", &ns_fcd);
@@ -514,7 +514,7 @@ test "lower: objcTypeEncodingFromSignature unwraps optional to wire type" {
.foreign_path = "NSString",
.runtime = .objc_class,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSString", &ns_fcd);
@@ -683,7 +683,7 @@ test "lower: isObjcClassPointer recognises pointer-to-foreign-Obj-C-class" {
.foreign_path = "NSString",
.runtime = .objc_class,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSString", &ns_fcd);
@@ -699,7 +699,7 @@ test "lower: isObjcClassPointer recognises pointer-to-foreign-Obj-C-class" {
.foreign_path = "NSCopying",
.runtime = .objc_protocol,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSCopying", &proto_fcd);
@@ -731,7 +731,7 @@ test "lower: objcPropertyKind defaults + explicit ARC modifiers" {
.foreign_path = "NSString",
.runtime = .objc_class,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSString", &ns_fcd);
@@ -756,7 +756,7 @@ test "lower: objcPropertyKind defaults + explicit ARC modifiers" {
.foreign_path = "NSCoding",
.runtime = .objc_protocol,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try lowering.program_index.runtime_class_map.put("NSCoding", &proto_fcd);

View File

@@ -207,7 +207,7 @@ pub fn checkRequiredEntryPoints(self: *Lowering) void {
var it = self.program_index.runtime_class_map.iterator();
while (it.next()) |entry| {
const fcd = entry.value_ptr.*;
if (fcd.is_main and !fcd.is_reference and fcd.runtime == .jni_class) return;
if (fcd.is_main and !fcd.is_extern and fcd.runtime == .jni_class) return;
}
if (self.diagnostics) |diags| {

View File

@@ -270,7 +270,7 @@ pub fn lowerRuntimeMethodCall(
if (fcd.runtime == .objc_class or fcd.runtime == .objc_protocol) {
return self.lowerObjcMethodCall(fcd, method, target, method_args, span);
}
if (!fcd.is_reference) {
if (!fcd.is_extern) {
if (self.diagnostics) |d| {
d.addFmt(.err, span, "sx-defined classes on non-Obj-C runtimes can't yet be dispatched into (class '{s}', runtime '{s}')", .{ fcd.name, @tagName(fcd.runtime) });
}
@@ -505,7 +505,7 @@ pub fn lowerObjcStaticCall(
// instead of going through `objc_msgSend` (which would land in the
// +alloc IMP and use `__sx_default_context.allocator`). This honors
// a surrounding `push Context.{ allocator = ... }`.
if (!fcd.is_reference and
if (!fcd.is_extern and
fcd.runtime == .objc_class and
method_args.len == 0 and
std.mem.eql(u8, method.name, "alloc"))
@@ -794,7 +794,7 @@ pub fn lowerSuperCall(
/// substituted to `*<ClassName>State` during body lowering (M1.2 A.2b).
pub fn registerRuntimeClassDecl(self: *Lowering, fcd: *const ast.RuntimeClassDecl) void {
self.program_index.runtime_class_map.put(fcd.name, fcd) catch {};
if (!fcd.is_reference and fcd.runtime == .objc_class) {
if (!fcd.is_extern and fcd.runtime == .objc_class) {
if (self.module.lookupObjcDefinedClass(fcd.name) == null) {
self.module.appendObjcDefinedClass(fcd.name, fcd);
// M2.3 — resolve the `#extends` alias to the actual
@@ -829,7 +829,7 @@ pub fn resolveObjcParentName(self: *Lowering, fcd: *const ast.RuntimeClassDecl)
for (fcd.members) |m| switch (m) {
.extends => |alias| {
if (self.program_index.runtime_class_map.get(alias)) |parent_fcd| {
if (parent_fcd.is_reference) return parent_fcd.foreign_path;
if (parent_fcd.is_extern) return parent_fcd.foreign_path;
// Sx-defined parent — its alias IS its Obj-C name.
return parent_fcd.name;
}
@@ -1037,7 +1037,7 @@ pub fn synthesizeJniMainStubs(self: *Lowering) void {
while (it.next()) |entry| {
const fcd = entry.value_ptr.*;
if (!fcd.is_main) continue;
if (fcd.is_reference) continue;
if (fcd.is_extern) continue;
if (fcd.runtime != .jni_class) continue;
if (seen.contains(fcd.foreign_path)) continue;
seen.put(fcd.foreign_path, {}) catch continue;

View File

@@ -139,7 +139,7 @@ pub fn lookupObjcDefinedStateFieldOnPointer(self: *Lowering, obj_expr: *const as
const fcd = self.program_index.runtime_class_map.get(struct_name) orelse return null;
// Only sx-defined Obj-C classes have a state struct. Foreign
// classes' fields are purely declaration metadata (no state).
if (fcd.is_reference or fcd.runtime != .objc_class) return null;
if (fcd.is_extern or fcd.runtime != .objc_class) return null;
// Skip property fields — those dispatch via the M2.2 getter/setter
// path. Plain instance fields take the ivar+gep path.
for (fcd.members) |m| switch (m) {

View File

@@ -73,7 +73,7 @@ test "ProgramIndex declaration maps round-trip (A1.1b)" {
.foreign_path = "NSString",
.runtime = .objc_class,
.members = &.{},
.is_reference = true,
.is_extern = true,
.is_main = false,
};
try idx.runtime_class_map.put("NSString", &fcd);