Skip to content

Commit 1bea320

Browse files
committed
ZJIT: Test for method with positional optional that might have too many args
1 parent 1e33fab commit 1bea320

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

test/ruby/test_zjit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ def entry
765765
}, call_threshold: 2
766766
end
767767

768+
def test_pos_optional_with_maybe_too_many_args
769+
assert_compiles '[[1, 2, 3, 4, 5, 6], [10, 20, 30, 4, 5, 6], [10, 20, 30, 40, 50, 60]]', %q{
770+
def target(a = 1, b = 2, c = 3, d = 4, e = 5, f:) = [a, b, c, d, e, f]
771+
def test = [target(f: 6), target(10, 20, 30, f: 6), target(10, 20, 30, 40, 50, f: 60)]
772+
test
773+
test
774+
}, call_threshold: 2
775+
end
776+
768777
def test_send_all_arg_types
769778
assert_compiles '[:req, :opt, :post, :kwr, :kwo, true]', %q{
770779
def test(a, b = :opt, c, d:, e: :kwo) = [a, b, c, d, e, block_given?]

zjit/src/hir/opt_tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,50 @@ mod hir_opt_tests {
31293129
");
31303130
}
31313131

3132+
#[test]
3133+
fn test_call_with_pos_optional_and_maybe_too_many_args() {
3134+
eval("
3135+
def target(a = 1, b = 2, c = 3, d = 4, e = 5, f:) = [a, b, c, d, e, f]
3136+
def test = [target(f: 6), target(10, 20, 30, f: 6), target(10, 20, 30, 40, 50, f: 60)]
3137+
test
3138+
test
3139+
");
3140+
assert_snapshot!(hir_string("test"), @r"
3141+
fn test@<compiled>:3:
3142+
bb0():
3143+
EntryPoint interpreter
3144+
v1:BasicObject = LoadSelf
3145+
Jump bb2(v1)
3146+
bb1(v4:BasicObject):
3147+
EntryPoint JIT(0)
3148+
Jump bb2(v4)
3149+
bb2(v6:BasicObject):
3150+
v11:Fixnum[6] = Const Value(6)
3151+
PatchPoint NoSingletonClass(Object@0x1000)
3152+
PatchPoint MethodRedefined(Object@0x1000, target@0x1008, cme:0x1010)
3153+
v48:HeapObject[class_exact*:Object@VALUE(0x1000)] = GuardType v6, HeapObject[class_exact*:Object@VALUE(0x1000)]
3154+
v50:BasicObject = SendWithoutBlockDirect v48, :target (0x1038), v11
3155+
v16:Fixnum[10] = Const Value(10)
3156+
v18:Fixnum[20] = Const Value(20)
3157+
v20:Fixnum[30] = Const Value(30)
3158+
v22:Fixnum[6] = Const Value(6)
3159+
PatchPoint NoSingletonClass(Object@0x1000)
3160+
PatchPoint MethodRedefined(Object@0x1000, target@0x1008, cme:0x1010)
3161+
v53:HeapObject[class_exact*:Object@VALUE(0x1000)] = GuardType v6, HeapObject[class_exact*:Object@VALUE(0x1000)]
3162+
v55:BasicObject = SendWithoutBlockDirect v53, :target (0x1038), v16, v18, v20, v22
3163+
v27:Fixnum[10] = Const Value(10)
3164+
v29:Fixnum[20] = Const Value(20)
3165+
v31:Fixnum[30] = Const Value(30)
3166+
v33:Fixnum[40] = Const Value(40)
3167+
v35:Fixnum[50] = Const Value(50)
3168+
v37:Fixnum[60] = Const Value(60)
3169+
v39:BasicObject = SendWithoutBlock v6, :target, v27, v29, v31, v33, v35, v37 # SendFallbackReason: Too many arguments for LIR
3170+
v41:ArrayExact = NewArray v50, v55, v39
3171+
CheckInterrupts
3172+
Return v41
3173+
");
3174+
}
3175+
31323176
#[test]
31333177
fn test_send_call_to_iseq_with_optional_kw() {
31343178
eval("

0 commit comments

Comments
 (0)