From 889709d8e506e6b707c6eaec5c310edda9c2be65 Mon Sep 17 00:00:00 2001 From: Rustam Date: Wed, 12 Oct 2022 16:43:47 +0300 Subject: [PATCH] Change ty1.Equals(ty2) to call static op_Equality (#13028) Co-authored-by: Vlad Zarytovskii Co-authored-by: Don Syme --- src/Compiler/AbstractIL/ilreflect.fs | 5 +- src/Compiler/TypedTree/TypeProviders.fs | 2 +- src/Compiler/Utilities/sformat.fs | 4 +- src/Compiler/Utilities/sr.fs | 2 +- src/FSharp.Build/FSharpEmbedResourceText.fs | 2 +- src/FSharp.Core/Linq.fs | 11 +- src/FSharp.Core/Query.fs | 44 +-- src/FSharp.Core/prim-types.fs | 319 +++++++++--------- src/FSharp.Core/quotations.fs | 2 +- src/FSharp.Core/reflect.fs | 4 +- .../FSharp.DependencyManager.fs | 2 +- tests/service/data/TestTP/ProvidedTypes.fs | 2 +- 12 files changed, 202 insertions(+), 197 deletions(-) diff --git a/src/Compiler/AbstractIL/ilreflect.fs b/src/Compiler/AbstractIL/ilreflect.fs index 0fc3e73e247..5cf3ec58222 100644 --- a/src/Compiler/AbstractIL/ilreflect.fs +++ b/src/Compiler/AbstractIL/ilreflect.fs @@ -412,7 +412,7 @@ module Zmap = | Some y -> y | None -> failwithf "Zmap.force: %s: x = %+A" str x -let equalTypes (s: Type) (t: Type) = s.Equals t +let equalTypes (s: Type) (t: Type) = Type.op_Equality (s, t) let equalTypeLists (tys1: Type list) (tys2: Type list) = List.lengthsEqAndForall2 equalTypes tys1 tys2 @@ -820,7 +820,8 @@ let TypeBuilderInstantiationT = ty let typeIsNotQueryable (ty: Type) = - (ty :? TypeBuilder) || ((ty.GetType()).Equals(TypeBuilderInstantiationT)) + (ty :? TypeBuilder) + || Type.op_Equality (ty.GetType(), TypeBuilderInstantiationT) let queryableTypeGetField _emEnv (parentT: Type) (fref: ILFieldRef) = let res = diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 662081a1f45..02f6fafd05d 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -415,7 +415,7 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = member _.ApplyStaticArguments(provider: ITypeProvider, fullTypePathAfterArguments, staticArgs: obj[]) = provider.ApplyStaticArguments(x, fullTypePathAfterArguments, staticArgs) |> ProvidedType.Create ctxt - member _.IsVoid = (typeof.Equals x || (x.Namespace = "System" && x.Name = "Void")) + member _.IsVoid = (Type.op_Equality(x, typeof) || (x.Namespace = "System" && x.Name = "Void")) member _.IsGenericParameter = x.IsGenericParameter diff --git a/src/Compiler/Utilities/sformat.fs b/src/Compiler/Utilities/sformat.fs index 42b13e28ff9..303e2f968b5 100644 --- a/src/Compiler/Utilities/sformat.fs +++ b/src/Compiler/Utilities/sformat.fs @@ -455,9 +455,9 @@ module ReflectUtils = isNamedType (ty1) && if ty1.IsGenericType then ty2.IsGenericType - && (ty1.GetGenericTypeDefinition()).Equals(ty2.GetGenericTypeDefinition()) + && Type.op_Equality (ty1.GetGenericTypeDefinition(), ty2.GetGenericTypeDefinition()) else - ty1.Equals(ty2) + Type.op_Equality (ty1, ty2) let option = typedefof diff --git a/src/Compiler/Utilities/sr.fs b/src/Compiler/Utilities/sr.fs index 245ed9841c2..77552a03b90 100644 --- a/src/Compiler/Utilities/sr.fs +++ b/src/Compiler/Utilities/sr.fs @@ -37,7 +37,7 @@ module internal DiagnosticMessage = let isFunctionType (ty1: System.Type) = isNamedType (ty1) && ty1.IsGenericType - && (ty1.GetGenericTypeDefinition()).Equals(funTyC) + && System.Type.op_Equality (ty1.GetGenericTypeDefinition(), funTyC) let rec destFunTy (ty: System.Type) = if isFunctionType ty then diff --git a/src/FSharp.Build/FSharpEmbedResourceText.fs b/src/FSharp.Build/FSharpEmbedResourceText.fs index 77002aa4f54..d8a3848ba27 100644 --- a/src/FSharp.Build/FSharpEmbedResourceText.fs +++ b/src/FSharp.Build/FSharpEmbedResourceText.fs @@ -289,7 +289,7 @@ open Printf static let isNamedType(ty:System.Type) = not (ty.IsArray || ty.IsByRef || ty.IsPointer) static let isFunctionType (ty1:System.Type) = - isNamedType(ty1) && getTypeInfo(ty1).IsGenericType && (ty1.GetGenericTypeDefinition()).Equals(funTyC) + isNamedType(ty1) && getTypeInfo(ty1).IsGenericType && System.Type.op_Equality(ty1.GetGenericTypeDefinition(), funTyC) static let rec destFunTy (ty:System.Type) = if isFunctionType ty then diff --git a/src/FSharp.Core/Linq.fs b/src/FSharp.Core/Linq.fs index 33a1dd18265..6b62eccb93e 100644 --- a/src/FSharp.Core/Linq.fs +++ b/src/FSharp.Core/Linq.fs @@ -44,9 +44,9 @@ module LeafExpressionConverter = let equivHeadTypes (ty1:Type) (ty2:Type) = isNamedType(ty1) && if ty1.IsGenericType then - ty2.IsGenericType && (ty1.GetGenericTypeDefinition()).Equals(ty2.GetGenericTypeDefinition()) + ty2.IsGenericType && Type.op_Equality(ty1.GetGenericTypeDefinition(), ty2.GetGenericTypeDefinition()) else - ty1.Equals(ty2) + Type.op_Equality(ty1, ty2) let isFunctionType typ = equivHeadTypes typ (typeof<(int -> int)>) @@ -458,7 +458,7 @@ module LeafExpressionConverter = let converted = ConvExprToLinqInContext env x // Most of conversion scenarios in C# are covered by Expression.Convert - if x.Type.Equals toTy then converted // source and target types match - do nothing + if Type.op_Equality(x.Type, toTy) then converted // source and target types match - do nothing elif not (x.Type.IsValueType || toTy.IsValueType) && toTy.IsAssignableFrom x.Type then converted // converting reference type to supertype - do nothing else Expression.Convert(converted, toTy) |> asExpr // emit Expression.Convert @@ -522,7 +522,10 @@ module LeafExpressionConverter = Expression.New(ctor, argsR, [| for p in props -> (p :> MemberInfo) |]) |> asExpr // Do the same thing as C# compiler for string addition - | PlusQ (_, GenericArgs [|ty1; ty2; ty3|], [x1; x2]) when ty1 = typeof && ty2 = typeof && ty3 = typeof -> + | PlusQ (_, GenericArgs [|ty1; ty2; ty3|], [x1; x2]) + when Type.op_Equality(ty1, typeof) && + Type.op_Equality(ty2, typeof) && + Type.op_Equality(ty3, typeof) -> Expression.Add(ConvExprToLinqInContext env x1, ConvExprToLinqInContext env x2, StringConcat) |> asExpr // LanguagePrimitives.PhysicalEquality's generic constraint of both sides being the same reference type is already sufficient for Linq Expressions' requirements diff --git a/src/FSharp.Core/Query.fs b/src/FSharp.Core/Query.fs index ae11d3835a1..28a460619f6 100644 --- a/src/FSharp.Core/Query.fs +++ b/src/FSharp.Core/Query.fs @@ -440,7 +440,7 @@ module Query = let IsIEnumerableTy (ty: System.Type) = ty.IsGenericType && ty.GetGenericTypeDefinition() = IEnumerableTypeDef // Check a tag type on QuerySource is IQueryable - let qTyIsIQueryable (ty : System.Type) = not (ty.Equals(typeof)) + let qTyIsIQueryable (ty : System.Type) = not (Type.op_Equality(ty, typeof)) let FuncExprToDelegateExpr (srcTy, targetTy, v, body) = Expr.NewDelegate (Linq.Expressions.Expression.GetFuncType [| srcTy; targetTy |], [v], body) @@ -588,21 +588,21 @@ module Query = let selector = MakeImplicitExpressionConversion selector let maker = match resTyNoNullable with - | ty when ty = typeof -> mq_double - | ty when ty = typeof -> mq_single - | ty when ty = typeof -> mq_decimal - | ty when ty = typeof -> mq_int32 - | ty when ty = typeof -> mq_int64 + | ty when Type.op_Equality(ty, typeof) -> mq_double + | ty when Type.op_Equality(ty, typeof) -> mq_single + | ty when Type.op_Equality(ty, typeof) -> mq_decimal + | ty when Type.op_Equality(ty, typeof) -> mq_int32 + | ty when Type.op_Equality(ty, typeof) -> mq_int64 | _ -> failDueToUnsupportedInputTypeInSumByOrAverageBy() maker ([srcItemTy], [src; selector]) else // Try to dynamically invoke a LINQ method if one exists, since these may be optimized over arrays etc. match resTyNoNullable with - | ty when ty = typeof -> me_double ([srcItemTy], [src; selector]) - | ty when ty = typeof -> me_single ([srcItemTy], [src; selector]) - | ty when ty = typeof -> me_decimal ([srcItemTy], [src; selector]) - | ty when ty = typeof -> me_int32 ([srcItemTy], [src; selector]) - | ty when ty = typeof -> me_int64 ([srcItemTy], [src; selector]) + | ty when Type.op_Equality(ty, typeof) -> me_double ([srcItemTy], [src; selector]) + | ty when Type.op_Equality(ty, typeof) -> me_single ([srcItemTy], [src; selector]) + | ty when Type.op_Equality(ty, typeof) -> me_decimal ([srcItemTy], [src; selector]) + | ty when Type.op_Equality(ty, typeof) -> me_int32 ([srcItemTy], [src; selector]) + | ty when Type.op_Equality(ty, typeof) -> me_int64 ([srcItemTy], [src; selector]) | _ -> // The F# implementation needs a QuerySource as a parameter. let qTy = typeof @@ -617,22 +617,22 @@ module Query = let selector = FuncExprToLinqFunc2Expression (srcItemTy, resTy, v, res) let caller = match resTyNoNullable with - | ty when ty = typeof -> cq_double - | ty when ty = typeof -> cq_single - | ty when ty = typeof -> cq_decimal - | ty when ty = typeof -> cq_int32 - | ty when ty = typeof -> cq_int64 + | ty when Type.op_Equality(ty, typeof) -> cq_double + | ty when Type.op_Equality(ty, typeof) -> cq_single + | ty when Type.op_Equality(ty, typeof) -> cq_decimal + | ty when Type.op_Equality(ty, typeof) -> cq_int32 + | ty when Type.op_Equality(ty, typeof) -> cq_int64 | _ -> failDueToUnsupportedInputTypeInSumByOrAverageBy() caller ([srcItemTy], [src; box selector]) : obj else // Try to dynamically invoke a LINQ method if one exists, since these may be optimized over arrays etc. let linqMethOpt = match resTyNoNullable with - | ty when ty = typeof -> Some ce_double - | ty when ty = typeof -> Some ce_single - | ty when ty = typeof -> Some ce_decimal - | ty when ty = typeof -> Some ce_int32 - | ty when ty = typeof -> Some ce_int64 + | ty when Type.op_Equality(ty, typeof) -> Some ce_double + | ty when Type.op_Equality(ty, typeof) -> Some ce_single + | ty when Type.op_Equality(ty, typeof) -> Some ce_decimal + | ty when Type.op_Equality(ty, typeof) -> Some ce_int32 + | ty when Type.op_Equality(ty, typeof) -> Some ce_int64 | _ -> None match linqMethOpt with | Some ce -> @@ -1617,7 +1617,7 @@ module Query = let IQueryableTySpec = MakeIQueryableTy tyArg // if result type of nested query is derived from IQueryable but not IQueryable itself (i.e. IOrderedQueryable) // then add coercion to IQueryable so result type will match expected signature of QuerySource.Run - if (IQueryableTySpec.IsAssignableFrom replNestedQuery.Type) && not (IQueryableTySpec.Equals replNestedQuery.Type) then + if (IQueryableTySpec.IsAssignableFrom replNestedQuery.Type) && not (Type.op_Equality(IQueryableTySpec, replNestedQuery.Type)) then Expr.Coerce (replNestedQuery, IQueryableTySpec) else replNestedQuery diff --git a/src/FSharp.Core/prim-types.fs b/src/FSharp.Core/prim-types.fs index 0489528c062..85befedcb4b 100644 --- a/src/FSharp.Core/prim-types.fs +++ b/src/FSharp.Core/prim-types.fs @@ -606,7 +606,7 @@ namespace Microsoft.FSharp.Core then TypeNullnessSemantics_NullNever else if not (typeof<'T>.IsDefined(typeof, false)) then TypeNullnessSemantics_NullIsExtraValue - elif typeof<'T>.Equals(typeof) then + elif Type.op_Equality (typeof<'T>, typeof) then TypeNullnessSemantics_NullTrueValue elif typeof.IsAssignableFrom(typeof<'T>) then TypeNullnessSemantics_NullIsExtraValue @@ -2098,22 +2098,22 @@ namespace Microsoft.FSharp.Core type FastGenericEqualityComparerTable<'T>() = static let f : IEqualityComparer<'T> = match typeof<'T> with - | ty when ty.Equals(typeof) -> unboxPrim (box BoolIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box ByteIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box Int32IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt32IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box CharIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box SByteIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box Int16IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box Int64IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box IntPtrIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt16IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt64IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box UIntPtrIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box FloatIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box Float32IEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box DecimalIEquality) - | ty when ty.Equals(typeof) -> unboxPrim (box StringIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box BoolIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box ByteIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int32IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt32IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box CharIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box SByteIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int16IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int64IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box IntPtrIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt16IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt64IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UIntPtrIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box FloatIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Float32IEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box DecimalIEquality) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box StringIEquality) | _ -> MakeGenericEqualityComparer<'T>() static member Function : IEqualityComparer<'T> = f @@ -2193,42 +2193,42 @@ namespace Microsoft.FSharp.Core // REVIEW: in a future version we could extend this to include additional types static let fCanBeNull : IComparer<'T> = match typeof<'T> with - | ty when ty.Equals(typeof) -> unboxPrim (box IntPtrComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box UIntPtrComparer) - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> null - | ty when ty.Equals(typeof) -> unboxPrim (box StringComparer) - | ty when ty.Equals(typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box IntPtrComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UIntPtrComparer) + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> null + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box StringComparer) + | ty when Type.op_Equality(ty, typeof) -> null | _ -> MakeGenericComparer<'T>() static let f : IComparer<'T> = match typeof<'T> with - | ty when ty.Equals(typeof) -> unboxPrim (box ByteComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box CharComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box SByteComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box Int16Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box Int32Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box Int64Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box IntPtrComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt16Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt32Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box UInt64Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box UIntPtrComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box FloatComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box Float32Comparer) - | ty when ty.Equals(typeof) -> unboxPrim (box DecimalComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box StringComparer) - | ty when ty.Equals(typeof) -> unboxPrim (box BoolComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box ByteComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box CharComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box SByteComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int16Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int32Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Int64Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box IntPtrComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt16Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt32Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UInt64Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box UIntPtrComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box FloatComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box Float32Comparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box DecimalComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box StringComparer) + | ty when Type.op_Equality(ty, typeof) -> unboxPrim (box BoolComparer) | _ -> // Review: There are situations where we should be able // to return Generic.Comparer<'T>.Default here. @@ -2450,46 +2450,46 @@ namespace Microsoft.FSharp.Core type GenericZeroDynamicImplTable<'T>() = static let result : 'T = // The dynamic implementation - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<'T> (box 0y) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0s) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0L) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0n) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0uy) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0us) - elif aty.Equals(typeof) then unboxPrim<'T> (box '\000') - elif aty.Equals(typeof) then unboxPrim<'T> (box 0u) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0UL) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0un) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0M) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0.0) - elif aty.Equals(typeof) then unboxPrim<'T> (box 0.0f) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0y) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0s) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0L) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0n) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0uy) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0us) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box '\000') + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0u) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0UL) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0un) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0M) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0.0) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 0.0f) else - let pinfo = aty.GetProperty("Zero") + let pinfo = ty.GetProperty("Zero") unboxPrim<'T> (pinfo.GetValue(null,null)) static member Result : 'T = result type GenericOneDynamicImplTable<'T>() = static let result : 'T = // The dynamic implementation - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<'T> (box 1y) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1s) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1L) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1n) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1uy) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1us) - elif aty.Equals(typeof) then unboxPrim<'T> (box '\001') - elif aty.Equals(typeof) then unboxPrim<'T> (box 1u) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1UL) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1un) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1M) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1.0) - elif aty.Equals(typeof) then unboxPrim<'T> (box 1.0f) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1y) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1s) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1L) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1n) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1uy) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1us) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box '\001') + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1u) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1UL) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1un) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1M) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1.0) + elif Type.op_Equality(ty, typeof) then unboxPrim<'T> (box 1.0f) else - let pinfo = aty.GetProperty("One") + let pinfo = ty.GetProperty("One") unboxPrim<'T> (pinfo.GetValue(null,null)) static member Result : 'T = result @@ -2604,7 +2604,7 @@ namespace Microsoft.FSharp.Core let ameth = aty.GetSingleStaticMethodByTypes(opName, [| aty; bty |]) let bmeth = - if aty.Equals(bty) then null else + if Type.op_Equality(aty, bty) then null else bty.GetSingleStaticMethodByTypes(opName, [| aty; bty |]) match ameth, bmeth with | null, null -> raise (NotSupportedException (SR.GetString(SR.dyInvOpAddCoerce))) @@ -4175,7 +4175,7 @@ namespace Microsoft.FSharp.Core let Failure message = new Exception(message) [] - let (|Failure|_|) (error: exn) = if error.GetType().Equals(typeof) then Some error.Message else None + let (|Failure|_|) (error: exn) = if Type.op_Equality(error.GetType(), typeof) then Some error.Message else None let inline (<) x y = GenericLessThan x y @@ -5002,7 +5002,7 @@ namespace Microsoft.FSharp.Core when ^T : string = not (# "clt" (String.CompareOrdinal((# "" x : string #),(# "" y : string #))) 0 : bool #) when ^T : ^T = ((^T or ^U): (static member (>=) : ^T * ^U -> bool) (x,y)) - /// Static greater-than-or-equal with static optimizations for some well-known cases. + /// Static equal with static optimizations for some well-known cases. let inline (=) (x:^T) (y:^T) = EqualityDynamic<(^T), (^T), bool> x y when ^T : bool = (# "ceq" x y : bool #) @@ -5023,6 +5023,7 @@ namespace Microsoft.FSharp.Core when ^T : decimal = Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #)) when ^T : ^T = (^T : (static member (=) : ^T * ^T -> bool) (x,y)) + /// Static unequal with static optimizations for some well-known cases. let inline (<>) (x:^T) (y:^T) = InequalityDynamic<(^T), (^T), bool> x y when ^T : bool = not (# "ceq" x y : bool #) @@ -6472,181 +6473,181 @@ namespace Microsoft.FSharp.Core type AbsDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:sbyte) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int16) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int32) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int64) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:nativeint) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> absImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:decimal) -> absImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:sbyte) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int16) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int32) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int64) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:nativeint) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> absImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:decimal) -> absImpl x) else UnaryDynamicImpl "Abs" static member Result : ('T -> 'T) = result type AcosDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> acosImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> acosImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> acosImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> acosImpl x) else UnaryDynamicImpl "Acos" static member Result : ('T -> 'T) = result type AsinDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> asinImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> asinImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> asinImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> asinImpl x) else UnaryDynamicImpl "Asin" static member Result : ('T -> 'T) = result type AtanDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> atanImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> atanImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> atanImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> atanImpl x) else UnaryDynamicImpl "Atan" static member Result : ('T -> 'T) = result type Atan2DynamicImplTable<'T,'U>() = static let result : ('T -> 'T -> 'U) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) (y:float) -> atan2Impl x y) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) (y:float32) -> atan2Impl x y) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) (y:float) -> atan2Impl x y) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) (y:float32) -> atan2Impl x y) else BinaryDynamicImpl "Atan2" static member Result : ('T -> 'T -> 'U) = result type CeilingDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> ceilImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> ceilImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> ceilImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> ceilImpl x) else UnaryDynamicImpl "Ceiling" static member Result : ('T -> 'T) = result type ExpDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> expImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> expImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> expImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> expImpl x) else UnaryDynamicImpl "Exp" static member Result : ('T -> 'T) = result type FloorDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> floorImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> floorImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> floorImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> floorImpl x) else UnaryDynamicImpl "Floor" static member Result : ('T -> 'T) = result type TruncateDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> truncateImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> truncateImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> truncateImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> truncateImpl x) else UnaryDynamicImpl "Truncate" static member Result : ('T -> 'T) = result type RoundDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> roundImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> roundImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> roundImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> roundImpl x) else UnaryDynamicImpl "Round" static member Result : ('T -> 'T) = result type SignDynamicImplTable<'T>() = static let result : ('T -> int) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:nativeint) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:decimal) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int16) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int32) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:int64) -> signImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:sbyte) -> signImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:nativeint) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:decimal) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int16) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int32) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:int64) -> signImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:sbyte) -> signImpl x) else UnaryDynamicImpl "Sign" static member Result : ('T -> int) = result type LogDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> logImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> logImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> logImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> logImpl x) else UnaryDynamicImpl "Log" static member Result : ('T -> 'T) = result type Log10DynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> log10Impl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> log10Impl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> log10Impl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> log10Impl x) else UnaryDynamicImpl "Log10" static member Result : ('T -> 'T) = result type SqrtDynamicImplTable<'T,'U>() = static let result : ('T -> 'U) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> sqrtImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> sqrtImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> sqrtImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> sqrtImpl x) else UnaryDynamicImpl "Sqrt" static member Result : ('T -> 'U) = result type CosDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> cosImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> cosImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> cosImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> cosImpl x) else UnaryDynamicImpl "Cos" static member Result : ('T -> 'T) = result type CoshDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> coshImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> coshImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> coshImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> coshImpl x) else UnaryDynamicImpl "Cosh" static member Result : ('T -> 'T) = result type SinDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> sinImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> sinImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> sinImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> sinImpl x) else UnaryDynamicImpl "Sin" static member Result : ('T -> 'T) = result type SinhDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> sinhImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> sinhImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> sinhImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> sinhImpl x) else UnaryDynamicImpl "Sinh" static member Result : ('T -> 'T) = result type TanDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> tanImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> tanImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> tanImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> tanImpl x) else UnaryDynamicImpl "Tan" static member Result : ('T -> 'T) = result type TanhDynamicImplTable<'T>() = static let result : ('T -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) -> tanhImpl x) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) -> tanhImpl x) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) -> tanhImpl x) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) -> tanhImpl x) else UnaryDynamicImpl "Tanh" static member Result : ('T -> 'T) = result type PowDynamicImplTable<'T,'U>() = static let result : ('T -> 'U -> 'T) = - let aty = typeof<'T> - if aty.Equals(typeof) then unboxPrim<_>(fun (x:float) (y:float) -> powImpl x y) - elif aty.Equals(typeof) then unboxPrim<_>(fun (x:float32) (y:float32) -> powImpl x y) + let ty = typeof<'T> + if Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float) (y:float) -> powImpl x y) + elif Type.op_Equality(ty, typeof) then unboxPrim<_>(fun (x:float32) (y:float32) -> powImpl x y) else BinaryDynamicImpl "Pow" static member Result : ('T -> 'U -> 'T) = result diff --git a/src/FSharp.Core/quotations.fs b/src/FSharp.Core/quotations.fs index c3c7317e522..20f2e8ca06b 100644 --- a/src/FSharp.Core/quotations.fs +++ b/src/FSharp.Core/quotations.fs @@ -1403,7 +1403,7 @@ module Patterns = | Ambiguous of 'R let typeEquals (ty1: Type) (ty2: Type) = - ty1.Equals ty2 + Type.op_Equality (ty1, ty2) let typesEqual (tys1: Type list) (tys2: Type list) = (tys1.Length = tys2.Length) && List.forall2 typeEquals tys1 tys2 diff --git a/src/FSharp.Core/reflect.fs b/src/FSharp.Core/reflect.fs index 76dbb87c490..e9522f68c99 100644 --- a/src/FSharp.Core/reflect.fs +++ b/src/FSharp.Core/reflect.fs @@ -43,9 +43,9 @@ module internal Impl = isNamedType ty1 && if ty1.IsGenericType then ty2.IsGenericType - && (ty1.GetGenericTypeDefinition()).Equals(ty2.GetGenericTypeDefinition()) + && Type.op_Equality (ty1.GetGenericTypeDefinition(), ty2.GetGenericTypeDefinition()) else - ty1.Equals ty2 + Type.op_Equality (ty1, ty2) let func = typedefof<(obj -> obj)> diff --git a/src/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs b/src/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs index 294cf2df55d..0740f5aa753 100644 --- a/src/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs +++ b/src/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs @@ -132,7 +132,7 @@ module FSharpDependencyManager = | Some "timeout", None -> raise (ArgumentException(SR.missingTimeoutValue ())) | Some "timeout", value -> match value with - | Some v when v.GetType() = typeof -> + | Some v when Type.op_Equality (v.GetType(), typeof) -> let parsed, value = Int32.TryParse(v) if parsed && value >= 0 then diff --git a/tests/service/data/TestTP/ProvidedTypes.fs b/tests/service/data/TestTP/ProvidedTypes.fs index c13961cbc27..4e7a7604c6b 100644 --- a/tests/service/data/TestTP/ProvidedTypes.fs +++ b/tests/service/data/TestTP/ProvidedTypes.fs @@ -76,7 +76,7 @@ module Utils = /// General implementation of .Equals(Type) logic for System.Type over symbol types. You can use this with other types too. let rec eqTypes (ty1: Type) (ty2: Type) = if Object.ReferenceEquals(ty1, ty2) then true - elif ty1.IsGenericTypeDefinition then ty2.IsGenericTypeDefinition && ty1.Equals(ty2) + elif ty1.IsGenericTypeDefinition then ty2.IsGenericTypeDefinition && Type.op_Equality(ty1, ty2) elif ty1.IsGenericType then ty2.IsGenericType && not ty2.IsGenericTypeDefinition && eqTypes (ty1.GetGenericTypeDefinition()) (ty2.GetGenericTypeDefinition()) && lengthsEqAndForall2 (ty1.GetGenericArguments()) (ty2.GetGenericArguments()) eqTypes elif ty1.IsArray then ty2.IsArray && ty1.GetArrayRank() = ty2.GetArrayRank() && eqTypes (ty1.GetElementType()) (ty2.GetElementType()) elif ty1.IsPointer then ty2.IsPointer && eqTypes (ty1.GetElementType()) (ty2.GetElementType())