Skip to content

Commit

Permalink
flaterrors
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed May 23, 2023
1 parent 23a2e8d commit 7c896bc
Showing 10 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
@@ -4689,7 +4689,7 @@ type FsiEvaluationSession
let errs = diagnosticsLogger.GetDiagnostics()

let errorInfos =
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true)
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true, tcConfigB.flatErrors)

let userRes =
match res with
13 changes: 8 additions & 5 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
@@ -2207,7 +2207,8 @@ module internal ParseAndCheckFile =
mainInputFileName,
diagnosticsOptions: FSharpDiagnosticOptions,
sourceText: ISourceText,
suggestNamesForErrors: bool
suggestNamesForErrors: bool,
flatErrors: bool
) =
let mutable options = diagnosticsOptions
let diagnosticsCollector = ResizeArray<_>()
@@ -2218,7 +2219,7 @@ module internal ParseAndCheckFile =

let collectOne severity diagnostic =
for diagnostic in
DiagnosticHelpers.ReportDiagnostic(options, false, mainInputFileName, fileInfo, diagnostic, severity, suggestNamesForErrors) do
DiagnosticHelpers.ReportDiagnostic(options, false, mainInputFileName, fileInfo, diagnostic, severity, suggestNamesForErrors, flatErrors) do
diagnosticsCollector.Add diagnostic

if severity = FSharpDiagnosticSeverity.Error then
@@ -2327,7 +2328,7 @@ module internal ParseAndCheckFile =

usingLexbufForParsing (createLexbuf options.LangVersionText sourceText, fileName) (fun lexbuf ->
let errHandler =
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, false)

let lexfun = createLexerFunction fileName options lexbuf errHandler

@@ -2421,6 +2422,7 @@ module internal ParseAndCheckFile =
options: FSharpParsingOptions,
userOpName: string,
suggestNamesForErrors: bool,
flatErrors: bool,
identCapture: bool
) =
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)
@@ -2429,7 +2431,7 @@ module internal ParseAndCheckFile =
Activity.start "ParseAndCheckFile.parseFile" [| Activity.Tags.fileName, fileName |]

let errHandler =
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, flatErrors)

use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger

@@ -2596,7 +2598,7 @@ module internal ParseAndCheckFile =

// Initialize the error handler
let errHandler =
DiagnosticsHandler(true, mainInputFileName, tcConfig.diagnosticsOptions, sourceText, suggestNamesForErrors)
DiagnosticsHandler(true, mainInputFileName, tcConfig.diagnosticsOptions, sourceText, suggestNamesForErrors, tcConfig.flatErrors)

use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger

@@ -3260,6 +3262,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, tcConfig: TcConfig, tcGlobal
parsingOptions,
userOpName,
suggestNamesForErrors,
tcConfig.flatErrors,
tcConfig.captureIdentifiersWhenParsing
)

1 change: 1 addition & 0 deletions src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
@@ -537,6 +537,7 @@ module internal ParseAndCheckFile =
options: FSharpParsingOptions *
userOpName: string *
suggestNamesForErrors: bool *
flatErrors: bool *
identCapture: bool ->
FSharpDiagnostic[] * ParsedInput * bool

20 changes: 11 additions & 9 deletions src/Compiler/Service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
@@ -1599,16 +1599,18 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc
}

let diagnostics =
match builderOpt with
| Some builder ->
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
let diagnosticsLogger = CompilationDiagnosticLogger("IncrementalBuilderCreation", diagnosticsOptions)
delayedLogger.CommitDelayedDiagnostics diagnosticsLogger
diagnosticsLogger.GetDiagnostics()
| _ ->
Array.ofList delayedLogger.Diagnostics
let diagnostics, flatErrors =
match builderOpt with
| Some builder ->
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
let diagnosticsLogger = CompilationDiagnosticLogger("IncrementalBuilderCreation", diagnosticsOptions)
delayedLogger.CommitDelayedDiagnostics diagnosticsLogger
diagnosticsLogger.GetDiagnostics(), builder.TcConfig.flatErrors
| _ ->
Array.ofList delayedLogger.Diagnostics, false
diagnostics
|> Array.map (fun (diagnostic, severity) ->
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors))
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors, flatErrors))

