Skip to content

Commit 04790f1

Browse files
authored
Merge pull request swiftlang#18946 from DougGregor/specialize-validation
2 parents 9f37614 + d1ea181 commit 04790f1

File tree

5 files changed

+142
-281
lines changed

5 files changed

+142
-281
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace swift {
2929

3030
class GenericParamList;
3131
class RequirementRepr;
32+
class SpecializeAttr;
3233
struct TypeLoc;
3334

3435
/// Display a nominal type or extension thereof.
@@ -220,22 +221,27 @@ struct WhereClauseOwner {
220221

221222
/// The source of the where clause, which can be a generic parameter list
222223
/// or a declaration that can have a where clause.
223-
llvm::PointerUnion<GenericParamList *, Decl *> source;
224+
llvm::PointerUnion3<GenericParamList *, Decl *, SpecializeAttr *> source;
224225

225226
WhereClauseOwner(Decl *decl);
226227

227228
WhereClauseOwner(DeclContext *dc, GenericParamList *genericParams)
228229
: dc(dc), source(genericParams) { }
229230

231+
WhereClauseOwner(DeclContext *dc, SpecializeAttr *attr)
232+
: dc(dc), source(attr) { }
233+
230234
SourceLoc getLoc() const;
231235

232236
friend hash_code hash_value(const WhereClauseOwner &owner) {
233-
return hash_combine(hash_value(owner.dc), hash_value(owner.source));
237+
return hash_combine(hash_value(owner.dc),
238+
hash_value(owner.source.getOpaqueValue()));
234239
}
235240

236241
friend bool operator==(const WhereClauseOwner &lhs,
237242
const WhereClauseOwner &rhs) {
238-
return lhs.dc == rhs.dc && lhs.source == rhs.source;
243+
return lhs.dc == rhs.dc &&
244+
lhs.source.getOpaqueValue() == rhs.source.getOpaqueValue();
239245
}
240246

241247
friend bool operator!=(const WhereClauseOwner &lhs,

lib/AST/TypeCheckRequests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,18 @@ SourceLoc WhereClauseOwner::getLoc() const {
259259
if (auto decl = source.dyn_cast<Decl *>())
260260
return decl->getLoc();
261261

262+
if (auto attr = source.dyn_cast<SpecializeAttr *>())
263+
return attr->getLocation();
264+
262265
return source.get<GenericParamList *>()->getWhereLoc();
263266
}
264267

265268
void swift::simple_display(llvm::raw_ostream &out,
266269
const WhereClauseOwner &owner) {
267270
if (auto decl = owner.source.dyn_cast<Decl *>()) {
268271
simple_display(out, decl);
272+
} else if (owner.source.is<SpecializeAttr *>()) {
273+
out << "@_specialize";
269274
} else {
270275
out << "(SIL generic parameter list)";
271276
}
@@ -289,6 +294,13 @@ RequirementRequest::getRequirements(WhereClauseOwner owner) {
289294
return genericParams->getRequirements();
290295
}
291296

297+
if (auto attr = owner.source.dyn_cast<SpecializeAttr *>()) {
298+
if (auto whereClause = attr->getTrailingWhereClause())
299+
return whereClause->getRequirements();
300+
301+
return { };
302+
}
303+
292304
auto decl = owner.source.dyn_cast<Decl *>();
293305
if (!decl)
294306
return { };

0 commit comments

Comments
 (0)