Skip to content

Commit

Permalink
Change ty1.Equals(ty2) to call static op_Equality (#13028)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Zarytovskii <[email protected]>
Co-authored-by: Don Syme <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2022
1 parent b78ad5c commit 889709d
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 197 deletions.
5 changes: 3 additions & 2 deletions src/Compiler/AbstractIL/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/TypedTree/TypeProviders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>.Equals x || (x.Namespace = "System" && x.Name = "Void"))
member _.IsVoid = (Type.op_Equality(x, typeof<Void>) || (x.Namespace = "System" && x.Name = "Void"))

member _.IsGenericParameter = x.IsGenericParameter

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Utilities/sformat.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<obj option>

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Utilities/sr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Build/FSharpEmbedResourceText.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/FSharp.Core/Linq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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<string> && ty2 = typeof<string> && ty3 = typeof<string> ->
| PlusQ (_, GenericArgs [|ty1; ty2; ty3|], [x1; x2])
when Type.op_Equality(ty1, typeof<string>) &&
Type.op_Equality(ty2, typeof<string>) &&
Type.op_Equality(ty3, typeof<string>) ->
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
Expand Down
44 changes: 22 additions & 22 deletions src/FSharp.Core/Query.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEnumerable>))
let qTyIsIQueryable (ty : System.Type) = not (Type.op_Equality(ty, typeof<IEnumerable>))

let FuncExprToDelegateExpr (srcTy, targetTy, v, body) =
Expr.NewDelegate (Linq.Expressions.Expression.GetFuncType [| srcTy; targetTy |], [v], body)
Expand Down Expand Up @@ -588,21 +588,21 @@ module Query =
let selector = MakeImplicitExpressionConversion selector
let maker =
match resTyNoNullable with
| ty when ty = typeof<double> -> mq_double
| ty when ty = typeof<single> -> mq_single
| ty when ty = typeof<decimal> -> mq_decimal
| ty when ty = typeof<int32> -> mq_int32
| ty when ty = typeof<int64> -> mq_int64
| ty when Type.op_Equality(ty, typeof<double>) -> mq_double
| ty when Type.op_Equality(ty, typeof<single>) -> mq_single
| ty when Type.op_Equality(ty, typeof<decimal>) -> mq_decimal
| ty when Type.op_Equality(ty, typeof<int32>) -> mq_int32
| ty when Type.op_Equality(ty, typeof<int64>) -> 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<double> -> me_double ([srcItemTy], [src; selector])
| ty when ty = typeof<single> -> me_single ([srcItemTy], [src; selector])
| ty when ty = typeof<decimal> -> me_decimal ([srcItemTy], [src; selector])
| ty when ty = typeof<int32> -> me_int32 ([srcItemTy], [src; selector])
| ty when ty = typeof<int64> -> me_int64 ([srcItemTy], [src; selector])
| ty when Type.op_Equality(ty, typeof<double>) -> me_double ([srcItemTy], [src; selector])
| ty when Type.op_Equality(ty, typeof<single>) -> me_single ([srcItemTy], [src; selector])
| ty when Type.op_Equality(ty, typeof<decimal>) -> me_decimal ([srcItemTy], [src; selector])
| ty when Type.op_Equality(ty, typeof<int32>) -> me_int32 ([srcItemTy], [src; selector])
| ty when Type.op_Equality(ty, typeof<int64>) -> me_int64 ([srcItemTy], [src; selector])
| _ ->
// The F# implementation needs a QuerySource as a parameter.
let qTy = typeof<IEnumerable>
Expand All @@ -617,22 +617,22 @@ module Query =
let selector = FuncExprToLinqFunc2Expression (srcItemTy, resTy, v, res)
let caller =
match resTyNoNullable with
| ty when ty = typeof<double> -> cq_double
| ty when ty = typeof<single> -> cq_single
| ty when ty = typeof<decimal> -> cq_decimal
| ty when ty = typeof<int32> -> cq_int32
| ty when ty = typeof<int64> -> cq_int64
| ty when Type.op_Equality(ty, typeof<double>) -> cq_double
| ty when Type.op_Equality(ty, typeof<single>) -> cq_single
| ty when Type.op_Equality(ty, typeof<decimal>) -> cq_decimal
| ty when Type.op_Equality(ty, typeof<int32>) -> cq_int32
| ty when Type.op_Equality(ty, typeof<int64>) -> 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<double> -> Some ce_double
| ty when ty = typeof<single> -> Some ce_single
| ty when ty = typeof<decimal> -> Some ce_decimal
| ty when ty = typeof<int32> -> Some ce_int32
| ty when ty = typeof<int64> -> Some ce_int64
| ty when Type.op_Equality(ty, typeof<double>) -> Some ce_double
| ty when Type.op_Equality(ty, typeof<single>) -> Some ce_single
| ty when Type.op_Equality(ty, typeof<decimal>) -> Some ce_decimal
| ty when Type.op_Equality(ty, typeof<int32>) -> Some ce_int32
| ty when Type.op_Equality(ty, typeof<int64>) -> Some ce_int64
| _ -> None
match linqMethOpt with
| Some ce ->
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 889709d

Please sign in to comment.