Skip to content

Commit b454ded

Browse files
committed
Sema: have createBuiltinCall handle conformances
The only callers of `DerivedConformance::createBuiltinCall` aren't actually aware of what the generic signature is for the builtin they want to call. Thus, they can't really provide the needed conformances. This wasn't an issue when there were no conformances needed for the substitution map, but with NoncopyableGenerics, we need at least Copyable conformances for the generic parameters of a builtin. It's easy enough to make this function just handle generating the conformances list, so that's the refactoring here.
1 parent 107475b commit b454ded

4 files changed

+16
-6
lines changed

lib/Sema/DerivedConformanceActor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ deriveBodyActor_unownedExecutor(AbstractFunctionDecl *getter, void *) {
112112
auto builtinCall =
113113
DerivedConformance::createBuiltinCall(ctx,
114114
BuiltinValueKind::BuildDefaultActorExecutorRef,
115-
{selfType}, {}, {selfArg});
115+
{selfType}, {selfArg});
116116

117117
// Turn that into an UnownedSerialExecutor.
118118
auto initCall = constructUnownedSerialExecutor(ctx, builtinCall);

lib/Sema/DerivedConformanceDistributedActor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ deriveBodyDistributedActor_unownedExecutor(AbstractFunctionDecl *getter, void *)
664664
auto builtinCall =
665665
DerivedConformance::createBuiltinCall(ctx,
666666
BuiltinValueKind::BuildDefaultActorExecutorRef,
667-
{selfType}, {}, {selfArg});
667+
{selfType}, {selfArg});
668668
// Turn that into an UnownedSerialExecutor.
669669
auto initCall = constructDistributedUnownedSerialExecutor(ctx, builtinCall);
670670
if (!initCall) return failure();

lib/Sema/DerivedConformances.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ CallExpr *
462462
DerivedConformance::createBuiltinCall(ASTContext &ctx,
463463
BuiltinValueKind builtin,
464464
ArrayRef<Type> typeArgs,
465-
ArrayRef<ProtocolConformanceRef>
466-
conformances,
467465
ArrayRef<Expr *> args) {
468466
auto name = ctx.getIdentifier(getBuiltinName(builtin));
469467
auto decl = getBuiltinValueDecl(ctx, name);
@@ -472,8 +470,21 @@ DerivedConformance::createBuiltinCall(ASTContext &ctx,
472470
ConcreteDeclRef declRef = decl;
473471
auto fnType = decl->getInterfaceType();
474472
if (auto genericFnType = fnType->getAs<GenericFunctionType>()) {
473+
auto builtinModule = decl->getModuleContext();
475474
auto generics = genericFnType->getGenericSignature();
476-
auto subs = SubstitutionMap::get(generics, typeArgs, conformances);
475+
476+
auto genericParams = generics.getGenericParams();
477+
assert(genericParams.size() == typeArgs.size());
478+
479+
TypeSubstitutionMap map;
480+
for (auto i : indices(genericParams))
481+
map.insert({genericParams[i]->getCanonicalType()
482+
->getAs<SubstitutableType>(),
483+
typeArgs[i]});
484+
485+
auto subs = SubstitutionMap::get(generics,
486+
QueryTypeSubstitutionMap{map},
487+
LookUpConformanceInModule{builtinModule});
477488
declRef = ConcreteDeclRef(decl, subs);
478489
fnType = genericFnType->substGenericArgs(subs);
479490
} else {

lib/Sema/DerivedConformances.h

-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ class DerivedConformance {
387387
static CallExpr *createBuiltinCall(ASTContext &ctx,
388388
BuiltinValueKind builtin,
389389
ArrayRef<Type> typeArgs,
390-
ArrayRef<ProtocolConformanceRef> conformances,
391390
ArrayRef<Expr *> args);
392391

393392
/// Build a call to the stdlib function that should be called when unavailable

0 commit comments

Comments
 (0)