@@ -2089,37 +2089,32 @@ swift::performASTLowering(FileUnit &sf, Lowering::TypeConverter &tc,
2089
2089
2090
2090
static void transferSpecializeAttributeTargets (SILGenModule &SGM, SILModule &M,
2091
2091
Decl *d) {
2092
- if (auto *asd = dyn_cast<AbstractStorageDecl>(d)) {
2093
- for (auto ad : asd->getAllAccessors ()) {
2094
- transferSpecializeAttributeTargets (SGM, M, ad);
2092
+ auto *vd = cast<AbstractFunctionDecl>(d);
2093
+ for (auto *A : vd->getAttrs ().getAttributes <SpecializeAttr>()) {
2094
+ auto *SA = cast<SpecializeAttr>(A);
2095
+ // Filter _spi.
2096
+ auto spiGroups = SA->getSPIGroups ();
2097
+ auto hasSPIGroup = !spiGroups.empty ();
2098
+ if (hasSPIGroup) {
2099
+ if (vd->getModuleContext () != M.getSwiftModule () &&
2100
+ !M.getSwiftModule ()->isImportedAsSPI (SA, vd)) {
2101
+ continue ;
2102
+ }
2095
2103
}
2096
- } else if (auto *vd = dyn_cast<AbstractFunctionDecl>(d)) {
2097
- for (auto *A : vd->getAttrs ().getAttributes <SpecializeAttr>()) {
2098
- auto *SA = cast<SpecializeAttr>(A);
2099
- // Filter _spi.
2100
- auto spiGroups = SA->getSPIGroups ();
2101
- auto hasSPIGroup = !spiGroups.empty ();
2104
+ if (auto *targetFunctionDecl = SA->getTargetFunctionDecl (vd)) {
2105
+ auto target = SILDeclRef (targetFunctionDecl);
2106
+ auto targetSILFunction = SGM.getFunction (target, NotForDefinition);
2107
+ auto kind = SA->getSpecializationKind () ==
2108
+ SpecializeAttr::SpecializationKind::Full
2109
+ ? SILSpecializeAttr::SpecializationKind::Full
2110
+ : SILSpecializeAttr::SpecializationKind::Partial;
2111
+ Identifier spiGroupIdent;
2102
2112
if (hasSPIGroup) {
2103
- if (vd->getModuleContext () != M.getSwiftModule () &&
2104
- !M.getSwiftModule ()->isImportedAsSPI (SA, vd)) {
2105
- continue ;
2106
- }
2107
- }
2108
- if (auto *targetFunctionDecl = SA->getTargetFunctionDecl (vd)) {
2109
- auto target = SILDeclRef (targetFunctionDecl);
2110
- auto targetSILFunction = SGM.getFunction (target, NotForDefinition);
2111
- auto kind = SA->getSpecializationKind () ==
2112
- SpecializeAttr::SpecializationKind::Full
2113
- ? SILSpecializeAttr::SpecializationKind::Full
2114
- : SILSpecializeAttr::SpecializationKind::Partial;
2115
- Identifier spiGroupIdent;
2116
- if (hasSPIGroup) {
2117
- spiGroupIdent = spiGroups[0 ];
2118
- }
2119
- targetSILFunction->addSpecializeAttr (SILSpecializeAttr::create (
2120
- M, SA->getSpecializedSignature (), SA->isExported (), kind, nullptr ,
2121
- spiGroupIdent, vd->getModuleContext ()));
2113
+ spiGroupIdent = spiGroups[0 ];
2122
2114
}
2115
+ targetSILFunction->addSpecializeAttr (SILSpecializeAttr::create (
2116
+ M, SA->getSpecializedSignature (), SA->isExported (), kind, nullptr ,
2117
+ spiGroupIdent, vd->getModuleContext ()));
2123
2118
}
2124
2119
}
2125
2120
}
@@ -2143,14 +2138,11 @@ void SILGenModule::visitImportDecl(ImportDecl *import) {
2143
2138
if (module ->isNonSwiftModule ())
2144
2139
return ;
2145
2140
2146
- SmallVector<Decl*, 16 > topLevelDecls ;
2147
- module ->getTopLevelDecls (topLevelDecls );
2148
- for (auto *t : topLevelDecls ) {
2149
- if (auto *vd = dyn_cast<AbstractFunctionDecl>(t )) {
2141
+ SmallVector<Decl*, 16 > prespecializations ;
2142
+ module ->getExportedPrespecializations (prespecializations );
2143
+ for (auto *p : prespecializations ) {
2144
+ if (auto *vd = dyn_cast<AbstractFunctionDecl>(p )) {
2150
2145
transferSpecializeAttributeTargets (*this , M, vd);
2151
- } else if (auto *extension = dyn_cast<ExtensionDecl>(t)) {
2152
- for (auto *d : extension->getMembers ())
2153
- transferSpecializeAttributeTargets (*this , M, d);
2154
2146
}
2155
2147
}
2156
2148
}
0 commit comments