diff --git a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj index 55283b0065d..8d09c3a26f1 100644 --- a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj +++ b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj @@ -72,7 +72,7 @@ - + diff --git a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj index 54ca43c2cf4..a16f39b084c 100644 --- a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj +++ b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj @@ -1,4 +1,4 @@ - + $(MSBuildProjectDirectory)\..\..\src @@ -635,7 +635,7 @@ - + diff --git a/src/absil/illib.fs b/src/absil/illib.fs index b9ec8eaee68..55631794bc4 100644 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -432,18 +432,12 @@ module List = let existsSquared f xss = xss |> List.exists (fun xs -> xs |> List.exists (fun x -> f x)) let mapiFoldSquared f z xss = mapFoldSquared f z (xss |> mapiSquared (fun i j x -> (i,j,x))) -[] -type ValueOption<'T> = - | ValueSome of 'T - | ValueNone - member x.IsSome = match x with ValueSome _ -> true | ValueNone -> false - member x.IsNone = match x with ValueSome _ -> false | ValueNone -> true - member x.Value = match x with ValueSome r -> r | ValueNone -> failwith "ValueOption.Value: value is None" - [] module ValueOption = let inline ofOption x = match x with Some x -> ValueSome x | None -> ValueNone let inline bind f x = match x with ValueSome x -> f x | ValueNone -> ValueNone + let inline isSome x = match x with ValueSome _ -> true | ValueNone -> false + let inline isNone x = match x with ValueSome _ -> false | ValueNone -> true type String with member inline x.StartsWithOrdinal(value) = diff --git a/src/fsharp/NameResolution.fs b/src/fsharp/NameResolution.fs index 43f7c297ca6..bea8f403380 100644 --- a/src/fsharp/NameResolution.fs +++ b/src/fsharp/NameResolution.fs @@ -1100,7 +1100,7 @@ let AddEntityForProvidedType (amap: Import.ImportMap, modref: ModuleOrNamespaceR let tycon = Construct.NewProvidedTycon(resolutionEnvironment, st, importProvidedType, isSuppressRelocate, m) modref.ModuleOrNamespaceType.AddProvidedTypeEntity(tycon) let tcref = modref.NestedTyconRef tycon - System.Diagnostics.Debug.Assert modref.TryDeref.IsSome + System.Diagnostics.Debug.Assert(ValueOption.isSome modref.TryDeref) tcref diff --git a/src/fsharp/Optimizer.fs b/src/fsharp/Optimizer.fs index b2baed1a7a4..023961820d6 100644 --- a/src/fsharp/Optimizer.fs +++ b/src/fsharp/Optimizer.fs @@ -3090,7 +3090,7 @@ and OptimizeBinding cenv isRec env (TBind(vref, expr, spBind)) = | None -> false | Some mbrTyconRef -> // Check we can deref system_MarshalByRefObject_tcref. When compiling against the Silverlight mscorlib we can't - if mbrTyconRef.TryDeref.IsSome then + if ValueOption.isSome mbrTyconRef.TryDeref then // Check if this is a subtype of MarshalByRefObject assert (cenv.g.system_MarshalByRefObject_ty.IsSome) ExistsSameHeadTypeInHierarchy cenv.g cenv.amap vref.Range (generalizedTyconRef tcref) cenv.g.system_MarshalByRefObject_ty.Value diff --git a/src/fsharp/QuotationTranslator.fs b/src/fsharp/QuotationTranslator.fs index 9c7bc53e333..d37be61d8d8 100644 --- a/src/fsharp/QuotationTranslator.fs +++ b/src/fsharp/QuotationTranslator.fs @@ -66,7 +66,7 @@ type QuotationGenerationScope = static member ComputeQuotationFormat g = let deserializeExValRef = ValRefForIntrinsic g.deserialize_quoted_FSharp_40_plus_info - if deserializeExValRef.TryDeref.IsSome then + if ValueOption.isSome deserializeExValRef.TryDeref then QuotationSerializationFormat.FSharp_40_Plus else QuotationSerializationFormat.FSharp_20_Plus diff --git a/src/fsharp/symbols/Symbols.fs b/src/fsharp/symbols/Symbols.fs index 00e3c6a303c..104d998fda7 100644 --- a/src/fsharp/symbols/Symbols.fs +++ b/src/fsharp/symbols/Symbols.fs @@ -86,7 +86,7 @@ module Impl = let entityIsUnresolved(entity:EntityRef) = match entity with | ERefNonLocal(NonLocalEntityRef(ccu, _)) -> - ccu.IsUnresolvedReference && entity.TryDeref.IsNone + ccu.IsUnresolvedReference && ValueOption.isNone entity.TryDeref | _ -> false let checkEntityIsResolved(entity:EntityRef) = @@ -754,10 +754,10 @@ and FSharpUnionCase(cenv, v: UnionCaseRef) = let isUnresolved() = - entityIsUnresolved v.TyconRef || v.TryUnionCase.IsNone + entityIsUnresolved v.TyconRef || ValueOption.isNone v.TryUnionCase let checkIsResolved() = checkEntityIsResolved v.TyconRef - if v.TryUnionCase.IsNone then + if ValueOption.isNone v.TryUnionCase then invalidOp (sprintf "The union case '%s' could not be found in the target type" v.CaseName) member __.IsUnresolved = @@ -854,18 +854,18 @@ and FSharpField(cenv: SymbolEnv, d: FSharpFieldData) = let isUnresolved() = entityIsUnresolved d.DeclaringTyconRef || match d with - | RecdOrClass v -> v.TryRecdField.IsNone - | Union (v, _) -> v.TryUnionCase.IsNone + | RecdOrClass v -> ValueOption.isNone v.TryRecdField + | Union (v, _) -> ValueOption.isNone v.TryUnionCase | ILField _ -> false let checkIsResolved() = checkEntityIsResolved d.DeclaringTyconRef match d with | RecdOrClass v -> - if v.TryRecdField.IsNone then + if ValueOption.isNone v.TryRecdField then invalidOp (sprintf "The record field '%s' could not be found in the target type" v.FieldName) | Union (v, _) -> - if v.TryUnionCase.IsNone then + if ValueOption.isNone v.TryUnionCase then invalidOp (sprintf "The union case '%s' could not be found in the target type" v.CaseName) | ILField _ -> () @@ -1331,7 +1331,7 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) = let isUnresolved() = match fsharpInfo() with | None -> false - | Some v -> v.TryDeref.IsNone + | Some v -> ValueOption.isNone v.TryDeref let checkIsResolved() = if isUnresolved() then diff --git a/src/fsharp/tast.fs b/src/fsharp/tast.fs index 726d4d1ee04..b85f5d8bd8a 100644 --- a/src/fsharp/tast.fs +++ b/src/fsharp/tast.fs @@ -3261,7 +3261,7 @@ and ValueSome tcr.binding /// Is the destination assembly available? - member tcr.CanDeref = tcr.TryDeref.IsSome + member tcr.CanDeref = ValueOption.isSome tcr.TryDeref /// Gets the data indicating the compiled representation of a type or module in terms of Abstract IL data structures. member x.CompiledRepresentation = x.Deref.CompiledRepresentation @@ -3812,7 +3812,7 @@ and | None -> error(InternalError(sprintf "union case %s not found in type %s" x.CaseName x.TyconRef.LogicalName, x.TyconRef.Range)) /// Try to dereference the reference - member x.TryUnionCase = x.TyconRef.TryDeref |> ValueOption.bind (fun tcref -> tcref.GetUnionCaseByName x.CaseName |> ValueOption.ofOption) + member x.TryUnionCase = x.TyconRef.TryDeref |> ValueOption.bind (fun tcref -> tcref.GetUnionCaseByName x.CaseName |> ValueOption.ofOption) /// Get the attributes associated with the union case member x.Attribs = x.UnionCase.Attribs @@ -5447,9 +5447,9 @@ let primEntityRefEq compilingFslib fslibCcu (x : EntityRef) (y : EntityRef) = // The tcrefs may have forwarders. If they may possibly be equal then resolve them to get their canonical references // and compare those using pointer equality. (not (nonLocalRefDefinitelyNotEq x.nlr y.nlr) && - let v1 = x.TryDeref - let v2 = y.TryDeref - v1.IsSome && v2.IsSome && v1.Value === v2.Value)) then + match x.TryDeref with + | ValueSome v1 -> match y.TryDeref with ValueSome v2 -> v1 === v2 | _ -> false + | _ -> match y.TryDeref with ValueNone -> true | _ -> false)) then true else compilingFslib && fslibEntityRefEq fslibCcu x y @@ -5473,9 +5473,9 @@ let primValRefEq compilingFslib fslibCcu (x : ValRef) (y : ValRef) = else (// Use TryDeref to guard against the platforms/times when certain F# language features aren't available, // e.g. CompactFramework doesn't have support for quotations. - let v1 = x.TryDeref - let v2 = y.TryDeref - v1.IsSome && v2.IsSome && v1.Value === v2.Value) + match x.TryDeref with + | ValueSome v1 -> match y.TryDeref with ValueSome v2 -> v1 === v2 | _ -> false + | _ -> match y.TryDeref with ValueNone -> true | _ -> false) || (if compilingFslib then fslibValRefEq fslibCcu x y else false) //---------------------------------------------------------------------------