From ce3c2fe7bdf065e2cad1aadd43dd9ff1167ac180 Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 27 May 2026 12:50:23 +0300 Subject: [PATCH] =?UTF-8?q?ffi=20M5.A.next.1d.A:=20pack=20impl=20matching?= =?UTF-8?q?=20=E2=80=94=20lock=20in=20concrete-only=20miss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 1d lock-in test pinning today's matching behaviour. `registerParamImpl` records every impl in `param_impl_map` keyed by `"Proto\x00\x00"`. For a pack impl `Into(Block) for Closure(..$args) -> $R` the key contains the pack-shaped closure's mangle (interns with `pack_start = Some(0)` after 1c.B). At the `xx cl : *Block` site the lookup mangles the concrete `Closure(s32, bool) -> bool` source and finds nothing — the existing focused diagnostic fires: no `Into(Block) for cl_s32_bool__bool` impl — add a per-signature `__block_invoke_` trampoline + Into impl alongside the existing ones in modules/std/objc_block.sx, or declare it in your own code The pack impl is reachable in the file but never considered. Next commit (1d.B): - New `param_impl_pack_map` keyed by `"Proto\x00"` (no src) — populated by `registerParamImpl` when the source is pack-shaped. - `tryUserConversion` walks the pack map on concrete-key miss. Pack shape matches when the impl's fixed prefix equals the source's matching prefix; the remainder binds to `$args` and the source's return type binds to `$R`. Concrete impls win over pack impls (specificity). - `resolveTypeWithBindings` learns the closure_type_expr path so the impl body's `self: Closure(..$args) -> $R` substitutes to the concrete source closure during monomorphisation. The `Closure(s32, bool) -> bool` shape is not covered by stdlib or 96-block-multi-arg's hand-rolled impls, so the pack impl is the only candidate post-1d.B. 193/193 example tests + `zig build test` green. --- examples/155-pack-impl-match.sx | 46 +++++++++++++++++++++++++ tests/expected/155-pack-impl-match.exit | 1 + tests/expected/155-pack-impl-match.txt | 1 + 3 files changed, 48 insertions(+) create mode 100644 examples/155-pack-impl-match.sx create mode 100644 tests/expected/155-pack-impl-match.exit create mode 100644 tests/expected/155-pack-impl-match.txt diff --git a/examples/155-pack-impl-match.sx b/examples/155-pack-impl-match.sx new file mode 100644 index 0000000..892a0d2 --- /dev/null +++ b/examples/155-pack-impl-match.sx @@ -0,0 +1,46 @@ +// Variadic heterogeneous type packs — `..$args` — impl matching +// lock-in. +// +// Step 1d slice for the pack feature (see +// ~/.claude/plans/lets-see-options-for-merry-dijkstra.md). Pins +// today's concrete-only impl-matching behaviour: a user-declared +// `impl Into(Block) for Closure(..$args) -> $R` does NOT match +// any concrete closure source type. The xx cast site hits the +// existing "no `Into(Block) for ` impl" diagnostic even +// though the pack impl is reachable. +// +// Next commit (1d.B) teaches `tryUserConversion` / +// `registerParamImpl` to walk a second `param_impl_pack_map` +// when the concrete-key miss happens. Pack impls bind their +// `$args` and `$R` to the concrete source closure's tail types +// and return; monomorphisation proceeds against those bindings. +// +// The `Closure(s32, bool) -> bool` shape is not covered by +// stdlib's hand-rolled impls (only `Closure() -> void` and +// `Closure(bool) -> void`) and not covered by 96-block-multi-arg's +// `Closure(s32, *void) -> void` impl, so the pack impl is the +// only candidate. + +#import "modules/std.sx"; +#import "modules/std/objc_block.sx"; + +impl Into(Block) for Closure(..$args) -> $R { + convert :: (self: Closure(..$args) -> $R) -> Block { + .{ + isa = @_NSConcreteStackBlock, + flags = 0, + reserved = 0, + invoke = null, + descriptor = xx @__sx_block_descriptor, + sx_env = self.env, + sx_fn = self.fn_ptr, + }; + } +} + +main :: () -> s32 { + cl := (a: s32, b: bool) => true; + b : *Block = xx cl; + print("pack impl match ok\n"); + return 0; +} diff --git a/tests/expected/155-pack-impl-match.exit b/tests/expected/155-pack-impl-match.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/155-pack-impl-match.exit @@ -0,0 +1 @@ +1 diff --git a/tests/expected/155-pack-impl-match.txt b/tests/expected/155-pack-impl-match.txt new file mode 100644 index 0000000..47b309a --- /dev/null +++ b/tests/expected/155-pack-impl-match.txt @@ -0,0 +1 @@ +/Users/agra/projects/sx/examples/155-pack-impl-match.sx:43:21: error: no `Into(Block) for cl_s32_bool__bool` impl — add a per-signature `__block_invoke_` trampoline + Into impl alongside the existing ones in modules/std/objc_block.sx, or declare it in your own code