Skip to content

Commit e1e4d6a

Browse files
dotnet-botdsyme
andauthored
Merge main to release/dev17.3 (#13213)
* update fantomas (#13206) * Format most of FSharp.Core (#13150) * modify fantomasignore * fix setting * no single line functions in FSHarp.Core * update fantomas * apply formatting * Format src/Compiler/Driver (#13195) * adjust settings * adjust code * adjust settings * adjust code * fix code before formatting * remove unnecessary yield * manual pre-formatting * preadjust code * preadjust code * preadjust code * preadjust code * adjust settings" * adjust settings" * adjust settings * adjust settings * fix build * adjust settings * adjust code * adjust code * adjust code * update fantomas * apply formatting * apply formatting (fix build) (#13209) * preformat * apply formatting Co-authored-by: Don Syme <[email protected]>
1 parent ad3e6de commit e1e4d6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+18828
-12438
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"fantomas": {
6-
"version": "5.0.0-alpha-006",
6+
"version": "5.0.0-alpha-008",
77
"commands": [
88
"fantomas"
99
]

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
root = true
22

3+
# max_line_length is set to 140. At some point we will reduce it to 120 for as many files as reasonable.
34
[*.fs]
45
max_line_length=140
56
fsharp_newline_between_type_definition_and_members=true
7+
fsharp_max_function_binding_width=40
8+
fsharp_max_if_then_else_short_width=60
69
fsharp_max_infix_operator_expression=80
710
fsharp_max_array_or_list_width=80
811
fsharp_max_array_or_list_number_of_items=5
@@ -13,3 +16,13 @@ fsharp_keep_max_number_of_blank_lines=1
1316
[*.fsi]
1417
fsharp_newline_between_type_definition_and_members=true
1518
fsharp_keep_max_number_of_blank_lines=1
19+
20+
# These files contains many imperative if-then expressions which are not clearer on one line
21+
# Reducing fsharp_max_if_then_else_short_width back to its default formats these over multiple lines.
22+
[src/FSharp.Build/*.fs]
23+
fsharp_max_if_then_else_short_width=40
24+
25+
# This file contains a long list of one-line function definitions. Increasing
26+
# fsharp_max_function_binding_width formats these over a single line.
27+
[src/Compiler/Driver/CompilerDiagnostics.fs]
28+
fsharp_max_function_binding_width=70

.fantomasignore

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ artifacts/
1313

1414
# Explicitly unformatted implementation files
1515

16-
src/FSharp.Core/**/*.fs
1716
src/Compiler/Checking/**/*.fs
1817
src/Compiler/CodeGen/**/*.fs
1918
src/Compiler/DependencyManager/**/*.fs
20-
src/Compiler/Driver/**/*.fs
2119
src/Compiler/Facilities/**/*.fs
2220
src/Compiler/Interactive/**/*.fs
2321
src/Compiler/Legacy/**/*.fs
@@ -28,6 +26,23 @@ src/Compiler/SyntaxTree/**/*.fs
2826
src/Compiler/TypedTree/**/*.fs
2927
src/Microsoft.FSharp.Compiler/**/*.fs
3028

29+
# Fantomas limitations on implementation files in FSharp.Core (to investigate)
30+
31+
src/FSharp.Core/array2.fs
32+
src/FSharp.Core/array3.fs
33+
src/FSharp.Core/Linq.fs
34+
src/FSharp.Core/local.fs
35+
src/FSharp.Core/nativeptr.fs
36+
src/FSharp.Core/prim-types-prelude.fs
37+
src/FSharp.Core/prim-types.fs
38+
src/FSharp.Core/printf.fs
39+
src/FSharp.Core/Query.fs
40+
src/FSharp.Core/seqcore.fs
41+
42+
# Fantomas limitation https://github.com/fsprojects/fantomas/issues/2264
43+
44+
src/FSharp.Core/SI.fs
45+
3146
# Fantomas limitations on implementation files (to investigate)
3247

3348
src/Compiler/AbstractIL/ilwrite.fs

src/Compiler/AbstractIL/il.fs

Lines changed: 36 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ open Internal.Utilities
2525

2626
let logging = false
2727

28-
let _ =
29-
if logging then
30-
dprintn "* warning: Il.logging is on"
28+
let _ = if logging then dprintn "* warning: Il.logging is on"
3129

3230
let int_order = LanguagePrimitives.FastGenericComparer<int>
3331

@@ -70,19 +68,13 @@ let memoizeNamespaceRightTable =
7068
let memoizeNamespacePartTable = ConcurrentDictionary<string, string>()
7169

7270
let splitNameAt (nm: string) idx =
73-
if idx < 0 then
74-
failwith "splitNameAt: idx < 0"
71+
if idx < 0 then failwith "splitNameAt: idx < 0"
7572

7673
let last = nm.Length - 1
7774

78-
if idx > last then
79-
failwith "splitNameAt: idx > last"
75+
if idx > last then failwith "splitNameAt: idx > last"
8076

81-
(nm.Substring(0, idx)),
82-
(if idx < last then
83-
nm.Substring(idx + 1, last - idx)
84-
else
85-
"")
77+
(nm.Substring(0, idx)), (if idx < last then nm.Substring(idx + 1, last - idx) else "")
8678

8779
let rec splitNamespaceAux (nm: string) =
8880
match nm.IndexOf '.' with
@@ -218,14 +210,10 @@ module SHA1 =
218210
let inline (>>>&) (x: int) (y: int) = int32 (uint32 x >>> y)
219211

220212
let f (t, b, c, d) =
221-
if t < 20 then
222-
(b &&& c) ||| ((~~~b) &&& d)
223-
elif t < 40 then
224-
b ^^^ c ^^^ d
225-
elif t < 60 then
226-
(b &&& c) ||| (b &&& d) ||| (c &&& d)
227-
else
228-
b ^^^ c ^^^ d
213+
if t < 20 then (b &&& c) ||| ((~~~b) &&& d)
214+
elif t < 40 then b ^^^ c ^^^ d
215+
elif t < 60 then (b &&& c) ||| (b &&& d) ||| (c &&& d)
216+
else b ^^^ c ^^^ d
229217

230218
[<Literal>]
231219
let k0to19 = 0x5A827999
@@ -563,8 +551,7 @@ type ILAssemblyRef(data) =
563551
addC (convDigit (int32 v / 16))
564552
addC (convDigit (int32 v % 16))
565553
// retargetable can be true only for system assemblies that definitely have Version
566-
if aref.Retargetable then
567-
add ", Retargetable=Yes"
554+
if aref.Retargetable then add ", Retargetable=Yes"
568555

569556
b.ToString()
570557

@@ -773,17 +760,9 @@ type ILTypeRef =
773760
else
774761
y.ApproxId
775762

776-
let xScope =
777-
if isPrimaryX then
778-
primaryScopeRef
779-
else
780-
x.Scope
763+
let xScope = if isPrimaryX then primaryScopeRef else x.Scope
781764

782-
let yScope =
783-
if isPrimaryY then
784-
primaryScopeRef
785-
else
786-
y.Scope
765+
let yScope = if isPrimaryY then primaryScopeRef else y.Scope
787766

788767
(xApproxId = yApproxId)
789768
&& (xScope = yScope)
@@ -806,10 +785,7 @@ type ILTypeRef =
806785
else
807786
let c = compare x.Name y.Name
808787

809-
if c <> 0 then
810-
c
811-
else
812-
compare x.Enclosing y.Enclosing
788+
if c <> 0 then c else compare x.Enclosing y.Enclosing
813789

814790
member tref.FullName = String.concat "." (tref.Enclosing @ [ tref.Name ])
815791

@@ -883,11 +859,7 @@ and [<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugT
883859
&& (x.GenericArgs = y.GenericArgs)
884860

885861
override x.ToString() =
886-
x.TypeRef.ToString()
887-
+ if isNil x.GenericArgs then
888-
""
889-
else
890-
"<...>"
862+
x.TypeRef.ToString() + if isNil x.GenericArgs then "" else "<...>"
891863

892864
and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>] ILType =
893865
| Void
@@ -1859,20 +1831,13 @@ type ILGenericParameterDefs = ILGenericParameterDef list
18591831
let memberAccessOfFlags flags =
18601832
let f = (flags &&& 0x00000007)
18611833

1862-
if f = 0x00000001 then
1863-
ILMemberAccess.Private
1864-
elif f = 0x00000006 then
1865-
ILMemberAccess.Public
1866-
elif f = 0x00000004 then
1867-
ILMemberAccess.Family
1868-
elif f = 0x00000002 then
1869-
ILMemberAccess.FamilyAndAssembly
1870-
elif f = 0x00000005 then
1871-
ILMemberAccess.FamilyOrAssembly
1872-
elif f = 0x00000003 then
1873-
ILMemberAccess.Assembly
1874-
else
1875-
ILMemberAccess.CompilerControlled
1834+
if f = 0x00000001 then ILMemberAccess.Private
1835+
elif f = 0x00000006 then ILMemberAccess.Public
1836+
elif f = 0x00000004 then ILMemberAccess.Family
1837+
elif f = 0x00000002 then ILMemberAccess.FamilyAndAssembly
1838+
elif f = 0x00000005 then ILMemberAccess.FamilyOrAssembly
1839+
elif f = 0x00000003 then ILMemberAccess.Assembly
1840+
else ILMemberAccess.CompilerControlled
18761841

18771842
let convertMemberAccess (ilMemberAccess: ILMemberAccess) =
18781843
match ilMemberAccess with
@@ -2509,12 +2474,9 @@ let typeAccessOfFlags flags =
25092474
let typeEncodingOfFlags flags =
25102475
let f = (flags &&& 0x00030000)
25112476

2512-
if f = 0x00020000 then
2513-
ILDefaultPInvokeEncoding.Auto
2514-
elif f = 0x00010000 then
2515-
ILDefaultPInvokeEncoding.Unicode
2516-
else
2517-
ILDefaultPInvokeEncoding.Ansi
2477+
if f = 0x00020000 then ILDefaultPInvokeEncoding.Auto
2478+
elif f = 0x00010000 then ILDefaultPInvokeEncoding.Unicode
2479+
else ILDefaultPInvokeEncoding.Ansi
25182480

25192481
[<RequireQualifiedAccess>]
25202482
type ILTypeDefKind =
@@ -3613,32 +3575,20 @@ and rescopeILType scoref ty =
36133575
| ILType.Boxed cr1 ->
36143576
let cr2 = rescopeILTypeSpec scoref cr1
36153577

3616-
if cr1 === cr2 then
3617-
ty
3618-
else
3619-
mkILBoxedType cr2
3578+
if cr1 === cr2 then ty else mkILBoxedType cr2
36203579
| ILType.Array (s, ety1) ->
36213580
let ety2 = rescopeILType scoref ety1
36223581

3623-
if ety1 === ety2 then
3624-
ty
3625-
else
3626-
ILType.Array(s, ety2)
3582+
if ety1 === ety2 then ty else ILType.Array(s, ety2)
36273583
| ILType.Value cr1 ->
36283584
let cr2 = rescopeILTypeSpec scoref cr1
36293585

3630-
if cr1 === cr2 then
3631-
ty
3632-
else
3633-
ILType.Value cr2
3586+
if cr1 === cr2 then ty else ILType.Value cr2
36343587
| ILType.Modified (b, tref, ty) -> ILType.Modified(b, rescopeILTypeRef scoref tref, rescopeILType scoref ty)
36353588
| x -> x
36363589

36373590
and rescopeILTypes scoref i =
3638-
if isNil i then
3639-
i
3640-
else
3641-
List.mapq (rescopeILType scoref) i
3591+
if isNil i then i else List.mapq (rescopeILType scoref) i
36423592

36433593
and rescopeILCallSig scoref csig =
36443594
mkILCallSig (csig.CallingConv, rescopeILTypes scoref csig.ArgTypes, rescopeILType scoref csig.ReturnType)
@@ -3933,13 +3883,7 @@ let prependInstrsToCode (instrs: ILInstr list) (c2: ILCode) =
39333883
let dict = Dictionary.newWithSize c2.Labels.Count
39343884

39353885
for kvp in c2.Labels do
3936-
dict.Add(
3937-
kvp.Key,
3938-
if kvp.Value = 0 then
3939-
0
3940-
else
3941-
kvp.Value + n
3942-
)
3886+
dict.Add(kvp.Key, (if kvp.Value = 0 then 0 else kvp.Value + n))
39433887

39443888
dict
39453889

@@ -4013,22 +3957,10 @@ let mkILField (isStatic, nm, ty, init: ILFieldInit option, at: byte[] option, ac
40133957
fieldType = ty,
40143958
attributes =
40153959
(convertFieldAccess access
4016-
||| (if isStatic then
4017-
FieldAttributes.Static
4018-
else
4019-
enum 0)
4020-
||| (if isLiteral then
4021-
FieldAttributes.Literal
4022-
else
4023-
enum 0)
4024-
||| (if init.IsSome then
4025-
FieldAttributes.HasDefault
4026-
else
4027-
enum 0)
4028-
||| (if at.IsSome then
4029-
FieldAttributes.HasFieldRVA
4030-
else
4031-
enum 0)),
3960+
||| (if isStatic then FieldAttributes.Static else enum 0)
3961+
||| (if isLiteral then FieldAttributes.Literal else enum 0)
3962+
||| (if init.IsSome then FieldAttributes.HasDefault else enum 0)
3963+
||| (if at.IsSome then FieldAttributes.HasFieldRVA else enum 0)),
40323964
literalValue = init,
40333965
data = at,
40343966
offset = None,
@@ -4362,12 +4294,7 @@ let mkCtorMethSpecForDelegate (ilg: ILGlobals) (ty: ILType, useUIntPtr) =
43624294
let argTys =
43634295
[
43644296
rescopeILType scoref ilg.typ_Object
4365-
rescopeILType
4366-
scoref
4367-
(if useUIntPtr then
4368-
ilg.typ_UIntPtr
4369-
else
4370-
ilg.typ_IntPtr)
4297+
rescopeILType scoref (if useUIntPtr then ilg.typ_UIntPtr else ilg.typ_IntPtr)
43714298
]
43724299

43734300
mkILInstanceMethSpecInTy (ty, ".ctor", argTys, ILType.Void, emptyILGenericArgsList)
@@ -5143,8 +5070,8 @@ let decodeILAttribData (ca: ILAttribute) =
51435070
try
51445071
let parser = ILTypeSigParser n
51455072
parser.ParseTypeSpec(), sigptr
5146-
with
5147-
| exn -> failwith (sprintf "decodeILAttribData: error parsing type in custom attribute blob: %s" exn.Message)
5073+
with exn ->
5074+
failwith (sprintf "decodeILAttribData: error parsing type in custom attribute blob: %s" exn.Message)
51485075
| ILType.Boxed tspec when tspec.Name = "System.Object" ->
51495076
let et, sigptr = sigptr_get_u8 bytes sigptr
51505077

@@ -5605,10 +5532,7 @@ and unscopeILType ty =
56055532
| x -> x
56065533

56075534
and unscopeILTypes i =
5608-
if List.isEmpty i then
5609-
i
5610-
else
5611-
List.map unscopeILType i
5535+
if List.isEmpty i then i else List.map unscopeILType i
56125536

56135537
and unscopeILCallSig csig =
56145538
mkILCallSig (csig.CallingConv, unscopeILTypes csig.ArgTypes, unscopeILType csig.ReturnType)

src/Compiler/AbstractIL/ilmorph.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ let cattr_ty2ty f (c: ILAttribute) =
184184
let elems = elems |> List.map (celem_ty2ty f)
185185
let namedArgs = namedArgs |> List.map (cnamedarg_ty2ty f)
186186
mkILCustomAttribMethRef (meth, elems, namedArgs)
187-
with
188-
| _ -> c.WithMethod(meth)
187+
with _ ->
188+
c.WithMethod(meth)
189189
else
190190
c.WithMethod(meth)
191191

0 commit comments

Comments
 (0)