@@ -2115,17 +2115,18 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21152115 // Make sure at least some of the entries are functions in the _Concurrency
21162116 // module.
21172117 ModuleDecl *concurrencyModule = nullptr ;
2118+ DeclBaseName baseName;
21182119 for (auto decl: decls) {
21192120 if (isReplaceable (decl)) {
21202121 concurrencyModule = decl->getDeclContext ()->getParentModule ();
2122+ baseName = decl->getName ().getBaseName ();
21212123 break ;
21222124 }
21232125 }
21242126 if (!concurrencyModule)
21252127 return ;
21262128
2127- // Dig out the name.
2128- auto baseName = decls.front ()->getName ().getBaseName ();
2129+ // Ignore anything with a special name.
21292130 if (baseName.isSpecial ())
21302131 return ;
21312132
@@ -2153,6 +2154,60 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21532154 }
21542155}
21552156
2157+ void swift::introduceUnsafeInheritExecutorReplacements (
2158+ const DeclContext *dc, Type base, SourceLoc loc, LookupResult &lookup) {
2159+ if (lookup.empty ())
2160+ return ;
2161+
2162+ auto baseNominal = base->getAnyNominal ();
2163+ if (!baseNominal || !inConcurrencyModule (baseNominal))
2164+ return ;
2165+
2166+ auto isReplaceable = [&](ValueDecl *decl) {
2167+ return isa<FuncDecl>(decl) && inConcurrencyModule (decl->getDeclContext ());
2168+ };
2169+
2170+ // Make sure at least some of the entries are functions in the _Concurrency
2171+ // module.
2172+ ModuleDecl *concurrencyModule = nullptr ;
2173+ DeclBaseName baseName;
2174+ for (auto &result: lookup) {
2175+ auto decl = result.getValueDecl ();
2176+ if (isReplaceable (decl)) {
2177+ concurrencyModule = decl->getDeclContext ()->getParentModule ();
2178+ baseName = decl->getBaseName ();
2179+ break ;
2180+ }
2181+ }
2182+ if (!concurrencyModule)
2183+ return ;
2184+
2185+ // Ignore anything with a special name.
2186+ if (baseName.isSpecial ())
2187+ return ;
2188+
2189+ // Look for entities with the _unsafeInheritExecutor_ prefix on the name.
2190+ ASTContext &ctx = base->getASTContext ();
2191+ Identifier newIdentifier = ctx.getIdentifier (
2192+ (" _unsafeInheritExecutor_" + baseName.getIdentifier ().str ()).str ());
2193+
2194+ LookupResult replacementLookup = TypeChecker::lookupMember (
2195+ const_cast <DeclContext *>(dc), base, DeclNameRef (newIdentifier), loc,
2196+ defaultMemberLookupOptions);
2197+ if (replacementLookup.innerResults ().empty ())
2198+ return ;
2199+
2200+ // Drop all of the _Concurrency entries in favor of the ones found by this
2201+ // lookup.
2202+ lookup.filter ([&](const LookupResultEntry &entry, bool ) {
2203+ return !isReplaceable (entry.getValueDecl ());
2204+ });
2205+
2206+ for (const auto &entry: replacementLookup.innerResults ()) {
2207+ lookup.add (entry, /* isOuter=*/ false );
2208+ }
2209+ }
2210+
21562211// / Check if it is safe for the \c globalActor qualifier to be removed from
21572212// / \c ty, when the function value of that type is isolated to that actor.
21582213// /
0 commit comments