Skip to content

Commit 768f39c

Browse files
dsymeKevinRansom
authored andcommitted
Remove redundant code (dotnet#6625)
* remove redundant code * remove redundant code
1 parent 70e1130 commit 768f39c

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

src/fsharp/TypeRelations.fs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open FSharp.Compiler.Infos
1414
open FSharp.Compiler.PrettyNaming
1515

1616
/// Implements a :> b without coercion based on finalized (no type variable) types
17-
// QUERY: This relation is approximate and not part of the language specification.
17+
// Note: This relation is approximate and not part of the language specification.
1818
//
1919
// Some appropriate uses:
2020
// patcompile.fs: IsDiscrimSubsumedBy (approximate warning for redundancy of 'isinst' patterns)
@@ -25,37 +25,24 @@ open FSharp.Compiler.PrettyNaming
2525
let rec TypeDefinitelySubsumesTypeNoCoercion ndeep g amap m ty1 ty2 =
2626
if ndeep > 100 then error(InternalError("recursive class hierarchy (detected in TypeDefinitelySubsumesTypeNoCoercion), ty1 = " + (DebugPrint.showType ty1), m))
2727
if ty1 === ty2 then true
28-
// QUERY : quadratic
2928
elif typeEquiv g ty1 ty2 then true
3029
else
3130
let ty1 = stripTyEqns g ty1
3231
let ty2 = stripTyEqns g ty2
33-
match ty1, ty2 with
34-
| TType_app (tc1, l1), TType_app (tc2, l2) when tyconRefEq g tc1 tc2 ->
35-
List.lengthsEqAndForall2 (typeEquiv g) l1 l2
36-
| TType_ucase (tc1, l1), TType_ucase (tc2, l2) when g.unionCaseRefEq tc1 tc2 ->
37-
List.lengthsEqAndForall2 (typeEquiv g) l1 l2
38-
| TType_tuple (tupInfo1, l1), TType_tuple (tupInfo2, l2) ->
39-
evalTupInfoIsStruct tupInfo1 = evalTupInfoIsStruct tupInfo2 &&
40-
List.lengthsEqAndForall2 (typeEquiv g) l1 l2
41-
| TType_fun (d1, r1), TType_fun (d2, r2) ->
42-
typeEquiv g d1 d2 && typeEquiv g r1 r2
43-
| TType_measure measure1, TType_measure measure2 ->
44-
measureEquiv g measure1 measure2
45-
| _ ->
46-
(typeEquiv g ty1 g.obj_ty && isRefTy g ty2) || (* F# reference types are subtypes of type 'obj' *)
47-
(isAppTy g ty2 &&
48-
isRefTy g ty2 &&
49-
50-
((match GetSuperTypeOfType g amap m ty2 with
51-
| None -> false
52-
| Some ty -> TypeDefinitelySubsumesTypeNoCoercion (ndeep+1) g amap m ty1 ty) ||
53-
54-
(isInterfaceTy g ty1 &&
55-
ty2 |> GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes g amap m
56-
|> List.exists (TypeDefinitelySubsumesTypeNoCoercion (ndeep+1) g amap m ty1))))
57-
58-
32+
// F# reference types are subtypes of type 'obj'
33+
(typeEquiv g ty1 g.obj_ty && isRefTy g ty2) ||
34+
// Follow the supertype chain
35+
(isAppTy g ty2 &&
36+
isRefTy g ty2 &&
37+
38+
((match GetSuperTypeOfType g amap m ty2 with
39+
| None -> false
40+
| Some ty -> TypeDefinitelySubsumesTypeNoCoercion (ndeep+1) g amap m ty1 ty) ||
41+
42+
// Follow the interface hierarchy
43+
(isInterfaceTy g ty1 &&
44+
ty2 |> GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes g amap m
45+
|> List.exists (TypeDefinitelySubsumesTypeNoCoercion (ndeep+1) g amap m ty1))))
5946

6047
type CanCoerce = CanCoerce | NoCoerce
6148

0 commit comments

Comments
 (0)