-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Attach Lazy ClangImporter Diagnostics as Notes to Sema Diagnostics #41079
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3275,11 +3275,6 @@ void ClangModuleUnit::lookupValue(DeclName name, NLKind lookupKind, | |
if (auto lookupTable = owner.findLookupTable(clangModule)) { | ||
// Search it. | ||
owner.lookupValue(*lookupTable, name, *consumer); | ||
if (getASTContext().LangOpts.EnableExperimentalClangImporterDiagnostics) { | ||
if (results.empty()) { | ||
owner.diagnoseValue(*lookupTable, name); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -4127,7 +4122,7 @@ void ClangImporter::Implementation::lookupVisibleDecls( | |
DeclBaseName name = baseName.toDeclBaseName(SwiftContext); | ||
if (!lookupValue(table, name, consumer) && | ||
SwiftContext.LangOpts.EnableExperimentalEagerClangModuleDiagnostics) { | ||
diagnoseValue(table, name); | ||
NuriAmari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
diagnoseTopLevelValue(name); | ||
} | ||
} | ||
} | ||
|
@@ -4183,30 +4178,42 @@ void ClangImporter::Implementation::lookupAllObjCMembers( | |
} | ||
} | ||
|
||
void ClangImporter::Implementation::diagnoseValue(SwiftLookupTable &table, | ||
DeclName name) { | ||
auto &clangCtx = getClangASTContext(); | ||
auto clangTU = clangCtx.getTranslationUnitDecl(); | ||
|
||
if (name.isOperator()) { | ||
for (auto entry : table.lookupMemberOperators(name.getBaseName())) { | ||
diagnoseTargetDirectly(entry); | ||
void ClangImporter::Implementation::diagnoseTopLevelValue( | ||
const DeclName &name) { | ||
forEachLookupTable([&](SwiftLookupTable &table) -> bool { | ||
for (const auto &entry : | ||
table.lookup(name.getBaseName(), | ||
EffectiveClangContext( | ||
getClangASTContext().getTranslationUnitDecl()))) { | ||
diagnoseTargetDirectly(importDiagnosticTargetFromLookupTableEntry(entry)); | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
for (auto entry : table.lookup(name.getBaseName(), clangTU)) { | ||
diagnoseTargetDirectly(importDiagnosticTargetFromLookupTableEntry(entry)); | ||
} | ||
void ClangImporter::Implementation::diagnoseMemberValue( | ||
const DeclName &name, const clang::DeclContext *container) { | ||
forEachLookupTable([&](SwiftLookupTable &table) -> bool { | ||
for (const auto &entry : | ||
table.lookup(name.getBaseName(), EffectiveClangContext(container))) { | ||
if (clang::NamedDecl *nd = entry.get<clang::NamedDecl *>()) { | ||
// We are only interested in members of a particular context, | ||
// skip other contexts. | ||
if (nd->getDeclContext() != container) | ||
continue; | ||
|
||
diagnoseTargetDirectly( | ||
importDiagnosticTargetFromLookupTableEntry(entry)); | ||
} | ||
// If the entry is not a NamedDecl, it is a form of macro, which cannot be | ||
// a member value. | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
void ClangImporter::Implementation::diagnoseTargetDirectly( | ||
ImportDiagnosticTarget target) { | ||
if (!(SwiftContext.LangOpts.EnableExperimentalClangImporterDiagnostics || | ||
NuriAmari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SwiftContext.LangOpts.EnableExperimentalEagerClangModuleDiagnostics) || | ||
DiagnosedValues.count(target)) | ||
return; | ||
|
||
DiagnosedValues.insert(target); | ||
if (const clang::Decl *decl = target.dyn_cast<const clang::Decl *>()) { | ||
Walker.TraverseDecl(const_cast<clang::Decl *>(decl)); | ||
} else if (const clang::MacroInfo *macro = | ||
|
@@ -4363,8 +4370,6 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate( | |
recordDecl->getClangDecl()) { | ||
if (auto import = ctx.getClangModuleLoader()->importDeclDirectly(named)) | ||
result.push_back(cast<ValueDecl>(import)); | ||
else if (ctx.LangOpts.EnableExperimentalClangImporterDiagnostics) | ||
ctx.getClangModuleLoader()->diagnoseDeclDirectly(named); | ||
} | ||
} | ||
|
||
|
@@ -4497,22 +4502,6 @@ ClangImporter::Implementation::loadNamedMembers( | |
return Members; | ||
} | ||
|
||
void ClangImporter::Implementation::diagnoseMissingNamedMember( | ||
NuriAmari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const IterableDeclContext *IDC, DeclName name) { | ||
Optional<clang::Module *> containingModule = | ||
getClangSubmoduleForDecl(IDC->getDecl()->getClangDecl()); | ||
assert(containingModule && | ||
"Members should never be loaded from a forward-declared decl"); | ||
auto allResults = evaluateOrDefault( | ||
SwiftContext.evaluator, | ||
ClangDirectLookupRequest({const_cast<Decl *>(IDC->getDecl()), | ||
IDC->getDecl()->getClangDecl(), name}), | ||
{}); | ||
for (auto entry : allResults) { | ||
diagnoseTargetDirectly(importDiagnosticTargetFromLookupTableEntry(entry)); | ||
} | ||
} | ||
|
||
EffectiveClangContext ClangImporter::Implementation::getEffectiveClangContext( | ||
const NominalTypeDecl *nominal) { | ||
// If we have a Clang declaration, look at it to determine the | ||
|
@@ -4747,6 +4736,23 @@ Decl *ClangImporter::importDeclDirectly(const clang::NamedDecl *decl) { | |
return Impl.importDecl(decl, Impl.CurrentVersion); | ||
} | ||
|
||
void ClangImporter::diagnoseDeclDirectly(const clang::NamedDecl *decl) { | ||
Impl.diagnoseTargetDirectly(decl); | ||
void ClangImporter::diagnoseTopLevelValue(const DeclName &name) { | ||
Impl.diagnoseTopLevelValue(name); | ||
} | ||
|
||
void ClangImporter::diagnoseMemberValue(const DeclName &name, | ||
const Type &baseType) { | ||
if (!baseType->getAnyNominal()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple changes here. Since this call is made from Sema, the baseType could be anything (not just an imported ClangType). I discovered a few more checks are needed here. First, Lastly, I added checks that |
||
return; | ||
|
||
SmallVector<NominalTypeDecl *, 4> nominalTypesToLookInto; | ||
namelookup::extractDirectlyReferencedNominalTypes(baseType, | ||
nominalTypesToLookInto); | ||
for (auto containerDecl : nominalTypesToLookInto) { | ||
const clang::Decl *clangContainerDecl = containerDecl->getClangDecl(); | ||
if (clangContainerDecl && isa<clang::DeclContext>(clangContainerDecl)) { | ||
Impl.diagnoseMemberValue(name, | ||
cast<clang::DeclContext>(clangContainerDecl)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
struct MyStruct { | ||
int _Complex commonName; | ||
}; | ||
|
||
_Complex int commonName(); |
Uh oh!
There was an error while loading. Please reload this page.