Skip to content

Commit 61104cf

Browse files
committed
SIL: Clean up AbstractionPattern::getLayoutConstraint()
1 parent 253c0ac commit 61104cf

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ bool AbstractionPattern::requiresClass() const {
236236
// ObjC generics are always class constrained.
237237
return true;
238238
}
239-
239+
240240
assert(GenericSig &&
241241
"Dependent type in pattern without generic signature?");
242242
return GenericSig->requiresClass(type);
@@ -250,30 +250,23 @@ bool AbstractionPattern::requiresClass() const {
250250
}
251251

252252
LayoutConstraint AbstractionPattern::getLayoutConstraint() const {
253-
// TODO: `ArchetypeType::getLayoutConstraint` and
254-
// `GenericSignature::getLayoutConstraint` don't always propagate implied
255-
// layout constraints from protocol/class constraints. `requiresClass`
256-
// is, for the time being, the only one we really care about, though, and
257-
// it behaves correctly.
258-
if (requiresClass()) {
259-
return LayoutConstraint::getLayoutConstraint(LayoutConstraintKind::Class);
260-
}
261-
return LayoutConstraint();
262-
263-
#if GET_LAYOUT_CONSTRAINT_WORKED_THE_WAY_I_WANT
264253
switch (getKind()) {
265254
case Kind::Opaque:
266255
return LayoutConstraint();
267256
case Kind::Type:
268-
case Kind::Discard: {
257+
case Kind::Discard:
258+
case Kind::ClangType: {
269259
auto type = getType();
270260
if (auto archetype = dyn_cast<ArchetypeType>(type)) {
271-
auto archetypeSig = archetype->getGenericEnvironment()
272-
->getGenericSignature();
273-
return archetypeSig->getLayoutConstraint(archetype->getInterfaceType());
274-
}
275-
else if (isa<DependentMemberType>(type) ||
276-
isa<GenericTypeParamType>(type)) {
261+
return archetype->getLayoutConstraint();
262+
} else if (isa<DependentMemberType>(type) ||
263+
isa<GenericTypeParamType>(type)) {
264+
if (getKind() == Kind::ClangType) {
265+
// ObjC generics are always class constrained.
266+
return LayoutConstraint::getLayoutConstraint(
267+
LayoutConstraintKind::Class);
268+
}
269+
277270
assert(GenericSig &&
278271
"Dependent type in pattern without generic signature?");
279272
return GenericSig->getLayoutConstraint(type);
@@ -283,7 +276,6 @@ LayoutConstraint AbstractionPattern::getLayoutConstraint() const {
283276
default:
284277
return LayoutConstraint();
285278
}
286-
#endif
287279
}
288280

289281
bool AbstractionPattern::matchesTuple(CanTupleType substType) {

0 commit comments

Comments
 (0)