Skip to content

Commit c032cc3

Browse files
committed
deterministic parallel ilxgen
1 parent 0c4e421 commit c032cc3

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ type CompileLocation =
368368
Enclosing: string list
369369

370370
QualifiedNameOfFile: string
371+
372+
Range: range
371373
}
372374

373375
//--------------------------------------------------------------------------
@@ -388,6 +390,7 @@ let CompLocForFragment fragName (ccu: CcuThunk) =
388390
Scope = ccu.ILScopeRef
389391
Namespace = None
390392
Enclosing = []
393+
Range = range0
391394
}
392395

393396
let CompLocForCcu (ccu: CcuThunk) = CompLocForFragment ccu.AssemblyName ccu
@@ -406,7 +409,7 @@ let CompLocForSubModuleOrNamespace cloc (submod: ModuleOrNamespace) =
406409
Namespace = Some(mkTopName cloc.Namespace n)
407410
}
408411

409-
let CompLocForFixedPath fragName qname (CompPath(sref, _, cpath)) =
412+
let CompLocForFixedPath fragName qname m (CompPath(sref, _, cpath)) =
410413
let ns, t =
411414
cpath
412415
|> List.takeUntil (fun (_, mkind) ->
@@ -425,10 +428,11 @@ let CompLocForFixedPath fragName qname (CompPath(sref, _, cpath)) =
425428
Scope = sref
426429
Namespace = ns
427430
Enclosing = encl
431+
Range = m
428432
}
429433

430434
let CompLocForFixedModule fragName qname (mspec: ModuleOrNamespace) =
431-
let cloc = CompLocForFixedPath fragName qname mspec.CompilationPath
435+
let cloc = CompLocForFixedPath fragName qname mspec.Range mspec.CompilationPath
432436
let cloc = CompLocForSubModuleOrNamespace cloc mspec
433437
cloc
434438

@@ -2333,8 +2337,11 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
23332337
MemoizationTable<CompileLocation * int, ILTypeSpec>(
23342338
"rawDataValueTypeGenerator",
23352339
(fun (cloc, size) ->
2336-
let name =
2337-
CompilerGeneratedName("T" + string (newUnique ()) + "_" + string size + "Bytes") // Type names ending ...$T<unique>_37Bytes
2340+
2341+
let unique =
2342+
g.CompilerGlobalState.Value.IlxGenNiceNameGenerator.IncrementOnly("@T", cloc.Range)
2343+
2344+
let name = CompilerGeneratedName $"T{unique}_{size}Bytes" // Type names ending ...$T<unique>_37Bytes
23382345

23392346
let vtdef = mkRawDataValueTypeDef g.iltyp_ValueType (name, size, 0us)
23402347
let vtref = NestedTypeRefForCompLoc cloc vtdef.Name
@@ -2390,7 +2397,12 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
23902397
// Byte array literals require a ValueType of size the required number of bytes.
23912398
// With fsi.exe, S.R.Emit TypeBuilder CreateType has restrictions when a ValueType VT is nested inside a type T, and T has a field of type VT.
23922399
// To avoid this situation, these ValueTypes are generated under the private implementation rather than in the current cloc. [was bug 1532].
2393-
let cloc = CompLocForPrivateImplementationDetails cloc
2400+
let cloc =
2401+
if cenv.options.isInteractive then
2402+
CompLocForPrivateImplementationDetails cloc
2403+
else
2404+
cloc
2405+
23942406
rawDataValueTypeGenerator.Apply((cloc, size))
23952407

23962408
member _.GenerateAnonType(genToStringMethod, anonInfo: AnonRecdTypeInfo) =
@@ -2754,7 +2766,11 @@ let GenConstArray cenv (cgbuf: CodeGenBuffer) eenv ilElementType (data: 'a[]) (w
27542766
CG.EmitInstrs cgbuf (pop 0) (Push [ ilArrayType ]) [ mkLdcInt32 0; I_newarr(ILArrayShape.SingleDimensional, ilElementType) ]
27552767
else
27562768
let vtspec = cgbuf.mgbuf.GenerateRawDataValueType(eenv.cloc, bytes.Length)
2757-
let ilFieldName = CompilerGeneratedName("field" + string (newUnique ()))
2769+
//let fi = eenv.cloc.Range.FileIndex
2770+
let unique =
2771+
g.CompilerGlobalState.Value.IlxGenNiceNameGenerator.IncrementOnly("@field", eenv.cloc.Range)
2772+
2773+
let ilFieldName = CompilerGeneratedName $"field{unique}"
27582774
let fty = ILType.Value vtspec
27592775

27602776
let ilFieldDef =
@@ -10417,6 +10433,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: Checke
1041710433
cloc =
1041810434
{ eenv.cloc with
1041910435
TopImplQualifiedName = qname.Text
10436+
Range = m
1042010437
}
1042110438
}
1042210439

src/Compiler/Driver/OptimizeInputs.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ let GenerateIlxCode
577577
isInteractive = tcConfig.isInteractive
578578
isInteractiveItExpr = isInteractiveItExpr
579579
alwaysCallVirt = tcConfig.alwaysCallVirt
580-
parallelIlxGenEnabled = tcConfig.parallelIlxGen && not tcConfig.deterministic
580+
parallelIlxGenEnabled = tcConfig.parallelIlxGen
581581
}
582582

583583
ilxGenerator.GenerateCode(ilxGenOpts, optimizedImpls, topAttrs.assemblyAttrs, topAttrs.netModuleAttrs)

src/Compiler/TypedTree/CompilerGlobalState.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ type NiceNameGenerator() =
2121
let basicNameCounts = ConcurrentDictionary<struct (string * int), int ref>(max Environment.ProcessorCount 1, 127)
2222
// Cache this as a delegate.
2323
let basicNameCountsAddDelegate = Func<struct (string * int), int ref>(fun _ -> ref 0)
24-
25-
member _.FreshCompilerGeneratedNameOfBasicName (basicName, m: range) =
24+
25+
let increment basicName (m: range) =
2626
let key = struct (basicName, m.FileIndex)
2727
let countCell = basicNameCounts.GetOrAdd(key, basicNameCountsAddDelegate)
28-
let count = Interlocked.Increment(countCell)
29-
30-
CompilerGeneratedNameSuffix basicName (string m.StartLine + (match (count-1) with 0 -> "" | n -> "-" + string n))
28+
Interlocked.Increment(countCell)
29+
30+
member _.FreshCompilerGeneratedNameOfBasicName (basicName, m: range) =
31+
let count = increment basicName m
32+
CompilerGeneratedNameSuffix basicName (string m.StartLine + (match (count - 1) with 0 -> "" | n -> "-" + string n))
3133

3234
member this.FreshCompilerGeneratedName (name, m: range) =
3335
this.FreshCompilerGeneratedNameOfBasicName (GetBasicNameOfPossibleCompilerGeneratedName name, m)
3436

37+
member _.IncrementOnly(name: string, m: range) = increment name m
38+
3539
/// Generates compiler-generated names marked up with a source code location, but if given the same unique value then
3640
/// return precisely the same name. Each name generated also includes the StartLine number of the range passed in
3741
/// at the point of first generation.

src/Compiler/TypedTree/CompilerGlobalState.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type NiceNameGenerator =
1717

1818
new: unit -> NiceNameGenerator
1919
member FreshCompilerGeneratedName: name: string * m: range -> string
20+
member IncrementOnly: name: string * m: range -> int
2021

2122
/// Generates compiler-generated names marked up with a source code location, but if given the same unique value then
2223
/// return precisely the same name. Each name generated also includes the StartLine number of the range passed in

0 commit comments

Comments
 (0)