Skip to content
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

Generic Run Analogues #218

Merged
merged 8 commits into from
Jul 15, 2024
Merged

Conversation

GrigoriiSolnyshkin
Copy link
Collaborator

With this pull request functions analogous to Kotlin run successfully compile to Viper if they're inline.
For instance, call to
inline fun <T, R> T.copiedRun(block: T.() -> R): R = block()
will be correctly inlined.

Support for real stdlib run and other notable extension functions (also, let etc.) as well as the cases with multiple possible receivers will be implemented in future PRs.

Copy link
Owner

Choose a reason for hiding this comment

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

Why treat the receiver in a special way like this? We can resolve parameters already, and the name of a parameter can be some special this object. Does this function add much?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it to avoid too many SpecialNames.THIS calls. Besides, the implementation for non-inline parameters is a little bit different.
I think I will need such function but with parameters in the upcoming PRs to find a proper receiver.
It turns out that explicit this in Kotlin can only refer to the innermost scope (with receiver argument), but implicit "this" may come from anywhere. With parameters the situation is different.

@jesyspa
Copy link
Owner

jesyspa commented Jul 9, 2024

The thing that concerns me here is that we are collapsing two different notions (dispatch receiver and extension receiver) into one. Maybe if we're working on this anyway, it would be best if we supported both? Or is there some technical reason why this would be much harder?

@GrigoriiSolnyshkin
Copy link
Collaborator Author

Or is there some technical reason why this would be much harder?

@jesyspa, well, in this case we would need to distinguish possible implicit receivers already.

@jesyspa
Copy link
Owner

jesyspa commented Jul 12, 2024

Let's have a call about this on Monday, I'm not entirely against doing it this way but it seems risky.

@GrigoriiSolnyshkin GrigoriiSolnyshkin merged commit 85731bf into formal-verification Jul 15, 2024
1 check passed
@GrigoriiSolnyshkin GrigoriiSolnyshkin deleted the generic-extension-run branch July 15, 2024 10:09
jesyspa pushed a commit that referenced this pull request Jul 26, 2024
With this pull request functions analogous to Kotlin `run` successfully
compile to Viper if they're inline.
For instance, call to
```inline fun <T, R> T.copiedRun(block: T.() -> R): R = block()```
will be correctly inlined.

Support for real stdlib `run` and other notable extension functions (`also`, `let` etc.) as well as the cases with multiple possible receivers will be implemented in future PRs.
Eric-Song-Nop pushed a commit that referenced this pull request Jul 30, 2024
With this pull request functions analogous to Kotlin `run` successfully
compile to Viper if they're inline.
For instance, call to
```inline fun <T, R> T.copiedRun(block: T.() -> R): R = block()```
will be correctly inlined.

Support for real stdlib `run` and other notable extension functions (`also`, `let` etc.) as well as the cases with multiple possible receivers will be implemented in future PRs.
Eric-Song-Nop pushed a commit that referenced this pull request Jul 30, 2024
With this pull request functions analogous to Kotlin `run` successfully
compile to Viper if they're inline.
For instance, call to
```inline fun <T, R> T.copiedRun(block: T.() -> R): R = block()```
will be correctly inlined.

Support for real stdlib `run` and other notable extension functions (`also`, `let` etc.) as well as the cases with multiple possible receivers will be implemented in future PRs.
Eric-Song-Nop pushed a commit that referenced this pull request Jul 30, 2024
With this pull request functions analogous to Kotlin `run` successfully
compile to Viper if they're inline.
For instance, call to
```inline fun <T, R> T.copiedRun(block: T.() -> R): R = block()```
will be correctly inlined.

Support for real stdlib `run` and other notable extension functions (`also`, `let` etc.) as well as the cases with multiple possible receivers will be implemented in future PRs.
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.

2 participants