Skip to content

Fix allocationless anonymous splat keyword argument check#15383

Merged
jeremyevans merged 1 commit intoruby:masterfrom
jeremyevans:allocationless-anonymous-positional-splat-21757
Dec 9, 2025
Merged

Fix allocationless anonymous splat keyword argument check#15383
jeremyevans merged 1 commit intoruby:masterfrom
jeremyevans:allocationless-anonymous-positional-splat-21757

Conversation

@jeremyevans
Copy link
Contributor

Previously, if an argument splat and keywords are provided by the caller, it did not check whether the method/proc accepted keywords before avoiding the allocation. This is incorrect, because if the method/proc does not accept keywords, the keywords passed by the caller are added as a positional argument, so there must be an allocation to avoid mutating the positional splat argument.

Add a check that if the caller passes keywords, the method/proc must accept keywords in order to optimize. If the caller passes a keyword splat, either the
method/proc must accept keywords, or the keyword splat must be empty in order to optimize.

If keywords are explicitly disallowed via **nil, the optimization should be skipped, because the array is mutated before the ArgumentError exception is raised.

In addition to a test for the correct behavior, add an allocation test for a method that accepts an anonymous splat without keywords.

Fixes [Bug #21757]

@jeremyevans jeremyevans requested a review from nobu December 3, 2025 05:36
@launchable-app

This comment has been minimized.

@apotonick
Copy link

Ha, hey @jeremyevans 🍻 long time no chat! Thanks for the quick fix! 💚 Good to see you're around here!

Previously, if an argument splat and keywords are provided by
the caller, it did not check whether the method/proc accepted
keywords before avoiding the allocation. This is incorrect,
because if the method/proc does not accept keywords, the
keywords passed by the caller are added as a positional
argument, so there must be an allocation to avoid mutating
the positional splat argument.

Add a check that if the caller passes keywords, the
method/proc must accept keywords in order to optimize.
If the caller passes a keyword splat, either the
method/proc must accept keywords, or the keyword splat must
be empty in order to optimize.

If keywords are explicitly disallowed via `**nil`, the
optimization should be skipped, because the array is mutated
before the ArgumentError exception is raised.

In addition to a test for the correct behavior, add an
allocation test for a method that accepts an anonymous splat
without keywords.

Fixes [Bug #21757]
@jeremyevans jeremyevans force-pushed the allocationless-anonymous-positional-splat-21757 branch from 32a3c20 to c39c4b2 Compare December 9, 2025 18:26
@jeremyevans jeremyevans merged commit 6409715 into ruby:master Dec 9, 2025
96 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants