From 5be8fd135104eb252e6c5163cfd6502ddadaa3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 26 Nov 2024 14:03:00 -0800 Subject: [PATCH] decouple Value.StaticType from interpreter --- interpreter/interface.go | 55 +++++++++++++++++++ interpreter/simplecompositevalue.go | 2 +- interpreter/value.go | 2 +- .../value_accountcapabilitycontroller.go | 2 +- interpreter/value_address.go | 4 +- interpreter/value_array.go | 6 +- interpreter/value_bool.go | 4 +- interpreter/value_capability.go | 4 +- interpreter/value_character.go | 4 +- interpreter/value_composite.go | 4 +- interpreter/value_dictionary.go | 2 +- interpreter/value_ephemeral_reference.go | 6 +- interpreter/value_fix64.go | 4 +- interpreter/value_function.go | 12 ++-- interpreter/value_int.go | 4 +- interpreter/value_int128.go | 4 +- interpreter/value_int16.go | 4 +- interpreter/value_int256.go | 4 +- interpreter/value_int32.go | 4 +- interpreter/value_int64.go | 4 +- interpreter/value_int8.go | 4 +- interpreter/value_link.go | 10 ++-- interpreter/value_nil.go | 6 +- interpreter/value_path.go | 8 +-- interpreter/value_pathcapability.go | 4 +- interpreter/value_placeholder.go | 2 +- interpreter/value_published.go | 4 +- interpreter/value_some.go | 6 +- interpreter/value_storage_reference.go | 18 +++--- .../value_storagecapabilitycontroller.go | 2 +- interpreter/value_string.go | 4 +- interpreter/value_type.go | 4 +- interpreter/value_ufix64.go | 4 +- interpreter/value_uint.go | 4 +- interpreter/value_uint128.go | 4 +- interpreter/value_uint16.go | 4 +- interpreter/value_uint256.go | 4 +- interpreter/value_uint32.go | 4 +- interpreter/value_uint64.go | 4 +- interpreter/value_uint8.go | 4 +- interpreter/value_void.go | 4 +- interpreter/value_word128.go | 4 +- interpreter/value_word16.go | 4 +- interpreter/value_word256.go | 4 +- interpreter/value_word32.go | 4 +- interpreter/value_word64.go | 4 +- interpreter/value_word8.go | 4 +- 47 files changed, 161 insertions(+), 106 deletions(-) create mode 100644 interpreter/interface.go diff --git a/interpreter/interface.go b/interpreter/interface.go new file mode 100644 index 0000000000..f9fa690572 --- /dev/null +++ b/interpreter/interface.go @@ -0,0 +1,55 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * 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 interpreter + +import ( + "github.com/onflow/cadence/common" + "github.com/onflow/cadence/sema" +) + +type TypeConverter interface { + MustConvertStaticToSemaType(staticType StaticType) sema.Type +} + +var _ TypeConverter = &Interpreter{} + +type SubTypeChecker interface { + IsSubTypeOfSemaType(staticSubType StaticType, superType sema.Type) bool +} + +var _ SubTypeChecker = &Interpreter{} + +type StorageReader interface { + ReadStored( + storageAddress common.Address, + domain common.StorageDomain, + identifier StorageMapKey, + ) Value +} + +var _ StorageReader = &Interpreter{} + +type StaticTypeGetter interface { + common.MemoryGauge + StorageReader + TypeConverter + SubTypeChecker +} + +var _ StaticTypeGetter = &Interpreter{} diff --git a/interpreter/simplecompositevalue.go b/interpreter/simplecompositevalue.go index 01620523e7..1a624889e2 100644 --- a/interpreter/simplecompositevalue.go +++ b/interpreter/simplecompositevalue.go @@ -103,7 +103,7 @@ func (v *SimpleCompositeValue) Walk(_ *Interpreter, walkChild func(Value), _ Loc }) } -func (v *SimpleCompositeValue) StaticType(_ *Interpreter) StaticType { +func (v *SimpleCompositeValue) StaticType(_ StaticTypeGetter) StaticType { return v.staticType } diff --git a/interpreter/value.go b/interpreter/value.go index bf698515c5..ff1bf9fc78 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -94,7 +94,7 @@ type Value interface { isValue() Accept(interpreter *Interpreter, visitor Visitor, locationRange LocationRange) Walk(interpreter *Interpreter, walkChild func(Value), locationRange LocationRange) - StaticType(interpreter *Interpreter) StaticType + StaticType(staticTypeGetter StaticTypeGetter) StaticType // ConformsToStaticType returns true if the value (i.e. its dynamic type) // conforms to its own static type. // Non-container values trivially always conform to their own static type. diff --git a/interpreter/value_accountcapabilitycontroller.go b/interpreter/value_accountcapabilitycontroller.go index c2036e271a..541ad1e82f 100644 --- a/interpreter/value_accountcapabilitycontroller.go +++ b/interpreter/value_accountcapabilitycontroller.go @@ -96,7 +96,7 @@ func (v *AccountCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *AccountCapabilityControllerValue) StaticType(_ *Interpreter) StaticType { +func (v *AccountCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeAccountCapabilityController } diff --git a/interpreter/value_address.go b/interpreter/value_address.go index 56ec54163c..05ab268f03 100644 --- a/interpreter/value_address.go +++ b/interpreter/value_address.go @@ -101,8 +101,8 @@ func (AddressValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (AddressValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeAddress) +func (AddressValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeAddress) } func (AddressValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_array.go b/interpreter/value_array.go index b032b9625c..73a01cdb83 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -324,7 +324,7 @@ func (v *ArrayValue) Walk( ) } -func (v *ArrayValue) StaticType(_ *Interpreter) StaticType { +func (v *ArrayValue) StaticType(_ StaticTypeGetter) StaticType { // TODO meter return v.Type } @@ -1538,10 +1538,10 @@ func (v *ArrayValue) GetOwner() common.Address { return common.Address(v.StorageAddress()) } -func (v *ArrayValue) SemaType(interpreter *Interpreter) sema.ArrayType { +func (v *ArrayValue) SemaType(typeConverter TypeConverter) sema.ArrayType { if v.semaType == nil { // this function will panic already if this conversion fails - v.semaType, _ = interpreter.MustConvertStaticToSemaType(v.Type).(sema.ArrayType) + v.semaType, _ = typeConverter.MustConvertStaticToSemaType(v.Type).(sema.ArrayType) } return v.semaType } diff --git a/interpreter/value_bool.go b/interpreter/value_bool.go index 31222efcc9..61cc63ea52 100644 --- a/interpreter/value_bool.go +++ b/interpreter/value_bool.go @@ -56,8 +56,8 @@ func (BoolValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (BoolValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeBool) +func (BoolValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeBool) } func (BoolValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_capability.go b/interpreter/value_capability.go index 8d766c6c48..9dd83df4f2 100644 --- a/interpreter/value_capability.go +++ b/interpreter/value_capability.go @@ -108,9 +108,9 @@ func (v *IDCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Locati walkChild(v.address) } -func (v *IDCapabilityValue) StaticType(inter *Interpreter) StaticType { +func (v *IDCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewCapabilityStaticType( - inter, + staticTypeGetter, v.BorrowType, ) } diff --git a/interpreter/value_character.go b/interpreter/value_character.go index 66e57da154..f6c6c435cf 100644 --- a/interpreter/value_character.go +++ b/interpreter/value_character.go @@ -86,8 +86,8 @@ func (CharacterValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (CharacterValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeCharacter) +func (CharacterValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeCharacter) } func (CharacterValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_composite.go b/interpreter/value_composite.go index cf460d466d..58e5f87200 100644 --- a/interpreter/value_composite.go +++ b/interpreter/value_composite.go @@ -264,12 +264,12 @@ func (v *CompositeValue) Walk(interpreter *Interpreter, walkChild func(Value), l }, locationRange) } -func (v *CompositeValue) StaticType(interpreter *Interpreter) StaticType { +func (v *CompositeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { if v.staticType == nil { // NOTE: Instead of using NewCompositeStaticType, which always generates the type ID, // use the TypeID accessor, which may return an already computed type ID v.staticType = NewCompositeStaticType( - interpreter, + staticTypeGetter, v.Location, v.QualifiedIdentifier, v.TypeID(), diff --git a/interpreter/value_dictionary.go b/interpreter/value_dictionary.go index b7b804c465..d7c78aa759 100644 --- a/interpreter/value_dictionary.go +++ b/interpreter/value_dictionary.go @@ -441,7 +441,7 @@ func (v *DictionaryValue) Walk(interpreter *Interpreter, walkChild func(Value), ) } -func (v *DictionaryValue) StaticType(_ *Interpreter) StaticType { +func (v *DictionaryValue) StaticType(_ StaticTypeGetter) StaticType { // TODO meter return v.Type } diff --git a/interpreter/value_ephemeral_reference.go b/interpreter/value_ephemeral_reference.go index 94e505cc1b..13a99fc5ab 100644 --- a/interpreter/value_ephemeral_reference.go +++ b/interpreter/value_ephemeral_reference.go @@ -111,11 +111,11 @@ func (v *EphemeralReferenceValue) MeteredString(interpreter *Interpreter, seenRe return v.Value.MeteredString(interpreter, seenReferences, locationRange) } -func (v *EphemeralReferenceValue) StaticType(inter *Interpreter) StaticType { +func (v *EphemeralReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewReferenceStaticType( - inter, + staticTypeGetter, v.Authorization, - v.Value.StaticType(inter), + v.Value.StaticType(staticTypeGetter), ) } diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index 8d975bb11c..9f4798915f 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -93,8 +93,8 @@ func (Fix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Fix64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeFix64) +func (Fix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeFix64) } func (Fix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_function.go b/interpreter/value_function.go index f5d8b99f45..9240699bee 100644 --- a/interpreter/value_function.go +++ b/interpreter/value_function.go @@ -103,8 +103,8 @@ func (f *InterpretedFunctionValue) Walk(_ *Interpreter, _ func(Value), _ Locatio // NO-OP } -func (f *InterpretedFunctionValue) StaticType(interpreter *Interpreter) StaticType { - return ConvertSemaToStaticType(interpreter, f.Type) +func (f *InterpretedFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return ConvertSemaToStaticType(staticTypeGetter, f.Type) } func (*InterpretedFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -237,8 +237,8 @@ func (f *HostFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f *HostFunctionValue) StaticType(interpreter *Interpreter) StaticType { - return ConvertSemaToStaticType(interpreter, f.Type) +func (f *HostFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return ConvertSemaToStaticType(staticTypeGetter, f.Type) } func (*HostFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -413,8 +413,8 @@ func (f BoundFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f BoundFunctionValue) StaticType(inter *Interpreter) StaticType { - return f.Function.StaticType(inter) +func (f BoundFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return f.Function.StaticType(staticTypeGetter) } func (BoundFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int.go b/interpreter/value_int.go index a9e6ef2c51..323dd2b6b7 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -109,8 +109,8 @@ func (IntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (IntValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt) +func (IntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt) } func (IntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index b95c3b70f9..b9bfd07a85 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -82,8 +82,8 @@ func (Int128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt128) +func (Int128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt128) } func (Int128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index 393093b153..647703b9a0 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -69,8 +69,8 @@ func (Int16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt16) +func (Int16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt16) } func (Int16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index c766978af7..29d68aa4e6 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -82,8 +82,8 @@ func (Int256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt256) +func (Int256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt256) } func (Int256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index e5847fc477..ecf3d4f44d 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -69,8 +69,8 @@ func (Int32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt32) +func (Int32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt32) } func (Int32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index 5f331e95aa..26a29e9f3e 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -66,8 +66,8 @@ func (Int64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt64) +func (Int64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt64) } func (Int64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index 12cc547687..e628ff8b96 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -67,8 +67,8 @@ func (Int8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt8) +func (Int8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt8) } func (Int8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_link.go b/interpreter/value_link.go index 0d7cd306e6..3b0e90da8a 100644 --- a/interpreter/value_link.go +++ b/interpreter/value_link.go @@ -59,7 +59,7 @@ func (v PathLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v PathLinkValue) StaticType(interpreter *Interpreter) StaticType { +func (v PathLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // When iterating over public/private paths, // the values at these paths are PathLinkValues, // placed there by the `link` function. @@ -67,7 +67,7 @@ func (v PathLinkValue) StaticType(interpreter *Interpreter) StaticType { // These are loaded as links, however, // for the purposes of checking their type, // we treat them as capabilities - return NewCapabilityStaticType(interpreter, v.Type) + return NewCapabilityStaticType(staticTypeGetter, v.Type) } func (PathLinkValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -184,7 +184,7 @@ func (AccountLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v AccountLinkValue) StaticType(interpreter *Interpreter) StaticType { +func (v AccountLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // When iterating over public/private paths, // the values at these paths are AccountLinkValues, // placed there by the `linkAccount` function. @@ -193,9 +193,9 @@ func (v AccountLinkValue) StaticType(interpreter *Interpreter) StaticType { // for the purposes of checking their type, // we treat them as capabilities return NewCapabilityStaticType( - interpreter, + staticTypeGetter, NewReferenceStaticType( - interpreter, + staticTypeGetter, FullyEntitledAccountAccess, PrimitiveStaticTypeAccount, ), diff --git a/interpreter/value_nil.go b/interpreter/value_nil.go index 8bd6459658..9bf4e94cc4 100644 --- a/interpreter/value_nil.go +++ b/interpreter/value_nil.go @@ -51,10 +51,10 @@ func (NilValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (NilValue) StaticType(interpreter *Interpreter) StaticType { +func (NilValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewOptionalStaticType( - interpreter, - NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeNever), + staticTypeGetter, + NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeNever), ) } diff --git a/interpreter/value_path.go b/interpreter/value_path.go index 54c6503c8a..f3a67d44ae 100644 --- a/interpreter/value_path.go +++ b/interpreter/value_path.go @@ -65,14 +65,14 @@ func (PathValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (v PathValue) StaticType(interpreter *Interpreter) StaticType { +func (v PathValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { switch v.Domain { case common.PathDomainStorage: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeStoragePath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeStoragePath) case common.PathDomainPublic: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypePublicPath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePublicPath) case common.PathDomainPrivate: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypePrivatePath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePrivatePath) default: panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_pathcapability.go b/interpreter/value_pathcapability.go index d12e460f8c..b95aa3ecd7 100644 --- a/interpreter/value_pathcapability.go +++ b/interpreter/value_pathcapability.go @@ -69,9 +69,9 @@ func (v *PathCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Loca walkChild(v.Path) } -func (v *PathCapabilityValue) StaticType(inter *Interpreter) StaticType { +func (v *PathCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewCapabilityStaticType( - inter, + staticTypeGetter, v.BorrowType, ) } diff --git a/interpreter/value_placeholder.go b/interpreter/value_placeholder.go index 1396f38458..30a2d8c5f9 100644 --- a/interpreter/value_placeholder.go +++ b/interpreter/value_placeholder.go @@ -51,7 +51,7 @@ func (f placeholderValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (f placeholderValue) StaticType(_ *Interpreter) StaticType { +func (f placeholderValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeNever } diff --git a/interpreter/value_published.go b/interpreter/value_published.go index 39821a32c4..c76b62283a 100644 --- a/interpreter/value_published.go +++ b/interpreter/value_published.go @@ -53,10 +53,10 @@ func (v *PublishedValue) Accept(interpreter *Interpreter, visitor Visitor, _ Loc visitor.VisitPublishedValue(interpreter, v) } -func (v *PublishedValue) StaticType(interpreter *Interpreter) StaticType { +func (v *PublishedValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // checking the static type of a published value should show us the // static type of the underlying value - return v.Value.StaticType(interpreter) + return v.Value.StaticType(staticTypeGetter) } func (*PublishedValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_some.go b/interpreter/value_some.go index f33f524b81..bac5afbc54 100644 --- a/interpreter/value_some.go +++ b/interpreter/value_some.go @@ -66,17 +66,17 @@ func (v *SomeValue) Walk(_ *Interpreter, walkChild func(Value), _ LocationRange) walkChild(v.value) } -func (v *SomeValue) StaticType(inter *Interpreter) StaticType { +func (v *SomeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { if v.isDestroyed { return nil } - innerType := v.value.StaticType(inter) + innerType := v.value.StaticType(staticTypeGetter) if innerType == nil { return nil } return NewOptionalStaticType( - inter, + staticTypeGetter, innerType, ) } diff --git a/interpreter/value_storage_reference.go b/interpreter/value_storage_reference.go index 906edc5819..19ceb465a0 100644 --- a/interpreter/value_storage_reference.go +++ b/interpreter/value_storage_reference.go @@ -98,8 +98,8 @@ func (v *StorageReferenceValue) MeteredString(interpreter *Interpreter, _ SeenRe return v.String() } -func (v *StorageReferenceValue) StaticType(inter *Interpreter) StaticType { - referencedValue, err := v.dereference(inter, EmptyLocationRange) +func (v *StorageReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + referencedValue, err := v.dereference(staticTypeGetter, EmptyLocationRange) if err != nil { panic(err) } @@ -107,9 +107,9 @@ func (v *StorageReferenceValue) StaticType(inter *Interpreter) StaticType { self := *referencedValue return NewReferenceStaticType( - inter, + staticTypeGetter, v.Authorization, - self.StaticType(inter), + self.StaticType(staticTypeGetter), ) } @@ -121,14 +121,14 @@ func (*StorageReferenceValue) IsImportable(_ *Interpreter, _ LocationRange) bool return false } -func (v *StorageReferenceValue) dereference(interpreter *Interpreter, locationRange LocationRange) (*Value, error) { +func (v *StorageReferenceValue) dereference(staticTypeGetter StaticTypeGetter, locationRange LocationRange) (*Value, error) { address := v.TargetStorageAddress domain := v.TargetPath.Domain.StorageDomain() identifier := v.TargetPath.Identifier storageMapKey := StringStorageMapKey(identifier) - referenced := interpreter.ReadStored(address, domain, storageMapKey) + referenced := staticTypeGetter.ReadStored(address, domain, storageMapKey) if referenced == nil { return nil, nil } @@ -141,10 +141,10 @@ func (v *StorageReferenceValue) dereference(interpreter *Interpreter, locationRa } if v.BorrowedType != nil { - staticType := referenced.StaticType(interpreter) + staticType := referenced.StaticType(staticTypeGetter) - if !interpreter.IsSubTypeOfSemaType(staticType, v.BorrowedType) { - semaType := interpreter.MustConvertStaticToSemaType(staticType) + if !staticTypeGetter.IsSubTypeOfSemaType(staticType, v.BorrowedType) { + semaType := staticTypeGetter.MustConvertStaticToSemaType(staticType) return nil, ForceCastTypeMismatchError{ ExpectedType: v.BorrowedType, diff --git a/interpreter/value_storagecapabilitycontroller.go b/interpreter/value_storagecapabilitycontroller.go index 55ef98359c..00f13e49e5 100644 --- a/interpreter/value_storagecapabilitycontroller.go +++ b/interpreter/value_storagecapabilitycontroller.go @@ -118,7 +118,7 @@ func (v *StorageCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *StorageCapabilityControllerValue) StaticType(_ *Interpreter) StaticType { +func (v *StorageCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeStorageCapabilityController } diff --git a/interpreter/value_string.go b/interpreter/value_string.go index df4e4cc3b6..989e74d82c 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -121,8 +121,8 @@ func (*StringValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (*StringValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeString) +func (*StringValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeString) } func (*StringValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_type.go b/interpreter/value_type.go index ed41180734..513f5644cb 100644 --- a/interpreter/value_type.go +++ b/interpreter/value_type.go @@ -65,8 +65,8 @@ func (TypeValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (TypeValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeMetaType) +func (TypeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeMetaType) } func (TypeValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index 53dd967167..ca7d9fd642 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -86,8 +86,8 @@ func (UFix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UFix64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUFix64) +func (UFix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUFix64) } func (UFix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index aec0c661e3..038fe7e172 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -124,8 +124,8 @@ func (UIntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UIntValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt) +func (UIntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt) } func (v UIntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index e0d7cb0e92..8f43fb31d0 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -82,8 +82,8 @@ func (UInt128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt128) +func (UInt128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt128) } func (UInt128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index c12bd1d2a9..39e7281287 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -67,8 +67,8 @@ func (UInt16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt16) +func (UInt16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt16) } func (UInt16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index 975454387a..e660f8aaf0 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -82,8 +82,8 @@ func (UInt256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt256) +func (UInt256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt256) } func (UInt256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index 83c7efb59f..cd486c6573 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -67,8 +67,8 @@ func (UInt32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt32) +func (UInt32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt32) } func (UInt32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index f8b3cdb2ce..dc62a35143 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -74,8 +74,8 @@ func (UInt64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt64) +func (UInt64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt64) } func (UInt64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index d2289f2ef1..8dc8670de4 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -67,8 +67,8 @@ func (UInt8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt8) +func (UInt8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt8) } func (UInt8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_void.go b/interpreter/value_void.go index 9ad8e54222..fc452d5adc 100644 --- a/interpreter/value_void.go +++ b/interpreter/value_void.go @@ -47,8 +47,8 @@ func (VoidValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (VoidValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeVoid) +func (VoidValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeVoid) } func (VoidValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index d845055941..f85eab3e0b 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -82,8 +82,8 @@ func (Word128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord128) +func (Word128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord128) } func (Word128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index 98d50f5264..fa8050ad0b 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -68,8 +68,8 @@ func (Word16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord16) +func (Word16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord16) } func (Word16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index 49924b6240..a36cbb59d6 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -82,8 +82,8 @@ func (Word256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord256) +func (Word256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord256) } func (Word256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index 13d92e5add..425b52adb4 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -68,8 +68,8 @@ func (Word32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord32) +func (Word32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord32) } func (Word32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index b79cec602b..c958e8303f 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -76,8 +76,8 @@ func (Word64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord64) +func (Word64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord64) } func (Word64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 8fffdf9c7d..932ff26ca6 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -67,8 +67,8 @@ func (Word8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord8) +func (Word8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord8) } func (Word8Value) IsImportable(_ *Interpreter, _ LocationRange) bool {