Skip to content

Commit e488275

Browse files
dotnet-botforki
andauthored
Remove isAppTy (#9282) (#9293)
Co-authored-by: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
1 parent 177e908 commit e488275

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/fsharp/infos.fs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ let CanImportILType scoref amap m ilty =
4141

4242
/// Indicates if an F# type is the type associated with an F# exception declaration
4343
let isExnDeclTy g ty =
44-
isAppTy g ty && (tcrefOfAppTy g ty).IsExceptionDecl
44+
match tryTcrefOfAppTy g ty with
45+
| ValueSome tcref -> tcref.IsExceptionDecl
46+
| _ -> false
4547

4648
/// Get the base type of a type, taking into account type instantiations. Return None if the
4749
/// type has no base type.
4850
let GetSuperTypeOfType g amap m ty =
4951
#if !NO_EXTENSIONTYPING
50-
let ty = (if isAppTy g ty && (tcrefOfAppTy g ty).IsProvided then stripTyEqns g ty else stripTyEqnsAndMeasureEqns g ty)
52+
let ty =
53+
match tryTcrefOfAppTy g ty with
54+
| ValueSome tcref when tcref.IsProvided -> stripTyEqns g ty
55+
| _ -> stripTyEqnsAndMeasureEqns g ty
5156
#else
5257
let ty = stripTyEqnsAndMeasureEqns g ty
5358
#endif
@@ -107,10 +112,11 @@ let rec GetImmediateInterfacesOfType skipUnref g amap m ty =
107112
[ match tcref.TypeReprInfo with
108113
| TMeasureableRepr reprTy ->
109114
for ity in GetImmediateInterfacesOfType skipUnref g amap m reprTy do
110-
if isAppTy g ity then
111-
let itcref = tcrefOfAppTy g ity
115+
match tryTcrefOfAppTy g ity with
116+
| ValueNone -> ()
117+
| ValueSome itcref ->
112118
if not (tyconRefEq g itcref g.system_GenericIComparable_tcref) &&
113-
not (tyconRefEq g itcref g.system_GenericIEquatable_tcref) then
119+
not (tyconRefEq g itcref g.system_GenericIEquatable_tcref) then
114120
yield ity
115121
| _ -> ()
116122
yield mkAppTy g.system_GenericIComparable_tcref [ty]
@@ -157,7 +163,10 @@ type AllowMultiIntfInstantiations = Yes | No
157163
let private FoldHierarchyOfTypeAux followInterfaces allowMultiIntfInst skipUnref visitor g amap m ty acc =
158164
let rec loop ndeep ty ((visitedTycon, visited: TyconRefMultiMap<_>, acc) as state) =
159165

160-
let seenThisTycon = isAppTy g ty && Set.contains (tcrefOfAppTy g ty).Stamp visitedTycon
166+
let seenThisTycon =
167+
match tryTcrefOfAppTy g ty with
168+
| ValueSome tcref -> Set.contains tcref.Stamp visitedTycon
169+
| _ -> false
161170

162171
// Do not visit the same type twice. Could only be doing this if we've seen this tycon
163172
if seenThisTycon && List.exists (typeEquiv g ty) (visited.Find (tcrefOfAppTy g ty)) then state else
@@ -166,11 +175,11 @@ let private FoldHierarchyOfTypeAux followInterfaces allowMultiIntfInst skipUnref
166175
if seenThisTycon && allowMultiIntfInst = AllowMultiIntfInstantiations.No then state else
167176

168177
let state =
169-
if isAppTy g ty then
170-
let tcref = tcrefOfAppTy g ty
178+
match tryTcrefOfAppTy g ty with
179+
| ValueSome tcref ->
171180
let visitedTycon = Set.add tcref.Stamp visitedTycon
172181
visitedTycon, visited.Add (tcref, ty), acc
173-
else
182+
| _ ->
174183
state
175184

176185
if ndeep > 100 then (errorR(Error((FSComp.SR.recursiveClassHierarchy (showType ty)), m)); (visitedTycon, visited, acc)) else
@@ -257,14 +266,18 @@ let AllInterfacesOfType g amap m allowMultiIntfInst ty =
257266

258267
/// Check if two types have the same nominal head type
259268
let HaveSameHeadType g ty1 ty2 =
260-
isAppTy g ty1 && isAppTy g ty2 &&
261-
tyconRefEq g (tcrefOfAppTy g ty1) (tcrefOfAppTy g ty2)
269+
match tryTcrefOfAppTy g ty1 with
270+
| ValueSome tcref1 ->
271+
match tryTcrefOfAppTy g ty2 with
272+
| ValueSome tcref2 -> tyconRefEq g tcref1 tcref2
273+
| _ -> false
274+
| _ -> false
262275

263276
/// Check if a type has a particular head type
264277
let HasHeadType g tcref ty2 =
265-
isAppTy g ty2 &&
266-
tyconRefEq g tcref (tcrefOfAppTy g ty2)
267-
278+
match tryTcrefOfAppTy g ty2 with
279+
| ValueSome tcref2 -> tyconRefEq g tcref tcref2
280+
| ValueNone -> false
268281

269282
/// Check if a type exists somewhere in the hierarchy which has the same head type as the given type (note, the given type need not have a head type at all)
270283
let ExistsSameHeadTypeInHierarchy g amap m typeToSearchFrom typeToLookFor =

0 commit comments

Comments
 (0)