@@ -12053,4 +12053,54 @@ mod hir_opt_tests {
1205312053 Jump bb7(v67, v93)
1205412054 " ) ;
1205512055 }
12056+
12057+ #[ test]
12058+ // TODO(Jacob): Clean up this test with a more clear example that won't change with other optimizations
12059+ // Alternatively, figure out a way to run this test with a single analysis pass active
12060+ fn test_scalar_replace_instance_variable ( ) {
12061+ eval ( "
12062+ class Shell
12063+ def initialize(x)
12064+ @x = x
12065+ end
12066+ end
12067+
12068+ def no_escape(x)
12069+ s = Shell.new(x)
12070+ s.instance_variable_get(:@x)
12071+ end
12072+ " ) ;
12073+ assert_snapshot ! ( hir_string( "no_escape" ) , @r"
12074+ fn no_escape@<compiled>:9:
12075+ bb0():
12076+ EntryPoint interpreter
12077+ v1:BasicObject = LoadSelf
12078+ v2:BasicObject = GetLocal :x, l0, SP@5
12079+ v3:NilClass = Const Value(nil)
12080+ Jump bb2(v1, v2, v3)
12081+ bb1(v6:BasicObject, v7:BasicObject):
12082+ EntryPoint JIT(0)
12083+ v8:NilClass = Const Value(nil)
12084+ Jump bb2(v6, v7, v8)
12085+ bb2(v10:BasicObject, v11:BasicObject, v12:NilClass):
12086+ v17:BasicObject = GetConstantPath 0x1000
12087+ v19:NilClass = Const Value(nil)
12088+ PatchPoint NoEPEscape(no_escape)
12089+ v25:CBool = IsMethodCFunc v17, :new
12090+ IfFalse v25, bb3(v10, v11, v12, v19, v17, v11)
12091+ v27:HeapBasicObject = ObjectAlloc v17
12092+ v29:BasicObject = SendWithoutBlock v27, :initialize, v11 # SendFallbackReason: Uncategorized(opt_send_without_block)
12093+ CheckInterrupts
12094+ Jump bb4(v10, v11, v12, v27, v29)
12095+ bb3(v33:BasicObject, v34:BasicObject, v35:NilClass, v36:NilClass, v37:BasicObject, v38:BasicObject):
12096+ v41:BasicObject = SendWithoutBlock v37, :new, v38 # SendFallbackReason: Uncategorized(opt_send_without_block)
12097+ Jump bb4(v33, v34, v35, v41, v36)
12098+ bb4(v44:BasicObject, v45:BasicObject, v46:NilClass, v47:BasicObject, v48:BasicObject):
12099+ PatchPoint NoEPEscape(no_escape)
12100+ v57:StaticSymbol[:@x] = Const Value(VALUE(0x1008))
12101+ v59:BasicObject = SendWithoutBlock v47, :instance_variable_get, v57 # SendFallbackReason: Uncategorized(opt_send_without_block)
12102+ CheckInterrupts
12103+ Return v59
12104+ " ) ;
12105+ }
1205612106}
0 commit comments