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

@@ -204,10 +204,10 @@ pub fn checkRequiredEntryPoints(self: *Lowering) void {
const tc = self.target_config orelse return;
if (!tc.isAndroid()) return;
var it = self.program_index.foreign_class_map.iterator();
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_foreign and fcd.runtime == .jni_class) return;
if (fcd.is_main and !fcd.is_reference and fcd.runtime == .jni_class) return;
}
if (self.diagnostics) |diags| {
@@ -341,11 +341,11 @@ pub fn lowerDecls(self: *Lowering, decls: []const *const Node) void {
.impl_block => {
self.protocolResolver().registerImplBlock(&decl.data.impl_block, is_imported, decl);
},
.foreign_class_decl => {
self.registerForeignClassDecl(&decl.data.foreign_class_decl);
.runtime_class_decl => {
self.registerRuntimeClassDecl(&decl.data.runtime_class_decl);
},
.namespace_decl => |ns| {
self.registerNamespacedForeignClasses(ns);
self.registerNamespacedRuntimeClasses(ns);
if (self.main_file != null) {
self.registerNamespaceQualifiedFns(ns.name, ns.own_decls);
self.lowerDecls(ns.decls);
@@ -769,11 +769,11 @@ pub fn scanDecls(self: *Lowering, decls: []const *const Node) void {
.impl_block => {
self.protocolResolver().registerImplBlock(&decl.data.impl_block, is_imported, decl);
},
.foreign_class_decl => {
self.registerForeignClassDecl(&decl.data.foreign_class_decl);
.runtime_class_decl => {
self.registerRuntimeClassDecl(&decl.data.runtime_class_decl);
},
.namespace_decl => |ns| {
self.registerNamespacedForeignClasses(ns);
self.registerNamespacedRuntimeClasses(ns);
if (self.main_file != null) {
self.scanDecls(ns.decls);
self.registerNamespaceQualifiedFns(ns.name, ns.own_decls);
@@ -1746,7 +1746,7 @@ pub fn selectNominalLeaf(self: *Lowering, name: []const u8, from: []const u8, ra
/// it is recognised via `type_aliases_by_source` separately from named types.
pub fn isNamedTypeKind(raw: resolver_mod.RawDeclRef) bool {
return switch (raw) {
.struct_decl, .enum_decl, .union_decl, .error_set_decl, .protocol_decl, .foreign_class_decl => true,
.struct_decl, .enum_decl, .union_decl, .error_set_decl, .protocol_decl, .runtime_class_decl => true,
.fn_decl, .const_decl, .var_decl, .namespace_decl => false,
};
}
@@ -1774,7 +1774,7 @@ pub fn namedRefTid(self: *Lowering, ref: resolver_mod.RawDeclRef, name: []const
.struct_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.enum_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.union_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.error_set_decl, .protocol_decl, .foreign_class_decl => table.findByName(table.internString(name)),
.error_set_decl, .protocol_decl, .runtime_class_decl => table.findByName(table.internString(name)),
.fn_decl, .const_decl, .var_decl, .namespace_decl => null,
};
}
@@ -2288,15 +2288,15 @@ pub fn lazyLowerFunction(self: *Lowering, name: []const u8) void {
// Already lowered?
if (self.lowered_functions.contains(name)) return;
// For sx-defined `#objc_class` methods, pin current_foreign_class
// For sx-defined `#objc_class` methods, pin current_runtime_class
// so `*Self` substitutions in resolveTypeWithBindings find the
// state-struct type (M1.2 A.2b). The inline body-lowering path
// below re-resolves param types, so the context must be set
// BEFORE any resolveReturnType / resolveParamType call.
const saved_fc_lazy = self.current_foreign_class;
defer self.current_foreign_class = saved_fc_lazy;
const saved_fc_lazy = self.current_runtime_class;
defer self.current_runtime_class = saved_fc_lazy;
if (self.lookupObjcDefinedClassForMethod(name)) |fcd| {
self.current_foreign_class = fcd;
self.current_runtime_class = fcd;
}
// No AST? (builtins, foreign functions, or imported functions not in this file)
const fd = self.program_index.fn_ast_map.get(name) orelse return;
@@ -2381,10 +2381,10 @@ pub fn lazyLowerFunction(self: *Lowering, name: []const u8) void {
pub fn lowerFunctionBodyInto(self: *Lowering, fd: *const ast.FnDecl, fid: FuncId, name: []const u8) void {
// objc-defined-class method context for `*Self` substitution (M1.2 A.2b);
// the resolveReturnType / resolveParamType calls below consult it.
const saved_fc = self.current_foreign_class;
defer self.current_foreign_class = saved_fc;
const saved_fc = self.current_runtime_class;
defer self.current_runtime_class = saved_fc;
if (self.lookupObjcDefinedClassForMethod(name)) |fcd| {
self.current_foreign_class = fcd;
self.current_runtime_class = fcd;
}
var reentry = FnBodyReentry.enter(self);
@@ -2477,13 +2477,13 @@ pub fn lowerFunctionBodyInto(self: *Lowering, fd: *const ast.FnDecl, fid: FuncId
/// Lower a single function declaration.
pub fn lowerFunction(self: *Lowering, fd: *const ast.FnDecl, name: []const u8, is_imported: bool) void {
// For sx-defined `#objc_class` methods (qualified `<Class>.<method>`),
// set `current_foreign_class` so `*Self` substitutions through
// set `current_runtime_class` so `*Self` substitutions through
// `resolveTypeWithBindings` find the state-struct type (M1.2 A.2b).
// Save+restore — function lowering can re-enter.
const saved_fc = self.current_foreign_class;
defer self.current_foreign_class = saved_fc;
const saved_fc = self.current_runtime_class;
defer self.current_runtime_class = saved_fc;
if (self.lookupObjcDefinedClassForMethod(name)) |fcd| {
self.current_foreign_class = fcd;
self.current_runtime_class = fcd;
}
const name_id = self.module.types.internString(name);