Skip to content

Commit c197707

Browse files
committed
ZJIT: Add HIR tests for block arg nil and non-nil
1 parent c9ae44e commit c197707

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

zjit/src/hir/opt_tests.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8193,6 +8193,68 @@ mod hir_opt_tests {
81938193
");
81948194
}
81958195

8196+
#[test]
8197+
fn test_optimize_send_with_non_nil_block_arg() {
8198+
eval(r#"
8199+
def foo = 42
8200+
8201+
def test
8202+
block = :to_s
8203+
foo(&block)
8204+
end
8205+
test; test
8206+
"#);
8207+
assert_snapshot!(hir_string("test"), @"
8208+
fn test@<compiled>:5:
8209+
bb1():
8210+
EntryPoint interpreter
8211+
v1:BasicObject = LoadSelf
8212+
v2:NilClass = Const Value(nil)
8213+
Jump bb3(v1, v2)
8214+
bb2():
8215+
EntryPoint JIT(0)
8216+
v5:BasicObject = LoadArg :self@0
8217+
v6:NilClass = Const Value(nil)
8218+
Jump bb3(v5, v6)
8219+
bb3(v8:BasicObject, v9:NilClass):
8220+
v13:StaticSymbol[:to_s] = Const Value(VALUE(0x1000))
8221+
v19:BasicObject = Send v8, &block, :foo, v13 # SendFallbackReason: Complex argument passing
8222+
CheckInterrupts
8223+
Return v19
8224+
");
8225+
}
8226+
8227+
#[test]
8228+
fn test_optimize_send_with_nil_block_arg() {
8229+
eval(r#"
8230+
def foo = 42
8231+
8232+
def test
8233+
block = nil
8234+
foo(&block)
8235+
end
8236+
test; test
8237+
"#);
8238+
assert_snapshot!(hir_string("test"), @"
8239+
fn test@<compiled>:5:
8240+
bb1():
8241+
EntryPoint interpreter
8242+
v1:BasicObject = LoadSelf
8243+
v2:NilClass = Const Value(nil)
8244+
Jump bb3(v1, v2)
8245+
bb2():
8246+
EntryPoint JIT(0)
8247+
v5:BasicObject = LoadArg :self@0
8248+
v6:NilClass = Const Value(nil)
8249+
Jump bb3(v5, v6)
8250+
bb3(v8:BasicObject, v9:NilClass):
8251+
v13:NilClass = Const Value(nil)
8252+
v19:BasicObject = Send v8, &block, :foo, v13 # SendFallbackReason: Complex argument passing
8253+
CheckInterrupts
8254+
Return v19
8255+
");
8256+
}
8257+
81968258
#[test]
81978259
fn test_inline_attr_reader_constant() {
81988260
eval("

0 commit comments

Comments
 (0)