Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move flatErrors tests from fsharpqa #15251

Merged
merged 7 commits into from
May 26, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>()
Expand All @@ -2218,7 +2219,16 @@ 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
Expand Down Expand Up @@ -2327,7 +2337,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

Expand Down Expand Up @@ -2421,6 +2431,7 @@ module internal ParseAndCheckFile =
options: FSharpParsingOptions,
userOpName: string,
suggestNamesForErrors: bool,
flatErrors: bool,
identCapture: bool
) =
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)
Expand All @@ -2429,7 +2440,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

Expand Down Expand Up @@ -2596,7 +2607,14 @@ 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

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

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

Expand Down
20 changes: 11 additions & 9 deletions src/Compiler/Service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -> [||]
Expand Down
69 changes: 54 additions & 15 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,7 +137,8 @@ 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 ->
Expand Down Expand Up @@ -487,7 +488,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
Expand All @@ -507,14 +508,22 @@ 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)
}
Expand All @@ -537,7 +546,14 @@ 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 |]

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

Expand Down Expand Up @@ -835,12 +852,26 @@ 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 |]

Expand Down Expand Up @@ -994,7 +1025,14 @@ 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 |]

Expand Down Expand Up @@ -1083,8 +1121,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
Expand All @@ -1102,6 +1138,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
Expand Down Expand Up @@ -1159,7 +1197,8 @@ 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)
}
Expand Down Expand Up @@ -1414,7 +1453,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)
Expand Down Expand Up @@ -1650,7 +1689,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(
Expand Down
Loading