-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor TASTy reflect TermRef, TypeRef, SymRef #6974
Conversation
d201434
to
bbdb60d
Compare
/** Type of a reference to a term */ | ||
type TermRef <: Type | ||
/** Type of a reference to a type symbol */ | ||
type SymTypeRef <: Type |
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.
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
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.
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.
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.
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.
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.
If I remember correctly, you can have type refinements where you have a name but no symbol.
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.
Makes sense. But surely that's the (much) less common case ... why not handle it separately?
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 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.
17082ec
to
0cc56d8
Compare
As agreed in the meeting, we merge this PR and create a new one to remove |
It will be removed in #7001 |
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.
LGTM
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.
LGTM
0cc56d8
to
d2f1448
Compare
Rebased |
* Split into SymRef into TermRef, TypeRef * Rename old TermRef/TypeRef to NamedTermRef/NamedTypeRef
d2f1448
to
ef1d699
Compare
Rebased again |
This will make it easier to use the correct
TypeRef
/TermRef
by default.