Moreover, it is incorect to save/restore the metavariable context
without saving/restoring `Term.State` fields contain metavariables
being rolled back.
The new class specifies an interface for saving and restoring the
backtrackable part of the state.
This commit also fixes a few issues.
- `commitWhen` at `LevelDefEq` was defining a checkpoint for
the `isDefEq` methods, and it affects how postponed universe
constraints are handled. However, the name suggests it is
similar to `commitWhenSome?`, and consequently it was used
in other places that had nothing to do with `isDefEq`.
So, I renamed it, and provided the generic `commitWhen` at the new
`MonadBacktrack.lean` file.
- We were restoring more state then needed in a few places.
For example, we were discarding all caches.
- At `SyntheticMVars.lean`, we were using the `Meta.commitWhenSome?`
method which does not restore the `Term.State`.
We use `nullKind` for the `group` parser combinator.
When pattern matching `nullKind` nodes, we check their arities.
So, error recovery often fails for parsers that use the `group`
combinator.
For example, we have the parser
```
def whereDecls := leading_parser "where " >> many1Indent (group (letRecDecl >> optional ";"))
```
If there is syntax error at `letRecDecl`, the node corresponding to
```
group (letRecDecl >> optional ";")
```
will contain only one child, and the pattern matching at
```
def expandWhereDecls (whereDecls : Syntax) (body : Syntax) : MacroM Syntax :=
match whereDecls with
| `(whereDecls|where $[$decls:letRecDecl $[;]?]*) => `(let rec $decls:letRecDecl,*; $body)
| _ => Macro.throwUnsupported
```
fails, and we can't elaborate the partial syntax tree for
`letRecDecl`, and auto-completion will not work there.
We address this issue by using a new kind for the `group` combinator.
The idea is to pattern match `group` as we pattern match `node`s with
proper syntax node kinds. This change is consistent with the way we
use `group` where it mainly a convenience for saving us the trouble of
defining a new parser definition that is used only once.
This kind of broken command does not have a position information, and
was producing a panic message in the server because it makes the
reasonable assumption that every command returned by `parserCommand`
has a position.