@@ -2089,37 +2089,32 @@ swift::performASTLowering(FileUnit &sf, Lowering::TypeConverter &tc,
20892089
20902090static void transferSpecializeAttributeTargets (SILGenModule &SGM, SILModule &M,
20912091 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+ }
20952103 }
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;
21022112 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 ];
21222114 }
2115+ targetSILFunction->addSpecializeAttr (SILSpecializeAttr::create (
2116+ M, SA->getSpecializedSignature (), SA->isExported (), kind, nullptr ,
2117+ spiGroupIdent, vd->getModuleContext ()));
21232118 }
21242119 }
21252120}
@@ -2143,14 +2138,11 @@ void SILGenModule::visitImportDecl(ImportDecl *import) {
21432138 if (module ->isNonSwiftModule ())
21442139 return ;
21452140
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 )) {
21502145 transferSpecializeAttributeTargets (*this , M, vd);
2151- } else if (auto *extension = dyn_cast<ExtensionDecl>(t)) {
2152- for (auto *d : extension->getMembers ())
2153- transferSpecializeAttributeTargets (*this , M, d);
21542146 }
21552147 }
21562148}
0 commit comments