Commit graph

17 commits

Author SHA1 Message Date
Sebastian Ullrich
efc99b982e
chore: deprecate Nix-based build, remove interactive components (#4895)
Users who prefer the flake build should maintain it externally
2024-08-02 09:57:34 +00:00
Marc Huisinga
e9f69d1068
feat: partial context info (#3159)
This PR facilitates augmenting the context of an `InfoTree` with
*partial* contexts while elaborating a command. Using partial contexts,
this PR also adds support for tracking the parent declaration name of a
term in the `InfoTree`. The parent declaration name is needed to compute
the call hierarchy in #3082.

Specifically, the `Lean.Elab.InfoTree.context` constructor is refactored
to take a value of the new type `Lean.Elab.PartialContextInfo` instead
of a `Lean.Elab.ContextInfo`, which now refers to a full `InfoTree`
context. The `PartialContextInfo` is then merged into a `ContextInfo`
while traversing the tree using
`Lean.Elab.PartialContextInfo.mergeIntoOuter?`. The partial context
after executing `liftTermElabM` is stored in values of a new type
`Lean.Elab.CommandContextInfo`.

As a result of this, `Lean.Elab.ContextInfo.save` moves to
`Lean.Elab.CommandContextInfo.save`.

For obtaining the parent declaration for a term, a new typeclass
`MonadParentDecl` is introduced to save the parent declaration in
`Lean.Elab.withSaveParentDeclInfoContext`. `Lean.Elab.Term.withDeclName
x` now calls `withSaveParentDeclInfoContext x` to save the declaration
name.

### Migration

**The changes to the `InfoTree.context` constructor break backwards
compatibility with all downstream users that traverse the `InfoTree`
manually instead of going through the functions in `InfoUtils.lean`.**
To fix this, you can merge the outer `ContextInfo` in a traversal with
the `PartialContextInfo` of an `InfoTree.context` node using
`PartialContextInfo.mergeIntoOuter?`. See e.g.
`Lean.Elab.InfoTree.foldInfo` for an example:
```lean
partial def InfoTree.foldInfo (f : ContextInfo → Info → α → α) (init : α) : InfoTree → α :=
  go none init
where go ctx? a
  | context ctx t => go (ctx.mergeIntoOuter? ctx?) a t
  | node i ts =>
    let a := match ctx? with
      | none => a
      | some ctx => f ctx i a
    ts.foldl (init := a) (go <| i.updateContext? ctx?)
  | _ => a
```

Downstream users that manually save `InfoTree`s may need to adjust calls
to `ContextInfo.save` to use `CommandContextInfo.save` instead and
potentially wrap their `CommandContextInfo` in a
`PartialContextInfo.commandCtx` constructor when storing it in an
`InfoTree` or `ContextInfo.mk` when creating a full context.

### Motivation

As of now, `ContextInfo`s are always *full* contexts, constructed as if
they were always created in `liftTermElabM` after running the
`TermElabM` action. This is not strictly true; we already create
`ContextInfo`s in several places other than `liftTermElabM` and work
around the limitation that `ContextInfo`s are always full contexts in
certain places (e.g. `Info.updateContext?` is a crux that we need
because we can't always create partial contexts at the term-level), but
it has mostly worked out so far. Note that one must be very careful when
saving a `ContextInfo` in places other than `liftTermElabM` because the
context may not be as complete as we would like (e.g. it may lack
meta-variable assignments, potentially leading to a language server
panic).

Unfortunately, the parent declaration of a term is another example of a
context that cannot be provided in `liftTermElabM`: The parent
declaration is usually set via `withDeclName`, which itself lives in
`TermElabM`. So by the time we are trying to save the full
`ContextInfo`, the declaration name is already gone. There is no easy
fix for this like in the other cases where we would really just like to
augment the context with an extra field.

The refactor that we decided on to resolve the issue is to refactor the
`InfoTree` to take a `PartialContextInfo` instead of a `ContextInfo` and
have code that traverses the `InfoTree` merge inner contexts with outer
contexts to produce a full `ContextInfo` value.

### Bumps for downstream projects

- `lean-pr-testing-3159` branch at Std, not yet opened as a PR
- `lean-pr-testing-3159` branch at Mathlib, not yet opened as a PR
- https://github.com/leanprover/LeanInk/pull/57
- https://github.com/hargoniX/LeanInk/pull/1
- https://github.com/tydeu/lean4-alloy/pull/7
- https://github.com/leanprover-community/repl/pull/29

---------

Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
2024-01-22 12:34:20 +00:00
Sebastian Ullrich
f6cd6c0695 chore: Nix: cache LeanInk output 2022-12-15 13:38:46 +01:00
Gabriel Ebner
c672046767 chore: update LeanInk 2022-10-19 09:28:08 -07:00
Gabriel Ebner
f58b26b4b0 chore: update LeanInk 2022-10-11 17:24:35 -07:00
Sebastian Ullrich
185829d089 chore: update mdBook
Resolves #1421
2022-08-09 22:19:40 +02:00
Sebastian Ullrich
5e46c0865e doc: update LeanInk 2022-07-03 17:56:51 +02:00
Sebastian Ullrich
1712d0fee3 chore: update LeanInk
Resolves leanprover/LeanInk#20
2022-06-23 11:32:16 +02:00
Sebastian Ullrich
8aea00213c chore: clean up doc/flake.nix 2022-06-18 13:21:02 +02:00
Sebastian Ullrich
388ed62858 chore: update Alectryon 2022-06-07 17:14:41 +02:00
Sebastian Ullrich
3cfbdd134a fix: update Alectryon 2022-06-03 16:05:59 +02:00
Sebastian Ullrich
4a1885f997 chore: update benchmark suite 2022-05-25 18:26:36 +02:00
Sebastian Ullrich
458da0e27b chore: update LeanInk 2022-04-15 08:53:34 -07:00
Sebastian Ullrich
2aaac3f94b doc: embed examples into doc book 2022-04-06 09:06:49 -07:00
Sebastian Ullrich
4fcc7c78dd chore: update LeanInk 2022-04-02 18:13:42 +02:00
Sebastian Ullrich
282147631f chore: Nix: add LeanInk + Alectyron to docs flake 2022-03-26 22:50:04 +01:00
Sebastian Ullrich
19925f8ec1 chore: Nix: move docs build into sub-flake
workflow is not ideal right now because of poor support for sub-flakes,
but I also don't want the doc input in the main flake...
2022-03-26 22:50:04 +01:00