-
Notifications
You must be signed in to change notification settings - Fork 344
Separate clangimporter errors #6864
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
Separate clangimporter errors #6864
Conversation
6a192b7
to
f5dfc31
Compare
@swift-ci test |
lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp
Outdated
Show resolved
Hide resolved
f5dfc31
to
f619b5f
Compare
@swift-ci test |
Introduce a "transactional" diagnostic consumer. Swift compiler and ClangImporter and LLDB operations can produce This patch introduces SwiftASTContext::forkDiagnosticConsumer() which
I'm not happy by the amount of code needed to make this work, or the |
@swift-ci test |
@swift-ci test windows |
d11204f
to
a300454
Compare
@swift-ci test |
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.
Haven't looked at all of SwiftASTContext yet but the other stuff looks ok I think.
if (expr_diagnostics->HasErrors() || | ||
m_swift_ast_ctx.HasClangImporterErrors()) { | ||
diagnostic_manager.PutString(eDiagnosticSeverityRemark, | ||
"couldn't IRGen expression"); |
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.
Are these messages meant to be seen by end users? If so, IRGen as a term is pretty specific to clang, swift, and llvm... maybe we can say something a little more user friendly like:
Failed to compile expression: IR generation failure
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.
That's a valid concern! Note that this is just one remark in a longer error. For example, the test in lang/swift/clangimporter/clang_errorhandling
produces:
error: expression failed to parse:
couldn't IRGen expression
error: /Volumes/Data/swift-5.9/llvm-project/lldb/test/API/lang/swift/clangimporter/clang_errorhandling/bridging-header.h:2:1: error: unknown type name 'i'
i am a syntax error
^
error: /Volumes/Data/swift-5.9/llvm-project/lldb/test/API/lang/swift/clangimporter/clang_errorhandling/bridging-header.h:2:5: error: expected ';' after top level declarator
i am a syntax error
^
error: failed to import bridging header '/Volumes/Data/swift-5.9/llvm-project/lldb/test/API/lang/swift/clangimporter/clang_errorhandling/bridging-header.h'
as the full error message.
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.
The IRGen remark is really mostly there for LLDB developers to understand at what point the expression failed to help with troubleshooting.
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.
With this in mind — any suggestions for how to improve the error message?
3c23fdd
to
f79bcc7
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
@swift-ci test windows |
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 didn't re-review everything but I see my concerns were addressed to LGTM.
SwiftASTContext resets the state of the DiagnosticConsumer after each import to make failed module imports non-fatal, however, the internal state of the DiagnosticEngine in Swift's embedded Clang compiler does not reset when encountering a fatal error. By storing Clang diagnostics separately, these errors can be surfaces when an expression fails to IRGen (which is usually when these fatal Clang diagnostics turn into an unrecoverable problem). rdar://108557254
Swift compiler and ClangImporter and LLDB operations can produce diagnostics, which are stored in StoringDiagnosticConsumer. Operations such as expression evaluation of module imports may produce multiple non-fatal error diagnostics. Prior to this patch, the expression parser would clear the diagnostic consumer before running. This had the unwanted side-effect of sometimes clearing out unreported earlier diagnostics. This patch introduces SwiftASTContext::forkDiagnosticConsumer() which returns an RAII object that behaves like a diagnostic consumer, can tell whether diagnostics where produced during its lifetime, and resets the StoringDiagnosticConsumer to its previous state upon destruction. This way - unreported diagnostics don't get cleared by the expression parser - the expression parser has precise access to only the diagnostics it produced - while still being able to report persistent errors (such as clang import failures) that happened before the expression parser started. I'm not happy by the amount of code needed to make this work, or the specific implementation, but at least the interface provided to the outside is nice and clean.
c7a7056
to
a2052d2
Compare
@swift-ci test |
@swift-ci test windows |
SwiftASTContext resets the state of the DiagnosticConsumer after each
import to make failed module imports non-fatal, however, the internal
state of the DiagnosticEngine in Swift's embedded Clang compiler does
not reset when encountering a fatal error. By storing Clang
diagnostics separately, these errors can be surfaces when an
expression fails to IRGen (which is usually when these fatal Clang
diagnostics turn into an unrecoverable problem).
rdar://108557254