Skip to content

Commit b118504

Browse files
authored
chore: remove cbv at from sym => mode and fix the transparency level for projections (#14030)
This PR removes the hypothesis rewriting functionality of `cbv` (introduced using `cbv at` syntax) in the `Sym` mode. Additionally, this PR fixes the transparency level when dealing with projections in `cbv`.
1 parent 75ece25 commit b118504

4 files changed

Lines changed: 26 additions & 36 deletions

File tree

src/Init/Grind/Interactive.lean

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,11 @@ It reduces terms by unfolding definitions using their defining equations and
347347
applying matcher equations. The unfolding is propositional, so `cbv` also works
348348
with functions defined via well-founded recursion or partial fixpoints.
349349
350-
`cbv` reduces the goal type (and optionally hypothesis types) using call-by-value
351-
evaluation. For equation goals (`lhs = rhs`), `cbv` automatically attempts `refl`
352-
after reduction to close the goal.
350+
`cbv` reduces the goal target using call-by-value evaluation. For equation goals
351+
(`lhs = rhs`), `cbv` automatically attempts `refl` after reduction to close the goal.
353352
354-
`cbv` supports the standard `at` location syntax:
355-
- `cbv` — reduce the goal target
356-
- `cbv at h` — reduce hypothesis `h`
357-
- `cbv at h |-` — reduce hypothesis `h` and the goal target
358-
- `cbv at *` — reduce all non-dependent propositional hypotheses and the goal target
353+
Unlike the standalone `cbv` tactic, this variant does not support the `at` location
354+
syntax: in `sym =>` mode it only reduces the goal target.
359355
360356
`cbv` is not a finishing tactic in general: it may leave a new (simpler) goal.
361357
@@ -365,6 +361,6 @@ generator.
365361
366362
This is a variant of `cbv` that only works in `sym =>` mode.
367363
-/
368-
syntax (name := symCbv) "cbv" (location)? : grind
364+
syntax (name := symCbv) "cbv" : grind
369365
end Grind
370366
end Lean.Parser.Tactic

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,11 @@ def elabDSimpVariant (variantName : Name) (args : DSimpArgs) : GrindTacticM (Sym
295295
goal.mvarId.assign mvarNew
296296
replaceMainGoal [{ goal with mvarId := mvarNew.mvarId! }]
297297

298-
/-- Resolve the hypothesis identifiers of a `cbv at` location to `FVarId`s. -/
299-
private def resolveLocFVarIds (hyps : Array Syntax) : GrindTacticM (Array FVarId) := do
300-
let lctx ← getLCtx
301-
hyps.mapM fun hyp => do
302-
let some decl := lctx.findFromUserName? hyp.getId
303-
| throwError "unknown hypothesis `{hyp}`"
304-
return decl.fvarId
305-
306-
@[builtin_grind_tactic Parser.Tactic.Grind.symCbv] def evalSymCbv : GrindTactic := fun stx => withMainContext do
298+
@[builtin_grind_tactic Parser.Tactic.Grind.symCbv] def evalSymCbv : GrindTactic := fun _ => withMainContext do
307299
ensureSym
308300
let goal ← getMainGoal
309-
let (fvarIds, simplifyTarget) ← match expandOptLocation stx[1] with
310-
| .targets hyps simplifyTarget => pure (← resolveLocFVarIds hyps, simplifyTarget)
311-
| .wildcard => pure (← goal.mvarId.getNondepPropHyps, true)
312301
let result ← liftGrindM <|
313-
Lean.Meta.Tactic.Cbv.cbvGoalCore goal.mvarId simplifyTarget fvarIds
302+
Lean.Meta.Tactic.Cbv.cbvGoalCore goal.mvarId
314303
match result with
315304
| none => replaceMainGoal []
316305
| some mvarId => replaceMainGoal [{ goal with mvarId }]

src/Lean/Meta/Tactic/Cbv/Main.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def handleProj : Simproc := fun e => do
205205
let res ← simp struct
206206
match res with
207207
| .rfl _ cd =>
208-
let some reduced ← withCbvOpaqueGuard <| reduceProj? <| .proj typeName idx struct | do
208+
let some reduced ← withCbvOpaqueGuard <| withDefault <| reduceProj? <| .proj typeName idx struct | do
209209
return .rfl (done := true) cd
210210

211211
let reduced ← Sym.share reduced
@@ -223,7 +223,7 @@ def handleProj : Simproc := fun e => do
223223
return .step (← Lean.Expr.updateProjS! e e') newProof cd
224224
else
225225
-- If the type of the projection function is dependent, we first try to reduce the projection
226-
let reduced ← withCbvOpaqueGuard <| reduceProj? e
226+
let reduced ← withCbvOpaqueGuard <| withDefault <| reduceProj? e
227227
match reduced with
228228
| .some reduced =>
229229
let reduced ← Sym.share reduced

tests/elab/sym_cbv.lean

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ example (h : a = 8) : Nat.succ 7 = a := by
99
cbv
1010
exact h.symm
1111

12-
example (h : Nat.succ 7 = a) : 8 = a := by
13-
sym =>
14-
cbv at h
15-
exact h
16-
17-
example (h : Nat.succ 7 = a) : Nat.succ 7 = a := by
18-
sym =>
19-
cbv at h ⊢
20-
exact h
12+
example :
13+
have v :=
14+
BitVec.ofNat 64 ((BitVec.ofNat (64 - 0) ((BitVec.setWidth 64 (Int64.toBitVec 2)).toNat >>> 0)).toNat >>> 0) - 1;
15+
have v_1 := BitVec.ofNat 64 ((BitVec.ofNat (64 - 0) (v.toNat >>> 0)).toNat >>> 0) - 1;
16+
v ≠ v_1
17+
:= by
18+
cbv
19+
intro hyp
20+
trivial
2121

22-
example (h : Nat.succ 7 = a) : Nat.succ 7 = a := by
22+
example :
23+
have v :=
24+
BitVec.ofNat 64 ((BitVec.ofNat (64 - 0) ((BitVec.setWidth 64 (Int64.toBitVec 2)).toNat >>> 0)).toNat >>> 0) - 1;
25+
have v_1 := BitVec.ofNat 64 ((BitVec.ofNat (64 - 0) (v.toNat >>> 0)).toNat >>> 0) - 1;
26+
v ≠ v_1
27+
:= by
2328
sym =>
24-
cbv at *
25-
exact h
29+
cbv
30+
intro hyp

0 commit comments

Comments
 (0)