Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d238d25
Enabling parallel parsing for compiling
TIHan Feb 23, 2021
9724f27
Using a delayed error logger per parsing file
TIHan Feb 23, 2021
53f234a
Added -parallel option
TIHan Feb 24, 2021
bf07e86
Fixing error logger
TIHan Feb 24, 2021
4b7c652
Moved parallel compiler option to be a test option
TIHan Feb 25, 2021
d2198df
Trying to get tests to pass
TIHan Feb 25, 2021
d4ad54c
Remove switch
TIHan Feb 25, 2021
23d81e3
Minor refactor
TIHan Feb 25, 2021
3f32f7d
More refactoring
TIHan Feb 25, 2021
03c8b8a
Add comment
TIHan Feb 25, 2021
51c897b
Initial work for parallel type checking
TIHan Feb 25, 2021
d3c674d
Minor refactor
TIHan Feb 26, 2021
20f285e
Add max
TIHan Feb 26, 2021
f40de5b
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Feb 26, 2021
6b06c3a
Some cleanup
TIHan Feb 26, 2021
c6c54b9
do not use SkipImpl
TIHan Feb 26, 2021
0f39ad4
minor refactor
TIHan Feb 26, 2021
fa5d394
Merged main
TIHan Feb 26, 2021
1236cbf
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Feb 26, 2021
5c5a466
Handling aggregate exceptions from ArrayParallel. Using try/finally t…
TIHan Mar 2, 2021
20e5263
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Mar 2, 2021
e5fa18b
Merged main
TIHan Mar 3, 2021
f408f04
Initial ilx-code-gen parallel work
TIHan Mar 3, 2021
b36f45a
compiles
TIHan Mar 3, 2021
0db7045
Does not work but it tries to use parallelism
TIHan Mar 3, 2021
17f3d9b
Compiles again
TIHan Mar 3, 2021
f4a298c
parallel ilx gen works
TIHan Mar 3, 2021
8b419b3
Merging main
TIHan Mar 4, 2021
bdfcb4b
Merge branch 'parallel-type-checking' into parallel-ilx-codegen
TIHan Mar 4, 2021
c1e89ae
Refactoring a bit
TIHan Mar 5, 2021
311d436
Fix build
TIHan Mar 5, 2021
898f894
Merge branch 'parallel-type-checking' into parallel-ilx-codegen
TIHan Mar 5, 2021
e056a1a
Removing a few LOH allocs
TIHan Mar 5, 2021
d3a1c78
Merge remote-tracking branch 'remote/main' into parallel-ilx-codegen
TIHan May 6, 2021
4adf375
merging
TIHan May 10, 2021
db1b986
Merging main
TIHan Nov 4, 2021
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
60 changes: 44 additions & 16 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module internal FSharp.Compiler.IlxGen
open System.IO
open System.Reflection
open System.Collections.Generic
open System.Collections.Immutable

open FSharp.Compiler.IO
open Internal.Utilities
Expand Down Expand Up @@ -1051,6 +1052,12 @@ and IlxGenEnv =

/// Indicates that the .locals init flag should be set on a method and all its nested methods and lambdas
initLocals: bool

/// Delay code gen for files.
delayCodeGen: bool

/// Collection of code-gen functions where each function represents a file.
delayedFileGen: ImmutableArray<(cenv -> unit) []>
}

override _.ToString() = "<IlxGenEnv>"
Expand Down Expand Up @@ -2489,7 +2496,7 @@ let rec GenExpr cenv cgbuf eenv sp (expr: Expr) sequel =

cenv.exprRecursionDepth <- cenv.exprRecursionDepth - 1

if cenv.exprRecursionDepth = 0 then
if cenv.exprRecursionDepth = 0 && not eenv.delayCodeGen then
ProcessDelayedGenMethods cenv

and ProcessDelayedGenMethods cenv =
Expand Down Expand Up @@ -2713,6 +2720,19 @@ and CodeGenMethodForExpr cenv mgbuf (spReq, entryPointInfo, methodName, eenv, al
(fun cgbuf eenv -> GenExpr cenv cgbuf eenv spReq expr0 sequel0),
expr0.Range)
code

and DelayCodeGenMethodForExpr cenv mgbuf (spReq, entryPointInfo, methodName, eenv, alreadyUsedArgs, expr0, sequel0) =
let ilLazyCode =
lazy
CodeGenMethodForExpr { cenv with exprRecursionDepth = 0; delayedGenMethods = Queue() } mgbuf (spReq, entryPointInfo, methodName, { eenv with delayCodeGen = false }, alreadyUsedArgs, expr0, sequel0)

if cenv.exprRecursionDepth > 0 || eenv.delayCodeGen then
cenv.delayedGenMethods.Enqueue(fun _ -> ilLazyCode.Force() |> ignore)
else
// Eagerly codegen if we are not in an expression depth.
ilLazyCode.Force() |> ignore

ilLazyCode

//--------------------------------------------------------------------------
// Generate sequels
Expand Down Expand Up @@ -6262,8 +6282,14 @@ and GenBindingAfterDebugPoint cenv cgbuf eenv sp (TBind(vspec, rhsExpr, _)) isSt
cgbuf.mgbuf.AddOrMergePropertyDef(ilGetterMethSpec.MethodRef.DeclaringTypeRef, ilPropDef, m)

