Skip to content

Commit 68d2d82

Browse files
committed
[NFC] Teach BuiltinFunctionBuilder to Build Requirements
There is no need to build a fake RequirementRepr if we can directly represent a the requested AnyObject conformance constraint in the generated generic signature. This removes the final user of the TypeLoc-bearing constructors of RequirementReprs.
1 parent 10f53c0 commit 68d2d82

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lib/AST/Builtins.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -431,26 +431,13 @@ createGenericParam(ASTContext &ctx, const char *name, unsigned index) {
431431

432432
/// Create a generic parameter list with multiple generic parameters.
433433
static GenericParamList *getGenericParams(ASTContext &ctx,
434-
unsigned numParameters,
435-
bool isAnyObject) {
434+
unsigned numParameters) {
436435
assert(numParameters <= llvm::array_lengthof(GenericParamNames));
437436

438-
SmallVector<GenericTypeParamDecl*, 2> genericParams;
437+
SmallVector<GenericTypeParamDecl *, 2> genericParams;
439438
for (unsigned i = 0; i != numParameters; ++i)
440439
genericParams.push_back(createGenericParam(ctx, GenericParamNames[i], i));
441440

442-
443-
if (isAnyObject) {
444-
CanType ao = ctx.getAnyObjectType();
445-
SmallVector<RequirementRepr, 1> req;
446-
req.push_back(RequirementRepr::getTypeConstraint(TypeLoc::withoutLoc(genericParams[0]->getInterfaceType()), SourceLoc(),
447-
TypeLoc::withoutLoc(ao)));
448-
449-
auto paramList = GenericParamList::create(ctx, SourceLoc(), genericParams,
450-
SourceLoc(), req, SourceLoc());
451-
return paramList;
452-
}
453-
454441
auto paramList = GenericParamList::create(ctx, SourceLoc(), genericParams,
455442
SourceLoc());
456443
return paramList;
@@ -474,9 +461,15 @@ namespace {
474461

475462
public:
476463
BuiltinFunctionBuilder(ASTContext &ctx, unsigned numGenericParams = 1,
477-
bool isAnyObject = false)
464+
bool wantsAdditionalAnyObjectRequirement = false)
478465
: Context(ctx) {
479-
TheGenericParamList = getGenericParams(ctx, numGenericParams, isAnyObject);
466+
TheGenericParamList = getGenericParams(ctx, numGenericParams);
467+
if (wantsAdditionalAnyObjectRequirement) {
468+
Requirement req(RequirementKind::Conformance,
469+
TheGenericParamList->getParams()[0]->getInterfaceType(),
470+
ctx.getAnyObjectType());
471+
addedRequirements.push_back(req);
472+
}
480473
for (auto gp : TheGenericParamList->getParams()) {
481474
genericParamTypes.push_back(
482475
gp->getDeclaredInterfaceType()->castTo<GenericTypeParamType>());

0 commit comments

Comments
 (0)