[4.2 EARLY] Fixes for batch mode diagnostics in Xcode #16530
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: This is fallout from Wire up FileSpecificDiagnosticConsumer for serialized diagnostics #14900, which was the first attempt to deal with batch mode being different from single-file mode in terms of what diagnostics get produced and where. There was a hole in that scheme, however: if processing B.swift results in a diagnostic being emitted in A.swift (and B.swift and A.swift are in different batches), that diagnostic would appear in every file in the same batch as B.swift. This (1) looks bad in Xcode's Log Editor, and (2) could result in a diagnostic that never goes away. (How? Fix the problem in A.swift, and A.swift and B.swift will get rebuilt…but not necessarily other files in B.swift's original batch.)
These changes do three things:
Change Sema diagnostics so that every diagnostic emitted in file A.swift while processing a different file B.swift would be emitted if we processed A.swift on its own.
Implicitly turn on
-continue-building-after-errors
when using batch mode to make sure we actually do process A.swift on its own in the same build. (A.swift might still not be processed if we're doing an incremental build, but that doesn't harm the model.)Stop emitting diagnostics located in A.swift altogether if A.swift isn't in the current batch.
Scope: Affects batch mode. (Also benignly tweaks some existing diagnostics in all modes.)
Issue: rdar://problem/40032762
Risk: Medium-high. We're choosing not to report some diagnostics in batch mode because we expect them to be reported elsewhere; if those assumptions are violated, users will not see these diagnostics at all, and will have to use either single-file or WMO instead.
Testing: Built a toy project and a real Apple project with the new compiler and observed the behavior of the Report Navigator for both warnings and errors.
Reviewed by: Me and @graydon (for @davidungar's change), @huonw and @DougGregor (for part of my changes), @davidungar (for the other part of my changes).