Skip to content

Commit d9181ba

Browse files
committed
ZJIT: Inline methods with rest parameters
1 parent 47292b0 commit d9181ba

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

zjit/src/codegen_tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6693,6 +6693,19 @@ fn test_inlined_method_returns_correct_value() {
66936693
});
66946694
}
66956695

6696+
#[test]
6697+
fn test_inlined_method_with_rest_parameter() {
6698+
with_inlining(|| {
6699+
assert_snapshot!(assert_inlines("
6700+
def add_rest(*rest) = rest[0] + rest[1]
6701+
def test = add_rest(1, 2)
6702+
6703+
test
6704+
test
6705+
"), @"3");
6706+
});
6707+
}
6708+
66966709
#[test]
66976710
fn test_inlined_method_deoptimizes_on_redefinition() {
66986711
with_inlining(|| {

zjit/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,11 +4951,11 @@ impl Function {
49514951
fn can_inline(callee_iseq: IseqPtr) -> bool {
49524952
// Inline callees with required, optional, post-required positional, keyword, and
49534953
// block parameters, including callees that dispatch to a passed block with `yield`.
4954-
// Rest params, double-splat (kwrest), and forwardable params stay out of the
4955-
// general inliner for now; rest-aware direct sends are still handled by codegen.
4954+
// Double-splat (kwrest) and forwardable params stay out of the general
4955+
// inliner for now. Rest params are already normalized to a packed Array by
4956+
// prepare_direct_send_args, so the inliner can map that Array to the rest local.
49564957
let params = unsafe { callee_iseq.params() };
4957-
if params.flags.has_rest() != 0
4958-
|| params.flags.forwardable() != 0
4958+
if params.flags.forwardable() != 0
49594959
|| params.flags.has_kwrest() != 0
49604960
{
49614961
incr_counter!(inline_reject_complex_params);

zjit/src/hir/opt_tests.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ mod hir_opt_tests {
2626
hir_string_proc(&format!("{}.method(:{})", "self", method))
2727
}
2828

29+
// Keep tests for rest-aware SendDirect snapshots focused on argument packing
30+
// even though rest callees are now eligible for the general inliner.
31+
#[track_caller]
32+
fn hir_string_without_inlining(method: &str) -> String {
33+
let old_threshold = get_option!(inline_threshold);
34+
unsafe { OPTIONS.as_mut().unwrap().inline_threshold = 0; }
35+
let result = hir_string(method);
36+
unsafe { OPTIONS.as_mut().unwrap().inline_threshold = old_threshold; }
37+
result
38+
}
39+
2940
#[test]
3041
fn test_fold_iftrue_away() {
3142
eval("
@@ -4008,7 +4019,7 @@ mod hir_opt_tests {
40084019
test
40094020
test
40104021
");
4011-
assert_snapshot!(hir_string("test"), @"
4022+
assert_snapshot!(hir_string_without_inlining("test"), @"
40124023
fn test@<compiled>:3:
40134024
bb1():
40144025
EntryPoint interpreter
@@ -4039,7 +4050,7 @@ mod hir_opt_tests {
40394050
test
40404051
test
40414052
");
4042-
assert_snapshot!(hir_string("test"), @"
4053+
assert_snapshot!(hir_string_without_inlining("test"), @"
40434054
fn test@<compiled>:3:
40444055
bb1():
40454056
EntryPoint interpreter
@@ -4074,7 +4085,7 @@ mod hir_opt_tests {
40744085
test
40754086
test
40764087
");
4077-
assert_snapshot!(hir_string("test"), @"
4088+
assert_snapshot!(hir_string_without_inlining("test"), @"
40784089
fn test@<compiled>:3:
40794090
bb1():
40804091
EntryPoint interpreter
@@ -4105,7 +4116,7 @@ mod hir_opt_tests {
41054116
test
41064117
test
41074118
");
4108-
assert_snapshot!(hir_string("test"), @"
4119+
assert_snapshot!(hir_string_without_inlining("test"), @"
41094120
fn test@<compiled>:3:
41104121
bb1():
41114122
EntryPoint interpreter
@@ -4136,7 +4147,7 @@ mod hir_opt_tests {
41364147
test
41374148
test
41384149
");
4139-
assert_snapshot!(hir_string("test"), @"
4150+
assert_snapshot!(hir_string_without_inlining("test"), @"
41404151
fn test@<compiled>:3:
41414152
bb1():
41424153
EntryPoint interpreter
@@ -4168,7 +4179,7 @@ mod hir_opt_tests {
41684179
test
41694180
test
41704181
");
4171-
assert_snapshot!(hir_string("test"), @"
4182+
assert_snapshot!(hir_string_without_inlining("test"), @"
41724183
fn test@<compiled>:3:
41734184
bb1():
41744185
EntryPoint interpreter
@@ -4199,7 +4210,7 @@ mod hir_opt_tests {
41994210
test
42004211
test
42014212
");
4202-
assert_snapshot!(hir_string("test"), @"
4213+
assert_snapshot!(hir_string_without_inlining("test"), @"
42034214
fn test@<compiled>:3:
42044215
bb1():
42054216
EntryPoint interpreter
@@ -4230,7 +4241,7 @@ mod hir_opt_tests {
42304241
test
42314242
test
42324243
");
4233-
assert_snapshot!(hir_string("test"), @"
4244+
assert_snapshot!(hir_string_without_inlining("test"), @"
42344245
fn test@<compiled>:3:
42354246
bb1():
42364247
EntryPoint interpreter

0 commit comments

Comments
 (0)