fix(kernel/metavar): wierd memory leak that only happens when compiling with clang++

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-05-01 12:55:55 -07:00
parent 9452d164ec
commit 027614cebb
4 changed files with 19 additions and 23 deletions

View file

@ -93,18 +93,6 @@ substitution substitution::assign(name const & m, level const & l) const {
return assign(m, l, justification()); return assign(m, l, justification());
} }
void substitution::for_each(std::function<void(name const & n, expr const & e, justification const & j)> const & fn) const {
m_expr_subst.for_each([=](name const & n, std::pair<expr, justification> const & a) {
fn(n, a.first, a.second);
});
}
void substitution::for_each(std::function<void(name const & n, level const & e, justification const & j)> const & fn) const {
m_level_subst.for_each([=](name const & n, std::pair<level, justification> const & a) {
fn(n, a.first, a.second);
});
}
std::pair<level, justification> substitution::d_instantiate_metavars(level const & l, bool use_jst, bool updt) { std::pair<level, justification> substitution::d_instantiate_metavars(level const & l, bool use_jst, bool updt) {
if (!has_param(l)) if (!has_param(l))
return mk_pair(l, justification()); return mk_pair(l, justification());

View file

@ -47,8 +47,15 @@ public:
substitution assign(name const & m, level const & t, justification const & j) const; substitution assign(name const & m, level const & t, justification const & j) const;
substitution assign(name const & m, level const & t) const; substitution assign(name const & m, level const & t) const;
void for_each(std::function<void(name const & n, expr const & e, justification const & j)> const & fn) const; template<typename F>
void for_each(std::function<void(name const & n, level const & e, justification const & j)> const & fn) const; void for_each_expr(F && fn) const {
for_each(m_expr_subst, [=](name const & n, std::pair<expr, justification> const & a) { fn(n, a.first, a.second); });
}
template<typename F>
void for_each_level(F && fn) const {
for_each(m_level_subst, [=](name const & n, std::pair<level, justification> const & a) { fn(n, a.first, a.second); });
}
bool is_assigned(expr const & m) const { lean_assert(is_metavar(m)); return is_expr_assigned(mlocal_name(m)); } bool is_assigned(expr const & m) const { lean_assert(is_metavar(m)); return is_expr_assigned(mlocal_name(m)); }
opt_expr_jst get_assignment(expr const & m) const { lean_assert(is_metavar(m)); return get_expr_assignment(mlocal_name(m)); } opt_expr_jst get_assignment(expr const & m) const { lean_assert(is_metavar(m)); return get_expr_assignment(mlocal_name(m)); }

View file

@ -46,13 +46,14 @@ void display_assumptions(std::ostream & out, justification const & j) {
} }
static std::ostream & operator<<(std::ostream & out, substitution const & s) { static std::ostream & operator<<(std::ostream & out, substitution const & s) {
bool first = true; // bool first = true;
s.for_each([&](name const & n, expr const & v, justification const & j) { // s.for_each([&](name const & n, expr const & v, justification const & j) {
if (first) first = false; else out << "\n"; // if (first) first = false; else out << "\n";
out << "?" << n << " <- " << v << " {"; // out << "?" << n << " <- " << v << " {";
display_assumptions(out, j); // display_assumptions(out, j);
out << "}"; // out << "}";
}); // });
s.for_each_expr([](name const &, expr const &, justification const &) {});
return out; return out;
} }

View file

@ -62,7 +62,7 @@ public:
ref operator[](K const & k) { return ref(*this, k); } ref operator[](K const & k) { return ref(*this, k); }
template<typename F> template<typename F>
void for_each(F f) const { void for_each(F && f) const {
auto f_prime = [&](entry const & e) { f(e.first, e.second); }; auto f_prime = [&](entry const & e) { f(e.first, e.second); };
return m_map.for_each(f_prime); return m_map.for_each(f_prime);
} }
@ -90,7 +90,7 @@ rb_map<K, T, CMP> erase(rb_map<K, T, CMP> const & m, K const & k) {
return r; return r;
} }
template<typename K, typename T, typename CMP, typename F> template<typename K, typename T, typename CMP, typename F>
void for_each(rb_map<K, T, CMP> const & m, F f) { void for_each(rb_map<K, T, CMP> const & m, F && f) {
return m.for_each(f); return m.for_each(f);
} }
void open_rb_map(lua_State * L); void open_rb_map(lua_State * L);