Skip to content

Commit 889709d

Browse files
rstm-sfvzarytovskiidsyme
authored
Change ty1.Equals(ty2) to call static op_Equality (dotnet#13028)
Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Don Syme <[email protected]>
1 parent b78ad5c commit 889709d

12 files changed

Lines changed: 202 additions & 197 deletions

File tree

src/Compiler/AbstractIL/ilreflect.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ module Zmap =
412412
| Some y -> y
413413
| None -> failwithf "Zmap.force: %s: x = %+A" str x
414414

415-
let equalTypes (s: Type) (t: Type) = s.Equals t
415+
let equalTypes (s: Type) (t: Type) = Type.op_Equality (s, t)
416416

417417
let equalTypeLists (tys1: Type list) (tys2: Type list) =
418418
List.lengthsEqAndForall2 equalTypes tys1 tys2
@@ -820,7 +820,8 @@ let TypeBuilderInstantiationT =
820820
ty
821821

822822
let typeIsNotQueryable (ty: Type) =
823-
(ty :? TypeBuilder) || ((ty.GetType()).Equals(TypeBuilderInstantiationT))
823+
(ty :? TypeBuilder)
824+
|| Type.op_Equality (ty.GetType(), TypeBuilderInstantiationT)
824825

825826
let queryableTypeGetField _emEnv (parentT: Type) (fref: ILFieldRef) =
826827
let res =

src/Compiler/TypedTree/TypeProviders.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) =
415415
member _.ApplyStaticArguments(provider: ITypeProvider, fullTypePathAfterArguments, staticArgs: obj[]) =
416416
provider.ApplyStaticArguments(x, fullTypePathAfterArguments, staticArgs) |> ProvidedType.Create ctxt
417417

418-
member _.IsVoid = (typeof<Void>.Equals x || (x.Namespace = "System" && x.Name = "Void"))
418+
member _.IsVoid = (Type.op_Equality(x, typeof<Void>) || (x.Namespace = "System" && x.Name = "Void"))
419419

420420
member _.IsGenericParameter = x.IsGenericParameter
421421

src/Compiler/Utilities/sformat.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ module ReflectUtils =
455455
isNamedType (ty1)
456456
&& if ty1.IsGenericType then
457457
ty2.IsGenericType
458-
&& (ty1.GetGenericTypeDefinition()).Equals(ty2.GetGenericTypeDefinition())
458+
&& Type.op_Equality (ty1.GetGenericTypeDefinition(), ty2.GetGenericTypeDefinition())
459459
else
460-
ty1.Equals(ty2)
460+
Type.op_Equality (ty1, ty2)
461461

462462
let option = typedefof<obj option>
463463

src/Compiler/Utilities/sr.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module internal DiagnosticMessage =
3737
let isFunctionType (ty1: System.Type) =
3838
isNamedType (ty1)
3939
&& ty1.IsGenericType
40-
&& (ty1.GetGenericTypeDefinition()).Equals(funTyC)
40+
&& System.Type.op_Equality (ty1.GetGenericTypeDefinition(), funTyC)
4141

4242
let rec destFunTy (ty: System.Type) =
4343
if isFunctionType ty then

src/FSharp.Build/FSharpEmbedResourceText.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ open Printf
289289
290290
static let isNamedType(ty:System.Type) = not (ty.IsArray || ty.IsByRef || ty.IsPointer)
291291
static let isFunctionType (ty1:System.Type) =
292-
isNamedType(ty1) && getTypeInfo(ty1).IsGenericType && (ty1.GetGenericTypeDefinition()).Equals(funTyC)
292+
isNamedType(ty1) && getTypeInfo(ty1).IsGenericType && System.Type.op_Equality(ty1.GetGenericTypeDefinition(), funTyC)
293293
294294
static let rec destFunTy (ty:System.Type) =
295295
if isFunctionType ty then

src/FSharp.Core/Linq.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ module LeafExpressionConverter =
4444
let equivHeadTypes (ty1:Type) (ty2:Type) =
4545
isNamedType(ty1) &&
4646
if ty1.IsGenericType then
47-
ty2.IsGenericType && (ty1.GetGenericTypeDefinition()).Equals(ty2.GetGenericTypeDefinition())
47+
ty2.IsGenericType && Type.op_Equality(ty1.GetGenericTypeDefinition(), ty2.GetGenericTypeDefinition())
4848
else
49-
ty1.Equals(ty2)
49+
Type.op_Equality(ty1, ty2)
5050

