no-identd / scala3-typed-holes

A WIP of scala-typed-holes for Scala3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to write a Scala 3 version of Scala Typed Holes

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 Scala 2 plugin

The plugin consists of two phases:

TypedHolesComponent

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")

NamedHoles

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")

Equivalent Scala 3 phases

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:

typerPostTyper
patmatPatternMatcher
parserFrontEnd
namer???

Explore each phase in detail

  • Why must the plugin run before and after these phases?
  • What are the equivalent phases in Scala 3?

Traversing the tree

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

Named holes

References

Dotty: Changes in compiler plugins

Dotty: using compiler plugins

Scala 2: Compiler plugins

Dotty phases

MegaPhase source

Scala 2 Typed Holes - Named holes

About

A WIP of scala-typed-holes for Scala3

License:Apache License 2.0


Languages

Language:Scala 83.4%Language:Nix 16.6%