return builderOpt, diagnostics
}
4 changes: 2 additions & 2 deletions src/Compiler/Service/ServiceAssemblyContent.fs
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ module AssemblyContent =
// are not triggered (see "if not entity.IsProvided") and the other data accessed is immutable or computed safely
// on-demand. However a more compete review may be warranted.

use _ignoreAllDiagnostics = new DiagnosticsScope()
use _ignoreAllDiagnostics = new DiagnosticsScope(false)

signature.TryGetEntities()
|> Seq.collect (traverseEntity contentType Parent.Empty)
@@ -265,7 +265,7 @@ module AssemblyContent =
// concurrently with other threads. On an initial review this is not a problem since type provider computations
// are not triggered (see "if not entity.IsProvided") and the other data accessed is immutable or computed safely
// on-demand. However a more compete review may be warranted.
use _ignoreAllDiagnostics = new DiagnosticsScope()
use _ignoreAllDiagnostics = new DiagnosticsScope(false)

#if !NO_TYPEPROVIDERS
match assemblies |> List.filter (fun x -> not x.IsProviderGenerated), fileName with
4 changes: 2 additions & 2 deletions src/Compiler/Service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
@@ -2012,7 +2012,7 @@ module ParsedInput =
// We ignore all diagnostics during this operation
//
// Based on an initial review, no diagnostics should be generated. However the code should be checked more closely.
use _ignoreAllDiagnostics = new DiagnosticsScope()
use _ignoreAllDiagnostics = new DiagnosticsScope(false)

let mutable result = None
let mutable ns = None
@@ -2175,7 +2175,7 @@ module ParsedInput =
// We ignore all diagnostics during this operation
//
// Based on an initial review, no diagnostics should be generated. However the code should be checked more closely.
use _ignoreAllDiagnostics = new DiagnosticsScope()
use _ignoreAllDiagnostics = new DiagnosticsScope(false)

match res with
| None -> [||]
31 changes: 16 additions & 15 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
@@ -99,14 +99,14 @@ module Helpers =
| _ -> false

module CompileHelpers =
let mkCompilationDiagnosticsHandlers () =
let mkCompilationDiagnosticsHandlers (flatErrors) =
let diagnostics = ResizeArray<_>()

let diagnosticsLogger =
{ new DiagnosticsLogger("CompileAPI") with

member _.DiagnosticSink(diag, isError) =
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true)) // Suggest names for errors
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true, flatErrors)) // Suggest names for errors

member _.ErrorCount =
diagnostics
@@ -137,7 +137,7 @@ module CompileHelpers =
/// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
let compileFromArgs (ctok, argv: string[], legacyReferenceResolver, tcImportsCapture, dynamicAssemblyCreator) =

let diagnostics, diagnosticsLogger, loggerProvider = mkCompilationDiagnosticsHandlers ()
let diagnostics, diagnosticsLogger, loggerProvider = mkCompilationDiagnosticsHandlers (argv |> Array.contains "--flaterrors")

let result =
tryCompile diagnosticsLogger (fun exiter ->
@@ -487,7 +487,7 @@ type BackgroundCompiler
checkFileInProjectCache.Set(ltok, key, res)
res)

member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, userOpName: string) =
member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, flatErrors: bool, userOpName: string) =
async {
use _ =
Activity.start
@@ -507,14 +507,14 @@ type BackgroundCompiler
Interlocked.Increment(&actualParseFileCount) |> ignore

let parseDiagnostics, parseTree, anyErrors =
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, suggestNamesForErrors, captureIdentifiersWhenParsing)
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, suggestNamesForErrors, flatErrors, captureIdentifiersWhenParsing)

