Skip to content

Commit

Permalink
Merge pull request #3048 from onflow/bastian/atree-register-inlining-…
Browse files Browse the repository at this point in the history
…v1.0
  • Loading branch information
turbolent authored Apr 8, 2024
2 parents 40b4d69 + fccfa81 commit b591a0d
Show file tree
Hide file tree
Showing 56 changed files with 2,812 additions and 823 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/kr/pretty v0.3.1
github.com/leanovate/gopter v0.2.9
github.com/logrusorgru/aurora/v4 v4.0.0
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f
github.com/onflow/atree v0.6.1-0.20240314011440-92714cac03fb
github.com/rivo/uniseg v0.4.4
github.com/schollz/progressbar/v3 v3.13.1
github.com/stretchr/testify v1.8.4
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvr
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo=
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM=
github.com/onflow/atree v0.6.1-0.20240314011440-92714cac03fb h1:9w+8wseSv7TZ9ikGfKSZ6yJifgYLhm717Zo0SVKpGEQ=
github.com/onflow/atree v0.6.1-0.20240314011440-92714cac03fb/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A=
github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg=
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down Expand Up @@ -167,5 +167,5 @@ gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLF
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
17 changes: 11 additions & 6 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,21 @@ func ConvertValueToEntitlements(

var values []interpreter.Value

v.Iterate(inter, func(key, value interpreter.Value) (resume bool) {
values = append(values, key)
values = append(values, value)
return true
})
v.Iterate(
inter,
interpreter.EmptyLocationRange,
func(key, value interpreter.Value) (resume bool) {
values = append(values, key)
values = append(values, value)
return true
},
)

return interpreter.NewDictionaryValue(
return interpreter.NewDictionaryValueWithAddress(
inter,
interpreter.EmptyLocationRange,
dictionaryStaticType,
v.GetOwner(),
values...,
), nil

Expand Down
1 change: 1 addition & 0 deletions migrations/entitlements/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,7 @@ func TestRehash(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down
3 changes: 2 additions & 1 deletion migrations/legacy_character_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (v *LegacyCharacterValue) Transfer(
_ atree.Address,
remove bool,
storable atree.Storable,
_ map[atree.StorageID]struct{},
_ map[atree.ValueID]struct{},
_ bool,
) interpreter.Value {
if remove {
interpreter.RemoveReferencedSlab(storable)
Expand Down
33 changes: 33 additions & 0 deletions migrations/legacy_intersection_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ type LegacyIntersectionType struct {

var _ interpreter.StaticType = &LegacyIntersectionType{}

func (t *LegacyIntersectionType) Equal(other interpreter.StaticType) bool {
var otherTypes []*interpreter.InterfaceStaticType

switch other := other.(type) {

case *LegacyIntersectionType:
otherTypes = other.Types

case *interpreter.IntersectionStaticType:
otherTypes = other.Types

default:
return false
}

if len(t.Types) != len(otherTypes) {
return false
}

outer:
for _, typ := range t.Types {
for _, otherType := range otherTypes {
if typ.Equal(otherType) {
continue outer
}
}

return false
}

return true
}

func (t *LegacyIntersectionType) ID() common.TypeID {
interfaceTypeIDs := make([]string, 0, len(t.Types))
for _, interfaceType := range t.Types {
Expand Down
14 changes: 14 additions & 0 deletions migrations/legacy_primitivestatic_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ type LegacyPrimitiveStaticType struct {

var _ interpreter.StaticType = LegacyPrimitiveStaticType{}

func (t LegacyPrimitiveStaticType) Equal(other interpreter.StaticType) bool {
switch other := other.(type) {

case LegacyPrimitiveStaticType:
return t == other

case interpreter.PrimitiveStaticType:
return t.PrimitiveStaticType == other

default:
return false
}
}

func (t LegacyPrimitiveStaticType) ID() common.TypeID {
switch t.PrimitiveStaticType {
case interpreter.PrimitiveStaticTypeAuthAccount: //nolint:staticcheck
Expand Down
20 changes: 20 additions & 0 deletions migrations/legacy_reference_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ type LegacyReferenceType struct {

var _ interpreter.StaticType = &LegacyReferenceType{}

// Equal() compares both value and type of t and other.
// LegacyReferenceType.Equal() is needed because Equal() in general
// compares values and their types. Embedded ReferenceStaticType.Equal()
// returns false when other is *LegacyReferenceType type.
func (t *LegacyReferenceType) Equal(other interpreter.StaticType) bool {
switch other := other.(type) {

case *LegacyReferenceType:
return t.Authorization.Equal(other.Authorization) &&
t.ReferencedType.Equal(other.ReferencedType)

case *interpreter.ReferenceStaticType:
return t.Authorization.Equal(other.Authorization) &&
t.ReferencedType.Equal(other.ReferencedType)

default:
return false
}
}

func (t *LegacyReferenceType) ID() common.TypeID {
borrowedType := t.ReferencedType
return common.TypeID(
Expand Down
3 changes: 2 additions & 1 deletion migrations/legacy_string_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (v *LegacyStringValue) Transfer(
_ atree.Address,
remove bool,
storable atree.Storable,
_ map[atree.StorageID]struct{},
_ map[atree.ValueID]struct{},
_ bool,
) interpreter.Value {
if remove {
interpreter.RemoveReferencedSlab(storable)
Expand Down
26 changes: 15 additions & 11 deletions migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,22 @@ func (m *StorageMigration) MigrateNestedValue(
// Read the keys first, so the iteration wouldn't be affected
// by the modification of the nested values.
var existingKeysAndValues []keyValuePair
dictionary.Iterate(m.interpreter, func(key, value interpreter.Value) (resume bool) {
existingKeysAndValues = append(
existingKeysAndValues,
keyValuePair{
key: key,
value: value,
},
)
dictionary.IterateReadOnly(
m.interpreter,
emptyLocationRange,
func(key, value interpreter.Value) (resume bool) {
existingKeysAndValues = append(
existingKeysAndValues,
keyValuePair{
key: key,
value: value,
},
)

// continue iteration
return true
})
// continue iteration
return true
},
)

for _, existingKeyAndValue := range existingKeysAndValues {
existingKey := existingKeyAndValue.key
Expand Down
2 changes: 2 additions & 0 deletions migrations/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func TestMultipleMigrations(t *testing.T) {
false,
nil,
nil,
true, // storedValue is standalone
)

inter.WriteStored(
Expand Down Expand Up @@ -621,6 +622,7 @@ func TestMigrationError(t *testing.T) {
false,
nil,
nil,
true, // storedValue is standalone
)

inter.WriteStored(
Expand Down
18 changes: 13 additions & 5 deletions migrations/statictypes/account_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ func TestAccountTypeInNestedTypeValueMigration(t *testing.T) {
false,
nil,
nil,
true, // storedValue is standalone

)

inter.WriteStored(
Expand Down Expand Up @@ -833,6 +835,7 @@ func TestMigratingValuesWithAccountStaticType(t *testing.T) {
false,
nil,
nil,
true, // storedValue is standalone
)

inter.WriteStored(
Expand Down Expand Up @@ -976,6 +979,7 @@ func TestAccountTypeRehash(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down Expand Up @@ -1035,11 +1039,15 @@ func TestAccountTypeRehash(t *testing.T) {
dictValue := storedValue.(*interpreter.DictionaryValue)

var existingKeys []interpreter.Value
dictValue.Iterate(inter, func(key, value interpreter.Value) (resume bool) {
existingKeys = append(existingKeys, key)
// continue iteration
return true
})
dictValue.Iterate(
inter,
interpreter.EmptyLocationRange,
func(key, value interpreter.Value) (resume bool) {
existingKeys = append(existingKeys, key)
// continue iteration
return true
},
)

for _, key := range existingKeys {
actual := dictValue.Remove(
Expand Down
3 changes: 3 additions & 0 deletions migrations/statictypes/intersection_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ func TestIntersectionTypeRehash(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down Expand Up @@ -710,6 +711,7 @@ func TestRehashNestedIntersectionType(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down Expand Up @@ -849,6 +851,7 @@ func TestRehashNestedIntersectionType(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down
4 changes: 4 additions & 0 deletions migrations/string_normalization/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestStringNormalizingMigration(t *testing.T) {
false,
nil,
nil,
true, // storedValue is standalone
)

inter.WriteStored(
Expand Down Expand Up @@ -382,6 +383,8 @@ func TestStringValueRehash(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone

),
)

Expand Down Expand Up @@ -521,6 +524,7 @@ func TestCharacterValueRehash(t *testing.T) {
false,
nil,
nil,
true, // dictValue is standalone
),
)

Expand Down
6 changes: 5 additions & 1 deletion runtime/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2277,9 +2277,13 @@ func TestRuntimePublicKeyPublicKeyField(t *testing.T) {
false,
nil,
nil,
true, // publicKey is standalone
).(*interpreter.CompositeValue)

publicKey.DeepRemove(inter)
publicKey.DeepRemove(
inter,
true, // publicKey is standalone
)

publicKeyArray2 := publicKey2.GetMember(
inter,
Expand Down
Loading

0 comments on commit b591a0d

Please sign in to comment.