@@ -569,10 +569,19 @@ object Trees {
569
569
override def isTerm : Boolean = ! isType // this will classify empty trees as terms, which is necessary
570
570
}
571
571
572
- case class GadtExpr [- T >: Untyped ] private [ast] (gadt : GadtConstraint , expr : Tree [T ])(implicit @ constructorOnly src : SourceFile )
572
+ case class AssumeInfo [- T >: Untyped ] private [ast] (sym : Symbol , nestingLevel : Int , info : Type , body : Tree [T ])(implicit @ constructorOnly src : SourceFile )
573
573
extends ProxyTree [T ] {
574
- type ThisTree [- T >: Untyped ] <: GadtExpr [T ]
575
- def forwardTo : Tree [T ] = expr
574
+ type ThisTree [- T >: Untyped ] <: AssumeInfo [T ]
575
+ def forwardTo : Tree [T ] = body
576
+
577
+ /** Un-nests AssumeInfo trees, returning them in a list, along with the last non-AssumeInfo body.
578
+ * On each recursion, the body is first mapped with `mapBody`. */
579
+ def unnest [U <: T ](mapBody : Tree [U ] => Tree [U ] = (body : Tree [U ]) => body): (List [AssumeInfo [U ]], Tree [U ]) =
580
+ val acc = scala.collection.mutable.ListBuffer .empty[AssumeInfo [U ]]
581
+ def rec (tree : Tree [U ]): (List [AssumeInfo [U ]], Tree [U ]) = tree match
582
+ case tree @ AssumeInfo (_, _, _, body) => acc += tree; rec(mapBody(body))
583
+ case _ => (acc.toList, tree)
584
+ rec(this )
576
585
}
577
586
578
587
/** if cond then thenp else elsep */
@@ -1077,7 +1086,7 @@ object Trees {
1077
1086
type NamedArg = Trees .NamedArg [T ]
1078
1087
type Assign = Trees .Assign [T ]
1079
1088
type Block = Trees .Block [T ]
1080
- type GadtExpr = Trees .GadtExpr [T ]
1089
+ type AssumeInfo = Trees .AssumeInfo [T ]
1081
1090
type If = Trees .If [T ]
1082
1091
type InlineIf = Trees .InlineIf [T ]
1083
1092
type Closure = Trees .Closure [T ]
@@ -1216,9 +1225,9 @@ object Trees {
1216
1225
case tree : Block if (stats eq tree.stats) && (expr eq tree.expr) => tree
1217
1226
case _ => finalize(tree, untpd.Block (stats, expr)(sourceFile(tree)))
1218
1227
}
1219
- def GadtExpr (tree : Tree )(gadt : GadtConstraint , expr : Tree )(using Context ): GadtExpr = tree match
1220
- case tree : GadtExpr if (gadt eq tree.gadt ) && (expr eq tree.expr ) => tree
1221
- case _ => finalize(tree, untpd.GadtExpr (gadt, expr )(sourceFile(tree)))
1228
+ def AssumeInfo (tree : Tree )(sym : Symbol , nestingLevel : Int , info : Type , body : Tree )(using Context ): AssumeInfo = tree match
1229
+ case tree : AssumeInfo if (sym eq tree.sym ) && (info eq tree.info) && (body eq tree.body) && (nestingLevel == tree.nestingLevel ) => tree
1230
+ case _ => finalize(tree, untpd.AssumeInfo (sym, nestingLevel, info, body )(sourceFile(tree)))
1222
1231
def If (tree : Tree )(cond : Tree , thenp : Tree , elsep : Tree )(using Context ): If = tree match {
1223
1232
case tree : If if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree
1224
1233
case tree : InlineIf => finalize(tree, untpd.InlineIf (cond, thenp, elsep)(sourceFile(tree)))
@@ -1351,6 +1360,8 @@ object Trees {
1351
1360
1352
1361
// Copier methods with default arguments; these demand that the original tree
1353
1362
// is of the same class as the copy. We only include trees with more than 2 elements here.
1363
+ def AssumeInfo (tree : AssumeInfo )(sym : Symbol = tree.sym, nestingLevel : Int = tree.nestingLevel, info : Type = tree.info, body : Tree = tree.body)(using Context ): AssumeInfo =
1364
+ AssumeInfo (tree : Tree )(sym, nestingLevel, info, body)
1354
1365
def If (tree : If )(cond : Tree = tree.cond, thenp : Tree = tree.thenp, elsep : Tree = tree.elsep)(using Context ): If =
1355
1366
If (tree : Tree )(cond, thenp, elsep)
1356
1367
def Closure (tree : Closure )(env : List [Tree ] = tree.env, meth : Tree = tree.meth, tpt : Tree = tree.tpt)(using Context ): Closure =
@@ -1440,8 +1451,10 @@ object Trees {
1440
1451
cpy.Closure (tree)(transform(env), transform(meth), transform(tpt))
1441
1452
case Match (selector, cases) =>
1442
1453
cpy.Match (tree)(transform(selector), transformSub(cases))
1443
- case GadtExpr (gadt, expr) =>
1444
- inContext(ctx.withGadt(gadt))(cpy.GadtExpr (tree)(gadt, transform(expr)))
1454
+ case tree @ AssumeInfo (sym, nestingLevel, info, body) =>
1455
+ ctx.gadt.withAssumeInfosIn(tree)(transform) { (assumeInfo, body) =>
1456
+ cpy.AssumeInfo (assumeInfo)(body = body)
1457
+ }
1445
1458
case CaseDef (pat, guard, body) =>
1446
1459
cpy.CaseDef (tree)(transform(pat), transform(guard), transform(body))
1447
1460
case Labeled (bind, expr) =>
@@ -1578,8 +1591,8 @@ object Trees {
1578
1591
this (this (this (x, env), meth), tpt)
1579
1592
case Match (selector, cases) =>
1580
1593
this (this (x, selector), cases)
1581
- case GadtExpr (gadt, expr ) =>
1582
- inContext( ctx.withGadt( gadt)) (this (x, expr) )
1594
+ case tree @ AssumeInfo (sym, _, info, body ) =>
1595
+ ctx.gadt.withAssumeInfosIn(tree) (this (x, _))((_, x) => x )
1583
1596
case CaseDef (pat, guard, body) =>
1584
1597
this (this (this (x, pat), guard), body)
1585
1598
case Labeled (bind, expr) =>
0 commit comments