From 719a7726d17f0800b8f8ef42f3f48e7558d5a444 Mon Sep 17 00:00:00 2001 From: Jimmy Miller Date: Tue, 7 Mar 2023 12:29:59 -0500 Subject: YJIT: Handle special case of splat and rest lining up (#7422) If you have a method that takes rest arguments and a splat call that happens to line up perfectly with that rest, you can just dupe the array rather than move anything around. We still have to dupe, because people could have a custom to_a method or something like that which means it is hard to guarantee we have exclusive access to that array. Example: ```ruby def foo(a, b, *rest) end foo(1, 2, *[3, 4]) ``` --- bootstraptest/test_yjit.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 7c2a50c4e0..d7dd0cd460 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -3632,3 +3632,25 @@ assert_normal_exit %q{ entry } + +# Test that splat and rest combined +# properly dupe the array +assert_equal "[]", %q{ + def foo(*rest) + rest << 1 + end + + def test(splat) + foo(*splat) + end + + EMPTY = [] + custom = Object.new + def custom.to_a + EMPTY + end + + test(custom) + test(custom) + EMPTY +} -- cgit v1.2.1