-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extract quote reification from Staging phase #5763
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
85e00d5
Extract quote reification from Staging
nicolasstucki 76f4c2c
Cleanup imports and fix documentation
nicolasstucki 7525d59
Use same local contexts as in TreeMap
nicolasstucki 02ff72f
Fix typo
nicolasstucki b71326c
Move Quoted and Spliced extractors to TreeInfo
nicolasstucki f9705a6
Refactor printer code
nicolasstucki c115a7b
`!sym.maybeOwner.isType` -> `sym.maybeOwber.isTerm`
nicolasstucki 9dfb215
Rename `quotation` -> `transformQuotation` and `splice` -> `transform…
nicolasstucki 8374c4d
Shorter names for quotation tags
nicolasstucki b523a05
Simplify handling of pimitive types
nicolasstucki bef8cce
Fix typo
nicolasstucki bb9874c
Fix after rebase
nicolasstucki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package dotty.tools.dotc.ast | ||
|
||
import dotty.tools.dotc.ast.Trees._ | ||
import dotty.tools.dotc.core.Contexts._ | ||
import dotty.tools.dotc.core.Flags._ | ||
import dotty.tools.dotc.core.Symbols._ | ||
import dotty.tools.dotc.core.TypeError | ||
|
||
import scala.annotation.tailrec | ||
|
||
/** A TreeMap that maintains the necessary infrastructure to support | ||
* contxtual implicit searches (type-scope implicits are supported anyway). | ||
* | ||
* This incudes impicits defined in scope as well as imported implicits. | ||
*/ | ||
class TreeMapWithImplicits extends tpd.TreeMap { | ||
import tpd._ | ||
|
||
def transformSelf(vd: ValDef)(implicit ctx: Context): ValDef = | ||
cpy.ValDef(vd)(tpt = transform(vd.tpt)) | ||
|
||
/** Transform statements, while maintaining import contexts and expression contexts | ||
* in the same way as Typer does. The code addresses additional concerns: | ||
* - be tail-recursive where possible | ||
* - don't re-allocate trees where nothing has changed | ||
*/ | ||
def transformStats(stats: List[Tree], exprOwner: Symbol)(implicit ctx: Context): List[Tree] = { | ||
|
||
@tailrec def traverse(curStats: List[Tree])(implicit ctx: Context): List[Tree] = { | ||
|
||
def recur(stats: List[Tree], changed: Tree, rest: List[Tree])(implicit ctx: Context): List[Tree] = { | ||
if (stats eq curStats) { | ||
val rest1 = transformStats(rest, exprOwner) | ||
changed match { | ||
case Thicket(trees) => trees ::: rest1 | ||
case tree => tree :: rest1 | ||
} | ||
} | ||
else stats.head :: recur(stats.tail, changed, rest) | ||
} | ||
|
||
curStats match { | ||
case stat :: rest => | ||
val statCtx = stat match { | ||
case stat: DefTree => ctx | ||
case _ => ctx.exprContext(stat, exprOwner) | ||
} | ||
val restCtx = stat match { | ||
case stat: Import => ctx.importContext(stat, stat.symbol) | ||
case _ => ctx | ||
} | ||
val stat1 = transform(stat)(statCtx) | ||
if (stat1 ne stat) recur(stats, stat1, rest)(restCtx) | ||
else traverse(rest)(restCtx) | ||
case nil => | ||
stats | ||
} | ||
} | ||
traverse(stats) | ||
} | ||
|
||
private def nestedScopeCtx(defs: List[Tree])(implicit ctx: Context): Context = { | ||
val nestedCtx = ctx.fresh.setNewScope | ||
defs foreach { | ||
case d: DefTree => nestedCtx.enter(d.symbol) | ||
case _ => | ||
} | ||
nestedCtx | ||
} | ||
|
||
override def transform(tree: Tree)(implicit ctx: Context): Tree = { | ||
def localCtx = | ||
if (tree.hasType && tree.symbol.exists) ctx.withOwner(tree.symbol) else ctx | ||
try tree match { | ||
case tree: Block => | ||
super.transform(tree)(nestedScopeCtx(tree.stats)) | ||
case tree: DefDef => | ||
implicit val ctx = localCtx | ||
cpy.DefDef(tree)( | ||
tree.name, | ||
transformSub(tree.tparams), | ||
tree.vparamss mapConserve (transformSub(_)), | ||
transform(tree.tpt), | ||
transform(tree.rhs)(nestedScopeCtx(tree.vparamss.flatten))) | ||
case EmptyValDef => | ||
tree | ||
case _: PackageDef | _: MemberDef => | ||
super.transform(tree)(localCtx) | ||
case impl @ Template(constr, parents, self, _) => | ||
cpy.Template(tree)( | ||
transformSub(constr), | ||
transform(parents)(ctx.superCallContext), | ||
Nil, | ||
transformSelf(self), | ||
transformStats(impl.body, tree.symbol)) | ||
case _ => | ||
super.transform(tree) | ||
} | ||
catch { | ||
case ex: TypeError => | ||
ctx.error(ex.toMessage, tree.sourcePos) | ||
tree | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
compiler/src/dotty/tools/dotc/transform/MacroTransformWithImplicits.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why typeText instead if keywordStr? (I don't know enough about the syntax highlighting stuff to be able to tell).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this:

I added it because in some large examples it was easyer to see which where types splices and which where terms splices.