diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 46edcb3d48..453861fc31 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -3997,39 +3997,31 @@ func (interpreter *Interpreter) IsSubType(subType StaticType, superType StaticTy return interpreter.IsSubTypeOfSemaType(subType, semaType) } -func (interpreter *Interpreter) IsSubTypeOfSemaType(subType StaticType, superType sema.Type) bool { +func (interpreter *Interpreter) IsSubTypeOfSemaType(staticSubType StaticType, superType sema.Type) bool { if superType == sema.AnyType { return true } - switch subType := subType.(type) { + // Optimization: Implement subtyping for common cases directly, + // without converting the subtype to a sema type. + + switch staticSubType := staticSubType.(type) { case *OptionalStaticType: if superType, ok := superType.(*sema.OptionalType); ok { - return interpreter.IsSubTypeOfSemaType(subType.Type, superType.Type) + return interpreter.IsSubTypeOfSemaType(staticSubType.Type, superType.Type) } switch superType { case sema.AnyStructType, sema.AnyResourceType: - return interpreter.IsSubTypeOfSemaType(subType.Type, superType) - } - - case *ReferenceStaticType: - if superType, ok := superType.(*sema.ReferenceType); ok { - - // First, check that the static type of the referenced value - // is a subtype of the super type - - return subType.ReferencedType != nil && - interpreter.IsSubTypeOfSemaType(subType.ReferencedType, superType.Type) && - superType.Authorization.PermitsAccess(interpreter.MustConvertStaticAuthorizationToSemaAccess(subType.Authorization)) + return interpreter.IsSubTypeOfSemaType(staticSubType.Type, superType) } return superType == sema.AnyStructType } - semaType := interpreter.MustConvertStaticToSemaType(subType) + semaSubType := interpreter.MustConvertStaticToSemaType(staticSubType) - return sema.IsSubType(semaType, superType) + return sema.IsSubType(semaSubType, superType) } func (interpreter *Interpreter) domainPaths(address common.Address, domain common.PathDomain) []Value {