Skip to content

Commit f321394

Browse files
committed
Drop InlineIf and InlineMatch
1 parent e2d8300 commit f321394

File tree

7 files changed

+9
-56
lines changed

7 files changed

+9
-56
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 & 2 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)

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)

0 commit comments

Comments
 (0)