-
Notifications
You must be signed in to change notification settings - Fork 713
feat: lint coercions that are deprecated or banned in core #11511
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
Open
datokrat
wants to merge
13
commits into
paul/base/slices/subarraycopy
Choose a base branch
from
paul/slices/subarraycopy
base: paul/base/slices/subarraycopy
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c82975d
introduce copy, remove coercion
datokrat 2949f5e
fixes and cleanups
datokrat 3902963
use withTermInfoContext' inside withInfoHole to prevent the custom in…
datokrat a849068
trigger ci
datokrat d21bfdc
fix one test; the other can't be reproduced locally...
datokrat 7ac7bc0
really fix the binopInfoTree test
datokrat 3bfa2f1
fix tests
datokrat 7e11922
cleanups
datokrat 7b9a1c2
rename linter
datokrat 2c6d6b0
reduce breakage related to coerce?
datokrat 1e5d986
further reduce breakageu
datokrat 9cb732c
revert versoDocs test
datokrat d24a4d4
revert changes to versoDocs
datokrat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /- | ||
| Copyright (c) 2025 Lean FRO, LLC. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Paul Reichert | ||
| -/ | ||
| module | ||
|
|
||
| prelude | ||
| public import Lean.Elab.Command | ||
| public import Lean.Server.InfoUtils | ||
| import Lean.Linter.Basic | ||
| import Lean.Linter.Deprecated | ||
| import all Lean.Elab.Term.TermElabM | ||
|
|
||
| public section | ||
| set_option linter.missingDocs true -- keep it documented | ||
|
|
||
| namespace Lean.Linter.Coe | ||
|
|
||
| /-- | ||
| `set_option linter.deprecatedCoercions true` enables a linter emitting warnings on deprecated | ||
| coercions. | ||
| -/ | ||
| register_builtin_option linter.deprecatedCoercions : Bool := { | ||
| defValue := true | ||
| descr := "Validate that no deprecated coercions are used." | ||
| } | ||
|
|
||
| /-- | ||
| Checks whether the "deprecated coercions" linter is enabled. | ||
| -/ | ||
| def shouldWarnOnDeprecatedCoercions [Monad m] [MonadOptions m] : m Bool := | ||
| return (← getOptions).get linter.deprecatedCoercions.name true | ||
|
|
||
| /-- A list of coercion names that must not be used in core. -/ | ||
| def coercionsBannedInCore : List Name := [``optionCoe, ``instCoeSubarrayArray] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /-- Validates that no coercions are used that are either deprecated or are banned in core. -/ | ||
| def coeLinter : Linter where | ||
| run := fun _ => do | ||
| let mainModule ← getMainModule | ||
| let isCoreModule := mainModule = `lean.run.linterCoe ∨ (mainModule.getRoot ∈ [`Init, `Std]) | ||
| let shouldWarnOnDeprecated := getLinterValue linter.deprecatedCoercions (← getLinterOptions) | ||
| let trees ← Elab.getInfoTrees | ||
| for tree in trees do | ||
| tree.visitM' (m := Elab.Command.CommandElabM) (fun _ info _ => do | ||
| match info with | ||
| | .ofCustomInfo ci => | ||
| if let some trace := ci.value.get? Elab.Term.CoeExpansionTrace then | ||
| for coeDecl in trace.expandedCoeDecls do | ||
| if isCoreModule && coeDecl ∈ coercionsBannedInCore then | ||
| logWarningAt ci.stx m!"This term uses the coercion `{coeDecl}`, which is banned in Lean's core library." | ||
| if shouldWarnOnDeprecated then | ||
| let some attr := deprecatedAttr.getParam? (← getEnv) coeDecl | pure () | ||
| logLint linter.deprecatedCoercions ci.stx <| .tagged ``deprecatedAttr <| | ||
| m!"This term uses the deprecated coercion `{.ofConstName coeDecl true}`." | ||
| | _ => pure () | ||
| return true) (fun _ _ _ _ => return) | ||
|
|
||
| builtin_initialize addLinter coeLinter | ||
|
|
||
| end Lean.Linter.Coe | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.