Skip to content

Commit b3c7a76

Browse files
committed
wip
1 parent ccac85f commit b3c7a76

22 files changed

+92
-168
lines changed

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,8 @@ type PhasedDiagnostic with
405405
(severity = FSharpDiagnosticSeverity.Info && level > 0)
406406
|| (severity = FSharpDiagnosticSeverity.Warning && level >= x.WarningLevel)
407407

408-
type PhasedDiagnosticWithSeverity with
409408
member x.AdjustSeverity(options) =
410-
let {
411-
PhasedDiagnostic = x
412-
Severity = severity
413-
} =
414-
x
415-
409+
let severity = x.Severity
416410
let n = x.Number
417411

418412
let localWarnon () = WarnScopes.IsWarnon options n x.Range
@@ -2014,7 +2008,7 @@ type PhasedDiagnostic with
20142008
x.Exception.Output(buf, suggestNames)
20152009
let message = buf.ToString()
20162010
let exn = DiagnosticWithText(x.Number, message, m)
2017-
{ Exception = exn; Phase = x.Phase }
2011+
{ x with Exception = exn }
20182012
| None -> x
20192013

20202014
let SanitizeFileName fileName implicitIncludeDir =
@@ -2320,7 +2314,7 @@ type DiagnosticsLoggerFilteringByScopedNowarn(diagnosticOptions: FSharpDiagnosti
23202314

23212315
let mutable realErrorPresent = false
23222316

2323-
override _.DiagnosticSink(diagnostic: PhasedDiagnosticWithSeverity) =
2317+
override _.DiagnosticSink(diagnostic: PhasedDiagnostic) =
23242318

23252319
if diagnostic.Severity = FSharpDiagnosticSeverity.Error then
23262320
realErrorPresent <- true

src/Compiler/Driver/CompilerDiagnostics.fsi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ type PhasedDiagnostic with
5959

6060
/// Format the core of the diagnostic as a string. Doesn't include the range information.
6161
member FormatCore: flattenErrors: bool * suggestNames: bool -> string
62-
62+
63+
/// Compute new severity according to the various diagnostics options
64+
member AdjustSeverity: FSharpDiagnosticOptions -> FSharpDiagnosticSeverity
65+
6366
/// Output all of a diagnostic to a buffer, including range
6467
member Output: buf: StringBuilder * tcConfig: TcConfig * severity: FSharpDiagnosticSeverity -> unit
6568

@@ -72,10 +75,6 @@ type PhasedDiagnostic with
7275
severity: FSharpDiagnosticSeverity ->
7376
unit
7477

75-
type PhasedDiagnosticWithSeverity with
76-
/// Compute new severity according to the various diagnostics options
77-
member AdjustSeverity: FSharpDiagnosticOptions -> FSharpDiagnosticSeverity
78-
7978
/// Get a diagnostics logger that filters the reporting of warnings based on scoped pragma information
8079
val GetDiagnosticsLoggerFilteringByScopedNowarn:
8180
diagnosticOptions: FSharpDiagnosticOptions * diagnosticsLogger: DiagnosticsLogger -> DiagnosticsLogger

src/Compiler/Driver/ScriptClosure.fs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type LoadClosureInput =
2929
{
3030
FileName: string
3131
SyntaxTree: ParsedInput option
32-
ParseDiagnostics: PhasedDiagnosticWithSeverity list
33-
MetaCommandDiagnostics: PhasedDiagnosticWithSeverity list
32+
ParseDiagnostics: PhasedDiagnostic list
33+
MetaCommandDiagnostics: PhasedDiagnostic list
3434
}
3535

3636
[<RequireQualifiedAccess>]
@@ -64,13 +64,13 @@ type LoadClosure =
6464
OriginalLoadReferences: (range * string * string) list
6565

6666
/// Diagnostics seen while processing resolutions
67-
ResolutionDiagnostics: PhasedDiagnosticWithSeverity list
67+
ResolutionDiagnostics: PhasedDiagnostic list
6868

6969
/// Diagnostics seen while parsing root of closure
70-
AllRootFileDiagnostics: PhasedDiagnosticWithSeverity list
70+
AllRootFileDiagnostics: PhasedDiagnostic list
7171

7272
/// Diagnostics seen while processing the compiler options implied root of closure
73-
LoadClosureRootFileDiagnostics: PhasedDiagnosticWithSeverity list
73+
LoadClosureRootFileDiagnostics: PhasedDiagnostic list
7474
}
7575

7676
[<RequireQualifiedAccess>]
@@ -91,8 +91,8 @@ module ScriptPreprocessClosure =
9191
fileName: string *
9292
range: range *
9393
parsedInput: ParsedInput option *
94-
parseDiagnostics: PhasedDiagnosticWithSeverity list *
95-
metaDiagnostics: PhasedDiagnosticWithSeverity list
94+
parseDiagnostics: PhasedDiagnostic list *
95+
metaDiagnostics: PhasedDiagnostic list
9696

9797
type Observed() =
9898
let seen = Dictionary<_, bool>()
@@ -594,8 +594,7 @@ module ScriptPreprocessClosure =
594594
| None -> true
595595

596596
// Filter out non-root errors and warnings
597-
let allRootDiagnostics =
598-
allRootDiagnostics |> List.filter (isRootRange << _.PhasedDiagnostic)
597+
let allRootDiagnostics = allRootDiagnostics |> List.filter isRootRange
599598

600599
{
601600
SourceFiles = List.groupBy fst sourceFiles |> List.map (map2Of2 (List.map snd))

src/Compiler/Driver/ScriptClosure.fsi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type LoadClosureInput =
2626

2727
SyntaxTree: ParsedInput option
2828

29-
ParseDiagnostics: PhasedDiagnosticWithSeverity list
29+
ParseDiagnostics: PhasedDiagnostic list
3030

31-
MetaCommandDiagnostics: PhasedDiagnosticWithSeverity list }
31+
MetaCommandDiagnostics: PhasedDiagnostic list }
3232

3333
[<RequireQualifiedAccess>]
3434
type LoadClosure =
@@ -61,13 +61,13 @@ type LoadClosure =
6161
OriginalLoadReferences: (range * string * string) list
6262

6363
/// Diagnostics seen while processing resolutions
64-
ResolutionDiagnostics: PhasedDiagnosticWithSeverity list
64+
ResolutionDiagnostics: PhasedDiagnostic list
6565

6666
/// Diagnostics to show for root of closure (used by fsc.fs)
67-
AllRootFileDiagnostics: PhasedDiagnosticWithSeverity list
67+
AllRootFileDiagnostics: PhasedDiagnostic list
6868

6969
/// Diagnostics seen while processing the compiler options implied root of closure
70-
LoadClosureRootFileDiagnostics: PhasedDiagnosticWithSeverity list
70+
LoadClosureRootFileDiagnostics: PhasedDiagnostic list
7171
}
7272

7373
/// Analyze a script text and find the closure of its references.

src/Compiler/Driver/fsc.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,25 @@ type DiagnosticsLoggerUpToMaxErrors(tcConfigB: TcConfigBuilder, exiter: Exiter,
7676

7777
override x.DiagnosticSink(diagnostic) =
7878
let tcConfig = TcConfig.Create(tcConfigB, validate = false)
79-
let phasedDiagnostic = diagnostic.PhasedDiagnostic
8079

8180
match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions) with
8281
| FSharpDiagnosticSeverity.Error ->
8382
if errors >= tcConfig.maxErrors then
8483
x.HandleTooManyErrors(FSComp.SR.fscTooManyErrors ())
8584
exiter.Exit 1
8685

87-
x.HandleIssue(tcConfig, phasedDiagnostic, FSharpDiagnosticSeverity.Error)
86+
x.HandleIssue(tcConfig, diagnostic, FSharpDiagnosticSeverity.Error)
8887

8988
errors <- errors + 1
9089

91-
match phasedDiagnostic.Exception, tcConfigB.simulateException with
90+
match diagnostic.Exception, tcConfigB.simulateException with
9291
| InternalError(msg, _), None
93-
| Failure msg, None -> Debug.Assert(false, sprintf "Bug in compiler: %s\n%s" msg (phasedDiagnostic.ToString()))
94-
| :? KeyNotFoundException, None -> Debug.Assert(false, sprintf "Lookup exception in compiler: %s" (phasedDiagnostic.ToString()))
92+
| Failure msg, None -> Debug.Assert(false, sprintf "Bug in compiler: %s\n%s" msg (diagnostic.ToString()))
93+
| :? KeyNotFoundException, None -> Debug.Assert(false, sprintf "Lookup exception in compiler: %s" (diagnostic.ToString()))
9594
| _ -> ()
9695

9796
| FSharpDiagnosticSeverity.Hidden -> ()
98-
| s -> x.HandleIssue(tcConfig, phasedDiagnostic, s)
97+
| s -> x.HandleIssue(tcConfig, diagnostic, s)
9998

10099
/// Create an error logger that counts and prints errors
101100
let ConsoleDiagnosticsLogger (tcConfigB: TcConfigBuilder, exiter: Exiter) =

src/Compiler/Driver/fsc.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type DiagnosticsLoggerUpToMaxErrors =
3939

4040
override ErrorCount: int
4141

42-
override DiagnosticSink: diagnostic: PhasedDiagnosticWithSeverity -> unit
42+
override DiagnosticSink: diagnostic: PhasedDiagnostic -> unit
4343

4444
/// The main (non-incremental) compilation entry point used by fsc.exe
4545
val CompileFromCommandLineArguments:

src/Compiler/Facilities/DiagnosticsLogger.fs

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,12 @@ type PhasedDiagnostic =
286286
{
287287
Exception: exn
288288
Phase: BuildPhase
289+
Severity: FSharpDiagnosticSeverity
290+
DefaultSeverity: FSharpDiagnosticSeverity
289291
}
290292

291293
/// Construct a phased error
292-
static member Create(exn: exn, phase: BuildPhase) : PhasedDiagnostic = { Exception = exn; Phase = phase }
294+
static member Create(exn: exn, phase: BuildPhase, severity: FSharpDiagnosticSeverity) : PhasedDiagnostic = { Exception = exn; Phase = phase; Severity = severity; DefaultSeverity = severity }
293295

294296
member this.DebugDisplay() =
295297
sprintf "%s: %s" (this.Subcategory()) this.Exception.Message
@@ -348,28 +350,14 @@ type PhasedDiagnostic =
348350
| BuildPhase.TypeCheck -> true
349351
| _ -> false
350352

351-
type PhasedDiagnosticWithSeverity =
352-
{
353-
PhasedDiagnostic: PhasedDiagnostic
354-
Severity: FSharpDiagnosticSeverity
355-
DefaultSeverity: FSharpDiagnosticSeverity
356-
}
357-
358-
static member Create(phasedDiagnostic, severity) =
359-
{
360-
PhasedDiagnostic = phasedDiagnostic
361-
Severity = severity
362-
DefaultSeverity = severity
363-
}
364-
365353
[<AbstractClass>]
366354
[<DebuggerDisplay("{DebugDisplay()}")>]
367355
type DiagnosticsLogger(nameForDebugging: string) =
368356
abstract ErrorCount: int
369357

370358
// The 'Impl' factoring enables a developer to place a breakpoint at the non-Impl
371359
// code just below and get a breakpoint for all error logger implementations.
372-
abstract DiagnosticSink: diagnostic: PhasedDiagnosticWithSeverity -> unit
360+
abstract DiagnosticSink: diagnostic: PhasedDiagnostic -> unit
373361

374362
member x.CheckForErrors() = (x.ErrorCount > 0)
375363

@@ -401,10 +389,7 @@ type CapturingDiagnosticsLogger(nm, ?eagerFormat) =
401389
let diagnostic =
402390
match eagerFormat with
403391
| None -> diagnostic
404-
| Some f ->
405-
{ diagnostic with
406-
PhasedDiagnostic = f diagnostic.PhasedDiagnostic
407-
}
392+
| Some f -> f diagnostic
408393

409394
if diagnostic.Severity = FSharpDiagnosticSeverity.Error then
410395
errorCount <- errorCount + 1
@@ -475,13 +460,8 @@ module DiagnosticsLoggerExtensions =
475460
PreserveStackTrace exn
476461
raise exn
477462
| _ ->
478-
let phasedDiagnostic =
479-
PhasedDiagnostic.Create(exn, DiagnosticsThreadStatics.BuildPhase)
480-
481-
let diagnosticWithSeverity =
482-
PhasedDiagnosticWithSeverity.Create(phasedDiagnostic, severity)
483-
484-
x.DiagnosticSink(diagnosticWithSeverity)
463+
let diagnostic =PhasedDiagnostic.Create(exn, DiagnosticsThreadStatics.BuildPhase, severity)
464+
x.DiagnosticSink(diagnostic)
485465

486466
member x.ErrorR exn =
487467
x.EmitDiagnostic(exn, FSharpDiagnosticSeverity.Error)
@@ -497,10 +477,7 @@ module DiagnosticsLoggerExtensions =
497477
raise (ReportedError(Some exn))
498478

499479
member x.SimulateError(diagnostic) =
500-
let diagnosticWithSeverity =
501-
PhasedDiagnosticWithSeverity.Create(diagnostic, FSharpDiagnosticSeverity.Error)
502-
503-
x.DiagnosticSink(diagnosticWithSeverity)
480+
x.DiagnosticSink(diagnostic)
504481
raise (ReportedError(Some diagnostic.Exception))
505482

506483
member x.ErrorRecovery (exn: exn) (m: range) =
@@ -613,12 +590,6 @@ let simulateError diagnostic =
613590
let diagnosticSink diagnostic =
614591
DiagnosticsThreadStatics.DiagnosticsLogger.DiagnosticSink(diagnostic)
615592

616-
let errorSink diagnostic =
617-
diagnosticSink (PhasedDiagnosticWithSeverity.Create(diagnostic, FSharpDiagnosticSeverity.Error))
618-
619-
let warnSink diagnostic =
620-
diagnosticSink (PhasedDiagnosticWithSeverity.Create(diagnostic, FSharpDiagnosticSeverity.Warning))
621-
622593
let errorRecovery exn m =
623594
DiagnosticsThreadStatics.DiagnosticsLogger.ErrorRecovery exn m
624595

src/Compiler/Facilities/DiagnosticsLogger.fsi

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ module BuildPhaseSubcategory =
178178

179179
type PhasedDiagnostic =
180180
{ Exception: exn
181-
Phase: BuildPhase }
181+
Phase: BuildPhase
182+
Severity: FSharpDiagnosticSeverity
183+
DefaultSeverity: FSharpDiagnosticSeverity }
182184

183185
/// Construct a phased error
184-
static member Create: exn: exn * phase: BuildPhase -> PhasedDiagnostic
186+
static member Create: exn: exn * phase: BuildPhase * severity: FSharpDiagnosticSeverity -> PhasedDiagnostic
185187

186188
/// Return true if the textual phase given is from the compile part of the build process.
187189
/// This set needs to be equal to the set of subcategories that the language service can produce.
@@ -199,14 +201,6 @@ type PhasedDiagnostic =
199201
///
200202
member Subcategory: unit -> string
201203

202-
type PhasedDiagnosticWithSeverity =
203-
{ PhasedDiagnostic: PhasedDiagnostic
204-
Severity: FSharpDiagnosticSeverity
205-
DefaultSeverity: FSharpDiagnosticSeverity }
206-
207-
static member Create:
208-
phasedDiagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> PhasedDiagnosticWithSeverity
209-
210204
/// Represents a capability to log diagnostics
211205
[<AbstractClass>]
212206
type DiagnosticsLogger =
@@ -216,7 +210,7 @@ type DiagnosticsLogger =
216210
member DebugDisplay: unit -> string
217211

218212
/// Emit a diagnostic to the logger
219-
abstract DiagnosticSink: diagnostic: PhasedDiagnosticWithSeverity -> unit
213+
abstract DiagnosticSink: diagnostic: PhasedDiagnostic -> unit
220214

221215
/// Get the number of error diagnostics reported
222216
abstract ErrorCount: int
@@ -243,9 +237,9 @@ type CapturingDiagnosticsLogger =
243237

244238
member CommitDelayedDiagnostics: diagnosticsLogger: DiagnosticsLogger -> unit
245239

246-
override DiagnosticSink: diagnostic: PhasedDiagnosticWithSeverity -> unit
240+
override DiagnosticSink: diagnostic: PhasedDiagnostic -> unit
247241

248-
member Diagnostics: PhasedDiagnosticWithSeverity list
242+
member Diagnostics: PhasedDiagnostic list
249243

250244
override ErrorCount: int
251245

@@ -321,11 +315,7 @@ val informationalWarning: exn: exn -> unit
321315

322316
val simulateError: diagnostic: PhasedDiagnostic -> 'T
323317

324-
val diagnosticSink: diagnostic: PhasedDiagnosticWithSeverity -> unit
325-
326-
val errorSink: diagnostic: PhasedDiagnostic -> unit
327-
328-
val warnSink: diagnostic: PhasedDiagnostic -> unit
318+
val diagnosticSink: diagnostic: PhasedDiagnostic -> unit
329319

330320
val errorRecovery: exn: exn -> m: range -> unit
331321

src/Compiler/Interactive/fsi.fs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,17 +898,11 @@ type internal DiagnosticsLoggerThatStopsOnFirstError
898898
member _.ResetErrorCount() = errorCount <- 0
899899

900900
override _.DiagnosticSink(diagnostic) =
901-
let {
902-
PhasedDiagnostic = phasedDiagnostic
903-
Severity = severity
904-
} =
905-
diagnostic
906-
907901
let tcConfig = TcConfig.Create(tcConfigB, validate = false)
908902

909903
match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions) with
910904
| FSharpDiagnosticSeverity.Error ->
911-
fsiStdinSyphon.PrintDiagnostic(tcConfig, phasedDiagnostic)
905+
fsiStdinSyphon.PrintDiagnostic(tcConfig, diagnostic)
912906
errorCount <- errorCount + 1
913907

914908
if tcConfigB.abortOnError then
@@ -919,7 +913,7 @@ type internal DiagnosticsLoggerThatStopsOnFirstError
919913
| FSharpDiagnosticSeverity.Info as adjustedSeverity ->
920914
DoWithDiagnosticColor adjustedSeverity (fun () ->
921915
fsiConsoleOutput.Error.WriteLine()
922-
phasedDiagnostic.WriteWithContext(fsiConsoleOutput.Error, " ", fsiStdinSyphon.GetLine, tcConfig, severity)
916+
diagnostic.WriteWithContext(fsiConsoleOutput.Error, " ", fsiStdinSyphon.GetLine, tcConfig, diagnostic.Severity)
923917
fsiConsoleOutput.Error.WriteLine()
924918
fsiConsoleOutput.Error.WriteLine()
925919
fsiConsoleOutput.Error.Flush())

0 commit comments

Comments
 (0)