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

Use arrays for storing source files in projects #9259

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ module Array =
/// Returns true if one array has trailing elements equal to another's.
let endsWith (suffix: _ []) (whole: _ []) =
isSubArray suffix whole (whole.Length-suffix.Length)


let unzip4 (array: _ []) =
let a, b, cd = Array.unzip3 (Array.map (fun (x, y, z, w) -> (x, y, (z, w))) array)
let c, d = Array.unzip cd
a, b, c, d

module Option =

let mapFold f s opt =
Expand Down
123 changes: 68 additions & 55 deletions src/fsharp/CompileOps.fs

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/fsharp/CompileOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type ModuleNamesDict = Map<string,Map<string,QualifiedNameOfFile>>
val DeduplicateParsedInputModuleName: ModuleNamesDict -> ParsedInput -> ParsedInput * ModuleNamesDict

/// Parse a single input (A signature file or implementation file)
val ParseInput: (UnicodeLexing.Lexbuf -> Parser.token) * ErrorLogger * UnicodeLexing.Lexbuf * string option * string * isLastCompiland:(bool * bool) -> ParsedInput
val ParseInput: (UnicodeLexing.Lexbuf -> Parser.token) * ErrorLogger * UnicodeLexing.Lexbuf * string option * string * isLastCompiland: bool * isExe: bool -> ParsedInput

//----------------------------------------------------------------------------
// Error and warnings
Expand Down Expand Up @@ -274,7 +274,7 @@ type TcConfigBuilder =
mutable light: bool option
mutable conditionalCompilationDefines: string list
/// Sources added into the build with #load
mutable loadedSources: (range * string * string) list
mutable loadedSources: (range * string * string)[]
mutable compilerToolPaths: string list
mutable referencedDLLs: AssemblyReference list
mutable packageManagerLines: Map<string, (bool * string * range) list>
Expand Down Expand Up @@ -413,7 +413,7 @@ type TcConfigBuilder =
tryGetMetadataSnapshot: ILReaderTryGetMetadataSnapshot
-> TcConfigBuilder

member DecideNames: string list -> outfile: string * pdbfile: string option * assemblyName: string
member DecideNames: string[] -> outfile: string * pdbfile: string option * assemblyName: string
member TurnWarningOff: range * string -> unit
member TurnWarningOn: range * string -> unit
member AddIncludePath: range * string * string -> unit
Expand Down Expand Up @@ -547,9 +547,9 @@ type TcConfig =
member GetTargetFrameworkDirectories: unit -> string list

/// Get the loaded sources that exist and issue a warning for the ones that don't
member GetAvailableLoadedSources: unit -> (range*string) list
member GetAvailableLoadedSources: unit -> (range * string)[]

member ComputeCanContainEntryPoint: sourceFiles:string list -> bool list *bool
member ComputeCanContainEntryPoint: sourceFiles: string[] -> bool[] * bool

/// File system query based on TcConfig settings
member ResolveSourceFile: range * filename: string * pathLoadedFrom: string -> string
Expand Down Expand Up @@ -722,7 +722,7 @@ val DefaultReferencesForScriptsAndOutOfProjectSources: bool -> string list
//--------------------------------------------------------------------------

/// Parse one input file
val ParseOneInputFile: TcConfig * Lexhelp.LexResourceManager * string list * string * isLastCompiland: (bool * bool) * ErrorLogger * (*retryLocked*) bool -> ParsedInput option
val ParseOneInputFile: TcConfig * Lexhelp.LexResourceManager * string list * string * isLastCompiland: bool * isExe: bool * ErrorLogger * (*retryLocked*) bool -> ParsedInput option

//----------------------------------------------------------------------------
// Type checking and querying the type checking state
Expand Down Expand Up @@ -764,18 +764,18 @@ val TypeCheckOneInputEventually :
-> Eventually<(TcEnv * TopAttribs * TypedImplFile option * ModuleOrNamespaceType) * TcState>

/// Finish the checking of multiple inputs
val TypeCheckMultipleInputsFinish: (TcEnv * TopAttribs * 'T option * 'U) list * TcState -> (TcEnv * TopAttribs * 'T list * 'U list) * TcState
val TypeCheckMultipleInputsFinish: (TcEnv * TopAttribs * 'T option * 'U)[] * TcState -> (TcEnv * TopAttribs * 'T[] * 'U[]) * TcState

