From da058f15265a83e6d3ab49dc014420a97ba5ca07 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 11 Jun 2023 10:44:15 -0700 Subject: [PATCH] Fix local variable names to be snake case. It was just old habbits, not something I was proposing. --- proposals/lifetimes-and-provenance.md | 38 ++++++++++++------------- proposals/lifetimes-keyword-renaming.md | 8 +++--- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/proposals/lifetimes-and-provenance.md b/proposals/lifetimes-and-provenance.md index 827f8396f7..8987a46058 100644 --- a/proposals/lifetimes-and-provenance.md +++ b/proposals/lifetimes-and-provenance.md @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/proposals/lifetimes-keyword-renaming.md b/proposals/lifetimes-keyword-renaming.md index 2dc192ba9f..801b9bc197 100644 --- a/proposals/lifetimes-keyword-renaming.md +++ b/proposals/lifetimes-keyword-renaming.md @@ -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` (??) @@ -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 ```