Skip to content

Commit

Permalink
Fix local variable names to be snake case. It was just
Browse files Browse the repository at this point in the history
old habbits, not something I was proposing.
  • Loading branch information
lattner committed Jun 11, 2023
1 parent ec7f3b8 commit da058f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
38 changes: 19 additions & 19 deletions proposals/lifetimes-and-provenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ bit different than Rust.
For example, we expect this to behave like the comments indicate:

```mojo
var someStr = String("hello")
var some_str = String("hello")
# The StringRef contains a reference to the someStr value
var someStrRef = StringRef(someStr)
# The StringRef contains a reference to the some_str value
var some_str_ref = StringRef(some_str)
# Last use of someStr, but don't destroy it because there is a use of
# Last use of some_str, but don't destroy it because there is a use of
# the reference below!
use(someStr)
use(some_str)
# References must be propagatable through methods.
someStrRef = someStrRef.drop_front().drop_back()
print(someStrRef) # Prints "ell"
# someStr destroyed here after last reference to it
some_str_ref = some_str_ref.drop_front().drop_back()
print(some_str_ref) # Prints "ell"
# some_str destroyed here after last reference to it
```

The major thing that Mojo (and Rust) need from lifetimes is what is called
Expand Down Expand Up @@ -186,12 +186,12 @@ fn example(cond: Bool):
var str2 = String("goodbye")
# Defines an immutable reference with inferred lifetime.
borrowed strRef = str1 if cond else str2
print(strRef)
borrowed str_ref = str1 if cond else str2
print(str_ref)
# Defines a mutable reference.
inout strRef = str1 if cond else str2
strRef = "a new look"
inout mut_ref = str1 if cond else str2
mut_ref = "a new look"
# One of these will have changed.
print(str1)
Expand All @@ -206,13 +206,13 @@ fn example[life: lifetime](cond: Bool,
x: borrowed[life] String,
y: borrowed[life] String):
# Late initialized local borrow with explicit lifetime
borrowed[life] strRef : String
borrowed[life] str_ref : String
if cond:
strRef = x
str_ref = x
else:
strRef = y
print(strRef)
str_ref = y
print(str_ref)
```

### Keyword (?) for static lifetime
Expand Down Expand Up @@ -292,9 +292,9 @@ being more efficient). We can do this by allowing:

```mojo
struct Pointer[type: AnyType, life: lifetime]:
# This getitem returns a reference, so no setitem needed.
fn __getitem__(self, offset: Int) -> inout[life] type:
return __get_address_as_lvalue[life](...)
# This getitem returns a reference, so no setitem needed.
fn __getitem__(self, offset: Int) -> inout[life] type:
return __get_address_as_lvalue[life](...)
```

We will also need to extend the magic `__get_address_as_lvalue` style functions
Expand Down
8 changes: 4 additions & 4 deletions proposals/lifetimes-keyword-renaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ the current Mojo keyword paint:
Instead of reading an argument as “this function takes foo which is a borrowed string”, we would read it as “foo is a borrow/ref of a string”. This makes it consistent with local borrows on the stack:

```mojo
fn doStuff(x: ref(a) String): ...
fn do_stuff(x: ref(a) String): ...
fn usage():
var str = String("hello")
ref r = str # Defines a local borrow of str.
doStuff(str) # Bind a reference to 'str'
doStuff(r) # Pass on existing reference 'str'
do_stuff(str) # Bind a reference to 'str'
do_stuff(r) # Pass on existing reference 'str'
```

## `inout` Keyword => `ref` or `mutref` (??)
Expand All @@ -40,7 +40,7 @@ arguments, so the `inout` keyword may return in the future. For example, we may
actually want to bind computed values to mutable references:

```mojo
for inout x in someArrayWithGetItemSetItem:
for inout x in some_array_with_getitem_and_setitem:
x += 1
```

Expand Down

0 comments on commit da058f1

Please sign in to comment.