Skip to content

Commit

Permalink
Merge pull request #2622 from onflow/fxamacker/decouple-address-from-…
Browse files Browse the repository at this point in the history
…atree-storage-id

Delegate storage address to Atree
  • Loading branch information
fxamacker authored Jul 6, 2023
2 parents 9397f7b + 6751377 commit ffa896e
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2587,11 +2587,10 @@ func (v *ArrayValue) Transfer(
}

currentStorageID := v.StorageID()
currentAddress := currentStorageID.Address

array := v.array

needsStoreTo := address != currentAddress
needsStoreTo := v.NeedsStoreTo(address)
isResourceKinded := v.IsResourceKinded(interpreter)

if needsStoreTo || !isResourceKinded {
Expand Down Expand Up @@ -2698,7 +2697,7 @@ func (v *ArrayValue) Clone(interpreter *Interpreter) Value {

array, err := atree.NewArrayFromBatchData(
config.Storage,
v.StorageID().Address,
v.StorageAddress(),
v.array.Type(),
func() (atree.Value, error) {
value, err := iterator.Next()
Expand Down Expand Up @@ -2764,8 +2763,12 @@ func (v *ArrayValue) StorageID() atree.StorageID {
return v.array.StorageID()
}

func (v *ArrayValue) StorageAddress() atree.Address {
return v.array.Address()
}

func (v *ArrayValue) GetOwner() common.Address {
return common.Address(v.StorageID().Address)
return common.Address(v.StorageAddress())
}

func (v *ArrayValue) SemaType(interpreter *Interpreter) sema.ArrayType {
Expand All @@ -2777,7 +2780,7 @@ func (v *ArrayValue) SemaType(interpreter *Interpreter) sema.ArrayType {
}

func (v *ArrayValue) NeedsStoreTo(address atree.Address) bool {
return address != v.StorageID().Address
return address != v.StorageAddress()
}

func (v *ArrayValue) IsResourceKinded(interpreter *Interpreter) bool {
Expand Down Expand Up @@ -15571,7 +15574,7 @@ func (v *CompositeValue) InitializeFunctions(interpreter *Interpreter) {
}

func (v *CompositeValue) OwnerValue(interpreter *Interpreter, locationRange LocationRange) OptionalValue {
address := v.StorageID().Address
address := v.StorageAddress()

if address == (atree.Address{}) {
return NilOptionalValue
Expand Down Expand Up @@ -15683,7 +15686,7 @@ func (v *CompositeValue) SetMember(
}()
}

address := v.StorageID().Address
address := v.StorageAddress()

value = value.Transfer(
interpreter,
Expand Down Expand Up @@ -16023,7 +16026,7 @@ func (v *CompositeValue) Storable(
}

func (v *CompositeValue) NeedsStoreTo(address atree.Address) bool {
return address != v.StorageID().Address
return address != v.StorageAddress()
}

func (v *CompositeValue) IsResourceKinded(interpreter *Interpreter) bool {
Expand Down Expand Up @@ -16075,11 +16078,11 @@ func (v *CompositeValue) Transfer(
}

currentStorageID := v.StorageID()
currentAddress := currentStorageID.Address
currentAddress := v.StorageAddress()

dictionary := v.dictionary

needsStoreTo := address != currentAddress
needsStoreTo := v.NeedsStoreTo(address)
isResourceKinded := v.IsResourceKinded(interpreter)

if needsStoreTo && v.Kind == common.CompositeKindContract {
Expand Down Expand Up @@ -16242,7 +16245,7 @@ func (v *CompositeValue) Clone(interpreter *Interpreter) Value {

dictionary, err := atree.NewMapFromBatchData(
config.Storage,
v.StorageID().Address,
v.StorageAddress(),
atree.NewDefaultDigesterBuilder(),
v.dictionary.Type(),
StringAtreeValueComparator,
Expand Down Expand Up @@ -16329,7 +16332,7 @@ func (v *CompositeValue) DeepRemove(interpreter *Interpreter) {
}

func (v *CompositeValue) GetOwner() common.Address {
return common.Address(v.StorageID().Address)
return common.Address(v.StorageAddress())
}

// ForEachField iterates over all field-name field-value pairs of the composite value.
Expand All @@ -16352,6 +16355,10 @@ func (v *CompositeValue) StorageID() atree.StorageID {
return v.dictionary.StorageID()
}

func (v *CompositeValue) StorageAddress() atree.Address {
return v.dictionary.Address()
}

func (v *CompositeValue) RemoveField(
interpreter *Interpreter,
_ LocationRange,
Expand Down Expand Up @@ -17575,11 +17582,10 @@ func (v *DictionaryValue) Transfer(
}

currentStorageID := v.StorageID()
currentAddress := currentStorageID.Address

dictionary := v.dictionary

needsStoreTo := address != currentAddress
needsStoreTo := v.NeedsStoreTo(address)
isResourceKinded := v.IsResourceKinded(interpreter)

if needsStoreTo || !isResourceKinded {
Expand Down Expand Up @@ -17701,7 +17707,7 @@ func (v *DictionaryValue) Clone(interpreter *Interpreter) Value {

dictionary, err := atree.NewMapFromBatchData(
config.Storage,
v.StorageID().Address,
v.StorageAddress(),
atree.NewDefaultDigesterBuilder(),
v.dictionary.Type(),
valueComparator,
Expand Down Expand Up @@ -17779,13 +17785,17 @@ func (v *DictionaryValue) DeepRemove(interpreter *Interpreter) {
}

func (v *DictionaryValue) GetOwner() common.Address {
return common.Address(v.StorageID().Address)
return common.Address(v.StorageAddress())
}

func (v *DictionaryValue) StorageID() atree.StorageID {
return v.dictionary.StorageID()
}

func (v *DictionaryValue) StorageAddress() atree.Address {
return v.dictionary.Address()
}

func (v *DictionaryValue) SemaType(interpreter *Interpreter) *sema.DictionaryType {
if v.semaType == nil {
// this function will panic already if this conversion fails
Expand All @@ -17795,7 +17805,7 @@ func (v *DictionaryValue) SemaType(interpreter *Interpreter) *sema.DictionaryTyp
}

func (v *DictionaryValue) NeedsStoreTo(address atree.Address) bool {
return address != v.StorageID().Address
return address != v.StorageAddress()
}

func (v *DictionaryValue) IsResourceKinded(interpreter *Interpreter) bool {
Expand Down

0 comments on commit ffa896e

Please sign in to comment.