ClangImporter: import SPIs from bridging headers by default

rdar://82822440
This commit is contained in:
Xi Ge
2021-09-07 14:54:34 -07:00
parent eb8e52b8d6
commit 4e4bae64cb
2 changed files with 20 additions and 0 deletions

View File

@@ -492,6 +492,8 @@ ModuleImplicitImportsRequest::evaluate(Evaluator &evaluator,
auto *clangImporter =
static_cast<ClangImporter *>(ctx.getClangModuleLoader());
SmallVector<Identifier, 4> clangSpiGroups;
clangSpiGroups.push_back(ctx.getIdentifier(CLANG_MODULE_DEFUALT_SPI_GROUP_NAME));
// Implicitly import the bridging header module if needed.
auto bridgingHeaderPath = importInfo.BridgingHeaderPath;
if (!bridgingHeaderPath.empty() &&
@@ -499,6 +501,8 @@ ModuleImplicitImportsRequest::evaluate(Evaluator &evaluator,
auto *headerModule = clangImporter->getImportedHeaderModule();
assert(headerModule && "Didn't load bridging header?");
imports.emplace_back(ImportedModule(headerModule), ImportFlags::Exported);
imports.back().options |= ImportFlags::SPIAccessControl;
imports.back().spiGroups = ctx.AllocateCopy(clangSpiGroups);
}
// Implicitly import the underlying Clang half of this module if needed.
@@ -509,6 +513,8 @@ ModuleImplicitImportsRequest::evaluate(Evaluator &evaluator,
unloadedImports.emplace_back(UnloadedImportedModule(importPath.copyTo(ctx),
/*isScoped=*/false),
ImportFlags::Exported);
imports.back().options |= ImportFlags::SPIAccessControl;
imports.back().spiGroups = ctx.AllocateCopy(clangSpiGroups);
}
return { ctx.AllocateCopy(imports), ctx.AllocateCopy(unloadedImports) };

View File

@@ -0,0 +1,14 @@
// REQUIRES: OS=macosx
// RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/frameworks/SPIContainer.framework/Headers/SPIContainer.h -verify
@_spi(a) public let a: SPIInterface1
@_spi(a) public let b: SPIInterface2
public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1' here; it is an SPI imported from '__ObjC'}}
public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from '__ObjC'}}
@inlinable
public func inlinableUsingSPI() {
SharedInterface.foo() // expected-error{{class method 'foo()' cannot be used in an '@inlinable' function because it is an SPI imported from '__ObjC'}}
}