Skip to content

Commit 3a76625

Browse files
authored
ZJIT: Don't specialize calls with kwsplat (#15513)
1 parent 1f0ca55 commit 3a76625

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,15 @@ def entry = test(e: :e, d: :d, c: :c, a: :a, b: :b)
626626
}, call_threshold: 2
627627
end
628628

629+
def test_send_kwsplat
630+
assert_compiles '3', %q{
631+
def test(a:) = a
632+
def entry = test(**{a: 3})
633+
entry
634+
entry
635+
}, call_threshold: 2
636+
end
637+
629638
def test_send_kwrest
630639
assert_compiles '{a: 3}', %q{
631640
def test(**kwargs) = kwargs

zjit/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5229,6 +5229,7 @@ fn unspecializable_c_call_type(flags: u32) -> bool {
52295229
/// If a given call uses overly complex arguments, then we won't specialize.
52305230
fn unspecializable_call_type(flags: u32) -> bool {
52315231
((flags & VM_CALL_ARGS_SPLAT) != 0) ||
5232+
((flags & VM_CALL_KW_SPLAT) != 0) ||
52325233
((flags & VM_CALL_ARGS_BLOCKARG) != 0)
52335234
}
52345235

zjit/src/hir/opt_tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,33 @@ mod hir_opt_tests {
29932993
");
29942994
}
29952995

2996+
#[test]
2997+
fn dont_specialize_call_to_iseq_with_call_kwsplat() {
2998+
eval("
2999+
def foo(a:) = a
3000+
def test = foo(**{a: 1})
3001+
test
3002+
test
3003+
");
3004+
assert_snapshot!(hir_string("test"), @r"
3005+
fn test@<compiled>:3:
3006+
bb0():
3007+
EntryPoint interpreter
3008+
v1:BasicObject = LoadSelf
3009+
Jump bb2(v1)
3010+
bb1(v4:BasicObject):
3011+
EntryPoint JIT(0)
3012+
Jump bb2(v4)
3013+
bb2(v6:BasicObject):
3014+
v11:HashExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
3015+
v12:HashExact = HashDup v11
3016+
IncrCounter complex_arg_pass_caller_kw_splat
3017+
v14:BasicObject = SendWithoutBlock v6, :foo, v12 # SendFallbackReason: Complex argument passing
3018+
CheckInterrupts
3019+
Return v14
3020+
");
3021+
}
3022+
29963023
#[test]
29973024
fn dont_specialize_call_to_iseq_with_param_kwrest() {
29983025
eval("

0 commit comments

Comments
 (0)