`vcgen`: spec lemmas never apply when the spec's value type is a dependent application `T r` of a rule premise
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- tooling
Research direction
Start with the self-contained reproducer in the issue and the vcgen spec-application path, especially applySpec; compare how it unifies the spec value type with the goal against how it unifies the program. Run the reproducer and its non-dependent control to confirm the failure and expected behavior. Done means the dependent spec applies after the program determines its rule premise, with both result-type phrasings working.
Written by the indexing model from the issue text.
Description
Description
A @[spec] lemma for a program whose result type is a type-family application T r, with r universally quantified in the lemma, is found as a candidate but never applies:
error: No spec applicable to program readReg R.a in monad EStateM PUnit St.
Candidates were [SpecProof.global readReg_spec].
Self-contained reproducer (also in Repro.lean, which contains a passing non-dependent control with the identical proof shape):
import Std.Tactic.Do
import Std.WP
import Std.Data.ExtDHashMap
open Std.WP Lean.Order
set_option experimental.vcgen true
inductive R where | a | b deriving DecidableEq, Hashable
abbrev T : R → Type | .a => Nat | .b => Bool
structure St where
regs : Std.ExtDHashMap R T
abbrev M := EStateM Unit St
def resultPost {σ α ε : Type} (Q : α → σ → Prop) (E : ε → σ → Prop) :
EStateM.Result ε σ α → Prop
| .ok a s => Q a s
| .error e s => E e s
def readReg (r : R) : M (T r) := do
let .some v := (← get).regs.get? r
| throw ()
pure v
@[spec] theorem readReg_spec (r : R) (Q : T r → St → Prop) (E : Unit → St → Prop) :
Triple (readReg r) (fun s => resultPost Q E (readReg r s)) Q E := by
constructor
intro s h
cases hres : readReg r s <;>
simp_all [wp, WP.trans, Lean.Order.PredTrans.apply_mk, resultPost]
-- on v4.35.0: simp_all [wp, WP.wpTrans, resultPost]
example : ⦃fun s => s.regs.get? R.a = some (0 : Nat)⦄
(readReg R.a)
⦃fun v _ => v = (0 : Nat)⦄ := by
vcgen -- No spec applicable to program readReg R.a
all_goals simp_all [readReg, resultPost, bind, EStateM.bind, get, getThe,
MonadState.get, MonadStateOf.get, EStateM.get, throw, throwThe,
MonadExceptOf.throw, EStateM.throw, pure, EStateM.pure]
The same file with value type Nat instead of T r (the readNat control in Repro.lean) applies and closes.
Analysis
The goal's Triple/wp carries the reduced value type (Nat): with T an abbrev this always happens at elaboration; with a non-reducible def T it happens whenever the call site forces the reduced type, e.g. a postcondition fun v _ => v = (0 : Nat). The spec's value type is T ?r. Spec application appears to attempt T ?r =?= Nat before the program unification (readReg ?r =?= readReg R.a) that would determine ?r := R.a, and T ?r =?= Nat cannot be solved by inversion, so applySpec gives up.
Consistent with this, with def T the example applies when the postcondition is phrased type-preservingly (through val : (r : R) → T r, keeping the goal's value type T R.a), and fails with the (0 : Nat) phrasing. Unifying the program first would make both phrasings work.
The Std.Do/mvcgen machinery applies the analogous spec in all phrasings.
Context
The shape comes from Sail's Lean backend (https://github.com/rems-project/lean-sail): generated ISA semantics use a register file RegisterType : Register → Type with readReg r : SailM (RegisterType r) over EStateM (Error ue) (SequentialState RegisterType c), and generated call sites always use the reduced value type (BitVec 32). This makes per-primitive @[spec] lemmas unusable for Sail-generated code; we currently work around it with relational specs at whole-instruction granularity.
A likely-related symptom in the full Sail-generated setting (not yet minimized): binding the raw state, do return (← get).regs.get? X3, in the generated SailM also reports No spec applicable for the surrounding bind, although the same pattern works in small monads.
Versions
Reproduced identically on v4.35.0, nightly-2026-11-24
(4.38.0-nightly-2026-11-24, commit 59cbe2250650), and nightly-2026-11-30
(4.38.0-nightly-2026-11-30, commit fd149e00cbdb).
- Dominant language
- Lean
- Stars
- 10.5k
- Forks
- 1.2k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 323
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/lean4
-
P-medium
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
leanprover/lean4#16958 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
leanprover/lean4#16897 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16892 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16886 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 78/100
leanprover/lean4#16820 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlPossibly taken @alexeyfala claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
danipen/TextMateSharp#145 · 2 comments ·
-
accepted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
future-agi/future-agi#6368 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
omacom/omarchy#21787 · 1 comment ·
Maintainers usually reply within 1 day
-
Windows 内置更新报“更新进程启动确认超时”:Explorer ShellExecute 冗余的 -WindowStyle Hidden + -EncodedCommand 触发卡巴斯基挂起Openbug status/needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
WhiteBr1ck/agy-powertools#397 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
leanprover/vscode-lean4#841 ·
Maintainers usually reply within 2 days