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

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

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

import core.*
import Contexts.*, Symbols.*, Decorators.*
import MegaPhase.*

/** Rewrite `{ stats; expr}.f(args)` to `{ stats; expr.f(args) }` and
 *  `{ stats; expr }(args)` to `{ stats; expr(args) }` before proceeding,
 *  but leave closures alone. This is necessary to be able to
 *  collapse applies of IFTs (this is done in Erasure).
 */
class LetOverApply extends MiniPhase:
  import ast.tpd.*

  override def phaseName: String = LetOverApply.name

  override def description: String = LetOverApply.description

  override def transformApply(tree: Apply)(using Context): Tree =
    tree.fun match
      case Select(blk @ Block(stats, expr), name) if !expr.isInstanceOf[Closure] =>
        cpy.Block(blk)(stats,
          cpy.Apply(tree)(
            cpy.Select(tree.fun)(expr, name), tree.args))
      case Block(stats, expr) =>
        cpy.Block(tree.fun)(stats,
          cpy.Apply(tree)(expr, tree.args))
      case _ =>
        tree

end LetOverApply

object LetOverApply:
  val name: String = "letOverApply"
  val description: String = "lift blocks from receivers of applications"




© 2015 - 2025 Weber Informatics LLC | Privacy Policy