Skip to content

Rename TASTy reflect show to showExtractors #6228

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

nicolasstucki
Copy link
Contributor

This renaming is to avoid confusion with the quote.{Expr|Type}.show method which
shows the source representation of the code.

This renaming is to avoid confusion with the `quote.{Expr|Type}.show` method which
shows the source representation of the code.
@nicolasstucki nicolasstucki requested a review from liufengyun April 4, 2019 11:30
@nicolasstucki nicolasstucki marked this pull request as ready for review April 4, 2019 12:25
@allanrenucci
Copy link
Contributor

What about we use the same API as Scala Reflect? https://docs.scala-lang.org/overviews/reflection/symbols-trees-types.html#inspecting-trees

Inspecting Trees

Scala Reflection provides a handful of ways to visualize trees, all available through a universe. Given a tree, one can:

  • use methods show or toString which print pseudo-Scala code represented by the tree.
  • use method showRaw to see the raw internal tree that the typechecker operates upon.

@nicolasstucki
Copy link
Contributor Author

We cannot override toString adding a context and implement it as an extension method. Therefore the only possible result is the raw underlying dotty tree.

The next PR will rename the current showCode (pseudo code) to show and match the Expr.show which prints the same code.

Using showRaw for what I called showExtractors would be confusing as the toString already shows the raw tree. Instead, we want the TASTy Reflect representation of the tree. Hence it is better to clearly differentiate these two. Maybe showExtractors is not the best name, but usually I use it to know which extractors to use.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

There are two minor concerns:

  • The name showExtractors -- some are constructors
  • The semantics of showExtractors is unclear (e.g., when there are several constructors for the same tree), which may affect the utility of the method.

@nicolasstucki
Copy link
Contributor Author

The semantic are simple, print which extractor is needed to patter match on this tree.

Constructors have nothing to do with this method. It would be worth it to have another method showConstructors to know which constructors should be called to recreate this tree. Those two can clearly no print the same result as not all extractors/constructors are symmetrical.

@nicolasstucki nicolasstucki merged commit 635061f into scala:master Apr 7, 2019
@ghost ghost removed the stat:needs review label Apr 7, 2019
@nicolasstucki nicolasstucki deleted the rename-tasty-reflect-show-extractors branch April 7, 2019 15:03
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.

3 participants