Zulip Chat Archive

Stream: lean4

Topic: Relation between Meta/C++ typecheckers


Wojciech Nawrocki (Jul 05 2022 at 21:53):

What is the relation between the Lean.Meta typechecking functionality, and the corresponding code in the kernel? For example, there is isExprDefEq and is_def_eq which seem to be totally separate. Can we expect them to do exactly the same thing?

Arthur Paulino (Jul 05 2022 at 21:54):

cc @Gabriel Barreto

Leonardo de Moura (Jul 05 2022 at 22:08):

Wojciech Nawrocki said:

What is the relation between the Lean.Meta typechecking functionality, and the corresponding code in the kernel? For example, there is isExprDefEq and is_def_eq which seem to be totally separate. Can we expect them to do exactly the same thing?

There is one big difference: the kernel has no support for metavariables. It expects that all of them have been eliminated by the frontend.

Leonardo de Moura (Jul 05 2022 at 22:10):

The Lean.Meta version also supports features that are not relevant in the kernel. Example: smart unfolding.

Leonardo de Moura (Jul 05 2022 at 22:16):

The heuristics are also slightly different, and the kernel does not take attributes such as [reducible] into account.

Arthur Paulino (Jul 05 2022 at 22:20):

Which are the contexts of use for each of them?

Leonardo de Moura (Jul 05 2022 at 22:33):

The kernel is used to type-check fully elaborated declarations. We say it is part of the "trusted code base". Suppose one implements a buggy tactic that produces an invalid proof. The kernel will catch the mistake during type checking.
Lean.Meta is used in to implement the frontend: tactics, type inference, type class resolution, etc. The whole elaborator is based on Lean.Meta.

Wojciech Nawrocki (Jul 05 2022 at 23:03):

Thank you! Then the one worry I would have about discrepancies is if there were terms (that can go into the kernel, so metavariable-less, etc) which the Meta version accepts but the kernel rejects, or alternatively ones which Meta complains about but the kernel would be happy with.

Siddharth Bhat (Jul 05 2022 at 23:06):

@Leonardo de Moura if I may, I have a follow up question: what is the type checking algorithm used by the kernel? is it normalization-by-evaluation flavoured? If it is not NbE, what is the algorithm?

Leonardo de Moura (Jul 05 2022 at 23:45):

Wojciech Nawrocki said:

Thank you! Then the one worry I would have about discrepancies is if there were terms (that can go into the kernel, so metavariable-less, etc) which the Meta version accepts but the kernel rejects, or alternatively ones which Meta complains about but the kernel would be happy with.

This is a valid concern. If the kernel does not accept something created by Meta, we treat it as a bug. The other direction is harder to observe, at least, as a regular user.

Leonardo de Moura (Jul 05 2022 at 23:47):

Siddharth Bhat said:

Leonardo de Moura if I may, I have a follow up question: what is the type checking algorithm used by the kernel? is it normalization-by-evaluation flavoured? If it is not NbE, what is the algorithm?

The kernel type checker is very simple. There isn't any fancy algorithm there. It unfolds things lazily and uses a cache. That being said, we want to implement an efficient term normalizer in the future. The goal is to provide better support for proofs by reflection.

Mac (Jul 06 2022 at 01:44):

Wojciech Nawrocki said:

terms (that can go into the kernel, so metavariable-less, etc) which the Meta version accepts but the kernel rejects

If you ever see an error message that begins with (kernel), this is what has happened. And, as Leo mentioned, it should ideally be reported as a bug.


Last updated: Dec 20 2023 at 11:08 UTC