Skip to content

Add missing TASTy reflect instance checks #5504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid duplicated checks for blocks
  • Loading branch information
nicolasstucki committed Nov 23, 2018
commit 4c9035019d92e27dd72063db3d3e3d5cd134413b
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,16 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
}

object IsBlock extends IsBlockModule {
def unapply(x: Term)(implicit ctx: Context): Option[Block] = Block.normalizedLoops(x) match {
def unapply(x: Term)(implicit ctx: Context): Option[Block] = normalizedLoops(x) match {
case x: tpd.Block => Some(x)
case _ => None
}
}

object Block extends BlockExtractor {
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = normalizedLoops(x) match {
case Trees.Block(stats, expr) => Some((stats, expr))
case _ => None
}
/** Normalizes non Blocks.
* i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }`
* ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }`
*/
private[Term] def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
private def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
case block: tpd.Block if block.stats.size > 1 =>
def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match {
case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) =>
Expand All @@ -402,6 +396,13 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
}
}

object Block extends BlockExtractor {
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = x match {
case IsBlock(x) => Some((x.stats, x.expr))
case _ => None
}
}

object IsInlined extends IsInlinedModule {
def unapply(x: Term)(implicit ctx: Context): Option[Inlined] = x match {
case x: tpd.Inlined => Some(x)
Expand Down