Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format src/Compiler/Service #13238

Merged
merged 24 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ fsharp_max_if_then_else_short_width=40
# fsharp_max_function_binding_width formats these over a single line.
[src/Compiler/Driver/CompilerDiagnostics.fs]
fsharp_max_function_binding_width=70

# This file contains long specifications of navigation items
[src/Compiler/Service/ServiceStructure.fs]
fsharp_max_value_binding_width=100

# This file contains long specifications of navigation items
[src/Compiler/Service/ServiceNavigation.fs]
max_line_length=170
fsharp_max_value_binding_width=120

# This file contains long calls with explicitly named arguments
[src/Compiler/Service/service.fs]
max_line_length=150
fsharp_max_value_binding_width=100
6 changes: 4 additions & 2 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ docs/
eng/
fcs-samples/
scripts/
service/
setup/
tests/
vsintegration/
Expand All @@ -20,7 +19,6 @@ src/Compiler/Facilities/**/*.fs
src/Compiler/Interactive/**/*.fs
src/Compiler/Legacy/**/*.fs
src/Compiler/Optimize/**/*.fs
src/Compiler/Service/**/*.fs
src/Compiler/Symbols/**/*.fs
src/Compiler/TypedTree/**/*.fs
src/Microsoft.FSharp.Compiler/**/*.fs
Expand Down Expand Up @@ -50,6 +48,10 @@ src/FSharp.Core/SI.fs

src/Compiler/AbstractIL/ilwrite.fs
src/Compiler/Utilities/lib.fs
src/Compiler/Service/IncrementalBuild.fs
src/Compiler/Service/ServiceAssemblyContent.fs
src/Compiler/Service/ServiceDeclarationLists.fs
src/Compiler/Service/ServiceErrorResolutionHints.fs

# Fantomas limitations on signature files (to investigate)

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ and seekReadInterfaceImpls (ctxt: ILMetadataReader) mdv numTypars tidx =
fst,
simpleIndexCompare tidx,
isSorted ctxt TableNames.InterfaceImpl,
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject (*ok*) [])
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject [])
)

and seekReadGenericParams ctxt numTypars (a, b) : ILGenericParameterDefs =
Expand Down Expand Up @@ -2229,7 +2229,7 @@ and seekReadGenericParamConstraints (ctxt: ILMetadataReader) mdv numTypars gpidx
fst,
simpleIndexCompare gpidx,
isSorted ctxt TableNames.GenericParamConstraint,
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject (*ok*) List.empty)
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject [])
)

and seekReadTypeDefAsType (ctxt: ILMetadataReader) boxity (ginst: ILTypes) idx =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ let convTypeRefAux (cenv: cenv) (tref: ILTypeRef) =
[<AutoSerializable(false)>]
type ILDynamicAssemblyEmitEnv =
{
emTypMap: Zmap<ILTypeRef, Type * TypeBuilder * ILTypeDef * Type option (*the created type*) >
emTypMap: Zmap<ILTypeRef, Type * TypeBuilder * ILTypeDef * Type option>
emConsMap: Zmap<ILMethodRef, ConstructorBuilder>
emMethMap: Zmap<ILMethodRef, MethodBuilder>
emFieldMap: Zmap<ILFieldRef, FieldBuilder>
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
// For 'query' check immediately
if isQuery then
match (List.map (BindingNormalization.NormalizeBinding ValOrMemberBinding cenv env) binds) with
| [NormalizedBinding(_, SynBindingKind.Normal, (*inline*)false, (*mutable*)false, _, _, _, _, _, _, _, _)] when not isRec ->
| [NormalizedBinding(_, SynBindingKind.Normal, false, false, _, _, _, _, _, _, _, _)] when not isRec ->
()
| normalizedBindings ->
let failAt m = error(Error(FSComp.SR.tcNonSimpleLetBindingInQuery(), m))
Expand Down Expand Up @@ -1770,7 +1770,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
// Add a call to 'Quote' if the method is present
let quotedSynExpr =
if isAutoQuote then
SynExpr.Quote (mkSynIdGet mDelayOrQuoteOrRun (CompileOpName "<@ @>"), (*isRaw=*)false, delayedExpr, (*isFromQueryExpression=*)true, mWhole)
SynExpr.Quote (mkSynIdGet mDelayOrQuoteOrRun (CompileOpName "<@ @>"), false, delayedExpr, true, mWhole)
else delayedExpr

// Add a call to 'Run' if the method is present
Expand Down
10 changes: 5 additions & 5 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ module IncrClassChecking =
let valSynData = SynValInfo([[]], SynInfo.unnamedRetVal)
let id = ident ("cctor", m)
CheckForNonAbstractInterface ModuleOrMemberBinding tcref (ClassCtorMemberFlags SynMemberFlagsTrivia.Zero) id.idRange
let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [(*no attributes*)], [], (ClassCtorMemberFlags SynMemberFlagsTrivia.Zero), valSynData, id, false)
let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [], [], (ClassCtorMemberFlags SynMemberFlagsTrivia.Zero), valSynData, id, false)
let prelimValReprInfo = TranslateSynValInfo m (TcAttributes cenv env) valSynData
let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, cctorTy)
let topValInfo = InferGenericArityFromTyScheme prelimTyschemeG prelimValReprInfo
Expand Down Expand Up @@ -864,13 +864,13 @@ module IncrClassChecking =
type IncrClassValRepr =

