Skip to content

Commit

Permalink
Fantomas update (#15847)
Browse files Browse the repository at this point in the history
* Fantomas upgrade + format

* Fantomas upgrade + format

---------

Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
  • Loading branch information
dawedawe and vzarytovskii committed Nov 22, 2023
1 parent 4355e04 commit 5cd52b7
Show file tree
Hide file tree
Showing 165 changed files with 4,519 additions and 4,533 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.3",
"version": "6.2.3",
"commands": [
"fantomas"
]
Expand Down
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fsharp_max_array_or_list_width=80
fsharp_max_array_or_list_number_of_items=5
fsharp_max_dot_get_expression_width=80
fsharp_multiline_block_brackets_on_same_column=true
fsharp_multiline_bracket_style=aligned
fsharp_keep_max_number_of_blank_lines=1

[*.fsi]
Expand Down
4 changes: 2 additions & 2 deletions DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ or
Some of the code in this repository is formatted automatically by [Fantomas](https://github.com/fsprojects/fantomas). To format all files use:

```cmd
dotnet fantomas . -r
dotnet fantomas .
```

The formatting is checked automatically by CI:

```cmd
dotnet fantomas . -r --check
dotnet fantomas . --check
```

At the time of writing only a subset of signature files (`*.fsi`) are formatted. See the settings in `.fantomasignore` and `.editorconfig`.
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ stages:
env:
DOTNET_ROLL_FORWARD_TO_PRERELEASE: 1
displayName: Check error code sorting in src/Compiler/FSComp.txt
- script: dotnet fantomas . -r --check
- script: dotnet fantomas . --check
env:
DOTNET_ROLL_FORWARD_TO_PRERELEASE: 1
displayName: Check code formatting (run 'dotnet fantomas . -r' to fix)
displayName: Check code formatting (run 'dotnet fantomas .' to fix)

# Check whether package with current version has been published to nuget.org
# We will try to restore both FSharp.Core and FCS and if restore is _successful_, package version needs to be bumped.
Expand Down
120 changes: 60 additions & 60 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ let AssemblyRefUniqueStampGenerator = UniqueStampGenerator<AssemblyRefData>()
type ILAssemblyRef(data) =
let pkToken key =
match key with
| Some (PublicKey bytes) -> Some(PublicKey(SHA1.sha1HashBytes bytes))
| Some (PublicKeyToken token) -> Some(PublicKey token)
| Some(PublicKey bytes) -> Some(PublicKey(SHA1.sha1HashBytes bytes))
| Some(PublicKeyToken token) -> Some(PublicKey token)
| None -> None

let uniqueStamp =
Expand Down Expand Up @@ -649,9 +649,9 @@ type ILCallingConv =

| Callconv of ILThisConvention * ILArgConvention

member x.ThisConv = let (Callconv (a, _b)) = x in a
member x.ThisConv = let (Callconv(a, _b)) = x in a

member x.BasicConv = let (Callconv (_a, b)) = x in b
member x.BasicConv = let (Callconv(_a, b)) = x in b

member x.IsInstance =
match x.ThisConv with
Expand Down Expand Up @@ -885,8 +885,8 @@ and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison; Structur
member x.BasicQualifiedName =
match x with
| ILType.TypeVar n -> "!" + string n
| ILType.Modified (_, _ty1, ty2) -> ty2.BasicQualifiedName
| ILType.Array (ILArrayShape s, ty) -> ty.BasicQualifiedName + "[" + String(',', s.Length - 1) + "]"
| ILType.Modified(_, _ty1, ty2) -> ty2.BasicQualifiedName
| ILType.Array(ILArrayShape s, ty) -> ty.BasicQualifiedName + "[" + String(',', s.Length - 1) + "]"
| ILType.Value tr
| ILType.Boxed tr -> tr.BasicQualifiedName
| ILType.Void -> "void"
Expand All @@ -897,8 +897,8 @@ and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison; Structur
member x.AddQualifiedNameExtension basic =
match x with
| ILType.TypeVar _n -> basic
| ILType.Modified (_, _ty1, ty2) -> ty2.AddQualifiedNameExtension basic
| ILType.Array (ILArrayShape (_s), ty) -> ty.AddQualifiedNameExtension basic
| ILType.Modified(_, _ty1, ty2) -> ty2.AddQualifiedNameExtension basic
| ILType.Array(ILArrayShape(_s), ty) -> ty.AddQualifiedNameExtension basic
| ILType.Value tr
| ILType.Boxed tr -> tr.AddQualifiedNameExtension basic
| ILType.Void -> failwith "void"
Expand Down Expand Up @@ -1190,18 +1190,18 @@ type ILAttribute =

member x.Method =
match x with
| Encoded (method, _, _)
| Decoded (method, _, _) -> method
| Encoded(method, _, _)
| Decoded(method, _, _) -> method

member x.Elements =
match x with
| Encoded (_, _, elements) -> elements
| Decoded (_, fixedArgs, namedArgs) -> fixedArgs @ (namedArgs |> List.map (fun (_, _, _, e) -> e))
| Encoded(_, _, elements) -> elements
| Decoded(_, fixedArgs, namedArgs) -> fixedArgs @ (namedArgs |> List.map (fun (_, _, _, e) -> e))

member x.WithMethod(method: ILMethodSpec) =
match x with
| Encoded (_, data, elements) -> Encoded(method, data, elements)
| Decoded (_, fixedArgs, namedArgs) -> Decoded(method, fixedArgs, namedArgs)
| Encoded(_, data, elements) -> Encoded(method, data, elements)
| Decoded(_, fixedArgs, namedArgs) -> Decoded(method, fixedArgs, namedArgs)

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
Expand Down Expand Up @@ -1804,9 +1804,9 @@ type ILReturn =
type ILOverridesSpec =
| OverridesSpec of ILMethodRef * ILType

member x.MethodRef = let (OverridesSpec (mr, _ty)) = x in mr
member x.MethodRef = let (OverridesSpec(mr, _ty)) = x in mr

member x.DeclaringType = let (OverridesSpec (_mr, ty)) = x in ty
member x.DeclaringType = let (OverridesSpec(_mr, ty)) = x in ty

override x.ToString() =
"overrides " + x.DeclaringType.ToString() + "::" + x.MethodRef.ToString()
Expand Down Expand Up @@ -3337,7 +3337,7 @@ let isILArrTy ty =

let destILArrTy ty =
match ty with
| ILType.Array (shape, ty) -> (shape, ty)
| ILType.Array(shape, ty) -> (shape, ty)
| _ -> failwith "destILArrTy"

// --------------------------------------------------------------------
Expand Down Expand Up @@ -3547,7 +3547,7 @@ let isILValueTy =

let rec stripILModifiedFromTy (ty: ILType) =
match ty with
| ILType.Modified (_, _, ty) -> stripILModifiedFromTy ty
| ILType.Modified(_, _, ty) -> stripILModifiedFromTy ty
| _ -> ty

let isBuiltInTySpec (ilg: ILGlobals) (tspec: ILTypeSpec) n =
Expand Down Expand Up @@ -3655,15 +3655,15 @@ and rescopeILType scoref ty =
let cr2 = rescopeILTypeSpec scoref cr1

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

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
| ILType.Modified (b, tref, ty) -> ILType.Modified(b, rescopeILTypeRef scoref tref, rescopeILType scoref ty)
| ILType.Modified(b, tref, ty) -> ILType.Modified(b, rescopeILTypeRef scoref tref, rescopeILType scoref ty)
| x -> x

and rescopeILTypes scoref i =
Expand Down Expand Up @@ -3700,7 +3700,7 @@ and instILTypeAux numFree (inst: ILGenericArgs) ty =
match ty with
| ILType.Ptr t -> ILType.Ptr(instILTypeAux numFree inst t)
| ILType.FunctionPointer t -> ILType.FunctionPointer(instILCallSigAux numFree inst t)
| ILType.Array (a, t) -> ILType.Array(a, instILTypeAux numFree inst t)
| ILType.Array(a, t) -> ILType.Array(a, instILTypeAux numFree inst t)
| ILType.Byref t -> ILType.Byref(instILTypeAux numFree inst t)
| ILType.Boxed cr -> mkILBoxedType (instILTypeSpecAux numFree inst cr)
| ILType.Value cr -> ILType.Value(instILTypeSpecAux numFree inst cr)
Expand Down Expand Up @@ -3822,7 +3822,7 @@ let mkILCtor (access, args, impl) =
let mkCallBaseConstructor (ty, args: ILType list) =
[ mkLdarg0 ]
@ List.mapi (fun i _ -> mkLdarg (uint16 (i + 1))) args
@ [ mkNormalCall (mkILCtorMethSpecForTy (ty, [])) ]
@ [ mkNormalCall (mkILCtorMethSpecForTy (ty, [])) ]

let mkNormalStfld fspec = I_stfld(Aligned, Nonvolatile, fspec)

Expand Down Expand Up @@ -4643,7 +4643,7 @@ let rec encodeCustomAttrElemType x =
| ILType.Boxed tspec when tspec.Name = tname_Object -> [| 0x51uy |]
| ILType.Boxed tspec when tspec.Name = tname_Type -> [| 0x50uy |]
| ILType.Value tspec -> Array.append [| 0x55uy |] (encodeCustomAttrString tspec.TypeRef.QualifiedName)
| ILType.Array (shape, elemType) when shape = ILArrayShape.SingleDimensional ->
| ILType.Array(shape, elemType) when shape = ILArrayShape.SingleDimensional ->
Array.append [| et_SZARRAY |] (encodeCustomAttrElemType elemType)
| _ -> failwith "encodeCustomAttrElemType: unrecognized custom element type"

Expand All @@ -4666,7 +4666,7 @@ let rec encodeCustomAttrElemTypeForObject x =
| ILAttribElem.Null -> [| et_STRING |] // yes, the 0xe prefix is used when passing a "null" to a property or argument of type "object" here
| ILAttribElem.Single _ -> [| et_R4 |]
| ILAttribElem.Double _ -> [| et_R8 |]
| ILAttribElem.Array (elemTy, _) -> [| yield et_SZARRAY; yield! encodeCustomAttrElemType elemTy |]
| ILAttribElem.Array(elemTy, _) -> [| yield et_SZARRAY; yield! encodeCustomAttrElemType elemTy |]

let tspan = TimeSpan(DateTime.UtcNow.Ticks - DateTime(2000, 1, 1).Ticks)

Expand Down Expand Up @@ -4774,7 +4774,7 @@ let rec encodeCustomAttrPrimValue c =
| ILAttribElem.Type None
| ILAttribElem.TypeRef None
| ILAttribElem.Null -> [| 0xFFuy |]
| ILAttribElem.String (Some s) -> encodeCustomAttrString s
| ILAttribElem.String(Some s) -> encodeCustomAttrString s
| ILAttribElem.Char x -> u16AsBytes (uint16 x)
| ILAttribElem.SByte x -> i8AsBytes x
| ILAttribElem.Int16 x -> i16AsBytes x
Expand All @@ -4786,9 +4786,9 @@ let rec encodeCustomAttrPrimValue c =
| ILAttribElem.UInt64 x -> u64AsBytes x
| ILAttribElem.Single x -> ieee32AsBytes x
| ILAttribElem.Double x -> ieee64AsBytes x
| ILAttribElem.Type (Some ty) -> encodeCustomAttrString ty.QualifiedName
| ILAttribElem.TypeRef (Some tref) -> encodeCustomAttrString tref.QualifiedName
| ILAttribElem.Array (_, elems) ->
| ILAttribElem.Type(Some ty) -> encodeCustomAttrString ty.QualifiedName
| ILAttribElem.TypeRef(Some tref) -> encodeCustomAttrString tref.QualifiedName
| ILAttribElem.Array(_, elems) ->
[|
yield! i32AsBytes elems.Length
for elem in elems do
Expand All @@ -4802,8 +4802,8 @@ and encodeCustomAttrValue ty c =
yield! encodeCustomAttrElemTypeForObject c
yield! encodeCustomAttrPrimValue c
|]
| ILType.Array (shape, _), ILAttribElem.Null when shape = ILArrayShape.SingleDimensional -> [| yield! i32AsBytes 0xFFFFFFFF |]
| ILType.Array (shape, elemType), ILAttribElem.Array (_, elems) when shape = ILArrayShape.SingleDimensional ->
| ILType.Array(shape, _), ILAttribElem.Null when shape = ILArrayShape.SingleDimensional -> [| yield! i32AsBytes 0xFFFFFFFF |]
| ILType.Array(shape, elemType), ILAttribElem.Array(_, elems) when shape = ILArrayShape.SingleDimensional ->
[|
yield! i32AsBytes elems.Length
for elem in elems do
Expand Down Expand Up @@ -4843,8 +4843,8 @@ let mkILCustomAttribute (tref, argTys, argvs, propvs) =

let getCustomAttrData cattr =
match cattr with
| ILAttribute.Encoded (_, data, _) -> data
| ILAttribute.Decoded (mspec, fixedArgs, namedArgs) -> encodeCustomAttrArgs mspec fixedArgs namedArgs
| ILAttribute.Encoded(_, data, _) -> data
| ILAttribute.Decoded(mspec, fixedArgs, namedArgs) -> encodeCustomAttrArgs mspec fixedArgs namedArgs

// ILSecurityDecl is a 'blob' having the following format:
// - A byte containing a period (.).
Expand Down Expand Up @@ -5071,8 +5071,8 @@ type ILTypeSigParser(tstring: string) =

let decodeILAttribData (ca: ILAttribute) =
match ca with
| ILAttribute.Decoded (_, fixedArgs, namedArgs) -> fixedArgs, namedArgs
| ILAttribute.Encoded (_, bytes, _) ->
| ILAttribute.Decoded(_, fixedArgs, namedArgs) -> fixedArgs, namedArgs
| ILAttribute.Encoded(_, bytes, _) ->

let sigptr = 0
let bb0, sigptr = sigptr_get_byte bytes sigptr
Expand Down Expand Up @@ -5141,7 +5141,7 @@ let decodeILAttribData (ca: ILAttribute) =
else
let ty, sigptr = decodeCustomAttrElemType bytes sigptr et
parseVal ty sigptr
| ILType.Array (shape, elemTy) when shape = ILArrayShape.SingleDimensional ->
| ILType.Array(shape, elemTy) when shape = ILArrayShape.SingleDimensional ->
let n, sigptr = sigptr_get_i32 bytes sigptr

if n = 0xFFFFFFFF then
Expand Down Expand Up @@ -5261,10 +5261,10 @@ let rec refsOfILType s x =
match x with
| ILType.Void
| ILType.TypeVar _ -> ()
| ILType.Modified (_, ty1, ty2) ->
| ILType.Modified(_, ty1, ty2) ->
refsOfILTypeRef s ty1
refsOfILType s ty2
| ILType.Array (_, ty)
| ILType.Array(_, ty)
| ILType.Ptr ty
| ILType.Byref ty -> refsOfILType s ty
| ILType.Value tr
Expand Down Expand Up @@ -5294,7 +5294,7 @@ and refsOfILFieldRef s x =
refsOfILType s x.Type
s.refsFs.Add x |> ignore

and refsOfILOverridesSpec s (OverridesSpec (mref, ty)) =
and refsOfILOverridesSpec s (OverridesSpec(mref, ty)) =
refsOfILMethodRef s mref
refsOfILType s ty

Expand All @@ -5317,9 +5317,9 @@ and refsOfILToken s x =

and refsOfILCustomAttrElem s (elem: ILAttribElem) =
match elem with
| Type (Some ty) -> refsOfILType s ty
| TypeRef (Some tref) -> refsOfILTypeRef s tref
| Array (ty, els) ->
| Type(Some ty) -> refsOfILType s ty
| TypeRef(Some tref) -> refsOfILTypeRef s tref
| Array(ty, els) ->
refsOfILType s ty
refsOfILCustomAttrElems s els
| _ -> ()
Expand All @@ -5338,41 +5338,41 @@ and refsOfILVarArgs s tyso = Option.iter (refsOfILTypes s) tyso

and refsOfILInstr s x =
match x with
| I_call (_, mr, varargs)
| I_newobj (mr, varargs)
| I_callvirt (_, mr, varargs) ->
| I_call(_, mr, varargs)
| I_newobj(mr, varargs)
| I_callvirt(_, mr, varargs) ->
refsOfILMethodSpec s mr
refsOfILVarArgs s varargs
| I_callconstraint (_, _, tr, mr, varargs) ->
| I_callconstraint(_, _, tr, mr, varargs) ->
refsOfILType s tr
refsOfILMethodSpec s mr
refsOfILVarArgs s varargs
| I_calli (_, callsig, varargs) ->
| I_calli(_, callsig, varargs) ->
refsOfILCallsig s callsig
refsOfILVarArgs s varargs
| I_jmp mr
| I_ldftn mr
| I_ldvirtftn mr -> refsOfILMethodSpec s mr
| I_ldsfld (_, fr)
| I_ldfld (_, _, fr)
| I_ldsfld(_, fr)
| I_ldfld(_, _, fr)
| I_ldsflda fr
| I_ldflda fr
| I_stsfld (_, fr)
| I_stfld (_, _, fr) -> refsOfILFieldSpec s fr
| I_stsfld(_, fr)
| I_stfld(_, _, fr) -> refsOfILFieldSpec s fr
| I_isinst ty
| I_castclass ty
| I_cpobj ty
| I_initobj ty
| I_ldobj (_, _, ty)
| I_stobj (_, _, ty)
| I_ldobj(_, _, ty)
| I_stobj(_, _, ty)
| I_box ty
| I_unbox ty
| I_unbox_any ty
| I_sizeof ty
| I_ldelem_any (_, ty)
| I_ldelema (_, _, _, ty)
| I_stelem_any (_, ty)
| I_newarr (_, ty)
| I_ldelem_any(_, ty)
| I_ldelema(_, _, _, ty)
| I_stelem_any(_, ty)
| I_newarr(_, ty)
| I_mkrefany ty
| I_refanyval ty
| EI_ilzero ty -> refsOfILType s ty
Expand Down Expand Up @@ -5448,7 +5448,7 @@ and refsOfILCode s (c: ILCode) =

for exnClause in c.Exceptions do
match exnClause.Clause with
| ILExceptionClause.TypeCatch (ilTy, _) -> refsOfILType s ilTy
| ILExceptionClause.TypeCatch(ilTy, _) -> refsOfILType s ilTy
| _ -> ()

and refsOfILMethodBody s (il: ILMethodBody) =
Expand Down Expand Up @@ -5531,7 +5531,7 @@ and refsOfILExportedTypes s (tab: ILExportedTypesAndForwarders) =
and refsOfILResourceLocation s x =
match x with
| ILResourceLocation.Local _ -> ()
| ILResourceLocation.File (mref, _) -> refsOfILModuleRef s mref
| ILResourceLocation.File(mref, _) -> refsOfILModuleRef s mref
| ILResourceLocation.Assembly aref -> refsOfILAssemblyRef s aref

and refsOfILResource s x =
Expand Down Expand Up @@ -5587,9 +5587,9 @@ and unscopeILType ty =
| ILType.FunctionPointer t -> ILType.FunctionPointer(unscopeILCallSig t)
| ILType.Byref t -> ILType.Byref(unscopeILType t)
| ILType.Boxed cr -> mkILBoxedType (unscopeILTypeSpec cr)
| ILType.Array (s, ty) -> ILType.Array(s, unscopeILType ty)
| ILType.Array(s, ty) -> ILType.Array(s, unscopeILType ty)
| ILType.Value cr -> ILType.Value(unscopeILTypeSpec cr)
| ILType.Modified (b, tref, ty) -> ILType.Modified(b, unscopeILTypeRef tref, unscopeILType ty)
| ILType.Modified(b, tref, ty) -> ILType.Modified(b, unscopeILTypeRef tref, unscopeILType ty)
| x -> x

and unscopeILTypes i =
Expand Down
Loading

0 comments on commit 5cd52b7

Please sign in to comment.