Implementation of the Deprecated Instances proposal #575
This commit implements the ability to deprecate certain instances,
which causes the compiler to emit the desired deprecation message
whenever they are instantiated. For example:
module A where
class C t where
instance {-# DEPRECATED "dont use" #-} C Int where
module B where
import A
f :: C t => t
f = undefined
g :: Int
g = f -- "dont use" emitted here
The implementation is as follows:
- In the parser, we parse deprecations/warnings attached to instances:
instance {-# DEPRECATED "msg" #-} Show X
deriving instance {-# WARNING "msg2" #-} Eq Y
(Note that non-standalone deriving instance declarations do not support
this mechanism.)
- We store the resulting warning message in `ClsInstDecl` (respectively, `DerivDecl`).
In `GHC.Tc.TyCl.Instance.tcClsInstDecl` (respectively, `GHC.Tc.Deriv.Utils.newDerivClsInst`),
we pass on that information to `ClsInst` (and eventually store it in `IfaceClsInst` too).
- Finally, when we solve a constraint using such an instance, in
`GHC.Tc.Instance.Class.matchInstEnv`, we emit the appropriate warning
that was stored in `ClsInst`.
Note that we only emit a warning when the instance is used in a different module
than it is defined, which keeps the behaviour in line with the deprecation of
top-level identifiers.
Signed-off-by:
Bartłomiej Cieślar <bcieslar2001@gmail.com>
Showing
- compiler/GHC/Core/InstEnv.hs 39 additions, 13 deletionscompiler/GHC/Core/InstEnv.hs
- compiler/GHC/Hs.hs 2 additions, 2 deletionscompiler/GHC/Hs.hs
- compiler/GHC/Hs/Decls.hs 59 additions, 11 deletionscompiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/ImpExp.hs 12 additions, 12 deletionscompiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Iface/Make.hs 5 additions, 2 deletionscompiler/GHC/Iface/Make.hs
- compiler/GHC/Iface/Syntax.hs 12 additions, 5 deletionscompiler/GHC/Iface/Syntax.hs
- compiler/GHC/IfaceToCore.hs 3 additions, 2 deletionscompiler/GHC/IfaceToCore.hs
- compiler/GHC/Parser.y 28 additions, 37 deletionscompiler/GHC/Parser.y
- compiler/GHC/Parser/PostProcess.hs 1 addition, 1 deletioncompiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Rename/Env.hs 11 additions, 12 deletionscompiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Module.hs 10 additions, 5 deletionscompiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Names.hs 5 additions, 6 deletionscompiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Deriv.hs 15 additions, 7 deletionscompiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Utils.hs 9 additions, 3 deletionscompiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Errors/Ppr.hs 19 additions, 10 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs 20 additions, 4 deletionscompiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs 3 additions, 6 deletionscompiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Instance/Class.hs 11 additions, 4 deletionscompiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/Solver/Dict.hs 58 additions, 1 deletioncompiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/TyCl/Instance.hs 4 additions, 2 deletionscompiler/GHC/Tc/TyCl/Instance.hs
Loading
Please register or sign in to comment