Skip to content

Commit

Permalink
Merge main to release/dev17.3 (#13213)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dotnet-bot and dsyme authored May 31, 2022
1 parent ad3e6de commit e1e4d6a
Show file tree
Hide file tree
Showing 88 changed files with 18,828 additions and 12,438 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fantomas": {
"version": "5.0.0-alpha-006",
"version": "5.0.0-alpha-008",
"commands": [
"fantomas"
]
Expand Down
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
root = true

# max_line_length is set to 140. At some point we will reduce it to 120 for as many files as reasonable.
[*.fs]
max_line_length=140
fsharp_newline_between_type_definition_and_members=true
fsharp_max_function_binding_width=40
fsharp_max_if_then_else_short_width=60
fsharp_max_infix_operator_expression=80
fsharp_max_array_or_list_width=80
fsharp_max_array_or_list_number_of_items=5
Expand All @@ -13,3 +16,13 @@ fsharp_keep_max_number_of_blank_lines=1
[*.fsi]
fsharp_newline_between_type_definition_and_members=true
fsharp_keep_max_number_of_blank_lines=1

# These files contains many imperative if-then expressions which are not clearer on one line
# Reducing fsharp_max_if_then_else_short_width back to its default formats these over multiple lines.
[src/FSharp.Build/*.fs]
fsharp_max_if_then_else_short_width=40

# This file contains a long list of one-line function definitions. Increasing
# fsharp_max_function_binding_width formats these over a single line.
[src/Compiler/Driver/CompilerDiagnostics.fs]
fsharp_max_function_binding_width=70
19 changes: 17 additions & 2 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ artifacts/

# Explicitly unformatted implementation files

src/FSharp.Core/**/*.fs
src/Compiler/Checking/**/*.fs
src/Compiler/CodeGen/**/*.fs
src/Compiler/DependencyManager/**/*.fs
src/Compiler/Driver/**/*.fs
src/Compiler/Facilities/**/*.fs
src/Compiler/Interactive/**/*.fs
src/Compiler/Legacy/**/*.fs
Expand All @@ -28,6 +26,23 @@ src/Compiler/SyntaxTree/**/*.fs
src/Compiler/TypedTree/**/*.fs
src/Microsoft.FSharp.Compiler/**/*.fs

# Fantomas limitations on implementation files in FSharp.Core (to investigate)

src/FSharp.Core/array2.fs
src/FSharp.Core/array3.fs
src/FSharp.Core/Linq.fs
src/FSharp.Core/local.fs
src/FSharp.Core/nativeptr.fs
src/FSharp.Core/prim-types-prelude.fs
src/FSharp.Core/prim-types.fs
src/FSharp.Core/printf.fs
src/FSharp.Core/Query.fs
src/FSharp.Core/seqcore.fs

# Fantomas limitation https://github.com/fsprojects/fantomas/issues/2264

src/FSharp.Core/SI.fs

# Fantomas limitations on implementation files (to investigate)

src/Compiler/AbstractIL/ilwrite.fs
Expand Down
148 changes: 36 additions & 112 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ open Internal.Utilities

let logging = false

let _ =
if logging then
dprintn "* warning: Il.logging is on"
let _ = if logging then dprintn "* warning: Il.logging is on"

let int_order = LanguagePrimitives.FastGenericComparer<int>

Expand Down Expand Up @@ -70,19 +68,13 @@ let memoizeNamespaceRightTable =
let memoizeNamespacePartTable = ConcurrentDictionary<string, string>()

let splitNameAt (nm: string) idx =
if idx < 0 then
failwith "splitNameAt: idx < 0"
if idx < 0 then failwith "splitNameAt: idx < 0"

let last = nm.Length - 1

if idx > last then
failwith "splitNameAt: idx > last"
if idx > last then failwith "splitNameAt: idx > last"

(nm.Substring(0, idx)),
(if idx < last then
nm.Substring(idx + 1, last - idx)
else
"")
(nm.Substring(0, idx)), (if idx < last then nm.Substring(idx + 1, last - idx) else "")

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

let f (t, b, c, d) =
if t < 20 then
(b &&& c) ||| ((~~~b) &&& d)
elif t < 40 then
b ^^^ c ^^^ d
elif t < 60 then
(b &&& c) ||| (b &&& d) ||| (c &&& d)
else
b ^^^ c ^^^ d
if t < 20 then (b &&& c) ||| ((~~~b) &&& d)
elif t < 40 then b ^^^ c ^^^ d
elif t < 60 then (b &&& c) ||| (b &&& d) ||| (c &&& d)
else b ^^^ c ^^^ d

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

b.ToString()

Expand Down Expand Up @@ -773,17 +760,9 @@ type ILTypeRef =
else
y.ApproxId

let xScope =
if isPrimaryX then
primaryScopeRef
else
x.Scope
let xScope = if isPrimaryX then primaryScopeRef else x.Scope

let yScope =
if isPrimaryY then
primaryScopeRef
else
y.Scope
let yScope = if isPrimaryY then primaryScopeRef else y.Scope

(xApproxId = yApproxId)
&& (xScope = yScope)
Expand All @@ -806,10 +785,7 @@ type ILTypeRef =
else
let c = compare x.Name y.Name

if c <> 0 then
c
else
compare x.Enclosing y.Enclosing
if c <> 0 then c else compare x.Enclosing y.Enclosing

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

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

override x.ToString() =
x.TypeRef.ToString()
+ if isNil x.GenericArgs then
""
else
"<...>"
x.TypeRef.ToString() + if isNil x.GenericArgs then "" else "<...>"

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

if f = 0x00000001 then
ILMemberAccess.Private
elif f = 0x00000006 then
ILMemberAccess.Public
elif f = 0x00000004 then
ILMemberAccess.Family
elif f = 0x00000002 then
ILMemberAccess.FamilyAndAssembly
elif f = 0x00000005 then
ILMemberAccess.FamilyOrAssembly
elif f = 0x00000003 then
ILMemberAccess.Assembly
else
ILMemberAccess.CompilerControlled
if f = 0x00000001 then ILMemberAccess.Private
elif f = 0x00000006 then ILMemberAccess.Public
elif f = 0x00000004 then ILMemberAccess.Family
elif f = 0x00000002 then ILMemberAccess.FamilyAndAssembly
elif f = 0x00000005 then ILMemberAccess.FamilyOrAssembly
elif f = 0x00000003 then ILMemberAccess.Assembly
else ILMemberAccess.CompilerControlled

let convertMemberAccess (ilMemberAccess: ILMemberAccess) =
match ilMemberAccess with
Expand Down Expand Up @@ -2509,12 +2474,9 @@ let typeAccessOfFlags flags =
let typeEncodingOfFlags flags =
let f = (flags &&& 0x00030000)

if f = 0x00020000 then
ILDefaultPInvokeEncoding.Auto
elif f = 0x00010000 then
ILDefaultPInvokeEncoding.Unicode
else
ILDefaultPInvokeEncoding.Ansi
if f = 0x00020000 then ILDefaultPInvokeEncoding.Auto
elif f = 0x00010000 then ILDefaultPInvokeEncoding.Unicode
else ILDefaultPInvokeEncoding.Ansi

[<RequireQualifiedAccess>]
type ILTypeDefKind =
Expand Down Expand Up @@ -3613,32 +3575,20 @@ and rescopeILType scoref ty =
| ILType.Boxed cr1 ->
let cr2 = rescopeILTypeSpec scoref cr1

if cr1 === cr2 then
ty
else
mkILBoxedType cr2
if cr1 === cr2 then ty else mkILBoxedType cr2
| ILType.Array (s, ety1) ->
let ety2 = rescopeILType scoref ety1

if ety1 === ety2 then
ty
else
ILType.Array(s, ety2)
if ety1 === ety2 then ty else ILType.Array(s, ety2)
| ILType.Value cr1 ->
let cr2 = rescopeILTypeSpec scoref cr1

if cr1 === cr2 then
ty
else
ILType.Value cr2
if cr1 === cr2 then ty else ILType.Value cr2
| ILType.Modified (b, tref, ty) -> ILType.Modified(b, rescopeILTypeRef scoref tref, rescopeILType scoref ty)
| x -> x

and rescopeILTypes scoref i =
if isNil i then
i
else
List.mapq (rescopeILType scoref) i
if isNil i then i else List.mapq (rescopeILType scoref) i

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

for kvp in c2.Labels do
dict.Add(
kvp.Key,
if kvp.Value = 0 then
0
else
kvp.Value + n
)
dict.Add(kvp.Key, (if kvp.Value = 0 then 0 else kvp.Value + n))

dict

Expand Down Expand Up @@ -4013,22 +3957,10 @@ let mkILField (isStatic, nm, ty, init: ILFieldInit option, at: byte[] option, ac
fieldType = ty,
attributes =
(convertFieldAccess access
||| (if isStatic then
FieldAttributes.Static
else
enum 0)
||| (if isLiteral then
FieldAttributes.Literal
else
enum 0)
||| (if init.IsSome then
FieldAttributes.HasDefault
else
enum 0)
||| (if at.IsSome then
FieldAttributes.HasFieldRVA
else
enum 0)),
||| (if isStatic then FieldAttributes.Static else enum 0)
||| (if isLiteral then FieldAttributes.Literal else enum 0)
||| (if init.IsSome then FieldAttributes.HasDefault else enum 0)
||| (if at.IsSome then FieldAttributes.HasFieldRVA else enum 0)),
literalValue = init,
data = at,
offset = None,
Expand Down Expand Up @@ -4362,12 +4294,7 @@ let mkCtorMethSpecForDelegate (ilg: ILGlobals) (ty: ILType, useUIntPtr) =
let argTys =
[
rescopeILType scoref ilg.typ_Object
rescopeILType
scoref
(if useUIntPtr then
ilg.typ_UIntPtr
else
ilg.typ_IntPtr)
rescopeILType scoref (if useUIntPtr then ilg.typ_UIntPtr else ilg.typ_IntPtr)
]

mkILInstanceMethSpecInTy (ty, ".ctor", argTys, ILType.Void, emptyILGenericArgsList)
Expand Down Expand Up @@ -5143,8 +5070,8 @@ let decodeILAttribData (ca: ILAttribute) =
try
let parser = ILTypeSigParser n
parser.ParseTypeSpec(), sigptr
with
| exn -> failwith (sprintf "decodeILAttribData: error parsing type in custom attribute blob: %s" exn.Message)
with exn ->
failwith (sprintf "decodeILAttribData: error parsing type in custom attribute blob: %s" exn.Message)
| ILType.Boxed tspec when tspec.Name = "System.Object" ->
let et, sigptr = sigptr_get_u8 bytes sigptr

Expand Down Expand Up @@ -5605,10 +5532,7 @@ and unscopeILType ty =
| x -> x

and unscopeILTypes i =
if List.isEmpty i then
i
else
List.map unscopeILType i
if List.isEmpty i then i else List.map unscopeILType i

and unscopeILCallSig csig =
mkILCallSig (csig.CallingConv, unscopeILTypes csig.ArgTypes, unscopeILType csig.ReturnType)
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/AbstractIL/ilmorph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ let cattr_ty2ty f (c: ILAttribute) =
let elems = elems |> List.map (celem_ty2ty f)
let namedArgs = namedArgs |> List.map (cnamedarg_ty2ty f)
mkILCustomAttribMethRef (meth, elems, namedArgs)
with
| _ -> c.WithMethod(meth)
with _ ->
c.WithMethod(meth)
else
c.WithMethod(meth)

Expand Down
Loading

0 comments on commit e1e4d6a

Please sign in to comment.