Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix recursive let for well formed check #5780

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/relay/analysis/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ class VarVisitor : protected ExprVisitor, protected PatternVisitor {
}

void VisitExpr_(const LetNode* op) final {
MarkBounded(op->var);
VisitExpr(op->value);
VisitExpr(op->body);
Expr let = GetRef<Let>(op);
while (auto let_node = let.as<LetNode>()) {
MarkBounded(let_node->var);
VisitExpr(let_node->value);
let = let_node->body;
}
VisitExpr(let);
}

void VisitPattern(const Pattern& p) final { PatternVisitor::VisitPattern(p); }
Expand Down
21 changes: 15 additions & 6 deletions src/relay/analysis/well_formed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ class WellFormedChecker : private ExprVisitor, PatternVisitor {
}

void VisitExpr_(const LetNode* l) final {
Scope s(this);
// we do letrec only for FunctionNode,
// but shadowing let in let binding is likely programming error, and we should forbidden it.
Bound(l->var);
CheckWellFormed(l->value);
CheckWellFormed(l->body);
std::vector<Scope*> scopes;
Expr let = GetRef<Let>(l);
while (auto let_node = let.as<LetNode>()) {
scopes.push_back(new Scope(this));
// we do letrec only for FunctionNode,
// but shadowing let in let binding is likely programming error, and we should forbidden it.
Bound(let_node->var);
CheckWellFormed(let_node->value);
let = let_node->body;
}
CheckWellFormed(let);
while (!scopes.empty()) {
delete scopes.back();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use unique_ptr?

scopes.pop_back();
}
}

void VisitExpr_(const FunctionNode* f) final {
Expand Down