Skip to content

Commit d4cc35a

Browse files
committed
AST: Remove VarDecl::hasNonPatternBindingInit()
1 parent 7cb809b commit d4cc35a

16 files changed

+18
-73
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,13 @@ class alignas(1 << DeclAlignInBits) Decl {
353353
IsStatic : 1
354354
);
355355

356-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+1+1+1+1+1+1,
356+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+1+1+1+1+1,
357357
/// Encodes whether this is a 'let' binding.
358358
Introducer : 1,
359359

360360
/// Whether this declaration captures the 'self' param under the same name.
361361
IsSelfParamCapture : 1,
362362

363-
/// Whether this vardecl has an initial value bound to it in a way
364-
/// that isn't represented in the AST with an initializer in the pattern
365-
/// binding. This happens in cases like "for i in ...", switch cases, etc.
366-
HasNonPatternBindingInit : 1,
367-
368363
/// Whether this is a property used in expressions in the debugger.
369364
/// It is up to the debugger to instruct SIL how to access this variable.
370365
IsDebuggerVar : 1,
@@ -5115,16 +5110,6 @@ class VarDecl : public AbstractStorageDecl {
51155110
Bits.VarDecl.IsSelfParamCapture = IsSelfParamCapture;
51165111
}
51175112

5118-
/// Return true if this vardecl has an initial value bound to it in a way
5119-
/// that isn't represented in the AST with an initializer in the pattern
5120-
/// binding. This happens in cases like "for i in ...", switch cases, etc.
5121-
bool hasNonPatternBindingInit() const {
5122-
return Bits.VarDecl.HasNonPatternBindingInit;
5123-
}
5124-
void setHasNonPatternBindingInit(bool V = true) {
5125-
Bits.VarDecl.HasNonPatternBindingInit = V;
5126-
}
5127-
51285113
/// Determines if this var has an initializer expression that should be
51295114
/// exposed to clients.
51305115
/// There's a very narrow case when we would: if the decl is an instance

include/swift/AST/Pattern.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ class alignas(8) Pattern {
190190

191191
bool isNeverDefaultInitializable() const;
192192

193-
/// Mark all vardecls in this pattern as having non-pattern initial
194-
/// values bound into them.
195-
void markHasNonPatternBindingInit() {
196-
forEachVariable([&](VarDecl *VD) {
197-
VD->setHasNonPatternBindingInit();
198-
});
199-
}
200-
201193
/// Mark all vardecls in this pattern as having an owning statement for
202194
/// the pattern.
203195
void markOwnedByStatement(Stmt *S) {

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,6 @@ namespace {
842842
printCommon(VD, "var_decl");
843843
if (VD->isLet())
844844
PrintWithColorRAII(OS, DeclModifierColor) << " let";
845-
if (VD->hasNonPatternBindingInit())
846-
PrintWithColorRAII(OS, DeclModifierColor) << " non_pattern_init";
847845
if (VD->getAttrs().hasAttribute<LazyAttr>())
848846
PrintWithColorRAII(OS, DeclModifierColor) << " lazy";
849847
printStorageImpl(VD);

lib/AST/Decl.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5408,7 +5408,6 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
54085408
Bits.VarDecl.IsSelfParamCapture = false;
54095409
Bits.VarDecl.IsDebuggerVar = false;
54105410
Bits.VarDecl.IsLazyStorageProperty = false;
5411-
Bits.VarDecl.HasNonPatternBindingInit = false;
54125411
Bits.VarDecl.IsPropertyWrapperBackingProperty = false;
54135412
Bits.VarDecl.IsTopLevelGlobal = false;
54145413
}
@@ -5431,26 +5430,21 @@ bool VarDecl::isSettable(const DeclContext *UseDC,
54315430
if (!isLet())
54325431
return supportsMutation();
54335432

5433+
//
5434+
// All the remaining logic handles the special cases where you can
5435+
// assign a 'let'.
5436+
//
5437+
54345438
// Debugger expression 'let's are initialized through a side-channel.
54355439
if (isDebuggerVar())
54365440
return false;
54375441

5438-
// We have a 'let'; we must be checking settability from a specific
5439-
// DeclContext to go on further.
5442+
// 'let's are only ever settable from a specific DeclContext.
54405443
if (UseDC == nullptr)
54415444
return false;
5442-
5443-
// If the decl has a value bound to it but has no PBD, then it is
5444-
// initialized.
5445-
if (hasNonPatternBindingInit())
5446-
return false;
5447-
5448-
// Capture list bindings are never settable.
5449-
if (isCaptureList())
5450-
return false;
54515445

5452-
// Properties in structs/classes are only ever mutable in their designated
5453-
// initializer(s).
5446+
// 'let' properties in structs/classes are only ever settable in their
5447+
// designated initializer(s).
54545448
if (isInstanceMember()) {
54555449
auto *CD = dyn_cast<ConstructorDecl>(UseDC);
54565450
if (!CD) return false;
@@ -5480,7 +5474,12 @@ bool VarDecl::isSettable(const DeclContext *UseDC,
54805474
return true;
54815475
}
54825476

5483-
// If the decl has an explicitly written initializer with a pattern binding,
5477+
// If the 'let' has a value bound to it but has no PBD, then it is
5478+
// already initializedand not settable.
5479+
if (getParentPatternBinding() == nullptr)
5480+
return false;
5481+
5482+
// If the 'let' has an explicitly written initializer with a pattern binding,
54845483
// then it isn't settable.
54855484
if (isParentInitialized())
54865485
return false;

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
19931993
/*NameLoc=*/SourceLoc(),
19941994
Context.Id_dollarInterpolation, CurDeclContext);
19951995
InterpolationVar->setImplicit(true);
1996-
InterpolationVar->setHasNonPatternBindingInit(true);
19971996
InterpolationVar->setUserAccessible(false);
19981997
addToScope(InterpolationVar);
19991998
setLocalDiscriminator(InterpolationVar);

lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,6 @@ static void parseGuardedPattern(Parser &P, GuardedPattern &result,
11291129
boundDecls.push_back(VD);
11301130
});
11311131

1132-
// Now that we have them, mark them as being initialized without a PBD.
1133-
for (auto VD : boundDecls)
1134-
VD->setHasNonPatternBindingInit();
1135-
11361132
// Parse the optional 'where' guard.
11371133
parseWhereGuard(P, result, status, parsingContext, isExprBasic);
11381134
} else {
@@ -1178,10 +1174,6 @@ static void parseGuardedPattern(Parser &P, GuardedPattern &result,
11781174
status.setIsParseError();
11791175
}
11801176
}
1181-
1182-
for (auto VD : repeatedDecls) {
1183-
VD->setHasNonPatternBindingInit();
1184-
}
11851177

11861178
// Parse the optional 'where' guard, with this particular pattern's bound
11871179
// vars in scope.
@@ -1544,7 +1536,6 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
15441536
setLocalDiscriminator(VD);
15451537
if (VD->hasName())
15461538
addToScope(VD);
1547-
VD->setHasNonPatternBindingInit();
15481539
});
15491540
return Status;
15501541
}
@@ -2034,7 +2025,6 @@ ParserResult<CaseStmt> Parser::parseStmtCatch() {
20342025
auto *vNew = new (Context) VarDecl(
20352026
/*IsStatic*/ false, vOld->getIntroducer(),
20362027
vOld->getNameLoc(), vOld->getName(), vOld->getDeclContext());
2037-
vNew->setHasNonPatternBindingInit();
20382028
vNew->setImplicit();
20392029
Result[i] = vNew;
20402030
}
@@ -2145,9 +2135,6 @@ ParserResult<Stmt> Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) {
21452135
parseToken(tok::kw_in, InLoc, diag::expected_foreach_in);
21462136
}
21472137

