Skip to content

Commit b643cd8

Browse files
committed
[AST/Sema] NonCopyableGenerics: Remove all but one direct use of getMarking(...)
1 parent 6e0cfb5 commit b643cd8

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

lib/AST/ConformanceLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ getBuiltinInvertibleProtocolConformance(NominalTypeDecl *nominal,
415415
case InvertibleProtocolKind::Copyable:
416416
// If move-only classes is enabled, we'll check the markings.
417417
if (ctx.LangOpts.hasFeature(Feature::MoveOnlyClasses)) {
418-
auto marking = nominal->getMarking(*ip);
419-
switch (marking.getInverse().getKind()) {
418+
switch (nominal->hasInverseMarking(*ip).getKind()) {
420419
case InverseMarking::Kind::LegacyExplicit:
421420
case InverseMarking::Kind::Explicit:
422421
// An inverse ~Copyable prevents conformance.

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,11 +3219,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32193219
auto &ctx = decl->getASTContext();
32203220

32213221
for (auto ip : InvertibleProtocolSet::full()) {
3222-
auto marking = decl->getMarking(ip);
3222+
auto inverseMarking = decl->hasInverseMarking(ip);
32233223

32243224
// Inferred inverses are already ignored for classes.
32253225
// FIXME: we can also diagnose @_moveOnly here if we use `isAnyExplicit`
3226-
if (!marking.getInverse().is(InverseMarking::Kind::Explicit))
3226+
if (!inverseMarking.is(InverseMarking::Kind::Explicit))
32273227
continue;
32283228

32293229
// Allow ~Copyable when MoveOnlyClasses is enabled
@@ -3232,7 +3232,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32323232
continue;
32333233

32343234

3235-
ctx.Diags.diagnose(marking.getInverse().getLoc(),
3235+
ctx.Diags.diagnose(inverseMarking.getLoc(),
32363236
diag::inverse_on_class,
32373237
getProtocolName(getKnownProtocolKind(ip)));
32383238
}

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,24 @@ static void addConformanceFixIt(const NominalTypeDecl *nominal,
5252
// a conformance to KP.
5353
static void emitAdviceToApplyInverseAfter(InFlightDiagnostic &&diag,
5454
InvertibleProtocolKind ip,
55-
InverseMarking marking,
55+
InverseMarking::Mark inverseMarking,
5656
NominalTypeDecl *nominal) {
5757
auto kp = getKnownProtocolKind(ip);
5858

5959
// Immediately flush, then emit notes, so they're associated.
6060
diag.flush();
6161

62-
auto &ctx = nominal->getASTContext();
63-
// Not expecting the positive KP constraint to be classified as "Inferred".
64-
assert(marking.getPositive().getKind() != InverseMarking::Kind::Inferred);
65-
6662
// Have no advice for situations where the KP conformance is explicit.
63+
auto marking = nominal->getMarking(ip);
6764
if (marking.getPositive().isPresent())
6865
return;
6966

70-
switch (marking.getInverse().getKind()) {
67+
auto &ctx = nominal->getASTContext();
68+
69+
switch (inverseMarking.getKind()) {
7170
case InverseMarking::Kind::Inferred:
7271
// Note that the enclosing type is conditionally conforming to KP first.
73-
ctx.Diags.diagnose(marking.getInverse().getLoc(),
72+
ctx.Diags.diagnose(inverseMarking.getLoc(),
7473
diag::note_inverse_preventing_conformance_implicit,
7574
nominal, getProtocolName(kp));
7675
LLVM_FALLTHROUGH;
@@ -104,7 +103,7 @@ static void tryEmitContainmentFixits(InFlightDiagnostic &&diag,
104103
auto kp = getKnownProtocolKind(ip);
105104

106105
// Check the enclosing type's markings to see what to suggest.
107-
auto enclosingMarking = enclosingNom->getMarking(ip);
106+
auto enclosingMarking = enclosingNom->hasInverseMarking(ip);
108107

109108
// First, the generic advice.
110109
emitAdviceToApplyInverseAfter(std::move(diag), ip,
@@ -131,7 +130,7 @@ static void tryEmitContainmentFixits(InFlightDiagnostic &&diag,
131130
// not IP.
132131
if (auto nominal = nonConformingTy->getAnyNominal()) {
133132
if (nominal->getLoc(/*SerializedOK=*/false)) {
134-
auto inverse = nominal->getMarking(ip).getInverse();
133+
auto inverse = nominal->hasInverseMarking(ip);
135134
auto loc = inverse.getLoc();
136135

137136
switch (inverse.getKind()) {
@@ -176,10 +175,10 @@ static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
176175
//
177176
// So, if the nominal has `~Copyable` but this conformance is
178177
// written in an extension, then we do not raise an error.
179-
auto marking = nom->getMarking(ip);
180-
if (marking.getInverse().isAnyExplicit()) {
178+
auto inverseMarking = nom->hasInverseMarking(ip);
179+
if (inverseMarking.isAnyExplicit()) {
181180
if (conformance->getDeclContext() == nom) {
182-
ctx.Diags.diagnose(marking.getInverse().getLoc(),
181+
ctx.Diags.diagnose(inverseMarking.getLoc(),
183182
diag::inverse_but_also_conforms,
184183
nom, getProtocolName(kp));
185184
conforms &= false;
@@ -200,7 +199,7 @@ static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
200199
auto diag = deinit->diagnose(diag::copyable_illegal_deinit, nom);
201200
emitAdviceToApplyInverseAfter(std::move(diag),
202201
ip,
203-
nom->getMarking(ip),
202+
inverseMarking,
204203
nom);
205204
conforms &= false;
206205
}
@@ -398,14 +397,9 @@ ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
398397
return generateConformance(ext);
399398
};
400399

401-
auto marking = nominal->getMarking(*ip);
402-
403-
// Unexpected to have any positive marking for IP if we're deriving it.
404-
assert(!marking.getPositive().isPresent());
405-
406400
// Check what kind of inverse-marking we have to determine whether to generate
407401
// a conformance for IP.
408-
switch (marking.getInverse().getKind()) {
402+
switch (nominal->hasInverseMarking(*ip).getKind()) {
409403
case InverseMarking::Kind::LegacyExplicit:
410404
case InverseMarking::Kind::Explicit:
411405
return nullptr; // No positive IP conformance will be inferred.

0 commit comments

Comments
 (0)