[Sema] Report uses of implicitly imported decls in inlinable code

Implicitly imported decls may end up in inlinable code and break the
module API. This have been known to lead to deserialization crash and
could in theory break the generated swiftinterfaces files. Let's
explicitly check for such a case, keeping it to a warning until Swift 6
where we can make it an error.

rdar://95816286
This commit is contained in:
Alexis Laferrière
2022-06-23 16:43:02 -07:00
parent 4d9c8ee5eb
commit 9127f90d8d
7 changed files with 121 additions and 8 deletions

View File

@@ -2440,14 +2440,18 @@ bool SourceFile::hasTestableOrPrivateImport(
RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *module) const {
auto &imports = getASTContext().getImportCache();
RestrictedImportKind importKind = RestrictedImportKind::Implicit;
// Look at the imports of this source file.
for (auto &desc : *Imports) {
// Ignore implementation-only imports.
if (desc.options.contains(ImportFlags::ImplementationOnly))
if (desc.options.contains(ImportFlags::ImplementationOnly)) {
if (imports.isImportedBy(module, desc.module.importedModule))
importKind = RestrictedImportKind::ImplementationOnly;
continue;
}
// If the module is imported this way, it's not imported
// If the module is imported publicly, it's not imported
// implementation-only.
if (imports.isImportedBy(module, desc.module.importedModule))
return RestrictedImportKind::None;
@@ -2457,7 +2461,7 @@ RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *modul
if (imports.isImportedBy(module, getParentModule()))
return RestrictedImportKind::None;
return RestrictedImportKind::ImplementationOnly;
return importKind;
}
bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const {