Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

* Type relations cache: optimize key generation ([Issue #19116](https://github.com/dotnet/fsharp/issues/18767)) ([PR #19120](https://github.com/dotnet/fsharp/pull/19120))

### Added

* FSharpDiagnostic: add default severity ([#19152](https://github.com/dotnet/fsharp/pull/19152))

### Breaking Changes

* `SynExpr.LetOrUse` holds `SynLetOrUse`. ([PR #19090](https://github.com/dotnet/fsharp/pull/19090))
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Add FSharpCodeCompletionOptions ([PR #19030](https://github.com/dotnet/fsharp/pull/19030))
* Type checker: recover on checking binding parameter constraints ([#19046](https://github.com/dotnet/fsharp/pull/19046))
* Debugger: provide breakpoint ranges for short lambdas ([#19067](https://github.com/dotnet/fsharp/pull/19067))
* FSharpDiagnostic: add default severity ([#19152](https://github.com/dotnet/fsharp/pull/19152))

### Changed

Expand Down
15 changes: 8 additions & 7 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ type PhasedDiagnostic with
(severity = FSharpDiagnosticSeverity.Info && level > 0)
|| (severity = FSharpDiagnosticSeverity.Warning && level >= x.WarningLevel)

member x.AdjustSeverity(options, severity) =
member x.AdjustSeverity(options) =
let severity = x.Severity
let n = x.Number

let localWarnon () = WarnScopes.IsWarnon options n x.Range
Expand Down Expand Up @@ -2007,7 +2008,7 @@ type PhasedDiagnostic with
x.Exception.Output(buf, suggestNames)
let message = buf.ToString()
let exn = DiagnosticWithText(x.Number, message, m)
{ Exception = exn; Phase = x.Phase }
{ x with Exception = exn }
| None -> x

let SanitizeFileName fileName implicitIncludeDir =
Expand Down Expand Up @@ -2313,15 +2314,15 @@ type DiagnosticsLoggerFilteringByScopedNowarn(diagnosticOptions: FSharpDiagnosti

let mutable realErrorPresent = false

override _.DiagnosticSink(diagnostic: PhasedDiagnostic, severity) =
override _.DiagnosticSink(diagnostic: PhasedDiagnostic) =

if severity = FSharpDiagnosticSeverity.Error then
if diagnostic.Severity = FSharpDiagnosticSeverity.Error then
realErrorPresent <- true
diagnosticsLogger.DiagnosticSink(diagnostic, severity)
diagnosticsLogger.DiagnosticSink(diagnostic)
else
match diagnostic.AdjustSeverity(diagnosticOptions, severity) with
match diagnostic.AdjustSeverity(diagnosticOptions) with
| FSharpDiagnosticSeverity.Hidden -> ()
| s -> diagnosticsLogger.DiagnosticSink(diagnostic, s)
| s -> diagnosticsLogger.DiagnosticSink({ diagnostic with Severity = s })

override _.ErrorCount = diagnosticsLogger.ErrorCount

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerDiagnostics.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type PhasedDiagnostic with
member FormatCore: flattenErrors: bool * suggestNames: bool -> string

/// Compute new severity according to the various diagnostics options
member AdjustSeverity: FSharpDiagnosticOptions * FSharpDiagnosticSeverity -> FSharpDiagnosticSeverity
member AdjustSeverity: FSharpDiagnosticOptions -> FSharpDiagnosticSeverity

/// Output all of a diagnostic to a buffer, including range
member Output: buf: StringBuilder * tcConfig: TcConfig * severity: FSharpDiagnosticSeverity -> unit
Expand Down
16 changes: 8 additions & 8 deletions src/Compiler/Driver/ScriptClosure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type LoadClosureInput =
{
FileName: string
SyntaxTree: ParsedInput option
ParseDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
MetaCommandDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
ParseDiagnostics: PhasedDiagnostic list
MetaCommandDiagnostics: PhasedDiagnostic list
}

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -64,13 +64,13 @@ type LoadClosure =
OriginalLoadReferences: (range * string * string) list

/// Diagnostics seen while processing resolutions
ResolutionDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
ResolutionDiagnostics: PhasedDiagnostic list

/// Diagnostics seen while parsing root of closure
AllRootFileDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
AllRootFileDiagnostics: PhasedDiagnostic list

/// Diagnostics seen while processing the compiler options implied root of closure
LoadClosureRootFileDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
LoadClosureRootFileDiagnostics: PhasedDiagnostic list
}

[<RequireQualifiedAccess>]
Expand All @@ -91,8 +91,8 @@ module ScriptPreprocessClosure =
fileName: string *
range: range *
parsedInput: ParsedInput option *
parseDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list *
metaDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
parseDiagnostics: PhasedDiagnostic list *
metaDiagnostics: PhasedDiagnostic list

type Observed() =
let seen = Dictionary<_, bool>()
Expand Down Expand Up @@ -594,7 +594,7 @@ module ScriptPreprocessClosure =
| None -> true

// Filter out non-root errors and warnings
let allRootDiagnostics = allRootDiagnostics |> List.filter (fst >> isRootRange)
let allRootDiagnostics = allRootDiagnostics |> List.filter isRootRange

{
SourceFiles = List.groupBy fst sourceFiles |> List.map (map2Of2 (List.map snd))
Expand Down
10 changes: 5 additions & 5 deletions src/Compiler/Driver/ScriptClosure.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type LoadClosureInput =

SyntaxTree: ParsedInput option

ParseDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
ParseDiagnostics: PhasedDiagnostic list

MetaCommandDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list }
MetaCommandDiagnostics: PhasedDiagnostic list }

[<RequireQualifiedAccess>]
type LoadClosure =
Expand Down Expand Up @@ -61,13 +61,13 @@ type LoadClosure =
OriginalLoadReferences: (range * string * string) list

/// Diagnostics seen while processing resolutions
ResolutionDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
ResolutionDiagnostics: PhasedDiagnostic list

/// Diagnostics to show for root of closure (used by fsc.fs)
AllRootFileDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
AllRootFileDiagnostics: PhasedDiagnostic list

/// Diagnostics seen while processing the compiler options implied root of closure
LoadClosureRootFileDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
LoadClosureRootFileDiagnostics: PhasedDiagnostic list
}

/// Analyze a script text and find the closure of its references.
Expand Down
9 changes: 4 additions & 5 deletions src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ type DiagnosticsLoggerUpToMaxErrors(tcConfigB: TcConfigBuilder, exiter: Exiter,

override _.ErrorCount = errors

override x.DiagnosticSink(diagnostic, severity) =
override x.DiagnosticSink(diagnostic) =
let tcConfig = TcConfig.Create(tcConfigB, validate = false)

match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions, severity) with
match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions) with
| FSharpDiagnosticSeverity.Error ->
if errors >= tcConfig.maxErrors then
x.HandleTooManyErrors(FSComp.SR.fscTooManyErrors ())
Expand All @@ -89,9 +89,8 @@ type DiagnosticsLoggerUpToMaxErrors(tcConfigB: TcConfigBuilder, exiter: Exiter,

match diagnostic.Exception, tcConfigB.simulateException with
| InternalError(msg, _), None
| Failure msg, None -> Debug.Assert(false, sprintf "Bug in compiler: %s\n%s" msg (diagnostic.Exception.ToString()))
| :? KeyNotFoundException, None ->
Debug.Assert(false, sprintf "Lookup exception in compiler: %s" (diagnostic.Exception.ToString()))
| Failure msg, None -> Debug.Assert(false, sprintf "Bug in compiler: %s\n%s" msg (diagnostic.ToString()))
| :? KeyNotFoundException, None -> Debug.Assert(false, sprintf "Lookup exception in compiler: %s" (diagnostic.ToString()))
| _ -> ()

| FSharpDiagnosticSeverity.Hidden -> ()
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/fsc.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DiagnosticsLoggerUpToMaxErrors =

override ErrorCount: int

override DiagnosticSink: diagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> unit
override DiagnosticSink: diagnostic: PhasedDiagnostic -> unit

/// The main (non-incremental) compilation entry point used by fsc.exe
val CompileFromCommandLineArguments:
Expand Down
44 changes: 23 additions & 21 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,18 @@ type PhasedDiagnostic =
{
Exception: exn
Phase: BuildPhase
Severity: FSharpDiagnosticSeverity
DefaultSeverity: FSharpDiagnosticSeverity
}

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

member this.DebugDisplay() =
sprintf "%s: %s" (this.Subcategory()) this.Exception.Message
Expand Down Expand Up @@ -355,7 +363,7 @@ type DiagnosticsLogger(nameForDebugging: string) =

// The 'Impl' factoring enables a developer to place a breakpoint at the non-Impl
// code just below and get a breakpoint for all error logger implementations.
abstract DiagnosticSink: diagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> unit
abstract DiagnosticSink: diagnostic: PhasedDiagnostic -> unit

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

Expand All @@ -367,14 +375,14 @@ type DiagnosticsLogger(nameForDebugging: string) =

let DiscardErrorsLogger =
{ new DiagnosticsLogger("DiscardErrorsLogger") with
member _.DiagnosticSink(diagnostic, severity) = ()
member _.DiagnosticSink(diagnostic) = ()
member _.ErrorCount = 0
}

let AssertFalseDiagnosticsLogger =
{ new DiagnosticsLogger("AssertFalseDiagnosticsLogger") with
// TODO: reenable these asserts in the compiler service
member _.DiagnosticSink(diagnostic, severity) = (* assert false; *) ()
member _.DiagnosticSink(diagnostic) = (* assert false; *) ()
member _.ErrorCount = (* assert false; *) 0
}

Expand All @@ -383,16 +391,16 @@ type CapturingDiagnosticsLogger(nm, ?eagerFormat) =
let mutable errorCount = 0
let diagnostics = ResizeArray()

override _.DiagnosticSink(diagnostic, severity) =
override _.DiagnosticSink(diagnostic) =
let diagnostic =
match eagerFormat with
| None -> diagnostic
| Some f -> f diagnostic

if severity = FSharpDiagnosticSeverity.Error then
if diagnostic.Severity = FSharpDiagnosticSeverity.Error then
errorCount <- errorCount + 1

diagnostics.Add(diagnostic, severity)
diagnostics.Add(diagnostic)

override _.ErrorCount = errorCount

Expand Down Expand Up @@ -457,7 +465,7 @@ module DiagnosticsLoggerExtensions =
| ReportedError _ ->
PreserveStackTrace exn
raise exn
| _ -> x.DiagnosticSink(PhasedDiagnostic.Create(exn, DiagnosticsThreadStatics.BuildPhase), severity)
| _ -> x.DiagnosticSink(PhasedDiagnostic.Create(exn, DiagnosticsThreadStatics.BuildPhase, severity))

member x.ErrorR exn =
x.EmitDiagnostic(exn, FSharpDiagnosticSeverity.Error)
Expand All @@ -472,8 +480,8 @@ module DiagnosticsLoggerExtensions =
x.ErrorR exn
raise (ReportedError(Some exn))

member x.SimulateError diagnostic =
x.DiagnosticSink(diagnostic, FSharpDiagnosticSeverity.Error)
member x.SimulateError(diagnostic) =
x.DiagnosticSink(diagnostic)
raise (ReportedError(Some diagnostic.Exception))

member x.ErrorRecovery (exn: exn) (m: range) =
Expand Down Expand Up @@ -580,17 +588,11 @@ let error exn =
DiagnosticsThreadStatics.DiagnosticsLogger.Error exn

/// Simulates an error. For test purposes only.
let simulateError (diagnostic: PhasedDiagnostic) =
DiagnosticsThreadStatics.DiagnosticsLogger.SimulateError diagnostic

let diagnosticSink (diagnostic, severity) =
DiagnosticsThreadStatics.DiagnosticsLogger.DiagnosticSink(diagnostic, severity)

let errorSink diagnostic =
diagnosticSink (diagnostic, FSharpDiagnosticSeverity.Error)
let simulateError diagnostic =
DiagnosticsThreadStatics.DiagnosticsLogger.SimulateError(diagnostic)

let warnSink diagnostic =
diagnosticSink (diagnostic, FSharpDiagnosticSeverity.Warning)
let diagnosticSink diagnostic =
DiagnosticsThreadStatics.DiagnosticsLogger.DiagnosticSink(diagnostic)

let errorRecovery exn m =
DiagnosticsThreadStatics.DiagnosticsLogger.ErrorRecovery exn m
Expand Down Expand Up @@ -623,7 +625,7 @@ let suppressErrorReporting f =
try
let diagnosticsLogger =
{ new DiagnosticsLogger("suppressErrorReporting") with
member _.DiagnosticSink(_phasedError, _isError) = ()
member _.DiagnosticSink(_diagnostic) = ()
member _.ErrorCount = 0
}

Expand Down
18 changes: 8 additions & 10 deletions src/Compiler/Facilities/DiagnosticsLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ module BuildPhaseSubcategory =

type PhasedDiagnostic =
{ Exception: exn
Phase: BuildPhase }
Phase: BuildPhase
Severity: FSharpDiagnosticSeverity
DefaultSeverity: FSharpDiagnosticSeverity }

/// Construct a phased error
static member Create: exn: exn * phase: BuildPhase -> PhasedDiagnostic
static member Create: exn: exn * phase: BuildPhase * severity: FSharpDiagnosticSeverity -> PhasedDiagnostic

/// Return true if the textual phase given is from the compile part of the build process.
/// This set needs to be equal to the set of subcategories that the language service can produce.
Expand All @@ -208,7 +210,7 @@ type DiagnosticsLogger =
member DebugDisplay: unit -> string

/// Emit a diagnostic to the logger
abstract DiagnosticSink: diagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> unit
abstract DiagnosticSink: diagnostic: PhasedDiagnostic -> unit

/// Get the number of error diagnostics reported
abstract ErrorCount: int
Expand All @@ -235,9 +237,9 @@ type CapturingDiagnosticsLogger =

member CommitDelayedDiagnostics: diagnosticsLogger: DiagnosticsLogger -> unit

override DiagnosticSink: diagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> unit
override DiagnosticSink: diagnostic: PhasedDiagnostic -> unit

member Diagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity) list
member Diagnostics: PhasedDiagnostic list

override ErrorCount: int

Expand Down Expand Up @@ -313,11 +315,7 @@ val informationalWarning: exn: exn -> unit

val simulateError: diagnostic: PhasedDiagnostic -> 'T

val diagnosticSink: diagnostic: PhasedDiagnostic * severity: FSharpDiagnosticSeverity -> unit

val errorSink: diagnostic: PhasedDiagnostic -> unit

val warnSink: diagnostic: PhasedDiagnostic -> unit
val diagnosticSink: diagnostic: PhasedDiagnostic -> unit

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

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ type internal DiagnosticsLoggerThatStopsOnFirstError

member _.ResetErrorCount() = errorCount <- 0

override _.DiagnosticSink(diagnostic, severity) =
override _.DiagnosticSink(diagnostic) =
let tcConfig = TcConfig.Create(tcConfigB, validate = false)

match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions, severity) with
match diagnostic.AdjustSeverity(tcConfig.diagnosticsOptions) with
| FSharpDiagnosticSeverity.Error ->
fsiStdinSyphon.PrintDiagnostic(tcConfig, diagnostic)
errorCount <- errorCount + 1
Expand All @@ -913,7 +913,7 @@ type internal DiagnosticsLoggerThatStopsOnFirstError
| FSharpDiagnosticSeverity.Info as adjustedSeverity ->
DoWithDiagnosticColor adjustedSeverity (fun () ->
fsiConsoleOutput.Error.WriteLine()
diagnostic.WriteWithContext(fsiConsoleOutput.Error, " ", fsiStdinSyphon.GetLine, tcConfig, severity)
diagnostic.WriteWithContext(fsiConsoleOutput.Error, " ", fsiStdinSyphon.GetLine, tcConfig, diagnostic.Severity)
fsiConsoleOutput.Error.WriteLine()
fsiConsoleOutput.Error.WriteLine()
fsiConsoleOutput.Error.Flush())
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/BackgroundCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ type internal BackgroundCompiler
let flatErrors = options.OtherOptions |> Array.contains "--flaterrors"

loadClosure.LoadClosureRootFileDiagnostics
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, false, flatErrors, None))
|> List.map (fun diagnostic -> FSharpDiagnostic.CreateFromException(diagnostic, false, flatErrors, None))

return options, (diags @ diagnostics.Diagnostics)
}
Expand Down
Loading
Loading