Skip to content

Commit c0e01a2

Browse files
authored
ZJIT: Compile ISEQs with forwardable parameters (ruby#14491)
1 parent 928fea3 commit c0e01a2

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

test/ruby/test_zjit.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,21 @@ def entry = [test(1), test(3, 4)]
439439
}, call_threshold: 2
440440
end
441441

442+
def test_forwardable_iseq
443+
assert_compiles '1', %q{
444+
def test(...) = 1
445+
test
446+
}
447+
end
448+
449+
def test_sendforward
450+
assert_runs '[1, 2]', %q{
451+
def callee(a, b) = [a, b]
452+
def test(...) = callee(...)
453+
test(1, 2)
454+
}, insns: [:sendforward]
455+
end
456+
442457
def test_iseq_with_optional_arguments
443458
assert_compiles '[[1, 2], [3, 4]]', %q{
444459
def test(a, b = 2) = [a, b]

zjit/src/hir.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,17 +2965,9 @@ pub enum CallType {
29652965
Forwarding,
29662966
}
29672967

2968-
#[derive(Clone, Debug, PartialEq)]
2969-
pub enum ParameterType {
2970-
/// For example, `foo(...)`. Interaction of JIT
2971-
/// calling convention and side exits currently unsolved.
2972-
Forwardable,
2973-
}
2974-
29752968
#[derive(Clone, Debug, PartialEq)]
29762969
pub enum ParseError {
29772970
StackUnderflow(FrameState),
2978-
UnknownParameterType(ParameterType),
29792971
MalformedIseq(u32), // insn_idx into iseq_encoded
29802972
Validation(ValidationError),
29812973
NotAllowed,
@@ -3049,17 +3041,11 @@ impl ProfileOracle {
30493041
/// The index of the self parameter in the HIR function
30503042
pub const SELF_PARAM_IDX: usize = 0;
30513043

3052-
fn filter_unknown_parameter_type(iseq: *const rb_iseq_t) -> Result<(), ParseError> {
3053-
if unsafe { rb_get_iseq_flags_forwardable(iseq) } { return Err(ParseError::UnknownParameterType(ParameterType::Forwardable)); }
3054-
Ok(())
3055-
}
3056-
30573044
/// Compile ISEQ into High-level IR
30583045
pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
30593046
if !ZJITState::can_compile_iseq(iseq) {
30603047
return Err(ParseError::NotAllowed);
30613048
}
3062-
filter_unknown_parameter_type(iseq)?;
30633049
let payload = get_or_create_iseq_payload(iseq);
30643050
let mut profiles = ProfileOracle::new(payload);
30653051
let mut fun = Function::new(iseq);
@@ -5198,13 +5184,23 @@ mod tests {
51985184
eval("
51995185
def test(...) = super(...)
52005186
");
5201-
assert_compile_fails("test", ParseError::UnknownParameterType(ParameterType::Forwardable));
5187+
assert_snapshot!(hir_string("test"), @r"
5188+
fn test@<compiled>:2:
5189+
bb0(v0:BasicObject, v1:BasicObject):
5190+
SideExit UnhandledYARVInsn(invokesuperforward)
5191+
");
52025192
}
52035193

52045194
#[test]
5205-
fn test_cant_compile_forwardable() {
5195+
fn test_compile_forwardable() {
52065196
eval("def forwardable(...) = nil");
5207-
assert_compile_fails("forwardable", ParseError::UnknownParameterType(ParameterType::Forwardable));
5197+
assert_snapshot!(hir_string("forwardable"), @r"
5198+
fn forwardable@<compiled>:1:
5199+
bb0(v0:BasicObject, v1:BasicObject):
5200+
v5:NilClass = Const Value(nil)
5201+
CheckInterrupts
5202+
Return v5
5203+
");
52085204
}
52095205

52105206
// TODO(max): Figure out how to generate a call with OPT_SEND flag
@@ -5249,7 +5245,11 @@ mod tests {
52495245
eval("
52505246
def test(...) = foo(...)
52515247
");
5252-
assert_compile_fails("test", ParseError::UnknownParameterType(ParameterType::Forwardable));
5248+
assert_snapshot!(hir_string("test"), @r"
5249+
fn test@<compiled>:2:
5250+
bb0(v0:BasicObject, v1:BasicObject):
5251+
SideExit UnhandledYARVInsn(sendforward)
5252+
");
52535253
}
52545254

52555255
#[test]

zjit/src/stats.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ make_counters! {
130130
compile_error_parse_malformed_iseq,
131131
compile_error_parse_validation,
132132
compile_error_parse_not_allowed,
133-
compile_error_parse_parameter_type_forwardable,
134133

135134
// The number of times YARV instructions are executed on JIT code
136135
zjit_insn_count,
@@ -196,7 +195,6 @@ pub enum CompileError {
196195
/// Return a raw pointer to the exit counter for a given CompileError
197196
pub fn exit_counter_for_compile_error(compile_error: &CompileError) -> Counter {
198197
use crate::hir::ParseError::*;
199-
use crate::hir::ParameterType::*;
200198
use crate::stats::CompileError::*;
201199
use crate::stats::Counter::*;
202200
match compile_error {
@@ -210,9 +208,6 @@ pub fn exit_counter_for_compile_error(compile_error: &CompileError) -> Counter {
210208
MalformedIseq(_) => compile_error_parse_malformed_iseq,
211209
Validation(_) => compile_error_parse_validation,
212210
NotAllowed => compile_error_parse_not_allowed,
213-
UnknownParameterType(parameter_type) => match parameter_type {
214-
Forwardable => compile_error_parse_parameter_type_forwardable,
215-
}
216211
}
217212
}
218213
}

0 commit comments

Comments
 (0)