feat(library/blast): improve blast type_context push/pop operations

This commit is contained in:
Leonardo de Moura 2015-11-09 13:36:49 -08:00
parent 9c364b410e
commit 973a5c4812
3 changed files with 23 additions and 18 deletions

View file

@ -87,8 +87,8 @@ class blastenv {
unsigned m_inc_depth; unsigned m_inc_depth;
class tctx : public type_context { class tctx : public type_context {
blastenv & m_benv; blastenv & m_benv;
std::vector<state> m_stack; std::vector<state::assignment_snapshot> m_stack;
public: public:
tctx(blastenv & benv): tctx(blastenv & benv):
type_context(benv.m_env, benv.m_ios, benv.m_tmp_local_generator), type_context(benv.m_env, benv.m_ios, benv.m_tmp_local_generator),
@ -199,12 +199,11 @@ class blastenv {
} }
virtual void push() { virtual void push() {
// TODO(Leo): we only need to save the assignment and metavar_decls. m_stack.push_back(m_benv.m_curr_state.save_assignment());
m_stack.push_back(m_benv.m_curr_state);
} }
virtual void pop() { virtual void pop() {
m_benv.m_curr_state = m_stack.back(); m_benv.m_curr_state.restore_assignment(m_stack.back());
m_stack.pop_back(); m_stack.pop_back();
} }

View file

@ -514,6 +514,16 @@ expr state::expand_hrefs(expr const & e, list<expr> const & hrefs) const {
return expand_hrefs_fn(*this, hrefs)(e); return expand_hrefs_fn(*this, hrefs)(e);
} }
auto state::save_assignment() -> assignment_snapshot {
return assignment_snapshot(m_uassignment, m_metavar_decls, m_eassignment);
}
void state::restore_assignment(assignment_snapshot const & s) {
m_uassignment = s.m_uassignment;
m_metavar_decls = s.m_metavar_decls;
m_eassignment = s.m_eassignment;
}
void initialize_state() { void initialize_state() {
g_prefix = new name(name::mk_internal_unique_name()); g_prefix = new name(name::mk_internal_unique_name());
} }

View file

@ -246,23 +246,19 @@ public:
void display(environment const & env, io_state const & ios) const; void display(environment const & env, io_state const & ios) const;
/** Auxiliary object for creating snapshots of the metavariable assignments.
\remark The snapshots are created (and restored) in constant time */
class assignment_snapshot { class assignment_snapshot {
state & m_state; friend class state;
uassignment m_old_uassignment; uassignment m_uassignment;
eassignment m_old_eassignment; metavar_decls m_metavar_decls;
eassignment m_eassignment;
assignment_snapshot(uassignment const & u, metavar_decls const & decls, eassignment const & e):
m_uassignment(u), m_metavar_decls(decls), m_eassignment(e) {}
public: public:
assignment_snapshot(state & s):
m_state(s),
m_old_uassignment(s.m_uassignment),
m_old_eassignment(s.m_eassignment) {}
void restore() {
m_state.m_uassignment = m_old_uassignment;
m_state.m_eassignment = m_old_eassignment;
}
}; };
assignment_snapshot save_assignment();
void restore_assignment(assignment_snapshot const & s);
void push_proof_step(proof_step const & ps) { void push_proof_step(proof_step const & ps) {
m_depth++; m_depth++;
m_proof_steps = cons(ps, m_proof_steps); m_proof_steps = cons(ps, m_proof_steps);