-
Notifications
You must be signed in to change notification settings - Fork 735
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f67e2e4
introduce copy, remove coercion
datokrat 8621183
fixes and cleanups
datokrat a319d2b
use withTermInfoContext' inside withInfoHole to prevent the custom in…
datokrat 16240ca
trigger ci
datokrat 6dd6ff7
fix one test; the other can't be reproduced locally...
datokrat 2ed53c5
really fix the binopInfoTree test
datokrat 5fbf91e
fix tests
datokrat 53cb4c1
cleanups
datokrat 3063387
rename linter
datokrat b3f0ac0
reduce breakage related to coerce?
datokrat a4f4332
further reduce breakageu
datokrat 42771cc
revert versoDocs test
datokrat 3077a29
revert changes to versoDocs
datokrat d0e49fe
use Array
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 : Array Name := #[``optionCoe, ``instCoeSubarrayArray] | ||
|
|
||
| /-- 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.