Skip to content

Commit 852cda6

Browse files
committed
[Conformance checking] Factor requirement environment into its own type.
Rather than computing the requirement environment as a tuple of (generic signature, generic environment, substitution map), encapsulate the result in a new RequirementEnvironment class. Moreover, create a RequirementEnvironment once and re-use it when matching each of the witnesses, because the environment itself doesn't change---only the substitutions do. This saves us some work when there are multiple potential witnesses (which is common).
1 parent 0fe28ea commit 852cda6

File tree

5 files changed

+162
-129
lines changed

5 files changed

+162
-129
lines changed

lib/AST/ArchetypeBuilder.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,6 @@ bool ArchetypeBuilder::addSameTypeRequirement(Type Reqt1, Type Reqt2,
13011301

13021302
// Require that at least one side of the requirement be a potential archetype.
13031303
if (!T1 && !T2) {
1304-
assert(Source.getLoc().isValid() && "reintroducing invalid requirement");
13051304
Diags.diagnose(Source.getLoc(), diag::requires_no_same_type_archetype);
13061305
return true;
13071306
}
@@ -1489,7 +1488,7 @@ void ArchetypeBuilder::addRequirement(const Requirement &req,
14891488
switch (req.getKind()) {
14901489
case RequirementKind::Superclass: {
14911490
PotentialArchetype *pa = resolveArchetype(req.getFirstType());
1492-
assert(pa && "Re-introducing invalid requirement");
1491+
if (!pa) return;
14931492

14941493
assert(req.getSecondType()->getClassOrBoundGenericClass());
14951494
addSuperclassRequirement(pa, req.getSecondType(), source);
@@ -1498,11 +1497,7 @@ void ArchetypeBuilder::addRequirement(const Requirement &req,
14981497

14991498
case RequirementKind::Conformance: {
15001499
PotentialArchetype *pa = resolveArchetype(req.getFirstType());
1501-
assert(pa && "Re-introducing invalid requirement");
1502-
// FIXME: defensively return if assertions are disabled until we figure out
1503-
// how this situation can occur and fix it properly.
1504-
if (!pa)
1505-
return;
1500+
if (!pa) return;
15061501

15071502
SmallVector<ProtocolDecl *, 4> conformsTo;
15081503
bool existential = req.getSecondType()->isExistentialType(conformsTo);

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ namespace {
21532153
auto type = simplifyType(openedType);
21542154
expr->setType(type);
21552155

2156+
if (type->is<UnresolvedType>()) return expr;
2157+
21562158
Type conformingType = type;
21572159
if (auto baseType = conformingType->getAnyOptionalObjectType()) {
21582160
// The type may be optional due to a failable initializer in the

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,8 @@ static Optional<ObjCReason> shouldMarkAsObjC(TypeChecker &TC,
21602160
else if (VD->getOverriddenDecl() && VD->getOverriddenDecl()->isObjC())
21612161
return ObjCReason::OverridesObjC;
21622162
// A witness to an @objc protocol requirement is implicitly @objc.
2163-
else if (!TC.findWitnessedObjCRequirements(
2163+
else if (VD->getDeclContext()->getAsClassOrClassExtensionContext() &&
2164+
!TC.findWitnessedObjCRequirements(
21642165
VD,
21652166
/*anySingleRequirement=*/true).empty())
21662167
return ObjCReason::WitnessToObjC;

0 commit comments

Comments
 (0)