Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect caching from migrations #3375

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions migrations/cache.go

This file was deleted.

25 changes: 2 additions & 23 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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:
Expand Down
29 changes: 1 addition & 28 deletions migrations/statictypes/statictype_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
type StaticTypeMigration struct {
compositeTypeConverter CompositeTypeConverterFunc
interfaceTypeConverter InterfaceTypeConverterFunc
migratedTypeCache migrations.StaticTypeCache
}

type CompositeTypeConverterFunc func(*interpreter.CompositeStaticType) interpreter.StaticType
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading