lean4-htt/tests/bench/big_beq.lean
Joachim Breitner 0e122870be
perf: mkNoConfusionCtors: cheaper inferType (#10455)
This PR changes `mkNoConfusionCtors` so that its use of `inferType` does
not have to reduce `noConfusionType`, to make #10315 really effective.
2025-09-19 10:51:17 +00:00

42 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean
/-!
Creates an non-recursive inductive data type with n constructors and deriving `BEq`.
-/
set_option Elab.async false
open Lean Elab
open Elab.Command (CommandElab CommandElabM elabCommand)
open Parser.Command
open Parser.Term
-- Create a name.
def strName (s : String) : Name := Name.anonymous |>.str s
def mkCtorStr (idx : Nat) : String := s!"con{idx}"
def mkCtorIdent (idx : Nat) : Ident := mkIdent <| strName <| mkCtorStr idx
/--
`#test_gen name cnt` creates an inductive type with icnt` unary constructors
-/
syntax (name := testGen) (docComment)? "#test_gen" ident num : command -- declare the syntax
@[command_elab testGen]
def testGenImpl: CommandElab := fun stx => do
match stx with
| `(#test_gen $t $con_count) =>
let con_count := con_count.getNat
let cons ← Array.ofFnM (n := con_count) fun cIdx =>
let con := mkCtorIdent cIdx
`(ctor| | $con:ident : α → $t:ident α )
let idecl ←
-- Create constant case definitions
`(inductive $t:ident (α : Type) : Type where
$cons:ctor*
deriving instance BEq for $t:ident
)
elabCommand idecl
| _ =>
throwIllFormedSyntax
#time #test_gen T 100