From 6f39e77a972e6f4d7c6ca7cd4c7c9b22eb60c420 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 4 Mar 2018 18:31:27 +0100 Subject: [PATCH 1/6] clean option module in illib --- src/absil/illib.fs | 61 +++++++-------------------------------- src/fsharp/NicePrint.fs | 16 +++++----- src/fsharp/TastOps.fs | 2 +- src/fsharp/TypeChecker.fs | 2 +- src/fsharp/ast.fs | 2 +- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/absil/illib.fs b/src/absil/illib.fs index a19497e8c56..2e97b0ab88c 100644 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -37,14 +37,14 @@ let inline isSingleton l = let inline isNonNull x = not (isNull x) let inline nonNull msg x = if isNull x then failwith ("null: " ^ msg) else x -let (===) x y = LanguagePrimitives.PhysicalEquality x y +let inline (===) x y = LanguagePrimitives.PhysicalEquality x y //--------------------------------------------------------------------- // Library: ReportTime //--------------------------------------------------------------------- let reportTime = - let tFirst = ref None - let tPrev = ref None + let tFirst = ref None + let tPrev = ref None fun showTimes descr -> if showTimes then let t = System.Diagnostics.Process.GetCurrentProcess().UserProcessorTime.TotalSeconds @@ -237,36 +237,12 @@ module Option = let mapFold f s opt = match opt with | None -> None,s - | Some x -> let x',s' = f s x in Some x',s' - - let otherwise opt dflt = - match opt with - | None -> dflt - | Some x -> x - - let fold f z x = - match x with - | None -> z - | Some x -> f z x - - let attempt (f: unit -> 'T) = try Some (f()) with _ -> None - - - let orElseWith f opt = - match opt with - | None -> f() - | x -> x - - let orElse v opt = - match opt with - | None -> v - | x -> x - - let defaultValue v opt = - match opt with - | None -> v - | Some x -> x + | Some x -> + let x',s' = f s x + Some x',s' + let attempt (f: unit -> 'T) = try Some (f()) with _ -> None + module List = //let item n xs = List.nth xs n @@ -442,9 +418,6 @@ module List = | x::xs -> if i=n then f x::xs else x::mn (i+1) xs mn 0 xs - - let rec until p l = match l with [] -> [] | h::t -> if p h then [] else h :: until p t - let count pred xs = List.fold (fun n x -> if pred x then n+1 else n) 0 xs // WARNING: not tail-recursive @@ -521,23 +494,9 @@ module String = if s.Length = 0 then s else lowercase s.[0..0] + s.[ 1.. s.Length - 1 ] + let dropPrefix (s:string) (t:string) = s.[t.Length..s.Length - 1] - let tryDropPrefix (s:string) (t:string) = - if s.StartsWith t then - Some s.[t.Length..s.Length - 1] - else - None - - let tryDropSuffix (s:string) (t:string) = - if s.EndsWith t then - Some s.[0..s.Length - t.Length - 1] - else - None - - let hasPrefix s t = Option.isSome (tryDropPrefix s t) - let dropPrefix s t = match (tryDropPrefix s t) with Some(res) -> res | None -> failwith "dropPrefix" - - let dropSuffix s t = match (tryDropSuffix s t) with Some(res) -> res | None -> failwith "dropSuffix" + let dropSuffix (s:string) (t:string) = s.[0..s.Length - t.Length - 1] open System open System.IO diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index 519cca8f3fe..e66588bdd2f 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -71,9 +71,10 @@ module internal PrintUtilities = tcref.DisplayName // has no static params else tcref.DisplayName+"<...>" // shorten - if isAttribute then - defaultArg (String.tryDropSuffix name "Attribute") name - else name + if isAttribute && name.EndsWith "Attribute" then + String.dropSuffix name "Attribute" + else + name let tyconTextL = tagEntityRefName tcref demangled |> mkNav tcref.DefinitionRange @@ -654,9 +655,10 @@ module private PrintTypes = | ILAttrib ilMethRef -> let trimmedName = let name = ilMethRef.DeclaringTypeRef.Name - match String.tryDropSuffix name "Attribute" with - | Some shortName -> shortName - | None -> name + if name.EndsWith "Attribute" then + String.dropSuffix name "Attribute" + else + name let tref = ilMethRef.DeclaringTypeRef let tref = ILTypeRef.Create(scope= tref.Scope, enclosing=tref.Enclosing, name=trimmedName) PrintIL.layoutILTypeRef denv tref ++ argsL @@ -1275,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if isNil (List.concat paramDatas) then + if Seq.isEmpty (Seq.concat paramDatas) then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas) diff --git a/src/fsharp/TastOps.fs b/src/fsharp/TastOps.fs index 6500430ed20..a5f59868f54 100644 --- a/src/fsharp/TastOps.fs +++ b/src/fsharp/TastOps.fs @@ -1451,7 +1451,7 @@ let tryDestRefTupleTy g ty = type UncurriedArgInfos = (TType * ArgReprInfo) list type CurriedArgInfos = (TType * ArgReprInfo) list list -// A 'tau' type is one with its type paramaeters stripped off +// A 'tau' type is one with its type parameters stripped off let GetTopTauTypeInFSharpForm g (curriedArgInfos: ArgReprInfo list list) tau m = let nArgInfos = curriedArgInfos.Length let argtys, rty = stripFunTyN g nArgInfos tau diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 3a1fa009c4f..4ec8d3a3d96 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -5107,7 +5107,7 @@ and TcPatBindingName cenv env id ty isMemberThis vis1 topValData (inlineFlag, de // isLeftMost indicates we are processing the left-most path through a disjunctive or pattern. // For those binding locations, CallNameResolutionSink is called in MakeAndPublishValue, like all other bindings // For non-left-most paths, we register the name resolutions here - if not isLeftMost && not vspec.IsCompilerGenerated && not (String.hasPrefix vspec.LogicalName "_") then + if not isLeftMost && not vspec.IsCompilerGenerated && not (vspec.LogicalName.StartsWith "_") then let item = Item.Value(mkLocalValRef vspec) CallNameResolutionSink cenv.tcSink (id.idRange, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights) diff --git a/src/fsharp/ast.fs b/src/fsharp/ast.fs index 2444a699a81..1963b00ed34 100644 --- a/src/fsharp/ast.fs +++ b/src/fsharp/ast.fs @@ -100,7 +100,7 @@ type XmlDoc = | (lineA::rest) as lines -> let lineAT = lineA.TrimStart([|' '|]) if lineAT = "" then processLines rest - else if String.hasPrefix lineAT "<" then lines + else if lineAT.StartsWith "<" then lines else [""] @ (lines |> List.map (fun line -> Microsoft.FSharp.Core.XmlAdapters.escape(line))) @ [""] From d3dcbfd405f8668b27ce7355e2df7014aaf4301a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 10 Mar 2018 10:06:56 +0100 Subject: [PATCH 2/6] Update NicePrint.fs --- src/fsharp/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index e66588bdd2f..acc168f9edc 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -1277,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if Seq.isEmpty (Seq.concat paramDatas) then + if not (List.exists (isNil >> not) paramDatas) then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas) From 0c1d8787a7584f276cf8f258e937d04866ccde8c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 10 Mar 2018 10:12:36 +0100 Subject: [PATCH 3/6] Update NicePrint.fs --- src/fsharp/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index acc168f9edc..cec34bf7727 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -1277,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if not (List.exists (isNil >> not) paramDatas) then + if List.forAll sNil paramDatas) then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas) From 5cffa9ce5b1bd6de47664e677f8de8418ac0fb8a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 10 Mar 2018 10:25:33 +0100 Subject: [PATCH 4/6] Update NicePrint.fs --- src/fsharp/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index cec34bf7727..b4c3964ba80 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -1277,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if List.forAll sNil paramDatas) then + if List.forAll sNil paramDatas then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas) From e2e03ccc92f8553f7dcdaa41694e4d562ac54d26 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 10 Mar 2018 10:31:14 +0100 Subject: [PATCH 5/6] Update NicePrint.fs --- src/fsharp/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index b4c3964ba80..98be3a90f25 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -1277,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if List.forAll sNil paramDatas then + if List.forall sNil paramDatas then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas) From 8c19fb98dc1889669719142992c368f44cdb425c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 10 Mar 2018 10:40:46 +0100 Subject: [PATCH 6/6] Update NicePrint.fs --- src/fsharp/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/NicePrint.fs b/src/fsharp/NicePrint.fs index 98be3a90f25..d3116650608 100755 --- a/src/fsharp/NicePrint.fs +++ b/src/fsharp/NicePrint.fs @@ -1277,7 +1277,7 @@ module InfoMemberPrinting = let paramDatas = minfo.GetParamDatas(amap, m, minst) let layout = layout ^^ - if List.forall sNil paramDatas then + if List.forall isNil paramDatas then WordL.structUnit else sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas)