-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: collect level parameters in evalExpr #3090
Conversation
|
It would be good to have a Mathlib build for this one. Could you rebase onto |
I'm afraid I probably have no time today to do so, but might later this week. My figuring is that this is very unlikely to break anything, since the change only affects code that was previously producing kernel errors; but indeed it's good practice to test it anyway. |
`elabEvalUnsafe` already does something similar.
35d80b8
to
8335d4e
Compare
let value ← instantiateMVars value | ||
let us := collectLevelParams {} value |>.params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elabEvalUnsafe
uses
lean4/src/Lean/Elab/BuiltinCommand.lean
Lines 634 to 637 in 8335d4e
let value ← Term.levelMVarToParam (← instantiateMVars value) | |
let type ← inferType value | |
let us := collectLevelParams {} value |>.params | |
let value ← instantiateMVars value |
which rather puzzlingly uses instantiateMVars
twice. I don't really know which if either is right, so I've limited this to the minimal change that fixes my bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmill, do you have any guesses as to why inferType
happens to the pre-instantiateMVars
d value in the other file referenced above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@digama0, @semorrison, do you have any thoughts on what's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason to instantiateMVars
that second time, but I do wonder if it should be let type ← instantiateMVars type
instead, since there's no reason why the inferred type will be metavariable-free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can a value have no metavariables but its inferred type have some?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the value is a
where a : ?m1
is a hypothesis then this can happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But eval
can't work if there are free variables anyway, so presumably this doesn't matter?
I did this rebase @semorrison, but I guess CI won't run until tomorrow? |
The workflow is a bit racy; by the time it ran, a new nightly tag appeared ( |
Seems to work (https://github.com/leanprover/lean4/actions/runs/7274620683/job/19820906002), mathlib CI should be running |
awaiting-review |
@semorrison, do you think this is ok as is? While there's some discussion above about instantiating metavariables, it's mainly about code that isn't part of this patch anyway; and the actual change is only two lines! |
Just to note this now also impacts import Mathlib.Tactic.Eval
def foo.{u} (x : PUnit.{u}) : Nat := 37
-- fails without this PR
def bar.{u} (x : PUnit.{u}) : Nat := eval% foo.{u} PUnit.unit |
elabEvalUnsafe
already does something similar: it also instantiates universe metavariables, but it is not clear to me whether that is sensible here.To be conservative, I leave it out of this PR.
See #3090 (comment) for a comparison between
#eval
andMeta.evalExpr
. This PR is not trying to fully align them, but just to fix one particular misalignment that I am impacted by.Closes #3091