let res = FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
parseCacheLock.AcquireLock(fun ltok -> parseFileCache.Set(ltok, (fileName, hash, options), res))
return res
else
let parseDiagnostics, parseTree, anyErrors =
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, captureIdentifiersWhenParsing)
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, flatErrors, captureIdentifiersWhenParsing)

return FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
}
@@ -537,7 +537,7 @@ type BackgroundCompiler
let parseTree, _, _, parseDiagnostics = builder.GetParseResultsForFile fileName

let parseDiagnostics =
DiagnosticHelpers.CreateDiagnostics(builder.TcConfig.diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
DiagnosticHelpers.CreateDiagnostics(builder.TcConfig.diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)

let diagnostics = [| yield! creationDiags; yield! parseDiagnostics |]

@@ -767,6 +767,7 @@ type BackgroundCompiler
parsingOptions,
userOpName,
suggestNamesForErrors,
builder.TcConfig.flatErrors,
captureIdentifiersWhenParsing
)

@@ -835,12 +836,12 @@ type BackgroundCompiler
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions

let parseDiagnostics =
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)

let parseDiagnostics = [| yield! creationDiags; yield! parseDiagnostics |]

let tcDiagnostics =
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, tcDiagnostics, suggestNamesForErrors)
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, tcDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)

let tcDiagnostics = [| yield! creationDiags; yield! tcDiagnostics |]

@@ -994,7 +995,7 @@ type BackgroundCompiler
let tcDependencyFiles = tcInfo.tcDependencyFiles

let tcDiagnostics =
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, true, fileName, tcDiagnostics, suggestNamesForErrors)
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, true, fileName, tcDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)

let diagnostics = [| yield! creationDiags; yield! tcDiagnostics |]

@@ -1083,8 +1084,6 @@ type BackgroundCompiler
[| Activity.Tags.fileName, fileName; Activity.Tags.userOpName, _userOpName |]

cancellable {
use diagnostics = new DiagnosticsScope()

// Do we add a reference to FSharp.Compiler.Interactive.Settings by default?
let useFsiAuxLib = defaultArg useFsiAuxLib true
let useSdkRefs = defaultArg useSdkRefs true
@@ -1102,6 +1101,8 @@ type BackgroundCompiler

let otherFlags = defaultArg otherFlags extraFlags

use diagnostics = new DiagnosticsScope (otherFlags |> Array.contains "--flaterrors")

let useSimpleResolution = otherFlags |> Array.exists (fun x -> x = "--simpleresolution")

let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
@@ -1159,7 +1160,7 @@ type BackgroundCompiler

let diags =
loadClosure.LoadClosureRootFileDiagnostics
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false))
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false, options.OtherOptions |> Array.contains "--flaterrors"))

return options, (diags @ diagnostics.Diagnostics)
}
@@ -1414,7 +1415,7 @@ type FSharpChecker
member _.ParseFile(fileName, sourceText, options, ?cache, ?userOpName: string) =
let cache = defaultArg cache true
let userOpName = defaultArg userOpName "Unknown"
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, userOpName)
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, false, userOpName)

member ic.ParseFileInProject(fileName, source: string, options, ?cache: bool, ?userOpName: string) =
let parsingOptions, _ = ic.GetParsingOptionsFromProjectOptions(options)
@@ -1650,7 +1651,7 @@ type FSharpChecker
member _.GetParsingOptionsFromCommandLineArgs(sourceFiles, argv, ?isInteractive, ?isEditing) =
let isEditing = defaultArg isEditing false
let isInteractive = defaultArg isInteractive false
use errorScope = new DiagnosticsScope()
use errorScope = new DiagnosticsScope (argv |> List.contains "--flaterrors")

let tcConfigB =
TcConfigBuilder.CreateNew(
Loading

0 comments on commit 7c896bc

Please sign in to comment.