@@ -14008,7 +14008,69 @@ mod opt_tests {
1400814008 PatchPoint MethodRedefined(Array@0x1000, <<@0x1008, cme:0x1010)
1400914009 PatchPoint NoSingletonClass(Array@0x1000)
1401014010 v26:ArrayExact = GuardType v9, ArrayExact
14011- v27:BasicObject = CCallWithFrame <<@0x1038, v26, v13
14011+ ArrayPush v26, v13
14012+ IncrCounter inline_cfunc_optimized_send_count
14013+ CheckInterrupts
14014+ Return v26
14015+ ");
14016+ }
14017+
14018+ #[test]
14019+ fn test_optimize_array_push_single_arg() {
14020+ eval("
14021+ def test(arr)
14022+ arr.push(1)
14023+ end
14024+ test([])
14025+ ");
14026+ assert_snapshot!(hir_string("test"), @r"
14027+ fn test@<compiled>:3:
14028+ bb0():
14029+ EntryPoint interpreter
14030+ v1:BasicObject = LoadSelf
14031+ v2:BasicObject = GetLocal l0, SP@4
14032+ Jump bb2(v1, v2)
14033+ bb1(v5:BasicObject, v6:BasicObject):
14034+ EntryPoint JIT(0)
14035+ Jump bb2(v5, v6)
14036+ bb2(v8:BasicObject, v9:BasicObject):
14037+ v13:Fixnum[1] = Const Value(1)
14038+ PatchPoint MethodRedefined(Array@0x1000, push@0x1008, cme:0x1010)
14039+ PatchPoint NoSingletonClass(Array@0x1000)
14040+ v24:ArrayExact = GuardType v9, ArrayExact
14041+ ArrayPush v24, v13
14042+ IncrCounter inline_cfunc_optimized_send_count
14043+ CheckInterrupts
14044+ Return v24
14045+ ");
14046+ }
14047+
14048+ #[test]
14049+ fn test_do_not_optimize_array_push_multi_arg() {
14050+ eval("
14051+ def test(arr)
14052+ arr.push(1,2,3)
14053+ end
14054+ test([])
14055+ ");
14056+ assert_snapshot!(hir_string("test"), @r"
14057+ fn test@<compiled>:3:
14058+ bb0():
14059+ EntryPoint interpreter
14060+ v1:BasicObject = LoadSelf
14061+ v2:BasicObject = GetLocal l0, SP@4
14062+ Jump bb2(v1, v2)
14063+ bb1(v5:BasicObject, v6:BasicObject):
14064+ EntryPoint JIT(0)
14065+ Jump bb2(v5, v6)
14066+ bb2(v8:BasicObject, v9:BasicObject):
14067+ v13:Fixnum[1] = Const Value(1)
14068+ v14:Fixnum[2] = Const Value(2)
14069+ v15:Fixnum[3] = Const Value(3)
14070+ PatchPoint MethodRedefined(Array@0x1000, push@0x1008, cme:0x1010)
14071+ PatchPoint NoSingletonClass(Array@0x1000)
14072+ v26:ArrayExact = GuardType v9, ArrayExact
14073+ v27:BasicObject = CCallVariadic push@0x1038, v26, v13, v14, v15
1401214074 CheckInterrupts
1401314075 Return v27
1401414076 ");
0 commit comments