mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help explain why certain C, Objective-C or C++ declarations fail to import into Swift. This patch includes new diagnostics for the following entities: - C functions - C struct fields - Macros - Objective-C properties - Objective-C methods In particular, notes are attached to indicate when any of the above entities fail to import as a result of refering an incomplete (only forward declared) type. The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily, while the second eagerly imports all declarations visible from loaded Clang modules. The first flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
This commit is contained in:
@@ -992,6 +992,30 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Invocation.getLangOptions()
|
||||
.EnableExperimentalEagerClangModuleDiagnostics) {
|
||||
|
||||
// A consumer meant to import all visible declarations.
|
||||
class EagerConsumer : public VisibleDeclConsumer {
|
||||
public:
|
||||
virtual void
|
||||
foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
|
||||
DynamicLookupInfo dynamicLookupInfo = {}) override {
|
||||
if (auto *IDC = dyn_cast<IterableDeclContext>(VD)) {
|
||||
(void)IDC->getMembers();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EagerConsumer consumer;
|
||||
for (auto module : ctx.getLoadedModules()) {
|
||||
// None of the passed parameter have an effect, we just need to trigger
|
||||
// imports.
|
||||
module.second->lookupVisibleDecls(/*Access Path*/ {}, consumer,
|
||||
NLKind::QualifiedLookup);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This predicate matches the status quo, but there's no reason
|
||||
// indexing cannot run for actions that do not require stdlib e.g. to better
|
||||
// facilitate tests.
|
||||
|
||||
Reference in New Issue
Block a user