Skip to content

Commit 8ae9d6a

Browse files
committed
Drop InlineIf and InlineMatch
1 parent e2d8300 commit 8ae9d6a

File tree

15 files changed

+40
-89
lines changed

15 files changed

+40
-89
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,6 @@ object Trees {
497497
extends TermTree[T] {
498498
type ThisTree[-T >: Untyped] = If[T]
499499
}
500-
class InlineIf[T >: Untyped] private[ast] (cond: Tree[T], thenp: Tree[T], elsep: Tree[T])
501-
extends If(cond, thenp, elsep) {
502-
override def toString = s"InlineIf($cond, $thenp, $elsep)"
503-
}
504500

505501
/** A closure with an environment and a reference to a method.
506502
* @param env The captured parameters of the closure
@@ -521,10 +517,6 @@ object Trees {
521517
extends TermTree[T] {
522518
type ThisTree[-T >: Untyped] = Match[T]
523519
}
524-
class InlineMatch[T >: Untyped] private[ast] (selector: Tree[T], cases: List[CaseDef[T]])
525-
extends Match(selector, cases) {
526-
override def toString = s"InlineMatch($selector, $cases)"
527-
}
528520

529521
/** case pat if guard => body; only appears as child of a Match */
530522
case class CaseDef[-T >: Untyped] private[ast] (pat: Tree[T], guard: Tree[T], body: Tree[T])
@@ -910,10 +902,8 @@ object Trees {
910902
type Assign = Trees.Assign[T]
911903
type Block = Trees.Block[T]
912904
type If = Trees.If[T]
913-
type InlineIf = Trees.InlineIf[T]
914905
type Closure = Trees.Closure[T]
915906
type Match = Trees.Match[T]
916-
type InlineMatch = Trees.InlineMatch[T]
917907
type CaseDef = Trees.CaseDef[T]
918908
type Labeled = Trees.Labeled[T]
919909
type Return = Trees.Return[T]
@@ -1045,9 +1035,6 @@ object Trees {
10451035
case _ => finalize(tree, untpd.Block(stats, expr))
10461036
}
10471037
def If(tree: Tree)(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = tree match {
1048-
case tree: InlineIf =>
1049-
if ((cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep)) tree
1050-
else finalize(tree, untpd.InlineIf(cond, thenp, elsep))
10511038
case tree: If if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree
10521039
case _ => finalize(tree, untpd.If(cond, thenp, elsep))
10531040
}
@@ -1056,9 +1043,6 @@ object Trees {
10561043
case _ => finalize(tree, untpd.Closure(env, meth, tpt))
10571044
}
10581045
def Match(tree: Tree)(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = tree match {
1059-
case tree: InlineMatch =>
1060-
if ((selector eq tree.selector) && (cases eq tree.cases)) tree
1061-
else finalize(tree, untpd.InlineMatch(selector, cases))
10621046
case tree: Match if (selector eq tree.selector) && (cases eq tree.cases) => tree
10631047
case _ => finalize(tree, untpd.Match(selector, cases))
10641048
}

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
272272
def Assign(lhs: Tree, rhs: Tree): Assign = new Assign(lhs, rhs)
273273
def Block(stats: List[Tree], expr: Tree): Block = new Block(stats, expr)
274274
def If(cond: Tree, thenp: Tree, elsep: Tree): If = new If(cond, thenp, elsep)
275-
def InlineIf(cond: Tree, thenp: Tree, elsep: Tree): If = new InlineIf(cond, thenp, elsep)
276275
def Closure(env: List[Tree], meth: Tree, tpt: Tree): Closure = new Closure(env, meth, tpt)
277276
def Match(selector: Tree, cases: List[CaseDef]): Match = new Match(selector, cases)
278-
def InlineMatch(selector: Tree, cases: List[CaseDef]): Match = new InlineMatch(selector, cases)
279277
def CaseDef(pat: Tree, guard: Tree, body: Tree): CaseDef = new CaseDef(pat, guard, body)
280278
def Labeled(bind: Bind, expr: Tree): Labeled = new Labeled(bind, expr)
281279
def Return(expr: Tree, from: Tree): Return = new Return(expr, from)
@@ -544,8 +542,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
544542
cpy.ContextBounds(tree)(transformSub(bounds), transform(cxBounds))
545543
case PatDef(mods, pats, tpt, rhs) =>
546544
cpy.PatDef(tree)(mods, transform(pats), transform(tpt), transform(rhs))
547-
case tpd.UntypedSplice(splice) =>
548-
cpy.UntypedSplice(tree)(transform(splice))
549545
case TypedSplice(_) =>
550546
tree
551547
case _ =>
@@ -595,8 +591,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
595591
this(this(this(x, pats), tpt), rhs)
596592
case TypedSplice(splice) =>
597593
this(x, splice)
598-
case tpd.UntypedSplice(splice) =>
599-
this(x, splice)
600594
case _ =>
601595
super.foldMoreCases(x, tree)
602596
}

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,16 +786,10 @@ class TreePickler(pickler: TastyPickler) {
786786
withLength { pickleUntyped(expr); stats.foreach(pickleUntyped) }
787787
case If(cond, thenp, elsep) =>
788788
writeByte(IF)
789-
withLength {
790-
if (tree.isInstanceOf[untpd.InlineIf]) writeByte(INLINE)
791-
pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep)
792-
}
789+
withLength { pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep) }
793790
case Match(selector, cases) =>
794791
writeByte(MATCH)
795-
withLength {
796-
if (tree.isInstanceOf[untpd.InlineMatch]) writeByte(INLINE)
797-
pickleUntyped(selector); cases.foreach(pickleUntyped)
798-
}
792+
withLength { pickleUntyped(selector); cases.foreach(pickleUntyped) }
799793
case CaseDef(pat, guard, rhs) =>
800794
writeByte(CASEDEF)
801795
withLength { pickleUntyped(pat); pickleUntyped(rhs); pickleUnlessEmpty(guard) }

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,13 +1332,10 @@ class TreeUnpickler(reader: TastyReader,
13321332
val stats = until(end)(readUntyped())
13331333
untpd.Block(stats, expr)
13341334
case IF =>
1335-
val mkIf = if (nextByte == INLINE) { readByte(); untpd.InlineIf(_, _, _) }
1336-
else untpd.If(_, _, _)
1335+
val mkIf = untpd.If(_, _, _)
13371336
mkIf(readUntyped(), readUntyped(), readUntyped())
13381337
case MATCH =>
1339-
val mkMatch =
1340-
if (nextByte == INLINE) { readByte(); untpd.InlineMatch(_, _) }
1341-
else untpd.Match(_, _)
1338+
val mkMatch = untpd.Match(_, _)
13421339
mkMatch(readUntyped(), readCases(end))
13431340
case CASEDEF =>
13441341
val pat = readUntyped()

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,21 +1214,7 @@ object Parsers {
12141214
case FOR =>
12151215
forExpr()
12161216
case _ =>
1217-
if (isIdent(nme.INLINEkw)) {
1218-
val start = in.skipToken()
1219-
in.token match {
1220-
case IF =>
1221-
ifExpr(start, InlineIf)
1222-
case _ =>
1223-
val t = postfixExpr()
1224-
if (in.token == MATCH) matchExpr(t, start, InlineMatch)
1225-
else {
1226-
syntaxErrorOrIncomplete("`match` or `if` expected but ${in.token} found")
1227-
t
1228-
}
1229-
}
1230-
}
1231-
else expr1Rest(postfixExpr(), location)
1217+
expr1Rest(postfixExpr(), location)
12321218
}
12331219

12341220
def expr1Rest(t: Tree, location: Location.Value) = in.token match {
@@ -1242,7 +1228,7 @@ object Parsers {
12421228
case COLON =>
12431229
ascription(t, location)
12441230
case MATCH =>
1245-
matchExpr(t, startOffset(t), Match)
1231+
matchExpr(t, startOffset(t))
12461232
case _ =>
12471233
t
12481234
}
@@ -1289,9 +1275,9 @@ object Parsers {
12891275
/** `match' { CaseClauses }
12901276
* `match' { ImplicitCaseClauses }
12911277
*/
1292-
def matchExpr(t: Tree, start: Offset, mkMatch: (Tree, List[CaseDef]) => Match) =
1278+
def matchExpr(t: Tree, start: Offset) =
12931279
atPos(start, in.skipToken()) {
1294-
inBraces(mkMatch(t, caseClauses(caseClause)))
1280+
inBraces(Match(t, caseClauses(caseClause)))
12951281
}
12961282

12971283
/** `match' { ImplicitCaseClauses }
@@ -1306,7 +1292,7 @@ object Parsers {
13061292
case mods => markFirstIllegal(mods)
13071293
}
13081294
val result @ Match(t, cases) =
1309-
matchExpr(ImplicitScrutinee().withPos(implicitKwPos(start)), start, InlineMatch)
1295+
matchExpr(ImplicitScrutinee().withPos(implicitKwPos(start)), start)
13101296
for (CaseDef(pat, _, _) <- cases) {
13111297
def isImplicitPattern(pat: Tree) = pat match {
13121298
case Typed(pat1, _) => isVarPattern(pat1)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,6 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
587587
if (isIdempotentExpr(cond1)) selected
588588
else Block(cond1 :: Nil, selected)
589589
case cond1 =>
590-
if (tree.isInstanceOf[untpd.InlineIf])
591-
errorTree(tree, em"""cannot reduce inline if
592-
| its condition ${tree.cond}
593-
| is not a constant value.""")
594590
val if1 = untpd.cpy.If(tree)(cond = untpd.TypedSplice(cond1))
595591
super.typedIf(if1, pt)
596592
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ class Typer extends Namer
711711
}
712712

713713
def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context): Tree = track("typedIf") {
714-
if (tree.isInstanceOf[untpd.InlineIf] && !Inliner.typedInline) checkInInlineContext("inline if", tree.pos)
715714
val cond1 = typed(tree.cond, defn.BooleanType)
716715
val thenp2 :: elsep2 :: Nil = harmonic(harmonize) {
717716
val thenp1 = typed(tree.thenp, pt.notApplied)
@@ -981,7 +980,6 @@ class Typer extends Namer
981980
val sel1 = id.withType(defn.ImplicitScrutineeTypeRef)
982981
typedMatchFinish(tree, sel1, sel1.tpe, pt)
983982
case _ =>
984-
if (tree.isInstanceOf[untpd.InlineMatch] && !Inliner.typedInline) checkInInlineContext("inline match", tree.pos)
985983
val sel1 = typedExpr(tree.selector)
986984
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos).widen
987985
typedMatchFinish(tree, sel1, selType, pt)

library/src-scala3/scala/Tuple.scala

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sealed trait Tuple extends Any {
66
import Tuple._
77

88
inline def toArray: Array[Object] =
9-
if (specialize)
9+
/*if (specialize)
1010
inline constValueOpt[BoundedSize[this.type]] match {
1111
case Some(0) =>
1212
$emptyArray
@@ -29,10 +29,10 @@ sealed trait Tuple extends Any {
2929
case None =>
3030
dynamicToArray(this)
3131
}
32-
else dynamicToArray(this)
32+
else*/ dynamicToArray(this)
3333

3434
inline def *: [H] (x: H): H *: this.type =
35-
if (specialize) {
35+
/*if (specialize) {
3636
type Result = H *: this.type
3737
inline constValueOpt[BoundedSize[this.type]] match {
3838
case Some(0) =>
@@ -54,10 +54,10 @@ sealed trait Tuple extends Any {
5454
dynamic_*:[this.type, H](this, x)
5555
}
5656
}
57-
else dynamic_*:[this.type, H](this, x)
57+
else*/ dynamic_*:[this.type, H](this, x)
5858

5959
inline def ++(that: Tuple): Concat[this.type, that.type] =
60-
if (specialize) {
60+
/*if (specialize) {
6161
type Result = Concat[this.type, that.type]
6262
inline constValueOpt[BoundedSize[this.type]] match {
6363
case Some(0) =>
@@ -95,20 +95,20 @@ sealed trait Tuple extends Any {
9595
dynamic_++[this.type, that.type](this, that)
9696
}
9797
}
98-
else dynamic_++[this.type, that.type](this, that)
98+
else*/ dynamic_++[this.type, that.type](this, that)
9999

100100
inline def genericConcat[T <: Tuple](xs: Tuple, ys: Tuple): Tuple =
101101
fromArray[T](xs.toArray ++ ys.toArray)
102102

103103
inline def size: Size[this.type] =
104-
if (specialize) {
104+
/*if (specialize) {
105105
type Result = Size[this.type]
106106
inline constValueOpt[BoundedSize[this.type]] match {
107107
case Some(n) => n.asInstanceOf[Result]
108108
case _ => dynamicSize(this)
109109
}
110110
}
111-
else dynamicSize(this)
111+
else*/ dynamicSize(this)
112112
}
113113

114114
object Tuple {
@@ -175,7 +175,7 @@ object Tuple {
175175
}
176176

177177
inline def fromArray[T <: Tuple](xs: Array[Object]): T =
178-
if (specialize)
178+
/*if (specialize)
179179
inline constValue[BoundedSize[T]] match {
180180
case 0 => ().asInstanceOf[T]
181181
case 1 => Tuple1(xs(0)).asInstanceOf[T]
@@ -202,7 +202,7 @@ object Tuple {
202202
case 22 => Tuple22(xs(0), xs(1), xs(2), xs(3), xs(4), xs(5), xs(6), xs(7), xs(8), xs(9), xs(10), xs(11), xs(12), xs(13), xs(14), xs(15), xs(16), xs(17), xs(18), xs(19), xs(20), xs(21)).asInstanceOf[T]
203203
case _ => TupleXXL(xs).asInstanceOf[T]
204204
}
205-
else dynamicFromArray[T](xs)
205+
else */dynamicFromArray[T](xs)
206206

207207
def dynamicFromArray[T <: Tuple](xs: Array[Object]): T = xs.length match {
208208
case 0 => ().asInstanceOf[T]
@@ -297,7 +297,7 @@ abstract sealed class NonEmptyTuple extends Tuple {
297297
import NonEmptyTuple._
298298

299299
inline def head: Head[this.type] =
300-
if (specialize) {
300+
/*if (specialize) {
301301
type Result = Head[this.type]
302302
val resVal = inline constValueOpt[BoundedSize[this.type]] match {
303303
case Some(1) =>
@@ -322,10 +322,10 @@ abstract sealed class NonEmptyTuple extends Tuple {
322322
}
323323
resVal.asInstanceOf[Result]
324324
}
325-
else dynamicHead[this.type](this)
325+
else*/ dynamicHead[this.type](this)
326326

327327
inline def tail: Tail[this.type] =
328-
if (specialize) {
328+
/*if (specialize) {
329329
type Result = Tail[this.type]
330330
inline constValueOpt[BoundedSize[this.type]] match {
331331
case Some(1) =>
@@ -348,16 +348,18 @@ abstract sealed class NonEmptyTuple extends Tuple {
348348
dynamicTail[this.type](this)
349349
}
350350
}
351-
else dynamicTail[this.type](this)
351+
else*/ dynamicTail[this.type](this)
352352

353+
/*
353354
inline def fallbackApply(n: Int) =
354355
inline constValueOpt[n.type] match {
355356
case Some(n: Int) => error("index out of bounds: ", n)
356357
case None => dynamicApply[this.type](this, n)
357358
}
359+
*/
358360

359361
inline def apply(n: Int): Elem[this.type, n.type] =
360-
if (specialize) {
362+
/*if (specialize) {
361363
type Result = Elem[this.type, n.type]
362364
inline constValueOpt[Size[this.type]] match {
363365
case Some(1) =>
@@ -405,7 +407,7 @@ abstract sealed class NonEmptyTuple extends Tuple {
405407
case _ => fallbackApply(n).asInstanceOf[Result]
406408
}
407409
}
408-
else dynamicApply[this.type](this, n)
410+
else*/ dynamicApply[this.type](this, n)
409411
}
410412

411413
object NonEmptyTuple {

tests/neg/nested-rewrites.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ object Test {
1515
object Test0 {
1616

1717
def f(x: Int) = {
18-
inline def g(x: Int) = inline x match {
18+
inline def g(x: Int) = x match {
1919
case 0 => 0
2020
}
2121
g(0)
2222
inline val Y = 0
2323
g(Y)
2424

25-
inline def h(x: Int) = inline x match {
25+
inline def h(x: Int) = x match {
2626
case Y => 0
2727
}
2828
h(0)
@@ -35,14 +35,14 @@ object Test0 {
3535
object Test1 {
3636

3737
erased inline def f(x: Int) = {
38-
erased inline def g(x: Int) = inline x match { // error: implementation restriction: nested inline methods are not supported
38+
erased inline def g(x: Int) = x match { // error: implementation restriction: nested inline methods are not supported
3939
case 0 => 0
4040
}
4141
g(0)
4242
inline val Y = 0
4343
g(Y)
4444

45-
inline def h(x: Int) = inline x match { // error: implementation restriction: nested inline methods are not supported
45+
inline def h(x: Int) = x match { // error: implementation restriction: nested inline methods are not supported
4646
case Y => 0
4747
}
4848
h(0)

tests/neg/transparent-override/B_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class B extends A {
2-
inline def f(x: Int): Int = inline x match { // error
2+
inline def f(x: Int): Int = x match { // error
33
case 0 => 1
44
case _ => x
55
}

tests/neg/typelevel-noeta.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
object Test {
33
def anyValue[T]: T = ???
44

5-
inline def test(x: Int) = inline x match {
5+
inline def test(x: Int) = x match {
66
case _: Byte =>
77
case _: Char =>
88
}
99

10-
inline def test2() = inline 1 match {
10+
inline def test2() = 1 match {
1111
case _: Byte =>
1212
case _: Char =>
1313
}

tests/pos-deep-subtype/tuples23.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Test extends App {
1414
case (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) =>
1515
println(x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23)
1616
}
17-
inline def decompose3 = inline x23 match { case x *: y *: xs => (x, y, xs) }
17+
inline def decompose3 = x23 match { case x *: y *: xs => (x, y, xs) }
1818

1919
{ val (x, y, xs) = decompose3
2020
val xc: Int = x

tests/pos/i2166.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Test {
2-
inline def f = inline "" match { case _ => false }
2+
inline def f = "" match { case _ => false }
33

44
def main(args: Array[String]): Unit = f
55
}

0 commit comments

Comments
 (0)