Skip to content

Commit 198601d

Browse files
committed
Bitpack the transitional API
1 parent 8c73b7d commit 198601d

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

include/swift/AST/Decl.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ class PatternBindingEntry {
18921892
/// Whether the contents of this initializer were subsumed by
18931893
/// some other initialization, e.g., a lazy property's initializer
18941894
/// gets subsumed by the getter body.
1895-
Subsumed = 1 << 2,
1895+
Subsumed = 1 << 2,
18961896
};
18971897
llvm::PointerIntPair<Pattern *, 3, OptionSet<Flags>> PatternAndFlags;
18981898

@@ -1918,8 +1918,13 @@ class PatternBindingEntry {
19181918
StringRef InitStringRepresentation;
19191919
};
19201920

1921+
enum class PatternFlags {
1922+
IsText = 1 << 0,
1923+
IsFullyValidated = 1 << 1,
1924+
};
19211925
/// The initializer context used for this pattern binding entry.
1922-
llvm::PointerIntPair<DeclContext *, 1, bool> InitContextAndIsText;
1926+
llvm::PointerIntPair<DeclContext *, 2, OptionSet<PatternFlags>>
1927+
InitContextAndFlags;
19231928

19241929
/// Values captured by this initializer.
19251930
CaptureInfo Captures;
@@ -1931,22 +1936,21 @@ class PatternBindingEntry {
19311936
// Flags::Checked.
19321937
friend class PatternBindingEntryRequest;
19331938

1934-
bool IsFullyValidated = false;
1935-
19361939
bool isFullyValidated() const {
1937-
return IsFullyValidated;
1940+
return InitContextAndFlags.getInt().contains(
1941+
PatternFlags::IsFullyValidated);
19381942
}
19391943
void setFullyValidated() {
1940-
IsFullyValidated = true;
1944+
InitContextAndFlags.setInt(InitContextAndFlags.getInt() |
1945+
PatternFlags::IsFullyValidated);
19411946
}
19421947

19431948
public:
19441949
/// \p E is the initializer as parsed.
19451950
PatternBindingEntry(Pattern *P, SourceLoc EqualLoc, Expr *E,
19461951
DeclContext *InitContext)
1947-
: PatternAndFlags(P, {}), InitExpr({E, E, EqualLoc}),
1948-
InitContextAndIsText({InitContext, false}) {
1949-
}
1952+
: PatternAndFlags(P, {}), InitExpr({E, E, EqualLoc}),
1953+
InitContextAndFlags({InitContext, None}) {}
19501954

19511955
Pattern *getPattern() const { return PatternAndFlags.getPointer(); }
19521956
void setPattern(Pattern *P) { PatternAndFlags.setPointer(P); }
@@ -1956,7 +1960,7 @@ class PatternBindingEntry {
19561960

19571961
Expr *getInit() const {
19581962
if (PatternAndFlags.getInt().contains(Flags::Removed) ||
1959-
InitContextAndIsText.getInt())
1963+
InitContextAndFlags.getInt().contains(PatternFlags::IsText))
19601964
return nullptr;
19611965
return InitExpr.initAfterSynthesis;
19621966
}
@@ -1976,7 +1980,8 @@ class PatternBindingEntry {
19761980
/// deserialized from a partial module.
19771981
void setInitStringRepresentation(StringRef str) {
19781982
InitStringRepresentation = str;
1979-
InitContextAndIsText.setInt(true);
1983+
InitContextAndFlags.setInt(InitContextAndFlags.getInt() |
1984+
PatternFlags::IsText);
19801985
}
19811986

19821987
/// Whether this pattern entry can generate a string representation of its
@@ -1985,12 +1990,14 @@ class PatternBindingEntry {
19851990

19861991
/// Retrieve the location of the equal '=' token.
19871992
SourceLoc getEqualLoc() const {
1988-
return InitContextAndIsText.getInt() ? SourceLoc() : InitExpr.EqualLoc;
1993+
return InitContextAndFlags.getInt().contains(PatternFlags::IsText)
1994+
? SourceLoc()
1995+
: InitExpr.EqualLoc;
19891996
}
19901997

19911998
/// Set the location of the equal '=' token.
19921999
void setEqualLoc(SourceLoc equalLoc) {
1993-
assert(!InitContextAndIsText.getInt() &&
2000+
assert(!InitContextAndFlags.getInt().contains(PatternFlags::IsText) &&
19942001
"cannot set equal loc for textual initializer");
19952002
InitExpr.EqualLoc = equalLoc;
19962003
}
@@ -2021,13 +2028,11 @@ class PatternBindingEntry {
20212028

20222029
// Retrieve the declaration context for the initializer.
20232030
DeclContext *getInitContext() const {
2024-
return InitContextAndIsText.getPointer();
2031+
return InitContextAndFlags.getPointer();
20252032
}
20262033

20272034
/// Override the initializer context.
2028-
void setInitContext(DeclContext *dc) {
2029-
InitContextAndIsText.setPointer(dc);
2030-
}
2035+
void setInitContext(DeclContext *dc) { InitContextAndFlags.setPointer(dc); }
20312036

20322037
SourceLoc getStartLoc() const;
20332038

lib/AST/Decl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,9 @@ unsigned PatternBindingDecl::getPatternEntryIndexForVarDecl(const VarDecl *VD) c
14441444
}
14451445

14461446
Expr *PatternBindingEntry::getOriginalInit() const {
1447-
return InitContextAndIsText.getInt() ? nullptr : InitExpr.originalInit;
1447+
return InitContextAndFlags.getInt().contains(PatternFlags::IsText)
1448+
? nullptr
1449+
: InitExpr.originalInit;
14481450
}
14491451

14501452
SourceRange PatternBindingEntry::getOriginalInitRange() const {
@@ -1455,7 +1457,8 @@ SourceRange PatternBindingEntry::getOriginalInitRange() const {
14551457

14561458
void PatternBindingEntry::setOriginalInit(Expr *E) {
14571459
InitExpr.originalInit = E;
1458-
InitContextAndIsText.setInt(false);
1460+
InitContextAndFlags.setInt(InitContextAndFlags.getInt() -
1461+
PatternFlags::IsText);
14591462
}
14601463

14611464
bool PatternBindingEntry::isInitialized() const {
@@ -1481,7 +1484,8 @@ void PatternBindingEntry::setInit(Expr *E) {
14811484
PatternAndFlags.setInt(F | Flags::Removed);
14821485
}
14831486
InitExpr.initAfterSynthesis = E;
1484-
InitContextAndIsText.setInt(false);
1487+
InitContextAndFlags.setInt(InitContextAndFlags.getInt() -
1488+
PatternFlags::IsText);
14851489
}
14861490

14871491
VarDecl *PatternBindingEntry::getAnchoringVarDecl() const {
@@ -1530,7 +1534,7 @@ SourceRange PatternBindingEntry::getSourceRange(bool omitAccessors) const {
15301534
}
15311535

15321536
bool PatternBindingEntry::hasInitStringRepresentation() const {
1533-
if (InitContextAndIsText.getInt())
1537+
if (InitContextAndFlags.getInt().contains(PatternFlags::IsText))
15341538
return !InitStringRepresentation.empty();
15351539
return getInit() && getInit()->getSourceRange().isValid();
15361540
}
@@ -1541,7 +1545,8 @@ StringRef PatternBindingEntry::getInitStringRepresentation(
15411545
assert(hasInitStringRepresentation() &&
15421546
"must check if pattern has string representation");
15431547

1544-
if (InitContextAndIsText.getInt() && !InitStringRepresentation.empty())
1548+
if (InitContextAndFlags.getInt().contains(PatternFlags::IsText) &&
1549+
!InitStringRepresentation.empty())
15451550
return InitStringRepresentation;
15461551
auto &sourceMgr = getAnchoringVarDecl()->getASTContext().SourceMgr;
15471552
auto init = getOriginalInit();

lib/Sema/TypeCheckStorage.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ PatternBindingEntryRequest::evaluate(Evaluator &eval,
217217

218218
if (TC->typeCheckPattern(pattern, binding->getDeclContext(), options)) {
219219
swift::setBoundVarsTypeError(pattern, Context);
220-
setBoundVarsTypeError(pattern, Context);
221220
binding->setInvalid();
222221
pattern->setType(ErrorType::get(Context));
223222
return &pbe;
@@ -241,10 +240,7 @@ PatternBindingEntryRequest::evaluate(Evaluator &eval,
241240
// we'll need to check the initializer.
242241
if (!pattern->hasType() || pattern->getType()->hasUnboundGenericType()) {
243242
if (TC->typeCheckPatternBinding(binding, entryNumber)) {
244-
swift::setBoundVarsTypeError(pattern, Context);
245-
setBoundVarsTypeError(pattern, Context);
246243
binding->setInvalid();
247-
pattern->setType(ErrorType::get(Context));
248244
return &pbe;
249245
}
250246

0 commit comments

Comments
 (0)