5151
let isFunctionType typ = equivHeadTypes typ (typeof<(int -> int)>)
5252

@@ -458,7 +458,7 @@ module LeafExpressionConverter =
458458
let converted = ConvExprToLinqInContext env x
459459

460460
// Most of conversion scenarios in C# are covered by Expression.Convert
461-
if x.Type.Equals toTy then converted // source and target types match - do nothing
461+
if Type.op_Equality(x.Type, toTy) then converted // source and target types match - do nothing
462462
elif not (x.Type.IsValueType || toTy.IsValueType) && toTy.IsAssignableFrom x.Type then converted // converting reference type to supertype - do nothing
463463
else Expression.Convert(converted, toTy) |> asExpr // emit Expression.Convert
464464

@@ -522,7 +522,10 @@ module LeafExpressionConverter =
522522
Expression.New(ctor, argsR, [| for p in props -> (p :> MemberInfo) |]) |> asExpr
523523

524524
// Do the same thing as C# compiler for string addition
525-
| PlusQ (_, GenericArgs [|ty1; ty2; ty3|], [x1; x2]) when ty1 = typeof<string> && ty2 = typeof<string> && ty3 = typeof<string> ->
525+
| PlusQ (_, GenericArgs [|ty1; ty2; ty3|], [x1; x2])
526+
when Type.op_Equality(ty1, typeof<string>) &&
527+
Type.op_Equality(ty2, typeof<string>) &&
528+
Type.op_Equality(ty3, typeof<string>) ->
526529
Expression.Add(ConvExprToLinqInContext env x1, ConvExprToLinqInContext env x2, StringConcat) |> asExpr
527530

528531
// LanguagePrimitives.PhysicalEquality's generic constraint of both sides being the same reference type is already sufficient for Linq Expressions' requirements

src/FSharp.Core/Query.fs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ module Query =
440440
let IsIEnumerableTy (ty: System.Type) = ty.IsGenericType && ty.GetGenericTypeDefinition() = IEnumerableTypeDef
441441

442442
// Check a tag type on QuerySource is IQueryable
443-
let qTyIsIQueryable (ty : System.Type) = not (ty.Equals(typeof<IEnumerable>))
443+
let qTyIsIQueryable (ty : System.Type) = not (Type.op_Equality(ty, typeof<IEnumerable>))
444444