2148-
// Bound variables all get their initial values from the generator.
2149-
pattern.get()->markHasNonPatternBindingInit();
2150-
21512138
if (IsCStyleFor) {
21522139
// Skip until start of body part.
21532140
if (Tok.is(tok::l_paren)) {
@@ -2381,7 +2368,6 @@ parseStmtCase(Parser &P, SourceLoc &CaseLoc,
23812368
auto *vNew = new (P.Context) VarDecl(
23822369
/*IsStatic*/ false, vOld->getIntroducer(),
23832370
vOld->getNameLoc(), vOld->getName(), vOld->getDeclContext());
2384-
vNew->setHasNonPatternBindingInit();
23852371
vNew->setImplicit();
23862372
Result[i] = vNew;
23872373
}

lib/SILGen/SILGenDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,6 @@ class LetValueInitialization : public Initialization {
470470
assert(!isa<ParamDecl>(vd)
471471
&& "should not bind function params on this path");
472472
if (vd->getParentPatternBinding() && !vd->getParentInitializer()) {
473-
// This value is uninitialized (and unbound) if it has a pattern binding
474-
// decl, with no initializer value.
475-
assert(!vd->hasNonPatternBindingInit() && "Bound values aren't uninit!");
476-
477473
// If this is a let-value without an initializer, then we need a temporary
478474
// buffer. DI will make sure it is only assigned to once.
479475
needsTemporaryBuffer = true;

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ namespace {
21662166
// FIXME: This should be handled in the solver, not here.
21672167
//
21682168
// Otherwise, create a new type variable.
2169-
if (!var->hasNonPatternBindingInit() &&
2169+
if (var->getParentPatternBinding() &&
21702170
!var->hasAttachedPropertyWrapper() &&
21712171
optionality != ReferenceOwnershipOptionality::Required) {
21722172
if (auto boundExpr = locator.trySimplifyToExpr()) {

lib/Sema/DerivedConformanceComparable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ deriveBodyComparable_enum_hasAssociatedValues_lt(AbstractFunctionDecl *ltDecl, v
146146
auto *vNew = new (C) VarDecl(
147147
/*IsStatic*/ false, vOld->getIntroducer(),
148148
vOld->getNameLoc(), vOld->getName(), vOld->getDeclContext());
149-
vNew->setHasNonPatternBindingInit();
150149
vNew->setImplicit();
151150
copy[i] = vNew;
152151
}

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ deriveBodyEquatable_enum_hasAssociatedValues_eq(AbstractFunctionDecl *eqDecl,
207207
auto *vNew = new (C) VarDecl(
208208
/*IsStatic*/ false, vOld->getIntroducer(),
209209
vOld->getNameLoc(), vOld->getName(), vOld->getDeclContext());
210-
vNew->setHasNonPatternBindingInit();
211210
vNew->setImplicit();
212211
copy[i] = vNew;
213212
}
@@ -732,7 +731,6 @@ deriveBodyHashable_enum_hasAssociatedValues_hashInto(
732731
auto *vNew = new (C) VarDecl(
733732
/*IsStatic*/ false, vOld->getIntroducer(),
734733
vOld->getNameLoc(), vOld->getName(), vOld->getDeclContext());
735-
vNew->setHasNonPatternBindingInit();
736734
vNew->setImplicit();
737735
copy[i] = vNew;
738736
}

0 commit comments

Comments
 (0)