-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
FIR: Self types draft #4796
Draft
maxim092001
wants to merge
24
commits into
JetBrains:master
Choose a base branch
from
maxim092001:self-types-thesis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
FIR: Self types draft #4796
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mglukhikh
reviewed
May 23, 2022
mglukhikh
reviewed
May 23, 2022
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 23, 2022
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 23, 2022
...jetbrains/kotlin/fir/resolve/transformers/plugin/FirAnnotationArgumentsResolveTransformer.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 23, 2022
mglukhikh
reviewed
May 23, 2022
.../src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 23, 2022
.../src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 27, 2022
compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 27, 2022
compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirSelfTypeScope.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 27, 2022
.../src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt
Outdated
Show resolved
Hide resolved
mglukhikh
reviewed
May 27, 2022
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt
Outdated
Show resolved
Hide resolved
maxim092001
force-pushed
the
self-types-thesis
branch
from
July 30, 2022 07:48
a6b8f18
to
76a55e2
Compare
mglukhikh
reviewed
Dec 6, 2022
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt
Outdated
Show resolved
Hide resolved
maxim092001
force-pushed
the
self-types-thesis
branch
4 times, most recently
from
January 7, 2023 19:31
95d8ae9
to
ab6c031
Compare
Self type will be generated for classes/interfaces annotated with `@Self`. For FIR will be generated special type <Self> and transformed to $Self during FIR2IR. Self type is added as last type parameter. Example: ``` @self class Foo { // generated type: out Self: Foo<Self> fun foo(): Self = this as Self // without UNCHECKED_CAST warning } ```
constructors of this class. This allows to create Self classes. Example: ``` @self class Foo<T> { // generated type: out Self: Foo<T, Self> ... } Foo<Int>() // last type argument would be generated as Foo<Foo<Int, *>> ```
compiler using Self types. Some parts were changed due to complexity of initial implementation.
maxim092001
force-pushed
the
self-types-thesis
branch
from
January 7, 2023 19:40
ab6c031
to
210d584
Compare
maxim092001
force-pushed
the
self-types-thesis
branch
from
January 14, 2023 14:03
f1076ab
to
ec1ca0f
Compare
* Usage of self types deriving sealed interface. * Checker for @self classes with custom `Self` type parameter declared. * Self class with `Self` function. * Self class extending interface with `out` type parameter. * Self class with qualified this.
Some more questionable examples:
|
mglukhikh
reviewed
Jan 20, 2023
@@ -451,7 +451,7 @@ open class FirSupertypeResolverVisitor( | |||
private fun addSelfToTypeParameters(firClass: FirClassLikeDeclaration, session: FirSession) { | |||
val isSelf = firClass.getAnnotationByClassId(StandardClassIds.Annotations.Self, session) != null | |||
val params = firClass.typeParameters | |||
if (params is MutableList && isSelf) { | |||
if (params is MutableList && isSelf && params.find { it.symbol.name == SpecialNames.SELF_TYPE } == null) { |
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.
Please add a test confirming this check is needed
Add * to type parameters for classes with `@Self` annotation when class used as type. Add test for class with `@Self` annotation used as return type. Add test for class with `@Self` annotation used as value parameter.
test for anonymous objects
…pe parameter and custom type parameter
* Nested class extends outer self class * Nested class extends nested self class
* Lazy container with Self type, list and set implementations
* Allows to use this as Self type without explicit cast
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposal