Skip to content

feat: do not instantiate metavariables in kabstract/rw for disallowed occurrences#2539

Merged
leodemoura merged 1 commit intoleanprover:masterfrom
kim-em:rw-occs
Jan 3, 2024
Merged

feat: do not instantiate metavariables in kabstract/rw for disallowed occurrences#2539
leodemoura merged 1 commit intoleanprover:masterfrom
kim-em:rw-occs

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Sep 13, 2023

Fixes #2538.

@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 Sep 14, 2023
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 14, 2023
@ghost
Copy link
Copy Markdown

ghost commented Sep 14, 2023

ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 14, 2023
kim-em added a commit to leanprover-community/mathlib4 that referenced this pull request Sep 15, 2023
@ghost ghost added the builds-mathlib CI has verified that Mathlib builds against this PR label Sep 15, 2023
-- We save the metavariable context here,
-- so that it can be rolled back unless `occs.contains i`.
let mctx ← getMCtx
if (← isDefEq e p) then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about exceptions? We should handle them here, or add a comment saying why it is ok to not rollback the mctx in this case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I don't understand how exception handling is relevant here.

  • Previously, if there was an exception at isDefEq then that would propagate to the caller of kabstract. That is still the case. Why would we try handling the exception here now?

  • We are now rolling back the mctx if the occurrence has been rejected by the caller. Why would we want to rollback the mctx on an exception? (Again, previously an exception in isDefEq would result in the caller of kabstract receiving whatever mctx resulted.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@leodemoura, could I ping you on this query?

@kim-em kim-em marked this pull request as ready for review October 4, 2023 01:04
@kim-em kim-em added the awaiting-review Waiting for someone to review the PR label Oct 4, 2023
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Oct 9, 2023
@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Oct 23, 2023

Someone just ran into this on zulip.

@MichaelStollBayreuth
Copy link
Copy Markdown

Fixing nth_rw/nth_rewrite would be good. The current behavior is confusing especially for beginners/students.

ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Dec 12, 2023
@kbuzzard
Copy link
Copy Markdown
Contributor

Another confused beginner here.

@MichaelStollBayreuth
Copy link
Copy Markdown

Here is me stumbling over unexpected nth_rw behavior.

else
-- We save the metavariable context here,
-- so that it can be rolled back unless `occs.contains i`.
let mctx ← getMCtx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed that in the definition of checkPointDefEq, it uses the MonadBacktrack SavedState MetaM instance for restoring the state if isDefEq fails or returns false. Is there any reason that you instead use the MonadMCtx MetaM instance?

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 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.

metavariables in rw are instantiated at the first match, even if this is disallowed by occs.

5 participants