leanprover / leanprover/lean4

RFC: a more robust solution to `auxDecl`

Open
#1,898 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-low RFC
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

During elaboration, recursive calls are not represented as constants (as the function is not part of the environment yet) but local variables with the auxDecl LocalDeclKind. As that is not how users think about recursive calls, there is significant work keeping up the illusion that these variables are more or less constants. Some quick examples:

Unfortunately, we cannot e.g. add these as constants as opaques to a temporary environment that is later discarded as elaboration may mutate the environment even during nested term elaboration and removing specific constants from an environment is not something we should support. Thus I propose to make recursive bindings merely logically part of the environment during elaboration, which could be done in a variety of ways:

  • Keep recursive bindings in the elaboration context, abstract direct environment access during elaboration away into monadic functions that mix in the recursive bindings
  • Keep recursive bindings in a new structure extending Environment used only during elaboration: similar to above, but works for non-monadic functions as well
  • Keep recursive bindings in a new field of Environment itself that is never accessed by the kernel, clear field at end of elaboration: not elegant, but least churn

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the issue's discussion of recursive bindings, auxDecl, elaboration, and Environment. Compare the three proposed approaches: elaboration-context integration, a temporary Environment extension, or an Environment field. Done means selecting and implementing a robust approach that avoids special cases while preserving kernel behavior, but no specific files or tests are named.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.