Skip to content

Add all deserialization fatal output to the pretty stack trace #37743

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

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Jun 2, 2021

Rather than outputting diagnostics and to stderr, output all the extra
information added when deserialization fatally fails to the pretty stack
trace instead. Since the pretty stack trace is added to crash logs, this
should avoid the dance of requesting the compiler output

  • Moves the previous "**** DESERIALIZATION FAILURE ..." output to the
    last pretty stack trace line

  • Removes the module and compiler version notes added to the fatal
    diagnostic

  • Adds a new effective compiler version line for all frontend failure.
    Somewhat duplicates the line from the driver, but adds in the
    effective version

  • Adds a new line for the full misc version of the module that failed.
    May double up with previous "While reading from ..." lines that are
    added in various deserialization methods, but better to have it
    twice than not at all

@bnbarham bnbarham requested a review from xymus June 2, 2021 06:21
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 2, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 2, 2021

Build failed
Swift Test Linux Platform
Git Sha - 126e03facf3f99360b3c51b4ec140743c763f576

@bnbarham bnbarham force-pushed the prefer-pretty-stack-trace branch from 126e03f to ae06648 Compare June 2, 2021 08:07
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 2, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 2, 2021

Build failed
Swift Test Linux Platform
Git Sha - ae066483a5e08a003bed299675cf081091f70ed9

@swift-ci
Copy link
Contributor

swift-ci commented Jun 2, 2021

Build failed
Swift Test OS X Platform
Git Sha - ae066483a5e08a003bed299675cf081091f70ed9

os << "module '" << Name << "' with full misc version '" << MiscVersion
<< "'";
if (Bits.IsAllowModuleWithCompilerErrorsEnabled)
os << " (built while allowing compiler errors)";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the flag instead here built with -experimental-allow-module-with-compiler-errors? It would be more precise and we could add more relevant flags to it in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sounds good 👍

@@ -12,6 +12,7 @@
// CHECK: Stack dump:
// CHECK-NEXT: Program arguments:
// CHECK-NEXT: Swift version
// CHECK-NEXT: Compiling with Swift version
Copy link
Contributor

Choose a reason for hiding this comment

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

This is part of the existing output right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, which also answers your question below - the driver current outputs "Swift version ..." but does so before parsing any flags. I added a second version output after flags are passed so that we can pass in the effective version as well, which is the "Compiling with..." line (though note some tests are failing because apparently this can actually be Apple Swift sometimes).

I could remove the first version, but crashes during argument parsing would be missing the version then. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks we only want the effective language version out of that line and from what I see swift::getSwiftFullVersion directly prints the value of LangOpts.EffectiveLanguageVersion. How about we bring that logic up and print the language version on its own line only if it's different than getCurrentLanguageVersion?

