issues: relocate legacy examples/issue-* repros into issues/
Clear the examples/issue-* namespace (new layout keeps open-issue repros under
issues/, co-located with their .md). Two legacy files:
- issue-0030 was a feature-request placeholder (trivial main, no real test).
`extern G : T;` cross-file sx globals are still unimplemented (parse error),
so it's an open feature request: issues/0030-extern-global-declarations.{md,sx}.
- issue-0019 was a broken/superseded multi-file fixture (relative imports, not
runnable from root; the non-transitive-#import scenario is covered by the
passing 0706-modules-import-non-transitive). Moved to
issues/0019-import-non-transitive-c-scope/ with a status note; safe to delete.
Suite unchanged: 324 passed.
This commit is contained in:
27
issues/0019-import-non-transitive-c-scope.md
Normal file
27
issues/0019-import-non-transitive-c-scope.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# 0019 — `#import` is non-transitive (C-function scope across files)
|
||||
|
||||
> **Status: superseded — kept for reference.** Relocated from the old
|
||||
> `examples/issue-0019/` fixture during the test-layout migration. The behavior
|
||||
> it probed (A imports B and C; C must NOT see B's `#foreign` C functions just
|
||||
> because A imported B) is now covered by the passing test
|
||||
> `examples/0706-modules-import-non-transitive.sx`.
|
||||
|
||||
## What it probed
|
||||
|
||||
`main` imports both `c_wrapper.sx` (which declares C `#foreign` functions) and
|
||||
`other.sx`. `other.sx` should *not* gain access to `c_wrapper`'s C functions
|
||||
transitively — using one should produce the "not visible; #import the module that
|
||||
declares it" diagnostic.
|
||||
|
||||
- `main_good.sx` — the valid arrangement.
|
||||
- `main_bad.sx` — the arrangement that must be rejected.
|
||||
- `c_wrapper.sx`, `other.sx` — the imported modules.
|
||||
|
||||
## Caveat (why it doesn't run as-is)
|
||||
|
||||
The fixture uses **relative** imports (`#import "../modules/std.sx"`), which only
|
||||
resolve relative to a specific working directory and violate the project's
|
||||
"always `package:`/module-path imports, never relative" rule. It is not runnable
|
||||
from the repo root and is not wired into the suite. If revived, rewrite the
|
||||
imports to the standard `modules/...` form and pin expected output; otherwise it
|
||||
can be deleted (the scenario is already covered by `0706-modules-import-non-transitive`).
|
||||
10
issues/0019-import-non-transitive-c-scope/c_wrapper.sx
Normal file
10
issues/0019-import-non-transitive-c-scope/c_wrapper.sx
Normal file
@@ -0,0 +1,10 @@
|
||||
// This module imports C functions and provides wrappers
|
||||
#import c {
|
||||
#include "vendors/test_c/test.h";
|
||||
#source "vendors/test_c/test.c";
|
||||
};
|
||||
|
||||
// Wrapper function that calls the C function
|
||||
wrapped_add :: (a: s32, b: s32) -> s32 {
|
||||
add_numbers(a, b);
|
||||
}
|
||||
18
issues/0019-import-non-transitive-c-scope/main_bad.sx
Normal file
18
issues/0019-import-non-transitive-c-scope/main_bad.sx
Normal file
@@ -0,0 +1,18 @@
|
||||
// Test: other.sx calls C functions without importing the C module
|
||||
// main imports both c_wrapper.sx and other.sx
|
||||
// other.sx should NOT have access to C functions from c_wrapper
|
||||
#import "../modules/std.sx";
|
||||
#import "c_wrapper.sx";
|
||||
#import "other.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
// This works: we import c_wrapper so we have transitive access
|
||||
result := wrapped_add(10, 20);
|
||||
print("wrapped_add(10, 20) = {}\n", result);
|
||||
|
||||
// This calls other.sx's function which tries to call add_numbers
|
||||
// other.sx did NOT import c_wrapper.sx, so this should fail
|
||||
bad := use_c_directly();
|
||||
print("use_c_directly() = {}\n", bad);
|
||||
0;
|
||||
}
|
||||
10
issues/0019-import-non-transitive-c-scope/main_good.sx
Normal file
10
issues/0019-import-non-transitive-c-scope/main_good.sx
Normal file
@@ -0,0 +1,10 @@
|
||||
// Test: calling wrapper functions works (we import the module)
|
||||
#import "../modules/std.sx";
|
||||
#import "c_wrapper.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
// This should work: calling the sx wrapper
|
||||
result := wrapped_add(10, 20);
|
||||
print("wrapped_add(10, 20) = {}\n", result);
|
||||
0;
|
||||
}
|
||||
6
issues/0019-import-non-transitive-c-scope/other.sx
Normal file
6
issues/0019-import-non-transitive-c-scope/other.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file does NOT import c_wrapper.sx
|
||||
// It should NOT be able to call add_numbers
|
||||
|
||||
use_c_directly :: () -> s32 {
|
||||
add_numbers(5, 3);
|
||||
}
|
||||
63
issues/0030-extern-global-declarations.md
Normal file
63
issues/0030-extern-global-declarations.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# 0030 — `extern G : T;` cross-file sx global declarations (feature request)
|
||||
|
||||
> **Status: OPEN feature request** (not a bug). Relocated from the old
|
||||
> `examples/issue-0030.sx` placeholder during the test-layout migration. Repro:
|
||||
> `issues/0030-extern-global-declarations.sx` (currently a parse error — the
|
||||
> syntax doesn't exist yet).
|
||||
|
||||
## Symptom / request
|
||||
|
||||
Support an `extern G : T;` top-level form so a global **defined** in one sx
|
||||
source file can be **referenced** from another without threading it through
|
||||
parameters — mirroring how `#foreign` function declarations work (declared in one
|
||||
place, defined elsewhere, resolved at link time).
|
||||
|
||||
```sx
|
||||
// game/main.sx
|
||||
g_metal_gpu : *MetalGPU = null;
|
||||
|
||||
// game/chess/pieces.sx
|
||||
extern g_metal_gpu : *MetalGPU; // ← parse error today
|
||||
|
||||
load :: (self: *ChessPieces, path: [:0]u8) {
|
||||
inline if OS == .ios {
|
||||
tex := g_metal_gpu.create_texture(w, h, .rgba8, xx pixels);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Today `pieces.load` takes `has_gpu: bool, gpu: GPU` params and `main.sx` threads
|
||||
them through; cross-file `extern` globals would drop that ceremony. Distinct from
|
||||
the existing `name : T #foreign;` form (an *external C* data symbol from
|
||||
libsystem etc. — see `examples/1205-ffi-foreign-global.sx`); this request is for
|
||||
sx-defined globals shared across sx modules.
|
||||
|
||||
## Reproduction
|
||||
|
||||
`issues/0030-extern-global-declarations.sx`:
|
||||
|
||||
```sx
|
||||
#import "modules/std.sx";
|
||||
extern g_x : *void; // want: a reference to a global defined elsewhere
|
||||
main :: () -> s32 { 0; }
|
||||
```
|
||||
|
||||
`./zig-out/bin/sx run …` → `error: expected '::', ':=', or ':' after identifier`
|
||||
(the `extern` keyword/form is unparsed).
|
||||
|
||||
## Implementation sketch
|
||||
|
||||
- **parser** — surface syntax for `extern G : T;`. Must not clash with `G :: T;`
|
||||
(type alias), `G : T = ---;` (uninitialized global), `G : T;` (typed global).
|
||||
Reject `extern G : T = expr;` (an extern can't carry an initializer).
|
||||
- **src/ir/lower.zig** — record an extern-global stub that resolves at
|
||||
module-link time.
|
||||
- **src/ir/emit_llvm.zig** — emit an `external` LLVM global (no storage, just a
|
||||
reference). Globals already have first-class IR addresses; this adds an
|
||||
"extern" flag meaning "emit a reference, not storage."
|
||||
|
||||
## Caveat
|
||||
|
||||
Encourages process-global state. Steer callers toward explicit parameter passing
|
||||
where reasonable; reserve for genuine process singletons (active GPU, active
|
||||
platform) where threading through every call site is more noise than signal.
|
||||
14
issues/0030-extern-global-declarations.sx
Normal file
14
issues/0030-extern-global-declarations.sx
Normal file
@@ -0,0 +1,14 @@
|
||||
// Repro for issue 0030 (OPEN feature request): cross-file sx `extern` globals.
|
||||
// Want: `extern G : T;` declares a reference to a global defined in another sx
|
||||
// file (resolved at link time), mirroring `#foreign` functions. Today this is a
|
||||
// parse error — the form doesn't exist. Distinct from `name : T #foreign;`
|
||||
// (an external C data symbol; see examples/1205-ffi-foreign-global.sx).
|
||||
//
|
||||
// Expected (once implemented): parses; `g_x` resolves to a global defined
|
||||
// elsewhere. Actual: error "expected '::', ':=', or ':' after identifier".
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
extern g_x : *void;
|
||||
|
||||
main :: () -> s32 { 0; }
|
||||
Reference in New Issue
Block a user