Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
ba0c05e
Adding AsyncLazy
TIHan May 14, 2021
458c3fc
Trying to get rid of cancellable and eventually use in incrementalbui…
TIHan May 14, 2021
58949ac
remove a lot of use of eventually and cancellable in incremental build
TIHan May 14, 2021
9bc6919
trying
TIHan May 14, 2021
0cec5da
More refactoring
TIHan May 15, 2021
78fbe4d
drastrically less use of ctok
TIHan May 15, 2021
2c57028
fixing build
TIHan May 15, 2021
c8bd0a6
Using reactor for foreground checking
TIHan May 15, 2021
afc5da2
more cleanup
TIHan May 15, 2021
49f39b6
more cleanup
TIHan May 15, 2021
ac91f7f
Properly set a background build
TIHan May 15, 2021
f128d56
fixing build
TIHan May 15, 2021
82a09a3
fixing build
TIHan May 15, 2021
fb4c274
trying to fix it
TIHan May 15, 2021
10759ac
Added Seq.foldAsync
TIHan May 15, 2021
5051b9c
Changes to return 'option' on some service APIs
TIHan May 15, 2021
165c035
fixing tests
TIHan May 15, 2021
3c82b66
fixing surface area test
TIHan May 15, 2021
24d2a9f
reseting lazy async
TIHan May 15, 2021
312577c
minor name change
TIHan May 15, 2021
83e57e4
Trying to cleanup more incremental builder stuff
TIHan May 15, 2021
f762278
fixing a few bugs
TIHan May 15, 2021
c535671
trying to fix tests
TIHan May 15, 2021
88faacb
More cleanup
TIHan May 15, 2021
befd8e8
fixing tests
TIHan May 15, 2021
b82da8e
Fixing build
TIHan May 15, 2021
43682f7
comment updates and adding a finalize
TIHan May 15, 2021
c19dcdd
Minor comment update
TIHan May 15, 2021
9b6b03a
Using run synchronously so it can perform cancellation
TIHan May 15, 2021
6d47c59
cleanup
TIHan May 15, 2021
b80f39b
need to reply
TIHan May 15, 2021
312ef18
Merge remote-tracking branch 'upstream/main' into loop-fix
TIHan May 15, 2021
fa5e3fd
Reverting back to the previous AsyncLazy behavior
TIHan May 15, 2021
ed6f56d
Cleaning up asynclazy
TIHan May 15, 2021
612891a
More comment updates
TIHan May 15, 2021
999ef3e
Remove open
TIHan May 15, 2021
39a1cdd
Adding constraint
TIHan May 15, 2021
2fa9147
Allow setting cultureinfo for async lazy
TIHan May 15, 2021
f272296
Minor update
TIHan May 15, 2021
10cfa1c
re-using compilation globals scope correctly
TIHan May 15, 2021
54e344c
Added foregroundCheckFileCacheAgent
TIHan May 16, 2021
9c0265e
Fixing deadlock
TIHan May 16, 2021
e6b0a3b
Minor fix
TIHan May 16, 2021
fcaf6fe
An incremental build will not invalidate itself if a reference has ch…
TIHan May 16, 2021
36a41ac
Added 'autoInvalidateConfiguration' option to FSharpChecker. Added 'I…
TIHan May 16, 2021
835f94c
Fixing builder
TIHan May 16, 2021
20dfb13
Fixing up-to-date check
TIHan May 16, 2021
3100d89
Update surface area. Renamed IsProjectInvalidated to IsProjectReferen…
TIHan May 16, 2021
2db06b3
fixing build
TIHan May 16, 2021
8768b73
Trying to fix tests
TIHan May 16, 2021
d69a5e9
skip test
TIHan May 16, 2021
07182ca
minor cleanup
TIHan May 18, 2021
e9102d9
Updating surface area. Minor cleanup
TIHan May 18, 2021
b12f76a
Merge branch 'loop-fix' of github.com:TIHan/visualfsharp into loop-fix
TIHan May 18, 2021
1d2bdf0
Update surface area
TIHan May 18, 2021
b255beb
Use the parseLock instead of a mailbox
TIHan May 18, 2021
dcb2209
Added AsyncLazy.fs and AsyncLazyTests.fs. Combined AsyncLazyWeak and …
TIHan May 19, 2021
cce8e04
More cleanup
TIHan May 19, 2021
cb4d8af
Trying to minimize diff
TIHan May 19, 2021
3a12c90
Trying to minimize diff
TIHan May 19, 2021
f705978
Removing ctok in more places
TIHan May 19, 2021
3b96582
Updating baseline. Removing Reactor.fs.
TIHan May 19, 2021
f4ebfdd
Added a comment
TIHan May 19, 2021
51180a4
More cleanup
TIHan May 19, 2021
87ec615
Fixing build
TIHan May 19, 2021
09f0ba6
Fixing build
TIHan May 19, 2021
09a2301
Fixing build
TIHan May 19, 2021
265d16a
Updated baseline
TIHan May 19, 2021
40bd05d
Remove lock
TIHan May 19, 2021
df33476
Fixing tests
TIHan May 20, 2021
d49c032
Trying to fix tests
TIHan May 20, 2021
159d70b
Fixing tests
TIHan May 20, 2021
b71cd47
Revert that
TIHan May 20, 2021
b88b325
Fixing tests
TIHan May 20, 2021
7db2c66
Fixing
TIHan May 20, 2021
71b4696
Minor format change
TIHan May 20, 2021
51f392b
Fixing tests
TIHan May 20, 2021
817c612
no gc.collect
TIHan May 20, 2021
78c5be8
Trying to fix tests
TIHan May 20, 2021
5fc4535
Trying to fix tests
TIHan May 20, 2021
3d31a9c
Using logical
TIHan May 20, 2021
51fb857
trying to fix tests
TIHan May 20, 2021
36b447d
updating test sdk
TIHan May 20, 2021
56e06e9
Fixing tests. Reverting back test sdk
TIHan May 21, 2021
1138166
Merge branch 'main' into loop-fix
TIHan May 21, 2021
0bb511c
Fixing tests
TIHan May 21, 2021
5dbd396
Merge branch 'loop-fix' of github.com:TIHan/visualfsharp into loop-fix
TIHan May 21, 2021
9534202
Fixing tests
TIHan May 21, 2021
40e4997
Fixing test
TIHan May 21, 2021
41377df
TcImports uses Async instead of Cancellable now
TIHan May 21, 2021
aed7934
FrameworkImportCache is now will ensure it only computes once for key
TIHan May 21, 2021
737a3c0
Removing some dependency on ctok
TIHan May 21, 2021
db47317
Removed lock in compiler assert
TIHan May 21, 2021
0cec67e
Added AsyncErrorLogger
TIHan May 22, 2021
8493839
More work on error logger
TIHan May 22, 2021
621b2c1
more error logger work
TIHan May 22, 2021
a437397
merging
TIHan May 22, 2021
24b0d62
Fixed build
TIHan May 22, 2021
088786b
Should be partly working
TIHan May 22, 2021
385ede0
Cleaning up AsyncErrorLogger
TIHan May 22, 2021
b4f6fc1
minor change
TIHan May 22, 2021
d5992b2
minor fix for debug
TIHan May 22, 2021
2756a9e
Using assemblyResolutionGate to lock
TIHan May 22, 2021
d2fc04c
fixing async lazy tests
TIHan May 22, 2021
e1e70de
do not make these type provider tests parallel
TIHan May 22, 2021
e2813f4
do not make these type provider tests parallel
TIHan May 22, 2021
a80051e
make more tests non-parallelizable
TIHan May 22, 2021
4af9ee6
Fixing test
TIHan May 22, 2021
7c33a81
Use getOrCreateBuilder
TIHan May 23, 2021
e24b70d
Make type provider tests non-parallel
TIHan May 23, 2021
0d988e0
Allow cancellation exception to be thrown when evaluating raw contents
TIHan May 24, 2021
ae66383
Refactored AsyncLazy. Added GraphNode and LazyGraphNode.
TIHan May 24, 2021
3112820
Fixing GraphNode
TIHan May 25, 2021
ad3920f
Fixing tests. Adding stack trace info.
TIHan May 25, 2021
42f5ff5
fixing build
TIHan May 25, 2021
51d6c7b
using string
TIHan May 25, 2021
5cb0e63
Merge branch 'main' into loop-fix
TIHan May 25, 2021
55e3b6a
Reactoring build graph
TIHan May 26, 2021
a6a2ab0
More refactoring
TIHan May 26, 2021
84ecc3a
Fixing build
TIHan May 27, 2021
fdb9334
Removing another mutable state
TIHan May 27, 2021
36ec35f
Bigger buffer time in tests
TIHan May 27, 2021
d2dafbb
Ported AsyncLazy from Roslyn
TIHan May 27, 2021
001b754
Merge branch 'main' into loop-fix
TIHan May 27, 2021
5a5ce4d
Fixing build
TIHan May 28, 2021
928af7b
Removed RequestCount
TIHan May 28, 2021
dde34bf
Removed Roslyn AsyncLazy
TIHan May 28, 2021
9f46615
Skipping tests temporarily until linux passes. GraphNode now will ret…
TIHan May 28, 2021
4b44434
slowly re-enable tests
TIHan May 29, 2021
b460498
Re-enable build graph tests
TIHan Jun 2, 2021
fbc54cb
Merge remote-tracking branch 'remote/main' into loop-fix
TIHan Jun 2, 2021
31ae3f9
Remove Thread.Sleep in tests. Add timeout exceptions
TIHan Jun 2, 2021
734cf42
TcImports locking, use lock/token methodology, remove Enventually, re…
Jun 4, 2021
25fe917
fix build
Jun 4, 2021
3f49902
fix build
Jun 4, 2021
e864be7
Fixing build
TIHan Jun 7, 2021
be60f1b
Removed API changes that are returning 'option' in FCS
TIHan Jun 7, 2021
33ae186
Allow single background check for a script
TIHan Jun 7, 2021
50c5732
Fixing build
TIHan Jun 7, 2021
0f6c807
Fixing build
TIHan Jun 7, 2021
b3df4a8
Better handling of scripts
TIHan Jun 7, 2021
35353c8
fix taking semaphore atomically
Jun 7, 2021
98b7d3f
comment
Jun 7, 2021
b18245c
Check for task completed
TIHan Jun 7, 2021
bfc317a
Using explicit continuation options
TIHan Jun 7, 2021
5982dbe
use underscore
TIHan Jun 7, 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
393 changes: 393 additions & 0 deletions src/fsharp/BuildGraph.fs

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions src/fsharp/BuildGraph.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

