-
Notifications
You must be signed in to change notification settings - Fork 333
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
[lldb] Use forward decls with redeclared definitions instead of minimal import for records #8222
[lldb] Use forward decls with redeclared definitions instead of minimal import for records #8222
Conversation
void CompleteRedeclChain(const clang::Decl *D) override { | ||
for (size_t i = 0; i < Sources.size(); ++i) | ||
for (size_t i = 0; i < Sources.size(); ++i) { |
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.
for (size_t i = 0; i < Sources.size(); ++i) { | |
for (auto &Source : Sources) { |
ImporterDelegateSP delegate_sp( | ||
GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx)); | ||
|
||
if (delegate_sp) | ||
delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); | ||
if (!TypeSystemClang::UseRedeclCompletion()) { |
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 think all other conditions were inverted so far. It would be nice to consistently check for the positive case so it's less confusing to read.
|
||
return true; | ||
} | ||
|
||
bool ClangASTImporter::CompleteAndFetchChildren(clang::QualType type) { | ||
if (!RequireCompleteType(type)) | ||
return false; | ||
const auto ret = RequireCompleteType(type); |
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's the return value of RequireCompleteType?
if (!RequireCompleteType(type)) | ||
return false; | ||
const auto ret = RequireCompleteType(type); | ||
if (TypeSystemClang::UseRedeclCompletion() || !ret) |
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 would write this as two separate conditions.
@@ -882,6 +963,14 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) { | |||
for (clang::Decl *candidate : lr) { | |||
if (candidate->getKind() == From->getKind()) { | |||
RegisterImportedDecl(From, candidate); | |||
|
|||
// If we're dealing with redecl chains. We want to find the definition, |
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.
// If we're dealing with redecl chains. We want to find the definition, | |
// If we're dealing with redecl chains, we want to find the definition, |
lldb_private::TypeSystemClang &m_ast; | ||
DIEToDeclMap m_die_to_decl; | ||
DIEToDeclContextMap m_die_to_decl_ctx; | ||
DeclContextToDIEMap m_decl_ctx_to_die; | ||
DIEToModuleMap m_die_to_module; | ||
DIEToRecordMap m_die_to_record_map; |
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.
Doxygen comment what this map is used for?
std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_up; | ||
|
||
struct TypeToComplete { |
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.
Why foes this have both a CompilerType and a lldb::Type?
@@ -227,6 +245,9 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser { | |||
void LinkDeclToDIE(clang::Decl *decl, | |||
const lldb_private::plugin::dwarf::DWARFDIE &die); | |||
|
|||
void RegisterDIE(lldb_private::plugin::dwarf::DWARFDebugInfoEntry *die, |
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.
Doxygen comment?
@@ -2615,6 +2706,120 @@ TypeSystemClang::GetDeclContextForType(clang::QualType type) { | |||
return nullptr; | |||
} | |||
|
|||
static clang::Type const *GetCompleteRecordType(clang::ASTContext *ast, |
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.
Comments?
@@ -8035,9 +8187,13 @@ clang::ObjCMethodDecl *TypeSystemClang::AddMethodToObjCObjectType( | |||
return nullptr; | |||
|
|||
clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); | |||
if (class_interface_decl) | |||
if (auto * def = class_interface_decl->getDefinition()) |
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.
clan-format
ac62cbe
to
d092bd7
Compare
@swift-ci test |
d092bd7
to
f4e9874
Compare
@swift-ci test |
Please test with following pull request: @swift-ci Please test macOS platform |
f4e9874
to
3686ac4
Compare
Please test with following pull request: @swift-ci test |
3686ac4
to
d487b84
Compare
Please test with following pull request: @swift-ci test |
63abffc
to
3ebe89e
Compare
I don't see the test reports? Is that because the PR is in DRAFT mode? |
3ebe89e
to
8ace0bc
Compare
…hodToObjCObjectType (llvm#73832) (cherry picked from commit bcb621f)
This patch backports a one-liner `std::to_underlying` that came with C++23. This is useful for refactoring unscoped enums into scoped enums, because the latter are not implicitly convertible to integer types. I followed libc++ implementation, but I consider their testing too heavy for us, so I wrote a simpler set of tests. (cherry picked from commit d0caa4e)
8ace0bc
to
3fa5017
Compare
The build wasn't passing, so tests weren't running yet. Should be fixed now |
Please test with following pull request: @swift-ci test |
3fa5017
to
70c9abd
Compare
Please test with following pull request: @swift-ci test |
Please test with following pull request: @swift-ci test Windows |
70c9abd
to
2e68ca9
Compare
Please test with following pull request: @swift-ci test |
swiftlang/swift#71724 |
Note, this is a no-op when the LLDB setting `plugin.typesystem.clang.experimental-redecl-completion` is not set (which is currently the default). So this patch has no affect unless the user explicitly opts into it. The type-completion rework (aka redecl-completion) implemented in swiftlang#8222 comes with a large performance penalty, since we now eagerly complete `RecordType`s. Completing a `RecordType` previously unconditionally resolved all member function of said type. With redecl-completion completion, however, this meant we were now pulling in many more definitions than needed. Without redecl-completion, this isn't a problem, since importing method parameters is cheap (they are imported minimally), so we wouldn't notice that we always resolved all member functions. This patch tries to load methods lazily when in redecl-completion mode. We do this by introducing a new `ExternalASTSource::FindExternalVisibleMethods` API which Clang parses a member access expression. The callback into LLDB will do a `FindFunctions` call for all methods with the method name we're looking for, filters out any mismatches, and lets Clang continue with it's parsing. We still load following methods eagerly: 1. virtual functions: currently overrides are resolved in `CompleteRecordType` 2. operators: currently I couldn't find a point at which Clang can call into LLDB here to facilitate lazy loading 3. ctors/dtors: same reason as (2) In our benchmark harness, we saw this patch bring down redecl-completion expression evaluation on-par with top-of-tree expression evaluation.
Note, this is a no-op when the LLDB setting `plugin.typesystem.clang.experimental-redecl-completion` is not set (which is currently the default). So this patch has no affect unless the user explicitly opts into it. The type-completion rework (aka redecl-completion) implemented in swiftlang#8222 comes with a large performance penalty, since we now eagerly complete `RecordType`s. Completing a `RecordType` previously unconditionally resolved all member function of said type. With redecl-completion completion, however, this meant we were now pulling in many more definitions than needed. Without redecl-completion, this isn't a problem, since importing method parameters is cheap (they are imported minimally), so we wouldn't notice that we always resolved all member functions. This patch tries to load methods lazily when in redecl-completion mode. We do this by introducing a new `ExternalASTSource::FindExternalVisibleMethods` API which Clang parses a member access expression. The callback into LLDB will do a `FindFunctions` call for all methods with the method name we're looking for, filters out any mismatches, and lets Clang continue with it's parsing. We still load following methods eagerly: 1. virtual functions: currently overrides are resolved in `CompleteRecordType` 2. operators: currently I couldn't find a point at which Clang can call into LLDB here to facilitate lazy loading 3. ctors/dtors: same reason as (2) In our benchmark harness, we saw this patch bring down redecl-completion expression evaluation on-par with top-of-tree expression evaluation.
…lazy-method-loading Note, this is a no-op when the LLDB setting `plugin.typesystem.clang.experimental-redecl-completion` is not set (which is currently the default). So this patch has no effect unless the user explicitly opts into it. The type-completion rework (aka redecl-completion) implemented in #8222 comes with a large performance penalty, since we now eagerly complete `RecordType`s. Completing a `RecordType` previously unconditionally resolved all member functions of said type. With redecl-completion completion, however, this meant we were now pulling in many more definitions than needed. Without redecl-completion, this isn't a problem, since importing method parameters is cheap (they are imported minimally), so we wouldn't notice that we always resolved all member functions. This patch tries to load methods lazily when in redecl-completion mode. We do this by introducing a new `ExternalASTSource::FindExternalVisibleMethods` API which Clang calls when parsing a member access expression. The callback into LLDB will do a `FindFunctions` call for all methods with the method name we're looking for, filters out any mismatches, and lets Clang continue with its parsing. We still load following methods eagerly: 1. virtual functions: currently overrides are resolved in `CompleteRecordType` 2. operators: currently I couldn't find a point at which Clang can call into LLDB here to facilitate lazy loading 3. ctors/dtors: same reason as (2) In our benchmark harness, we saw this patch bring down redecl-completion expression evaluation performance on-par with top-of-tree expression evaluation.
…crash-fixes [lldb][Type Completion] Fix various redecl-completion issues that stem from the `UseRedeclCompletion` setting split Debugging larger programs with the redecl-completion setting enabled was causing various crashes. This patch series resolves these. All of them were caused by either missed cherry-picks or incorrect UseRedeclCompletion guards. Follow-ups from #8222
…crash-fixes-to-next [lldb][Type Completion] Fix various redecl-completion issues that stem from the UseRedeclCompletion setting split Debugging larger programs with the redecl-completion setting enabled was causing various crashes. This patch series resolves these. All of them were caused by either missed cherry-picks or incorrect UseRedeclCompletion guards. Follow-ups from #8222
Note, this is a no-op when the LLDB setting `plugin.typesystem.clang.experimental-redecl-completion` is not set (which is currently the default). So this patch has no affect unless the user explicitly opts into it. The type-completion rework (aka redecl-completion) implemented in swiftlang#8222 comes with a large performance penalty, since we now eagerly complete `RecordType`s. Completing a `RecordType` previously unconditionally resolved all member function of said type. With redecl-completion completion, however, this meant we were now pulling in many more definitions than needed. Without redecl-completion, this isn't a problem, since importing method parameters is cheap (they are imported minimally), so we wouldn't notice that we always resolved all member functions. This patch tries to load methods lazily when in redecl-completion mode. We do this by introducing a new `ExternalASTSource::FindExternalVisibleMethods` API which Clang parses a member access expression. The callback into LLDB will do a `FindFunctions` call for all methods with the method name we're looking for, filters out any mismatches, and lets Clang continue with it's parsing. We still load following methods eagerly: 1. virtual functions: currently overrides are resolved in `CompleteRecordType` 2. operators: currently I couldn't find a point at which Clang can call into LLDB here to facilitate lazy loading 3. ctors/dtors: same reason as (2) In our benchmark harness, we saw this patch bring down redecl-completion expression evaluation on-par with top-of-tree expression evaluation. (cherry picked from commit ff8fdb9)
Note, this is a no-op when the LLDB setting `plugin.typesystem.clang.experimental-redecl-completion` is not set (which is currently the default). So this patch has no affect unless the user explicitly opts into it. The type-completion rework (aka redecl-completion) implemented in swiftlang#8222 comes with a large performance penalty, since we now eagerly complete `RecordType`s. Completing a `RecordType` previously unconditionally resolved all member function of said type. With redecl-completion completion, however, this meant we were now pulling in many more definitions than needed. Without redecl-completion, this isn't a problem, since importing method parameters is cheap (they are imported minimally), so we wouldn't notice that we always resolved all member functions. This patch tries to load methods lazily when in redecl-completion mode. We do this by introducing a new `ExternalASTSource::FindExternalVisibleMethods` API which Clang parses a member access expression. The callback into LLDB will do a `FindFunctions` call for all methods with the method name we're looking for, filters out any mismatches, and lets Clang continue with it's parsing. We still load following methods eagerly: 1. virtual functions: currently overrides are resolved in `CompleteRecordType` 2. operators: currently I couldn't find a point at which Clang can call into LLDB here to facilitate lazy loading 3. ctors/dtors: same reason as (2) In our benchmark harness, we saw this patch bring down redecl-completion expression evaluation on-par with top-of-tree expression evaluation.
This patch is rewriting the way we move Clang types between different ASTS in Clang.
The motivation is that the current approach for 'completing types' in LLDB just doesn't work. We have all kinds of situations where we either have Clang crash due to for example having a Record without DefinitionData but with FieldDecls in it.
The reason for that is that at the moment we create record types ([CXX]RecordDecls and ObjCInterfaceDecls) and we always pretend that a type potentially has a definition that somehow could be lazily pulled in. However, Clang doesn't have any interface (at least none that is consistently called) that turns a RecordDecl without DefinitionData into a RecordDecl with DefinitionData. The only relevant API in the ExternalASTSource is CompleteType is suffering from the fact that it's essentially not used by generic Clang code.
The part of the ExternalASTSource API that is consistently called to pull in a potential definition is CompleteRedeclChain (which is for example automatically called when calling getDefinition on a RecordDecl). The problem with CompleteRedeclChain however is that it's not supposed to add definition data to the Decl its called on, but instead it should provide a redeclaration that is defining the record. That's a very different system than what we currently have and we can't just swap it out under the hood.
To make it short: We probably need to rewrite that part of LLDB.
So the solution here is essentially rewriting all our completion code to do this:
The ASTImporter can now also stop using the minimal mode for records as there is no reason anymore. It just imports first the forward declaration and then the definition when needed.