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
[Merged by Bors] - fix(init/meta/converter/interactive): Do not ignore errors and tactic state changes in for
and find
#482
Conversation
Could you please add the other test case from #476 (comment) and copy the PR description from #476 (bors uses it in the commit message). Otherwise LGTM. bors d+ |
✌️ eric-wieser can now approve this pull request. To approve and merge a pull request, simply reply with |
Where should the passing test-cases go? |
Oh, I didn't look where you put the test case. Typically these test cases (where the error message is important) go into Some explanation here: https://github.com/leanprover-community/lean/blob/master/doc/fixing_tests.md |
bors r+ |
… state changes in `for` and `find` (#482) An example of the type of code that used to work and now fails: ```lean import algebra.ring example {a b c : ℕ} : (a * b) * c = (a * b) * c := begin conv { for (_ * _) [1] { rw this_isnt_a_lemma, -- no error message? }, }, end example {a b c : ℕ} : (a * b) * c = (a * b) * c := begin conv { find (_ * _) { rw this_isnt_a_lemma, -- no error message? }, -- error: pattern not found (not true!) }, end ``` Without this PR, users like me get no information on why their tactic failed, which is a very frustrating experience. The problem here is that `ext_simplify_core` ignores all failures in its `pre` and `post` arguments - failures are treated as "there was nothing to simplify here, move on to the next one". In `find` and `for`, we need to distinguish the cases of failing due to the pattern not matching and failuring due to an error in the user-provided tactic. This PR adds three new tactic primitives, `tactic.capture`, `tactic.unwrap`, and `tactic.resume`, the first two of which are inspired by the python functions [from the `trio-outcome` package](https://outcome.readthedocs.io/en/latest/api.html) with the same name. `capture` can be used to run the user-provided tactic and keep track of any errors that occured. `unwrap` is then used to re-throw the error once `ext_simplify_core` is done. It turns out that not only does `ext_simplify_core` ignore all failures, but it resets the tactic state after it completes - which clears populated metavariables. To preserve the tactic state, we need `resume`. --- A replacement for #476, since that PR does not have CI runs
Thanks for the review, and for pointing me towards the better fix! |
Pull request successfully merged into master. Build succeeded: |
for
and find
for
and find
An example of the type of code that used to work and now fails:
Without this PR, users like me get no information on why their tactic failed, which is a very frustrating experience.
The problem here is that
ext_simplify_core
ignores all failures in itspre
andpost
arguments - failures are treated as "there was nothing to simplify here, move on to the next one". Infind
andfor
, we need to distinguish the cases of failing due to the pattern not matching and failuring due to an error in the user-provided tactic.This PR adds three new tactic primitives,
tactic.capture
,tactic.unwrap
, andtactic.resume
, the first two of which are inspired by the python functions from thetrio-outcome
package with the same name.capture
can be used to run the user-provided tactic and keep track of any errors that occured.unwrap
is then used to re-throw the error onceext_simplify_core
is done.It turns out that not only does
ext_simplify_core
ignore all failures, but it resets the tactic state after it completes - which clears populated metavariables. To preserve the tactic state, we needresume
.A replacement for #476, since that PR does not have CI runs