mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use "SPI group" for the name used in an @_spi attribute
This commit is contained in:
@@ -1177,23 +1177,23 @@ class SPIAccessControlAttr final : public DeclAttribute,
|
||||
friend TrailingObjects;
|
||||
|
||||
SPIAccessControlAttr(SourceLoc atLoc, SourceRange range,
|
||||
ArrayRef<Identifier> spiNames);
|
||||
ArrayRef<Identifier> spiGroups);
|
||||
|
||||
// Number of trailing names.
|
||||
size_t numSPINames;
|
||||
// Number of trailing SPI group identifiers.
|
||||
size_t numSPIGroups;
|
||||
|
||||
public:
|
||||
static SPIAccessControlAttr *create(ASTContext &context, SourceLoc atLoc,
|
||||
SourceRange range,
|
||||
ArrayRef<Identifier> spiNames);
|
||||
ArrayRef<Identifier> spiGroups);
|
||||
|
||||
/// Name of SPIs declared by the attribute.
|
||||
///
|
||||
/// Note: A single SPI name per attribute is currently supported but this
|
||||
/// may change with the syntax change.
|
||||
ArrayRef<Identifier> getSPINames() const {
|
||||
ArrayRef<Identifier> getSPIGroups() const {
|
||||
return { this->template getTrailingObjects<Identifier>(),
|
||||
numSPINames };
|
||||
numSPIGroups };
|
||||
}
|
||||
|
||||
static bool classof(const DeclAttribute *DA) {
|
||||
|
||||
@@ -101,10 +101,11 @@ public:
|
||||
ObjCSelector selector,
|
||||
SmallVectorImpl<AbstractFunctionDecl *> &results) const = 0;
|
||||
|
||||
/// Find all SPI imported from \p importedModule by this module, collecting
|
||||
/// their identifiers in \p spis.
|
||||
virtual void lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const {};
|
||||
/// Find all SPI names imported from \p importedModule by this module,
|
||||
/// collecting the identifiers in \p spiGroups.
|
||||
virtual void lookupImportedSPIGroups(
|
||||
const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const {};
|
||||
|
||||
/// Returns the comment attached to the given declaration.
|
||||
///
|
||||
|
||||
@@ -458,10 +458,10 @@ public:
|
||||
ObjCSelector selector,
|
||||
SmallVectorImpl<AbstractFunctionDecl *> &results) const;
|
||||
|
||||
/// Find all SPI imported from \p importedModule by this module, collecting
|
||||
/// their identifiers in \p spis.
|
||||
void lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const;
|
||||
/// Find all SPI names imported from \p importedModule by this module,
|
||||
/// collecting the identifiers in \p spiGroups.
|
||||
void lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const;
|
||||
|
||||
/// \sa getImportedModules
|
||||
enum class ImportFilterKind {
|
||||
|
||||
@@ -75,11 +75,13 @@ public:
|
||||
StringRef filename;
|
||||
|
||||
// Names of explicitly imported SPIs.
|
||||
ArrayRef<Identifier> spis;
|
||||
ArrayRef<Identifier> spiGroups;
|
||||
|
||||
ImportedModuleDesc(ModuleDecl::ImportedModule module, ImportOptions options,
|
||||
StringRef filename = {}, ArrayRef<Identifier> spis = {})
|
||||
: module(module), importOptions(options), filename(filename), spis(spis) {
|
||||
StringRef filename = {},
|
||||
ArrayRef<Identifier> spiGroups = {})
|
||||
: module(module), importOptions(options), filename(filename),
|
||||
spiGroups(spiGroups) {
|
||||
assert(!(importOptions.contains(ImportFlags::Exported) &&
|
||||
importOptions.contains(ImportFlags::ImplementationOnly)) ||
|
||||
importOptions.contains(ImportFlags::Reserved));
|
||||
@@ -281,11 +283,11 @@ public:
|
||||
|
||||
bool isImportedImplementationOnly(const ModuleDecl *module) const;
|
||||
|
||||
/// Find all SPI imported from \p importedModule by this module, collecting
|
||||
/// their identifiers in \p spis.
|
||||
/// Find all SPI names imported from \p importedModule by this file,
|
||||
/// collecting the identifiers in \p spiGroups.
|
||||
virtual void
|
||||
lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const override;
|
||||
lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const override;
|
||||
|
||||
// Is \p targetDecl accessible as an explictly imported SPI from this file?
|
||||
bool isImportedAsSPI(const ValueDecl *targetDecl) const;
|
||||
|
||||
@@ -351,8 +351,8 @@ public:
|
||||
SmallVectorImpl<AbstractFunctionDecl *> &results) const override;
|
||||
|
||||
virtual void
|
||||
lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const override;
|
||||
lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const override;
|
||||
|
||||
Optional<CommentInfo> getCommentForDecl(const Decl *D) const override;
|
||||
|
||||
|
||||
@@ -782,7 +782,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
|
||||
if (!Options.PrintSPIs) return false;
|
||||
|
||||
auto spiAttr = static_cast<const SPIAccessControlAttr*>(this);
|
||||
interleave(spiAttr->getSPINames(),
|
||||
interleave(spiAttr->getSPIGroups(),
|
||||
[&](Identifier spiName) {
|
||||
Printer.printAttrName(getAttrName(), true);
|
||||
Printer << "(" << spiName << ")";
|
||||
@@ -1538,11 +1538,11 @@ SpecializeAttr *SpecializeAttr::create(ASTContext &Ctx, SourceLoc atLoc,
|
||||
}
|
||||
|
||||
SPIAccessControlAttr::SPIAccessControlAttr(SourceLoc atLoc, SourceRange range,
|
||||
ArrayRef<Identifier> spiNames)
|
||||
ArrayRef<Identifier> spiGroups)
|
||||
: DeclAttribute(DAK_SPIAccessControl, atLoc, range,
|
||||
/*Implicit=*/false),
|
||||
numSPINames(spiNames.size()) {
|
||||
std::uninitialized_copy(spiNames.begin(), spiNames.end(),
|
||||
numSPIGroups(spiGroups.size()) {
|
||||
std::uninitialized_copy(spiGroups.begin(), spiGroups.end(),
|
||||
getTrailingObjects<Identifier>());
|
||||
}
|
||||
|
||||
@@ -1550,10 +1550,10 @@ SPIAccessControlAttr *
|
||||
SPIAccessControlAttr::create(ASTContext &context,
|
||||
SourceLoc atLoc,
|
||||
SourceRange range,
|
||||
ArrayRef<Identifier> spiNames) {
|
||||
unsigned size = totalSizeToAlloc<Identifier>(spiNames.size());
|
||||
ArrayRef<Identifier> spiGroups) {
|
||||
unsigned size = totalSizeToAlloc<Identifier>(spiGroups.size());
|
||||
void *mem = context.Allocate(size, alignof(SPIAccessControlAttr));
|
||||
return new (mem) SPIAccessControlAttr(atLoc, range, spiNames);
|
||||
return new (mem) SPIAccessControlAttr(atLoc, range, spiGroups);
|
||||
}
|
||||
|
||||
DifferentiableAttr::DifferentiableAttr(bool implicit, SourceLoc atLoc,
|
||||
|
||||
@@ -549,9 +549,9 @@ void ModuleDecl::lookupObjCMethods(
|
||||
FORWARD(lookupObjCMethods, (selector, results));
|
||||
}
|
||||
|
||||
void ModuleDecl::lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const {
|
||||
FORWARD(lookupImportedSPIs, (importedModule, spis));
|
||||
void ModuleDecl::lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const {
|
||||
FORWARD(lookupImportedSPIGroups, (importedModule, spiGroups));
|
||||
}
|
||||
|
||||
void BuiltinUnit::lookupValue(DeclName name, NLKind lookupKind,
|
||||
@@ -1782,13 +1782,13 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
|
||||
return !imports.isImportedBy(module, getParentModule());
|
||||
}
|
||||
|
||||
void SourceFile::lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const {
|
||||
void SourceFile::lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const {
|
||||
for (auto &import : Imports) {
|
||||
if (import.importOptions.contains(ImportFlags::SPIAccessControl) &&
|
||||
importedModule == std::get<ModuleDecl*>(import.module)) {
|
||||
auto importedSpis = import.spis;
|
||||
spis.append(importedSpis.begin(), importedSpis.end());
|
||||
auto importedSpis = import.spiGroups;
|
||||
spiGroups.append(importedSpis.begin(), importedSpis.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1799,10 +1799,10 @@ bool SourceFile::isImportedAsSPI(const ValueDecl *targetDecl) const {
|
||||
|
||||
auto targetModule = targetDecl->getModuleContext();
|
||||
SmallVector<Identifier, 4> importedSpis;
|
||||
lookupImportedSPIs(targetModule, importedSpis);
|
||||
lookupImportedSPIGroups(targetModule, importedSpis);
|
||||
|
||||
for (auto attr : targetDecl->getAttrs().getAttributes<SPIAccessControlAttr>())
|
||||
for (auto declSPI : attr->getSPINames())
|
||||
for (auto declSPI : attr->getSPIGroups())
|
||||
for (auto importedSPI : importedSpis)
|
||||
if (importedSPI == declSPI)
|
||||
return true;
|
||||
|
||||
@@ -119,7 +119,7 @@ static void printImports(raw_ostream &out,
|
||||
// SPI attribute on imports
|
||||
if (Opts.PrintSPIs) {
|
||||
SmallVector<Identifier, 4> spis;
|
||||
M->lookupImportedSPIs(importedModule, spis);
|
||||
M->lookupImportedSPIGroups(importedModule, spis);
|
||||
for (auto spiName : spis)
|
||||
out << "@_spi(" << spiName << ") ";
|
||||
}
|
||||
|
||||
@@ -1634,7 +1634,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
|
||||
return false;
|
||||
}
|
||||
|
||||
SmallVector<Identifier, 4> spiNames;
|
||||
SmallVector<Identifier, 4> spiGroups;
|
||||
|
||||
if (!Tok.is(tok::identifier) ||
|
||||
Tok.isContextualKeyword("set")) {
|
||||
@@ -1645,7 +1645,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
|
||||
}
|
||||
|
||||
auto text = Tok.getText();
|
||||
spiNames.push_back(Context.getIdentifier(text));
|
||||
spiGroups.push_back(Context.getIdentifier(text));
|
||||
consumeToken();
|
||||
|
||||
if (!consumeIf(tok::r_paren)) {
|
||||
@@ -1656,7 +1656,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
|
||||
|
||||
AttrRange = SourceRange(Loc, Tok.getLoc());
|
||||
Attributes.add(SPIAccessControlAttr::create(Context, AtLoc, AttrRange,
|
||||
spiNames));
|
||||
spiGroups));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace {
|
||||
ModuleDecl::AccessPathTy declPath;
|
||||
|
||||
// Names of explicitly imported SPI groups via @_spi.
|
||||
ArrayRef<Identifier> spiNames;
|
||||
ArrayRef<Identifier> spiGroups;
|
||||
|
||||
/// If this UnboundImport directly represents an ImportDecl, contains the
|
||||
/// ImportDecl it represents. This should only be used for diagnostics and
|
||||
@@ -145,7 +145,7 @@ namespace {
|
||||
/// UnboundImport.
|
||||
ImportedModuleDesc makeDesc(ModuleDecl *module) const {
|
||||
return ImportedModuleDesc({ declPath, module }, options,
|
||||
privateImportFileName);
|
||||
privateImportFileName, spiGroups);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -517,13 +517,13 @@ UnboundImport::UnboundImport(ImportDecl *ID)
|
||||
privateImportFileName = privateImportAttr->getSourceFile();
|
||||
}
|
||||
|
||||
SmallVector<Identifier, 4> spiNames;
|
||||
SmallVector<Identifier, 4> spiGroups;
|
||||
for (auto attr : ID->getAttrs().getAttributes<SPIAccessControlAttr>()) {
|
||||
options |= SourceFile::ImportFlags::SPIAccessControl;
|
||||
auto attrSPIs = attr->getSPINames();
|
||||
spiNames.append(attrSPIs.begin(), attrSPIs.end());
|
||||
auto attrSPIs = attr->getSPIGroups();
|
||||
spiGroups.append(attrSPIs.begin(), attrSPIs.end());
|
||||
}
|
||||
this->spiNames = ID->getASTContext().AllocateCopy(spiNames);
|
||||
this->spiGroups = ID->getASTContext().AllocateCopy(spiGroups);
|
||||
}
|
||||
|
||||
bool UnboundImport::checkNotTautological(const SourceFile &SF) {
|
||||
|
||||
@@ -2014,7 +2014,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file,
|
||||
while (!spisStr.empty()) {
|
||||
StringRef nextComponent;
|
||||
std::tie(nextComponent, spisStr) = spisStr.split('\0');
|
||||
dependency.spis.push_back(ctx.getIdentifier(nextComponent));
|
||||
dependency.spiGroups.push_back(ctx.getIdentifier(nextComponent));
|
||||
}
|
||||
|
||||
if (!module->hasResolvedImports()) {
|
||||
@@ -2556,13 +2556,13 @@ void ModuleFile::lookupObjCMethods(
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleFile::lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const {
|
||||
void ModuleFile::lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const {
|
||||
for (auto &dep : Dependencies) {
|
||||
auto depSpis = dep.spis;
|
||||
auto depSpis = dep.spiGroups;
|
||||
if (dep.Import.second == importedModule &&
|
||||
!depSpis.empty()) {
|
||||
spis.append(depSpis.begin(), depSpis.end());
|
||||
spiGroups.append(depSpis.begin(), depSpis.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
ModuleDecl::ImportedModule Import = {};
|
||||
const StringRef RawPath;
|
||||
const StringRef RawSPIs;
|
||||
SmallVector<Identifier, 4> spis;
|
||||
SmallVector<Identifier, 4> spiGroups;
|
||||
|
||||
private:
|
||||
using ImportFilterKind = ModuleDecl::ImportFilterKind;
|
||||
@@ -122,9 +122,9 @@ public:
|
||||
return static_cast<ImportFilterKind>(1 << RawImportControl);
|
||||
}
|
||||
|
||||
Dependency(StringRef path, StringRef spis, bool isHeader, ImportFilterKind importControl,
|
||||
Dependency(StringRef path, StringRef spiGroups, bool isHeader, ImportFilterKind importControl,
|
||||
bool isScoped)
|
||||
: RawPath(path), RawSPIs(spis), RawImportControl(rawControlFromKind(importControl)),
|
||||
: RawPath(path), RawSPIs(spiGroups), RawImportControl(rawControlFromKind(importControl)),
|
||||
IsHeader(isHeader), IsScoped(isScoped) {
|
||||
assert(llvm::countPopulation(static_cast<unsigned>(importControl)) == 1 &&
|
||||
"must be a particular filter option, not a bitset");
|
||||
@@ -132,8 +132,8 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
Dependency(StringRef path, StringRef spis, ImportFilterKind importControl, bool isScoped)
|
||||
: Dependency(path, spis, false, importControl, isScoped) {}
|
||||
Dependency(StringRef path, StringRef spiGroups, ImportFilterKind importControl, bool isScoped)
|
||||
: Dependency(path, spiGroups, false, importControl, isScoped) {}
|
||||
|
||||
static Dependency forHeader(StringRef headerPath, bool exported) {
|
||||
auto importControl = exported ? ImportFilterKind::Public
|
||||
@@ -788,10 +788,10 @@ public:
|
||||
ObjCSelector selector,
|
||||
SmallVectorImpl<AbstractFunctionDecl *> &results);
|
||||
|
||||
/// Find all SPI imported from \p importedModule by this module, collecting
|
||||
/// their identifiers in \p spis.
|
||||
void lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const;
|
||||
/// Find all SPI names imported from \p importedModule by this module,
|
||||
/// collecting the identifiers in \p spiGroups.
|
||||
void lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const;
|
||||
|
||||
/// Reports all link-time dependencies.
|
||||
void collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const;
|
||||
|
||||
@@ -1077,7 +1077,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
|
||||
stableImportControl = ImportControl::ImplementationOnly;
|
||||
|
||||
SmallVector<Identifier, 4> spis;
|
||||
M->lookupImportedSPIs(import.second, spis);
|
||||
M->lookupImportedSPIGroups(import.second, spis);
|
||||
|
||||
ImportedModule.emit(ScratchRecord,
|
||||
static_cast<uint8_t>(stableImportControl),
|
||||
@@ -2211,7 +2211,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
auto abbrCode = S.DeclTypeAbbrCodes[SPIAccessControlDeclAttrLayout::Code];
|
||||
|
||||
SmallVector<IdentifierID, 4> spis;
|
||||
for (auto spi : theAttr->getSPINames()) {
|
||||
for (auto spi : theAttr->getSPIGroups()) {
|
||||
assert(!spi.empty() && "Empty SPI name");
|
||||
spis.push_back(S.addDeclBaseNameRef(spi));
|
||||
}
|
||||
|
||||
@@ -1110,9 +1110,9 @@ void SerializedASTFile::lookupObjCMethods(
|
||||
File.lookupObjCMethods(selector, results);
|
||||
}
|
||||
|
||||
void SerializedASTFile::lookupImportedSPIs(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spis) const {
|
||||
File.lookupImportedSPIs(importedModule, spis);
|
||||
void SerializedASTFile::lookupImportedSPIGroups(const ModuleDecl *importedModule,
|
||||
SmallVectorImpl<Identifier> &spiGroups) const {
|
||||
File.lookupImportedSPIGroups(importedModule, spiGroups);
|
||||
}
|
||||
|
||||
Optional<CommentInfo>
|
||||
|
||||
Reference in New Issue
Block a user