summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bernstein <[email protected]>2025-06-30 17:43:50 -0400
committerGitHub <[email protected]>2025-06-30 14:43:50 -0700
commit90247fb77d4b99a55ba321d89eccaa5de1eda3b7 (patch)
treef61d6a6053852c01e6b05396e3d31e8bd5ea58da
parent99360e500ddec455612a7b3e776352971268ac77 (diff)
ZJIT: Don't compile functions with unhandled parameter types (#13749)
-rw-r--r--test/ruby/test_zjit.rb1
-rw-r--r--zjit/src/hir.rs17
2 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index d9130c3116..823fb8e043 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -118,6 +118,7 @@ class TestZJIT < Test::Unit::TestCase
end
def test_invokebuiltin
+ omit 'Test fails at the moment due to not handling optional parameters'
assert_compiles '["."]', %q{
def test = Dir.glob(".")
test
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index b5ad8b48b1..bba3b183a0 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -2187,8 +2187,14 @@ pub enum CallType {
}
#[derive(Debug, PartialEq)]
+pub enum ParameterType {
+ Optional,
+}
+
+#[derive(Debug, PartialEq)]
pub enum ParseError {
StackUnderflow(FrameState),
+ UnknownParameterType(ParameterType),
MalformedIseq(u32), // insn_idx into iseq_encoded
}
@@ -2248,8 +2254,14 @@ impl ProfileOracle {
/// The index of the self parameter in the HIR function
pub const SELF_PARAM_IDX: usize = 0;
+fn filter_unknown_parameter_type(iseq: *const rb_iseq_t) -> Result<(), ParseError> {
+ if unsafe { rb_get_iseq_body_param_opt_num(iseq) } != 0 { return Err(ParseError::UnknownParameterType(ParameterType::Optional)); }
+ Ok(())
+}
+
/// Compile ISEQ into High-level IR
pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
+ filter_unknown_parameter_type(iseq)?;
let payload = get_or_create_iseq_payload(iseq);
let mut profiles = ProfileOracle::new(payload);
let mut fun = Function::new(iseq);
@@ -3227,6 +3239,11 @@ mod tests {
assert_eq!(result.unwrap_err(), reason);
}
+ #[test]
+ fn test_cant_compile_optional() {
+ eval("def test(x=1) = 123");
+ assert_compile_fails("test", ParseError::UnknownParameterType(ParameterType::Optional));
+ }
#[test]
fn test_putobject() {