mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user