445445
let FuncExprToDelegateExpr (srcTy, targetTy, v, body) =
446446
Expr.NewDelegate (Linq.Expressions.Expression.GetFuncType [| srcTy; targetTy |], [v], body)
@@ -588,21 +588,21 @@ module Query =
588588
let selector = MakeImplicitExpressionConversion selector
589589
let maker =
590590
match resTyNoNullable with
591-
| ty when ty = typeof<double> -> mq_double
592-
| ty when ty = typeof<single> -> mq_single
593-
| ty when ty = typeof<decimal> -> mq_decimal
594-
| ty when ty = typeof<int32> -> mq_int32
595-
| ty when ty = typeof<int64> -> mq_int64
591+
| ty when Type.op_Equality(ty, typeof<double>) -> mq_double
592+
| ty when Type.op_Equality(ty, typeof<single>) -> mq_single
593+
| ty when Type.op_Equality(ty, typeof<decimal>) -> mq_decimal
594+
| ty when Type.op_Equality(ty, typeof<int32>) -> mq_int32
595+
| ty when Type.op_Equality(ty, typeof<int64>) -> mq_int64
596596
| _ -> failDueToUnsupportedInputTypeInSumByOrAverageBy()
597597
maker ([srcItemTy], [src; selector])
598598
else
599599
// Try to dynamically invoke a LINQ method if one exists, since these may be optimized over arrays etc.
600600
match resTyNoNullable with
601-
| ty when ty = typeof<double> -> me_double ([srcItemTy], [src; selector])
602-
| ty when ty = typeof<single> -> me_single ([srcItemTy], [src; selector])
603-
| ty when ty = typeof<decimal> -> me_decimal ([srcItemTy], [src; selector])
604-
| ty when ty = typeof<int32> -> me_int32 ([srcItemTy], [src; selector])
605-
| ty when ty = typeof<int64> -> me_int64 ([srcItemTy], [src; selector])
601+
| ty when Type.op_Equality(ty, typeof<double>) -> me_double ([srcItemTy], [src; selector])
602+
| ty when Type.op_Equality(ty, typeof<single>) -> me_single ([srcItemTy], [src; selector])
603+
| ty when Type.op_Equality(ty, typeof<decimal>) -> me_decimal ([srcItemTy], [src; selector])
604+
| ty when Type.op_Equality(ty, typeof<int32>) -> me_int32 ([srcItemTy], [src; selector])
605+
| ty when Type.op_Equality(ty, typeof<int64>) -> me_int64 ([srcItemTy], [src; selector])
606606
| _ ->
607607
// The F# implementation needs a QuerySource as a parameter.
608608
let qTy = typeof<IEnumerable>
@@ -617,22 +617,22 @@ module Query =
617617
let selector = FuncExprToLinqFunc2Expression (srcItemTy, resTy, v, res)
618618
let caller =
619619
match resTyNoNullable with
620-
| ty when ty = typeof<double> -> cq_double
621-
| ty when ty = typeof<single> -> cq_single
622-
| ty when ty = typeof<decimal> -> cq_decimal
623-
| ty when ty = typeof<int32> -> cq_int32
624-
| ty when ty = typeof<int64> -> cq_int64
620+
| ty when Type.op_Equality(ty, typeof<double>) -> cq_double
621+
| ty when Type.op_Equality(ty, typeof<single>) -> cq_single
622+
| ty when Type.op_Equality(ty, typeof<decimal>) -> cq_decimal
623+
| ty when Type.op_Equality(ty, typeof<int32>) -> cq_int32
624+
| ty when Type.op_Equality(ty, typeof<int64>) -> cq_int64
625625
| _ -> failDueToUnsupportedInputTypeInSumByOrAverageBy()
626626
caller ([srcItemTy], [src; box selector]) : obj
627627
else
628628
// Try to dynamically invoke a LINQ method if one exists, since these may be optimized over arrays etc.
629629
let linqMethOpt =
630630
match resTyNoNullable with
631-
| ty when ty = typeof<double> -> Some ce_double
632-
| ty when ty = typeof<single> -> Some ce_single
633-
| ty when ty = typeof<decimal> -> Some ce_decimal
634-
| ty when ty = typeof<int32> -> Some ce_int32
635-
| ty when ty = typeof<int64> -> Some ce_int64
631+
| ty when Type.op_Equality(ty, typeof<double>) -> Some ce_double
632+
| ty when Type.op_Equality(ty, typeof<single>) -> Some ce_single
633+
| ty when Type.op_Equality(ty, typeof<decimal>) -> Some ce_decimal
634+
| ty when Type.op_Equality(ty, typeof<int32>) -> Some ce_int32
635+
| ty when Type.op_Equality(ty, typeof<int64>) -> Some ce_int64
636636
| _ -> None
637637
match linqMethOpt with
638638
| Some ce ->
@@ -1617,7 +1617,7 @@ module Query =
16171617
let IQueryableTySpec = MakeIQueryableTy tyArg
16181618
// if result type of nested query is derived from IQueryable but not IQueryable itself (i.e. IOrderedQueryable)
16191619
// then add coercion to IQueryable so result type will match expected signature of QuerySource.Run
1620-
if (IQueryableTySpec.IsAssignableFrom replNestedQuery.Type) && not (IQueryableTySpec.Equals replNestedQuery.Type) then
1620+
if (IQueryableTySpec.IsAssignableFrom replNestedQuery.Type) && not (Type.op_Equality(IQueryableTySpec, replNestedQuery.Type)) then
16211621
Expr.Coerce (replNestedQuery, IQueryableTySpec)
16221622
else
16231623
replNestedQuery

0 commit comments

Comments
 (0)