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: stack overflow at mkBinding if type occurs check fails #6079

Closed
wants to merge 4 commits into from

Conversation

JovanGerb
Copy link
Contributor

@JovanGerb JovanGerb commented Nov 14, 2024

This PR fixes a stackoverflow bug in mkBinding caused by metavariables appearing in their own type.

Closes #6013
Closes #3150 edit: this has been closed

@JovanGerb JovanGerb marked this pull request as draft November 14, 2024 15:05
@JovanGerb JovanGerb changed the title fix: stack overflow at mkBinding if type occurs check fails. fix: stack overflow at mkBinding if type occurs check fails Nov 14, 2024
@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 Nov 14, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 14, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 14, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Nov 14, 2024

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 14, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 14, 2024
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Nov 14, 2024
@JovanGerb JovanGerb marked this pull request as ready for review November 15, 2024 14:08
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 15, 2024
@kim-em
Copy link
Collaborator

kim-em commented Nov 17, 2024

@JovanGerb could you confirm that #6105 has resolved this?

@JovanGerb
Copy link
Contributor Author

It is only partially resolved. #6105 closes #3150 by avoiding the type occurs check failure in elaborating structure instances.

#6013 is unaffected.

@leodemoura
Copy link
Member

@JovanGerb I am concerned about this PR. We want to avoid cyclic dependencies in the metavariable assignment. This PR goes in a different direction: let's tolerate cycles. For example, in #3150, we were adding an assignment without performing the occurs check. This PR would "mask" the real problem.

@JovanGerb
Copy link
Contributor Author

That makes sense.

In the PR that introduced the type occurs check, commit 72e5528 defines skipAtMostNumBinders, which somewhat allows cyclic dependencies. (Although I didn't understand where in mathlib or the test file this was happening). Should this be modified to avoid cyclic dependencies?

@leodemoura
Copy link
Member

@JovanGerb

Should this be modified to avoid cyclic dependencies?

#6104 does that, but unfortunately it breaks a test. The test comes from a real repo: Plausible.
They would have to add an extra annotation (i.e., (β := β)) here:

      let nextStep := minimizeAux cfg var candidate (n + 1)

I will discuss with the author whether the change is reasonable or not.

@JovanGerb
Copy link
Contributor Author

Looking at that breaking test, I think this may be fixed with the change I suggested in the last comment on #6013. The particular cyclic metavariables occurrence is in the value of a let-expression where the bound variable doesn't appear in the body. So modifying

| LocalDecl.ldecl _ _ n type value nonDep _ =>
let type := type.headBeta
let type ← abstractRangeAux xs i type
let value ← abstractRangeAux xs i value
let e := mkLet n type value e nonDep
match kind with
| MetavarKind.syntheticOpaque =>
-- See "Gruesome details" section in the beginning of the file
let e := e.liftLooseBVars 0 1
return mkForall n BinderInfo.default type e
| _ => pure e

so that it only creates the let if there is a bound variable may help.

@JovanGerb
Copy link
Contributor Author

Closing, with an alternative solution at #6128.

@JovanGerb JovanGerb closed this Nov 20, 2024
@JovanGerb JovanGerb deleted the stackOverflow branch November 21, 2024 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR 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.

stack overflow during elaboration Bug leading to stack overflow
4 participants