-
Notifications
You must be signed in to change notification settings - Fork 0
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
Two receivers (extension and dispatch) support #234
Conversation
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.
Thanks, this generally looks good! Some questions on the details
if (isExtension) signature.run { extensionReceiver } | ||
else signature.run { dispatchReceiver } |
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.
Why not just signature.extensionReceiver
?
if (isExtension) substitutions[ExtraSpecialNames.E_THIS] | ||
else substitutions[ExtraSpecialNames.D_THIS] |
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.
For names in the code, I'd prefer to avoid such abbreviations
@@ -165,7 +165,7 @@ class ProgramConverter(val session: FirSession, override val config: PluginConfi | |||
val receiverType: TypeEmbedding? = type.receiverType(session)?.let { embedType(it) } | |||
val paramTypes: List<TypeEmbedding> = type.valueParameterTypesWithoutReceivers(session).map(::embedType) | |||
val returnType: TypeEmbedding = embedType(type.returnType(session)) | |||
val signature = CallableSignatureData(receiverType, paramTypes, returnType) | |||
val signature = CallableSignatureData(receiverType, null, paramTypes, returnType) |
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.
Why can't we resolve this type at this point?
val isExtensionReceiverUnique = symbol.receiverParameter?.isUnique(session) ?: false | ||
val isExtensionReceiverBorrowed = symbol.receiverParameter?.isBorrowed(session) ?: false |
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 this information always about the extension receiver? That seems a bit strange
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.
At least I don't quite understand here what would be the syntax for dispatch. If it is not possible to mark the dispatch receiver as unique directly, I suppose we could introduce a special annotation @MemberUnique
for member functions specifically.
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.
@francescoo22 We definitely want to be able to have the dispatch receiver be unique. I would expect @receiver:Unique
to work.
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.
As far as I know it's not possible to annotate the dispatch receiver with @receiver:Unique
.
I think @GrigoriiSolnyshkin is right, we need to introduce a special annotation like @receiverUnique
and annotate the function.
This is what the Kotlin doc says about the receiver target for annotations: "receiver
(receiver parameter of an extension function or property)"
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.
Ah, that's annoying. LGTM then
...rification/formver.core/src/org/jetbrains/kotlin/formver/conversion/StmtConversionVisitor.kt
Show resolved
Hide resolved
21d0ae2
to
7826b35
Compare
private fun embeddedVarByIndex(ix: Int): VariableEmbedding = | ||
resolveByIndex(ix, { signature.dispatchReceiver!! }) { signature.params[it] } |
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.
What are the rules on using an extension receiver here? I'm guessing we just don't support it.
val isExtensionReceiverUnique = symbol.receiverParameter?.isUnique(session) ?: false | ||
val isExtensionReceiverBorrowed = symbol.receiverParameter?.isBorrowed(session) ?: false |
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.
@francescoo22 We definitely want to be able to have the dispatch receiver be unique. I would expect @receiver:Unique
to work.
if (isExtension) substitutions[ExtraSpecialNames.EXTENSION_THIS] | ||
else substitutions[ExtraSpecialNames.DISPATCH_THIS] |
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.
Modifying the key type would probably be the more elegant way to deal with this, but it's okay to do as-is.
…through whole hierarchy
…ep recursive lookup)
517ba7b
to
bc4907a
Compare
(into function with two arguments).
this
which chooses dispatch/extension receiver, but does not take into considerationthis
parameters from outer scopes.