let ilMethodDef =
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], ilGetterMethSpec.Name, eenv, 0, None, rhsExpr, Return)
let ilMethodBody = MethodBody.IL(lazy ilCode)
let ilLazyCode =
if eenv.delayCodeGen then
DelayCodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], ilGetterMethSpec.Name, eenv, 0, rhsExpr, Return)
else
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], ilGetterMethSpec.Name, eenv, 0, rhsExpr, Return)
lazy ilCode

let ilMethodBody = MethodBody.IL(ilLazyCode)
(mkILStaticMethod ([], ilGetterMethSpec.Name, access, [], mkILReturn ilTy, ilMethodBody)).WithSpecialName
|> AddNonUserCompilerGeneratedAttribs g

Expand Down Expand Up @@ -6828,20 +6854,10 @@ and GenMethodForBinding
| [h] -> Some h
| _ -> None

let ilCodeLazy = lazy CodeGenMethodForExpr cenv mgbuf (SPAlways, tailCallInfo, mspec.Name, eenvForMeth, 0, selfValOpt, bodyExpr, sequel)
let ilLazyCode = DelayCodeGenMethodForExpr cenv mgbuf (SPAlways, tailCallInfo, mspec.Name, eenvForMeth, 0, selfValOpt, bodyExpr, sequel)

// This is the main code generation for most methods
false, MethodBody.IL(ilCodeLazy), false

match ilMethodBody with
| MethodBody.IL(ilCodeLazy) ->
if cenv.exprRecursionDepth > 0 then
cenv.delayedGenMethods.Enqueue(fun _ -> ilCodeLazy.Force() |> ignore)
else
// Eagerly codegen if we are not in an expression depth.
ilCodeLazy.Force() |> ignore
| _ ->
()
false, MethodBody.IL(ilLazyCode), false

// Do not generate DllImport attributes into the code - they are implicit from the P/Invoke
let attrs =
Expand Down Expand Up @@ -7748,7 +7764,9 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: TypedI
let allocVal = ComputeAndAddStorageForLocalTopVal (cenv.amap, g, cenv.intraAssemblyInfo, cenv.opts.isInteractive, NoShadowLocal)
AddBindingsForLocalModuleType allocVal clocCcu eenv mexpr.Type

eenvafter
let eenvfinal = { eenvafter with delayedFileGen = eenvafter.delayedFileGen.Add(cenv.delayedGenMethods |> Array.ofSeq) }
cenv.delayedGenMethods.Clear()
eenvfinal

and GenForceWholeFileInitializationAsPartOfCCtor cenv (mgbuf: AssemblyBuilder) (lazyInitInfo: ResizeArray<_>) tref imports m =
// Authoring a .cctor with effects forces the cctor for the 'initialization' module by doing a dummy store & load of a field
Expand Down Expand Up @@ -8621,6 +8639,14 @@ let CodegenAssembly cenv eenv mgbuf implFiles =
let eenv = List.fold (GenImplFile cenv mgbuf None) eenv a
let eenv = GenImplFile cenv mgbuf cenv.opts.mainMethodInfo eenv b

let genMeths = eenv.delayedFileGen |> Array.ofSeq

genMeths
|> ArrayParallel.iter (fun genMeths ->
genMeths
|> Array.iter (fun gen -> gen cenv)
)

// Some constructs generate residue types and bindings. Generate these now. They don't result in any
// top-level initialization code.
let extraBindings = mgbuf.GrabExtraBindingsToGenerate()
Expand Down Expand Up @@ -8663,6 +8689,8 @@ let GetEmptyIlxGenEnv (g: TcGlobals) ccu =
isInLoop = false
initLocals = true
imports = None
delayCodeGen = true
delayedFileGen = ImmutableArray.Empty
}

type IlxGenResults =
Expand Down
9 changes: 8 additions & 1 deletion src/fsharp/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ type TcState =
{ x with tcsTcSigEnv = tcEnvAtEndOfLastInput
tcsTcImplEnv = tcEnvAtEndOfLastInput }


/// Create the initial type checking state for compiling an assembly
let GetInitialTcState(m, ccuName, tcConfig: TcConfig, tcGlobals, tcImports: TcImports, niceNameGen, tcEnv0, openDecls0) =
ignore tcImports
Expand Down Expand Up @@ -955,6 +954,14 @@ let TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals
TypeCheckOneInput (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp, false)
|> Cancellable.runWithoutCancellation

/// Typecheck a single file (or interactive entry into F# Interactive)
let TypeCheckOneInput (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
TypeCheckOneInputAux(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp false

/// Typecheck a single file but skip it if the file is an impl and has a backing sig
let TypeCheckOneInputSkipImpl (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
TypeCheckOneInputAux(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp true

/// Finish checking multiple files (or one interactive entry into F# Interactive)
let TypeCheckMultipleInputsFinish(results, tcState: TcState) =
let tcEnvsAtEndFile, topAttrs, implFiles, ccuSigsForFiles = List.unzip4 results
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/ParseAndCheckInputs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type TcState =

member CreatesGeneratedProvidedTypes: bool

member RemoveImpl: QualifiedNameOfFile -> TcState

/// Get the initial type checking state for a set of inputs
val GetInitialTcState:
range *
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/absil/bytes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ namespace FSharp.Compiler.IO




4 changes: 4 additions & 0 deletions src/fsharp/lib.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ type DisposablesTracker =
[<RequireQualifiedAccess>]
module ArrayParallel =

val inline iter : ('T -> unit) -> 'T [] -> unit

val inline iteri : (int -> 'T -> unit) -> 'T [] -> unit

val inline map : ('T -> 'U) -> 'T [] -> 'U []

val inline mapi : (int -> 'T -> 'U) -> 'T [] -> 'U []