You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both values and variables can be marked with these lifetimes
In the compiler:
enumLifetime{Inside,Outside(arg:u64),}structArg{
...
// args can have their lifetime tied input args// this number is the input arg that the lifetime is tied topublifetime:Option<Lifetime>,}
Sarus examples: [i64;100] is an array of i64, [..] returns a slice from 0 to len
fnsome_func() -> (b:[u8]){
a = [0;100]//inside, copy
b = a[..]//inside, not copy// ERROR b lifetime is inside, and b is not copy// consider declaring fn as inline}
When a function returns or mutates something that derives its lifetime from an arg, that is shown in the funcdef.
fnsome_func(a:[u8]) -> (b:[u8]){
b = a[5..10]//inherit arg a, not copy}fnother_func(){
arr = [0;100]//inside, copy
a = arr[..]//inside, not copy//fn some_func says return 0 lifetime is the same as arg 0
b = some_func(a)//inside, not copy}
fnmutates_an_arg(a:Stuff){
b = [0;100][..]//inside, not copy
a.s = b
//ERROR b lifetime is inside, and b is not copy//OR perhaps in caller's function b is marked as no longer usable after this call}
fnmutates_an_arg(a:[i64],b:Stuff){
b.sl = a //arg b inherit arg a, not copy}fnother_func(arr:[i64;100]){
s = Stuff{//outside, not copysl: arr[..]//outside, not copy}
a = [0;100][..]//inside, not copy//fn mutates_an_arg says it will make arg 1 lifetime match arg 0mutates_an_arg(a, s)//inside, not copy//arg 0 is inside, so now s is marked with inside}
Need to also account of lifetime implications in loops. The scope of a loop will need to be handled similarly to a function call.
fnmain() -> (){
a = [0;10000][..]
i = 0while i < 5{i+=1}:{if i == 0{
b = [2;10000]//(while)inner, copy
a = b[..]//TODO compiler error}}}
The text was updated successfully, but these errors were encountered:
Ideas regarding lifetimes in Sarus
There would be 2 lifetimes: inside and outside
Both values and variables can be marked with these lifetimes
In the compiler:
Sarus examples:
[i64;100]
is an array of i64,[..]
returns a slice from 0 to lenWhen a function returns or mutates something that derives its lifetime from an arg, that is shown in the funcdef.
Need to also account of lifetime implications in loops. The scope of a loop will need to be handled similarly to a function call.
The text was updated successfully, but these errors were encountered: