@@ -3504,36 +3504,27 @@ private[optimizer] abstract class OptimizerCore(
3504
3504
withBinding(rtLongBinding) { (scope1, cont1) =>
3505
3505
implicit val scope = scope1
3506
3506
val tRef = VarRef (tName)(rtLongClassType)
3507
- val newTree = New (LongImpl .RuntimeLongClass ,
3508
- MethodIdent (LongImpl .initFromParts),
3509
- List (Apply (ApplyFlags .empty, tRef, MethodIdent (LongImpl .lo), Nil )(IntType ),
3510
- Apply (ApplyFlags .empty, tRef, MethodIdent (LongImpl .hi), Nil )(IntType )))
3511
- pretransformExpr(newTree)(cont1)
3507
+
3508
+ val lo = Apply (ApplyFlags .empty, tRef, MethodIdent (LongImpl .lo), Nil )(IntType )
3509
+ val hi = Apply (ApplyFlags .empty, tRef, MethodIdent (LongImpl .hi), Nil )(IntType )
3510
+
3511
8000
+ pretransformExprs(lo, hi) { (tlo, thi) =>
3512
+ inlineClassConstructor(AllocationSite .Anonymous , LongImpl .RuntimeLongClass ,
3513
+ inlinedRTLongStructure, MethodIdent (LongImpl .initFromParts), List (tlo, thi),
3514
+ () => throw new AssertionError (s " rolled-back RuntimeLong inlining at $pos" ))(cont1)
3515
+ }
3512
3516
} (cont)
3513
3517
}
3514
3518
3515
3519
private def expandLongOps (pretrans : PreTransform )(cont : PreTransCont )(
3516
3520
implicit scope : Scope ): TailRec [Tree ] = {
3517
3521
implicit val pos = pretrans.pos
3518
3522
3519
- // unfortunately nullable for the result types of methods
3520
- def rtLongClassType = ClassType (LongImpl .RuntimeLongClass , nullable = true )
3521
-
3522
- def expandUnaryOp (methodName : MethodName , arg : PreTransform ,
3523
- resultType : Type = rtLongClassType): TailRec [Tree ] = {
3524
- pretransformApplyStatic(ApplyFlags .empty, LongImpl .RuntimeLongClass ,
3525
- MethodIdent (methodName), arg :: Nil , resultType,
3526
- isStat = false , usePreTransform = true )(
3527
- cont)
3528
- }
3529
-
3530
- def expandBinaryOp (methodName : MethodName , lhs : PreTransform ,
3531
- rhs : PreTransform ,
3532
- resultType : Type = rtLongClassType): TailRec [Tree ] = {
3533
- pretransformApplyStatic(ApplyFlags .empty, LongImpl .RuntimeLongClass ,
3534
- MethodIdent (methodName), lhs :: rhs :: Nil , resultType,
3535
- isStat = false , usePreTransform = true )(
3536
- cont)
3523
+ def expand (methodName : MethodName , targs : PreTransform * ): TailRec [Tree ] = {
3524
+ val impl = staticCall(LongImpl .RuntimeLongClass , MemberNamespace .PublicStatic , methodName)
3525
+ pretransformSingleDispatch(ApplyFlags .empty, impl, None , targs.toList,
3526
+ isStat = false , usePreTransform = true )(cont)(
3527
+ throw new AssertionError (s " failed to inline RuntimeLong method $methodName at $pos" ))
3537
3528
}
3538
3529
3539
3530
pretrans match {
@@ -3542,30 +3533,30 @@ private[optimizer] abstract class OptimizerCore(
3542
3533
3543
3534
(op : @ switch) match {
3544
3535
case IntToLong =>
3545
- expandUnaryOp (LongImpl .fromInt, arg)
3536
+ expand (LongImpl .fromInt, arg)
3546
3537
3547
3538
case LongToInt =>
3548
- expandUnaryOp (LongImpl .toInt, arg, IntType )
3539
+ expand (LongImpl .toInt, arg)
3549
3540
3550
3541
case LongToDouble =>
3551
- expandUnaryOp (LongImpl .toDouble, arg, DoubleType )
3542
+ expand (LongImpl .toDouble, arg)
3552
3543
3553
3544
case DoubleToLong =>
3554
- expandUnaryOp (LongImpl .fromDouble, arg)
3545
+ expand (LongImpl .fromDouble, arg)
3555
3546
3556
3547
case LongToFloat =>
3557
- expandUnaryOp (LongImpl .toFloat, arg, FloatType )
3548
+ expand (LongImpl .toFloat, arg)
3558
3549
3559
3550
case Double_toBits if config.coreSpec.esFeatures.esVersion >= ESVersion .ES2015 =>
3560
- expandBinaryOp (LongImpl .fromDoubleBits,
3551
+ expand (LongImpl .fromDoubleBits,
3561
3552
arg, PreTransTree (Transient (GetFPBitsDataView )))
3562
3553
3563
3554
case Double_fromBits if config.coreSpec.esFeatures.esVersion >= ESVersion .ES2015 =>
3564
8000
- expandBinaryOp (LongImpl .bitsToDouble,
3555
+ expand (LongImpl .bitsToDouble,
3565
3556
arg, PreTransTree (Transient (GetFPBitsDataView )))
3566
3557
3567
3558
case Long_clz =>
3568
- expandUnaryOp (LongImpl .clz, arg, IntType )
3559
+ expand (LongImpl .clz, arg)
3569
3560
3570
3561
case _ =>
3571
3562
cont(pretrans)
@@ -3575,37 +3566,37 @@ private[optimizer] abstract class OptimizerCore(
3575
3566
import BinaryOp ._
3576
3567
3577
3568
(op : @ switch) match {
3578
- case Long_+ => expandBinaryOp (LongImpl .add, lhs, rhs)
3569
+ case Long_+ => expand (LongImpl .add, lhs, rhs)
3579
3570
3580
3571
case Long_- =>
3581
3572
lhs match {
3582
3573
case PreTransLit (LongLiteral (0L )) =>
3583
- expandUnaryOp (LongImpl .neg, rhs)
3574
+ expand (LongImpl .neg, rhs)
3584
3575
case _ =>
3585
- expandBinaryOp (LongImpl .sub, lhs, rhs)
3576
+ expand (LongImpl .sub, lhs, rhs)
3586
3577
}
3587
3578
3588
- case Long_* => expandBinaryOp (LongImpl .mul, lhs, rhs)
3589
- case Long_/ => expandBinaryOp (LongImpl .divide, lhs, rhs)
3590
- case Long_% => expandBinaryOp (LongImpl .remainder, lhs, rhs)
3579
+ case Long_* => expand (LongImpl .mul, lhs, rhs)
3580
+ case Long_/ => expand (LongImpl .divide, lhs, rhs)
3581
+ case Long_% => expand (LongImpl .remainder, lhs, rhs)
3591
3582
3592
- case Long_& => expandBinaryOp (LongImpl .and, lhs, rhs)
3593
- case Long_| => expandBinaryOp (LongImpl .or, lhs, rhs)
3594
- case Long_^ => expandBinaryOp (LongImpl .xor, lhs, rhs)
3583
+ case Long_& => expand (LongImpl .and, lhs, rhs)
3584
+ case Long_| => expand (LongImpl .or, lhs, rhs)
3585
+ case Long_^ => expand (LongImpl .xor, lhs, rhs)
3595
3586
3596
- case Long_<< => expandBinaryOp (LongImpl .shl, lhs, rhs)
3597
- case Long_>>> => expandBinaryOp (LongImpl .shr, lhs, rhs)
3598
- case Long_>> => expandBinaryOp (LongImpl .sar, lhs, rhs)
3587
+ case Long_<< => expand (LongImpl .shl, lhs, rhs)
8000
3588
+ case Long_>>> => expand (LongImpl .shr, lhs, rhs)
3589
+ case Long_>> => expand (LongImpl .sar, lhs, rhs)
3599
3590
3600
- case Long_== => expandBinaryOp (LongImpl .equals_, lhs, rhs)
3601
- case Long_!= => expandBinaryOp (LongImpl .notEquals, lhs, rhs)
3602
- case Long_< => expandBinaryOp (LongImpl .lt, lhs, rhs)
3603
- case Long_<= => expandBinaryOp (LongImpl .le, lhs, rhs)
3604
- case Long_> => expandBinaryOp (LongImpl .gt, lhs, rhs)
3605
- case Long_>= => expandBinaryOp (LongImpl .ge, lhs, rhs)
3591
+ case Long_== => expand (LongImpl .equals_, lhs, rhs)
3592
+ case Long_!= => expand (LongImpl .notEquals, lhs, rhs)
3593
+ case Long_< => expand (LongImpl .lt, lhs, rhs)
3594
+ case Long_<= => expand (LongImpl .le, lhs, rhs)
3595
+ case Long_> => expand (LongImpl .gt, lhs, rhs)
3596
+ case Long_>= => expand (LongImpl .ge, lhs, rhs)
3606
3597
3607
- case Long_unsigned_/ => expandBinaryOp (LongImpl .divideUnsigned, lhs, rhs)
3608
- case Long_unsigned_% => expandBinaryOp (LongImpl .remainderUnsigned, lhs, rhs)
3598
+ case Long_unsigned_/ => expand (LongImpl .divideUnsigned, lhs, rhs)
3599
+ case Long_unsigned_% => expand (LongImpl .remainderUnsigned, lhs, rhs)
3609
3600
3610
3601
case _ =>
3611
3602
cont(pretrans)
0 commit comments