@@ -337,12 +337,20 @@ void RequirementSignatureRequest::cacheResult(ArrayRef<Requirement> value) const
337
337
// Requirement computation.
338
338
// ----------------------------------------------------------------------------//
339
339
340
- WhereClauseOwner::WhereClauseOwner (Decl *decl)
341
- : dc(decl->getInnermostDeclContext ()), source(decl) { }
340
+ WhereClauseOwner::WhereClauseOwner (GenericContext *genCtx): dc(genCtx) {
341
+ if (const auto whereClause = genCtx->getTrailingWhereClause ())
342
+ source = whereClause;
343
+ else
344
+ source = genCtx->getGenericParams ();
345
+ }
346
+
347
+ WhereClauseOwner::WhereClauseOwner (AssociatedTypeDecl *atd)
348
+ : dc(atd->getInnermostDeclContext ()),
349
+ source(atd->getTrailingWhereClause ()) {}
342
350
343
351
SourceLoc WhereClauseOwner::getLoc () const {
344
- if (auto decl = source.dyn_cast <Decl *>())
345
- return decl-> getLoc ();
352
+ if (auto where = source.dyn_cast <TrailingWhereClause *>())
353
+ return where-> getWhereLoc ();
346
354
347
355
if (auto attr = source.dyn_cast <SpecializeAttr *>())
348
356
return attr->getLocation ();
@@ -352,8 +360,8 @@ SourceLoc WhereClauseOwner::getLoc() const {
352
360
353
361
void swift::simple_display (llvm::raw_ostream &out,
354
362
const WhereClauseOwner &owner) {
355
- if (auto decl = owner.source .dyn_cast <Decl *>()) {
356
- simple_display (out, decl );
363
+ if (auto where = owner.source .dyn_cast <TrailingWhereClause *>()) {
364
+ simple_display (out, owner. dc -> getAsDecl () );
357
365
} else if (owner.source .is <SpecializeAttr *>()) {
358
366
out << " @_specialize" ;
359
367
} else {
@@ -375,36 +383,13 @@ void RequirementRequest::noteCycleStep(DiagnosticEngine &diags) const {
375
383
}
376
384
377
385
MutableArrayRef<RequirementRepr> WhereClauseOwner::getRequirements () const {
378
- if (auto genericParams = source.dyn_cast <GenericParamList *>()) {
386
+ if (const auto genericParams = source.dyn_cast <GenericParamList *>()) {
379
387
return genericParams->getRequirements ();
380
- }
381
-
382
- if (auto attr = source.dyn_cast <SpecializeAttr *>()) {
388
+ } else if (const auto attr = source.dyn_cast <SpecializeAttr *>()) {
383
389
if (auto whereClause = attr->getTrailingWhereClause ())
384
390
return whereClause->getRequirements ();
385
-
386
- return { };
387
- }
388
-
389
- auto decl = source.dyn_cast <Decl *>();
390
- if (!decl)
391
- return { };
392
-
393
- if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
394
- if (auto whereClause = proto->getTrailingWhereClause ())
395
- return whereClause->getRequirements ();
396
-
397
- return { };
398
- }
399
-
400
- if (auto assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
401
- if (auto whereClause = assocType->getTrailingWhereClause ())
402
- return whereClause->getRequirements ();
403
- }
404
-
405
- if (auto genericContext = decl->getAsGenericContext ()) {
406
- if (auto genericParams = genericContext->getGenericParams ())
407
- return genericParams->getRequirements ();
391
+ } else if (const auto whereClause = source.get <TrailingWhereClause *>()) {
392
+ return whereClause->getRequirements ();
408
393
}
409
394
410
395
return { };
0 commit comments