fsharp
fsharp copied to clipboard
Fix some possibly buggy usage of `UseDiagnosticsLogger`
Description
There was some odd behavior I noticed while trying to test AsyncLocal diagnostics state.
UseDiagnosticsLogger
creates a diagnostics scope and should restore previous logger on dispose. This should in theory work consistently, pushing and unwinding loggers in the given order. I noticed the disposals often happen out of order, leading to momentarily inconsistent state.
By chance I stumbled upon what I believ are some slight bugs in ParseAndCheckInputs.fs:
https://github.com/dotnet/fsharp/blob/3ec9b18de99808756ea1c577dfc0465b9d219408/src/Compiler/Driver/ParseAndCheckInputs.fs#L1390-L1401 This function returns a cancellable, so the disposables will get disposed immediately instead of participating in the cancellable execution.
Similar situation here: https://github.com/dotnet/fsharp/blob/3ec9b18de99808756ea1c577dfc0465b9d219408/src/Compiler/Driver/ParseAndCheckInputs.fs#L1857-L1881
Disposal happens immediately, leaving us with other global diagnostic logger than expected.
Let's see if fixing this breaks something else.
:warning: Release notes required, but author opted out
[!WARNING] Author opted out of release notes, check is disabled for this pull request. cc @dotnet/fsharp-team-msft
This is only tangentially related, but I replaced the instances where we don't intend to ever unwind:
let _holder = UseDiagnosticsLogger diagnosticsLogger
with
SetThreadDiagnosticsLoggerNoUnwind diagnosticsLogger
which does not allocate a disposable and makes it easier to later test for correct order of unwinds.
/azp run
Azure Pipelines successfully started running 2 pipeline(s).