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);