void ModuleFileSharedCore::fatal(llvm::Error error) {
logAllUnhandledErrors(std::move(error), llvm::errs(),
"\n*** DESERIALIZATION FAILURE (please include this "
"section in any bug report) ***\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good change but I feel nostalgic with the idea of losing the part the nobody read (please include this section in any bug report)!

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 think the main issue is that most of the time the compiler output wouldn't even be seen - ie. there'd be a crash and it gets reported based on the crash log and not the output.

os << "Compiling with " <<
version::getSwiftFullVersion(LangOpts.EffectiveLanguageVersion);
if (LangOpts.AllowModuleWithCompilerErrors)
os << " while allowing modules with compiler errors enabled";
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too we could list the flag instead.

}
getContext().Diags.diagnose(
SourceLoc(), diag::serialization_compatibility_version_mismatch,
effectiveVersionBuffer, Core->Name, compatVersionBuffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still have the information about the Swift language compatibility version of the module somewhere in the output? This note has been useful to me at least once to quickly explain a deserialization failure due to changes in ClangImporter behaviors between two Swift versions.

Copy link
Contributor Author

@bnbarham bnbarham Jun 2, 2021

Choose a reason for hiding this comment

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

See above re. the effective version, as an example output:

Stack dump:
0.	Program arguments: ......
1.	Swift version 5.5-dev (LLVM <hash>, Swift <hash>)
2.	Compiling with Swift version 5.5-dev effective-4.2 (LLVM <hash>, Swift <hash>)
3.	While evaluating request TypeCheckSourceFileRequest(source_file "<stdin>")
4.	While type-checking statement at [<stdin>:1:13 - line:1:21] RangeText="_ = Sub."
5.	While type-checking expression at [<stdin>:1:13 - line:1:21] RangeText="_ = Sub."
6.	While evaluating request QualifiedLookupRequest(0x7fa27c81ce00 TopLevelCodeDecl line=1, {Lib.(file).Sub}, 'disappearingMethod', { NL_ProtocolMembers, NL_RemoveNonVisible, NL_RemoveOverridden, NL_OnlyTypes })
7.	While evaluating request DirectLookupRequest(directly looking up 'disappearingMethod' on Lib.(file).Sub with options {  })
8.	While loading members for 'Sub' (in module 'Lib')
9.	*** DESERIALIZATION FAILURE ***
module 'Lib' with full misc version '5.5(4.1.50)/Swift version 5.5-dev (LLVM <hash>, Swift <hash>)'
could not find 'disappearingMethod()' in parent class

So here we can see the version being compiled is effective-4.2 (2.) and the module was compiled with (4.1.50) (9.)

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

Thank you for this!

@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 3, 2021

To give an example of the full stderr that's now output:

<unknown>:0: error: fatal error encountered while reading from module 'Lib'; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: ...
1.	Swift version 5.5-dev (LLVM <hash>, Swift <hash>)
2.	Compiling with Swift version 5.5-dev effective-4.2 (LLVM <hash>, Swift <hash>) and -experimental-allow-module-with-compiler-errors
3.	While evaluating request TypeCheckSourceFileRequest(source_file "<stdin>")
4.	While type-checking statement at [<stdin>:1:13 - line:1:21] RangeText="_ = Sub."
5.	While type-checking expression at [<stdin>:1:13 - line:1:21] RangeText="_ = Sub."
6.	While evaluating request QualifiedLookupRequest(0x7fc86e810e00 TopLevelCodeDecl line=1, {Lib.(file).Sub}, 'disappearingMethod', { NL_ProtocolMembers, NL_RemoveNonVisible, NL_RemoveOverridden, NL_OnlyTypes })
7.	While evaluating request DirectLookupRequest(directly looking up 'disappearingMethod' on Lib.(file).Sub with options {  })
8.	While loading members for 'Sub' (in module 'Lib')
9.	*** DESERIALIZATION FAILURE ***
module 'Lib' with full misc version '5.5(4.1.50)/Swift version 5.5-dev (LLVM <hash>, Swift <hash>)' (built with -experimental-allow-module-with-compiler-errors)
could not find 'disappearingMethod()' in parent class

As I mentioned in one of the comments, I'm not a huge fan of doubling up the compiler version, @xymus do you think it's worth keeping the one before arguments are parsed? Also, assuming we have program arguments there's also the double up with the -experimental-allow-module-with-compiler-errors there and the one in Compiling with ... and -experimental-allow-module-with-compiler-errors.

@bnbarham bnbarham force-pushed the prefer-pretty-stack-trace branch from ae06648 to 452c3e4 Compare June 3, 2021 03:44
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 3, 2021

@swift-ci please test

Rather than outputting diagnostics and to stderr, output all the extra
information added when deserialization fatally fails to the pretty stack
trace instead. Since the pretty stack trace is added to crash logs, this
should avoid the dance of requesting the compiler output

  - Moves the previous "**** DESERIALIZATION FAILURE ..." output to the
    last pretty stack trace line

  - Removes the module and compiler version notes added to the fatal
    diagnostic

  - Adds a new effective compiler version line for all frontend failure.
    Somewhat duplicates the line from the driver, but adds in the
    effective version

  - Adds a new line for the full misc version of the module that failed.
    May double up with previous "While reading from ..." lines that are
    added in various deserialization methods, but better to have it
    twice than not at all
@bnbarham bnbarham force-pushed the prefer-pretty-stack-trace branch from 452c3e4 to 599ba8b Compare June 3, 2021 22:32
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 3, 2021

Okay, changed to just give the effective version and removed the superfluous "-experimental-allow-module-with-errors":

<unknown>:0: error: fatal error encountered while reading from module 'Lib'; ...
Stack dump:
0.	Program arguments: ...
1.	Swift version 5.5-dev (LLVM <hash>, Swift <hash>)
2.	Compiling with effective version 4.2
...
8.	While loading members for 'Sub' (in module 'Lib')
9.	*** DESERIALIZATION FAILURE ***
module 'Lib' with full misc version '5.5(4.1.50)/Swift version 5.5-dev (LLVM <hash>, Swift <hash>)' (built with -experimental-allow-module-with-compiler-errors)
could not find 'disappearingMethod()' in parent class

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 4, 2021

Build failed
Swift Test OS X Platform
Git Sha - 599ba8b

@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 4, 2021

@swift-ci please test macOS platform

@bnbarham bnbarham merged commit a68ce7b into swiftlang:main Jun 4, 2021
@bnbarham bnbarham deleted the prefer-pretty-stack-trace branch June 4, 2021 22:36
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.

4 participants