Skip to content

Commit 4551230

Browse files
committed
Sema: Remove ConformanceCheckFlags::Used
1 parent 3917268 commit 4551230

File tree

9 files changed

+41
-63
lines changed

9 files changed

+41
-63
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ SubstitutionMap Solution::computeSubstitutions(
9090

9191
return tc.conformsToProtocol(replacement, protoType,
9292
getConstraintSystem().DC,
93-
(ConformanceCheckFlags::InExpression|
94-
ConformanceCheckFlags::Used));
93+
ConformanceCheckFlags::InExpression);
9594
};
9695

9796
return SubstitutionMap::get(sig,
@@ -428,8 +427,7 @@ namespace {
428427
auto conformance =
429428
tc.conformsToProtocol(
430429
baseTy, proto, cs.DC,
431-
(ConformanceCheckFlags::InExpression|
432-
ConformanceCheckFlags::Used));
430+
ConformanceCheckFlags::InExpression);
433431
if (conformance && conformance->isConcrete()) {
434432
if (auto witness =
435433
conformance->getConcrete()->getWitnessDecl(decl, &tc)) {
@@ -1699,8 +1697,7 @@ namespace {
16991697
= tc.conformsToProtocol(valueType,
17001698
bridgedProto,
17011699
cs.DC,
1702-
(ConformanceCheckFlags::InExpression|
1703-
ConformanceCheckFlags::Used));
1700+
ConformanceCheckFlags::InExpression);
17041701

17051702
FuncDecl *fn = nullptr;
17061703

@@ -4575,9 +4572,6 @@ namespace {
45754572
auto hashable =
45764573
cs.getASTContext().getProtocol(KnownProtocolKind::Hashable);
45774574

4578-
auto equatable =
4579-
cs.getASTContext().getProtocol(KnownProtocolKind::Equatable);
4580-
45814575
auto &TC = cs.getTypeChecker();
45824576
auto fnType = overload.openedType->castTo<FunctionType>();
45834577
for (const auto &param : fnType->getParams()) {
@@ -4587,20 +4581,9 @@ namespace {
45874581
// with all of the generic parameters resolved.
45884582
auto hashableConformance =
45894583
TC.conformsToProtocol(indexType, hashable, cs.DC,
4590-
(ConformanceCheckFlags::Used |
4591-
ConformanceCheckFlags::InExpression));
4584+
ConformanceCheckFlags::InExpression);
45924585
assert(hashableConformance.hasValue());
45934586

4594-
// FIXME: Hashable implies Equatable, but we need to make sure the
4595-
// Equatable conformance is forced into existence during type
4596-
// checking so that it's available for SILGen.
4597-
auto eqConformance =
4598-
TC.conformsToProtocol(indexType, equatable, cs.DC,
4599-
(ConformanceCheckFlags::Used |
4600-
ConformanceCheckFlags::InExpression));
4601-
assert(eqConformance.hasValue());
4602-
(void)eqConformance;
4603-
46044587
conformances.push_back(*hashableConformance);
46054588
}
46064589

@@ -5152,8 +5135,7 @@ collectExistentialConformances(TypeChecker &tc, Type fromType, Type toType,
51525135
for (auto proto : layout.getProtocols()) {
51535136
conformances.push_back(
51545137
*tc.containsProtocol(fromType, proto->getDecl(), DC,
5155-
(ConformanceCheckFlags::InExpression|
5156-
ConformanceCheckFlags::Used)));
5138+
ConformanceCheckFlags::InExpression));
51575139
}
51585140

51595141
return tc.Context.AllocateCopy(conformances);
@@ -6262,8 +6244,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
62626244
auto conformance =
62636245
tc.conformsToProtocol(
62646246
cs.getType(expr), hashable, cs.DC,
6265-
(ConformanceCheckFlags::InExpression |
6266-
ConformanceCheckFlags::Used));
6247+
ConformanceCheckFlags::InExpression);
62676248
assert(conformance && "must conform to Hashable");
62686249

62696250
return cs.cacheType(

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ static CodableConformanceType typeConformsToCodable(TypeChecker &tc,
8989
return typeConformsToCodable(tc, context, target->getOptionalObjectType(),
9090
false, proto);
9191

92-
return tc.conformsToProtocol(target, proto, context,
93-
ConformanceCheckFlags::Used) ? Conforms
94-
: DoesNotConform;
92+
return tc.conformsToProtocol(target, proto, context, None) ? Conforms
93+
: DoesNotConform;
9594
}
9695

9796
/// Returns whether the given variable conforms to the given {En,De}codable
@@ -282,7 +281,7 @@ static CodingKeysValidity hasValidCodingKeysEnum(DerivedConformance &derived) {
282281
auto *codingKeyProto = C.getProtocol(KnownProtocolKind::CodingKey);
283282
if (!tc.conformsToProtocol(codingKeysType, codingKeyProto,
284283
derived.getConformanceContext(),
285-
ConformanceCheckFlags::Used)) {
284+
None)) {
286285
// If CodingKeys is a typealias which doesn't point to a valid nominal type,
287286
// codingKeysTypeDecl will be nullptr here. In that case, we need to warn on
288287
// the location of the usage, since there isn't an underlying type to
@@ -1069,8 +1068,7 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) {
10691068
if (auto *superclassDecl = classDecl->getSuperclassDecl()) {
10701069
DeclName memberName;
10711070
auto superType = superclassDecl->getDeclaredInterfaceType();
1072-
if (tc.conformsToProtocol(superType, proto, superclassDecl,
1073-
ConformanceCheckFlags::Used)) {
1071+
if (tc.conformsToProtocol(superType, proto, superclassDecl, None)) {
10741072
// super.init(from:) must be accessible.
10751073
memberName = cast<ConstructorDecl>(requirement)->getFullName();
10761074
} else {

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ static bool allAssociatedValuesConformToProtocol(DeclContext *DC,
5252
for (auto param : *PL) {
5353
auto type = param->getInterfaceType();
5454
if (!TypeChecker::conformsToProtocol(DC->mapTypeIntoContext(type),
55-
protocol, DC,
56-
ConformanceCheckFlags::Used)) {
55+
protocol, DC, None)) {
5756
return false;
5857
}
5958
}
@@ -81,8 +80,7 @@ static bool allStoredPropertiesConformToProtocol(DeclContext *DC,
8180
auto type = propertyDecl->getValueInterfaceType();
8281

8382
if (!TypeChecker::conformsToProtocol(DC->mapTypeIntoContext(type),
84-
protocol, DC,
85-
ConformanceCheckFlags::Used)) {
83+
protocol, DC, None)) {
8684
return false;
8785
}
8886
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,8 +4373,7 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
43734373
if (Context.LangOpts.EnableObjCInterop) {
43744374
if (auto errorTypeProto = Context.getProtocol(KnownProtocolKind::Error)) {
43754375
if (conformsToProtocol(toType, errorTypeProto, dc,
4376-
(ConformanceCheckFlags::InExpression|
4377-
ConformanceCheckFlags::Used))) {
4376+
ConformanceCheckFlags::InExpression)) {
43784377
auto nsError = Context.getNSErrorDecl();
43794378
if (nsError) {
43804379
if (!nsError->hasInterfaceType()) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,9 +5524,7 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
55245524
auto targetType = target->getDeclaredInterfaceType();
55255525
if (auto ref = conformsToProtocol(
55265526
targetType, protocol, target,
5527-
(ConformanceCheckFlags::Used|
5528-
ConformanceCheckFlags::SkipConditionalRequirements),
5529-
SourceLoc())) {
5527+
ConformanceCheckFlags::SkipConditionalRequirements)) {
55305528
if (auto *conformance = dyn_cast<NormalProtocolConformance>(
55315529
ref->getConcrete()->getRootConformance())) {
55325530
if (conformance->getState() == ProtocolConformanceState::Incomplete) {

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,7 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
18261826
auto InheritedConformance =
18271827
TC.conformsToProtocol(
18281828
T, InheritedProto, DC,
1829-
(ConformanceCheckFlags::Used|
1830-
ConformanceCheckFlags::SkipConditionalRequirements),
1829+
ConformanceCheckFlags::SkipConditionalRequirements,
18311830
ComplainLoc);
18321831
if (!InheritedConformance || !InheritedConformance->isConcrete()) {
18331832
// Recursive call already diagnosed this problem, but tack on a note
@@ -3725,7 +3724,7 @@ void ConformanceChecker::ensureRequirementsAreSatisfied(
37253724
proto->getRequirementSignature(),
37263725
QuerySubstitutionMap{substitutions},
37273726
TypeChecker::LookUpConformance(DC),
3728-
ConformanceCheckFlags::Used, &listener);
3727+
None, &listener);
37293728

37303729
switch (result) {
37313730
case RequirementCheckResult::Success:
@@ -4180,12 +4179,6 @@ Optional<ProtocolConformanceRef> TypeChecker::conformsToProtocol(
41804179
recordDependency();
41814180
}
41824181

4183-
// If we're using this conformance, note that.
4184-
if (options.contains(ConformanceCheckFlags::Used)) {
4185-
if (auto lazyResolver = DC->getASTContext().getLazyResolver())
4186-
lazyResolver->markConformanceUsed(*lookupResult, DC);
4187-
}
4188-
41894182
auto condReqs = lookupResult->getConditionalRequirementsIfAvailable();
41904183
// If we have a conditional requirements that
41914184
// we need to check, do so now.
@@ -4272,9 +4265,8 @@ TypeChecker::LookUpConformance::operator()(
42724265
conformingReplacementType,
42734266
conformedProtocol,
42744267
dc,
4275-
(ConformanceCheckFlags::Used|
4276-
ConformanceCheckFlags::InExpression|
4277-
ConformanceCheckFlags::SkipConditionalRequirements));
4268+
ConformanceCheckFlags::InExpression|
4269+
ConformanceCheckFlags::SkipConditionalRequirements);
42784270
}
42794271

42804272
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
@@ -5566,8 +5558,7 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
55665558
auto requirementProto =
55675559
req.getSecondType()->castTo<ProtocolType>()->getDecl();
55685560
auto conformance = conformsToProtocol(defaultAssocTypeInContext,
5569-
requirementProto, proto,
5570-
ConformanceCheckFlags::Used);
5561+
requirementProto, proto, None);
55715562
if (!conformance) {
55725563
// Diagnose the lack of a conformance. This is potentially an ABI
55735564
// incompatibility.

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ Type TypeChecker::applyUnboundGenericArguments(
852852
genericSig->getGenericParams(),
853853
genericSig->getRequirements(),
854854
QueryTypeSubstitutionMap{subs},
855-
LookUpConformance(dc));
855+
LookUpConformance(dc), None);
856856

857857
switch (result) {
858858
case RequirementCheckResult::Failure:

lib/Sema/TypeChecker.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,29 +488,25 @@ enum class RequirementCheckResult {
488488
enum class ConformanceCheckFlags {
489489
/// Whether we're performing the check from within an expression.
490490
InExpression = 0x01,
491-
/// Whether we will be using the conformance in the AST.
492-
///
493-
/// This implies that the conformance will have to be complete.
494-
Used = 0x02,
495491
/// Whether to suppress dependency tracking entirely.
496492
///
497493
/// FIXME: This deals with some oddities with the
498494
/// _ObjectiveCBridgeable conformances.
499-
SuppressDependencyTracking = 0x04,
495+
SuppressDependencyTracking = 0x02,
500496
/// Whether to skip the check for any conditional conformances.
501497
///
502498
/// When set, the caller takes responsibility for any
503499
/// conditional requirements required for the conformance to be
504500
/// correctly used. Otherwise (the default), all of the conditional
505501
/// requirements will be checked.
506-
SkipConditionalRequirements = 0x08,
502+
SkipConditionalRequirements = 0x04,
507503

508504
/// Whether to require that the conditional requirements have been computed.
509505
///
510506
/// When set, if the conditional requirements aren't available, they are just
511507
/// skipped, and the caller is responsible for detecting and handling this
512508
/// case (likely via another call to getConditionalRequirementsIfAvailable).
513-
AllowUnavailableConditionalRequirements = 0x10,
509+
AllowUnavailableConditionalRequirements = 0x08,
514510
};
515511

516512
/// Options that control protocol conformance checking.
@@ -1191,7 +1187,7 @@ class TypeChecker final : public LazyResolver {
11911187
ArrayRef<Requirement> requirements,
11921188
TypeSubstitutionFn substitutions,
11931189
LookupConformanceFn conformances,
1194-
ConformanceCheckOptions conformanceOptions = ConformanceCheckFlags::Used,
1190+
ConformanceCheckOptions conformanceOptions,
11951191
GenericRequirementsCheckListener *listener = nullptr,
11961192
SubstOptions options = None);
11971193

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
struct Generic${N}<T : Protocol${N}> {}
6+
7+
struct Conforms${N} : Protocol${N} {
8+
% if int(N) > 1:
9+
typealias A = Generic${int(N)-1}<Conforms${int(N)-1}>
10+
% end
11+
}
12+
13+
protocol Protocol${N} {
14+
% if int(N) > 1:
15+
associatedtype A
16+
% end
17+
}

0 commit comments

Comments
 (0)