Skip to content
Merged
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
e5b3131
Transparent Compiler Tests
0101 Jan 25, 2024
44a2f66
Fail early with proper error message when no input files are specified
0101 Jan 25, 2024
e522b12
We don't guarantee the ordering of symbols
0101 Jan 25, 2024
f97683f
update
0101 Jan 29, 2024
96f5b51
Fix format specifiers in results
0101 Jan 31, 2024
53bd38b
Merge remote-tracking branch 'upstream/main' into transparent-compile…
0101 Jan 31, 2024
fb99f36
more fixes
0101 Jan 31, 2024
6d7a4f5
Remove redundant parsing errors
0101 Jan 31, 2024
e0bedf1
fix fuzzing tests
0101 Jan 31, 2024
d7514a0
Added support for other refernce types
0101 Feb 1, 2024
af949ed
surfacearea
0101 Feb 1, 2024
8dcf23c
deduplicate diagnostics
0101 Feb 1, 2024
4432092
f
0101 Feb 1, 2024
670a5fa
Merge branch 'main' into transparent-compiler-tests
0101 Feb 1, 2024
9663c3b
revert test config
0101 Feb 1, 2024
f509f2d
docs
0101 Feb 2, 2024
1fe0323
surfacearea
0101 Feb 2, 2024
d69f971
fix release notes
0101 Feb 2, 2024
d987d23
uncomment
0101 Feb 2, 2024
b43feb1
Merge branch 'main' into transparent-compiler-tests
0101 Feb 2, 2024
2db0a52
Merge branch 'tc-fixes-2' into transparent-compiler-tests
0101 Feb 2, 2024
34231cb
Merge remote-tracking branch 'upstream/main' into transparent-compile…
0101 Feb 8, 2024
ff358b9
Plug in dependency files
0101 Feb 8, 2024
b6d9b9d
Merge branch 'main' into transparent-compiler-tests
0101 Feb 8, 2024
f176a0d
pipeline update
0101 Feb 8, 2024
f9d7f3f
Merge branch 'main' into transparent-compiler-tests
0101 Feb 8, 2024
deac66c
more tests, separating pipeline from experimental features
0101 Feb 8, 2024
0664ffe
Use DocumentSource when creating snapshot from options
0101 Feb 8, 2024
1d415dd
Merge branch 'main' into transparent-compiler-tests
0101 Feb 8, 2024
665b909
stabilize AsyncMemoize.Basics test
0101 Feb 8, 2024
3656a73
surfacearea
0101 Feb 8, 2024
57d13b5
revert test
0101 Feb 8, 2024
a919193
f
0101 Feb 8, 2024
822b6ab
Merge branch 'main' into transparent-compiler-tests
0101 Feb 8, 2024
4223425
un-hardcode seed
0101 Feb 9, 2024
bf360f9
rename
0101 Feb 9, 2024
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ let fuzzingTest seed (project: SyntheticProject) = task {
[<InlineData(SignatureFiles.Some)>]
let Fuzzing signatureFiles =

let seed = 1106087513
let seed = System.Random().Next()
let rng = System.Random(int seed)

let fileCount = 30
Expand Down Expand Up @@ -711,7 +711,6 @@ type GiraffeTheoryAttribute() =
[<InlineData false>]
let GiraffeFuzzing signatureFiles =
let seed = System.Random().Next()
//let seed = 1044159179

let giraffeDir = if signatureFiles then giraffeSignaturesDir else giraffeDir
let giraffeTestsDir = if signatureFiles then giraffeSignaturesTestsDir else giraffeTestsDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module TyparNameTests =
(additionalFile: SourceCodeFileKind)
: string array =
let typeCheckResult =
cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject false false
cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject false CompilerAssertHelpers.UseTransparentCompiler

assert (Array.isEmpty typeCheckResult.Diagnostics)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,7 @@ FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: Boolean Equals(
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: Boolean IsSignatureFile
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: Boolean get_IsSignatureFile()
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: FSharpFileSnapshot Create(System.String, System.String, Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.Threading.Tasks.Task`1[FSharp.Compiler.Text.ISourceTextNew]])
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: FSharpFileSnapshot CreateFromDocumentSource(System.String, FSharp.Compiler.CodeAnalysis.DocumentSource)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: FSharpFileSnapshot CreateFromFileSystem(System.String)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: Int32 GetHashCode()
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot: System.String FileName
Expand Down Expand Up @@ -2333,9 +2334,9 @@ FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: FSharpProjec
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: FSharpProjectIdentifier get_Identifier()
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: FSharpProjectSnapshot Create(System.String, Microsoft.FSharp.Core.FSharpOption`1[System.String], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+ReferenceOnDisk], Microsoft.FSharp.Collections.FSharpList`1[System.String], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpReferencedProjectSnapshot], Boolean, Boolean, System.DateTime, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet], Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[FSharp.Compiler.Text.Range,System.String,System.String]], Microsoft.FSharp.Core.FSharpOption`1[System.Int64])
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: FSharpProjectSnapshot Replace(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot])
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot] FromOptions(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot] FromOptions(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, FSharp.Compiler.CodeAnalysis.DocumentSource)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot] FromOptions(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, Microsoft.FSharp.Core.FSharpFunc`2[FSharp.Compiler.CodeAnalysis.FSharpProjectOptions,Microsoft.FSharp.Core.FSharpFunc`2[System.String,Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpFileSnapshot]]], Microsoft.FSharp.Core.FSharpOption`1[System.Collections.Generic.Dictionary`2[FSharp.Compiler.CodeAnalysis.FSharpProjectOptions,FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot]])
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot] FromOptions(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, System.String, Int32, FSharp.Compiler.Text.ISourceText)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: Microsoft.FSharp.Control.FSharpAsync`1[FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot] FromOptions(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, System.String, Int32, FSharp.Compiler.Text.ISourceText, FSharp.Compiler.CodeAnalysis.DocumentSource)
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: System.String Label
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpProjectSnapshot: System.String get_Label()
FSharp.Compiler.CodeAnalysis.ProjectSnapshot+FSharpReferencedProjectSnapshot+FSharpReference: FSharpProjectSnapshot get_snapshot()
Expand Down
Loading