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

Values, variables, pointers, and references #821

Closed
wants to merge 13 commits into from
Closed

Values, variables, pointers, and references #821

wants to merge 13 commits into from

Commits on Sep 9, 2021

  1. 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!
    chandlerc committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    778c275 View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2021

  1. Apply suggestions from code review

    Co-authored-by: josh11b <[email protected]>
    Co-authored-by: Richard Smith <[email protected]>
    3 people authored Sep 11, 2021
    Configuration menu
    Copy the full SHA
    872df42 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8cba545 View commit details
    Browse the repository at this point in the history
  3. format and toc

    chandlerc committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    103247d View commit details
    Browse the repository at this point in the history
  4. Updates based on review.

    chandlerc committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    0f64c1e View commit details
    Browse the repository at this point in the history
  5. toc

    chandlerc committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    8189b40 View commit details
    Browse the repository at this point in the history
  6. more updates from review

    chandlerc committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    a88b292 View commit details
    Browse the repository at this point in the history
  7. toc

    chandlerc committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    26c1dd6 View commit details
    Browse the repository at this point in the history

Commits on Sep 15, 2021

  1. spelling fix

    chandlerc committed Sep 15, 2021
    Configuration menu
    Copy the full SHA
    9a967ed View commit details
    Browse the repository at this point in the history

Commits on Sep 17, 2021

  1. Configuration menu
    Copy the full SHA
    aafedfc View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    702e12a View commit details
    Browse the repository at this point in the history
  3. toc

    chandlerc committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    5307a3d View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2021

  1. Configuration menu
    Copy the full SHA
    d10013f View commit details
    Browse the repository at this point in the history