Skip to content

Commit

Permalink
Merge pull request #3320 from onflow/bastian/sync-atree-register-inli…
Browse files Browse the repository at this point in the history
…ning-v1.0
  • Loading branch information
turbolent authored May 7, 2024
2 parents 4ef6541 + b7bef97 commit fac39f8
Show file tree
Hide file tree
Showing 10 changed files with 954 additions and 168 deletions.
15 changes: 12 additions & 3 deletions migrations/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ import (
"github.com/onflow/cadence/runtime/interpreter"
)

type StaticTypeCache struct {
type StaticTypeCache interface {
Get(typeID interpreter.TypeID) (interpreter.StaticType, bool)
Set(typeID interpreter.TypeID, ty interpreter.StaticType)
}

type DefaultStaticTypeCache struct {
entries sync.Map
}

func (c *StaticTypeCache) Get(typeID interpreter.TypeID) (interpreter.StaticType, bool) {
func NewDefaultStaticTypeCache() *DefaultStaticTypeCache {
return &DefaultStaticTypeCache{}
}

func (c *DefaultStaticTypeCache) Get(typeID interpreter.TypeID) (interpreter.StaticType, bool) {
v, ok := c.entries.Load(typeID)
if !ok {
return nil, false
}
return v.(interpreter.StaticType), true
}

func (c *StaticTypeCache) Set(typeID interpreter.TypeID, ty interpreter.StaticType) {
func (c *DefaultStaticTypeCache) Set(typeID interpreter.TypeID, ty interpreter.StaticType) {
c.entries.Store(typeID, ty)
}
7 changes: 4 additions & 3 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ import (

type EntitlementsMigration struct {
Interpreter *interpreter.Interpreter
migratedTypeCache *migrations.StaticTypeCache
migratedTypeCache migrations.StaticTypeCache
}

var _ migrations.ValueMigration = EntitlementsMigration{}

func NewEntitlementsMigration(inter *interpreter.Interpreter) EntitlementsMigration {
return NewEntitlementsMigrationWithCache(inter, &migrations.StaticTypeCache{})
staticTypeCache := migrations.NewDefaultStaticTypeCache()
return NewEntitlementsMigrationWithCache(inter, staticTypeCache)
}

func NewEntitlementsMigrationWithCache(
inter *interpreter.Interpreter,
migratedTypeCache *migrations.StaticTypeCache,
migratedTypeCache migrations.StaticTypeCache,
) EntitlementsMigration {
return EntitlementsMigration{
Interpreter: inter,
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 @@ -730,6 +730,7 @@ func convertEntireTestValue(
testEntitlementsMigration{inter: inter},
},
reporter,
true,
)

err = migration.Commit()
Expand Down
Loading

0 comments on commit fac39f8

Please sign in to comment.