Skip to content

Conversation

@davidungar
Copy link
Contributor

@davidungar davidungar commented May 10, 2018

When in batch mode, swallow diagnostics for non-primary files.
rdar://40032762

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar requested review from graydon and jrose-apple May 10, 2018 00:43
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar changed the title [Batch Mode] WIP on suppressing diagnostics for non-primaries [Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762 May 10, 2018
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@jrose-apple jrose-apple left a 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.)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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!

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()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

} else if (DiagnosticConsumer *c = specificConsumer.getValue())
c->handleDiagnostic(SM, Loc, Kind, FormatString, FormatArgs, Info);
else {
/// suppress non-primary diagnostic in batch mode
Copy link
Contributor

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!

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.)

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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'
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

@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:
Copy link
Contributor

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.)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@davidungar
Copy link
Contributor Author

@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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

@graydon graydon left a 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!

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test and merge

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@davidungar davidungar merged commit 46b8ad3 into swiftlang:master May 10, 2018
jrose-apple pushed a commit to jrose-apple/swift that referenced this pull request May 11, 2018
[Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762

(cherry picked from commit 46b8ad3)
jrose-apple pushed a commit to jrose-apple/swift that referenced this pull request May 11, 2018
[Batch Mode] Suppressing diagnostics for non-primaries - rdar://40032762

(cherry picked from commit 46b8ad3)
@davidungar davidungar deleted the oddball-diags branch June 14, 2019 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants