lean4-htt/tests/lean/run/computedFields.lean
Kim Morrison 3a457e6ad6
chore: use #guard_msgs in run tests (#4175)
Many of our tests in `tests/lean/run/` produce output from `#eval` (or
`#check`) statements, that is then ignored.

This PR tries to capture all the useful output using `#guard_msgs`. I've
only done a cursory check that the output is still sane --- there is a
chance that some "unchecked" tests have already accumulated regressions
and this just cements them!

In the other direction, I did identify two rotten tests:
* a minor one in `setStructInstNotation.lean`, where a comment says `Set
Nat`, but `#check` actually prints `?_`. Weird?
* `CompilerProbe.lean` is generating empty output, apparently indicating
that something is broken, but I don't know the signficance of this file.

In any case, I'll ask about these elsewhere.

(This started by noticing that a recent `grind` test file had an
untested `trace_state`, and then got carried away.)
2024-05-16 00:38:31 +00:00

68 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.

inductive Exp
| hole
| var (i : UInt32)
| app (a b : Exp)
with
/-- Computes the hash -/ @[simp, computed_field] protected hash : Exp → UInt64
| .var i => Hashable.hash i
| .app a b => mixHash a.hash b.hash
| .hole => 32
def dagLikeTerm : Nat → Exp
| 0 => .app (.var 42) .hole
| n+1 => .app (dagLikeTerm n) (dagLikeTerm n)
#guard (dagLikeTerm 1000).hash == 10432648428259852868 -- memoized
def varNum? : Exp → Option UInt32
| .var i => i
| _ => none
example : varNum? (.var 32) = some 32 := by native_decide
namespace WithIndices
inductive B.C (α : Type u) : Nat → Type u
| a : C α 0
| b (c : C α n) {d : C α (n-1)} : C α (n+1)
with
@[computed_field] hash : ∀ α i, C α i → UInt64
| _, _, .a => 1
| _, _, .b c => 42 + c.hash
#guard (B.C.b (α := Nat) (.a) (d := .a)).hash == 43
end WithIndices
namespace Mutual
mutual
inductive A
| a (b : B)
| b (b : B)
with
@[computed_field] f : A → Nat
| .a c => 32 + c.f
| .b c => 42 + 2*c.f
inductive B
| c (a : A)
| d
with
@[computed_field] f : B → Nat
| .c a => a.f
| .d => 0
end
#guard (B.c (.a .d)).f == 32
end Mutual