module internal FSharp.Compiler.BuildGraph

open System
open System.Threading
open System.Threading.Tasks
open FSharp.Compiler.ErrorLogger
open Internal.Utilities.Library

/// This represents the global state established as each task function runs as part of the build.
///
/// Use to reset error and warning handlers.
type CompilationGlobalsScope =
new : ErrorLogger * BuildPhase -> CompilationGlobalsScope
interface IDisposable

/// Represents code that can be run as part of the build graph.
///
/// This is essentially cancellable async code where the only asynchronous waits are on nodes.
/// When a node is evaluated the evaluation is run synchronously on the thread of the
/// first requestor.
[<NoEquality;NoComparison;Sealed>]
type NodeCode<'T>

type Async<'T> with

/// Asynchronously await code in the build graph
static member AwaitNodeCode: node: NodeCode<'T> -> Async<'T>

/// A standard builder for node code.
[<Sealed>]
type NodeCodeBuilder =

member Bind : NodeCode<'T> * ('T -> NodeCode<'U>) -> NodeCode<'U>

member Zero : unit -> NodeCode<unit>

member Delay : (unit -> NodeCode<'T>) -> NodeCode<'T>

member Return : 'T -> NodeCode<'T>

member ReturnFrom : NodeCode<'T> -> NodeCode<'T>

member TryWith : NodeCode<'T> * (exn -> NodeCode<'T>) -> NodeCode<'T>

