refactor(ffi-linkage): Phase 8 pre-cutover — migrate keyword-neutral diagnostic tests
Migrate the two #foreign-bearing diagnostic tests whose assertions survive the cutover, with INTENTIONAL snapshot regens (reviewed): - 1172 (foreign-symbol-conflict): decl '#foreign libc "getenv"' → 'extern libc "getenv"'. Still tests the dup-C-symbol conflict; the 'foreign symbol already bound' message is the keyword-neutral INTERNAL wording (renamed to 'extern symbol' in Phase 9.1), so it persists — only the echoed source line + caret moved. - 1228 (non-transitive C-import visibility): its identity was the #foreign≡extern equivalence lock, now historical (structural via the A→B gate + unified AST). The identifier 'c_foreign_abs' itself contained 'foreign' (would fail the Phase 9.4 gate), so converted c.sx/b.sx/main to two foreign-free extern symbols (c_abs_one/c_abs_two); still pins per-symbol non-transitive visibility. Reverted the orthogonal 0→1-byte empty-stdout normalization on 1228/1231 (known writeGolden idempotency quirk, not a behavior change). Suite green (647/444).
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
libc :: #library "c";
|
||||
// std/process.sx already binds getenv as `-> *u8`; this view disagrees.
|
||||
getenv_opt :: (name: [:0]u8) -> ?[:0]u8 #foreign libc "getenv";
|
||||
getenv_opt :: (name: [:0]u8) -> ?[:0]u8 extern libc "getenv";
|
||||
|
||||
main :: () -> i32 {
|
||||
p := getenv_opt("PATH");
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
// `#import` is non-transitive for C-import functions: main imports b,
|
||||
// b imports c, so main must NOT see c's lib-less `#foreign` / `extern`
|
||||
// C functions directly. Referencing either is rejected by the
|
||||
// C-import visibility gate (lower/decl.zig `c_import_bare`).
|
||||
//
|
||||
// Equivalence lock (FFI-linkage Part B): the legacy `#foreign` form and
|
||||
// the new `extern` keyword are two spellings of the same lib-less
|
||||
// C-symbol import, so they must produce the SAME "C function not
|
||||
// visible" diagnostic — not the generic top-level-name wording. This
|
||||
// pins that equivalence as a prerequisite for migrating the fn-decl
|
||||
// `#foreign` path onto `extern`.
|
||||
// b imports c, so main must NOT see c's lib-less `extern` C functions
|
||||
// directly. Referencing either is rejected by the C-import visibility
|
||||
// gate (lower/decl.zig `c_import_bare`) with a C-specific "not visible"
|
||||
// diagnostic — not the generic top-level-name wording. Two distinct
|
||||
// extern symbols pin that the gate fires per-symbol.
|
||||
#import "modules/std.sx";
|
||||
#import "1228-ffi-extern-c-non-transitive/b.sx";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("{}\n", c_foreign_abs(-3));
|
||||
print("{}\n", c_extern_abs(-4));
|
||||
print("{}\n", c_abs_one(-3));
|
||||
print("{}\n", c_abs_two(-4));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
#import "c.sx";
|
||||
|
||||
b_use :: () -> i32 {
|
||||
return c_foreign_abs(-1) + c_extern_abs(-2);
|
||||
return c_abs_one(-1) + c_abs_two(-2);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Two spellings of the same lib-less C-symbol import: the legacy
|
||||
// `#foreign` form and the new `extern` keyword. Both declare a C
|
||||
// function resolved at link time with no library reference. The
|
||||
// FFI-linkage migration (Part B) requires the two to be policed
|
||||
// IDENTICALLY by the non-transitive C-import visibility gate.
|
||||
c_foreign_abs :: (x: i32) -> i32 #foreign;
|
||||
c_extern_abs :: (x: i32) -> i32 extern;
|
||||
// Two lib-less `extern` C-symbol imports: each declares a C function
|
||||
// resolved at link time with no library reference. Both are policed by
|
||||
// the non-transitive C-import visibility gate, per-symbol.
|
||||
c_abs_one :: (x: i32) -> i32 extern;
|
||||
c_abs_two :: (x: i32) -> i32 extern;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: foreign symbol 'getenv' is already bound with a different signature; two views of one C symbol must declare identical types
|
||||
--> examples/1172-diagnostics-foreign-symbol-conflict.sx:9:41
|
||||
--> examples/1172-diagnostics-foreign-symbol-conflict.sx:9:61
|
||||
|
|
||||
9 | getenv_opt :: (name: [:0]u8) -> ?[:0]u8 #foreign libc "getenv";
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
9 | getenv_opt :: (name: [:0]u8) -> ?[:0]u8 extern libc "getenv";
|
||||
| ^
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error: C function 'c_foreign_abs' not visible; add #import for the module that declares it
|
||||
--> examples/1228-ffi-extern-c-non-transitive.sx:16:19
|
||||
error: C function 'c_abs_one' not visible; add #import for the module that declares it
|
||||
--> examples/1228-ffi-extern-c-non-transitive.sx:11:19
|
||||
|
|
||||
16 | print("{}\n", c_foreign_abs(-3));
|
||||
| ^^^^^^^^^^^^^
|
||||
11 | print("{}\n", c_abs_one(-3));
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: C function 'c_extern_abs' not visible; add #import for the module that declares it
|
||||
--> examples/1228-ffi-extern-c-non-transitive.sx:17:19
|
||||
error: C function 'c_abs_two' not visible; add #import for the module that declares it
|
||||
--> examples/1228-ffi-extern-c-non-transitive.sx:12:19
|
||||
|
|
||||
17 | print("{}\n", c_extern_abs(-4));
|
||||
| ^^^^^^^^^^^^
|
||||
12 | print("{}\n", c_abs_two(-4));
|
||||
| ^^^^^^^^^
|
||||
|
||||
Reference in New Issue
Block a user