Skip to content

Commit 0ed0442

Browse files
committed
rebase
1 parent 3159664 commit 0ed0442

File tree

76 files changed

+976
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+976
-681
lines changed

eng/Build.ps1

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -362,36 +362,81 @@ function VerifyAssemblyVersionsAndSymbols() {
362362
}
363363
}
364364

365-
function TestUsingMSBuild([string] $testProject, [string] $targetFramework, [string]$testadapterpath, [boolean] $asBackgroundJob = $false) {
365+
function TestUsingMSBuild([string] $testProject, [string] $targetFramework, [string]$testadapterpath, [string] $backgroundJob = "", [string] $settings = "") {
366+
$jobId = if ($backgroundJob) { "_$backgroundJob"} else {""}
366367
$dotnetPath = InitializeDotNetCli
367368
$dotnetExe = Join-Path $dotnetPath "dotnet.exe"
368369
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($testProject)
369-
$testLogPath = "$ArtifactsDir\TestResults\$configuration\${projectName}_$targetFramework.xml"
370-
$testBinLogPath = "$LogDir\${projectName}_$targetFramework.binlog"
371-
$args = "test $testProject -c $configuration -f $targetFramework -v n --test-adapter-path $testadapterpath --logger ""xunit;LogFilePath=$testLogPath"" /bl:$testBinLogPath"
372-
$args += " --blame --results-directory $ArtifactsDir\TestResults\$configuration -p:vstestusemsbuildoutput=false"
370+
$testLogPath = "$ArtifactsDir\TestResults\$configuration\${projectName}_$targetFramework$jobId.xml"
371+
$testBinLogPath = "$LogDir\${projectName}_$targetFramework$jobId.binlog"
372+
$arguments = "test $testProject -c $configuration -f $targetFramework -v n --test-adapter-path $testadapterpath --logger ""xunit;LogFilePath=$testLogPath"" /bl:$testBinLogPath"
373+
$arguments += " --blame --blame-hang-timeout 5minutes --results-directory $ArtifactsDir\TestResults\$configuration -p:vstestusemsbuildoutput=true"
373374

374375
if (-not $noVisualStudio -or $norestore) {
375-
$args += " --no-restore"
376+
$arguments += " --no-restore"
376377
}
377378

378379
if (-not $noVisualStudio) {
379-
$args += " --no-build"
380+
$arguments += " --no-build"
380381
}
381382

382-
if ($asBackgroundJob) {
383-
Write-Host("Starting on the background: $args")
383+
$arguments += " $settings"
384+
385+
if ($backgroundJob) {
386+
Write-Host
387+
Write-Host("Starting on the background: $arguments")
384388
Write-Host("------------------------------------")
385-
$bgJob = Start-Job -ScriptBlock {
386-
& $using:dotnetExe test $using:testProject -c $using:configuration -f $using:targetFramework -v n --test-adapter-path $using:testadapterpath --logger "xunit;LogFilePath=$using:testLogPath" /bl:$using:testBinLogPath --blame --results-directory $using:ArtifactsDir\TestResults\$using:configuration
389+
Start-Job -ScriptBlock {
390+
$argArray = $using:arguments -Split " "
391+
& $using:dotnetExe $argArray
387392
if ($LASTEXITCODE -ne 0) {
388393
throw "Command failed to execute with exit code $($LASTEXITCODE): $using:dotnetExe $using:args"
389394
}
390395
}
391-
return $bgJob
392-
} else{
393-
Write-Host("$args")
394-
Exec-Console $dotnetExe $args
396+
} else {
397+
Write-Host("$arguments")
398+
Exec-Console $dotnetExe $arguments
399+
}
400+
}
401+
402+
function TestSolutionUsingMSBuild([string] $testSolution, [string] $targetFramework, [string] $testadapterpath, [string] $backgroundJob = "", [string] $settings = "") {
403+
$jobId = if ($backgroundJob) { "_$backgroundJob"} else {""}
404+
$dotnetPath = InitializeDotNetCli
405+
$dotnetExe = Join-Path $dotnetPath "dotnet.exe"
406+
$solutionName = [System.IO.Path]::GetFileNameWithoutExtension($testSolution)
407+
$testLogPath = "$ArtifactsDir\TestResults\$configuration\{assembly}.{framework}$jobId.xml"
408+
$testBinLogPath = "$LogDir\${solutionName}_$targetFramework$jobId.binlog"
409+
410+
$arguments = "test"
411+
412+
$arguments += " $testSolution -c $configuration -f $targetFramework --test-adapter-path $testadapterpath -v n --logger ""xunit;LogFilePath=$testLogPath"" /bl:$testBinLogPath"
413+
$arguments += " --blame-hang-timeout 5minutes --results-directory $ArtifactsDir\TestResults\$configuration /p:VsTestUseMSBuildOutput=true"
414+
415+
if (-not $noVisualStudio -or $norestore) {
416+
$arguments += " --no-restore"
417+
}
418+
419+
if (-not $noVisualStudio) {
420+
$arguments += " --no-build"
421+
}
422+
423+
$arguments += " $settings"
424+
425+
if ($backgroundJob) {
426+
Write-Host
427+
Write-Host("Starting on the background: $arguments")
428+
Write-Host("------------------------------------")
429+
Start-Job -ScriptBlock {
430+
$argArray = $using:arguments -Split " "
431+
$argArray += "--no-build"
432+
& $using:dotnetExe $argArray
433+
if ($LASTEXITCODE -ne 0) {
434+
throw "Command failed to execute with exit code $($LASTEXITCODE): $using:dotnetExe $using:args"
435+
}
436+
}
437+
} else {
438+
Write-Host("$arguments")
439+
Exec-Console $dotnetExe $arguments
395440
}
396441
}
397442

@@ -588,32 +633,48 @@ try {
588633
$script:BuildCategory = "Test"
589634
$script:BuildMessage = "Failure running tests"
590635

636+
function Receive($job) {
637+
while($job.HasMoreData) {
638+
Receive-Job $job | Write-Host
639+
Start-Sleep -Seconds 1
640+
}
641+
Receive-Job $job -Wait -ErrorAction Stop
642+
}
643+
591644
if ($testCoreClr) {
592-
$bgJob = TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\" -asBackgroundJob $true
645+
$cpuLimit = if ($ci) { "-m:2 -- xUnit.MaxParallelThreads=0.25x" } else { "" }
646+
TestSolutionUsingMSBuild -testSolution "$RepoRoot\FSharp.sln" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -settings $cpuLimit
647+
}
593648

594-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\"
595-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Service.Tests\"
596-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Private.Scripting.UnitTests\FSharp.Compiler.Private.Scripting.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Private.Scripting.UnitTests\"
597-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Build.UnitTests\"
598-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Core.UnitTests\"
649+
if ($testDesktop -and -not $ci) {
650+
651+
# Split ComponentTests into processes using filter, because it is slow and underutilizes CPU locally.
652+
$bgJob1 = TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -backgroundJob 1 -settings "--filter ExecutionNode=1"
653+
$bgJob2 = TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -backgroundJob 2 -settings "--filter ExecutionNode=2"
654+
$bgJob3 = TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -backgroundJob 3 -settings "--filter ExecutionNode=3"
655+
$bgJob4 = TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -backgroundJob 4 -settings "--filter ExecutionNode=4"
656+
657+
TestSolutionUsingMSBuild -testSolution "$RepoRoot\FSharp.sln" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -settings " --filter ""Project!=FSharpSuite.Tests&Project!=FSharp.Compiler.ComponentTests"" "
658+
# FSharpSuite does most of it's work in external processes, saturating the CPU. It makes sense to run it separately.
659+
TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\"
599660

600-
# Collect output from background jobs
601-
Wait-job $bgJob | out-null
602-
Receive-Job $bgJob -ErrorAction Stop
661+
# Collect output from background jobs
662+
Receive -job $bgJob1
663+
Receive -job $bgJob2
664+
Receive -job $bgJob3
665+
Receive -job $bgJob4
603666
}
604667

605-
if ($testDesktop) {
606-
$bgJob = TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\" -asBackgroundJob $true
668+
if ($testDesktop -and $ci) {
669+
$bgJob = TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\" -backgroundJob 1
607670

608671
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\"
609672
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Service.Tests\"
610673
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Private.Scripting.UnitTests\FSharp.Compiler.Private.Scripting.UnitTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Private.Scripting.UnitTests\"
611674
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Build.UnitTests\"
612675
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Core.UnitTests\"
613676

614-
# Collect output from background jobs
615-
Wait-job $bgJob | out-null
616-
Receive-Job $bgJob -ErrorAction Stop
677+
Receive -job $bgJob
617678
}
618679

619680
if ($testFSharpQA) {

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<MicrosoftNETCoreAppRefVersion>3.1.0</MicrosoftNETCoreAppRefVersion>
185185
<MicrosoftNETCoreILDAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILDAsmVersion>
186186
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILAsmVersion>
187-
<MicrosoftNETTestSdkVersion>17.4.0</MicrosoftNETTestSdkVersion>
187+
<MicrosoftNETTestSdkVersion>17.11.1</MicrosoftNETTestSdkVersion>
188188
<NewtonsoftJsonVersion>13.0.3</NewtonsoftJsonVersion>
189189
<RoslynToolsSignToolVersion>1.0.0-beta2-dev3</RoslynToolsSignToolVersion>
190190
<StreamJsonRpcVersion>2.18.48</StreamJsonRpcVersion>

eng/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ function Test() {
214214
projectname=$(basename -- "$testproject")
215215
projectname="${projectname%.*}"
216216
testlogpath="$artifacts_dir/TestResults/$configuration/${projectname}_$targetframework.xml"
217-
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"xunit;LogFilePath=$testlogpath\" --blame --results-directory $artifacts_dir/TestResults/$configuration -p:vstestusemsbuildoutput=false"
217+
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"xunit;LogFilePath=$testlogpath\" --blame-hang-timeout 5minutes --results-directory $artifacts_dir/TestResults/$configuration -p:vstestusemsbuildoutput=false"
218+
args+=" -- xUnit.MaxParallelThreads=4"
218219
"$DOTNET_INSTALL_DIR/dotnet" $args || exit $?
219220
}
220221

src/Compiler/Driver/GraphChecking/GraphProcessing.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ let processGraphAsync<'Item, 'Result when 'Item: equality and 'Item: comparison>
252252
let rec queueNode node =
253253
Async.Start(
254254
async {
255+
use! _catch = Async.OnCancel(completionSignal.TrySetCanceled >> ignore)
255256
let! res = processNode node |> Async.Catch
256257

257258
match res with

src/Compiler/Driver/fsc.fs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ let SetProcessThreadLocals tcConfigB =
273273
| Some s -> Thread.CurrentThread.CurrentUICulture <- CultureInfo(s)
274274
| None -> ()
275275

276-
if tcConfigB.utf8output then
277-
Console.OutputEncoding <- Encoding.UTF8
278-
279276
let ProcessCommandLineFlags (tcConfigB: TcConfigBuilder, lcidFromCodePage, argv) =
280277
let mutable inputFilesRef = []
281278

@@ -550,6 +547,17 @@ let main1
550547
| Some parallelReferenceResolution -> tcConfigB.parallelReferenceResolution <- parallelReferenceResolution
551548
| None -> ()
552549

550+
if tcConfigB.utf8output && Console.OutputEncoding <> Encoding.UTF8 then
551+
let previousEncoding = Console.OutputEncoding
552+
Console.OutputEncoding <- Encoding.UTF8
553+
554+
disposables.Register(
555+
{ new IDisposable with
556+
member _.Dispose() =
557+
Console.OutputEncoding <- previousEncoding
558+
}
559+
)
560+
553561
// Display the banner text, if necessary
554562
if not bannerAlreadyPrinted then
555563
Console.Write(GetBannerText tcConfigB)
@@ -1242,16 +1250,6 @@ let CompileFromCommandLineArguments
12421250
) =
12431251

12441252
use disposables = new DisposablesTracker()
1245-
let savedOut = Console.Out
1246-
1247-
use _ =
1248-
{ new IDisposable with
1249-
member _.Dispose() =
1250-
try
1251-
Console.SetOut(savedOut)
1252-
with _ ->
1253-
()
1254-
}
12551253

12561254
main1 (
12571255
ctok,

src/Compiler/Interactive/fsi.fs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ type internal FsiStdinSyphon(errorWriter: TextWriter) =
846846
/// Encapsulates functions used to write to outWriter and errorWriter
847847
type internal FsiConsoleOutput(tcConfigB, outWriter: TextWriter, errorWriter: TextWriter) =
848848

849-
let nullOut = new StreamWriter(Stream.Null) :> TextWriter
849+
let nullOut = TextWriter.Null
850850

851851
let fprintfnn (os: TextWriter) fmt =
852852
Printf.kfprintf
@@ -1203,11 +1203,6 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, argv: s
12031203
if tcConfigB.clearResultsCache then
12041204
dependencyProvider.ClearResultsCache(tcConfigB.compilerToolPaths, getOutputDir tcConfigB, reportError rangeCmdArgs)
12051205

1206-
if tcConfigB.utf8output then
1207-
let prev = Console.OutputEncoding
1208-
Console.OutputEncoding <- Encoding.UTF8
1209-
System.AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> Console.OutputEncoding <- prev)
1210-
12111206
do
12121207
let firstArg =
12131208
match sourceFiles with
@@ -4646,6 +4641,20 @@ type FsiEvaluationSession
46464641
with e ->
46474642
warning (e)
46484643

4644+
let restoreEncoding =
4645+
if tcConfigB.utf8output && Console.OutputEncoding <> Text.Encoding.UTF8 then
4646+
let previousEncoding = Console.OutputEncoding
4647+
Console.OutputEncoding <- Encoding.UTF8
4648+
4649+
Some(
4650+
{ new IDisposable with
4651+
member _.Dispose() =
4652+
Console.OutputEncoding <- previousEncoding
4653+
}
4654+
)
4655+
else
4656+
None
4657+
46494658
do
46504659
updateBannerText () // resetting banner text after parsing options
46514660

@@ -4789,6 +4798,7 @@ type FsiEvaluationSession
47894798
member _.Dispose() =
47904799
(tcImports :> IDisposable).Dispose()
47914800
uninstallMagicAssemblyResolution.Dispose()
4801+
restoreEncoding |> Option.iter (fun x -> x.Dispose())
47924802

47934803
/// Load the dummy interaction, load the initial files, and,
47944804
/// if interacting, start the background thread to read the standard input.

src/Compiler/Service/service.fs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ module CompileHelpers =
100100

101101
diagnostics.ToArray(), result
102102

103-
let setOutputStreams execute =
104-
// Set the output streams, if requested
105-
match execute with
106-
| Some(writer, error) ->
107-
Console.SetOut writer
108-
Console.SetError error
109-
| None -> ()
110-
111103
[<Sealed; AutoSerializable(false)>]
112104
// There is typically only one instance of this type in an IDE process.
113105
type FSharpChecker

src/Compiler/Utilities/illib.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module internal PervasiveAutoOpens =
137137
type Async with
138138

139139
static member RunImmediate(computation: Async<'T>, ?cancellationToken) =
140-
let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken
140+
let cancellationToken = defaultArg cancellationToken CancellationToken.None
141141

142142
let ts = TaskCompletionSource<'T>()
143143

src/FSharp.Core/mailbox.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ type Mailbox<'Msg>(cancellationSupported: bool, isThrowExceptionAfterDisposed: b
340340
inboxStore.Clear()
341341

342342
arrivals.Clear()
343-
isDisposed <- true)
343+
isDisposed <- true
344344

345-
if isNotNull pulse then
346-
(pulse :> IDisposable).Dispose()
345+
if isNotNull pulse then
346+
(pulse :> IDisposable).Dispose()
347+
pulse <- null)
347348

348349
#if DEBUG
349350
member x.UnsafeContents = (x.inbox, arrivals, pulse, savedCont) |> box

src/fsi/fsimain.fs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,6 @@ let evaluateSession (argv: string[]) =
358358
let MainMain argv =
359359
ignore argv
360360
let argv = System.Environment.GetCommandLineArgs()
361-
let savedOut = Console.Out
362-
363-
use __ =
364-
{ new IDisposable with
365-
member _.Dispose() =
366-
try
367-
Console.SetOut(savedOut)
368-
with _ ->
369-
()
370-
}
371361

372362
let timesFlag = argv |> Array.exists (fun x -> x = "/times" || x = "--times")
373363

0 commit comments

Comments
 (0)