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

Looking at match01 --- flakey test #6673

Merged
merged 4 commits into from
May 13, 2019
Merged
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
3 changes: 3 additions & 0 deletions fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@
<Compile Include="$(FSharpSourcesRoot)/fsharp/QuotationPickler.fs">
<Link>TypedAST/QuotationPickler.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)/fsharp/CompilerGlobalState.fs">
<Link>TypedAST/CompilerGlobalState.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)/fsharp/tast.fs">
<Link>TypedAST/tast.fs</Link>
</Compile>
Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4639,13 +4639,13 @@ type TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAssemblyResolu
match scoref with
| ILScopeRef.Assembly aref -> Some aref
| ILScopeRef.Local | ILScopeRef.Module _ -> error(InternalError("not ILScopeRef.Assembly", rangeStartup)))
fslibCcuInfo.FSharpViewOfMetadata
fslibCcuInfo.FSharpViewOfMetadata

// OK, now we have both mscorlib.dll and FSharp.Core.dll we can create TcGlobals
let tcGlobals = TcGlobals(tcConfig.compilingFslib, ilGlobals, fslibCcu,
tcConfig.implicitIncludeDir, tcConfig.mlCompatibility,
tcConfig.isInteractive, tryFindSysTypeCcu, tcConfig.emitDebugInfoInQuotations,
tcConfig.noDebugData, tcConfig.pathMap)
let tcGlobals = TcGlobals(tcConfig.compilingFslib, ilGlobals, fslibCcu,
tcConfig.implicitIncludeDir, tcConfig.mlCompatibility,
tcConfig.isInteractive, tryFindSysTypeCcu, tcConfig.emitDebugInfoInQuotations,
tcConfig.noDebugData, tcConfig.pathMap)

#if DEBUG
// the global_g reference cell is used only for debug printing
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/CompileOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ val GetInitialTcEnv: assemblyName: string * range * TcConfig * TcImports * TcGlo
[<Sealed>]
/// Represents the incremental type checking state for a set of inputs
type TcState =
member NiceNameGenerator: Ast.NiceNameGenerator
member NiceNameGenerator: NiceNameGenerator

/// The CcuThunk for the current assembly being checked
member Ccu: CcuThunk
Expand All @@ -729,7 +729,7 @@ type TcState =

/// Get the initial type checking state for a set of inputs
val GetInitialTcState:
range * string * TcConfig * TcGlobals * TcImports * Ast.NiceNameGenerator * TcEnv -> TcState
range * string * TcConfig * TcGlobals * TcImports * NiceNameGenerator * TcEnv -> TcState

