-
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
Conversation
e7ffcae to
2751b14
Compare
5f4664a to
50114ec
Compare
50114ec to
55d62d6
Compare
17771f5 to
5fcab04
Compare
9cd54ba to
2082ba0
Compare
|
Rebased |
| if (tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply) | ||
| keywordStr("'[") ~ toTextGlobal(tree.args, ", ") ~ keywordStr("]") | ||
| else | ||
| toTextLocal(tree.fun) ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]" |
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.
keywordStr in both branches? Also, why not factor out the prefix?
val leading =
if (tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply) keywordStr("'[")
else toTextLocal(tree.fun) ~ keywordStr("[")
leading ~ toTextGlobal(tree.args, ", ") ~ keywordStr("]")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.
The suffix also depends on the condition. Though I can refactor it a bit.
val isQuote = tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply
val (open, close) = if (isQuote) (keywordStr("'["), keywordStr("]")) else ("[", "]")
toTextLocal(tree.fun).provided(!isQuote) ~ open ~ toTextGlobal(tree.args, ", ") ~ closeThere 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.
I pushed this refactoring of the code
| case tree @ Select(qual, name) => | ||
| if (tree.hasType && tree.symbol == defn.QuotedExpr_~ || tree.symbol == defn.QuotedType_~) keywordStr("~(") ~ toTextLocal(qual) ~ keywordStr(")") | ||
| if (tree.hasType && tree.symbol == defn.QuotedExpr_~) keywordStr("~(") ~ toTextLocal(qual) ~ keywordStr(")") | ||
| else if (tree.hasType && tree.symbol == defn.QuotedType_~) typeText("~(") ~ toTextLocal(qual) ~ typeText(")") |
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.
compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala
Outdated
Show resolved
Hide resolved
compiler/src/dotty/tools/dotc/transform/TreeMapWithStages.scala
Outdated
Show resolved
Hide resolved
2082ba0 to
88d42d5
Compare
Split current `Staging` into `Staging` and `ReifyQuotes`
- `Staging`
- Just before `Pickler`
- Checks PCP
- Heals phase consistency by replacing `T` with `~implicitly[Type[T]]({{t}})` (actually `~t`)
- Expand macros
- Ycheck that PCP holds (without healing) until `ReifyQuotes`
- `ReifyQuotes`
- Aliases all type splices by replacing `~t` by `T$1` and inserting `type T$1 = ~t` at the start of the quoted block.
- Transform `'{ ... ~(... ) ... }` into `unpickle('{ ... Hole(...) ... }, List(args => ....))`
- `TreeMapWithStages` a new `TreeMap` that contains the logic to track quotation levels while mapping the tree.
- Moved logic from `MacroTransformWithImplicits` to `TreeMapWithImplicits` to be able to tranform a tree without the need to be in a macro transform. This will be useful to integrate the PCP checks and macro expansion in `Typer`.
58f1347 to
bef8cce
Compare
|
Rebased |
|
@nicolasstucki Which commits did you add after my last review? |

Split current
StagingintoStagingandReifyQuotesStagingPicklerTwith~implicitly[Type[T]]({{t}})(actually~t)ReifyQuotesReifyQuotes~tbyT$1and insertingtype T$1 = ~tat the start of the quoted block.'{ ... ~(...) ... }intounpickle('{ ... Hole(...) ... }, List(args => ....))TreeMapWithStagesa newTreeMapthat contains the logic to track quotation levels while mapping the tree.MacroTransformWithImplicitstoTreeMapWithImplicitsto be able to tranform a tree without the need to be in a macro transform. This will be useful to integrate the PCP checks and macro expansion inTyper.