Add implicit SPI import feature

API development sometimes requires a redesign while supporting early
adopters. Currently this is done by adding @_spi(name) to the API but
that requires adding the attribute in import statements as well, causing
manual overhead of adding and then removing when the redesign is done.

This PR introduces a special spi group name '_' and allows an implicit
spi import of a module containing API attributed with '@_spi(_)'

Resolves rdar://109797632
This commit is contained in:
Ellie Shin
2023-05-31 17:28:19 -07:00
parent c2c24145bf
commit 32f53d1eb8
5 changed files with 140 additions and 6 deletions

View File

@@ -2677,7 +2677,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
SmallVector<IdentifierID, 4> spis;
for (auto spi : theAttr->getSPIGroups()) {
assert(!spi.empty() && "Empty SPI name");
// SPI group name in source code can be '_', a specifier that allows
// implicit import of the SPI. It gets converted to to an empty identifier
// during parsing to match the existing AST node representation. An empty
// identifier is printed as '_' at serialization.
spis.push_back(S.addDeclBaseNameRef(spi));
}