From ffc04fd7dfba592fd9db9e65428c2d1d08f56e91 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 1 Feb 2018 19:25:16 -0800 Subject: [PATCH] fix(library/tactic/smt): add temporary hack to workaround revert-all issue --- src/library/local_context.h | 9 +++++++++ src/library/tactic/revert_tactic.cpp | 13 +++++++++++++ src/library/tactic/revert_tactic.h | 3 +++ src/library/tactic/smt/smt_state.cpp | 3 ++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/library/local_context.h b/src/library/local_context.h index 472e4a72e2..1876f91355 100644 --- a/src/library/local_context.h +++ b/src/library/local_context.h @@ -118,6 +118,9 @@ class local_context { - If `freeze_local_instances` is not set, then type_context will compute local instances during initialization. This is needed to be able to elaborate parameter. + + The solution above is incompatible with the `revert-all, do something, reintroduce` + idiom. This idiom is used to implement `dsimp *` and SMT tactic. */ optional m_instance_fingerprint; friend class type_context; @@ -144,6 +147,12 @@ public: return lctx; } + /* Temporary hack to make sure we can use SMT tactic until we fix the m_instance_fingerprint issue + described above. */ + void reset_instance_fingerprint() { + m_instance_fingerprint = optional(); + } + optional get_instance_fingerprint() const { return m_instance_fingerprint; } bool empty() const { return m_idx2local_decl.empty(); } diff --git a/src/library/tactic/revert_tactic.cpp b/src/library/tactic/revert_tactic.cpp index 26072ec382..f50f2c8ae1 100644 --- a/src/library/tactic/revert_tactic.cpp +++ b/src/library/tactic/revert_tactic.cpp @@ -27,6 +27,19 @@ tactic_state revert(buffer & locals, tactic_state const & s, bool preserve return set_mctx_goals(s, mctx, cons(new_g, tail(s.goals()))); } +/* Temporary hack to make sure we can use SMT tactics until we fix the m_instance_fingerprint issue */ +tactic_state reset_instance_fingerprint(tactic_state const & s) { + lean_assert(s.goals()); + metavar_context mctx = s.mctx(); + expr mvar = head(s.goals()); + optional g = mctx.find_metavar_decl(mvar); + local_context lctx = g->get_context(); + lctx.reset_instance_fingerprint(); + expr new_mvar = mctx.mk_metavar_decl(lctx, g->get_type()); + mctx.assign(mvar, new_mvar); + return set_mctx_goals(s, mctx, cons(new_mvar, tail(s.goals()))); +} + vm_obj revert(list const & ls, tactic_state const & s, bool preserve_locals_order) { optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); diff --git a/src/library/tactic/revert_tactic.h b/src/library/tactic/revert_tactic.h index 845c41ef19..f597eb159e 100644 --- a/src/library/tactic/revert_tactic.h +++ b/src/library/tactic/revert_tactic.h @@ -16,6 +16,9 @@ tactic_state revert(buffer & hs, tactic_state const & s, bool preserve_hs_ expr revert(environment const & env, options const & opts, metavar_context & mctx, expr const & mvar, buffer & locals, bool preserve_locals_order); +// temp hack +tactic_state reset_instance_fingerprint(tactic_state const & s); + void initialize_revert_tactic(); void finalize_revert_tactic(); } diff --git a/src/library/tactic/smt/smt_state.cpp b/src/library/tactic/smt/smt_state.cpp index 1c4fe73993..282ba4182c 100644 --- a/src/library/tactic/smt/smt_state.cpp +++ b/src/library/tactic/smt/smt_state.cpp @@ -400,8 +400,9 @@ tactic_state add_em_facts(tactic_state const & ts, smt_goal & g) { vm_obj mk_smt_state(tactic_state s, smt_config const & cfg) { if (!s.goals()) return mk_no_goals_exception(s); unsigned num_reverted; + /* TODO(Leo): revert-all is an anti-idiom. See discussion at m_instance_fingerprint. */ std::tie(s, num_reverted) = revert_all(clear_recs(s)); - + s = reset_instance_fingerprint(s); smt_goal new_goal(cfg); vm_obj r = preprocess(s, cfg.m_pre_config);