Skip to content

Commit 899f5da

Browse files
committed
Add initial test
1 parent 220619a commit 899f5da

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

zjit/src/hir/opt_tests.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12084,4 +12084,54 @@ mod hir_opt_tests {
1208412084
Jump bb7(v67, v93)
1208512085
");
1208612086
}
12087+
12088+
#[test]
12089+
// TODO(Jacob): Clean up this test with a more clear example that won't change with other optimizations
12090+
// Alternatively, figure out a way to run this test with a single analysis pass active
12091+
fn test_scalar_replace_instance_variable() {
12092+
eval("
12093+
class Shell
12094+
def initialize(x)
12095+
@x = x
12096+
end
12097+
end
12098+
12099+
def no_escape(x)
12100+
s = Shell.new(x)
12101+
s.instance_variable_get(:@x)
12102+
end
12103+
");
12104+
assert_snapshot!(hir_string("no_escape"), @r"
12105+
fn no_escape@<compiled>:9:
12106+
bb0():
12107+
EntryPoint interpreter
12108+
v1:BasicObject = LoadSelf
12109+
v2:BasicObject = GetLocal :x, l0, SP@5
12110+
v3:NilClass = Const Value(nil)
12111+
Jump bb2(v1, v2, v3)
12112+
bb1(v6:BasicObject, v7:BasicObject):
12113+
EntryPoint JIT(0)
12114+
v8:NilClass = Const Value(nil)
12115+
Jump bb2(v6, v7, v8)
12116+
bb2(v10:BasicObject, v11:BasicObject, v12:NilClass):
12117+
v17:BasicObject = GetConstantPath 0x1000
12118+
v19:NilClass = Const Value(nil)
12119+
PatchPoint NoEPEscape(no_escape)
12120+
v25:CBool = IsMethodCFunc v17, :new
12121+
IfFalse v25, bb3(v10, v11, v12, v19, v17, v11)
12122+
v27:HeapBasicObject = ObjectAlloc v17
12123+
v29:BasicObject = SendWithoutBlock v27, :initialize, v11 # SendFallbackReason: Uncategorized(opt_send_without_block)
12124+
CheckInterrupts
12125+
Jump bb4(v10, v11, v12, v27, v29)
12126+
bb3(v33:BasicObject, v34:BasicObject, v35:NilClass, v36:NilClass, v37:BasicObject, v38:BasicObject):
12127+
v41:BasicObject = SendWithoutBlock v37, :new, v38 # SendFallbackReason: Uncategorized(opt_send_without_block)
12128+
Jump bb4(v33, v34, v35, v41, v36)
12129+
bb4(v44:BasicObject, v45:BasicObject, v46:NilClass, v47:BasicObject, v48:BasicObject):
12130+
PatchPoint NoEPEscape(no_escape)
12131+
v57:StaticSymbol[:@x] = Const Value(VALUE(0x1008))
12132+
v59:BasicObject = SendWithoutBlock v47, :instance_variable_get, v57 # SendFallbackReason: Uncategorized(opt_send_without_block)
12133+
CheckInterrupts
12134+
Return v59
12135+
");
12136+
}
1208712137
}

0 commit comments

Comments
 (0)