Commit graph

20 commits

Author SHA1 Message Date
Kyle Miller
fdd5aec172
feat: better #eval command (#5627)
This refactors and improves the `#eval` command, introducing some new
features.
* Now evaluated results can be represented using `ToExpr` and pretty
printing. This means **hoverable output**. If `ToExpr` fails, it then
tries `Repr` and then `ToString`. The `eval.pp` option controls whether
or not to try `ToExpr`.
* There is now **auto-derivation** of `Repr` instances, enabled with the
`pp.derive.repr` option (default to **true**). For example:
  ```lean
  inductive Baz
    | a | b

  #eval Baz.a
  -- Baz.a
  ```
It simply does `deriving instance Repr for Baz` when there's no way to
represent `Baz`. If core Lean gets `ToExpr` derive handlers, they could
be used here as well.
* The option `eval.type` controls whether or not to include the type in
the output. For now the default is false.
* Now things like `#eval do return 2` work. It tries using
`CommandElabM`, `TermElabM`, or `IO` when the monad is unknown.
* Now there is no longer `Lean.Eval` or `Lean.MetaEval`. These each used
to be responsible for both adapting monads and printing results. The
concerns have been split into two. (1) The `MonadEval` class is
responsible for adapting monads for evaluation (it is similar to
`MonadLift`, but instances are allowed to use default data when
initializing state) and (2) finding a way to represent results is
handled separately.
* Error messages about failed instance synthesis are now more precise.
Once it detects that a `MonadEval` class applies, then the error message
will be specific about missing `ToExpr`/`Repr`/`ToString` instances.
* Fixes a bug where `Repr`/`ToString` instances can't be found by
unfolding types "under the monad". For example, this works now:
  ```lean
  def Foo := List Nat
  def Foo.mk (l : List Nat) : Foo := l
  #eval show Lean.CoreM Foo from do return Foo.mk [1,2,3]
  ```
* Elaboration errors now abort evaluation. This eliminates some
not-so-relevant error messages.
* Now evaluating a value of type `m Unit` never prints a blank message.
* Fixes bugs where evaluating `MetaM` and `CoreM` wouldn't collect log
messages.

The `run_cmd`, `run_elab`, and `run_meta` commands are now frontends for
`#eval`.
2024-10-08 20:51:46 +00:00
Kim Morrison
3a457e6ad6
chore: use #guard_msgs in run tests (#4175)
Many of our tests in `tests/lean/run/` produce output from `#eval` (or
`#check`) statements, that is then ignored.

This PR tries to capture all the useful output using `#guard_msgs`. I've
only done a cursory check that the output is still sane --- there is a
chance that some "unchecked" tests have already accumulated regressions
and this just cements them!

In the other direction, I did identify two rotten tests:
* a minor one in `setStructInstNotation.lean`, where a comment says `Set
Nat`, but `#check` actually prints `?_`. Weird?
* `CompilerProbe.lean` is generating empty output, apparently indicating
that something is broken, but I don't know the signficance of this file.

In any case, I'll ask about these elsewhere.

(This started by noticing that a recent `grind` test file had an
untested `trace_state`, and then got carried away.)
2024-05-16 00:38:31 +00:00
Leonardo de Moura
3fc226dc6d chore: fix tests 2021-09-07 19:14:30 -07:00
Leonardo de Moura
d9273786c7 chore: remove when and «unless»
They are obsolete.

cc @Kha
2021-03-20 18:52:18 -07:00
Leonardo de Moura
db9e390b4d chore: remove new_frontend from tests 2020-10-25 09:16:38 -07:00
Leonardo de Moura
c10e92b348 chore: add temporary workarounds 2020-09-30 07:05:46 -07:00
Leonardo de Moura
4ddd4c4657 chore: move more tests to new frontend 2020-09-11 10:28:00 -07:00
Leonardo de Moura
9c0bd9dd41 chore: fix tests 2020-05-26 15:05:00 -07:00
Simon Hudon
92c8773137 feat: file IO using handles 2020-01-12 08:02:48 -08:00
Leonardo de Moura
a32fd2e693 feat: implement design documented at 868a217202 2019-12-21 15:53:36 -08:00
Leonardo de Moura
fdfff29bb1 feat: expose liftLooseBVars and lowerLooseBVars 2019-12-21 08:57:11 -08:00
Leonardo de Moura
033f781724 chore: fix tests 2019-11-17 08:53:18 -08:00
Leonardo de Moura
524872d68a chore: avoid Expr constructors in tests 2019-11-14 16:54:36 -08:00
Leonardo de Moura
c768a24735 chore: mkApp => mkAppN
We are goint to use `mkApp` for creating unary applications
2019-11-14 15:44:17 -08:00
Leonardo de Moura
0193ead596 test: add corner case 2019-11-12 13:59:24 -08:00
Leonardo de Moura
28d7fe3f49 test: add etaExpanded? tests 2019-11-12 12:24:31 -08:00
Leonardo de Moura
1e065d495b feat: expose hasLooseBVar 2019-11-09 12:29:50 -08:00
Leonardo de Moura
638ceebab4 feat: helper functions 2019-11-01 17:07:26 -07:00
Leonardo de Moura
9baf91e641 feat: add Level.isEquiv 2019-10-21 10:56:59 -07:00
Leonardo de Moura
d18305297d feat: add Expr.getAppRevArgs 2019-10-21 10:49:01 -07:00