-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762 #16485
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
Conversation
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
…ing unneeded ObjCHeader.
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
jrose-apple
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this, David! All my comments are small.
| /// a particular consumer if diagnostic goes there. | ||
| /// | ||
| /// (For Xcode compatibility, batch mode must suppress diagnostics to | ||
| /// non-primaries.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really accurate. Emitting diagnostics to non-primaries is a normal thing to do and has nothing to do with Xcode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean "omitting diagnostics to non-primaries"? If emitting them is normal, then why are we omitting them if not for Xcode compatibility? What would be the accurate statement here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, emitting is correct. We are omitting them so that we don't end up with a copy in multiple serialized diagnostic files. It's true that only Xcode reads those files right now, but that's not a "compatibility" issue, and it's not really part of the design here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have rewritten that comment. Thanks for clarifying!
lib/AST/DiagnosticConsumer.cpp
Outdated
| assert(bufferID.hasValue() && "consumer registered for unknown file"); | ||
| CharSourceRange range = SM.getRangeForBuffer(bufferID.getValue()); | ||
| ConsumersOrderedByRange.emplace_back(range, pair.second.get()); | ||
| ConsumersOrderedByRange.emplace_back(range, pair.second ? pair.second.get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe get handles this already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed.
lib/AST/DiagnosticConsumer.cpp
Outdated
| } else if (DiagnosticConsumer *c = specificConsumer.getValue()) | ||
| c->handleDiagnostic(SM, Loc, Kind, FormatString, FormatArgs, Info); | ||
| else { | ||
| /// suppress non-primary diagnostic in batch mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This should not be a doc comment, and it should be formatted like a sentence.
Extra-nitpick: I'm not sure it's officially in the style guide, but I'd prefer if all parts of an if/else if/else chain are consistent about whether they use braces!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I have fixed those nitpicks, though I liked the other rule about using braces for > 1 line. I guess the idea is to use the disjunction: braces when either arm has > 1 line.
| bool FrontendInputsAndOutputs::forEachInputNotProducingSupplementaryOutput( | ||
| llvm::function_ref<bool(const InputFile &)> fn) const { | ||
| // If no primary inputs, compiler is in whole-module-optimzation mode, and | ||
| // every input can produce supplementary outputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: "contributes to the supplementary outputs", maybe? Because we still only produce one of each supplementary output for the whole job in WMO mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree; your comment is a great catch, and not just a nitpick! I have fixed the code. Should probably add a test for this case in a subsequent PR.
| printAsObjCIfNeeded( | ||
| Invocation.getObjCHeaderOutputPathForAtMostOnePrimary(), | ||
| Instance.getMainModule(), opts.ImplicitObjCHeaderPath, | ||
| moduleIsPublic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you save this for a later PR? (I'm confused as to why it's needed anyway, but it's not relevant here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how to.
Without this fix, the test causes the compiler to falsify an assertion. If you ask for a -typecheck in batch mode, it calls getObjCHeaderOutputPathForAtMostOnePrimary, but that trips an assertion because there is >1 primary, even though no objC header has been requested.
The test could be folded into getObjCHeaderOutputPathForAtMostOnePrimary but that would be inconsistent with the other ForAtMostOnePrimary functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What changed that makes this come up now, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Will investigate after lunch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this to be a bug that has been there for a while. I ran an older version of the compiler with the following arguments: -frontend -typecheck -primary-file /s/io/1.swift -primary-file /s/io/2.swift (where each .swift file is empty) and it falsified an assertion.
It is the combination of -typecheck with > 1 primary that excites the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I guess we can sneak it in here then.
| // NO-DIAGNOSTICS: Number of diagnostics: 0 | ||
|
|
||
| // RUN: not %FileCheck -check-prefix=ERROR %s <%t.main.txt | ||
| // RUN: not %FileCheck -check-prefix=ERROR %s <%t.empty.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This time I'm going to ask that you use the CHECK-NOT strategy. If anyone adds additional ERROR check lines, this won't be testing the same thing anymore.
(although honestly the NO-DIAGNOSTICS check is probably good enough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't completely understand.
- Do you mean to ask for combined or separate FileCheck invocations for the positive and negative checks?
- Or do you prefer simply the NO-DIAGNISTICS check?
- When you write "this won't be testing the same thing anymore", I don't understand the meaning of "same".
I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm saying it's bad style to use not %FileCheck, because in general there are many ways something can fail. In this case there's only one CHECK line that's being matched, so not %FileCheck + CHECK is equivalent to %FileCheck + CHECK-NOT, but that's not generally a good thing to rely on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks. Fixed.
|
|
||
|
|
||
| func test(x: SomeType) { | ||
| // CHECK-MAIN-DAG: serialized-diagnostics-batch-mode.swift:[[@LINE]]:3: error: use of unresolved identifier 'nonexistent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually the right error, and you're not testing these CHECK lines. Did you mean to be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I goofed. Thanks. Check lines removed.
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
|
|
||
| // RUN: %FileCheck -check-prefix=NO-ERROR %s <%t.main.txt | ||
| // RUN: %FileCheck -check-prefix=NO-ERROR %s <%t.empty.txt | ||
| // NO-ERROR-NOT: error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
| /// non-primaries.) | ||
| /// (If batch mode failed to suppress diagnostics for non-primary files, it | ||
| /// would end up writing each of those diagnostics in each primary file's | ||
| /// serialized diagnostic file.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should have been clearer, because this is still describing the behavior (which is already on the line above). I don't think you should have any comment here at all, because it's not FileSpecificDiagnosticConsumer's job to decide why some diagnostics are suppressed. If you have a comment at the client side, it should note that we're relying on diagnostics located in a non-primary file already appearing when you compile that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's easy: Comment deleted.
|
@swift-ci please smoke test |
| return forEachNonPrimaryInput(fn); | ||
| // If no primary inputs, compiler is in whole-module-optimization mode, and | ||
| // only the first input can produce supplementary outputs, although all | ||
| // inputs may contribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh. This is what I meant by the name being wrong. We want the behavior you had before, even though it's not the complement of forEachInputProducingSupplementaryOutput, because it would be Very Bad if we dropped diagnostics from every file but the first one in WMO mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed per off-line discussion.
…antics for forEachInputNotProducingSupplementaryOutput.
graydon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me!
|
@swift-ci please smoke test and merge |
|
@swift-ci Please smoke test |
[Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762 (cherry picked from commit 46b8ad3)
[Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762 (cherry picked from commit 46b8ad3)
When in batch mode, swallow diagnostics for non-primary files.
rdar://40032762