refactor(ffi-linkage): Phase 9.2a — rename runtime-class TYPE names → Runtime* (Decision 5)

Mechanical, collision-free PascalCase renames (object-model axis, not linkage):
ForeignClassDecl→RuntimeClassDecl, ForeignMethodDecl→RuntimeMethodDecl,
ForeignClassMember→RuntimeClassMember, ForeignFieldDecl→RuntimeFieldDecl,
ForeignRuntime→RuntimeKind, ForeignClassPrefix→RuntimeClassPrefix. Snapshot-neutral;
suite green (646/444). Remaining 9.2: snake_case state (foreign_class_map,
current_foreign_class, foreign_path [coupled to .sx hooks], the foreign_class_decl
union variant) + the parse/lower/resolve fn names + ForeignClassDecl.is_foreign flag.
This commit is contained in:
agra
2026-06-15 08:57:53 +03:00
parent 7ffdc7d2a2
commit 3354446412
16 changed files with 129 additions and 129 deletions

View File

@@ -235,7 +235,7 @@ pub fn lowerJniCall(self: *Lowering, fic: *const ast.FfiIntrinsicCall) Ref {
/// Phase 3/4 and currently surface a clear diagnostic.
pub fn lowerForeignMethodCall(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
fcd: *const ast.RuntimeClassDecl,
method_name: []const u8,
target: Ref,
method_args: []const Ref,
@@ -359,7 +359,7 @@ pub fn lowerForeignMethodCall(
/// fictitious `Self` struct and the next dispatch lookup fails.
pub fn resolveForeignClassMemberType(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
fcd: *const ast.RuntimeClassDecl,
type_node: *const ast.Node,
) TypeId {
if (type_node.data == .type_expr and std.mem.eql(u8, type_node.data.type_expr.name, "Self")) {
@@ -376,14 +376,14 @@ pub fn resolveForeignClassMemberType(
pub fn resolveForeignMethodReturnType(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
method: ast.ForeignMethodDecl,
fcd: *const ast.RuntimeClassDecl,
method: ast.RuntimeMethodDecl,
) TypeId {
const rt = method.return_type orelse return .void;
return self.resolveForeignClassMemberType(fcd, rt);
}
pub fn foreignClassStructType(self: *Lowering, fcd: *const ast.ForeignClassDecl) TypeId {
pub fn foreignClassStructType(self: *Lowering, fcd: *const ast.RuntimeClassDecl) TypeId {
const name_id = self.module.types.internString(fcd.name);
if (self.module.types.findByName(name_id)) |existing| return existing;
return self.module.types.intern(.{ .@"struct" = .{ .name = name_id, .fields = &.{} } });
@@ -396,8 +396,8 @@ pub fn foreignClassStructType(self: *Lowering, fcd: *const ast.ForeignClassDecl)
/// sharing the cached-SEL slot path with explicit `#objc_call`.
pub fn lowerObjcMethodCall(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
method: ast.ForeignMethodDecl,
fcd: *const ast.RuntimeClassDecl,
method: ast.RuntimeMethodDecl,
target: Ref,
method_args: []const Ref,
span: ast.Span,
@@ -460,8 +460,8 @@ pub fn lowerObjcMethodCall(
/// selector mangling as instance methods (Phase 3.0).
pub fn lowerObjcStaticCall(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
method: ast.ForeignMethodDecl,
fcd: *const ast.RuntimeClassDecl,
method: ast.RuntimeMethodDecl,
method_args: []const Ref,
span: ast.Span,
) Ref {
@@ -570,8 +570,8 @@ pub fn lowerObjcStaticCall(
/// that need to instantiate Android classes (SurfaceView, etc.).
pub fn lowerForeignStaticCall(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
method: ast.ForeignMethodDecl,
fcd: *const ast.RuntimeClassDecl,
method: ast.RuntimeMethodDecl,
method_args: []const Ref,
span: ast.Span,
) Ref {
@@ -609,7 +609,7 @@ pub fn lowerForeignStaticCall(
// constructor returns void; the new jobject comes back from
// `NewObject` itself). Patch the AST by overriding return_type
// to null during derivation.
const m_for_desc: ast.ForeignMethodDecl = .{
const m_for_desc: ast.RuntimeMethodDecl = .{
.name = method.name,
.params = method.params,
.param_names = method.param_names,
@@ -703,7 +703,7 @@ pub fn lowerSuperCall(
// enclosing method's descriptor; cross-method super calls require
// the parent class to be declared via `#foreign #jni_class`.
var descriptor: []const u8 = "";
var resolved_method: ?ast.ForeignMethodDecl = null;
var resolved_method: ?ast.RuntimeMethodDecl = null;
if (self.current_foreign_method) |em| {
if (std.mem.eql(u8, em.name, method_name)) {
resolved_method = em;
@@ -792,7 +792,7 @@ pub fn lowerSuperCall(
/// under qualified names `<ClassName>.<methodName>`. Lazy lowering
/// then handles the body via the standard path; `*Self` is
/// substituted to `*<ClassName>State` during body lowering (M1.2 A.2b).
pub fn registerForeignClassDecl(self: *Lowering, fcd: *const ast.ForeignClassDecl) void {
pub fn registerForeignClassDecl(self: *Lowering, fcd: *const ast.RuntimeClassDecl) void {
self.program_index.foreign_class_map.put(fcd.name, fcd) catch {};
if (!fcd.is_foreign and fcd.runtime == .objc_class) {
if (self.module.lookupObjcDefinedClass(fcd.name) == null) {
@@ -825,7 +825,7 @@ pub fn registerForeignClassDecl(self: *Lowering, fcd: *const ast.ForeignClassDec
/// foreign_path; aliases for OTHER sx-defined classes use the
/// alias name directly (which equals the Obj-C class name for
/// sx-defined classes).
pub fn resolveObjcParentName(self: *Lowering, fcd: *const ast.ForeignClassDecl) []const u8 {
pub fn resolveObjcParentName(self: *Lowering, fcd: *const ast.RuntimeClassDecl) []const u8 {
for (fcd.members) |m| switch (m) {
.extends => |alias| {
if (self.program_index.foreign_class_map.get(alias)) |parent_fcd| {
@@ -875,14 +875,14 @@ pub fn declareObjcDefinedClassGlobal(self: *Lowering, class_name: []const u8) vo
}
/// For each bodied instance method on an sx-defined `#objc_class`,
/// synthesize an `FnDecl` from the `ForeignMethodDecl`, register it
/// synthesize an `FnDecl` from the `RuntimeMethodDecl`, register it
/// in `fn_ast_map` under `<ClassName>.<methodName>`, declare the IR
/// function, AND collect per-method registration data (selector
/// mangling + type encoding + IMP symbol name) into the class's
/// cache entry so emit_llvm can wire up `class_addMethod` calls
/// (M1.2 A.4b.iii). Bodyless declarations are skipped — they
/// reference inherited / external methods, not sx-side bodies.
pub fn registerObjcDefinedClassMethods(self: *Lowering, fcd: *const ast.ForeignClassDecl) void {
pub fn registerObjcDefinedClassMethods(self: *Lowering, fcd: *const ast.RuntimeClassDecl) void {
// Set current_foreign_class so `*Self` substitutions in
// declareFunction's type resolution find the state struct.
const saved = self.current_foreign_class;
@@ -942,11 +942,11 @@ pub fn registerObjcDefinedClassMethods(self: *Lowering, fcd: *const ast.ForeignC
}
/// Build an `FnDecl` whose params are zipped from the
/// `ForeignMethodDecl.params` (type nodes) and `param_names`. Used
/// `RuntimeMethodDecl.params` (type nodes) and `param_names`. Used
/// to feed sx-defined class methods through the standard
/// fn-lowering pipeline. Allocator-owned; lives for the duration
/// of the Lowering pass.
pub fn synthesizeFnDeclFromObjcMethod(self: *Lowering, method: ast.ForeignMethodDecl, body: *ast.Node) ?*ast.FnDecl {
pub fn synthesizeFnDeclFromObjcMethod(self: *Lowering, method: ast.RuntimeMethodDecl, body: *ast.Node) ?*ast.FnDecl {
if (method.params.len != method.param_names.len) return null;
var params = std.ArrayList(ast.Param).empty;
for (method.params, method.param_names) |type_node, p_name| {
@@ -968,10 +968,10 @@ pub fn synthesizeFnDeclFromObjcMethod(self: *Lowering, method: ast.ForeignMethod
/// If `name` matches an sx-defined `#objc_class`'s qualified-method
/// pattern (`<ClassName>.<methodName>`), return the class's
/// ForeignClassDecl. Used by `lowerFunction` to set
/// RuntimeClassDecl. Used by `lowerFunction` to set
/// `current_foreign_class` so `*Self` resolves to the state struct
/// during body lowering.
pub fn lookupObjcDefinedClassForMethod(self: *Lowering, name: []const u8) ?*const ast.ForeignClassDecl {
pub fn lookupObjcDefinedClassForMethod(self: *Lowering, name: []const u8) ?*const ast.RuntimeClassDecl {
const dot = std.mem.indexOf(u8, name, ".") orelse return null;
return self.module.lookupObjcDefinedClass(name[0..dot]);
}
@@ -1053,7 +1053,7 @@ pub fn synthesizeJniMainStubs(self: *Lowering) void {
}
}
pub fn synthesizeJniMainStub(self: *Lowering, fcd: *const ast.ForeignClassDecl, md: ast.ForeignMethodDecl) void {
pub fn synthesizeJniMainStub(self: *Lowering, fcd: *const ast.RuntimeClassDecl, md: ast.RuntimeMethodDecl) void {
const mangled = jni_descriptor.jniMangleNativeName(self.alloc, fcd.foreign_path, md.name) catch return;
const name_id = self.module.types.internString(mangled);

View File

@@ -56,8 +56,8 @@ pub fn lowerObjcDefinedClassMethods(self: *Lowering) void {
/// If `obj_expr` is typed as a pointer to a foreign Obj-C class
/// and that class (or any of its `#extends` ancestors) declares a
/// `#property` field with the given name, return the
/// `ForeignFieldDecl`. M2.2 + M2.3.
pub fn lookupObjcPropertyOnPointer(self: *Lowering, obj_expr: *const ast.Node, field_name: []const u8) ?ast.ForeignFieldDecl {
/// `RuntimeFieldDecl`. M2.2 + M2.3.
pub fn lookupObjcPropertyOnPointer(self: *Lowering, obj_expr: *const ast.Node, field_name: []const u8) ?ast.RuntimeFieldDecl {
const obj_ty = self.inferExprType(obj_expr);
if (obj_ty.isBuiltin()) return null;
const ptr_info = self.module.types.get(obj_ty);
@@ -74,8 +74,8 @@ pub fn lookupObjcPropertyOnPointer(self: *Lowering, obj_expr: *const ast.Node, f
/// 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.ForeignClassDecl, method_name: []const u8) ?struct { fcd: *const ast.ForeignClassDecl, method: ast.ForeignMethodDecl } {
var current: *const ast.ForeignClassDecl = fcd;
pub fn findForeignMethodInChain(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) {
for (current.members) |m| switch (m) {
@@ -97,8 +97,8 @@ pub fn findForeignMethodInChain(self: *Lowering, fcd: *const ast.ForeignClassDec
/// Walk the `#extends` chain looking for a `#property` field by
/// name. M2.3 companion to findForeignMethodInChain.
pub fn findForeignPropertyInChain(self: *Lowering, fcd: *const ast.ForeignClassDecl, field_name: []const u8) ?ast.ForeignFieldDecl {
var current: *const ast.ForeignClassDecl = fcd;
pub fn findForeignPropertyInChain(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) {
for (current.members) |m| switch (m) {
@@ -121,7 +121,7 @@ const ObjcDefinedStateField = struct {
field_ty: TypeId,
state_ty: TypeId,
field_idx: u32,
fcd: *const ast.ForeignClassDecl,
fcd: *const ast.RuntimeClassDecl,
};
/// State-field-access info: if obj_expr is *<sx-defined-class>
@@ -190,7 +190,7 @@ pub fn lowerObjcDefinedStateFieldRead(
/// `state = object_getIvar(obj, load(__<Cls>_state_ivar))`. Shared
/// helper for state-field read + write (M1.2 A.3).
pub fn lowerObjcDefinedStateForObj(self: *Lowering, obj_ref: Ref, fcd: *const ast.ForeignClassDecl) ?Ref {
pub fn lowerObjcDefinedStateForObj(self: *Lowering, obj_ref: Ref, fcd: *const ast.RuntimeClassDecl) ?Ref {
const ptr_void = self.module.types.ptrTo(.void);
const ivar_global_name = std.fmt.allocPrint(self.alloc, "__{s}_state_ivar", .{fcd.name}) catch return null;
defer self.alloc.free(ivar_global_name);
@@ -207,7 +207,7 @@ pub fn lowerObjcDefinedStateForObj(self: *Lowering, obj_ref: Ref, fcd: *const as
/// Lower `obj.field` for an Obj-C `#property` field as
/// `objc_msg_send(obj, sel_<fieldName>)`. M2.2 — getter side.
/// The setter side lives in the assignment-statement lowering.
pub fn lowerObjcPropertyGetter(self: *Lowering, obj_expr: *const ast.Node, field: ast.ForeignFieldDecl, _: []const u8, _: ast.Span) Ref {
pub fn lowerObjcPropertyGetter(self: *Lowering, obj_expr: *const ast.Node, field: ast.RuntimeFieldDecl, _: []const u8, _: ast.Span) Ref {
const obj_ref = self.lowerExpr(obj_expr);
const ret_ty = self.resolveType(field.field_type);
const vptr_ty = self.module.types.ptrTo(.void);
@@ -228,7 +228,7 @@ pub fn lowerObjcPropertyGetter(self: *Lowering, obj_expr: *const ast.Node, field
/// `objc_msg_send(obj, sel_set<Field>:, val)`. M2.2 — setter side.
/// Selector: prepend "set", capitalize the first letter of the
/// field name, append ":". `backgroundColor` → `setBackgroundColor:`.
pub fn lowerObjcPropertySetter(self: *Lowering, obj_expr: *const ast.Node, field: ast.ForeignFieldDecl, val: Ref) void {
pub fn lowerObjcPropertySetter(self: *Lowering, obj_expr: *const ast.Node, field: ast.RuntimeFieldDecl, val: Ref) void {
const obj_ref = self.lowerExpr(obj_expr);
const vptr_ty = self.module.types.ptrTo(.void);
@@ -361,7 +361,7 @@ pub fn ensureArcRuntimeDecls(self: *Lowering) void {
/// Both IMPs land in the cache's methods slice with appropriate
/// selectors + encodings; emit_llvm's class_addMethod loop wires
/// them up like any other instance method.
pub fn emitObjcDefinedClassPropertyImps(self: *Lowering, fcd: *const ast.ForeignClassDecl, field: ast.ForeignFieldDecl) void {
pub fn emitObjcDefinedClassPropertyImps(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field: ast.RuntimeFieldDecl) void {
const state_ty = self.objc().objcDefinedStateStructType(fcd);
const state_info = self.module.types.get(state_ty);
if (state_info != .@"struct") return;
@@ -404,7 +404,7 @@ pub fn emitObjcDefinedClassPropertyImps(self: *Lowering, fcd: *const ast.Foreign
self.registerObjcDefinedPropertyMethodEntries(fcd, field, field_ty, is_readonly);
}
pub fn emitObjcDefinedPropertyGetter(self: *Lowering, fcd: *const ast.ForeignClassDecl, field: ast.ForeignFieldDecl, state_ty: TypeId, fidx: u32, field_ty: TypeId) void {
pub fn emitObjcDefinedPropertyGetter(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field: ast.RuntimeFieldDecl, state_ty: TypeId, fidx: u32, field_ty: TypeId) void {
const saved_func = self.builder.func;
const saved_block = self.builder.current_block;
const saved_counter = self.builder.inst_counter;
@@ -484,7 +484,7 @@ pub fn emitObjcDefinedPropertyGetter(self: *Lowering, fcd: *const ast.ForeignCla
self.builder.finalize();
}
pub fn emitObjcDefinedPropertySetter(self: *Lowering, fcd: *const ast.ForeignClassDecl, field: ast.ForeignFieldDecl, state_ty: TypeId, fidx: u32, field_ty: TypeId) void {
pub fn emitObjcDefinedPropertySetter(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field: ast.RuntimeFieldDecl, state_ty: TypeId, fidx: u32, field_ty: TypeId) void {
const saved_func = self.builder.func;
const saved_block = self.builder.current_block;
const saved_counter = self.builder.inst_counter;
@@ -610,7 +610,7 @@ pub fn emitObjcDefinedPropertySetter(self: *Lowering, fcd: *const ast.ForeignCla
/// entries to the class's method-registration slice so emit_llvm
/// calls class_addMethod on each. Selectors + encodings derived
/// from the field type.
pub fn registerObjcDefinedPropertyMethodEntries(self: *Lowering, fcd: *const ast.ForeignClassDecl, field: ast.ForeignFieldDecl, field_ty: TypeId, is_readonly: bool) void {
pub fn registerObjcDefinedPropertyMethodEntries(self: *Lowering, fcd: *const ast.RuntimeClassDecl, field: ast.RuntimeFieldDecl, field_ty: TypeId, is_readonly: bool) void {
const cur = self.module.lookupObjcDefinedClass(fcd.name) orelse return;
_ = cur;
// Find the existing entry and grow its methods slice.
@@ -665,7 +665,7 @@ pub fn registerObjcDefinedPropertyMethodEntries(self: *Lowering, fcd: *const ast
self.module.setObjcDefinedClassMethods(fcd.name, slice);
}
pub fn emitObjcDefinedClassImp(self: *Lowering, fcd: *const ast.ForeignClassDecl, md: ast.ForeignMethodDecl) void {
pub fn emitObjcDefinedClassImp(self: *Lowering, fcd: *const ast.RuntimeClassDecl, md: ast.RuntimeMethodDecl) void {
// Class methods (no `*Self` first param) skip the ivar read —
// they have no instance state to thread through.
if (md.is_static) {
@@ -800,7 +800,7 @@ pub fn emitObjcDefinedClassImp(self: *Lowering, fcd: *const ast.ForeignClassDecl
/// `current_ctx_ref` as the ctx — so `push Context.{ allocator = ... }`
/// flows through to per-instance allocator capture without going via
/// the IMP.
pub fn emitObjcDefinedClassAllocImp(self: *Lowering, fcd: *const ast.ForeignClassDecl) void {
pub fn emitObjcDefinedClassAllocImp(self: *Lowering, fcd: *const ast.RuntimeClassDecl) void {
const saved_func = self.builder.func;
const saved_block = self.builder.current_block;
const saved_counter = self.builder.inst_counter;
@@ -858,7 +858,7 @@ pub fn emitObjcDefinedClassAllocImp(self: *Lowering, fcd: *const ast.ForeignClas
/// missing (compiler bug — should be impossible after scan pass).
pub fn emitObjcDefinedAllocAndInit(
self: *Lowering,
fcd: *const ast.ForeignClassDecl,
fcd: *const ast.RuntimeClassDecl,
cls_ref: Ref,
ctx_addr: Ref,
) ?Ref {
@@ -953,7 +953,7 @@ pub fn emitObjcDefinedAllocAndInit(
/// ret <result>
///
/// No ivar read — class methods have no per-instance state.
pub fn emitObjcDefinedClassStaticImp(self: *Lowering, fcd: *const ast.ForeignClassDecl, md: ast.ForeignMethodDecl) void {
pub fn emitObjcDefinedClassStaticImp(self: *Lowering, fcd: *const ast.RuntimeClassDecl, md: ast.RuntimeMethodDecl) void {
const saved_func = self.builder.func;
const saved_block = self.builder.current_block;
const saved_counter = self.builder.inst_counter;
@@ -1050,7 +1050,7 @@ pub fn emitObjcDefinedClassStaticImp(self: *Lowering, fcd: *const ast.ForeignCla
/// +alloc time (M4.0a + M4.0b). Reading it back lets -dealloc free
/// through the same allocator the instance was constructed with —
/// the per-instance allocator design from M1.2 A.5, now realised.
pub fn emitObjcDefinedClassDeallocImp(self: *Lowering, fcd: *const ast.ForeignClassDecl) void {
pub fn emitObjcDefinedClassDeallocImp(self: *Lowering, fcd: *const ast.RuntimeClassDecl) void {
const saved_func = self.builder.func;
const saved_block = self.builder.current_block;
const saved_counter = self.builder.inst_counter;