Skip to content

Commit fd63a1e

Browse files
author
David Ungar
committed
Change strategy for non-primaries
No more vacuous subconsumers. Output into active primary or everywhere.
1 parent 7ac4592 commit fd63a1e

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

include/swift/AST/DiagnosticConsumer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
174174
/// diagnostics that are not in any of the other consumers' files.
175175
std::string inputFileName;
176176

177-
/// The consumer (if any) for diagnostics associated with the inputFileName.
178-
/// A null pointer for the DiagnosticConsumer means that diagnostics for
179-
/// this file should not be emitted.
177+
/// The consumer for diagnostics associated with the inputFileName.
178+
/// Should never be null, because diagnostics for non-primary files are
179+
/// either emitted in the corresponding primary file's .dia or are
180+
/// emitted to every .dia.
180181
std::unique_ptr<DiagnosticConsumer> consumer;
181182

182183
// Has this subconsumer ever handled a diagnostic that is an error?
@@ -196,8 +197,6 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
196197
ArrayRef<DiagnosticArgument> FormatArgs,
197198
const DiagnosticInfo &Info,
198199
const SourceLoc defaultDiagnosticLoc) {
199-
if (!getConsumer())
200-
return;
201200
hasAnErrorBeenConsumed |= Kind == DiagnosticKind::Error;
202201
getConsumer()->handleDiagnostic(SM, Loc, Kind, FormatString, FormatArgs,
203202
Info, defaultDiagnosticLoc);

lib/AST/DiagnosticConsumer.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
186186
FileSpecificDiagnosticConsumer::findSubconsumer(
187187
SourceManager &SM, SourceLoc loc, DiagnosticKind Kind,
188188
SourceLoc defaultDiagnosticLoc) {
189+
// Ensure that a note goes to the same place as the preceeding non-note.
189190
switch (Kind) {
190191
case DiagnosticKind::Error:
191192
case DiagnosticKind::Warning:
@@ -203,19 +204,13 @@ Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
203204
FileSpecificDiagnosticConsumer::findSubconsumerForNonNote(
204205
SourceManager &SM, const SourceLoc loc,
205206
const SourceLoc defaultDiagnosticLoc) {
206-
const auto subconsumer = subconsumerForLocation(SM, loc);
207-
if (!subconsumer)
208-
return None; // No place to put it
209-
if ((*subconsumer)->getConsumer())
207+
if (auto subconsumer = subconsumerForLocation(SM, loc))
210208
return subconsumer; // A primary file with a .dia file
211-
if (defaultDiagnosticLoc.isInvalid())
212-
return None;
213-
const auto currentPrimarySubconsumer =
214-
subconsumerForLocation(SM, defaultDiagnosticLoc);
215-
assert(currentPrimarySubconsumer &&
216-
(*currentPrimarySubconsumer)->getConsumer() &&
217-
"current primary must have a .dia file");
218-
return currentPrimarySubconsumer;
209+
// The diagnostic is located in a non-primary.
210+
// Try to put it in the current primary file's .dia file.
211+
if (defaultDiagnosticLoc.isValid())
212+
return subconsumerForLocation(SM, defaultDiagnosticLoc);
213+
return None;
219214
}
220215

221216
bool FileSpecificDiagnosticConsumer::finishProcessing() {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,24 +1539,12 @@ createDispatchingDiagnosticConsumerIfNeeded(
15391539

15401540
inputsAndOutputs.forEachInputProducingSupplementaryOutput(
15411541
[&](const InputFile &input) -> bool {
1542-
if (auto consumer = maybeCreateConsumerForDiagnosticsFrom(input))
1542+
if (auto consumer = maybeCreateConsumerForDiagnosticsFrom(input)) {
1543+
assert(consumer && "Consumer should always be non-null");
15431544
subconsumers.emplace_back(input.file(), std::move(consumer));
1545+
}
15441546
return false;
15451547
});
1546-
// For batch mode, the compiler must swallow diagnostics pertaining to
1547-
// non-primary files in order to avoid Xcode showing the same diagnostic
1548-
// multiple times. So, create a diagnostic "eater" for those non-primary
1549-
// files.
1550-
// To avoid introducing bugs into WMO or single-file modes, test for multiple
1551-
// primaries.
1552-
if (inputsAndOutputs.hasMultiplePrimaryInputs()) {
1553-
inputsAndOutputs.forEachNonPrimaryInput(
1554-
[&](const InputFile &input) -> bool {
1555-
subconsumers.emplace_back(input.file(), nullptr);
1556-
return false;
1557-
});
1558-
}
1559-
15601548
return FileSpecificDiagnosticConsumer::consolidateSubconsumers(subconsumers);
15611549
}
15621550

0 commit comments

Comments
 (0)