Skip to content

Commit

Permalink
Delegate Cadence composite Storable() to Atree
Browse files Browse the repository at this point in the history
Currently, Cadence ArrayValue, CompositeValue, and DictionaryValue
creates atree.Storable directly from StorageID of its Atree values.

In the future, some Atree values can be inlined so they don't have
StorageID, and Atree values need to handle Storable depending
on maxInlineSize and other factors.

This commit delegates Cadence composite values' Storable() to its
internal Atree values.  So future changes to Atree values and their
storables don't break Cadence.
  • Loading branch information
fxamacker committed Jun 30, 2023
1 parent 5f84e78 commit a0ea3d5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2540,8 +2540,12 @@ func (v *ArrayValue) Equal(interpreter *Interpreter, locationRange LocationRange
return true
}

func (v *ArrayValue) Storable(_ atree.SlabStorage, _ atree.Address, _ uint64) (atree.Storable, error) {
return atree.StorageIDStorable(v.StorageID()), nil
func (v *ArrayValue) Storable(
storage atree.SlabStorage,
address atree.Address,
maxInlineSize uint64,
) (atree.Storable, error) {
return v.array.Storable(storage, address, maxInlineSize)
}

func (v *ArrayValue) IsReferenceTrackedResourceKindedValue() {}
Expand Down Expand Up @@ -16022,12 +16026,16 @@ func (v *CompositeValue) IsStorable() bool {
return v.Location != nil
}

func (v *CompositeValue) Storable(_ atree.SlabStorage, _ atree.Address, _ uint64) (atree.Storable, error) {
func (v *CompositeValue) Storable(
storage atree.SlabStorage,
address atree.Address,
maxInlineSize uint64,
) (atree.Storable, error) {
if !v.IsStorable() {
return NonStorable{Value: v}, nil
}

return atree.StorageIDStorable(v.StorageID()), nil
return v.dictionary.Storable(storage, address, maxInlineSize)
}

func (v *CompositeValue) NeedsStoreTo(address atree.Address) bool {
Expand Down Expand Up @@ -17533,8 +17541,12 @@ func (v *DictionaryValue) Equal(interpreter *Interpreter, locationRange Location
}
}

func (v *DictionaryValue) Storable(_ atree.SlabStorage, _ atree.Address, _ uint64) (atree.Storable, error) {
return atree.StorageIDStorable(v.StorageID()), nil
func (v *DictionaryValue) Storable(
storage atree.SlabStorage,
address atree.Address,
maxInlineSize uint64,
) (atree.Storable, error) {
return v.dictionary.Storable(storage, address, maxInlineSize)
}

func (v *DictionaryValue) IsReferenceTrackedResourceKindedValue() {}
Expand Down

0 comments on commit a0ea3d5

Please sign in to comment.