-
Notifications
You must be signed in to change notification settings - Fork 148
New opcode 'PACKSTRUCT' #51
Comments
Is there a specific scenario that you need this for? |
Without going into too much detail, we effectively store every value as an array of
An equivalent struct is much more expensive to create, to the point that it's not feasible to use structs at all. If we were able to use structs, then we could make other parts more efficient, for example,
4x more efficient if we can use a struct and a single [1] Note, later iterations of neo-one will optimize this away when possible, but still in some cases we will need to continue wrapping. |
Creating struct with
Creating struct without
|
@dicarlo2 Not sure why you should need that? Structs are treated the same as arrays. Their values are just an ordered union on the stack. The compiler should track all additional information about the underlying type and index of a field. |
@anthdm Structs do not work the same as arrays - I invite you to take a look at the source code to see the differences. |
@erikzhang do you have objections to adding |
1256: refactor(PACK+NEWSTRUCT): Replace PACKSTRUCT with PACK+NEWSTRUCT r=dicarlo2 a=afragapane ### Description of the Change Removes the PACKSTRUCT Opcode and modifies NEWSTRUCT/NEWARRAY to be able to convert an existing array into a struct and struct into array. This allows the use of a PACK+NEWSTRUCT pair of opcodes in place of PACKSTRUCT. ### Test Plan Added tests for the conversions in NEWSTRUCT and NEWARRAY. Updated existing tests to reflect the slightly higher GAS costs of neo-one compiled contracts. ### Alternate Designs Previously the plan was to implement our PACKSTRUCT in the neo-vm as per neo-project/neo-vm#51 and neo-project/neo-vm#88. This new solution was suggested and implemented here: neo-project/neo-vm#91. ### Benefits ### Possible Drawbacks Very slightly higher GAS cost for neo-one compiled smart contracts. ### Applicable Issues #1254 Co-authored-by: afragapane <ahfragapane@gmail.com>
1256: refactor(PACK+NEWSTRUCT): Replace PACKSTRUCT with PACK+NEWSTRUCT r=dicarlo2 a=afragapane ### Description of the Change Removes the PACKSTRUCT Opcode and modifies NEWSTRUCT/NEWARRAY to be able to convert an existing array into a struct and struct into array. This allows the use of a PACK+NEWSTRUCT pair of opcodes in place of PACKSTRUCT. ### Test Plan Added tests for the conversions in NEWSTRUCT and NEWARRAY. Updated existing tests to reflect the slightly higher GAS costs of neo-one compiled contracts. ### Alternate Designs Previously the plan was to implement our PACKSTRUCT in the neo-vm as per neo-project/neo-vm#51 and neo-project/neo-vm#88. This new solution was suggested and implemented here: neo-project/neo-vm#91. ### Benefits ### Possible Drawbacks Very slightly higher GAS cost for neo-one compiled smart contracts. ### Applicable Issues #1254 Co-authored-by: afragapane <ahfragapane@gmail.com>
Like
PACK
but for structs.The text was updated successfully, but these errors were encountered: