Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Feb 9, 2024
2 parents d62ec6e + b897908 commit 7dd40ee
Show file tree
Hide file tree
Showing 50 changed files with 517 additions and 404 deletions.
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 @@ -82,6 +82,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 @@ -604,13 +623,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 @@ -620,7 +648,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
36 changes: 23 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 @@ -1470,8 +1475,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 @@ -1531,7 +1534,7 @@ type internal TransparentCompiler
projectSnapshot.IsIncompleteTypeCheckEnvironment,
None,
projectSnapshot.ToOptions(),
Array.ofList tcDependencyFiles,
Array.ofList tcInfo.tcDependencyFiles,
creationDiags,
parseResults.Diagnostics,
tcDiagnostics,
Expand Down Expand Up @@ -1931,7 +1934,7 @@ type internal TransparentCompiler
userOpName: string
) : Async<FSharpCheckFileAnswer> =
async {
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)

ignore parseResults

Expand All @@ -1950,7 +1953,7 @@ type internal TransparentCompiler
userOpName: string
) : Async<FSharpCheckFileAnswer option> =
async {
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)

ignore parseResults

Expand Down Expand Up @@ -2001,7 +2004,8 @@ type internal TransparentCompiler
) : Async<seq<range>> =
async {
ignore canInvalidateProject
let! snapshot = FSharpProjectSnapshot.FromOptions options

let! snapshot = FSharpProjectSnapshot.FromOptions(options, documentSource)

return! this.FindReferencesInFile(fileName, snapshot.ProjectSnapshot, symbol, userOpName)
}
Expand All @@ -2014,7 +2018,8 @@ type internal TransparentCompiler

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

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

Expand All @@ -2033,7 +2038,7 @@ type internal TransparentCompiler
userOpName: string
) : Async<FSharpParseFileResults * FSharpCheckFileResults> =
async {
let! snapshot = FSharpProjectSnapshot.FromOptions options
let! snapshot = FSharpProjectSnapshot.FromOptions(options, documentSource)

match! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, userOpName) with
| parseResult, FSharpCheckFileAnswer.Succeeded checkResult -> return parseResult, checkResult
Expand All @@ -2047,7 +2052,8 @@ type internal TransparentCompiler
userOpName: string
) : Async<FSharpParseFileResults> =
async {
let! snapshot = FSharpProjectSnapshot.FromOptions options
let! snapshot = FSharpProjectSnapshot.FromOptions(options, documentSource)

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

Expand All @@ -2061,7 +2067,7 @@ type internal TransparentCompiler
async {
ignore builder

let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, 1, sourceText)
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, 1, sourceText, documentSource)

match! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, "GetCachedCheckFileResult") with
| parseResult, FSharpCheckFileAnswer.Succeeded checkResult -> return Some(parseResult, checkResult)
Expand Down Expand Up @@ -2110,7 +2116,9 @@ type internal TransparentCompiler
) : Async<EditorServices.SemanticClassificationView option> =
async {
ignore userOpName
let! snapshot = FSharpProjectSnapshot.FromOptions options

let! snapshot = FSharpProjectSnapshot.FromOptions(options, documentSource)

return! ComputeSemanticClassification(fileName, snapshot.ProjectSnapshot)
}

Expand All @@ -2132,7 +2140,7 @@ type internal TransparentCompiler
userOpName: string
) : Async<FSharpParseFileResults * FSharpCheckFileAnswer> =
async {
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText)
let! snapshot = FSharpProjectSnapshot.FromOptions(options, fileName, fileVersion, sourceText, documentSource)

return! this.ParseAndCheckFileInProject(fileName, snapshot.ProjectSnapshot, userOpName)
}
Expand All @@ -2143,7 +2151,9 @@ type internal TransparentCompiler
member this.ParseAndCheckProject(options: FSharpProjectOptions, userOpName: string) : Async<FSharpCheckProjectResults> =
async {
ignore userOpName
let! snapshot = FSharpProjectSnapshot.FromOptions options

let! snapshot = FSharpProjectSnapshot.FromOptions(options, documentSource)

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 @@ -76,26 +76,23 @@ extends [runtime]System.Object
}
.method assembly specialname static class [runtime]System.Tuple`2<bool,int32>
get_patternInput@9() cil managed
.method assembly specialname static class [runtime]System.Tuple`2<bool,int32> get_patternInput@9() cil managed
{
.maxstack 8
IL_0000: ldsfld class [runtime]System.Tuple`2<bool,int32> '<StartupCode$assembly>'.$OutOptionalTests::patternInput@9
IL_0005: ret
}
.method assembly specialname static int32
get_outArg@9() cil managed
.method assembly specialname static int32 get_outArg@9() cil managed
{
.maxstack 8
IL_0000: ldsfld int32 '<StartupCode$assembly>'.$OutOptionalTests::outArg@9
IL_0005: ret
}
.method assembly specialname static void
set_outArg@9(int32 'value') cil managed
.method assembly specialname static void set_outArg@9(int32 'value') cil managed
{
.maxstack 8
Expand All @@ -104,26 +101,23 @@ extends [runtime]System.Object
IL_0006: ret
}
.method assembly specialname static class [runtime]System.Tuple`2<bool,int32>
'get_patternInput@10-1'() cil managed
.method assembly specialname static class [runtime]System.Tuple`2<bool,int32> 'get_patternInput@10-1'() cil managed
{
.maxstack 8
IL_0000: ldsfld class [runtime]System.Tuple`2<bool,int32> '<StartupCode$assembly>'.$OutOptionalTests::'patternInput@10-1'
IL_0005: ret
}
.method assembly specialname static int32
'get_outArg@10-1'() cil managed
.method assembly specialname static int32 'get_outArg@10-1'() cil managed
{
.maxstack 8
IL_0000: ldsfld int32 '<StartupCode$assembly>'.$OutOptionalTests::'outArg@10-1'
IL_0005: ret
}
.method assembly specialname static void
'set_outArg@10-1'(int32 'value') cil managed
.method assembly specialname static void 'set_outArg@10-1'(int32 'value') cil managed
{
.maxstack 8
Expand Down Expand Up @@ -174,8 +168,7 @@ extends [runtime]System.Object
.custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
.method private specialname rtspecialname static
void .cctor() cil managed
.method private specialname rtspecialname static void .cctor() cil managed
{
.maxstack 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,7 @@ let main _ =
|> shouldSucceed
|> verifyIL [
"""
.method public specialname static class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1<class [FSharp.Core]Microsoft.FSharp.Core.Unit>
'|GoodPotato|_|'<(class [Potato]Potato.Lib/IPotato`1<!!T>) T>(!!T x) cil managed
.method public specialname static class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1<class [FSharp.Core]Microsoft.FSharp.Core.Unit> '|GoodPotato|_|'<(class [Potato]Potato.Lib/IPotato`1<!!T>) T>(!!T x) cil managed
{
.maxstack 8
Expand Down

0 comments on commit 7dd40ee

Please sign in to comment.