// e.g representation for 'let v = 3' if it is not used in anything given a method representation
| InVar of (* isArg: *) bool
| InVar of isArg: bool

// e.g representation for 'let v = 3'
| InField of (*isStatic:*)bool * (*staticCountForSafeInit:*) int * RecdFieldRef
| InField of isStatic: bool * staticCountForSafeInit: int * fieldRef: RecdFieldRef

// e.g representation for 'let f x = 3'
| InMethod of (*isStatic:*)bool * Val * ValReprInfo
| InMethod of isStatic:bool * value: Val * valReprInfo: ValReprInfo

/// IncrClassReprInfo represents the decisions we make about the representation of 'let' and 'do' bindings in a
/// type defined with implicit class construction.
Expand Down Expand Up @@ -1932,7 +1932,7 @@ module MutRecBindingChecking =

// Type check local recursive binding
let binds = binds |> List.map (fun bind -> RecDefnBindingInfo(ExprContainerInfo, NoNewSlots, ClassLetBinding isStatic, bind))
let binds, env, tpenv = TcLetrecBindings ErrorOnOverrides cenv envForBinding tpenv (binds, scopem(*bindsm*), scopem)
let binds, env, tpenv = TcLetrecBindings ErrorOnOverrides cenv envForBinding tpenv (binds, scopem, scopem)
let bindRs = [IncrClassBindingGroup(binds, isStatic, true)]
binds, bindRs, env, tpenv
else
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@ let CheckAllTyparsInferrable amap m item =
/// ultimately calls ResolutionInfo.Method to record it for
/// later use by Visual Studio.
type ResolutionInfo =
| ResolutionInfo of (*entityPath, reversed*)(range * EntityRef) list * (*warnings/errors*)(ResultTyparChecker -> unit) * tinstEnclosing: EnclosingTypeInst
| ResolutionInfo of revEntityPath: (range * EntityRef) list * reportResult: (ResultTyparChecker -> unit) * tinstEnclosing: EnclosingTypeInst

