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: subst notation (heq ▸ h) should fail if it does't subst #3994

Merged
merged 1 commit into from
Apr 28, 2024

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Apr 26, 2024

The subst notation substitues in the expected type, if present, or in
the type of the argument, if no expected type is known.

If there is an expected type it already fails if it cannot find the
equations' left hand side or right hand side. But if the expected type
is not known and the equation's lhs is not present in the second
argument's type, it will happily do a no-op-substitution.

This is inconsistent and unlikely what the user intended to do, so we
now print an error message now.

This still only looks for the lhs; search for the rhs as well seems
prudent, but I’ll leave that for a separate PR, to better diagnose the
impact on mathlib.

This triggers a small number of pointless uses of subst in mathlib, see
leanprover-community/mathlib4#12451

The subst notation substitues in the expected type, if present, or in
the type of the argument, if no expected type is known.

If there is an expected type it already fails if it cannot find the
equations' left hand side or right hand side. But if the expected type
is not known and the equation's lhs is not present in the second
argument's type, it will happily do a no-op-substitution.

This is inconsistent and unlikely what the user intended to do, so we
now print an error message now.

This still only looks for the lhs; search for the rhs as well seems
prudent, but I’ll leave that for a separate PR, to better diagnose the
impact on mathlib.
Comment on lines +7 to +16
def ex4 (heq : foo = bar) (P : Nat → Prop) (h : P 3) := heq ▸ h -- error
def ex5 (heq : foo = bar) (P : Nat → Prop) (h : P 3) : P 4 := heq ▸ h -- error
def ex6 (heq : foo = bar) (P : Nat → Prop) (h : P 3) : P bar := heq ▸ h

def ex7 (heq : bar = foo) (P : Nat → Prop) (h : P foo) := heq ▸ h -- error
def ex8 (heq : bar = foo) (P : Nat → Prop) (h : P foo) : P 4 := heq ▸ h -- error
def ex9 (heq : bar = foo) (P : Nat → Prop) (h : P foo) : P bar := heq ▸ h
def ex10 (heq : bar = foo) (P : Nat → Prop) (h : P 3) := heq ▸ h -- error
def ex11 (heq : bar = foo) (P : Nat → Prop) (h : P 3) : P 4 := heq ▸ h -- error
def ex12 (heq : bar = foo) (P : Nat → Prop) (h : P 3) : P bar := heq ▸ h
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, ex4, ex7 and ex10 would not err.

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc April 26, 2024 12:45 Inactive
@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 Apr 26, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 26, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Apr 26, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Apr 26, 2024

Mathlib CI status (docs):

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc April 26, 2024 13:25 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 26, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
refactor: avoid useless subst

while working on leanprover/lean4#3994 I found a
few uses of ▸ that do not actually do any rewriting. I plan to make
this an error, but of course dropping them is already useful now.
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Apr 26, 2024
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
while working on leanprover/lean4#3994 I found a
few uses of ▸ that do not actually do any rewriting. I plan to make
this an error, but of course dropping them is already useful now.
@nomeata nomeata added the awaiting-review Waiting for someone to review the PR label Apr 26, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc April 26, 2024 15:10 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 26, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 26, 2024
@leodemoura leodemoura removed the awaiting-review Waiting for someone to review the PR label Apr 28, 2024
@nomeata nomeata added this pull request to the merge queue Apr 28, 2024
Merged via the queue into master with commit bb1a373 Apr 28, 2024
30 of 35 checks passed
@kim-em
Copy link
Collaborator

kim-em commented Apr 28, 2024

I've merged lean-pr-testing-3994 into nightly-testing.

@nomeata nomeata deleted the joachim/subst-fails branch April 29, 2024 05:58
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.

4 participants