member TryFinally : NodeCode<'T> * (unit -> unit) -> NodeCode<'T>

member For : xs: 'T seq * binder: ('T -> NodeCode<unit>) -> NodeCode<unit>

member Combine : x1: NodeCode<unit> * x2: NodeCode<'T> -> NodeCode<'T>

/// A limited form 'use' for establishing the compilation globals. (Note
/// that a proper generic 'use' could be implemented but has not currently been necessary)
member Using : CompilationGlobalsScope * (CompilationGlobalsScope -> NodeCode<'T>) -> NodeCode<'T>

/// Specifies code that can be run as part of the build graph.
val node : NodeCodeBuilder

/// Contains helpers to specify code that can be run as part of the build graph.
[<AbstractClass;Sealed>]
type NodeCode =

/// Only used for testing, do not use
static member RunImmediate: computation: NodeCode<'T> * ct: CancellationToken -> 'T

/// Used in places where we don't care about cancellation, e.g. the command line compiler
/// and F# Interactive
static member RunImmediateWithoutCancellation: computation: NodeCode<'T> -> 'T

static member CancellationToken: NodeCode<CancellationToken>

static member Sequential: computations: NodeCode<'T> seq -> NodeCode<'T []>

/// Execute the cancellable computation synchronously using the ambient cancellation token of
/// the NodeCode.
static member FromCancellable: computation: Cancellable<'T> -> NodeCode<'T>

/// Only used for testing, do not use
static member StartAsTask_ForTesting: computation: NodeCode<'T> * ?ct: CancellationToken -> Task<'T>

/// Only used for testing, do not use
static member AwaitWaitHandle_ForTesting: waitHandle: WaitHandle -> NodeCode<bool>

/// Contains helpers related to the build graph
[<RequireQualifiedAccess>]
module internal GraphNode =

/// Allows to specify the language for error messages
val SetPreferredUILang: preferredUiLang: string option -> unit

/// Evaluate the computation, allowing asynchronous waits on existing ongoing evaluations of the
/// same node, and strongly cache the result.
///
/// Once the result has been cached, the computation function will also be removed, or 'null'ed out,
/// as to prevent any references captured by the computation from being strongly held.
[<Sealed>]
type internal GraphNode<'T> =

/// - retryCompute - When set to 'true', subsequent requesters will retry the computation if the first-in request cancels. Retrying computations will have better callstacks.
/// - computation - The computation code to run.
new: retryCompute: bool * computation: NodeCode<'T> -> GraphNode<'T>

/// By default, 'retryCompute' is 'true'.
new : computation: NodeCode<'T> -> GraphNode<'T>

/// Return NodeCode which, when executed, will get the value of the computation if already computed, or
/// await an existing in-progress computation for the node if one exists, or else will synchronously
/// start the computation on the current thread.
member GetOrComputeValue: unit -> NodeCode<'T>

/// Return 'Some' if the computation has already been computed, else None if
/// the computation is in-progress or has not yet been started.
member TryPeekValue: unit -> 'T voption

/// Return 'true' if the computation has already been computed.
member HasValue: bool

/// Return 'true' if the computation is in-progress.
member IsComputing: bool
24 changes: 12 additions & 12 deletions src/fsharp/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5003,8 +5003,8 @@ module TcDeclarations =
// Bind module types
//-------------------------------------------------------------------------

let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synSigDecl: Eventually<TcEnv> =
eventually {
let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synSigDecl: Cancellable<TcEnv> =
cancellable {
try
match synSigDecl with
| SynModuleSigDecl.Exception (edef, m) ->
Expand Down Expand Up @@ -5155,7 +5155,7 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS


and TcSignatureElements cenv parent endm env xml mutRecNSInfo defs =
eventually {
cancellable {
// Ensure the .Deref call in UpdateAccModuleOrNamespaceType succeeds
if cenv.compilingCanonicalFslibModuleType then
let doc = xml.ToXmlDoc(true, Some [])
Expand All @@ -5170,10 +5170,10 @@ and TcSignatureElements cenv parent endm env xml mutRecNSInfo defs =
}

and TcSignatureElementsNonMutRec cenv parent typeNames endm env defs =
Eventually.fold (TcSignatureElementNonMutRec cenv parent typeNames endm) env defs
Cancellable.fold (TcSignatureElementNonMutRec cenv parent typeNames endm) env defs

and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (defs: SynModuleSigDecl list) =
eventually {
cancellable {
let m = match defs with [] -> m | _ -> defs |> List.map (fun d -> d.Range) |> List.reduce unionRanges
let scopem = (defs, m) ||> List.foldBack (fun h m -> unionRanges h.Range m)

Expand Down Expand Up @@ -5227,7 +5227,7 @@ and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (d

and TcModuleOrNamespaceSignatureElementsNonMutRec cenv parent env (id, modKind, defs, m: range, xml) =

eventually {
cancellable {
let endm = m.EndRange // use end of range for errors

// Create the module type that will hold the results of type checking....
Expand Down Expand Up @@ -5287,7 +5287,7 @@ let CheckLetOrDoInNamespace binds m =

/// The non-mutually recursive case for a declaration
let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem env synDecl =
eventually {
cancellable {
cenv.synArgNameGenerator.Reset()
let tpenv = emptyUnscopedTyparEnv

Expand Down Expand Up @@ -5468,7 +5468,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem

/// The non-mutually recursive case for a sequence of declarations
and TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm (defsSoFar, env, envAtEnd) (moreDefs: SynModuleDecl list) =
eventually {
cancellable {
match moreDefs with
| (firstDef :: otherDefs) ->
// Lookahead one to find out the scope of the next declaration.
Expand All @@ -5488,7 +5488,7 @@ and TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm (defsSoFar,

/// The mutually recursive case for a sequence of declarations (and nested modules)
and TcModuleOrNamespaceElementsMutRec (cenv: cenv) parent typeNames m envInitial mutRecNSInfo (defs: SynModuleDecl list) =
eventually {
cancellable {

let m = match defs with [] -> m | _ -> defs |> List.map (fun d -> d.Range) |> List.reduce unionRanges
let scopem = (defs, m) ||> List.foldBack (fun h m -> unionRanges h.Range m)
Expand Down Expand Up @@ -5578,7 +5578,7 @@ and TcMutRecDefsFinish cenv defs m =
TMDefRec(true, tycons, binds, m)

and TcModuleOrNamespaceElements cenv parent endm env xml mutRecNSInfo defs =
eventually {
cancellable {
// Ensure the deref_nlpath call in UpdateAccModuleOrNamespaceType succeeds
if cenv.compilingCanonicalFslibModuleType then
let doc = xml.ToXmlDoc(true, Some [])
Expand Down Expand Up @@ -5798,7 +5798,7 @@ let TypeCheckOneImplFile

let infoReader = InfoReader(g, amap)

eventually {
cancellable {
let cenv =
cenv.Create (g, isScript, niceNameGen, amap, topCcu, false, Option.isSome rootSigOpt,
conditionalDefines, tcSink, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
Expand Down Expand Up @@ -5904,7 +5904,7 @@ let TypeCheckOneImplFile

/// Check an entire signature file
let TypeCheckOneSigFile (g, niceNameGen, amap, topCcu, checkForErrors, conditionalDefines, tcSink, isInternalTestSpanStackReferring) tcEnv (ParsedSigFileInput (_, qualNameOfFile, _, _, sigFileFrags)) =
eventually {
cancellable {
let cenv =
cenv.Create
(g, false, niceNameGen, amap, topCcu, true, false, conditionalDefines, tcSink,
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/CheckDeclarations.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ val TypeCheckOneImplFile :
-> TcEnv
-> ModuleOrNamespaceType option
-> ParsedImplFileInput
-> Eventually<TopAttribs * TypedImplFile * ModuleOrNamespaceType * TcEnv * bool>
-> Cancellable<TopAttribs * TypedImplFile * ModuleOrNamespaceType * TcEnv * bool>

val TypeCheckOneSigFile :
TcGlobals * NiceNameGenerator * ImportMap * CcuThunk * (unit -> bool) * ConditionalDefines option * NameResolution.TcResultsSink * bool
-> TcEnv
-> ParsedSigFileInput
-> Eventually<TcEnv * ModuleOrNamespaceType * bool>
-> Cancellable<TcEnv * ModuleOrNamespaceType * bool>

exception ParameterlessStructCtor of range

Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open FSharp.Compiler.Xml
open FSharp.Compiler.TypedTree
open FSharp.Compiler.BuildGraph

#if !NO_EXTENSIONTYPING
open FSharp.Compiler.ExtensionTyping
Expand Down Expand Up @@ -205,7 +206,7 @@ and IProjectReference =
abstract FileName: string

/// Evaluate raw contents of the assembly file generated by the project
abstract EvaluateRawContents: CompilationThreadToken -> Cancellable<IRawFSharpAssemblyData option>
abstract EvaluateRawContents: unit -> NodeCode<IRawFSharpAssemblyData option>

/// Get the logical timestamp that would be the timestamp of the assembly file generated by the project
///
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.Features
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text
open FSharp.Compiler.BuildGraph

exception FileNameNotResolved of (*filename*) string * (*description of searched locations*) string * range
exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
Expand Down Expand Up @@ -68,7 +69,7 @@ and IProjectReference =
abstract FileName: string

/// Evaluate raw contents of the assembly file generated by the project
abstract EvaluateRawContents: CompilationThreadToken -> Cancellable<IRawFSharpAssemblyData option>
abstract EvaluateRawContents: unit -> NodeCode<IRawFSharpAssemblyData option>

/// Get the logical timestamp that would be the timestamp of the assembly file generated by the project.
///
Expand Down
Loading