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:
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user