Skip to content

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 12 commits into from
Feb 14, 2019

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jan 21, 2019

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.

@nicolasstucki nicolasstucki self-assigned this Jan 21, 2019
@nicolasstucki nicolasstucki force-pushed the split-staging-2 branch 16 times, most recently from e7ffcae to 2751b14 Compare January 24, 2019 15:50
@ghost ghost added review and removed in progress labels Jan 29, 2019
@nicolasstucki nicolasstucki changed the title WIP Extract quote reification from Staging Extract quote reification from Staging phase Jan 29, 2019
@ghost ghost added review and removed in progress labels Jan 29, 2019
@nicolasstucki
Copy link
Contributor Author

Rebased

if (tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply)
keywordStr("'[") ~ toTextGlobal(tree.args, ", ") ~ keywordStr("]")
else
toTextLocal(tree.fun) ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]"
Copy link
Contributor

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

Copy link
Contributor Author

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, ", ") ~ close

Copy link
Contributor Author

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

@@ -320,7 +324,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (name.isTypeName) typeText(txt)
else txt
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(")")
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this:
screenshot 2019-02-12 at 10 33 08

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

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`.
@nicolasstucki
Copy link
Contributor Author

Rebased

@odersky
Copy link
Contributor

odersky commented Feb 14, 2019

@nicolasstucki Which commits did you add after my last review?

@nicolasstucki
Copy link
Contributor Author

@odersky your las review was just before b71326c

@odersky odersky merged commit d101462 into scala:master Feb 14, 2019
@allanrenucci allanrenucci deleted the split-staging-2 branch February 14, 2019 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants