Documentation

Lean.Elab.ConfigEval

Configuration evaluation #

This module provides a system for constructing efficient elaborators for evaluating configuration syntaxes.

Users should import this module to ensure they have all elaborators and instances in scope.

The main interfaces are the declare_core_config_elab, declare_term_config_elab, declare_config_elab and declare_command_config_elab commands. These are macros that construct configuration elaborators from lower-level components. Metaprogram authors may choose to directly interface with the lower-level components instead.

These commands handle the common cases where

  1. your configuration type is a structure with no parameters, indices, or universes (only Type is supported);
  2. default values are self-contained and not dependent on other fields; and
  3. all fields have types that are composed from Option, List, Array, String, and inductive types in Type with no parameters or indices, whose constructor fields are similarly composed.

The macros synthesize a self-contained configuration elaboration procedure, analyzing the EvalTerm and EvalExpr instances that are currently available or automatically derivable. These are the components of the system:

The derivation procedures analyze which EvalTerm/EvalExpr instances already exist and only derive the "leaf" instances that are necessary to construct EvalTerm and EvalExpr instances. The derived instances are made private local — since configuration elaborators are meant to be self-contained, we decided not to let the additional instances be a side effect of the macros, except in the current section. The instances can be added globally by manually using the ensure_* commands.

Notes for core Lean #

Builtin elaborators should put their configuration types in, for example, Init.MetaTypes or Init.Meta.Defs so that hovers can function when nothing is imported.

Due to the flexibility of ConfigEval.foldConfigM, changing the syntax definitions for custom configurations doesn't generally lead to bootstrapping issues. Custom configuration options with a non-Term values are fine with the caveat that their use ought to be avoided in the prelude, to avoid bootstrapping issues when their syntax changes or the custom configuration elaborator changes.