Skip to content

Commit d7274c6

Browse files
forkidsyme
authored andcommitted
Clean up illib (#4428)
* clean option module in illib * Update NicePrint.fs * Update NicePrint.fs * Update NicePrint.fs * Update NicePrint.fs * Update NicePrint.fs
1 parent 3fb44a4 commit d7274c6

File tree

5 files changed

+22
-61
lines changed

5 files changed

+22
-61
lines changed

src/absil/illib.fs

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ let inline isSingleton l =
3737

3838
let inline isNonNull x = not (isNull x)
3939
let inline nonNull msg x = if isNull x then failwith ("null: " ^ msg) else x
40-
let (===) x y = LanguagePrimitives.PhysicalEquality x y
40+
let inline (===) x y = LanguagePrimitives.PhysicalEquality x y
4141

4242
//---------------------------------------------------------------------
4343
// Library: ReportTime
4444
//---------------------------------------------------------------------
4545
let reportTime =
46-
let tFirst = ref None
47-
let tPrev = ref None
46+
let tFirst = ref None
47+
let tPrev = ref None
4848
fun showTimes descr ->
4949
if showTimes then
5050
let t = System.Diagnostics.Process.GetCurrentProcess().UserProcessorTime.TotalSeconds
@@ -237,36 +237,12 @@ module Option =
237237
let mapFold f s opt =
238238
match opt with
239239
| None -> None,s
240-
| Some x -> let x',s' = f s x in Some x',s'
241-
242-
let otherwise opt dflt =
243-
match opt with
244-
| None -> dflt
245-
| Some x -> x
246-
247-
let fold f z x =
248-
match x with
249-
| None -> z
250-
| Some x -> f z x
251-
252-
let attempt (f: unit -> 'T) = try Some (f()) with _ -> None
253-
254-
255-
let orElseWith f opt =
256-
match opt with
257-
| None -> f()
258-
| x -> x
259-
260-
let orElse v opt =
261-
match opt with
262-
| None -> v
263-
| x -> x
264-
265-
let defaultValue v opt =
266-
match opt with
267-
| None -> v
268-
| Some x -> x
240+
| Some x ->
241+
let x',s' = f s x
242+
Some x',s'
269243

244+
let attempt (f: unit -> 'T) = try Some (f()) with _ -> None
245+
270246
module List =
271247

272248
//let item n xs = List.nth xs n
@@ -442,9 +418,6 @@ module List =
442418
| x::xs -> if i=n then f x::xs else x::mn (i+1) xs
443419

444420
mn 0 xs
445-
446-
let rec until p l = match l with [] -> [] | h::t -> if p h then [] else h :: until p t
447-
448421
let count pred xs = List.fold (fun n x -> if pred x then n+1 else n) 0 xs
449422

450423
// WARNING: not tail-recursive
@@ -521,23 +494,9 @@ module String =
521494
if s.Length = 0 then s
522495
else lowercase s.[0..0] + s.[ 1.. s.Length - 1 ]
523496

497+
let dropPrefix (s:string) (t:string) = s.[t.Length..s.Length - 1]
524498

525-
let tryDropPrefix (s:string) (t:string) =
526-
if s.StartsWith t then
527-
Some s.[t.Length..s.Length - 1]
528-
else
529-
None
530-
531-
let tryDropSuffix (s:string) (t:string) =
532-
if s.EndsWith t then
533-
Some s.[0..s.Length - t.Length - 1]
534-
else
535-
None
536-
537-
let hasPrefix s t = Option.isSome (tryDropPrefix s t)
538-
let dropPrefix s t = match (tryDropPrefix s t) with Some(res) -> res | None -> failwith "dropPrefix"
539-
540-
let dropSuffix s t = match (tryDropSuffix s t) with Some(res) -> res | None -> failwith "dropSuffix"
499+
let dropSuffix (s:string) (t:string) = s.[0..s.Length - t.Length - 1]
541500

542501
open System
543502
open System.IO

src/fsharp/NicePrint.fs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ module internal PrintUtilities =
7171
tcref.DisplayName // has no static params
7272
else
7373
tcref.DisplayName+"<...>" // shorten
74-
if isAttribute then
75-
defaultArg (String.tryDropSuffix name "Attribute") name
76-
else name
74+
if isAttribute && name.EndsWith "Attribute" then
75+
String.dropSuffix name "Attribute"
76+
else
77+
name
7778
let tyconTextL =
7879
tagEntityRefName tcref demangled
7980
|> mkNav tcref.DefinitionRange
@@ -654,9 +655,10 @@ module private PrintTypes =
654655
| ILAttrib ilMethRef ->
655656
let trimmedName =
656657
let name = ilMethRef.DeclaringTypeRef.Name
657-
match String.tryDropSuffix name "Attribute" with
658-
| Some shortName -> shortName
659-
| None -> name
658+
if name.EndsWith "Attribute" then
659+
String.dropSuffix name "Attribute"
660+
else
661+
name
660662
let tref = ilMethRef.DeclaringTypeRef
661663
let tref = ILTypeRef.Create(scope= tref.Scope, enclosing=tref.Enclosing, name=trimmedName)
662664
PrintIL.layoutILTypeRef denv tref ++ argsL
@@ -1275,7 +1277,7 @@ module InfoMemberPrinting =
12751277
let paramDatas = minfo.GetParamDatas(amap, m, minst)
12761278
let layout =
12771279
layout ^^
1278-
if isNil (List.concat paramDatas) then
1280+
if List.forall isNil paramDatas then
12791281
WordL.structUnit
12801282
else
12811283
sepListL WordL.arrow (List.map ((List.map (layoutParamData denv)) >> sepListL WordL.star) paramDatas)

src/fsharp/TastOps.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ let tryDestRefTupleTy g ty =
14511451
type UncurriedArgInfos = (TType * ArgReprInfo) list
14521452
type CurriedArgInfos = (TType * ArgReprInfo) list list
14531453

1454-
// A 'tau' type is one with its type paramaeters stripped off
1454+
// A 'tau' type is one with its type parameters stripped off
14551455
let GetTopTauTypeInFSharpForm g (curriedArgInfos: ArgReprInfo list list) tau m =
14561456
let nArgInfos = curriedArgInfos.Length
14571457
let argtys, rty = stripFunTyN g nArgInfos tau

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5112,7 +5112,7 @@ and TcPatBindingName cenv env id ty isMemberThis vis1 topValData (inlineFlag, de
51125112
// isLeftMost indicates we are processing the left-most path through a disjunctive or pattern.
51135113
// For those binding locations, CallNameResolutionSink is called in MakeAndPublishValue, like all other bindings
51145114
// For non-left-most paths, we register the name resolutions here
5115-
if not isLeftMost && not vspec.IsCompilerGenerated && not (String.hasPrefix vspec.LogicalName "_") then
5115+
if not isLeftMost && not vspec.IsCompilerGenerated && not (vspec.LogicalName.StartsWith "_") then
51165116
let item = Item.Value(mkLocalValRef vspec)
51175117
CallNameResolutionSink cenv.tcSink (id.idRange, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights)
51185118

src/fsharp/ast.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type XmlDoc =
100100
| (lineA::rest) as lines ->
101101
let lineAT = lineA.TrimStart([|' '|])
102102
if lineAT = "" then processLines rest
103-
else if String.hasPrefix lineAT "<" then lines
103+
else if lineAT.StartsWith "<" then lines
104104
else ["<summary>"] @
105105
(lines |> List.map (fun line -> Microsoft.FSharp.Core.XmlAdapters.escape(line))) @
106106
["</summary>"]

0 commit comments

Comments
 (0)