Skip to content

Commit 02caf18

Browse files
committed
AST: Remove VarDecl::getOpenedElementEnvironment()
1 parent 5158443 commit 02caf18

File tree

4 files changed

+5
-59
lines changed

4 files changed

+5
-59
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6053,10 +6053,6 @@ enum class PropertyWrapperSynthesizedPropertyKind {
60536053
class VarDecl : public AbstractStorageDecl {
60546054
friend class NamingPatternRequest;
60556055
NamedPattern *NamingPattern = nullptr;
6056-
/// When the variable is declared in context of a for-in loop over the elements of
6057-
/// a parameter pack, this is the opened element environment of the pack expansion
6058-
/// to use as the variable's context generic environment.
6059-
GenericEnvironment *OpenedElementEnvironment = nullptr;
60606056

60616057
public:
60626058
enum class Introducer : uint8_t {
@@ -6195,13 +6191,6 @@ class VarDecl : public AbstractStorageDecl {
61956191
NamedPattern *getNamingPattern() const;
61966192
void setNamingPattern(NamedPattern *Pat);
61976193

6198-
GenericEnvironment *getOpenedElementEnvironment() const {
6199-
return OpenedElementEnvironment;
6200-
}
6201-
void setOpenedElementEnvironment(GenericEnvironment *Env) {
6202-
OpenedElementEnvironment = Env;
6203-
}
6204-
62056194
/// If this is a VarDecl that does not belong to a CaseLabelItem's pattern,
62066195
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
62076196
/// CaseLabelItem. In that case, return the first case label item of the first

lib/AST/Decl.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7286,12 +7286,6 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
72867286
}
72877287

72887288
Type VarDecl::getTypeInContext() const {
7289-
// If the variable is declared in context of a for-in loop over the elements
7290-
// of a parameter pack, its interface type must be mapped into context using
7291-
// the opened element environment of the pack expansion.
7292-
if (auto *env = getOpenedElementEnvironment())
7293-
return GenericEnvironment::mapTypeIntoContext(env, getInterfaceType());
7294-
72957289
return getDeclContext()->mapTypeIntoContext(getInterfaceType());
72967290
}
72977291

lib/AST/GenericEnvironment.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,12 @@ Type GenericEnvironment::mapTypeIntoContext(GenericEnvironment *env,
416416
}
417417

418418
Type MapTypeOutOfContext::operator()(SubstitutableType *type) const {
419-
auto archetype = cast<ArchetypeType>(type);
420-
if (isa<OpaqueTypeArchetypeType>(archetype->getRoot()))
421-
return Type();
422-
423-
// Leave opened archetypes alone; they're handled contextually.
424-
if (isa<OpenedArchetypeType>(archetype))
425-
return Type(type);
419+
if (isa<PrimaryArchetypeType>(type) ||
420+
isa<PackArchetypeType>(type)) {
421+
return cast<ArchetypeType>(type)->getInterfaceType();
422+
}
426423

427-
return archetype->getInterfaceType();
424+
return type;
428425
}
429426

430427
Type TypeBase::mapTypeOutOfContext() {

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9411,35 +9411,6 @@ static std::optional<PackIterationInfo> applySolutionToForEachStmt(
94119411
std::optional<SyntacticElementTarget>(SyntacticElementTarget)>
94129412
rewriteTarget) {
94139413

9414-
// A special walker to record opened element environment for var decls in a
9415-
// for-each loop.
9416-
class Walker : public ASTWalker {
9417-
GenericEnvironment *Environment;
9418-
9419-
public:
9420-
Walker(GenericEnvironment *Environment) { this->Environment = Environment; }
9421-
9422-
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
9423-
if (isa<ForEachStmt>(S)) {
9424-
return Action::SkipNode(S);
9425-
}
9426-
return Action::Continue(S);
9427-
}
9428-
9429-
PreWalkAction walkToDeclPre(Decl *D) override {
9430-
if (auto *decl = dyn_cast<VarDecl>(D)) {
9431-
decl->setOpenedElementEnvironment(Environment);
9432-
}
9433-
if (isa<AbstractFunctionDecl>(D)) {
9434-
return Action::SkipNode();
9435-
}
9436-
if (isa<NominalTypeDecl>(D)) {
9437-
return Action::SkipNode();
9438-
}
9439-
return Action::Continue();
9440-
}
9441-
};
9442-
94439414
auto &cs = solution.getConstraintSystem();
94449415
auto *sequenceExpr = stmt->getParsedSequence();
94459416
PackExpansionExpr *expansion = cast<PackExpansionExpr>(sequenceExpr);
@@ -9453,11 +9424,6 @@ static std::optional<PackIterationInfo> applySolutionToForEachStmt(
94539424
// Simplify the pattern type of the pack expansion.
94549425
info.patternType = solution.simplifyType(info.patternType);
94559426

9456-
// Record the opened element environment for the VarDecls inside the loop
9457-
Walker forEachWalker(expansion->getGenericEnvironment());
9458-
stmt->getPattern()->walk(forEachWalker);
9459-
stmt->getBody()->walk(forEachWalker);
9460-
94619427
return info;
94629428
}
94639429

0 commit comments

Comments
 (0)