@@ -2115,17 +2115,18 @@ void swift::introduceUnsafeInheritExecutorReplacements(
2115
2115
// Make sure at least some of the entries are functions in the _Concurrency
2116
2116
// module.
2117
2117
ModuleDecl *concurrencyModule = nullptr ;
2118
+ DeclBaseName baseName;
2118
2119
for (auto decl: decls) {
2119
2120
if (isReplaceable (decl)) {
2120
2121
concurrencyModule = decl->getDeclContext ()->getParentModule ();
2122
+ baseName = decl->getName ().getBaseName ();
2121
2123
break ;
2122
2124
}
2123
2125
}
2124
2126
if (!concurrencyModule)
2125
2127
return ;
2126
2128
2127
- // Dig out the name.
2128
- auto baseName = decls.front ()->getName ().getBaseName ();
2129
+ // Ignore anything with a special name.
2129
2130
if (baseName.isSpecial ())
2130
2131
return ;
2131
2132
@@ -2153,6 +2154,60 @@ void swift::introduceUnsafeInheritExecutorReplacements(
2153
2154
}
2154
2155
}
2155
2156
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
+
2156
2211
// / Check if it is safe for the \c globalActor qualifier to be removed from
2157
2212
// / \c ty, when the function value of that type is isolated to that actor.
2158
2213
// /
0 commit comments