Zulip Chat Archive

Stream: lean4 dev

Topic: Catching mvars in `MVarId.apply`


Leni Aniva (Feb 09 2025 at 09:35):

I think the MVarId catching logic in MVarId.apply should get mvars from the actual expression assignment to the current goal:

    let otherMVarIds  getMVarsNoDelayed (mkAppN e newMVars)

as opposed to

    let otherMVarIds  getMVarsNoDelayed e

This is because the isDefEqApply in the go loop could potentially delay assign some mvars in newMVars, in which case the value of the delayed assignment would be lost since otherMVarIds only contain mvars from e.

I found a corner case in my project that suffers from this issue, but I don't know how to reliably reproduce this case.

Leni Aniva (Feb 11 2025 at 00:17):

Specifically when ctxApprox is true, isExprDefEq can cause mvars in newMVars to be assigned to another (unassigned) mvar with a smaller context, so there should be a way to catch them.

e.g.

    let newMVars  newMVars.filterM fun mvar => not <$> mvar.mvarId!.isAssigned

Instead of this, we could have

  let newMVars  newMVars.filterMapM fun mvar => do
    match  getExprMVarAssignment? mvar with
    | .none => pure $ .some mvar
    | .some (.mvar inner) => pure $ .some inner
    | .some _ => pure .none

which will ensure ctxApprox'd mvars are accounted for.

Leni Aniva (Feb 13 2025 at 01:58):

I don't know how to reliably trigger ctxApprox. Otherwise I can write a MWE that showcases when .apply loses track of a mvar.


Last updated: May 02 2025 at 03:31 UTC