/// Check one input, returned as an Eventually computation
val TypeCheckOneInputEventually :
Expand Down
16 changes: 7 additions & 9 deletions src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,17 +1572,17 @@ let ApplyCommandLineArgs(tcConfigB: TcConfigBuilder, sourceFiles: string list, c
//----------------------------------------------------------------------------

let showTermFileCount = ref 0
let PrintWholeAssemblyImplementation (tcConfig:TcConfig) outfile header expr =
let PrintWholeAssemblyImplementation g (tcConfig:TcConfig) outfile header expr =
if tcConfig.showTerms then
if tcConfig.writeTermsToFiles then
let filename = outfile + ".terms"
let n = !showTermFileCount
showTermFileCount := n+1
use f = System.IO.File.CreateText (filename + "-" + string n + "-" + header)
Layout.outL f (Layout.squashTo 192 (DebugPrint.implFilesL expr))
Layout.outL f (Layout.squashTo 192 (DebugPrint.implFilesL g expr))
else
dprintf "\n------------------\nshowTerm: %s:\n" header
Layout.outL stderr (Layout.squashTo 192 (DebugPrint.implFilesL expr))
Layout.outL stderr (Layout.squashTo 192 (DebugPrint.implFilesL g expr))
dprintf "\n------------------\n"

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -1680,13 +1680,13 @@ let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importM
// 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 tcConfig outfile "pass-start" implFiles
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-start" implFiles
#if DEBUG
if tcConfig.showOptimizationData then
dprintf "Expression prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.implFilesL implFiles)))
dprintf "Expression prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.implFilesL tcGlobals implFiles)))

if tcConfig.showOptimizationData then
dprintf "CCU prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.entityL ccu.Contents)))
dprintf "CCU prior to optimization:\n%s\n" (Layout.showL (Layout.squashTo 192 (DebugPrint.entityL tcGlobals ccu.Contents)))
#endif

let optEnv0 = optEnv
Expand Down Expand Up @@ -1768,12 +1768,10 @@ let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importM
let implFiles, implFileOptDatas = List.unzip results
let assemblyOptData = Optimizer.UnionOptimizationInfos implFileOptDatas
let tassembly = TypedAssemblyAfterOptimization implFiles
PrintWholeAssemblyImplementation tcConfig outfile "pass-end" (List.map fst implFiles)
PrintWholeAssemblyImplementation tcGlobals tcConfig outfile "pass-end" (List.map fst implFiles)
ReportTime tcConfig ("Ending Optimizations")

tassembly, assemblyOptData, optEnvFirstLoop


//----------------------------------------------------------------------------
// ILX generation
//----------------------------------------------------------------------------
Expand Down
96 changes: 96 additions & 0 deletions src/fsharp/CompilerGlobalState.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

/// Defines the global environment for all type checking.

namespace FSharp.Compiler

open System.Collections.Generic
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.Range
open FSharp.Compiler.PrettyNaming


/// Generates compiler-generated names. Each name generated also includes the StartLine number of the range passed in
/// at the point of first generation.
///
/// This type may be accessed concurrently, though in practice it is only used from the compilation thread.
/// It is made concurrency-safe since a global instance of the type is allocated in tast.fs, and it is good
/// policy to make all globally-allocated objects concurrency safe in case future versions of the compiler
/// are used to host multiple concurrent instances of compilation.
type NiceNameGenerator() =

let lockObj = obj()
let basicNameCounts = new Dictionary<string, int>(100)

member x.FreshCompilerGeneratedName (name, m: range) =
lock lockObj (fun () ->
let basicName = GetBasicNameOfPossibleCompilerGeneratedName name
let n =
match basicNameCounts.TryGetValue basicName with
| true, count -> count
| _ -> 0
let nm = CompilerGeneratedNameSuffix basicName (string m.StartLine + (match n with 0 -> "" | n -> "-" + string n))
basicNameCounts.[basicName] <- n + 1
nm)

member x.Reset () =
lock lockObj (fun () ->
basicNameCounts.Clear()
)

/// Generates compiler-generated names marked up with a source code location, but if given the same unique value then
/// return precisely the same name. Each name generated also includes the StartLine number of the range passed in
/// at the point of first generation.
///
/// This type may be accessed concurrently, though in practice it is only used from the compilation thread.
/// It is made concurrency-safe since a global instance of the type is allocated in tast.fs.
type StableNiceNameGenerator() =

let lockObj = obj()

let names = new Dictionary<(string * int64), string>(100)
let basicNameCounts = new Dictionary<string, int>(100)

member x.GetUniqueCompilerGeneratedName (name, m: range, uniq) =
lock lockObj (fun () ->
let basicName = GetBasicNameOfPossibleCompilerGeneratedName name
let key = basicName, uniq
match names.TryGetValue key with
| true, nm -> nm
| _ ->
let n =
match basicNameCounts.TryGetValue basicName with
| true, c -> c
| _ -> 0
let nm = CompilerGeneratedNameSuffix basicName (string m.StartLine + (match n with 0 -> "" | n -> "-" + string n))
names.[key] <- nm
basicNameCounts.[basicName] <- n + 1
nm
)

member x.Reset () =
lock lockObj (fun () ->
basicNameCounts.Clear()
names.Clear()
)

type internal CompilerGlobalState () =
/// A global generator of compiler generated names
// ++GLOBAL MUTABLE STATE (concurrency safe by locking inside NiceNameGenerator)
let globalNng = NiceNameGenerator()


/// A global generator of stable compiler generated names
// MUTABLE STATE (concurrency safe by locking inside StableNiceNameGenerator)
let globalStableNameGenerator = StableNiceNameGenerator ()

/// A name generator used by IlxGen for static fields, some generated arguments and other things.
/// REVIEW: this will mean the hosted compiler service is not deterministic. We should at least create a new one
/// of these for each compilation.
let ilxgenGlobalNng = NiceNameGenerator ()

member __.NiceNameGenerator = globalNng

member __.StableNameGenerator = globalStableNameGenerator

member __.IlxGenNiceNameGenerator = ilxgenGlobalNng
7 changes: 5 additions & 2 deletions src/fsharp/DetupleArgs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,11 @@ let mkTransform g (f: Val) m tps x1Ntys rty (callPattern, tyfringes: (TType list
let tys1r = List.collect fst tyfringes (* types for collapsed initial r args *)
let tysrN = List.drop tyfringes.Length x1Ntys (* types for remaining args *)
let argtys = tys1r @ tysrN
let fCty = mkLambdaTy tps argtys rty
let transformedVal = mkLocalVal f.Range (globalNng.FreshCompilerGeneratedName (f.LogicalName, f.Range)) fCty topValInfo
let fCty = mkLambdaTy tps argtys rty
let transformedVal =
// Ensure that we have an g.CompilerGlobalState
assert(g.CompilerGlobalState |> Option.isSome)
mkLocalVal f.Range (g.CompilerGlobalState.Value.NiceNameGenerator.FreshCompilerGeneratedName (f.LogicalName, f.Range)) fCty topValInfo
{ transformCallPattern = callPattern
transformedFormals = transformedFormals
transformedVal = transformedVal }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@
<Compile Include="..\QuotationPickler.fs">
<Link>TypedAST\QuotationPickler.fs</Link>
</Compile>
<Compile Include="..\CompilerGlobalState.fs">
<Link>TypedAST\CompilerGlobalState.fs</Link>
</Compile>
<Compile Include="..\tast.fs">
<Link>TypedAST\tast.fs</Link>
</Compile>
Expand Down
Loading