-
Notifications
You must be signed in to change notification settings - Fork 1k
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
A Problem of Neo.VM.Types.Struct
#3518
Comments
I think DUP for all types are like ref type.. |
@shargon @roman-khimov is struct be of any real use that can not be replaced with Array? isn't array already sufficient? |
It's special and mostly follows its primary use cases. Technically it can be emulated by compilers with arrays (although deep copying is not really fun and will burn some GAS), but at the same time this type is being currently used (at least by NeoGo, likely other compilers as well, @gsmachado, @ixje) and I just wouldn't touch it unless there is some huge problem (implicit copies can be problematic, but we hope most of them were solved previously). |
I always thought that we don't need the structs, but, now it's hard to remove |
Same here: I agree ☝️ . |
May NEO can re-explain
|
There are several builtin types in Neo-VM, and each type has its own characteristics(about Mutability, Reference or Value). For examples:
But characteristics of
Struct
are somewhat ambiguous(or unclear).According to doc from https://developers.neo.org/docs/n3/Advances/Neo%20VM%20instructions, the semantics of Neo-VM builtin types are affected by some types in C#.
Struct
Inherited fromArray
, aClone
method is added, andEquals
is not supported.From some running logic of the Neo-VM, it seems that
Struct
should be a value type. For examples:Struct
add to anArray
or aMap
(byAppend
,SetItem
), it will be cloned;Struct
picked from anArray
or aMap
(byValues
), it will be cloned too.Struct
is deep copied , it's subStruct
will deep copied too.But from other logic, struct seems to be a reference type, For examples:
Dup
aStruct
does not get a copy of the originalStruct
.PickItem
is similar toDup
operation.so if a dupped or picked
Struct
is mutated bySetItem
,ClearItems
orPopItem
, the originalStruct
is mutated too(becauseStruct
Inherited fromArray
,swtich (x) { case Array _: ... }
orif (x is Array
) will be true, a struct can be mutated bySetItem
,ClearItems
orPopItem
).So, is
Struct
value type or reference type?If
Struct
is value type, why not copied whenDup
,PickItem
or ...?If
Struct
is reference type, why needs to copy whenAppend
,Values
or ..?The text was updated successfully, but these errors were encountered: