Skip to content

Commit 01f203a

Browse files
committed
[Constraint system] Sink Expr::getDepthMap() into its one client.
NFC. It'll be easier to refactor this when it's not an API on Expr.
1 parent 4c2a7bf commit 01f203a

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,6 @@ class alignas(8) Expr {
530530
/// the parent map.
531531
llvm::DenseMap<Expr *, Expr *> getParentMap();
532532

533-
/// Produce a mapping from each subexpression to its depth and parent,
534-
/// in the root expression. The root expression has depth 0, its children have
535-
/// depth 1, etc.
536-
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> getDepthMap();
537-
538533
/// Produce a mapping from each expression to its index according to a
539534
/// preorder traversal of the expressions. The parent has index 0, its first
540535
/// child has index 1, its second child has index 2 if the first child is a

lib/AST/Expr.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -721,34 +721,6 @@ llvm::DenseMap<Expr *, Expr *> Expr::getParentMap() {
721721
return parentMap;
722722
}
723723

724-
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> Expr::getDepthMap() {
725-
class RecordingTraversal : public ASTWalker {
726-
public:
727-
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> &DepthMap;
728-
unsigned Depth = 0;
729-
730-
explicit RecordingTraversal(
731-
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> &depthMap)
732-
: DepthMap(depthMap) {}
733-
734-
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
735-
DepthMap[E] = {Depth, Parent.getAsExpr()};
736-
Depth++;
737-
return { true, E };
738-
}
739-
740-
Expr *walkToExprPost(Expr *E) override {
741-
Depth--;
742-
return E;
743-
}
744-
};
745-
746-
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> depthMap;
747-
RecordingTraversal traversal(depthMap);
748-
walk(traversal);
749-
return depthMap;
750-
}
751-
752724
llvm::DenseMap<Expr *, unsigned> Expr::getPreorderIndexMap() {
753725
class RecordingTraversal : public ASTWalker {
754726
public:

lib/Sema/ConstraintSystem.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,46 @@ ExpressionTimer::~ExpressionTimer() {
7373
.highlight(E->getSourceRange());
7474
}
7575

76+
/// Extend the given depth map by adding depths for all of the subexpressions
77+
/// of the given expression.
78+
static void extendDepthMap(
79+
Expr *expr,
80+
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> &depthMap) {
81+
class RecordingTraversal : public ASTWalker {
82+
public:
83+
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> &DepthMap;
84+
unsigned Depth = 0;
85+
86+
explicit RecordingTraversal(
87+
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> &depthMap)
88+
: DepthMap(depthMap) {}
89+
90+
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
91+
DepthMap[E] = {Depth, Parent.getAsExpr()};
92+
Depth++;
93+
return { true, E };
94+
}
95+
96+
Expr *walkToExprPost(Expr *E) override {
97+
Depth--;
98+
return E;
99+
}
100+
};
101+
102+
RecordingTraversal traversal(depthMap);
103+
expr->walk(traversal);
104+
}
105+
76106
ConstraintSystem::ConstraintSystem(DeclContext *dc,
77107
ConstraintSystemOptions options,
78108
Expr *expr)
79109
: Context(dc->getASTContext()), DC(dc), Options(options),
80110
Arena(dc->getASTContext(), Allocator),
81111
CG(*new ConstraintGraph(*this))
82112
{
83-
if (expr)
84-
ExprWeights = expr->getDepthMap();
113+
if (expr) {
114+
extendDepthMap(expr, ExprWeights);
115+
}
85116

86117
assert(DC && "context required");
87118
}

0 commit comments

Comments
 (0)