Files
lean4/tests/elab/doElemControlInfoAttribute.lean
Garmelon 08eb78a5b2 chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

65 lines
1.8 KiB
Lean4

import Lean
open Lean Parser Meta Elab Do
set_option backward.do.legacy false
syntax (name := myReturn) "myreturn" : doElem
@[doElem_elab myReturn] def elabMyReturn : DoElab := fun _stx dec => do
elabDoElem ( `(doElem| return 42)) dec
/--
error: No `ControlInfo` inference handler found for `myReturn` in syntax ⏎
myreturn
Register a handler with `@[doElem_control_info myReturn]`.
-/
#guard_msgs (error) in
#eval Id.run do
for i in [1, 2, 3] do
myreturn
return 0
@[doElem_control_info myReturn] def controlInfoMyReturn : ControlInfoHandler := fun _stx => do
return { numRegularExits := 0, returnsEarly := true }
/-- info: 42 -/
#guard_msgs in
#eval Id.run do
for i in [1, 2, 3] do
myreturn
return 0
syntax (name := myIf) "myif" term " then" doSeq " else" doSeq : doElem
@[doElem_elab myIf] def elabMyIf : DoElab := fun stx dec => do
let `(doElem| myif $cond:term then $thenSeq else $elseSeq) := stx | throwUnsupportedSyntax
elabDoElem ( `(doElem| if $cond then $thenSeq else $elseSeq)) dec
/--
error: No `ControlInfo` inference handler found for `myIf` in syntax ⏎
myif i > 1 then
return 23 else
continue
Register a handler with `@[doElem_control_info myIf]`.
-/
#guard_msgs (error) in
#eval Id.run do
for i in [1, 2, 3] do
myif i > 1 then return 23 else continue
return 0
@[doElem_control_info myIf] def controlInfoMyIf : ControlInfoHandler := fun stx => do
let `(doElem| myif $_:term then $thenSeq else $elseSeq) := stx | throwUnsupportedSyntax
let thenInfo inferControlInfoSeq thenSeq
let elseInfo inferControlInfoSeq elseSeq
return thenInfo.alternative elseInfo
/-- info: 26 -/
#guard_msgs in
#eval Id.run do
let mut x := 0
for i in [1, 2, 3] do
myif i > 2 then return x + 23 else x := x + i; continue
return 0