Skip to content

Commit e4b7e46

Browse files
committed
test: check that recusive functions do not apply attriubutes twices
I suspected a bug based on reading the code, but it seems there is no bug.
1 parent 7845a05 commit e4b7e46

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

tests/pkg/user_attr/UserAttr/BlaAttr.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ initialize fooAttr : ParametricAttribute (Nat × Bool) ←
2121
afterSet := fun declName _ => do
2222
IO.println s!"set attribute [foo] at {declName}"
2323
}
24+
25+
syntax (name := trace_add) "trace_add" : attr
26+
27+
initialize registerBuiltinAttribute {
28+
name := `trace_add
29+
descr := "Simply traces when added, to debug double-application bugs"
30+
add := fun decl _stx _kind => do
31+
logInfo m!"trace_add attribute added to {decl}"
32+
-- applicationTime := .afterCompilation
33+
}

tests/pkg/user_attr/UserAttr/Tst.lean

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,68 @@ simproc [my_simp] reduceBoo (boo _) := fun e => do
8888
example : f x + boo 2 = id (x + 2) + 12 := by
8989
simp
9090
simp [my_simp] -- Applies the simp and simproc sets
91+
92+
93+
namespace TraceAdd
94+
95+
set_option trace.Meta.Tactic.simp.rewrite false
96+
97+
/-- info: trace_add attribute added to TraceAdd.foo -/
98+
#guard_msgs in
99+
@[trace_add] def foo := 1
100+
101+
/-- info: trace_add attribute added to TraceAdd.foo -/
102+
#guard_msgs in
103+
attribute [trace_add] foo
104+
105+
/-- info: trace_add attribute added to TraceAdd.structural -/
106+
#guard_msgs in
107+
@[trace_add] def structural : Nat → Nat
108+
| 0 => 0
109+
| n+1 => structural n+1
110+
termination_by structural n => n
111+
112+
/-- info: trace_add attribute added to TraceAdd.wf -/
113+
#guard_msgs in
114+
@[trace_add] def wf : Nat → Nat
115+
| 0 => 0
116+
| n+1 => wf n+1
117+
termination_by n => n
118+
119+
/--
120+
info: trace_add attribute added to TraceAdd.mutual_structural_1
121+
---
122+
info: trace_add attribute added to TraceAdd.mutual_structural_2
123+
-/
124+
#guard_msgs in
125+
mutual
126+
@[trace_add] def mutual_structural_1 : Nat → Nat
127+
| 0 => 0
128+
| n+1 => mutual_structural_2 n+1
129+
termination_by structural n => n
130+
@[trace_add] def mutual_structural_2 : Nat → Nat
131+
| 0 => 0
132+
| n+1 => mutual_structural_1 n+1
133+
termination_by structural n => n
134+
end
135+
136+
/--
137+
info: trace_add attribute added to TraceAdd.mutual_wf_1._mutual
138+
---
139+
info: trace_add attribute added to TraceAdd.mutual_wf_1
140+
---
141+
info: trace_add attribute added to TraceAdd.mutual_wf_2
142+
-/
143+
#guard_msgs in
144+
mutual
145+
@[trace_add] def mutual_wf_1 : Nat → Nat
146+
| 0 => 0
147+
| n+1 => mutual_wf_2 n+1
148+
termination_by n => n
149+
@[trace_add] def mutual_wf_2 : Nat → Nat
150+
| 0 => 0
151+
| n+1 => mutual_wf_1 n+1
152+
termination_by n => n
153+
end
154+
155+
end TraceAdd

0 commit comments

Comments
 (0)