Term-constructor generators #
Commands generating constructors for specification entries, either named one by one or every entry a specification module declares. They are meant to be invoked from per-theory modules, so that a user compiles only the theories and the layer they actually import.
-- in `Cvc.Untyped.Theory.BitVec`
namespace Cvc.Untyped.Term variable [Ω]
gen_untyped% from Cvc.Spec.BitVec
-- in `Cvc.Typed.Theory.BitVec`
namespace Cvc.Typed.Term open Cvc renaming Untyped.Term → T variable [Ω]
gen_typed% from Cvc.Spec.BitVec
gen_untyped% emits the sort-erased constructor, going straight to runUnsafe; gen_typed%
emits the re-typed constructor, delegating to its untyped counterpart through the alias T. The
alias keeps the generator independent of where the untyped constructors live.
Requirements on a generation site:
- both layers:
import all Cvc.Basic.Env, since the emitted bodies use the privaterunUnsafebridge; - both layers:
import all Cvc.Untyped.Core.Defs, since the term type's conversions are private; - typed only:
import all Cvc.Typed.Core.Defs, because delegation typechecks byTyped.Term αbeing definitionallyUntyped.Term, and a plainimportkeeps that body opaque; - typed only: an alias
Tbound to the untyped term namespace, as shown above.
Emitted names #
Every name the generated code refers to is built with mkIdent rather than written literally
inside a quotation. Identifiers written literally are resolved against this module's environment
at quotation time, and this module deliberately imports neither layer, so such a reference would
be emitted unresolved and fail at the generation site.
runUnsafe, the private bridge into lean-cvc5.
Equations
- Cvc.runUnsafeId = Lean.mkIdent `runUnsafe
Instances For
Equations
- Cvc.toTypId = Lean.mkIdent `Cvc.ToTyp
Instances For
Equations
- Cvc.untypedTermId = Lean.mkIdent `Cvc.Untyped.Term
Instances For
Equations
- Cvc.untypedTermsId = Lean.mkIdent `Cvc.Untyped.Terms
Instances For
Equations
- Cvc.typedTermId = Lean.mkIdent `Cvc.Typed.Term
Instances For
Equations
- Cvc.typedTermsId = Lean.mkIdent `Cvc.Typed.Terms
Instances For
on0, what an N' variant answers for no term; not hygienic, so a caller can name it.
Equations
- Cvc.on0Id = Lean.mkIdent `on0
Instances For
on1, what an N' variant answers for one term; not hygienic, so a caller can name it.
Equations
- Cvc.on1Id = Lean.mkIdent `on1
Instances For
Cvc.Srt.of, which turns a Lean index into the sort it denotes.
Equations
- Cvc.srtOfId = Lean.mkIdent `Cvc.Srt.of
Instances For
The Cvc.Srt constructor of the given name.
Equations
- Cvc.srtConId id = Lean.mkIdent (`Cvc.Srt ++ id)
Instances For
Building a sort from its element sorts #
A constructor whose sort its arguments do not fix has to be handed one. It takes the sorts of its
element type variables, never the sort of the term it builds — setEmpty takes the element
sort, exactly as Lean's own ∅ : Set α is polymorphic in α. The sort cvc5's method wants is
built from those here.
That sort is usually the result's, but not always: mkEmptySequence takes the element sort where
mkEmptySet takes the set sort, which is what an entry's tmSortOf clause records.
Emits an Env Srt expression building the sort a shape describes.
ofVar says where a type variable's sort comes from: a parameter for one the caller supplies, and
an argument's getSort for one already fixed by an argument.
Rendering shapes as Lean types #
Renders a size expression as a Nat-valued term.
Renders a sort shape as the Lean type indexing a Typed.Term.
Names are emitted fully qualified so that generation sites are free to sit in whichever namespace
suits them. arityStx is what SizeExpr.arity renders to: a literal in a fixed-arity signature,
the term array's size in an n-ary one.
Shared pieces #
The cvc5.Kind constructor a specification builds its terms with.
Instances For
Name of the n-ary variant of an operator: <id>N, or the spec's own choice.
Equations
- spec.naryId = Lean.mkIdent (spec.naryName.getD (spec.id.appendAfter "N"))
Instances For
Name of the defaulting n-ary variant of an operator, the n-ary name primed.
Equations
- spec.naryPrimeId = Lean.mkIdent ((spec.naryName.getD (spec.id.appendAfter "N")).appendAfter "'")
Instances For
Docstring for an N' variant of op: what it answers for no term and for one.
lifted wraps the unit in some; overridable mentions the on0/on1 parameters that only the
sort-erased variants take.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Docstring for the N' variant; overridable for the sort-erased one, taking on0/on1.
Equations
- spec.naryPrimeDoc overridable = spec.primeDocOf spec.id false overridable
Instances For
Name of the nullable-lifted operator: the operator's own, suffixed with ?.
Equations
- spec.liftId = Lean.mkIdent (spec.id.appendAfter "?")
Instances For
Name of the nullable-lifted n-ary operator.
Equations
- spec.liftNaryId = Lean.mkIdent ((Lean.TSyntax.getId spec.naryId).appendAfter "?")
Instances For
Name of the nullable-lifted defaulting n-ary operator.
Equations
- spec.liftNaryPrimeId = Lean.mkIdent ((Lean.TSyntax.getId spec.naryPrimeId).appendAfter "?")
Instances For
Docstring for a lifted n-ary operator.
Equations
- spec.liftNaryDoc = toString "`" ++ toString (Lean.TSyntax.getId spec.liftId) ++ toString "` over two or more terms."
Instances For
Docstring for a lifted defaulting n-ary operator; overridable as for naryPrimeDoc.
Equations
- spec.liftNaryPrimeDoc overridable = spec.primeDocOf (Lean.TSyntax.getId spec.liftId) true overridable
Instances For
The default an N' variant answers for a single term, given the unit's term.
The term itself, for an operation whose result has its arguments' sort (addN' #[t] is t); the
unit for a relation (equalN' #[t] is true), whose single term has the wrong sort.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An integer unit as a sort-erased term at the sort of type, an arithmetic Lean type.
The sort-erased N' variants build their unit with mkInt, having no sort to go by; the typed ones
know theirs, and pass the unit at it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a docComment node from a docstring.
Equations
- Cvc.mkDocComment s = Lean.mkNode `Lean.Parser.Command.docComment #[Lean.mkAtom "/--", Lean.mkAtom (s ++ " -/")]
Instances For
Looks a specification up, failing with a located error if it is not registered.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Untyped generation #
Emits the sort-erased constructors for one specification entry.
Every argument and the result erase to Untyped.Term, so the shapes play no part beyond fixing
the arity: a pure operator kind infers its sort from its arguments, which op% checks.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Nullable lifting, sort-erased #
nullable.lift applies an operator to the values inside its nullable arguments, answering none
unless every one of them is some. It takes a Kind and the terms, so the lifted body is shorter
than the plain one — there is no sort to build and no Op to make.
Arity is right by construction here, which it would not be if a Kind were exposed to a caller:
cvc5 validates nothing, and mkNullableLift .NOT #[x, y] cheerfully builds the malformed
(nullable.lift (lambda (a b) (not a b)) x y). Generating from the specification means the
argument count and the n-ary form both come from the entry that already knows them.
Emits the sort-erased nullable-lifted constructors for one entry, if it has any.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emits the sort-erased lifted constructors for one entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the sort-erased lifted constructors for the named entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the sort-erased lifted constructors for every entry a module declares.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
DSL grammar generation #
The smtTerm grammar rule of an operator is emitted alongside its untyped constructor,
and only there: the typed constructors delegate to the untyped ones, so a typed theory module
always imports its untyped counterpart and inherits the grammar. Emitting from both layers would
declare the same rule twice.
Rules are named smtOp.<shape>.<id>, which under the enclosing namespace becomes
…Term.smtOp.binary.and and so on. Cvc.Ext.expandSmt dispatches on those trailing
three components, so it needs no knowledge of where generation happened.
Name of an operator's generated grammar rule, relative to the generation site's namespace.
Equations
- Cvc.smtRuleId shape id = Lean.mkIdent (`smtOp ++ shape ++ id)
Instances For
Emits the smtTerm grammar rules for one specification entry's notation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emits the sort-erased constructors, and the DSL grammar, for one entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the sort-erased constructors for the named specification entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the sort-erased constructors for every entry a specification module declares.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Typed generation #
Emits the binders a typed constructor needs: type, size, Ord and refinement classes.
A type variable carrying refinement classes also gets a ToTyp binder, since a refinement such as
IsArith is stated over the variable's Typ and so takes ToTyp as an instance argument.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emits the re-typed constructors for one specification entry, delegating to the untyped ones.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emits the re-typed constructors for one entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the re-typed constructors for the named specification entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the re-typed constructors for every entry a specification module declares.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Nullable lifting, typed #
Every term argument and the result gain an Option; everything else is the plain operator's
signature unchanged — type and size variables, Ord binders, and the refinement classes. The body
delegates, as the plain typed constructors do.
Option (Option α) needs no special case: add? at α := Option Int would demand
IsArith (Option Int), and no such instance exists.
Emits the re-typed nullable-lifted constructors for one entry, if it has any.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emits the re-typed lifted constructors for one entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the re-typed lifted constructors for the named entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generates the re-typed lifted constructors for every entry a module declares.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.