/// Finish the checking of a closed set of inputs
val TypeCheckClosedInputSetFinish: TypedImplFile list * TcState -> TcState * TypedImplFile list
val TypeCheckClosedInputSetFinish: TypedImplFile[] * TcState -> TcState * TypedImplFile[]

/// Check a closed set of inputs
val TypeCheckClosedInputSet: CompilationThreadToken * checkForErrors: (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * ParsedInput list -> TcState * TopAttribs * TypedImplFile list * TcEnv
val TypeCheckClosedInputSet: CompilationThreadToken * checkForErrors: (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * ParsedInput[] -> TcState * TopAttribs * TypedImplFile[] * TcEnv

/// Check a single input and finish the checking
val TypeCheckOneInputAndFinishEventually :
checkForErrors: (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * NameResolution.TcResultsSink * TcState * ParsedInput
-> Eventually<(TcEnv * TopAttribs * TypedImplFile list * ModuleOrNamespaceType list) * TcState>
-> Eventually<(TcEnv * TopAttribs * TypedImplFile[] * ModuleOrNamespaceType[]) * TcState>

/// Indicates if we should report a warning
val ReportWarning: FSharpErrorSeverityOptions -> PhasedDiagnostic -> bool
Expand Down Expand Up @@ -812,10 +812,10 @@ type LoadClosure =
UnresolvedReferences: UnresolvedAssemblyReference list

/// The list of all sources in the closure with inputs when available, with associated parse errors and warnings
Inputs: LoadClosureInput list
Inputs: LoadClosureInput[]

/// The original #load references, including those that didn't resolve
OriginalLoadReferences: (range * string * string) list
OriginalLoadReferences: (range * string * string)[]

/// The #nowarns
NoWarns: (string * range list) list
Expand Down
17 changes: 9 additions & 8 deletions src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,12 +1584,12 @@ let GetCoreFsiCompilerOptions (tcConfigB: TcConfigBuilder) =
testingAndQAFlags tcConfigB])
]

let ApplyCommandLineArgs(tcConfigB: TcConfigBuilder, sourceFiles: string list, commandLineArgs) =
let ApplyCommandLineArgs(tcConfigB: TcConfigBuilder, sourceFiles: string[], commandLineArgs) =
try
let sourceFilesAcc = ResizeArray sourceFiles
let collect name = if not (Filename.isDll name) then sourceFilesAcc.Add name
ParseCompilerOptions(collect, GetCoreServiceCompilerOptions tcConfigB, commandLineArgs)
ResizeArray.toList sourceFilesAcc
ResizeArray.toArray sourceFilesAcc
with e ->
errorRecovery e range0
sourceFiles
Expand Down Expand Up @@ -1695,16 +1695,17 @@ let GetInitialOptimizationEnv (tcImports:TcImports, tcGlobals:TcGlobals) =
let optEnv = List.fold (AddExternalCcuToOptimizationEnv tcGlobals) optEnv ccuinfos
optEnv

let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importMap, isIncrementalFragment, optEnv, ccu:CcuThunk, implFiles) =
let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importMap, isIncrementalFragment, optEnv, ccu:CcuThunk, implFiles: _[]) =
// NOTE: optEnv - threads through
//
// Always optimize once - the results of this step give the x-module optimization
// info. Subsequent optimization steps choose representations etc. which we don't
// want to save in the x-module info (i.e. x-module info is currently "high level").
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-start" implFiles
let implFilesArray = List.ofArray implFiles
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-start" implFilesArray
#if DEBUG
if tcConfig.showOptimizationData then
dprintf "Expression prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.implFilesL tcGlobals implFiles)))
dprintf "Expression prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.implFilesL tcGlobals implFilesArray)))

if tcConfig.showOptimizationData then
dprintf "CCU prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.entityL tcGlobals ccu.Contents)))
Expand All @@ -1721,7 +1722,7 @@ let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importM
let results, (optEnvFirstLoop, _, _, _) =
((optEnv0, optEnv0, optEnv0, SignatureHidingInfo.Empty), implFiles)

