Skip to content

Refactor TASTy reflect TermRef, TypeRef, SymRef #6974

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jul 31, 2019

  • Split into SymRef into TermRef, TypeRef
  • Rename old TermRef/TypeRef to NamedTermRef/NamedTypeRef

This will make it easier to use the correct TypeRef/TermRef by default.

@nicolasstucki nicolasstucki force-pushed the refactor-type-and-term-ref-api branch 6 times, most recently from d201434 to bbdb60d Compare July 31, 2019 14:18
@nicolasstucki nicolasstucki requested a review from liufengyun July 31, 2019 14:24
@nicolasstucki nicolasstucki marked this pull request as ready for review July 31, 2019 14:55
/** Type of a reference to a term */
type TermRef <: Type
/** Type of a reference to a type symbol */
type SymTypeRef <: Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Is SymTypeRef a subtype of NameTypeRef? Meanwhile, if most of the time it's possible to get a symbol from NamedTypeRef (of course not for type member of structural types), then the subtle difference of the two concepts seems not helpful to meta-programmers, only causing confusions.

The concern above is purely from the viewpoint of meta-programmers. I'm not familiar enough to tell from the perspective of compiler construction.

/cc: @odersky

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are not subtypes of each other. The current version caused confusion on you and @milessabin as the expectation was that a TypeRef would match both a type ref with a named or symbol designator. This change makes it explicit that type references could one of the two and they have to be handled slightly differently.

We could also add more subtyping by adding the generic TypeRef and TermRef.

type Type
  type TermRef <: Type
      type NamedTermRef <: Type
      type SymTermRef <: Type
  type TypeRef <: Type
      type NamedTypeRef <: Type
      type SymTypeRef <: Type

I did not add this into this PR because it make the hierarchy more complex.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused about how this relates to the Dotty internals. I quite like the internal TypeRef/TermRef (both a subtype of NamedType) distinction along with typeSymbol and termSymbol. Isn't it the case that if something has a name then it has a symbol? In which case I don't really understand why the TypeRef/TermRef extractors give us the name as a String and then makes us jump through hoops to get the symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remember correctly, you can have type refinements where you have a name but no symbol.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. But surely that's the (much) less common case ... why not handle it separately?

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 latest change uses TypeRef/TermRef for the ones with symbols and renames the named ones to NamedTypeRef/NamedTermRef. This will make the common simpler to match on.

@nicolasstucki nicolasstucki force-pushed the refactor-type-and-term-ref-api branch 4 times, most recently from 17082ec to 0cc56d8 Compare August 6, 2019 08:12
@liufengyun
Copy link
Contributor

As agreed in the meeting, we merge this PR and create a new one to remove NamedTypeRef and NamedTermRef.

@nicolasstucki
Copy link
Contributor Author

It will be removed in #7001

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

@milessabin milessabin self-requested a review August 7, 2019 09:49
Copy link
Contributor

@milessabin milessabin left a comment

Choose a reason for hiding this comment

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

LGTM

@nicolasstucki nicolasstucki force-pushed the refactor-type-and-term-ref-api branch from 0cc56d8 to d2f1448 Compare August 7, 2019 09:58
@nicolasstucki
Copy link
Contributor Author

Rebased

* Split into SymRef into TermRef, TypeRef
* Rename old TermRef/TypeRef to NamedTermRef/NamedTypeRef
@nicolasstucki nicolasstucki force-pushed the refactor-type-and-term-ref-api branch from d2f1448 to ef1d699 Compare August 7, 2019 12:59
@nicolasstucki
Copy link
Contributor Author

Rebased again

@nicolasstucki nicolasstucki merged commit 963719e into scala:master Aug 7, 2019
@nicolasstucki nicolasstucki deleted the refactor-type-and-term-ref-api branch August 7, 2019 15:00
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