Skip to content
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

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

eric-wieser
Copy link
Contributor

@eric-wieser eric-wieser commented Dec 18, 2023

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 and Meta.evalExpr. This PR is not trying to fully align them, but just to fix one particular misalignment that I am impacted by.

Closes #3091

@eric-wieser eric-wieser marked this pull request as ready for review December 18, 2023 15:49
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 18, 2023
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Dec 18, 2023

  • ❗ Mathlib CI will not be attempted unless you rebase your PR onto the 'nightly' branch. (2023-12-18 15:50:28)
  • ✅ Mathlib branch lean-pr-testing-3090 has successfully built against this PR. (2023-12-20 12:34:38) View Log
  • ✅ Mathlib branch lean-pr-testing-3090 has successfully built against this PR. (2023-12-20 13:12:04) View Log

@kim-em
Copy link
Collaborator

kim-em commented Dec 19, 2023

It would be good to have a Mathlib build for this one. Could you rebase onto nightly-with-mathlib?

@eric-wieser
Copy link
Contributor Author

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.
Comment on lines 14 to +15
let value ← instantiateMVars value
let us := collectLevelParams {} value |>.params
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elabEvalUnsafe uses

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.

Copy link
Contributor Author

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-instantiateMVarsd value in the other file referenced above?

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

@digama0 digama0 Feb 10, 2024

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.

Copy link
Contributor Author

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?

@eric-wieser
Copy link
Contributor Author

It would be good to have a Mathlib build for this one. Could you rebase onto nightly-with-mathlib?

I did this rebase @semorrison, but I guess CI won't run until tomorrow?

@nomeata
Copy link
Collaborator

nomeata commented Dec 20, 2023

It would be good to have a Mathlib build for this one. Could you rebase onto nightly-with-mathlib?

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 (2023-12-19), but nightly-with-mathlib did not advance. I hope that #3097 will fix that. Once that hits master, I can re-trigger the workflow and then it hopefully works. Sorry for the delays.

leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 20, 2023
@nomeata
Copy link
Collaborator

nomeata commented Dec 20, 2023

Seems to work (https://github.com/leanprover/lean4/actions/runs/7274620683/job/19820906002), mathlib CI should be running

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 20, 2023
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 20, 2023
@eric-wieser
Copy link
Contributor Author

awaiting-review

@github-actions github-actions bot added the awaiting-review Waiting for someone to review the PR label Dec 21, 2023
@eric-wieser
Copy link
Contributor Author

@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!

@eric-wieser
Copy link
Contributor Author

eric-wieser commented Apr 9, 2024

Just to note this now also impacts eval% in mathlib:

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

@Kha Kha enabled auto-merge September 27, 2024 09:52
@Kha Kha added the merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. label Sep 27, 2024
@Kha Kha disabled auto-merge September 27, 2024 09:55
@Kha Kha merged commit f22998e into leanprover:master Sep 27, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

evalExpr does not handle universe params, but #eval does
7 participants