You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
* create a file sanity_check
Currently it contains a tactic that detects unused arguments in declarations
In the future I want to add other cleaning tactics
* fix last tactic
* update comment
* checkpoint
* checkpoint
* rewrite sanity_check
* update sanity_check
* move results to appropriate files
* move some declarations
Some declarations in tactic.core made more sense in meta.expr
tactic.core now imports string.defs (which adds very little)
add documentation
* add entry to docs/tactic.md
* fix errors
* some extra documentation
* add test
* add doc to meta.expr
/-- If `nm` is a simple name (having only one string component) starting with `_`, then `deinternalize_field nm` removes the underscore. Otherwise, it does nothing. -/
11
20
metadefdeinternalize_field : name → name
12
-
| (name.mk_string s name.anonymous) :=
21
+
| (mk_string s name.anonymous) :=
13
22
let i := s.mk_iterator in
14
23
if i.curr = '_'then i.next.next_to_string else s
15
24
| n := n
16
25
26
+
/-- `get_nth_prefix nm n` removes the last `n` components from `nm` -/
17
27
metadefget_nth_prefix : name → ℕ → name
18
28
| nm 0 := nm
19
29
| nm (n + 1) := get_nth_prefix nm.get_prefix n
20
30
31
+
/-- Auxilliary definition for `pop_nth_prefix` -/
21
32
privatemetadefpop_nth_prefix_aux : name → ℕ → name × ℕ
22
33
| anonymous n := (anonymous, 1)
23
34
| nm n := let (pfx, height) := pop_nth_prefix_aux nm.get_prefix n in
24
35
if height ≤ n then (anonymous, height + 1)
25
36
else (nm.update_prefix pfx, height + 1)
26
37
27
-
-- Pops the top `n` prefixes from the given name.
38
+
/-- Pops the top `n` prefixes from the given name. -/
28
39
metadefpop_nth_prefix (nm : name) (n : ℕ) : name :=
29
40
prod.fst $ pop_nth_prefix_aux nm n
30
41
42
+
/-- Pop the prefix of a name -/
31
43
metadefpop_prefix (n : name) : name :=
32
44
pop_nth_prefix n 1
33
45
46
+
/-- Auxilliary definition for `from_components` -/
34
47
privatedeffrom_components_aux : name → list string → name
35
48
| n [] := n
36
49
| n (s :: rest) := from_components_aux (name.mk_string s n) rest
37
50
51
+
/-- Build a name from components. For example `from_components ["foo","bar"]` becomes
52
+
``` `foo.bar``` -/
38
53
deffrom_components : list string → name :=
39
54
from_components_aux name.anonymous
40
55
41
-
-- `name`s can contain numeral pieces, which are not legal names
42
-
-- when typed/passed directly to the parser. We turn an arbitrary
43
-
--name into a legal identifier name.
56
+
/-- `name`s can contain numeral pieces, which are not legal names
57
+
when typed/passed directly to the parser. We turn an arbitrary
58
+
name into a legal identifier name by turning the numbers to strings. -/
44
59
metadefsanitize_name : name → name
45
60
| name.anonymous := name.anonymous
46
61
| (name.mk_string s p) := name.mk_string s $ sanitize_name p
47
62
| (name.mk_numeral s p) := name.mk_string sformat!"n{s}" $ sanitize_name p
48
63
64
+
/-- Append a string to the last component of a name -/
49
65
defappend_suffix : name → string → name
50
66
| (mk_string s n) s' := mk_string (s ++ s') n
51
67
| n _ := n
52
68
69
+
/-- The first component of a name, turning a number to a string -/
70
+
metadefhead : name → string
71
+
| (mk_string s anonymous) := s
72
+
| (mk_string s p) := head p
73
+
| (mk_numeral n p) := head p
74
+
| anonymous := "[anonymous]"
75
+
76
+
/-- Tests whether the first component of a name is `"_private"` -/
77
+
metadefis_private (n : name) : bool :=
78
+
n.head = "_private"
79
+
80
+
/-- Get the last component of a name, and convert it to a string. -/
81
+
metadeflast : name → string
82
+
| (mk_string s _) := s
83
+
| (mk_numeral n _) := repr n
84
+
| anonymous := "[anonymous]"
85
+
86
+
/-- Returns the number of characters used to print all the string components of a name,
87
+
including periods between name segments. Ignores numerical parts of a name. -/
88
+
metadeflength : name → ℕ
89
+
| (mk_string s anonymous) := s.length
90
+
| (mk_string s p) := s.length + 1 + p.length
91
+
| (mk_numeral n p) := p.length
92
+
| anonymous := "[anonymous]".length
93
+
53
94
end name
54
95
55
96
namespace level
56
97
98
+
/-- Tests whether a universe level is non-zero for all assignments of its variables -/
57
99
metadefnonzero : level → bool
58
100
| (succ _) := tt
59
101
| (max l₁ l₂) := l₁.nonzero || l₂.nonzero
@@ -65,48 +107,56 @@ end level
65
107
namespace expr
66
108
open tactic
67
109
110
+
/-- Turns an expression into a positive natural number, assuming it is only built up from
111
+
`has_one.one`, `bit0` and `bit1`. -/
68
112
protectedmetadefto_pos_nat : expr → option ℕ
69
113
| `(has_one.one _) := some 1
70
114
| `(bit0 %%e) := bit0 <$> e.to_pos_nat
71
115
| `(bit1 %%e) := bit1 <$> e.to_pos_nat
72
116
| _ := none
73
117
118
+
/-- Turns an expression into a natural number, assuming it is only built up from
119
+
`has_one.one`, `bit0`, `bit1` and `has_zero.zero`. -/
74
120
protectedmetadefto_nat : expr → option ℕ
75
121
| `(has_zero.zero _) := some 0
76
122
| e := e.to_pos_nat
77
123
124
+
/-- Turns an expression into a integer, assuming it is only built up from
125
+
`has_one.one`, `bit0`, `bit1`, `has_zero.zero` and a optionally a single `has_neg.neg` as head. -/
78
126
protectedmetadefto_int : expr → option ℤ
79
127
| `(has_neg.neg %%e) := do n ← e.to_nat, some (-n)
80
128
| e := coe <$> e.to_nat
81
129
82
-
metadefis_meta_var : expr → bool
130
+
/-- Tests whether an expression is a meta-variable. -/
131
+
metadefis_mvar : expr → bool
83
132
| (mvar _ _ _) := tt
84
-
| e := ff
133
+
| _ := ff
85
134
135
+
/-- Tests whether an expression is a sort. -/
86
136
metadefis_sort : expr → bool
87
137
| (sort _) := tt
88
138
| e := ff
89
139
140
+
/-- Returns a list of all local constants in an expression (without duplicates). -/
90
141
metadeflist_local_consts (e : expr) : list expr :=
91
142
e.fold [] (λ e' _ es, if e'.is_local_constant then insert e' es else es)
92
143
144
+
/-- Returns a name_set of all constants in an expression. -/
93
145
metadeflist_constant (e : expr) : name_set :=
94
146
e.fold mk_name_set (λ e' _ es, if e'.is_constant then es.insert e'.const_name else es)
95
147
148
+
/-- Returns a list of all meta-variables in an expression (without duplicates). -/
96
149
metadeflist_meta_vars (e : expr) : list expr :=
97
-
e.fold [] (λ e' _ es, if e'.is_meta_varthen insert e' es else es)
150
+
e.fold [] (λ e' _ es, if e'.is_mvarthen insert e' es else es)
98
151
152
+
/-- Returns a name_set of all constants in an expression starting with a certain prefix. -/
99
153
metadeflist_names_with_prefix (pre : name) (e : expr) : name_set :=
100
154
e.fold mk_name_set $ λ e' _ l,
101
155
match e' with
102
156
| expr.const n _ := if n.get_prefix = pre then l.insert n else l
103
157
| _ := l
104
158
end
105
159
106
-
metadefis_mvar : expr → bool
107
-
| (mvar _ _ _) := tt
108
-
| _ := ff
109
-
110
160
/--
111
161
is_num_eq n1 n2 returns true if n1 and n2 are both numerals with the same numeral structure,
112
162
ignoring differences in type and type class arguments.
0 commit comments