-
Notifications
You must be signed in to change notification settings - Fork 137
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
Introduce dereference
on the Reference type
#2945
Introduce dereference
on the Reference type
#2945
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that there are two types of reference values - EphemeralReferenceValue
and StorageReferenceValue
.
Should this function be implemented on both or just EphemeralReferenceValue
?
sema.ReferenceDereferenceFunctionType(v.BorrowedType), | ||
func(invocation Invocation) Value { | ||
return v.Value | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of dereference
on EphemeralReferenceValue
looks straightforward. Is this correct or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this create new Value (copy of the value somehow ) ? something like Transfer etc.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more like:
let x: &[Int] = &[1]
x.dereference().append(2)
PS: if we make a copy also we can support non-primitives like structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this needs a Transfer
to the stack, i.e.
.Transfer(
interpreter,
locationRange,
atree.Address{},
false,
nil,
nil,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point @bluesign to test by operating on the returned value directly, my example above, let ints2 = ref.dereference()
was adding a copy 👍
@darkdrag00nv2 yeah, dereferencing needs to be implemented for both Dereferencing should be supported at the type level for references in general ( |
@turbolent You've mentioned primitive types and containers of primitive types. Could we not define it for all subtypes of |
Only edge case I see is attachments ( Contracts are covered by transfer ), attachments would allow detaching and attaching to new struct. ( which we don't allow currently ) struct T{
access(all) var tag : Int
init(_ tag:Int){
self.tag = tag
}
}
attachment X for AnyStruct{
}
fun main(): AnyStruct {
var t1 = T(1)
var t2 = T(2)
var res = attach X() to t1
var ff = res[X]!.dereference
var newAttached = attach ff() to t2
return newAttached
}
|
Not sure why this got closed. This should now be opened against the master (#2971) |
Same, it seems as though it was closed automatically when |
Closes #2803
Description
master
branchFiles changed
in the Github PR explorer