Skip to content

Commit d2d1211

Browse files
committed
Further improve AvailabilityWalker changes
Access context more quickly; document each flag’s purpose; perform a faster test before a slower one.
1 parent cbd1c59 commit d2d1211

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,7 @@ class AvailabilityWalker : public ASTWalker {
23112311
init->isImplicit() &&
23122312
init->getParameters()->size() == 1 &&
23132313
init->getParameters()->get(0)->getArgumentName() ==
2314-
DC->getASTContext().Id_rawValue;
2314+
TC.Context.Id_rawValue;
23152315
}
23162316

23172317
public:
@@ -2604,11 +2604,11 @@ AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
26042604
if (!isAccessorWithDeprecatedStorage)
26052605
TC.diagnoseIfDeprecated(R, DC, D, call);
26062606

2607-
if (Flags.contains(DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol)
2608-
&& isa<ProtocolDecl>(D))
2607+
if (Flags.contains(DeclAvailabilityFlag::AllowPotentiallyUnavailable))
26092608
return false;
26102609

2611-
if (Flags.contains(DeclAvailabilityFlag::AllowPotentiallyUnavailable))
2610+
if (Flags.contains(DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol)
2611+
&& isa<ProtocolDecl>(D))
26122612
return false;
26132613

26142614
// Diagnose (and possibly signal) for potential unavailability

lib/Sema/TypeCheckAvailability.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@ void diagAvailability(TypeChecker &TC, const Expr *E,
3535
DeclContext *DC);
3636

3737
enum class DeclAvailabilityFlag : uint8_t {
38+
/// Do not diagnose uses of protocols in versions before they were introduced.
39+
/// Used when type-checking protocol conformances, since conforming to a
40+
/// protocol that doesn't exist yet is allowed.
3841
AllowPotentiallyUnavailableProtocol = 1 << 0,
42+
43+
/// Diagnose uses of declarations in versions before they were introduced, but
44+
/// do not return true to indicate that a diagnostic was emitted.
3945
ContinueOnPotentialUnavailability = 1 << 1,
46+
47+
/// If a diagnostic must be emitted, use a variant indicating that the usage
48+
/// is inout and both the getter and setter must be available.
4049
ForInout = 1 << 2,
50+
51+
/// Do not diagnose uses of declarations in versions before they were
52+
/// introduced. Used to work around availability-checker bugs.
4153
AllowPotentiallyUnavailable = 1 << 3,
4254
};
4355
using DeclAvailabilityFlags = OptionSet<DeclAvailabilityFlag>;

0 commit comments

Comments
 (0)