Skip to content
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
16 changes: 14 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CI and PR triggers
# CI and PR triggers
trigger:
branches:
include:
Expand Down Expand Up @@ -433,6 +433,10 @@ stages:
vs_release:
_configuration: Release
_testKind: testVs
transparent_compiler_release:
_configuration: Release
_testKind: testCoreclr

${{ if eq(variables['Build.Reason'], 'Flaky, disabled, was PullRequest') }}:
inttests_release:
_configuration: Release
Expand All @@ -450,7 +454,15 @@ stages:
env:
NativeToolsOnMachine: true
displayName: Build / Test
condition: ne(variables['_testKind'], 'testIntegration')
condition: and( ne(variables['_testKind'], 'testIntegration'), ne(variables['System.JobName'], 'transparent_compiler_release') )

- script: eng\CIBuild.cmd -compressallmetadata -configuration $(_configuration) -$(_testKind)
env:
TEST_TRANSPARENT_COMPILER: 1
NativeToolsOnMachine: true
displayName: Build / Test Transparent Compiler
condition: and( eq(variables['System.JobName'], 'transparent_compiler_release'), ne(variables['_testKind'], 'testIntegration') )

- script: eng\CIBuild.cmd -compressallmetadata -configuration $(_configuration) -$(_testKind)
env:
NativeToolsOnMachine: true
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24105.3">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24107.1">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>ffac2194c39660f03761ba81bdd6026202942184</Sha>
<Sha>a739c05eb1a5200d7fa2f1e3977b4dc54fdec36a</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ open Internal.Utilities.Hashing

type FSharpUnresolvedReferencesSet = FSharpUnresolvedReferencesSet of UnresolvedAssemblyReference list

[<RequireQualifiedAccess>]
type DocumentSource =
| FileSystem
| Custom of (string -> Async<ISourceText option>)

[<Sealed>]
type DelayedILModuleReader =
val private name: string
Expand Down
6 changes: 6 additions & 0 deletions src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ open FSharp.Compiler.Text

open Internal.Utilities.Collections

[<Experimental "This type is experimental and likely to be removed in the future.">]
[<RequireQualifiedAccess>]
type DocumentSource =
| FileSystem
| Custom of (string -> Async<ISourceText option>)

/// Delays the creation of an ILModuleReader
[<Sealed>]
type DelayedILModuleReader =
Expand Down
42 changes: 35 additions & 7 deletions src/Compiler/Service/FSharpProjectSnapshot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ type FSharpFileSnapshot(FileName: string, Version: string, GetSource: unit -> Ta
|> Task.FromResult
)

static member CreateFromDocumentSource(fileName: string, documentSource: DocumentSource) =

match documentSource with
| DocumentSource.Custom f ->
let version = DateTime.Now.Ticks.ToString()

FSharpFileSnapshot(
fileName,
version,
fun () ->
task {
match! f fileName |> Async.StartAsTask with
| Some source -> return SourceTextNew.ofISourceText source
| None -> return failwith $"Couldn't get source for file {f}"
}
)

| DocumentSource.FileSystem -> FSharpFileSnapshot.CreateFromFileSystem fileName

member public _.FileName = FileName
member _.Version = Version
member _.GetSource() = GetSource()
Expand Down Expand Up @@ -603,13 +622,22 @@ and [<Experimental("This FCS API is experimental and subject to change.")>] FSha
return snapshotAccumulator[options]
}

static member internal GetFileSnapshotFromDisk _ fileName =
FSharpFileSnapshot.CreateFromFileSystem fileName |> async.Return

static member FromOptions(options: FSharpProjectOptions) =
FSharpProjectSnapshot.FromOptions(options, FSharpProjectSnapshot.GetFileSnapshotFromDisk)
static member FromOptions(options: FSharpProjectOptions, documentSource: DocumentSource) =
FSharpProjectSnapshot.FromOptions(
options,
fun _ fileName ->
FSharpFileSnapshot.CreateFromDocumentSource(fileName, documentSource)
|> async.Return
)

static member FromOptions(options: FSharpProjectOptions, fileName: string, fileVersion: int, sourceText: ISourceText) =
static member FromOptions
(
options: FSharpProjectOptions,
fileName: string,
fileVersion: int,
sourceText: ISourceText,
documentSource: DocumentSource
) =

let getFileSnapshot _ fName =
if fName = fileName then
Expand All @@ -619,7 +647,7 @@ and [<Experimental("This FCS API is experimental and subject to change.")>] FSha
fun () -> Task.FromResult(SourceTextNew.ofISourceText sourceText)
)
else
FSharpFileSnapshot.CreateFromFileSystem fName
FSharpFileSnapshot.CreateFromDocumentSource(fName, documentSource)
|> async.Return

FSharpProjectSnapshot.FromOptions(options, getFileSnapshot)
Expand Down
48 changes: 35 additions & 13 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ type internal TransparentCompiler
useSyntaxTreeCache
) as self =

let documentSource =
match getSource with
| Some getSource -> DocumentSource.Custom getSource
| None -> DocumentSource.FileSystem

// Is having just one of these ok?
let lexResourceManager = Lexhelp.LexResourceManager()

Expand Down Expand Up @@ -1474,8 +1479,6 @@ type internal TransparentCompiler
let tcSymbolUses = sink.GetSymbolUses()
let tcOpenDeclarations = sink.GetOpenDeclarations()

let tcDependencyFiles = [] // TODO add as a set to TcIntermediate

