Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
Source project has a limited visibility.
  • Bartłomiej Cieślar's avatar
    d2bedffd
    Implementation of the Deprecated Instances proposal #575 · d2bedffd
    Bartłomiej Cieślar authored and Marge Bot's avatar Marge Bot committed
    
    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: default avatarBartłomiej Cieślar <bcieslar2001@gmail.com>
    d2bedffd
    History
    Implementation of the Deprecated Instances proposal #575
    Bartłomiej Cieślar authored and Marge Bot's avatar Marge Bot committed
    
    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: default avatarBartłomiej Cieślar <bcieslar2001@gmail.com>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.