All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dotc.transform.PureStats.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
package dotty.tools.dotc
package transform

import ast.{Trees, tpd}
import core.*, core.Decorators.*
import MegaPhase.*
import Types.*, Contexts.*, Flags.*, DenotTransformers.*
import Symbols.*, StdNames.*, Trees.*

object PureStats {
  val name: String = "pureStats"
  val description: String = "remove pure statements in blocks"
}

/** Remove pure statements in blocks */
class PureStats extends MiniPhase {

  import tpd.*

  override def phaseName: String = PureStats.name

  override def description: String = PureStats.description

  override def runsAfter: Set[String] = Set(Erasure.name)

  override def transformBlock(tree: Block)(using Context): Tree =
    val stats = tree.stats.mapConserve {
      case Typed(Block(stats, expr), _) if isPureExpr(expr) => Thicket(stats)
      case stat if !stat.symbol.isConstructor && isPureExpr(stat) => EmptyTree
      case stat => stat
    }
    if stats eq tree.stats then tree
    else cpy.Block(tree)(Trees.flatten(stats), tree.expr)

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy