Skip to content

Commit

Permalink
Avoid to stripTyEqns multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 25, 2016
1 parent 3fa05c5 commit b4f999e
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/fsharp/TastOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,10 @@ let isProvenUnionCaseTy ty = match ty with TType_ucase _ -> true | _ -> false

let mkAppTy tcref tyargs = TType_app(tcref,tyargs)
let mkProvenUnionCaseTy ucref tyargs = TType_ucase(ucref,tyargs)

let isAppTy g ty = ty |> stripTyEqns g |> (function TType_app _ -> true | _ -> false)
let destAppTy g ty = ty |> stripTyEqns g |> (function TType_app(tcref,tinst) -> tcref,tinst | _ -> failwith "destAppTy")

let tcrefOfAppTy g ty = ty |> stripTyEqns g |> (function TType_app(tcref,_) -> tcref | _ -> failwith "tcrefOfAppTy")
let tryDestAppTy g ty = ty |> stripTyEqns g |> (function TType_app(tcref,_) -> Some tcref | _ -> None)
let (|AppTy|_|) g ty = ty |> stripTyEqns g |> (function TType_app(tcref,tinst) -> Some (tcref,tinst) | _ -> None)
Expand Down Expand Up @@ -736,11 +738,10 @@ let (|ByrefTy|_|) g ty =
| AppTy g (tcr,[tyarg]) when tyconRefEq g tcr g.byref_tcr -> Some tyarg
| _ -> None

let mkInstForAppTy g typ =
if isAppTy g typ then
let tcref,tinst = destAppTy g typ
mkTyconRefInst tcref tinst
else []
let mkInstForAppTy g typ =
match stripTyEqns g typ with
| TType_app(tcref,tinst) -> mkTyconRefInst tcref tinst
| _ -> []

let domainOfFunTy g ty = fst(destFunTy g ty)
let rangeOfFunTy g ty = snd(destFunTy g ty)
Expand Down Expand Up @@ -1574,8 +1575,8 @@ let isStructTy g ty =
// [Note: Constructed types and type-parameters are never unmanaged-types. end note]
let rec isUnmanagedTy g ty =
let ty = stripTyEqnsAndMeasureEqns g ty
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
match stripTyEqns g ty with
| TType_app(tcref,_) ->
let isEq tcref2 = tyconRefEq g tcref tcref2
if isEq g.nativeptr_tcr || isEq g.nativeint_tcr ||
isEq g.sbyte_tcr || isEq g.byte_tcr ||
Expand All @@ -1597,7 +1598,7 @@ let rec isUnmanagedTy g ty =
| [] -> tycon.AllInstanceFieldsAsList |> List.forall (fun r -> isUnmanagedTy g r.rfield_type)
| _ -> false // generic structs are never
else false
else
| _ ->
false

let isInterfaceTycon x =
Expand Down Expand Up @@ -5722,7 +5723,11 @@ let mkMinusOne g m = mkInt g m (-1)

let destInt32 = function Expr.Const(Const.Int32 n,_,_) -> Some n | _ -> None

let isIDelegateEventType g ty = isAppTy g ty && tyconRefEq g g.fslib_IDelegateEvent_tcr (tcrefOfAppTy g ty)
let isIDelegateEventType g ty =
match stripTyEqns g ty with
| TType_app(tcref,_) -> tyconRefEq g g.fslib_IDelegateEvent_tcr (tcref)
| _ -> false

let destIDelegateEventType g ty =
if isIDelegateEventType g ty then
match argsOfAppTy g ty with
Expand Down Expand Up @@ -6926,14 +6931,18 @@ let TypeNullNever g ty =
let TypeNullIsExtraValue g m ty =
if isILReferenceTy g ty || isDelegateTy g ty then
// Putting AllowNullLiteralAttribute(false) on an IL or provided type means 'null' can't be used with that type
not (isAppTy g ty && TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute (tcrefOfAppTy g ty) = Some(false))
match stripTyEqns g ty with
| TType_app(tcref,_) -> TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute tcref <> Some(false)
| _ -> true
elif TypeNullNever g ty then
false
else
// Putting AllowNullLiteralAttribute(true) on an F# type means 'null' can be used with that type
isAppTy g ty && TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute (tcrefOfAppTy g ty) = Some(true)
match stripTyEqns g ty with
| TType_app(tcref,_) -> TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute tcref = Some(true)
| _ -> false

let TypeNullIsTrueValue g ty =
let TypeNullIsTrueValue g ty =
(isAppTy g ty && IsUnionTypeWithNullAsTrueValue g (tyconOfAppTy g ty)) ||
(isUnitTy g ty)

Expand Down Expand Up @@ -6970,16 +6979,16 @@ let rec TypeHasDefaultValue g m ty =
let (|SpecialComparableHeadType|_|) g ty =
if isTupleTy g ty then
Some (destTupleTy g ty)
elif isAppTy g ty then
let tcref,tinst = destAppTy g ty
if isArrayTyconRef g tcref ||
tyconRefEq g tcref g.system_UIntPtr_tcref ||
tyconRefEq g tcref g.system_IntPtr_tcref then
Some tinst
else
None
else
None
match stripTyEqns g ty with
| TType_app(tcref,tinst) ->
if isArrayTyconRef g tcref ||
tyconRefEq g tcref g.system_UIntPtr_tcref ||
tyconRefEq g tcref g.system_IntPtr_tcref then
Some tinst
else
None
| _ -> None

let (|SpecialEquatableHeadType|_|) g ty = (|SpecialComparableHeadType|_|) g ty
let (|SpecialNotEquatableHeadType|_|) g ty =
Expand Down

0 comments on commit b4f999e

Please sign in to comment.