static member SendEntityPathToSink(sink, ncenv: NameResolver, nenv, occ, ad, ResolutionInfo(entityPath, warnings, _), typarChecker) =
entityPath |> List.iter (fun (m, eref: EntityRef) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7554,7 +7554,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: Checke
// Create the class to hold the initialization code and static fields for this file.
// internal static class $<StartupCode...> {}
// Put it at the end since that gives an approximation of dependency order (to aid FSI.EXE's code generator - see FSharp 1.0 5548)
GenTypeDefForCompLoc (cenv, eenv, mgbuf, initClassCompLoc, useHiddenInitCode, [], initClassTrigger, false, (*atEnd=*)true)
GenTypeDefForCompLoc (cenv, eenv, mgbuf, initClassCompLoc, useHiddenInitCode, [], initClassTrigger, false, true)

// lazyInitInfo is an accumulator of functions which add the forced initialization of the storage module to
// - mutable fields in public modules
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ type TcConfigBuilder =
// If true - the compiler will copy FSharp.Core.dll along the produced binaries
mutable copyFSharpCore: CopyFSharpCoreFlag

/// When false FSI will lock referenced assemblies requiring process restart, false = disable Shadow Copy false (*default*)
/// When false FSI will lock referenced assemblies requiring process restart, false = disable Shadow Copy false, the default
mutable shadowCopyReferences: bool

mutable useSdkRefs: bool
Expand Down
10 changes: 1 addition & 9 deletions src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -618,15 +618,7 @@ let main1
(fun exiter -> diagnosticsLoggerProvider.CreateDelayAndForwardLogger(exiter) :> CapturingDiagnosticsLogger)

let inputs =
ParseInputFiles(
tcConfig,
lexResourceManager,
sourceFiles,
diagnosticsLogger,
exiter,
createDiagnosticsLogger (*retryLocked*) ,
false
)
ParseInputFiles(tcConfig, lexResourceManager, sourceFiles, diagnosticsLogger, exiter, createDiagnosticsLogger, false)

let inputs, _ =
(Map.empty, inputs)
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ type internal FsiDynamicCompiler(
let m = match defs with [] -> rangeStdin0 | _ -> List.reduce unionRanges [for d in defs -> d.Range]
let prefix = mkFragmentPath m i
let prefixPath = pathOfLid prefix
let impl = SynModuleOrNamespace(prefix,(*isRec*)false, SynModuleOrNamespaceKind.NamedModule,defs,PreXmlDoc.Empty,[],None,m, { ModuleKeyword = None; NamespaceKeyword = None })
let impl = SynModuleOrNamespace(prefix,false, SynModuleOrNamespaceKind.NamedModule,defs,PreXmlDoc.Empty,[],None,m, { ModuleKeyword = None; NamespaceKeyword = None })
let isLastCompiland = true
let isExe = false
let input = ParsedInput.ImplFile (ParsedImplFileInput (fileName,true, ComputeQualifiedNameOfFileFromUniquePath (m,prefixPath),[],[],[impl],(isLastCompiland, isExe), { ConditionalDirectives = []; CodeComments = [] }))
Expand Down Expand Up @@ -2030,7 +2030,7 @@ type internal FsiDynamicCompiler(
input.MetaCommandDiagnostics |> List.iter diagnosticSink
let parsedInput =
match input.SyntaxTree with
| None -> ParseOneInputFile(tcConfig, lexResourceManager, input.FileName, (true, false), diagnosticsLogger, (*retryLocked*)false)
| None -> ParseOneInputFile(tcConfig, lexResourceManager, input.FileName, (true, false), diagnosticsLogger, false)
| Some parseTree -> parseTree
input.FileName, parsedInput)
|> List.unzip
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Legacy/LegacyMSBuildReferenceResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module FSharp.Compiler.CodeAnalysis.LegacyMSBuildReferenceResolver

/// Perform assembly resolution by instantiating the ResolveAssembly task directly from the MSBuild SDK.
let ResolveCore(resolutionEnvironment: LegacyResolutionEnvironment,
references:(string*(*baggage*)string)[],
references:(string*string)[],
targetFrameworkVersion: string,
targetFrameworkDirectories: string list,
targetProcessorArchitecture: string,
Expand Down
69 changes: 34 additions & 35 deletions src/Compiler/Service/ExternalSymbol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ open System.Diagnostics

module Option =

let ofOptionList (xs : 'a option list) : 'a list option =
let ofOptionList (xs: 'a option list) : 'a list option =

if xs |> List.forall Option.isSome then
xs |> List.map Option.get |> Some
else
None

/// Represents a type in an external (non F#) assembly.
[<RequireQualifiedAccess>]
type FindDeclExternalType =
Expand All @@ -36,36 +36,29 @@ type FindDeclExternalType =
| Type (name, genericArgs) ->
match genericArgs with
| [] -> ""
| args ->
args
|> List.map (sprintf "%O")
|> String.concat ", "
|> sprintf "<%s>"
| args -> args |> List.map (sprintf "%O") |> String.concat ", " |> sprintf "<%s>"
|> sprintf "%s%s" name
| Array inner -> sprintf "%O[]" inner
| Pointer inner -> sprintf "&%O" inner
| TypeVar name -> sprintf "'%s" name

module FindDeclExternalType =
let rec tryOfILType (typeVarNames: string array) (ilType: ILType) =

match ilType with
| ILType.Array (_, inner) ->
tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Array
| ILType.Array (_, inner) -> tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Array
| ILType.Boxed tyspec
| ILType.Value tyspec ->
tyspec.GenericArgs
|> List.map (tryOfILType typeVarNames)
|> Option.ofOptionList
|> Option.map (fun genericArgs -> FindDeclExternalType.Type (tyspec.FullName, genericArgs))
| ILType.Ptr inner ->
tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Pointer
|> Option.map (fun genericArgs -> FindDeclExternalType.Type(tyspec.FullName, genericArgs))
| ILType.Ptr inner -> tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Pointer
| ILType.TypeVar ordinal ->
typeVarNames
|> Array.tryItem (int ordinal)
|> Option.map (fun typeVarName -> FindDeclExternalType.TypeVar typeVarName)
| _ ->
None
| _ -> None

[<RequireQualifiedAccess>]
type FindDeclExternalParam =
Expand All @@ -74,27 +67,37 @@ type FindDeclExternalParam =

| Byref of parameterType: FindDeclExternalType

member c.IsByRef = match c with Byref _ -> true | _ -> false
member c.IsByRef =
match c with
| Byref _ -> true
| _ -> false

member c.ParameterType = match c with Byref ty -> ty | Param ty -> ty
member c.ParameterType =
match c with
| Byref ty -> ty
| Param ty -> ty

static member Create(parameterType, isByRef) =
static member Create(parameterType, isByRef) =
if isByRef then Byref parameterType else Param parameterType

override this.ToString () =
override this.ToString() =
match this with
| Param t -> t.ToString()
| Byref t -> sprintf "ref %O" t

module FindDeclExternalParam =
let tryOfILType (typeVarNames : string array) =
let tryOfILType (typeVarNames: string array) =
function
| ILType.Byref inner -> FindDeclExternalType.tryOfILType typeVarNames inner |> Option.map FindDeclExternalParam.Byref
| ilType -> FindDeclExternalType.tryOfILType typeVarNames ilType |> Option.map FindDeclExternalParam.Param
| ILType.Byref inner ->
FindDeclExternalType.tryOfILType typeVarNames inner
|> Option.map FindDeclExternalParam.Byref
| ilType ->
FindDeclExternalType.tryOfILType typeVarNames ilType
|> Option.map FindDeclExternalParam.Param

let tryOfILTypes typeVarNames ilTypes =
ilTypes |> List.map (tryOfILType typeVarNames) |> Option.ofOptionList

[<RequireQualifiedAccess>]
[<DebuggerDisplay "{ToDebuggerDisplay(),nq}">]
type FindDeclExternalSymbol =
Expand All @@ -105,7 +108,7 @@ type FindDeclExternalSymbol =
| Event of typeName: string * name: string
| Property of typeName: string * name: string

override this.ToString () =
override this.ToString() =
match this with
| Type fullName -> fullName
| Constructor (typeName, args) ->
Expand All @@ -114,25 +117,22 @@ type FindDeclExternalSymbol =
|> String.concat ", "
|> sprintf "%s..ctor(%s)" typeName
| Method (typeName, name, args, genericArity) ->
let genericAritySuffix =
if genericArity > 0 then sprintf "`%d" genericArity
else ""
let genericAritySuffix = if genericArity > 0 then sprintf "`%d" genericArity else ""

args
|> List.map (sprintf "%O")
|> String.concat ", "
|> sprintf "%s.%s%s(%s)" typeName name genericAritySuffix
| Field (typeName, name)
| Event (typeName, name)
| Property (typeName, name) ->
sprintf "%s.%s" typeName name
| Property (typeName, name) -> sprintf "%s.%s" typeName name

member this.ToDebuggerDisplay () =
member this.ToDebuggerDisplay() =
let caseInfo, _ = FSharpValue.GetUnionFields(this, typeof<FindDeclExternalSymbol>)
sprintf "%s %O" caseInfo.Name this

[<RequireQualifiedAccess>]
type FindDeclFailureReason =
type FindDeclFailureReason =

// generic reason: no particular information about error
| Unknown of message: string
Expand All @@ -147,7 +147,7 @@ type FindDeclFailureReason =
| ProvidedMember of memberName: string

[<RequireQualifiedAccess>]
type FindDeclResult =
type FindDeclResult =

/// declaration not found + reason
| DeclNotFound of FindDeclFailureReason
Expand All @@ -156,5 +156,4 @@ type FindDeclResult =
| DeclFound of location: range

/// Indicates an external declaration was found
| ExternalDecl of assembly : string * externalSym : FindDeclExternalSymbol

| ExternalDecl of assembly: string * externalSym: FindDeclExternalSymbol
Loading