refactor(ffi-linkage): Phase 9.2b — rename runtime-class fns + state → runtime_* / is_reference

The runtime-class object-model identifiers (Decision 5): parse/lower/find/resolve/
register/stamp fns Foreign→Runtime (parseRuntimeClassDecl, lowerRuntimeMethodCall,
findRuntimeMethodInChain, resolveRuntimeMethodReturnType, registerRuntimeClassDecl,
runtimeClassStructType, runtimeKindForOffset, …); state foreign_class_map→
runtime_class_map, current_foreign_class/_method→current_runtime_*, the
foreign_class_decl union variant→runtime_class_decl, foreign_method/static/instance/
class→runtime_*; and the reference-vs-define flag is_foreign→is_reference (+
is_foreign_eff→is_reference_eff) now that it only lives on RuntimeClassDecl.
Snapshot-neutral; suite green (646/444).

Remaining 9.2: the foreign_path family (coupled .sx hooks: jni_main_foreign_path_at
spans build.sx/bundle.sx/compiler_hooks.zig/specs.md) + the extern-ref validators
(checkForeignRefs etc. → Extern, linkage not runtime) + bare 'foreign' comments.
This commit is contained in:
agra
2026-06-15 09:01:04 +03:00
parent 3354446412
commit 5c8af6eb73
22 changed files with 205 additions and 205 deletions

View File

@@ -30,7 +30,7 @@ const Lowering = lower.Lowering;
/// `#objc_class`. The Obj-C runtime invokes these via the IMP
/// pointers wired up in M1.2 A.4 — no sx-side call path triggers
/// lazy lowering, so we walk the cache and force-lower here.
/// `lowerFunction` sets `current_foreign_class` automatically based
/// `lowerFunction` sets `current_runtime_class` automatically based
/// on the qualified name, so `*Self` substitutions in the body
/// resolve correctly (M1.2 A.2b). After the bodies are lowered,
/// `emitObjcDefinedClassImps` wraps each with a C-ABI trampoline
@@ -65,16 +65,16 @@ pub fn lookupObjcPropertyOnPointer(self: *Lowering, obj_expr: *const ast.Node, f
const pointee_info = self.module.types.get(ptr_info.pointer.pointee);
if (pointee_info != .@"struct") return null;
const struct_name = self.module.types.getString(pointee_info.@"struct".name);
const fcd = self.program_index.foreign_class_map.get(struct_name) orelse return null;
const fcd = self.program_index.runtime_class_map.get(struct_name) orelse return null;
if (fcd.runtime != .objc_class and fcd.runtime != .objc_protocol) return null;
return self.findForeignPropertyInChain(fcd, field_name);
return self.findRuntimePropertyInChain(fcd, field_name);
}
/// Walk the `#extends` chain looking for a method by name. M2.3.
/// Returns the owning fcd + the method decl, or null if no ancestor
/// declares it. Depth-capped at 16 to break accidental cycles
/// (real Obj-C class chains rarely exceed 6 levels).
pub fn findForeignMethodInChain(self: *Lowering, fcd: *const ast.RuntimeClassDecl, method_name: []const u8) ?struct { fcd: *const ast.RuntimeClassDecl, method: ast.RuntimeMethodDecl } {
pub fn findRuntimeMethodInChain(self: *Lowering, fcd: *const ast.RuntimeClassDecl, method_name: []const u8) ?struct { fcd: *const ast.RuntimeClassDecl, method: ast.RuntimeMethodDecl } {
var current: *const ast.RuntimeClassDecl = fcd;
var depth: u32 = 0;
while (depth < 16) : (depth += 1) {
@@ -90,14 +90,14 @@ pub fn findForeignMethodInChain(self: *Lowering, fcd: *const ast.RuntimeClassDec
};
break :blk null;
} orelse return null;
current = self.program_index.foreign_class_map.get(parent) orelse return null;
current = self.program_index.runtime_class_map.get(parent) orelse return null;
}
return null;
}
/// Walk the `#extends` chain looking for a `#property` field by
/// name. M2.3 companion to findForeignMethodInChain.
pub fn findForeignPropertyInChain(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field_name: []const u8) ?ast.RuntimeFieldDecl {
/// name. M2.3 companion to findRuntimeMethodInChain.
pub fn findRuntimePropertyInChain(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field_name: []const u8) ?ast.RuntimeFieldDecl {
var current: *const ast.RuntimeClassDecl = fcd;
var depth: u32 = 0;
while (depth < 16) : (depth += 1) {
@@ -112,7 +112,7 @@ pub fn findForeignPropertyInChain(self: *Lowering, fcd: *const ast.RuntimeClassD
};
break :blk null;
} orelse return null;
current = self.program_index.foreign_class_map.get(parent) orelse return null;
current = self.program_index.runtime_class_map.get(parent) orelse return null;
}
return null;
}
@@ -136,10 +136,10 @@ pub fn lookupObjcDefinedStateFieldOnPointer(self: *Lowering, obj_expr: *const as
const pointee_info = self.module.types.get(ptr_info.pointer.pointee);
if (pointee_info != .@"struct") return null;
const struct_name = self.module.types.getString(pointee_info.@"struct".name);
const fcd = self.program_index.foreign_class_map.get(struct_name) orelse return null;
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_foreign or fcd.runtime != .objc_class) return null;
if (fcd.is_reference 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) {
@@ -694,11 +694,11 @@ pub fn emitObjcDefinedClassImp(self: *Lowering, fcd: *const ast.RuntimeClassDecl
params.append(self.alloc, .{ .name = self.module.types.internString("obj"), .ty = ptr_void }) catch return;
params.append(self.alloc, .{ .name = self.module.types.internString("_cmd"), .ty = ptr_void }) catch return;
// Set current_foreign_class so *Self in user-param resolution
// Set current_runtime_class so *Self in user-param resolution
// resolves to *<Cls>State (M1.2 A.2b). Save+restore.
const saved_fc = self.current_foreign_class;
self.current_foreign_class = fcd;
defer self.current_foreign_class = saved_fc;
const saved_fc = self.current_runtime_class;
self.current_runtime_class = fcd;
defer self.current_runtime_class = saved_fc;
const param_start: usize = 1;
for (md.params[param_start..], 0..) |p_node, i| {
@@ -971,12 +971,12 @@ pub fn emitObjcDefinedClassStaticImp(self: *Lowering, fcd: *const ast.RuntimeCla
params.append(self.alloc, .{ .name = self.module.types.internString("cls"), .ty = ptr_void }) catch return;
params.append(self.alloc, .{ .name = self.module.types.internString("_cmd"), .ty = ptr_void }) catch return;
// current_foreign_class lets `*Self` (if it appears in
// current_runtime_class lets `*Self` (if it appears in
// user-arg types — rare for class methods) resolve to the
// state-struct type. Save+restore.
const saved_fc = self.current_foreign_class;
self.current_foreign_class = fcd;
defer self.current_foreign_class = saved_fc;
const saved_fc = self.current_runtime_class;
self.current_runtime_class = fcd;
defer self.current_runtime_class = saved_fc;
for (md.params, 0..) |p_node, i| {
const pty = self.resolveType(p_node);