lang 2.4: parameterized-protocol method calls on pack elements
`xs[i].get()` on a parameterised `..xs: Box(T)` pack now resolves — the canonical `ValueListenable` shape. registerParamImpl, for a CONCRETE-struct source, now also registers the impl's methods as `<Source>.<method>` in fn_ast_map (like a non-parameterised impl), so UFCS finds them. Such methods are already fully concrete (`impl Box(s64) for IntCell` → `get(self: *IntCell) -> s64`), so there's nothing to monomorphize; generic/pack sources stay lazy in param_impl_map. First impl wins on a name collision. Heterogeneous parameterised packs work: each `xs[i]` binds a different T and dispatches to its own impl. Regression: examples/194-protocol-pack-parameterized.sx (Box(s64) IntCell + Box(string) StrCell, order-independent).
This commit is contained in:
@@ -11633,7 +11633,7 @@ pub const Lowering = struct {
|
||||
// Methods are NOT registered in fn_ast_map — they're monomorphised lazily
|
||||
// per (Source, Target) pair at the xx call site.
|
||||
if (ib.protocol_type_args.len > 0) {
|
||||
self.registerParamImpl(ib, decl);
|
||||
self.registerParamImpl(ib, decl, is_imported);
|
||||
return;
|
||||
}
|
||||
// Collect explicitly implemented method names
|
||||
@@ -11674,7 +11674,7 @@ pub const Lowering = struct {
|
||||
/// `pack_start != null`) are additionally registered into
|
||||
/// `param_impl_pack_map` keyed without the source suffix — the matching
|
||||
/// site walks that map to bind packs against any concrete closure shape.
|
||||
fn registerParamImpl(self: *Lowering, ib: *const ast.ImplBlock, decl: *const Node) void {
|
||||
fn registerParamImpl(self: *Lowering, ib: *const ast.ImplBlock, decl: *const Node, is_imported: bool) void {
|
||||
const table = &self.module.types;
|
||||
|
||||
// Resolve the protocol's type-arg list to concrete TypeIds.
|
||||
@@ -11743,6 +11743,26 @@ pub const Lowering = struct {
|
||||
}
|
||||
gop.value_ptr.append(self.alloc, entry) catch return;
|
||||
|
||||
// Concrete-struct source: also register the impl's methods as
|
||||
// `<Source>.<method>` in fn_ast_map so UFCS resolves them (e.g.
|
||||
// `xs[i].get()` on a pack element). For a concrete impl like
|
||||
// `impl Box(s64) for IntCell`, the method is already fully concrete —
|
||||
// nothing to monomorphize, unlike generic/pack sources (which stay
|
||||
// lazy in param_impl_map and are handled below).
|
||||
{
|
||||
const si = table.get(src_ty);
|
||||
if (!src_ty.isBuiltin() and si == .@"struct") {
|
||||
const src_name = self.formatTypeName(src_ty);
|
||||
for (methods.items) |mfd| {
|
||||
const q = std.fmt.allocPrint(self.alloc, "{s}.{s}", .{ src_name, mfd.name }) catch continue;
|
||||
if (self.fn_ast_map.contains(q)) continue; // first impl wins
|
||||
self.fn_ast_map.put(q, mfd) catch {};
|
||||
self.import_flags.put(q, is_imported) catch {};
|
||||
self.declareFunction(mfd, q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pack-shaped source: also register in the pack map. The source
|
||||
// closure carries `pack_start` set; matching binds the source's
|
||||
// tail param types to the pack-name and the source's return to
|
||||
|
||||
Reference in New Issue
Block a user