Scala Typed Holes should be a [[*\[\[https://dotty.epfl.ch/docs/reference/changed-features/compiler-plugins.html\]\[Dotty: Changes in compiler plugins\]\]][standard compiler plugin]] with two phases. These slot in between existing compiler phases.
The plugin consists of two phases:
This calculates the type of a ???
override val phaseName: String = "typed-holes"
override val runsAfter: List[String] = List("typer")
override val runsBefore: List[String] = List("patmat")
This calculates the type of a [[*\[\[https://github.com/zainab-ali/scala-typed-holes#named-holes\]\[Scala 2 Typed Holes - Named holes\]\]][named hole]].
override val phaseName: String = "named-holes"
override val runsAfter: List[String] = List("parser")
override val runsBefore: List[String] = List("namer")
From a skim read of [[*\[\[https://dotty.epfl.ch/docs/internals/overall-structure.html\]\[Dotty phases\]\]][Dotty phases]], we might be able to translate the phases as follows:
typer | PostTyper |
patmat | PatternMatcher |
parser | FrontEnd |
namer | ??? |
- Why must the plugin run before and after these phases?
- What are the equivalent phases in Scala 3?
The typed holes plugin traverses the typed tree to find the appropriate matching type. There may be several methods for tree traversal available in a phase. See [[*\[\[https://dotty.epfl.ch/docs/reference/changed-features/compiler-plugins.html\]\[Dotty: Changes in compiler plugins\]\]][the example standard plugin]] and the [[*\[\[https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala\]\[MegaPhase source\]\]][MegaPhase source]]. This exposes individual methods for transforming each case.
The prepareFor
fuction is called before the tree’s children are transformed.
The transform
function is called after its children are transformed.
Bindings are pushed in prepare
and popped in transform