Skip to content

Commit a7ca25a

Browse files
committed
refactor: move truncateAnchors
1 parent effde06 commit a7ca25a

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/Lean/Elab/Tactic/Grind/Show.lean

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,33 +165,6 @@ def pushIfSome (msgs : Array MessageData) (msg? : Option MessageData) : Array Me
165165
logInfo <| MessageData.trace { cls := `grind, collapsed := false } "Grind state" msgs
166166
| _ => throwUnsupportedSyntax
167167

168-
def truncateAnchors (es : Array (UInt64 × α)) : Array (UInt64 × α) × Nat :=
169-
go 4
170-
where
171-
go (numDigits : Nat) : Array (UInt64 × α) × Nat := Id.run do
172-
if 4*numDigits < 64 then
173-
let shift := 64 - 4*numDigits
174-
let mut found : Std.HashSet UInt64 := {}
175-
let mut result := #[]
176-
for (a, e) in es do
177-
let a' := a >>> shift.toUInt64
178-
if found.contains a' then
179-
return (← go (numDigits+1))
180-
else
181-
found := found.insert a'
182-
result := result.push (a', e)
183-
return (result, numDigits)
184-
else
185-
return (es, numDigits)
186-
termination_by 64 - 4*numDigits
187-
188-
def anchorToString (numDigits : Nat) (anchor : UInt64) : String :=
189-
let cs := Nat.toDigits 16 anchor.toNat
190-
let n := cs.length
191-
let zs := List.replicate (numDigits - n) '0'
192-
let cs := zs ++ cs
193-
cs.asString
194-
195168
@[builtin_grind_tactic showSplits] def evalShowSplits : GrindTactic := fun stx => withMainContext do
196169
match stx with
197170
| `(grind| show_splits $[$filter?]?) =>

src/Lean/Meta/Tactic/Grind/Anchor.lean

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,24 @@ public def isAnchorPrefix (numHexDigits : Nat) (anchorPrefix : UInt64) (anchor :
8787
let shift := 64 - numHexDigits.toUInt64*4
8888
anchorPrefix == anchor >>> shift
8989

90+
public def truncateAnchors (es : Array (UInt64 × α)) : Array (UInt64 × α) × Nat :=
91+
go 4
92+
where
93+
go (numDigits : Nat) : Array (UInt64 × α) × Nat := Id.run do
94+
if 4*numDigits < 64 then
95+
let shift := 64 - 4*numDigits
96+
let mut found : Std.HashSet UInt64 := {}
97+
let mut result := #[]
98+
for (a, e) in es do
99+
let a' := a >>> shift.toUInt64
100+
if found.contains a' then
101+
return (← go (numDigits+1))
102+
else
103+
found := found.insert a'
104+
result := result.push (a', e)
105+
return (result, numDigits)
106+
else
107+
return (es, numDigits)
108+
termination_by 64 - 4*numDigits
109+
90110
end Lean.Meta.Grind

0 commit comments

Comments
 (0)