Skip to content

Commit 5ef7b45

Browse files
authored
doc: meta modifier (#10554)
1 parent 9f41f33 commit 5ef7b45

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Lean/Parser/Command.lean

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ def visibility :=
7272
withAntiquot (mkAntiquot "visibility" decl_name% (isPseudoKind := true)) <|
7373
«private» <|> «public»
7474
def «protected» := leading_parser "protected "
75+
/--
76+
(module system) The `meta` modifier can be applied to a `def` in order to make it available for
77+
compile-time execution, e.g. as part of a macro or tactic. Specifically, attributes such as
78+
`@[macro]` require the annotated declaration to be `meta`, and recursively a `meta` definition may
79+
only refer to other `meta` definitions unless the reference is irrelevant for compilation purposes.
80+
However, imported definitions not originally marked `meta`, such as most parts of the standard
81+
library, can be retroactively be marked so during importing to allow their use in `meta`
82+
definitions. If the metaprogramming use is local to the current module, such as through
83+
`local macro`, this can be done by `meta import`; if the metaprogram is available to other modules
84+
as well, `public meta import` is required.
85+
86+
Conversely, `meta def` makes the definition unavailable for run-time use, e.g. as part of a
87+
`lean_exe` executable generated by Lake. Thus `def`s that are not marked `meta` (nor
88+
`noncomputable`) may not refer to `meta def`s either in compilation-relevant ways. There is no way
89+
to remove the `meta` modifier retroactively. For any potential mixed use of a definition, it should
90+
be defined without `meta` and then imported with the correct modifier as needed. In particular,
91+
the same module can be `import`ed and `meta import`ed at once in order to make such regular `def`s
92+
available in both `meta` and non-`meta` `def`s.
93+
-/
94+
@[builtin_doc]
7595
def «meta» := leading_parser "meta "
7696
def «noncomputable» := leading_parser "noncomputable "
7797
def «unsafe» := leading_parser "unsafe "
@@ -92,7 +112,7 @@ All modifiers are optional, and have to come in the listed order.
92112
`nestedDeclModifiers` is the same as `declModifiers`, but attributes are printed
93113
on the same line as the declaration. It is used for declarations nested inside other syntax,
94114
such as inductive constructors, structure projections, and `let rec` / `where` definitions. -/
95-
@[builtin_doc] def declModifiers (inline : Bool) := leading_parser
115+
def declModifiers (inline : Bool) := leading_parser
96116
optional docComment >>
97117
optional (Term.«attributes» >> if inline then skip else ppDedent ppLine) >>
98118
optional visibility >>

0 commit comments

Comments
 (0)