||> List.mapFold (fun (optEnvFirstLoop, optEnvExtraLoop, optEnvFinalSimplify, hidden) implFile ->
||> Array.mapFold (fun (optEnvFirstLoop, optEnvExtraLoop, optEnvFinalSimplify, hidden) implFile ->

//ReportTime tcConfig ("Initial simplify")
let (optEnvFirstLoop, implFile, implFileOptData, hidden), optimizeDuringCodeGen =
Expand Down Expand Up @@ -1786,10 +1787,10 @@ let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importM

((implFile, optimizeDuringCodeGen), implFileOptData), (optEnvFirstLoop, optEnvExtraLoop, optEnvFinalSimplify, hidden))

let implFiles, implFileOptDatas = List.unzip results
let implFiles, implFileOptDatas = Array.unzip results
let assemblyOptData = Optimizer.UnionOptimizationInfos implFileOptDatas
let tassembly = TypedAssemblyAfterOptimization implFiles
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-end" (List.map fst implFiles)
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-end" (Array.map fst implFiles |> List.ofArray)
ReportTime tcConfig ("Ending Optimizations")
tassembly, assemblyOptData, optEnvFirstLoop

Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/CompileOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ val GetCoreFsiCompilerOptions : TcConfigBuilder -> CompilerOptionBlock list
val GetCoreServiceCompilerOptions : TcConfigBuilder -> CompilerOptionBlock list

/// Apply args to TcConfigBuilder and return new list of source files
val ApplyCommandLineArgs: tcConfigB: TcConfigBuilder * sourceFiles: string list * argv: string list -> string list
val ApplyCommandLineArgs: tcConfigB: TcConfigBuilder * sourceFiles: string[] * argv: string list -> string[]

// Expose the "setters" for some user switches, to enable setting of defaults
val SetOptimizeSwitch : TcConfigBuilder -> OptionSwitch -> unit
Expand All @@ -79,7 +79,7 @@ val GetGeneratedILModuleName : CompilerTarget -> string -> string

val GetInitialOptimizationEnv : TcImports * TcGlobals -> IncrementalOptimizationEnv
val AddExternalCcuToOptimizationEnv : TcGlobals -> IncrementalOptimizationEnv -> ImportedAssembly -> IncrementalOptimizationEnv
val ApplyAllOptimizations : TcConfig * TcGlobals * ConstraintSolver.TcValF * string * ImportMap * bool * IncrementalOptimizationEnv * CcuThunk * TypedImplFile list -> TypedAssemblyAfterOptimization * Optimizer.LazyModuleInfo * IncrementalOptimizationEnv
val ApplyAllOptimizations : TcConfig * TcGlobals * ConstraintSolver.TcValF * string * ImportMap * bool * IncrementalOptimizationEnv * CcuThunk * TypedImplFile[] -> TypedAssemblyAfterOptimization * Optimizer.LazyModuleInfo * IncrementalOptimizationEnv

val CreateIlxAssemblyGenerator : TcConfig * TcImports * TcGlobals * ConstraintSolver.TcValF * CcuThunk -> IlxGen.IlxAssemblyGenerator

Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ and AddBindingsForModuleTopVals _g allocVal _cloc eenv vs =
let AddIncrementalLocalAssemblyFragmentToIlxGenEnv (amap: ImportMap, isIncrementalFragment, g, ccu, fragName, intraAssemblyInfo, eenv, typedImplFiles) =
let cloc = CompLocForFragment fragName ccu
let allocVal = ComputeAndAddStorageForLocalTopVal (amap, g, intraAssemblyInfo, true, NoShadowLocal)
(eenv, typedImplFiles) ||> List.fold (fun eenv (TImplFile (qname, _, mexpr, _, _, _)) ->
(eenv, typedImplFiles) ||> Array.fold (fun eenv (TImplFile (qname, _, mexpr, _, _, _)) ->
let cloc = { cloc with TopImplQualifiedName = qname.Text }
if isIncrementalFragment then
match mexpr with
Expand Down Expand Up @@ -7610,9 +7610,9 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =


let CodegenAssembly cenv eenv mgbuf fileImpls =
if not (isNil fileImpls) then
let a, b = List.frontAndBack fileImpls
let eenv = List.fold (GenTopImpl cenv mgbuf None) eenv a
if not (Array.isEmpty fileImpls) then
let a, b = Array.take (fileImpls.Length - 1) fileImpls, Array.last fileImpls
let eenv = Array.fold (GenTopImpl cenv mgbuf None) eenv a
let eenv = GenTopImpl cenv mgbuf cenv.opts.mainMethodInfo eenv b

// Some constructs generate residue types and bindings. Generate these now. They don't result in any
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/IlxGen.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type public IlxAssemblyGenerator =

/// Register a fragment of the current assembly with the ILX code generator. If 'isIncrementalFragment' is true then the input
/// is assumed to be a fragment 'typed' into FSI.EXE, otherwise the input is assumed to be the result of a '#load'
member AddIncrementalLocalAssemblyFragment: isIncrementalFragment: bool * fragName:string * typedImplFiles: TypedImplFile list -> unit
member AddIncrementalLocalAssemblyFragment: isIncrementalFragment: bool * fragName:string * typedImplFiles: TypedImplFile[] -> unit

/// Generate ILX code for an assembly fragment
member GenerateCode: IlxGenOptions * TypedAssemblyAfterOptimization * Attribs * Attribs -> IlxGenResults
Expand Down
7 changes: 3 additions & 4 deletions src/fsharp/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type cenv =

reportErrors: bool

isLastCompiland : bool*bool
isLastCompiland: bool

isInternalTestSpanStackReferring: bool

Expand Down Expand Up @@ -1790,8 +1790,7 @@ let CheckModuleBinding cenv env (TBind(v, e, _) as bind) =
let isExplicitEntryPoint = HasFSharpAttribute g g.attrib_EntryPointAttribute v.Attribs
if isExplicitEntryPoint then
cenv.entryPointGiven <- true
let isLastCompiland = fst cenv.isLastCompiland
if not isLastCompiland && cenv.reportErrors then
if not cenv.isLastCompiland && cenv.reportErrors then
errorR(Error(FSComp.SR.chkEntryPointUsage(), v.Range))

// Analyze the r.h.s. for the "IsCompiledAsStaticPropertyWithoutField" condition
Expand Down Expand Up @@ -2293,7 +2292,7 @@ and CheckModuleSpec cenv env x =
let env = { env with reflect = env.reflect || HasFSharpAttribute cenv.g cenv.g.attrib_ReflectedDefinitionAttribute mspec.Attribs }
CheckDefnInModule cenv env rhs

let CheckTopImpl (g, amap, reportErrors, infoReader, internalsVisibleToPaths, viewCcu, denv, mexpr, extraAttribs, (isLastCompiland: bool*bool), isInternalTestSpanStackReferring) =
let CheckTopImpl (g, amap, reportErrors, infoReader, internalsVisibleToPaths, viewCcu, denv, mexpr, extraAttribs, (isLastCompiland: bool), isInternalTestSpanStackReferring) =
let cenv =
{ g =g
reportErrors=reportErrors
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/PostInferenceChecks.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val CheckTopImpl:
viewCcu: CcuThunk *
denv: DisplayEnv *
mexpr: ModuleOrNamespaceExprWithSig *
extraAttribs: Attribs * (bool * bool) *
extraAttribs: Attribs *
isLastCompiland: bool *
isInternalTestSpanStackReferring: bool
-> bool * StampMap<AnonRecdTypeInfo>
2 changes: 1 addition & 1 deletion src/fsharp/SyntaxTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ type ParsedImplFileInput =
scopedPragmas: ScopedPragma list *
hashDirectives: ParsedHashDirective list *
modules: SynModuleOrNamespace list *
isLastCompiland: (bool * bool)
isLastCompiland: bool

/// Represents the full syntax tree, file name and other parsing information for a signature file
[<NoEquality; NoComparison>]
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/TypedTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4933,7 +4933,7 @@ type TypedImplFile =
/// Represents a complete typechecked assembly, made up of multiple implementation files.
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
type TypedAssemblyAfterOptimization =
| TypedAssemblyAfterOptimization of (TypedImplFile * (* optimizeDuringCodeGen: *) (Expr -> Expr)) list
| TypedAssemblyAfterOptimization of (TypedImplFile * (* optimizeDuringCodeGen: *) (Expr -> Expr))[]

[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()
Expand Down
Loading