-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Values, variables, pointers, and references #821
Closed
Closed
Commits on Sep 9, 2021
-
Flesh out and solidify the design around values, variables, and
pointers. Explicitly discuss the use cases of references in C++ and propose specific approaches to address those use cases. This is something that we've been discussing across the team for a long time, and while there are definitely still challenges in this space we will need to address going forward, I want to try to codify where we are at and provide for a few fundamentals that haven't really been spelled out previously. That said, I've been staring at this document for *far* too long in a draft, and so I may be missing parts that are confusing or need work, so any help from folks to make this a coherent story is definitely appreciated. The current structure and wording is heavily informed by several reviews and suggestions from @zygoloid, @josh11b, and @wolffg with much appreciation. =] Some core examples of the consequence of this proposal: - Using `let` where we currently use `var` to declare a locally scoped immutable view of a value: ``` let index: i32 = 42; ``` - Specifying the expected semantics of parameters to by default be these immutable views of values like `let`. These should behave like C++ `const` references but allowing copies under *as-if*. - Specifying that `var` creates an *L-value* and binds names to it. - Defining `var` is being allowed to nest within `let` to mark a part of a pattern as an L-value: ``` let (x: i64, var y: i64) = (1, 2); // Ok to mutate `y`: y += F(); ``` When the entire declaration is a `var` the `let` can be omitted. This works with function parameters as well to mark *consuming* an input into a locally mutable L-value: ``` fn RegisterName(var name: String) { // `name` is a local L-value in this function and can be mutated. } ``` - Implementing operators by rewriting into method calls through an interface, which can then use `[addr me: Self*]` to implicitly obtain a mutable pointer to an object for mutating operators. - Providing user-defined pointer-like types and the implementation of both the `*`-operator and `->` member access in terms of rewriting into member calls through an interface and then forming L-values. - Providing indexed access through rewrites into method calls as well. Beyond these use cases, thread-safe interfaces and more complex lifetime based dispatch are deferred for future work. See the proposal for details here, and looking forward to feedback!
Configuration menu - View commit details
-
Copy full SHA for 778c275 - Browse repository at this point
Copy the full SHA 778c275View commit details
Commits on Sep 11, 2021
-
Apply suggestions from code review
Co-authored-by: josh11b <[email protected]> Co-authored-by: Richard Smith <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 872df42 - Browse repository at this point
Copy the full SHA 872df42View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8cba545 - Browse repository at this point
Copy the full SHA 8cba545View commit details -
Configuration menu - View commit details
-
Copy full SHA for 103247d - Browse repository at this point
Copy the full SHA 103247dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 0f64c1e - Browse repository at this point
Copy the full SHA 0f64c1eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8189b40 - Browse repository at this point
Copy the full SHA 8189b40View commit details -
Configuration menu - View commit details
-
Copy full SHA for a88b292 - Browse repository at this point
Copy the full SHA a88b292View commit details -
Configuration menu - View commit details
-
Copy full SHA for 26c1dd6 - Browse repository at this point
Copy the full SHA 26c1dd6View commit details
Commits on Sep 15, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 9a967ed - Browse repository at this point
Copy the full SHA 9a967edView commit details
Commits on Sep 17, 2021
-
Configuration menu - View commit details
-
Copy full SHA for aafedfc - Browse repository at this point
Copy the full SHA aafedfcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 702e12a - Browse repository at this point
Copy the full SHA 702e12aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5307a3d - Browse repository at this point
Copy the full SHA 5307a3dView commit details
Commits on Sep 25, 2021
-
Configuration menu - View commit details
-
Copy full SHA for d10013f - Browse repository at this point
Copy the full SHA d10013fView commit details
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.