18
18
19
19
using namespace swift ;
20
20
21
+ // Defined as a macro because you can't take the reference of a bitfield.
22
+ #define CONSTRAIN_BOOL (_old, _new ) \
23
+ [&]() { \
24
+ if (_old || !_new) \
25
+ return false ; \
26
+ _old = true ; \
27
+ return true ; \
28
+ }()
29
+
30
+ static bool constrainRange (AvailabilityRange &existing,
31
+ const AvailabilityRange &other) {
32
+ if (!other.isContainedIn (existing))
33
+ return false ;
34
+
35
+ existing = other;
36
+ return true ;
37
+ }
38
+
21
39
bool AvailabilityContext::PlatformInfo::constrainWith (
22
40
const PlatformInfo &other) {
23
41
bool isConstrained = false ;
24
- isConstrained |= constrainRange (other.Range );
42
+ isConstrained |= constrainRange (Range, other.Range );
25
43
if (other.IsUnavailable ) {
26
44
isConstrained |= constrainUnavailability (other.UnavailablePlatform );
27
45
}
28
- isConstrained |= constrainDeprecated ( other.IsDeprecated );
46
+ isConstrained |= CONSTRAIN_BOOL (IsDeprecated, other.IsDeprecated );
29
47
30
48
return isConstrained;
31
49
}
@@ -35,13 +53,13 @@ bool AvailabilityContext::PlatformInfo::constrainWith(const Decl *decl) {
35
53
auto &ctx = decl->getASTContext ();
36
54
37
55
if (auto range = AvailabilityInference::annotatedAvailableRange (decl))
38
- isConstrained |= constrainRange (*range);
56
+ isConstrained |= constrainRange (Range, *range);
39
57
40
58
if (auto *attr = decl->getAttrs ().getUnavailable (ctx))
41
59
isConstrained |= constrainUnavailability (attr->Platform );
42
60
43
- if (!IsDeprecated)
44
- isConstrained |= constrainDeprecated ( decl->getAttrs ().isDeprecated (ctx));
61
+ isConstrained |=
62
+ CONSTRAIN_BOOL (IsDeprecated, decl->getAttrs ().isDeprecated (ctx));
45
63
46
64
return isConstrained;
47
65
}
@@ -72,14 +90,6 @@ bool AvailabilityContext::PlatformInfo::constrainUnavailability(
72
90
return true ;
73
91
}
74
92
75
- bool AvailabilityContext::PlatformInfo::constrainDeprecated (bool deprecated) {
76
- if (IsDeprecated || !deprecated)
77
- return false ;
78
-
79
- IsDeprecated = true ;
80
- return true ;
81
- }
82
-
83
93
bool AvailabilityContext::PlatformInfo::isContainedIn (
84
94
const PlatformInfo &other) const {
85
95
if (!Range.isContainedIn (other.Range ))
@@ -156,7 +166,7 @@ void AvailabilityContext::constrainWithDecl(const Decl *decl) {
156
166
void AvailabilityContext::constrainWithPlatformRange (
157
167
const AvailabilityRange &platformRange, ASTContext &ctx) {
158
168
PlatformInfo platformAvailability{Info->Platform };
159
- if (!platformAvailability. constrainRange (platformRange))
169
+ if (!constrainRange (platformAvailability. Range , platformRange))
160
170
return ;
161
171
162
172
Info = Storage::get (platformAvailability, ctx);
@@ -167,7 +177,7 @@ void AvailabilityContext::constrainWithDeclAndPlatformRange(
167
177
PlatformInfo platformAvailability{Info->Platform };
168
178
bool isConstrained = false ;
169
179
isConstrained |= platformAvailability.constrainWith (decl);
170
- isConstrained |= platformAvailability. constrainRange (platformRange);
180
+ isConstrained |= constrainRange (platformAvailability. Range , platformRange);
171
181
172
182
if (!isConstrained)
173
183
return ;
0 commit comments