-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support mutable generics and remove var flag #158
Closed
Closed
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
gsps
reviewed
May 20, 2021
yannbolliger
force-pushed
the
mut-generics
branch
from
May 20, 2021 14:10
04970ad
to
170b129
Compare
yannbolliger
force-pushed
the
mut-generics
branch
3 times, most recently
from
May 26, 2021 13:52
7ca4d59
to
8956844
Compare
Merged
yannbolliger
force-pushed
the
mut-generics
branch
from
June 7, 2021 15:42
92d8c6e
to
72d0bd3
Compare
romac
approved these changes
Jun 8, 2021
yannbolliger
force-pushed
the
mut-generics
branch
from
June 8, 2021 10:32
72d0bd3
to
3022425
Compare
This is safe becaues it consumes whatever is the initializer.
(They fresh copy the last expression of each arm themselves.)
yannbolliger
force-pushed
the
mut-generics
branch
from
June 24, 2021 10:36
3022425
to
3b126e1
Compare
Closing in favour of #164. Most of the changes here are contained there. |
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.
This PR is the result of many discussions with @romac @gsps @vkuncak. There was also great support by @jad-hamza on the Stainless side of things, thanks!
The PR brings the mutability support of
rust-stainless
closer to Rust's semantics by dropping thevar
annotation on fields.Closes #157. Closes #99 because now, all fields can be mutated with
mut
at binding.This is a big step for #92 and brings us closer to #140.
Theory
The safety of what we do in this PR, mainly on this single line change is guaranteed by the following theoretical argument:
freshCopy
at our own riskBorrowKind::Shared
), it’s aliasable and we can therefore safelyfreshCopy
it.There are 3 other places, where
freshCopy
is/was introduced:For function parameters that are taken by-value. It's safe to
freshCopy
them because the by-value/move semantics guarantee that they are owned i.e. there are no other references to them.Return values are
freshCopy
'd to avoid aliasing. This is safe (currently) because we only support returning by-value or by shared, immutable reference.stainless::Map
is a special case. In order to get support for mutable value types, we needed to refactor the map extraction. Behind the immutable Rust interface that resides inlibstainless
the map is now extracted asMutableMap
. To combat aliasing, theinsert
andremove
method now consumeself
. This allows on the extraction side, to extract for examplelet b = a.insert(0, 1);
as the following in Scala: