[Sema] Check inconsistent @_spiOnly imports within one source file

This commit is contained in:
Alexis Laferrière
2022-09-12 10:34:01 -07:00
parent 329599d2d3
commit 47d2f1acc4
6 changed files with 139 additions and 0 deletions

View File

@@ -846,6 +846,33 @@ CheckInconsistentImplementationOnlyImportsRequest::evaluate(
return {};
}
evaluator::SideEffect
CheckInconsistentSPIOnlyImportsRequest::evaluate(
Evaluator &evaluator, SourceFile *SF) const {
auto mod = SF->getParentModule();
auto diagnose = [mod](const ImportDecl *normalImport,
const ImportDecl *spiOnlyImport) {
auto &diags = mod->getDiags();
{
diags.diagnose(normalImport, diag::spi_only_import_conflict,
normalImport->getModule()->getName());
}
diags.diagnose(spiOnlyImport,
diag::spi_only_import_conflict_here);
};
auto predicate = [](ImportDecl *decl) {
return decl->getAttrs().hasAttribute<SPIOnlyAttr>();
};
llvm::DenseMap<ModuleDecl *, const ImportDecl *> matchingImports;
llvm::DenseMap<ModuleDecl *, std::vector<const ImportDecl *>> otherImports;
findInconsistentImportsAcrossFile(SF, predicate, diagnose,
matchingImports, otherImports);
return {};
}
evaluator::SideEffect
CheckInconsistentWeakLinkedImportsRequest::evaluate(Evaluator &evaluator,
ModuleDecl *mod) const {