From d27be42a93e30e5c51f7756fde052c7ea5133d2e Mon Sep 17 00:00:00 2001 From: agra Date: Mon, 15 Jun 2026 09:03:35 +0300 Subject: [PATCH] =?UTF-8?q?refactor(ffi-linkage):=20Phase=209.2c=20?= =?UTF-8?q?=E2=80=94=20rename=20extern-ref=20validators=20=E2=86=92=20Exte?= =?UTF-8?q?rn=20(linkage)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checkForeignRefs→checkExternRefs, validateForeignRefs→validateExternRefs, collectForeignRefTargets→collectExternRefTargets — these police 'extern LIB' library references (linkage axis), so Extern not Runtime. Snapshot-neutral; suite green. --- src/c_import.zig | 14 +++++++------- src/core.zig | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/c_import.zig b/src/c_import.zig index 3610b99..dba7c7b 100644 --- a/src/c_import.zig +++ b/src/c_import.zig @@ -311,7 +311,7 @@ pub fn processCImport( // ── #foreign ref validation ─────────────────────────────────────────── -fn collectForeignRefTargets(valid: *std.StringHashMap(void), decls: []const *Node) !void { +fn collectExternRefTargets(valid: *std.StringHashMap(void), decls: []const *Node) !void { for (decls) |d| { switch (d.data) { .library_decl => |ld| try valid.put(ld.name, {}), @@ -324,14 +324,14 @@ fn collectForeignRefTargets(valid: *std.StringHashMap(void), decls: []const *Nod break; } } - try collectForeignRefTargets(valid, ns.decls); + try collectExternRefTargets(valid, ns.decls); }, else => {}, } } } -fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node, diags: *@import("errors.zig").DiagnosticList) void { +fn checkExternRefs(valid: *const std.StringHashMap(void), decls: []const *Node, diags: *@import("errors.zig").DiagnosticList) void { for (decls) |d| { switch (d.data) { .fn_decl => |fd| { @@ -343,7 +343,7 @@ fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node, diags.addFmt(.err, d.span, "extern library '{s}' is not declared; expected a #library constant or a named '#import c' unit", .{ref}); } }, - .namespace_decl => |ns| checkForeignRefs(valid, ns.decls, diags), + .namespace_decl => |ns| checkExternRefs(valid, ns.decls, diags), else => {}, } } @@ -355,12 +355,12 @@ fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node, /// namespaced into one tree, so existence is checked program-wide. /// Decls synthesized from `#include` headers carry no ref and are /// exempt. -pub fn validateForeignRefs(allocator: std.mem.Allocator, root: *const Node, diags: *@import("errors.zig").DiagnosticList) !void { +pub fn validateExternRefs(allocator: std.mem.Allocator, root: *const Node, diags: *@import("errors.zig").DiagnosticList) !void { if (root.data != .root) return; var valid = std.StringHashMap(void).init(allocator); defer valid.deinit(); - try collectForeignRefTargets(&valid, root.data.root.decls); - checkForeignRefs(&valid, root.data.root.decls, diags); + try collectExternRefTargets(&valid, root.data.root.decls); + checkExternRefs(&valid, root.data.root.decls, diags); } /// A cached entry must at least LOOK like an object file (Mach-O, diff --git a/src/core.zig b/src/core.zig index da0a39f..a182704 100644 --- a/src/core.zig +++ b/src/core.zig @@ -302,7 +302,7 @@ pub const Compilation = struct { // Every `#foreign ` must name a #library constant or a named // `#import c` unit — a typo'd ref otherwise resolves silently // through whatever image happens to carry the symbol. - try c_import.validateForeignRefs(self.allocator, root, &self.diagnostics); + try c_import.validateExternRefs(self.allocator, root, &self.diagnostics); if (self.diagnostics.hasErrors()) return error.CompileError; var module = ir.Module.init(self.allocator);