// TODO: Apparently creating diagnostics can produce further diagnostics. So let's capture those too. Hopefully there is a more elegant solution...
// Probably diagnostics need to be evaluated during typecheck anyway for proper formatting, which might take care of this too.
let extraLogger = CapturingDiagnosticsLogger("DiagnosticsWhileCreatingDiagnostics")
Expand Down Expand Up @@ -1535,7 +1538,7 @@ type internal TransparentCompiler
projectSnapshot.IsIncompleteTypeCheckEnvironment,
None,
projectSnapshot.ToOptions(),
Array.ofList tcDependencyFiles,
Array.ofList tcInfo.tcDependencyFiles,
creationDiags,
parseResults.Diagnostics,
tcDiagnostics,
Expand Down Expand Up @@ -1934,7 +1937,7 @@ type internal TransparentCompiler
) : NodeCode<FSharpCheckFileAnswer> =
node {
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)
|> NodeCode.AwaitAsync

ignore parseResults
Expand All @@ -1955,7 +1958,7 @@ type internal TransparentCompiler
) : NodeCode<FSharpCheckFileAnswer option> =
node {
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)
|> NodeCode.AwaitAsync

ignore parseResults
Expand Down Expand Up @@ -2007,7 +2010,10 @@ type internal TransparentCompiler
) : NodeCode<seq<range>> =
node {
ignore canInvalidateProject
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync

let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

return! this.FindReferencesInFile(fileName, snapshot.ProjectSnapshot, symbol, userOpName)
}
Expand All @@ -2020,7 +2026,10 @@ type internal TransparentCompiler

member this.GetAssemblyData(options: FSharpProjectOptions, fileName, userOpName: string) : NodeCode<ProjectAssemblyDataResult> =
node {
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

return! this.GetAssemblyData(snapshot.ProjectSnapshot, fileName, userOpName)
}

Expand All @@ -2039,7 +2048,9 @@ type internal TransparentCompiler
userOpName: string
) : NodeCode<FSharpParseFileResults * FSharpCheckFileResults> =
node {
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

match! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, userOpName) with
| parseResult, FSharpCheckFileAnswer.Succeeded checkResult -> return parseResult, checkResult
Expand All @@ -2053,7 +2064,10 @@ type internal TransparentCompiler
userOpName: string
) : NodeCode<FSharpParseFileResults> =
node {
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

return! this.ParseFile(fileName, snapshot.ProjectSnapshot, userOpName)
}

Expand All @@ -2068,7 +2082,7 @@ type internal TransparentCompiler
ignore builder

let! snapshot =
FSharpProjectSnapshot.FromOptions(options, fileName, 1, sourceText)
FSharpProjectSnapshot.FromOptions(options, fileName, 1, sourceText, documentSource)
|> NodeCode.AwaitAsync

match! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, "GetCachedCheckFileResult") with
Expand Down Expand Up @@ -2118,7 +2132,11 @@ type internal TransparentCompiler
) : NodeCode<EditorServices.SemanticClassificationView option> =
node {
ignore userOpName
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync

let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

return! ComputeSemanticClassification(fileName, snapshot.ProjectSnapshot)
}

Expand All @@ -2141,7 +2159,7 @@ type internal TransparentCompiler
) : NodeCode<FSharpParseFileResults * FSharpCheckFileAnswer> =
node {
let! snapshot =
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)
|> NodeCode.AwaitAsync

return! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, userOpName)
Expand All @@ -2153,7 +2171,11 @@ type internal TransparentCompiler
member this.ParseAndCheckProject(options: FSharpProjectOptions, userOpName: string) : NodeCode<FSharpCheckProjectResults> =
node {
ignore userOpName
let! snapshot = FSharpProjectSnapshot.FromOptions options |> NodeCode.AwaitAsync

let! snapshot =
FSharpProjectSnapshot.FromOptions(options, documentSource)
|> NodeCode.AwaitAsync

return! ComputeParseAndCheckProject snapshot.ProjectSnapshot
}

Expand Down
5 changes: 0 additions & 5 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ open FSharp.Compiler.Text.Range
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.BuildGraph

[<RequireQualifiedAccess>]
type DocumentSource =
| FileSystem
| Custom of (string -> Async<ISourceText option>)

/// Callback that indicates whether a requested result has become obsolete.
[<NoComparison; NoEquality>]
type IsResultObsolete = IsResultObsolete of (unit -> bool)
Expand Down
6 changes: 0 additions & 6 deletions src/Compiler/Service/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open FSharp.Compiler.Tokenization

[<Experimental "This type is experimental and likely to be removed in the future.">]
[<RequireQualifiedAccess>]
type DocumentSource =
| FileSystem
| Custom of (string -> Async<ISourceText option>)

/// Used to parse and check F# source code.
[<Sealed; AutoSerializable(false)>]
type public FSharpChecker =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type internal EventRecorder<'a, 'b, 'c when 'a : equality and 'b : equality>(mem
let actual = events |> Seq.toArray
Assert.Equal<_ array>(expected, actual)

member _.Sequence = events |> Seq.map id


[<Fact>]
let ``Basics``() =
Expand All @@ -63,10 +65,8 @@ let ``Basics``() =
return key * 2
}

let eventLog = ConcurrentBag()

let memoize = AsyncMemoize<int, int, int>()
memoize.OnEvent(fun (e, (_label, k, _version)) -> eventLog.Add (e, k))
let events = EventRecorder(memoize)

let result =
seq {
Expand All @@ -84,7 +84,9 @@ let ``Basics``() =

Assert.Equal<int array>(expected, result)

let groups = eventLog |> Seq.groupBy snd |> Seq.toList
(waitUntil (events.CountOf Finished) 3).Wait()

let groups = events.Sequence |> Seq.groupBy snd |> Seq.toList
Assert.Equal(3, groups.Length)
for key, events in groups do
Assert.Equal<Set<(JobEvent * int)>>(Set [ Requested, key; Started, key; Finished, key ], Set events)
Expand Down
Loading