Skip to content

Commit 1138bcc

Browse files
committed
[Sema] Remove generic environment tracking from StmtChecker
This is no longer necessary now that we use `mapLocalArchetypesOutOfContext` to assign depths for generic signatures involving element archetypes.
1 parent c6d1060 commit 1138bcc

File tree

8 files changed

+9
-50
lines changed

8 files changed

+9
-50
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,8 +2432,6 @@ class ConstraintSystem {
24322432
llvm::SmallDenseMap<PackElementExpr *, PackExpansionExpr *, 2>
24332433
PackElementExpansions;
24342434

2435-
llvm::SmallVector<GenericEnvironment *, 4> PackElementGenericEnvironments;
2436-
24372435
/// The set of functions that have been transformed by a result builder.
24382436
llvm::MapVector<AnyFunctionRef, AppliedBuilderTransform>
24392437
resultBuilderTransformed;

include/swift/Sema/SyntacticElementTarget.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class SyntacticElementTarget {
165165
ForEachStmt *stmt;
166166
DeclContext *dc;
167167
Pattern *pattern;
168-
GenericEnvironment *packElementEnv;
169168
ForEachStmtInfo info;
170169
} forEachPreamble;
171170

@@ -244,12 +243,10 @@ class SyntacticElementTarget {
244243
uninitializedVar.type = patternTy;
245244
}
246245

247-
SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc,
248-
GenericEnvironment *packElementEnv)
246+
SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc)
249247
: kind(Kind::forEachPreamble) {
250248
forEachPreamble.stmt = stmt;
251249
forEachPreamble.dc = dc;
252-
forEachPreamble.packElementEnv = packElementEnv;
253250
}
254251

