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 #18049

Open
wants to merge 112 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
7498b0b
WarnScopes (1): feature flag, baseline tests, and WarnScopes module
Martin521 Nov 22, 2024
9590899
WarnScopes (2): changes to lexing and parsing
Martin521 Nov 22, 2024
7b2eeb2
WarnScopes (3): remove legacy #nowarn processing
Martin521 Nov 22, 2024
4520e55
WarnScopes (4): integrate the new functionality and add tests
Martin521 Nov 22, 2024
0fdaa43
WarnScopes (5): add warn directive trivia
Martin521 Nov 22, 2024
fb848d9
WarnScopes (6): enable warn directive trivia
Martin521 Nov 22, 2024
e623fde
WarnScopes (7): remove defunct types and parameters
Martin521 Nov 22, 2024
62eb32a
WarnScopes (8): IlVerify baseline update
Martin521 Nov 22, 2024
5c77ecd
WarnScopes (9): ran fantomas, updated release notes
Martin521 Nov 22, 2024
bbdea9d
updated PR number in release notes
Martin521 Nov 22, 2024
1c97f60
adapted scipt test to WarnScopes
Martin521 Nov 22, 2024
ca6fd7a
updated PR link in release notes (now really)
Martin521 Nov 22, 2024
0d0e7bf
Merge remote-tracking branch 'upstream/main' into scoped-nowarn-dev
Martin521 Nov 22, 2024
29212c5
skipped a test in vsintegration that might need a vs update
Martin521 Nov 25, 2024
6c3ab12
Merge remote-tracking branch 'upstream/main' into scoped-nowarn-dev
Martin521 Nov 25, 2024
ceb7e38
Merge remote-tracking branch 'upstream/main' into scoped-nowarn-dev
Martin521 Nov 25, 2024
23e366f
merge upstream/main
Martin521 Nov 26, 2024
a727e67
moved ilverify baselines
Martin521 Nov 26, 2024
cdfef12
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Nov 27, 2024
e8a35f4
merge upstream/main
Martin521 Nov 29, 2024
2214e83
merge upstream/main
Martin521 Dec 2, 2024
5f358b3
update ilverify baselines
Martin521 Dec 2, 2024
30d66e2
merge upstream/main
Martin521 Dec 3, 2024
387049e
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Dec 3, 2024
d617fbd
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Dec 4, 2024
e7eb32f
update ilverify baseline (line number changes only)
Martin521 Dec 4, 2024
f05f993
merge upstream/main
Martin521 Dec 4, 2024
eba854f
merge upstream/main
Martin521 Dec 6, 2024
7fa6352
merge upstream/main
Martin521 Dec 15, 2024
1301542
fix merge issue
Martin521 Dec 15, 2024
48d0875
ilverify baselines
Martin521 Dec 15, 2024
2d29b15
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Dec 16, 2024
2f44500
made WarnScopes.IsWarnon / IsNowarn public
Martin521 Dec 16, 2024
f526549
merge upstream/main
Martin521 Dec 16, 2024
7e96882
added surface area change (IsNowarn/IsWarnon) to baseline
Martin521 Dec 16, 2024
c278c6a
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Dec 18, 2024
bbb8d7c
merge upstream/main
Martin521 Dec 21, 2024
e12a846
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 1, 2025
093b436
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 2, 2025
311fd2f
merge upstream/main
Martin521 Jan 3, 2025
8796c21
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 6, 2025
f9c0d6a
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 8, 2025
ca557af
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 8, 2025
bf33f82
merge upstream/main
Martin521 Jan 11, 2025
fc1eecf
fix merge issue
Martin521 Jan 11, 2025
bfc865c
moved release notes
Martin521 Jan 11, 2025
b02d2a0
merge upstream/main
Martin521 Jan 14, 2025
5edff8c
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 14, 2025
b8c92b9
merge upstream/main
Martin521 Jan 16, 2025
98ee3ef
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 16, 2025
2986459
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 17, 2025
5403abd
merge upstream/main
Martin521 Jan 21, 2025
0318a6a
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 22, 2025
56a1fb3
update ilverify baselines
Martin521 Jan 22, 2025
e538845
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 23, 2025
931fb86
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 23, 2025
205a9fc
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 27, 2025
5723876
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Jan 30, 2025
5ddd0e2
adjust vs tests
psfinaki Feb 4, 2025
dc0d5e6
Merge pull request #1 from psfinaki/scoped-nowarn-2
Martin521 Feb 4, 2025
8c665e5
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 4, 2025
6550c08
ilverify baselines
Martin521 Feb 4, 2025
367c231
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 4, 2025
8b58d99
review follow-up
Martin521 Feb 5, 2025
8c58e82
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 5, 2025
c7655da
fantomas
Martin521 Feb 6, 2025
900f3ad
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 15, 2025
10f0896
ilverify baselines
Martin521 Feb 16, 2025
ce18135
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 21, 2025
7e3cb94
dotnet update (cherry pick PR18333)
Martin521 Feb 23, 2025
991bb3d
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 25, 2025
53d8e94
unique project names in testing
Martin521 Feb 27, 2025
88c058d
just a typo fix for more consistency
Martin521 Feb 28, 2025
9aec259
minimizing WarnScopes surface
Martin521 Feb 28, 2025
e736f85
surface area bsl update
Martin521 Feb 28, 2025
33924fa
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Feb 28, 2025
85cef95
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 4, 2025
536f866
Added warn scopes test to service tests
Martin521 Mar 5, 2025
acac08c
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 6, 2025
b4c9032
Added WarnScopeTests to FSharp.Compiler.Service.Tests
Martin521 Mar 11, 2025
ceaec2c
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 11, 2025
d6dbcf9
Added warn scope tests using various service APIs (plus some fixes fo…
Martin521 Mar 13, 2025
37c1bbe
implemented some RFC diagnostic details
Martin521 Mar 13, 2025
2c93d30
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 13, 2025
89865f4
fantomas
Martin521 Mar 13, 2025
a47b80d
ilverify baselines
Martin521 Mar 13, 2025
12180ca
Add WarnScope AST tests (and correct the trivia ranges)
Martin521 Mar 14, 2025
c7a8bb4
Adress review comment re. tcConfig
Martin521 Mar 15, 2025
c4b0423
fantomas
Martin521 Mar 15, 2025
53cfa5e
recreate global nowarn for scripts for langVersion < 10
Martin521 Mar 15, 2025
0fd762c
fantomas
Martin521 Mar 15, 2025
118e5dc
Revert vs test (now that we have legacy script global nowarn back)
Martin521 Mar 15, 2025
558689c
updated ilverify baselines
Martin521 Mar 15, 2025
b6cd9a4
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 18, 2025
b07d57b
ilverify baselines
Martin521 Mar 18, 2025
8bd242b
fixed changed error number
Martin521 Mar 18, 2025
e5a887f
Added WarnScopes test with multiple interactions
Martin521 Mar 25, 2025
1cad767
fixed bug in WarnScopes storage
Martin521 Mar 25, 2025
c39de39
refactor WarnScopes module
Martin521 Mar 25, 2025
1acc930
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 25, 2025
3072b66
update devcontainer sdk version
Martin521 Mar 25, 2025
045e05f
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 25, 2025
a9f399f
ilverify baselines
Martin521 Mar 25, 2025
9472508
fantomas
Martin521 Mar 25, 2025
e7d9260
extended WarnScopes test for CheckFileInProject
Martin521 Mar 27, 2025
021ff6b
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 27, 2025
5194e91
ilverify baselines, fantomas
Martin521 Mar 27, 2025
588b586
undo devcontainer changes
Martin521 Mar 28, 2025
d39db69
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 31, 2025
359d136
fix tcConfig reuse in TransparentCompiler
Martin521 Mar 31, 2025
3783f08
Merge remote-tracking branch 'upstream/main' into scoped-nowarn
Martin521 Mar 31, 2025
4303d53
formatting fix
Martin521 Mar 31, 2025
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/release-notes/.FSharp.Compiler.Service/9.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Type parameter constraint `null` in generic code will now automatically imply `not struct` ([Issue #18320](https://github.com/dotnet/fsharp/issues/18320), [PR #18323](https://github.com/dotnet/fsharp/pull/18323))
* Add a switch to determine whether to generate a default implementation body for overridden method when completing. [PR #18341](https://github.com/dotnet/fsharp/pull/18341)
* Use a more accurate range for CE Combine methods. [PR #18394](https://github.com/dotnet/fsharp/pull/18394)

* Scoped Nowarn: added the #warnon compiler directive ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [RFC FS-1146 PR](https://github.com/fsharp/fslang-design/pull/782), [PR #18049](https://github.com/dotnet/fsharp/pull/18049))

### Changed
* FSharpCheckFileResults.ProjectContext.ProjectOptions will not be available when using the experimental Transparent Compiler feature. ([PR #18205](https://github.com/dotnet/fsharp/pull/18205))
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added type conversions cache, only enabled for compiler runs ([PR#17668](https://github.com/dotnet/fsharp/pull/17668))
* Support ValueOption + Struct attribute as optional parameter for methods ([Language suggestion #1136](https://github.com/fsharp/fslang-suggestions/issues/1136), [PR #18098](https://github.com/dotnet/fsharp/pull/18098))
* Warn when `unit` is passed to an `obj`-typed argument ([PR #18330](https://github.com/dotnet/fsharp/pull/18330))
* Scoped Nowarn: added the #warnon compiler directive ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [RFC FS-1146 PR](https://github.com/fsharp/fslang-design/pull/782), [PR #18049](https://github.com/dotnet/fsharp/pull/18049))

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,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 @@ -5892,7 +5892,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 @@ -10391,7 +10391,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
58 changes: 19 additions & 39 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,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 +412,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 @@ -2274,51 +2280,25 @@ type PhasedDiagnostic with
diagnostic.OutputContext(buf, prefix, fileLineFunction)
diagnostic.Output(buf, tcConfig, severity))

//----------------------------------------------------------------------------
// 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) =
inherit DiagnosticsLogger("DiagnosticsLoggerFilteringByScopedPragmas")
/// Build an DiagnosticsLogger that delegates to another DiagnosticsLogger but filters warnings
type DiagnosticsLoggerFilteringByScopedNowarn(diagnosticOptions: FSharpDiagnosticOptions, diagnosticsLogger: DiagnosticsLogger) =
inherit DiagnosticsLogger("DiagnosticsLoggerFilteringByScopedNowarn")

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 GetDiagnosticsLoggerFilteringByScopedNowarn (diagnosticOptions, diagnosticsLogger) =
DiagnosticsLoggerFilteringByScopedNowarn(diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger
8 changes: 2 additions & 6 deletions src/Compiler/Driver/CompilerDiagnostics.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ type PhasedDiagnostic with
unit

/// 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
val GetDiagnosticsLoggerFilteringByScopedNowarn:
diagnosticOptions: FSharpDiagnosticOptions * diagnosticsLogger: DiagnosticsLogger -> DiagnosticsLogger

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