Commit 71972a24
71972a243064Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 7 files · +2 added · ~5 modified
Description
Forward ... positional and keyword args (incl. chained) via synth params
def foo(...); bar(...); end was unsupported: the parser emits a
ForwardingParameterNode / ForwardingArgumentsNode that no pass lowered, and
the prerequisite *rest/**kw/&block forwarding machinery is broken in several
interacting ways (inliner mis-binds rest params, splat-into-typed-param
needs unboxing, etc.).
... is pure pass-through, so model it that way instead of going through the
rest/splat machinery: the compiler already knows the args a method receives.
For def foo(...), synthesize concrete params -- positional __fwd_0.. (arity
from foo's call sites) plus one named after each forwarded keyword (keyword
params compile to positional C params mapped by name, so a key-named param
carries the kwarg). The normal call-site inference types them, and bar(...)
emits a direct positional forward of those params. No rest array, no splat,
no unboxing.
A forwarding method reached only through another f(...) forward has no
concrete call site; a fixpoint pass (topup_forwarding_arity) raises its arity
to its forwarding target's, so chained h(...) -> f(...) -> g(a,b) works.
Sites: collect_def_params synthesizes the params; topup_forwarding_arity propagates arity through forward chains; bind_call_params seeds the callee's params from the enclosing method's; the two call-arg emitters (emit_args_filled, emit_dispatch) forward the synth params. Covers free-function, instance-method and class-method forwarding, multiple call sites, positional + keyword args, and chained forwards.
Block forwarding (needs the &block-method definition-emission fix) is not yet covered -- it fails to compile (loud), not silently. Refs #1288.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 71972a243064
- Parent
- 0b176e83033d
src/analyze.cmodifiedView file
register_globals_consts(c); rewrite_const_alias_receivers(c); register_ffi_decls(c); topup_forwarding_arity(c); /* rescue variables (`rescue => e`) are typed as exception objects. When the arm names exactly one user exception subclass that carries ivars, type thesrc/analyze_internal.hmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/analyze_scope.cmodifiedView file
Loading diff…
src/codegen_fold.cmodifiedView file
Loading diff…
test/forward_args.rbaddedView file
Loading diff…
test/forward_args.rb.expectedaddedView file
Loading diff…