diff --git a/migrations/cache.go b/migrations/cache.go deleted file mode 100644 index c960d17f57..0000000000 --- a/migrations/cache.go +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Cadence - The resource-oriented smart contract programming language - * - * Copyright Dapper Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package migrations - -import ( - "sync" - - "github.com/onflow/cadence/runtime/interpreter" -) - -type CachedStaticType struct { - StaticType interpreter.StaticType - Error error -} - -type StaticTypeCache interface { - Get(typeID interpreter.TypeID) (CachedStaticType, bool) - Set( - typeID interpreter.TypeID, - staticType interpreter.StaticType, - err error, - ) -} - -type DefaultStaticTypeCache struct { - entries sync.Map -} - -func NewDefaultStaticTypeCache() *DefaultStaticTypeCache { - return &DefaultStaticTypeCache{} -} - -func (c *DefaultStaticTypeCache) Get(typeID interpreter.TypeID) (CachedStaticType, bool) { - v, ok := c.entries.Load(typeID) - if !ok { - return CachedStaticType{}, false - } - return v.(CachedStaticType), true -} - -func (c *DefaultStaticTypeCache) Set( - typeID interpreter.TypeID, - staticType interpreter.StaticType, - err error, -) { - c.entries.Store(typeID, CachedStaticType{ - StaticType: staticType, - Error: err, - }) -} diff --git a/migrations/entitlements/migration.go b/migrations/entitlements/migration.go index 6991141eb1..c6639da7e4 100644 --- a/migrations/entitlements/migration.go +++ b/migrations/entitlements/migration.go @@ -28,24 +28,14 @@ import ( ) type EntitlementsMigration struct { - Interpreter *interpreter.Interpreter - migratedTypeCache migrations.StaticTypeCache + Interpreter *interpreter.Interpreter } var _ migrations.ValueMigration = EntitlementsMigration{} func NewEntitlementsMigration(inter *interpreter.Interpreter) EntitlementsMigration { - staticTypeCache := migrations.NewDefaultStaticTypeCache() - return NewEntitlementsMigrationWithCache(inter, staticTypeCache) -} - -func NewEntitlementsMigrationWithCache( - inter *interpreter.Interpreter, - migratedTypeCache migrations.StaticTypeCache, -) EntitlementsMigration { return EntitlementsMigration{ - Interpreter: inter, - migratedTypeCache: migratedTypeCache, + Interpreter: inter, } } @@ -84,17 +74,6 @@ func (m EntitlementsMigration) ConvertToEntitledType( } inter := m.Interpreter - migratedTypeCache := m.migratedTypeCache - - staticTypeID := staticType.ID() - - if migratedType, exists := migratedTypeCache.Get(staticTypeID); exists { - return migratedType.StaticType, migratedType.Error - } - - defer func() { - migratedTypeCache.Set(staticTypeID, resultType, err) - }() switch t := staticType.(type) { case *interpreter.ReferenceStaticType: diff --git a/migrations/statictypes/statictype_migration.go b/migrations/statictypes/statictype_migration.go index ade3762329..84de646a58 100644 --- a/migrations/statictypes/statictype_migration.go +++ b/migrations/statictypes/statictype_migration.go @@ -31,7 +31,6 @@ import ( type StaticTypeMigration struct { compositeTypeConverter CompositeTypeConverterFunc interfaceTypeConverter InterfaceTypeConverterFunc - migratedTypeCache migrations.StaticTypeCache } type CompositeTypeConverterFunc func(*interpreter.CompositeStaticType) interpreter.StaticType @@ -40,14 +39,7 @@ type InterfaceTypeConverterFunc func(*interpreter.InterfaceStaticType) interpret var _ migrations.ValueMigration = &StaticTypeMigration{} func NewStaticTypeMigration() *StaticTypeMigration { - staticTypeCache := migrations.NewDefaultStaticTypeCache() - return NewStaticTypeMigrationWithCache(staticTypeCache) -} - -func NewStaticTypeMigrationWithCache(migratedTypeCache migrations.StaticTypeCache) *StaticTypeMigration { - return &StaticTypeMigration{ - migratedTypeCache: migratedTypeCache, - } + return &StaticTypeMigration{} } func (m *StaticTypeMigration) WithCompositeTypeConverter(converterFunc CompositeTypeConverterFunc) *StaticTypeMigration { @@ -171,25 +163,6 @@ func (m *StaticTypeMigration) maybeConvertStaticType( ) ( resultType interpreter.StaticType, ) { - // Consult the cache and cache the result at the root of the migration, - // i.e. when the parent type is nil. - // - // Parse of the migration, e.g. the intersection type migration depends on the parent type. - // For example, `{Ts}` in `&{Ts}` is migrated differently from `{Ts}`. - - if parentType == nil { - migratedTypeCache := m.migratedTypeCache - staticTypeID := staticType.ID() - - if cachedType, exists := migratedTypeCache.Get(staticTypeID); exists { - return cachedType.StaticType - } - - defer func() { - migratedTypeCache.Set(staticTypeID, resultType, nil) - }() - } - switch staticType := staticType.(type) { case *interpreter.ConstantSizedStaticType: convertedType := m.maybeConvertStaticType(staticType.Type, staticType)