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

Scoped #nowarn #17507

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e91f72d
temp checkin for testing
Martin521 Sep 11, 2024
bd56222
add xlf files
Martin521 Sep 11, 2024
bab4a17
fix for Windows and fix for compatibilty mode
Martin521 Sep 12, 2024
bdb8a3b
corrected scope logic; added ClearLexbufStore
Martin521 Sep 18, 2024
f93ee42
Merge branch 'main' into scoped-nowarn-dev
Martin521 Sep 18, 2024
062ee2e
fixed issues from merge
Martin521 Sep 19, 2024
45105fd
added ScopedNowarn language feature
Martin521 Sep 19, 2024
f5525f3
xlf files
Martin521 Sep 19, 2024
5641361
MergeInto from lexbuf rather than warnScopes
Martin521 Sep 19, 2024
be99297
just updated comments
Martin521 Sep 19, 2024
74481a3
new handling of #line (lineMappingOrigin in FileIndex)
Martin521 Sep 20, 2024
82f48f2
corrected ApplyLineDirective, corrected tests, added tests
Martin521 Sep 20, 2024
369c3c8
extended regex to allow comments after directive
Martin521 Sep 20, 2024
164d7cf
moved LineMap to FSharpDiagnosticOptions
Martin521 Sep 21, 2024
267c8df
typo correction
Martin521 Sep 21, 2024
4bef77d
surface area baseline update
Martin521 Sep 21, 2024
f44248a
Remove ", []" in 900 baselines (because of removed scopedPragmas para…
Martin521 Sep 21, 2024
3f566a9
fantomas
Martin521 Sep 21, 2024
c82daef
handling warn directives for interactive and service (LineTokenizer)
Martin521 Oct 4, 2024
ecfce46
Merge branch 'scoped-nowarn-dev2' into draft-scoped-nowarn
Martin521 Oct 4, 2024
6041cdd
fix merge issues
Martin521 Oct 4, 2024
650df31
ran fantomas
Martin521 Oct 4, 2024
aacab15
fixed WARN_DIRECTIVE parse in fsi
Martin521 Oct 4, 2024
d36702e
disabled test on transitive #nowarn
Martin521 Oct 4, 2024
398a4a5
fixed formatting and unused variable
Martin521 Oct 4, 2024
c29e3f2
fix formatting
Martin521 Oct 4, 2024
b2f656e
fix or skip legacy tests
Martin521 Oct 5, 2024
47ddb66
enable intra-expression warn directives; tests; warnings
Martin521 Oct 15, 2024
38f1a82
merge upstream/main
Martin521 Oct 16, 2024
1f895a3
turned warning about consecutive #nowarn into Informational
Martin521 Oct 16, 2024
aca968f
some fixes and added test
Martin521 Oct 17, 2024
9a733f7
Merge remote-tracking branch 'upstream/main' into draft-scoped-nowarn
Martin521 Oct 17, 2024
55f2fc6
interaction with #line and diverse improvements
Martin521 Nov 8, 2024
c3d61e0
fixed merge issues
Martin521 Nov 8, 2024
7b2df5c
fix merge issues
Martin521 Nov 8, 2024
7e2d229
Merge remote-tracking branch 'upstream/main' into scoped-nowarn-dev6
Martin521 Nov 11, 2024
393d075
Some refactoring of WarnScopes;
Martin521 Nov 12, 2024
01c00f5
make LexerStore use lexbuf.GetLocalData
Martin521 Nov 12, 2024
c17404e
fixes
Martin521 Nov 12, 2024
3d86cc7
Merge remote-tracking branch 'upstream/main' into scoped-nowarn-temp
Martin521 Nov 12, 2024
2f6fe8c
formatting fixed
Martin521 Nov 13, 2024
f93883d
Merge remote-tracking branch 'upstream/main' into draft-scoped-nowarn
Martin521 Nov 14, 2024
bb7b32c
revert test change
Martin521 Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ src/Compiler/Utilities/HashMultiMap.fs
src/Compiler/Facilities/AsyncMemoize.fsi
src/Compiler/Facilities/AsyncMemoize.fs
src/Compiler/AbstractIL/il.fs
src/Compiler/SyntaxTree/LexerStore.fs
src/Compiler/SyntaxTree/UnicodeLexing.fsi
src/Compiler/SyntaxTree/UnicodeLexing.fs

src/Compiler/Driver/GraphChecking/Graph.fsi
src/Compiler/Driver/GraphChecking/Graph.fs
Expand Down
11 changes: 11 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Fixed


### Added

* Introduction of the `#warnon` compiler directive, enabling scoped nowarn / warnon sections according to [RFC FS-1146](https://github.com/fsharp/fslang-design/pull/782/files). ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [PR #17507](https://github.com/dotnet/fsharp/pull/17507))

### Changed


### Breaking Changes
24 changes: 12 additions & 12 deletions docs/release-notes/.FSharp.Core/9.0.200.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### Fixed
* Fix exception on Post after MailboxProcessor was disposed ([Issue #17849](https://github.com/dotnet/fsharp/issues/17849), [PR #17922](https://github.com/dotnet/fsharp/pull/17922))
### Added
### Changed
* String function changed to guarantee a non-null string return type ([PR #17809](https://github.com/dotnet/fsharp/pull/17809))
### Breaking Changes
### Fixed

* Fix exception on Post after MailboxProcessor was disposed ([Issue #17849](https://github.com/dotnet/fsharp/issues/17849), [PR #17922](https://github.com/dotnet/fsharp/pull/17922))

### Added

### Changed
* String function changed to guarantee a non-null string return type ([PR #17809](https://github.com/dotnet/fsharp/pull/17809))


### Breaking Changes

4 changes: 2 additions & 2 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5734,7 +5734,7 @@ let CheckOneImplFile
synImplFile,
diagnosticOptions) =

let (ParsedImplFileInput (fileName, isScript, qualNameOfFile, scopedPragmas, _, implFileFrags, isLastCompiland, _, _)) = synImplFile
let (ParsedImplFileInput (fileName, isScript, qualNameOfFile, _, implFileFrags, isLastCompiland, _, _)) = synImplFile
let infoReader = InfoReader(g, amap)

cancellable {
Expand Down Expand Up @@ -5873,7 +5873,7 @@ let CheckOneImplFile
|> Array.map (fun (KeyValue(k,v)) -> (k,v))
|> Map

let implFile = CheckedImplFile (qualNameOfFile, scopedPragmas, implFileTy, implFileContents, hasExplicitEntryPoint, isScript, anonRecdTypes, namedDebugPointsForInlinedCode)
let implFile = CheckedImplFile (qualNameOfFile, implFileTy, implFileContents, hasExplicitEntryPoint, isScript, anonRecdTypes, namedDebugPointsForInlinedCode)

return (topAttrs, implFile, envAtEnd, cenv.createsGeneratedProvidedTypes)
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10382,7 +10382,7 @@ and GenModuleBinding cenv (cgbuf: CodeGenBuffer) (qname: QualifiedNameOfFile) la

/// Generate the namespace fragments in a single file
and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: CheckedImplFileAfterOptimization) =
let (CheckedImplFile(qname, _, signature, contents, hasExplicitEntryPoint, isScript, anonRecdTypes, _)) =
let (CheckedImplFile(qname, signature, contents, hasExplicitEntryPoint, isScript, anonRecdTypes, _)) =
implFile.ImplFile

let optimizeDuringCodeGen = implFile.OptimizeDuringCodeGen
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ type TcConfigBuilder =
tcConfigB.outputFile <- Some outfile
outfile, pdbfile, assemblyName

member tcConfigB.TurnWarningOff(m, s: string) =
member tcConfigB.TurnWarningOff(m: range, s: string) =
use _ = UseBuildPhase BuildPhase.Parameter

match GetWarningNumber(m, WarningDescription.String s, tcConfigB.langVersion, WarningNumberSource.CommandLineOption) with
Expand All @@ -984,7 +984,7 @@ type TcConfigBuilder =
WarnOff = ListSet.insert (=) n tcConfigB.diagnosticsOptions.WarnOff
}

member tcConfigB.TurnWarningOn(m, s: string) =
member tcConfigB.TurnWarningOn(m: range, s: string) =
use _ = UseBuildPhase BuildPhase.Parameter

match GetWarningNumber(m, WarningDescription.String s, tcConfigB.langVersion, WarningNumberSource.CommandLineOption) with
Expand Down
54 changes: 19 additions & 35 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open FSharp.Compiler.ConstraintSolver
open FSharp.Compiler.DiagnosticMessage
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Features
open FSharp.Compiler.Infos
open FSharp.Compiler.IO
open FSharp.Compiler.Lexhelp
Expand Down Expand Up @@ -379,7 +380,7 @@ type PhasedDiagnostic with
// Level 2
| _ -> 2

member x.IsEnabled(severity, options) =
member private x.IsEnabled(severity, options) =
let level = options.WarnLevel
let specificWarnOn = options.WarnOn
let n = x.Number
Expand Down Expand Up @@ -412,19 +413,25 @@ type PhasedDiagnostic with
member x.AdjustSeverity(options, severity) =
let n = x.Number

let warnOff () = List.contains n options.WarnOff
let localWarnon () = WarnScopes.IsWarnon options n x.Range

let localNowarn () = WarnScopes.IsNowarn options n x.Range

let warnOff () =
List.contains n options.WarnOff && not (localWarnon ()) || localNowarn ()

match severity with
| FSharpDiagnosticSeverity.Error -> FSharpDiagnosticSeverity.Error
| FSharpDiagnosticSeverity.Warning when
x.IsEnabled(severity, options)
&& ((options.GlobalWarnAsError && not (warnOff ()))
|| List.contains n options.WarnAsError)
|| List.contains n options.WarnAsError && not (localNowarn ()))
&& not (List.contains n options.WarnAsWarn)
->
FSharpDiagnosticSeverity.Error
| FSharpDiagnosticSeverity.Info when List.contains n options.WarnAsError && not (localNowarn ()) -> FSharpDiagnosticSeverity.Error
| FSharpDiagnosticSeverity.Warning when x.IsEnabled(severity, options) && not (warnOff ()) -> FSharpDiagnosticSeverity.Warning
| FSharpDiagnosticSeverity.Info when List.contains n options.WarnAsError -> FSharpDiagnosticSeverity.Error
| FSharpDiagnosticSeverity.Warning when localWarnon () -> FSharpDiagnosticSeverity.Warning
| FSharpDiagnosticSeverity.Info when List.contains n options.WarnOn && not (warnOff ()) -> FSharpDiagnosticSeverity.Warning
| FSharpDiagnosticSeverity.Info when x.IsEnabled(severity, options) && not (warnOff ()) -> FSharpDiagnosticSeverity.Info
| _ -> FSharpDiagnosticSeverity.Hidden
Expand Down Expand Up @@ -2276,48 +2283,25 @@ type PhasedDiagnostic with
//----------------------------------------------------------------------------
// Scoped #nowarn pragmas

/// Build an DiagnosticsLogger that delegates to another DiagnosticsLogger but filters warnings turned off by the given pragma declarations
//
// NOTE: we allow a flag to turn of strict file checking. This is because file names sometimes don't match due to use of
// #line directives, e.g. for pars.fs/pars.fsy. In this case we just test by line number - in most cases this is sufficient
// because we install a filtering error handler on a file-by-file basis for parsing and type-checking.
// However this is indicative of a more systematic problem where source-line
// sensitive operations (lexfilter and warning filtering) do not always
// interact well with #line directives.
type DiagnosticsLoggerFilteringByScopedPragmas
(checkFile, scopedPragmas, diagnosticOptions: FSharpDiagnosticOptions, diagnosticsLogger: DiagnosticsLogger) =
/// Build an DiagnosticsLogger that delegates to another DiagnosticsLogger but filters warnings (still needed??)
type DiagnosticsLoggerFilteringByScopedPragmas(diagnosticOptions: FSharpDiagnosticOptions, diagnosticsLogger: DiagnosticsLogger) =
inherit DiagnosticsLogger("DiagnosticsLoggerFilteringByScopedPragmas")

let mutable realErrorPresent = false

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

if severity = FSharpDiagnosticSeverity.Error then
realErrorPresent <- true
diagnosticsLogger.DiagnosticSink(diagnostic, severity)
else
let report =
let warningNum = diagnostic.Number

match diagnostic.Range with
| Some m ->
scopedPragmas
|> List.exists (fun pragma ->
let (ScopedPragma.WarningOff(pragmaRange, warningNumFromPragma)) = pragma

warningNum = warningNumFromPragma
&& (not checkFile || m.FileIndex = pragmaRange.FileIndex)
&& posGeq m.Start pragmaRange.Start)
|> not
| None -> true

if report then
match diagnostic.AdjustSeverity(diagnosticOptions, severity) with
| FSharpDiagnosticSeverity.Hidden -> ()
| s -> diagnosticsLogger.DiagnosticSink(diagnostic, s)
match diagnostic.AdjustSeverity(diagnosticOptions, severity) with
| FSharpDiagnosticSeverity.Hidden -> ()
| s -> diagnosticsLogger.DiagnosticSink(diagnostic, s)

override _.ErrorCount = diagnosticsLogger.ErrorCount

override _.CheckForRealErrorsIgnoringWarnings = realErrorPresent

let GetDiagnosticsLoggerFilteringByScopedPragmas (checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) =
DiagnosticsLoggerFilteringByScopedPragmas(checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger
let GetDiagnosticsLoggerFilteringByScopedPragmas (diagnosticOptions, diagnosticsLogger) =
DiagnosticsLoggerFilteringByScopedPragmas(diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger
7 changes: 2 additions & 5 deletions src/Compiler/Driver/CompilerDiagnostics.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System.Text
open FSharp.Compiler.CompilerConfig
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Features
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text

Expand Down Expand Up @@ -78,11 +79,7 @@ type PhasedDiagnostic with

/// Get a diagnostics logger that filters the reporting of warnings based on scoped pragma information
val GetDiagnosticsLoggerFilteringByScopedPragmas:
checkFile: bool *
scopedPragmas: ScopedPragma list *
diagnosticOptions: FSharpDiagnosticOptions *
diagnosticsLogger: DiagnosticsLogger ->
DiagnosticsLogger
diagnosticOptions: FSharpDiagnosticOptions * diagnosticsLogger: DiagnosticsLogger -> DiagnosticsLogger

/// Remove 'implicitIncludeDir' from a file name before output
val SanitizeFileName: fileName: string -> implicitIncludeDir: string -> string
Expand Down
Loading
Loading