Skip to content

Commit 7e36060

Browse files
committed
AST: Remove VarDecl::getOpenedElementEnvironment()
1 parent 305e796 commit 7e36060

File tree

4 files changed

+5
-59
lines changed

4 files changed

+5
-59
lines changed

include/swift/AST/Decl.h

-11
Original file line numberDiff line numberDiff line change
@@ -6010,10 +6010,6 @@ enum class PropertyWrapperSynthesizedPropertyKind {
60106010
class VarDecl : public AbstractStorageDecl {
60116011
friend class NamingPatternRequest;
60126012
NamedPattern *NamingPattern = nullptr;
6013-
/// When the variable is declared in context of a for-in loop over the elements of
6014-
/// a parameter pack, this is the opened element environment of the pack expansion
6015-
/// to use as the variable's context generic environment.
6016-
GenericEnvironment *OpenedElementEnvironment = nullptr;
60176013

60186014
public:
60196015
enum class Introducer : uint8_t {
@@ -6155,13 +6151,6 @@ class VarDecl : public AbstractStorageDecl {
61556151
NamedPattern *getNamingPattern() const;
61566152
void setNamingPattern(NamedPattern *Pat);
61576153

6158-
GenericEnvironment *getOpenedElementEnvironment() const {
6159-
return OpenedElementEnvironment;
6160-
}
6161-
void setOpenedElementEnvironment(GenericEnvironment *Env) {
6162-
OpenedElementEnvironment = Env;
6163-
}
6164-
61656154
/// If this is a VarDecl that does not belong to a CaseLabelItem's pattern,
61666155
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
61676156
/// CaseLabelItem. In that case, return the first case label item of the first

lib/AST/Decl.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -7260,12 +7260,6 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
72607260
}
72617261

72627262
Type VarDecl::getTypeInContext() const {
7263-
// If the variable is declared in context of a for-in loop over the elements
7264-
// of a parameter pack, its interface type must be mapped into context using
7265-
// the opened element environment of the pack expansion.
7266-
if (auto *env = getOpenedElementEnvironment())
7267-
return GenericEnvironment::mapTypeIntoContext(env, getInterfaceType());
7268-
72697263
return getDeclContext()->mapTypeIntoContext(getInterfaceType());
72707264
}
72717265

lib/AST/GenericEnvironment.cpp

+5-8
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

-34
Original file line numberDiff line numberDiff line change
@@ -9370,35 +9370,6 @@ static std::optional<PackIterationInfo> applySolutionToForEachStmt(
93709370
std::optional<SyntacticElementTarget>(SyntacticElementTarget)>
93719371
rewriteTarget) {
93729372

9373-
// A special walker to record opened element environment for var decls in a
9374-
// for-each loop.
9375-
class Walker : public ASTWalker {
9376-
GenericEnvironment *Environment;
9377-
9378-
public:
9379-
Walker(GenericEnvironment *Environment) { this->Environment = Environment; }
9380-
9381-
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
9382-
if (isa<ForEachStmt>(S)) {
9383-
return Action::SkipNode(S);
9384-
}
9385-
return Action::Continue(S);
9386-
}
9387-
9388-
PreWalkAction walkToDeclPre(Decl *D) override {
9389-
if (auto *decl = dyn_cast<VarDecl>(D)) {
9390-
decl->setOpenedElementEnvironment(Environment);
9391-
}
9392-
if (isa<AbstractFunctionDecl>(D)) {
9393-
return Action::SkipNode();
9394-
}
9395-
if (isa<NominalTypeDecl>(D)) {
9396-
return Action::SkipNode();
9397-
}
9398-
return Action::Continue();
9399-
}
9400-
};
9401-
94029373
auto &cs = solution.getConstraintSystem();
94039374
auto *sequenceExpr = stmt->getParsedSequence();
94049375
PackExpansionExpr *expansion = cast<PackExpansionExpr>(sequenceExpr);
@@ -9412,11 +9383,6 @@ static std::optional<PackIterationInfo> applySolutionToForEachStmt(
94129383
// Simplify the pattern type of the pack expansion.
94139384
info.patternType = solution.simplifyType(info.patternType);
94149385

9415-
// Record the opened element environment for the VarDecls inside the loop
9416-
Walker forEachWalker(expansion->getGenericEnvironment());
9417-
stmt->getPattern()->walk(forEachWalker);
9418-
stmt->getBody()->walk(forEachWalker);
9419-
94209386
return info;
94219387
}
94229388

0 commit comments

Comments
 (0)