Repository navigation
Conversation
|
Thanks for this fix. I hit the same issue (#58) and tested this branch (5169499). Repro (Lean v4.36.0-rc1): theorem both : (∀ {a : Prop}, a → a) ∧ (∀ (a : Prop), a → a) := ⟨fun h => h, fun _ h => h⟩With this branch, the exported type of Keying - noMDataExprs : HashMap Expr Expr := HashMap.emptyWithCapacity 100000
+ noMDataExprs : HashMap ExprKey Expr := HashMap.emptyWithCapacity 100000
...
- if let some x := (← get).noMDataExprs[e]? then
+ if let some x := (← get).noMDataExprs[ExprKey.mk e]? then
...
- modify (fun st => { st with noMDataExprs := st.noMDataExprs.insert e e' })
+ modify (fun st => { st with noMDataExprs := st.noMDataExprs.insert (ExprKey.mk e) e' })With both maps keyed this way, the type of |
`noMDataExprs` was still keyed by `Expr`, whose `BEq` is alpha-equivalence, so alpha-equivalent subterms that differ only in binder info shared one cache entry inside a single type. Key it on `ExprKey` as well and cover a type with mixed implicit and explicit binders.
|
Thanks for the detailed repro — you tested
With |
Fixes #58.
visitedExprsandnoMDataExprswere both keyed byExprusing its defaultBEq, which is alpha-equivalence and ignores binder names and binder info. An expression could therefore reuse an index, or a cachedremoveMDataresult, from an alpha-equivalent expression exported earlier. This made exported binder names and binder info depend on which declarations had already been exported.This change introduces a small
ExprKeywrapper whoseBEqisExpr.equal(structural equality), and uses it for both expression caches:visitedExprs, which maps an expression to its export index.noMDataExprs, which cachesremoveMDataresults. That cache is reset once perdumpExprcall, not per subterm, so two alpha-equivalent subtrees with different binder info inside a single type collided.Expr.hashis still used for hashing; structural equality implies alpha-equivalence, so the existing hash remains compatible.Two regression tests:
mixedBinders, one theorem whose type mixes an implicit and an explicit∀over the same body:(∀ {a : Prop}, a → a) ∧ (∀ (a : Prop), a → a). A#guard_msgsdump ofci.typepins bothforallEnodes with their distinctbinderInfovalues and the shared body.The mixed-binder case fails on the old code: the explicit conjunct reuses the implicit
forallEnode atie 5, so the second binder is lost.This can slightly increase export size because alpha-equivalent copies are no longer deduplicated, but it makes each declaration's export independent of export order.
Validation:
lake buildpasses.lake testpasses onleanprover/lean4:v4.36.0-rc1.functionWithLetlinter warning is unchanged.