255252
/// Form a target for the initialization of a pattern from an expression.
@@ -271,8 +268,9 @@ class SyntacticElementTarget {
271268
/// Form a target for the preamble of a for-in loop, excluding its where
272269
/// clause and body.
273270
static SyntacticElementTarget
274-
forForEachPreamble(ForEachStmt *stmt, DeclContext *dc,
275-
GenericEnvironment *packElementEnv = nullptr);
271+
forForEachPreamble(ForEachStmt *stmt, DeclContext *dc) {
272+
return {stmt, dc};
273+
}
276274

277275
/// Form a target for a property with an attached property wrapper that is
278276
/// initialized out-of-line.
@@ -550,11 +548,6 @@ class SyntacticElementTarget {
550548
return expression.initialization.patternBindingIndex;
551549
}
552550

553-
GenericEnvironment *getPackElementEnv() const {
554-
assert(isForEachPreamble());
555-
return forEachPreamble.packElementEnv;
556-
}
557-
558551
const ForEachStmtInfo &getForEachStmtInfo() const {
559552
assert(isForEachPreamble());
560553
return forEachPreamble.info;

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4936,13 +4936,6 @@ bool ConstraintSystem::generateConstraints(
49364936
}
49374937

49384938
case SyntacticElementTarget::Kind::forEachPreamble: {
4939-
4940-
// Cache the outer generic environment, if it exists.
4941-
if (target.getPackElementEnv()) {
4942-
PackElementGenericEnvironments.push_back(target.getPackElementEnv());
4943-
ASSERT(!solverState && "Need to record a change");
4944-
}
4945-
49464939
// For a for-each statement, generate constraints for the pattern, where
49474940
// clause, and sequence traversal.
49484941
auto resultTarget = generateForEachPreambleConstraints(*this, target);

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,7 @@ ConstraintSystem::getPackExpansionEnvironment(PackExpansionExpr *expr) const {
887887

888888
GenericEnvironment *ConstraintSystem::createPackExpansionEnvironment(
889889
PackExpansionExpr *expr, CanGenericTypeParamType shapeParam) {
890-
auto *contextEnv = PackElementGenericEnvironments.empty()
891-
? DC->getGenericEnvironmentOfContext()
892-
: PackElementGenericEnvironments.back();
890+
auto *contextEnv = DC->getGenericEnvironmentOfContext();
893891
auto elementSig = getASTContext().getOpenedElementSignature(
894892
contextEnv->getGenericSignature().getCanonicalSignature(), shapeParam);
895893
auto contextSubs = contextEnv->getForwardingSubstitutionMap();

lib/Sema/SyntacticElementTarget.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,6 @@ SyntacticElementTarget::forReturn(ReturnStmt *returnStmt, Type contextTy,
193193
return target;
194194
}
195195

196-
SyntacticElementTarget
197-
SyntacticElementTarget::forForEachPreamble(ForEachStmt *stmt, DeclContext *dc,
198-
GenericEnvironment *packElementEnv) {
199-
SyntacticElementTarget target(stmt, dc, packElementEnv);
200-
return target;
201-
}
202-
203196
SyntacticElementTarget SyntacticElementTarget::forPropertyWrapperInitializer(
204197
VarDecl *wrappedVar, DeclContext *dc, Expr *initializer) {
205198
SyntacticElementTarget target(initializer, dc, CTP_Initialization,

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,7 @@ bool TypeChecker::typeCheckPatternBinding(PatternBindingDecl *PBD,
871871
return hadError;
872872
}
873873

874-
bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt,
875-
GenericEnvironment *packElementEnv) {
874+
bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
876875
auto &Context = dc->getASTContext();
877876
FrontendStatsTracer statsTracer(Context.Stats, "typecheck-for-each", stmt);
878877
PrettyStackTraceStmt stackTrace(Context, "type-checking-for-each", stmt);
@@ -888,8 +887,7 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt,
888887
return true;
889888
};
890889

891-
auto target =
892-
SyntacticElementTarget::forForEachPreamble(stmt, dc, packElementEnv);
890+
auto target = SyntacticElementTarget::forForEachPreamble(stmt, dc);
893891
if (!typeCheckTarget(target))
894892
return failed();
895893

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10221022

10231023
StmtChecker(DeclContext *DC) : Ctx(DC->getASTContext()), DC(DC) { }
10241024

1025-
llvm::SmallVector<GenericEnvironment *, 4> genericSigStack;
1026-
10271025
//===--------------------------------------------------------------------===//
10281026
// Helper Functions.
10291027
//===--------------------------------------------------------------------===//
@@ -1436,28 +1434,17 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
14361434
}
14371435

14381436
Stmt *visitForEachStmt(ForEachStmt *S) {
1439-
GenericEnvironment *genericSignature =
1440-
genericSigStack.empty() ? nullptr : genericSigStack.back();
1441-
1442-
if (TypeChecker::typeCheckForEachPreamble(DC, S, genericSignature))
1437+
if (TypeChecker::typeCheckForEachPreamble(DC, S))
14431438
return nullptr;
14441439

14451440
// Type-check the body of the loop.
14461441
auto sourceFile = DC->getParentSourceFile();
14471442
checkLabeledStmtShadowing(getASTContext(), sourceFile, S);
14481443

14491444
BraceStmt *Body = S->getBody();
1450-
1451-
if (auto packExpansion =
1452-
dyn_cast<PackExpansionExpr>(S->getParsedSequence()))
1453-
genericSigStack.push_back(packExpansion->getGenericEnvironment());
1454-
14551445
typeCheckStmt(Body);
14561446
S->setBody(Body);
14571447

1458-
if (isa<PackExpansionExpr>(S->getParsedSequence()))
1459-
genericSigStack.pop_back();
1460-
14611448
return S;
14621449
}
14631450

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,7 @@ bool typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned patternNumber,
764764
/// together.
765765
///
766766
/// \returns true if a failure occurred.
767-
bool typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt,
768-
GenericEnvironment *packElementEnv);
767+
bool typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt);
769768

770769
/// Compute the set of captures for the given closure.
771770
void computeCaptures(AbstractClosureExpr *ACE);

0 commit comments

Comments
 (0)