refactor(ffi-linkage): Phase 9.1a — rename collision-free linkage identifiers
Mechanical src/ rename of the linkage-family identifiers whose extern_* target is collision-free: callForeign→callExtern, marshalForeignArg→marshalExternArg, dedupeForeignSymbol→dedupeExternSymbol, foreign_name_map→extern_name_map, is_foreign_c_api→is_extern_c_api. Snapshot-neutral (internal only); suite green (646 corpus / 444 unit, 0 failed). Deferred (need per-site analysis — target name already exists): is_foreign↔is_extern (38 existing), foreign_lib/foreign_name↔extern_lib/extern_name (15/16 existing), foreign_expr (still built by c_import.zig auto-synthesis). Runtime-class family (ForeignClassDecl etc. → Runtime*, Decision 5) is Phase 9.2.
This commit is contained in:
@@ -1255,7 +1255,7 @@ pub fn allocViaContext(self: *Lowering, size_ref: Ref, void_ptr_ty: TypeId) Ref
|
||||
/// Used for the compiler-internal byte-copy in the protocol-erasure
|
||||
/// heap path and the closure env-copy path, both of which need
|
||||
/// libc `memcpy` after the `#builtin` form was dropped.
|
||||
pub fn callForeign(self: *Lowering, name: []const u8, args: []const Ref, ret_ty: TypeId) Ref {
|
||||
pub fn callExtern(self: *Lowering, name: []const u8, args: []const Ref, ret_ty: TypeId) Ref {
|
||||
const fid = self.resolveFuncByName(name) orelse @panic("foreign symbol missing — std.sx not imported?");
|
||||
return self.builder.call(fid, args, ret_ty);
|
||||
}
|
||||
@@ -1286,7 +1286,7 @@ fn protocolHasMethod(proto_info: anytype, name: []const u8) bool {
|
||||
|
||||
pub fn resolveFuncByName(self: *Lowering, name: []const u8) ?FuncId {
|
||||
// Check foreign name map first (e.g., "c_abs" → "abs")
|
||||
const effective_name = self.foreign_name_map.get(name) orelse name;
|
||||
const effective_name = self.extern_name_map.get(name) orelse name;
|
||||
const name_id = self.module.types.internString(effective_name);
|
||||
for (self.module.functions.items, 0..) |func, i| {
|
||||
if (func.name == name_id) return FuncId.fromIndex(@intCast(i));
|
||||
|
||||
@@ -216,7 +216,7 @@ pub fn lowerLambda(self: *Lowering, lam: *const ast.Lambda) Ref {
|
||||
const env_byte_size_inner = self.computeEnvSize(capture_list);
|
||||
const env_size_val = self.builder.constInt(@intCast(env_byte_size_inner), .i64);
|
||||
// memcpy(local_alloca, env_param, size)
|
||||
_ = self.callForeign("memcpy", &.{ env_local, env_param_ref, env_size_val }, self.module.types.ptrTo(.void));
|
||||
_ = self.callExtern("memcpy", &.{ env_local, env_param_ref, env_size_val }, self.module.types.ptrTo(.void));
|
||||
|
||||
for (capture_list, 0..) |cap, i| {
|
||||
// GEP into env struct to get field pointer
|
||||
@@ -359,7 +359,7 @@ pub fn lowerLambda(self: *Lowering, lam: *const ast.Lambda) Ref {
|
||||
const ptr_void = self.module.types.ptrTo(.void);
|
||||
const env_heap = self.allocViaContext(env_size, ptr_void);
|
||||
// memcpy(heap, stack_alloca, size)
|
||||
_ = self.callForeign("memcpy", &.{ env_heap, env_local, env_size }, ptr_void);
|
||||
_ = self.callExtern("memcpy", &.{ env_heap, env_local, env_size }, ptr_void);
|
||||
|
||||
return self.builder.closureCreate(func_id, env_heap, closure_ty);
|
||||
} else {
|
||||
|
||||
@@ -2035,7 +2035,7 @@ fn returnGenericLeaf(node: *const Node) ?[]const u8 {
|
||||
/// the later declaration (a `-> string` view of a symbol registered `-> *u8`
|
||||
/// reads the wrong shape; issue 0128). True = handled (shared or diagnosed),
|
||||
/// caller must not declare again.
|
||||
pub fn dedupeForeignSymbol(self: *Lowering, fd: *const ast.FnDecl, sym_name: StringId, params: []const Function.Param, ret_ty: TypeId) bool {
|
||||
pub fn dedupeExternSymbol(self: *Lowering, fd: *const ast.FnDecl, sym_name: StringId, params: []const Function.Param, ret_ty: TypeId) bool {
|
||||
for (self.module.functions.items, 0..) |*func, i| {
|
||||
if (func.name != sym_name or !func.is_extern) continue;
|
||||
var same = func.ret == ret_ty and func.params.len == params.len;
|
||||
@@ -2142,8 +2142,8 @@ pub fn declareFunction(self: *Lowering, fd: *const ast.FnDecl, name: []const u8)
|
||||
null;
|
||||
if (rename_c_name) |c_name| {
|
||||
const c_name_id = self.module.types.internString(c_name);
|
||||
if (self.dedupeForeignSymbol(fd, c_name_id, params.items, ret_ty)) {
|
||||
self.foreign_name_map.put(name, c_name) catch {};
|
||||
if (self.dedupeExternSymbol(fd, c_name_id, params.items, ret_ty)) {
|
||||
self.extern_name_map.put(name, c_name) catch {};
|
||||
return;
|
||||
}
|
||||
const fid = self.builder.declareExtern(c_name_id, params.items, ret_ty);
|
||||
@@ -2152,13 +2152,13 @@ pub fn declareFunction(self: *Lowering, fd: *const ast.FnDecl, name: []const u8)
|
||||
func.source_file = self.current_source_file;
|
||||
func.is_variadic = is_variadic;
|
||||
func.has_implicit_ctx = wants_ctx;
|
||||
self.foreign_name_map.put(name, c_name) catch {};
|
||||
self.extern_name_map.put(name, c_name) catch {};
|
||||
self.fn_decl_fids.put(fd, fid) catch {};
|
||||
return;
|
||||
}
|
||||
|
||||
const name_id = self.module.types.internString(name);
|
||||
if ((is_foreign or is_extern_decl) and self.dedupeForeignSymbol(fd, name_id, params.items, ret_ty)) return;
|
||||
if ((is_foreign or is_extern_decl) and self.dedupeExternSymbol(fd, name_id, params.items, ret_ty)) return;
|
||||
const fid = self.builder.declareExtern(name_id, params.items, ret_ty);
|
||||
const func = self.module.getFunctionMut(fid);
|
||||
func.call_conv = cc;
|
||||
@@ -2355,10 +2355,10 @@ pub fn lazyLowerFunction(self: *Lowering, name: []const u8) void {
|
||||
// its OWN FuncId by `lowerRetainedSameNameAuthors`.
|
||||
// A renamed `export … "csym"` fn was declared under its C symbol name
|
||||
// (declareFunction's rename path), so search for the stub under that name
|
||||
// and promote the body into it. `foreign_name_map` only carries an entry
|
||||
// and promote the body into it. `extern_name_map` only carries an entry
|
||||
// when a rename was registered; a bare export / normal define keeps its sx
|
||||
// name (Phase 2.2).
|
||||
const search_name = self.foreign_name_map.get(name) orelse name;
|
||||
const search_name = self.extern_name_map.get(name) orelse name;
|
||||
const name_id = self.module.types.internString(search_name);
|
||||
var func_id: ?FuncId = null;
|
||||
for (self.module.functions.items, 0..) |func, i| {
|
||||
|
||||
@@ -443,7 +443,7 @@ pub fn buildProtocolValue(self: *Lowering, concrete_ptr: Ref, proto_name: []cons
|
||||
const concrete_size = self.module.types.typeSizeBytes(concrete_ty);
|
||||
const size_ref = self.builder.constInt(@intCast(concrete_size), .i64);
|
||||
const heap_ptr = self.allocViaContext(size_ref, void_ptr_ty);
|
||||
_ = self.callForeign("memcpy", &.{ heap_ptr, concrete_ptr, size_ref }, void_ptr_ty);
|
||||
_ = self.callExtern("memcpy", &.{ heap_ptr, concrete_ptr, size_ref }, void_ptr_ty);
|
||||
ctx_ptr = heap_ptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user