Skip to content

Commit 73f9392

Browse files
committed
[AST] Allow pattern bindings to be marked as fully verified
This would be used by closures because they handle patterns and initializers via solver and set them back to the pattern binding decl as fully type-checked.
1 parent fba8088 commit 73f9392

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,12 @@ class PatternBindingDecl final : public Decl,
18051805
return getPatternList()[i].getPattern();
18061806
}
18071807

1808-
void setPattern(unsigned i, Pattern *Pat, DeclContext *InitContext);
1808+
void setPattern(unsigned i, Pattern *Pat, DeclContext *InitContext,
1809+
bool isFullyValidated = false);
1810+
1811+
bool isFullyValidated(unsigned i) const {
1812+
return getPatternList()[i].isFullyValidated();
1813+
}
18091814

18101815
DeclContext *getInitContext(unsigned i) const {
18111816
return getPatternList()[i].getInitContext();

lib/AST/Decl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,18 +1658,23 @@ bool PatternBindingDecl::hasStorage() const {
16581658
}
16591659

16601660
void PatternBindingDecl::setPattern(unsigned i, Pattern *P,
1661-
DeclContext *InitContext) {
1661+
DeclContext *InitContext,
1662+
bool isFullyValidated) {
16621663
auto PatternList = getMutablePatternList();
16631664
PatternList[i].setPattern(P);
16641665
PatternList[i].setInitContext(InitContext);
16651666

16661667
// Make sure that any VarDecl's contained within the pattern know about this
16671668
// PatternBindingDecl as their parent.
1668-
if (P)
1669+
if (P) {
16691670
P->forEachVariable([&](VarDecl *VD) {
16701671
if (!VD->isCaptureList())
16711672
VD->setParentPatternBinding(this);
16721673
});
1674+
1675+
if (isFullyValidated)
1676+
PatternList[i].setFullyValidated();
1677+
}
16731678
}
16741679

16751680

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,8 +1880,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
18801880

18811881
auto &Ctx = getASTContext();
18821882
for (auto i : range(PBD->getNumPatternEntries())) {
1883-
const auto *entry = evaluateOrDefault(
1884-
Ctx.evaluator, PatternBindingEntryRequest{PBD, i}, nullptr);
1883+
const auto *entry =
1884+
PBD->isFullyValidated(i)
1885+
? &PBD->getPatternList()[i]
1886+
: evaluateOrDefault(Ctx.evaluator,
1887+
PatternBindingEntryRequest{PBD, i}, nullptr);
18851888
assert(entry && "No pattern binding entry?");
18861889

18871890
const auto *Pat = PBD->getPattern(i);

0 commit comments

Comments
 (0)