    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LANGUAGE LambdaCase #-}

    module GHC.Types.DefaultEnv
       ( ClassDefaults (..)
       , DefaultProvenance (..)
       , DefaultEnv
       , emptyDefaultEnv
       , isEmptyDefaultEnv
       , defaultEnv
       , unitDefaultEnv
       , lookupDefaultEnv
       , filterDefaultEnv
       , defaultList
       , plusDefaultEnv
       , mkDefaultEnv
       , insertDefaultEnv
       , isHaskell2010Default
       )
    where

    import GHC.Core.Class (Class (className))
    import GHC.Prelude
    import GHC.Hs.Extension (GhcRn)
    import GHC.Tc.Utils.TcType (Type)
    import GHC.Types.Name (Name, nameUnique, stableNameCmp)
    import GHC.Types.Name.Env
    import GHC.Types.Unique.FM (lookupUFM_Directly)
    import GHC.Types.SrcLoc (SrcSpan)
    import GHC.Unit.Module.Warnings (WarningTxt)
    import GHC.Unit.Types (Module)
    import GHC.Utils.Outputable

    import Data.Data (Data)
    import Data.List (sortBy)
    import Data.Function (on)

    -- See Note [Named default declarations] in GHC.Tc.Gen.Default

    -- | Default environment mapping class name @Name@ to their default type lists
    --
    -- NB: this includes Haskell98 default declarations, at the 'Num' key.
    type DefaultEnv = NameEnv ClassDefaults

    {- Note [DefaultProvenance]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Each `ClassDefault` is annotated with its `DefaultProvenance`, which
    says where the default came from.  Specifically
    * `DP_Local loc h98`: the default came from an explicit `default` declaration in the module
       being compiled, at location `loc`, and the boolean `h98` indicates whether
       it was from a Haskell 98 default declaration (e.g. `default (Int, Double)`).
    * `DP_Imported M`: the default was imported, it is explicitly exported by module `M`.
    * `DP_Builtin`:  the default was automatically provided by GHC.
       see Note [Builtin class defaults] in GHC.Tc.Utils.Env

    These annotations are used to disambiguate multiple defaults for the same class.
    For example, consider the following modules:

      module M( default C ) where { default C( ... ) }
      module M2( default C) where { import M }
      module N( default C () where { default C(... ) }

      module A where { import M2 }
      module B where { import M2; import N }
      module A1 where { import N; default C ( ... ) }
      module B2 where { default C ( ... ); default C ( ... ) }

    When compiling N, the default for C is annotated with DP_Local loc.
    When compiling M2, the default for C is annotated with DP_Local M.
    When compiling A, the default for C is annotated with DP_Imported M2.

    Cases we needed to disambiguate:
      * Compiling B, two defaults for C: DP_Imported M2, DP_Imported N.
      * Compiling A1, two defaults for C: DP_Imported N, DP_Local loc.
      * Compiling B2, two defaults for C: DP_Local loc1, DP_Local loc2.

    For how we disambiguate these cases,
    See Note [Disambiguation of multiple default declarations] in GHC.Tc.Module.
    -}

    -- | The provenance of a collection of default types for a class.
    -- see Note [DefaultProvenance] for more details
    data DefaultProvenance
      -- | A locally defined default declaration.
      = DP_Local
         { DefaultProvenance -> SrcSpan
    defaultDeclLoc :: SrcSpan -- ^ The 'SrcSpan' of the default declaration
         , DefaultProvenance -> Bool
    defaultDeclH98 :: Bool    -- ^ Is this a Haskell 98 default declaration?
         }
      -- | Built-in class defaults.
      | DP_Builtin
      -- | Imported class defaults.
      | DP_Imported Module -- ^ The module from which the defaults were imported
      deriving (DefaultProvenance -> DefaultProvenance -> Bool
    (DefaultProvenance -> DefaultProvenance -> Bool)
    -> (DefaultProvenance -> DefaultProvenance -> Bool)
    -> Eq DefaultProvenance
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: DefaultProvenance -> DefaultProvenance -> Bool
    == :: DefaultProvenance -> DefaultProvenance -> Bool
    $c/= :: DefaultProvenance -> DefaultProvenance -> Bool
    /= :: DefaultProvenance -> DefaultProvenance -> Bool
    Eq, Typeable DefaultProvenance
    Typeable DefaultProvenance =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g)
     -> DefaultProvenance
     -> c DefaultProvenance)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c DefaultProvenance)
    -> (DefaultProvenance -> Constr)
    -> (DefaultProvenance -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c DefaultProvenance))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c DefaultProvenance))
    -> ((forall b. Data b => b -> b)
        -> DefaultProvenance -> DefaultProvenance)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r)
    -> (forall u.
        (forall d. Data d => d -> u) -> DefaultProvenance -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> DefaultProvenance -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d)
        -> DefaultProvenance -> m DefaultProvenance)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d)
        -> DefaultProvenance -> m DefaultProvenance)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d)
        -> DefaultProvenance -> m DefaultProvenance)
    -> Data DefaultProvenance
    DefaultProvenance -> Constr
    DefaultProvenance -> DataType
    (forall b. Data b => b -> b)
    -> DefaultProvenance -> DefaultProvenance
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u.
    Int -> (forall d. Data d => d -> u) -> DefaultProvenance -> u
    forall u. (forall d. Data d => d -> u) -> DefaultProvenance -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DefaultProvenance
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> DefaultProvenance -> c DefaultProvenance
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DefaultProvenance)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DefaultProvenance)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> DefaultProvenance -> c DefaultProvenance
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> DefaultProvenance -> c DefaultProvenance
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DefaultProvenance
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DefaultProvenance
    $ctoConstr :: DefaultProvenance -> Constr
    toConstr :: DefaultProvenance -> Constr
    $cdataTypeOf :: DefaultProvenance -> DataType
    dataTypeOf :: DefaultProvenance -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DefaultProvenance)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DefaultProvenance)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DefaultProvenance)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DefaultProvenance)
    $cgmapT :: (forall b. Data b => b -> b)
    -> DefaultProvenance -> DefaultProvenance
    gmapT :: (forall b. Data b => b -> b)
    -> DefaultProvenance -> DefaultProvenance
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DefaultProvenance -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> DefaultProvenance -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> DefaultProvenance -> [u]
    $cgmapQi :: forall u.
    Int -> (forall d. Data d => d -> u) -> DefaultProvenance -> u
    gmapQi :: forall u.
    Int -> (forall d. Data d => d -> u) -> DefaultProvenance -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DefaultProvenance -> m DefaultProvenance
    Data)

    instance Outputable DefaultProvenance where
      ppr :: DefaultProvenance -> SDoc
    ppr (DP_Local SrcSpan
    loc Bool
    h98) = SrcSpan -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr SrcSpan
    loc SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <> (if Bool
    h98 then String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    " (H98)" else SDoc
    forall doc. IsOutput doc => doc
    empty)
      ppr DefaultProvenance
    DP_Builtin         = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "built-in"
      ppr (DP_Imported Module
    mod)  = Module -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr Module
    mod

    isHaskell2010Default :: DefaultProvenance -> Bool
    isHaskell2010Default :: DefaultProvenance -> Bool
    isHaskell2010Default = \case
      DP_Local { defaultDeclH98 :: DefaultProvenance -> Bool
    defaultDeclH98 = Bool
    isH98 } -> Bool
    isH98
      DefaultProvenance
    DP_Builtin -> Bool
    True
      DP_Imported {} -> Bool
    False

    -- | Defaulting type assignments for the given class.
    data ClassDefaults
      = ClassDefaults { ClassDefaults -> Class
    cd_class   :: Class -- ^ The class whose defaults are being defined
                      , ClassDefaults -> [Type]
    cd_types   :: [Type]
                      , ClassDefaults -> DefaultProvenance
    cd_provenance :: DefaultProvenance
                        -- ^ Where the defaults came from
                        -- see Note [Default exports] in GHC.Tc.Gen.Export
                      , ClassDefaults -> Maybe (WarningTxt GhcRn)
    cd_warn    :: Maybe (WarningTxt GhcRn)
                        -- ^ Warning emitted when the default is used
                      }
      deriving Typeable ClassDefaults
    Typeable ClassDefaults =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> ClassDefaults -> c ClassDefaults)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c ClassDefaults)
    -> (ClassDefaults -> Constr)
    -> (ClassDefaults -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c ClassDefaults))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c ClassDefaults))
    -> ((forall b. Data b => b -> b) -> ClassDefaults -> ClassDefaults)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r)
    -> (forall u. (forall d. Data d => d -> u) -> ClassDefaults -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> ClassDefaults -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults)
    -> Data ClassDefaults
    ClassDefaults -> Constr
    ClassDefaults -> DataType
    (forall b. Data b => b -> b) -> ClassDefaults -> ClassDefaults
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> ClassDefaults -> u
    forall u. (forall d. Data d => d -> u) -> ClassDefaults -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ClassDefaults
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ClassDefaults -> c ClassDefaults
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ClassDefaults)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ClassDefaults)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ClassDefaults -> c ClassDefaults
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ClassDefaults -> c ClassDefaults
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ClassDefaults
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ClassDefaults
    $ctoConstr :: ClassDefaults -> Constr
    toConstr :: ClassDefaults -> Constr
    $cdataTypeOf :: ClassDefaults -> DataType
    dataTypeOf :: ClassDefaults -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ClassDefaults)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ClassDefaults)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ClassDefaults)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ClassDefaults)
    $cgmapT :: (forall b. Data b => b -> b) -> ClassDefaults -> ClassDefaults
    gmapT :: (forall b. Data b => b -> b) -> ClassDefaults -> ClassDefaults
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ClassDefaults -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> ClassDefaults -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> ClassDefaults -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ClassDefaults -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ClassDefaults -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ClassDefaults -> m ClassDefaults
    Data

    instance Outputable ClassDefaults where
      ppr :: ClassDefaults -> SDoc
    ppr ClassDefaults {cd_class :: ClassDefaults -> Class
    cd_class = Class
    cls, cd_types :: ClassDefaults -> [Type]
    cd_types = [Type]
    tys} = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text String
    "default" SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> Class -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr Class
    cls
            SDoc -> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc -> doc
    <+> SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc
    parens ([Type] -> SDoc
    forall a. Outputable a => [a] -> SDoc
    interpp'SP [Type]
    tys)

    emptyDefaultEnv :: DefaultEnv
    emptyDefaultEnv :: DefaultEnv
    emptyDefaultEnv = DefaultEnv
    forall a. NameEnv a
    emptyNameEnv

    isEmptyDefaultEnv :: DefaultEnv -> Bool
    isEmptyDefaultEnv :: DefaultEnv -> Bool
    isEmptyDefaultEnv = DefaultEnv -> Bool
    forall a. NameEnv a -> Bool
    isEmptyNameEnv

    unitDefaultEnv :: ClassDefaults -> DefaultEnv
    unitDefaultEnv :: ClassDefaults -> DefaultEnv
    unitDefaultEnv ClassDefaults
    d = Name -> ClassDefaults -> DefaultEnv
    forall a. Name -> a -> NameEnv a
    unitNameEnv (Class -> Name
    className (Class -> Name) -> Class -> Name
    forall a b. (a -> b) -> a -> b
    $ ClassDefaults -> Class
    cd_class ClassDefaults
    d) ClassDefaults
    d

    defaultEnv :: [ClassDefaults] -> DefaultEnv
    defaultEnv :: [ClassDefaults] -> DefaultEnv
    defaultEnv = (ClassDefaults -> Name) -> [ClassDefaults] -> DefaultEnv
    forall a. (a -> Name) -> [a] -> NameEnv a
    mkNameEnvWith (Class -> Name
    className (Class -> Name)
    -> (ClassDefaults -> Class) -> ClassDefaults -> Name
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ClassDefaults -> Class
    cd_class)

    defaultList :: DefaultEnv -> [ClassDefaults]
    defaultList :: DefaultEnv -> [ClassDefaults]
    defaultList = (ClassDefaults -> ClassDefaults -> Ordering)
    -> [ClassDefaults] -> [ClassDefaults]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (Name -> Name -> Ordering
    stableNameCmp (Name -> Name -> Ordering)
    -> (ClassDefaults -> Name)
    -> ClassDefaults
    -> ClassDefaults
    -> Ordering
    forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
    `on` Class -> Name
    className (Class -> Name)
    -> (ClassDefaults -> Class) -> ClassDefaults -> Name
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ClassDefaults -> Class
    cd_class) ([ClassDefaults] -> [ClassDefaults])
    -> (DefaultEnv -> [ClassDefaults]) -> DefaultEnv -> [ClassDefaults]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . DefaultEnv -> [ClassDefaults]
    forall a. NameEnv a -> [a]
    nonDetNameEnvElts
                  -- sortBy recovers determinism

    insertDefaultEnv :: ClassDefaults -> DefaultEnv -> DefaultEnv
    insertDefaultEnv :: ClassDefaults -> DefaultEnv -> DefaultEnv
    insertDefaultEnv ClassDefaults
    d DefaultEnv
    env = DefaultEnv -> Name -> ClassDefaults -> DefaultEnv
    forall a. NameEnv a -> Name -> a -> NameEnv a
    extendNameEnv DefaultEnv
    env (Class -> Name
    className (Class -> Name) -> Class -> Name
    forall a b. (a -> b) -> a -> b
    $ ClassDefaults -> Class
    cd_class ClassDefaults
    d) ClassDefaults
    d

    lookupDefaultEnv :: DefaultEnv -> Name -> Maybe ClassDefaults
    lookupDefaultEnv :: DefaultEnv -> Name -> Maybe ClassDefaults
    lookupDefaultEnv DefaultEnv
    env = DefaultEnv -> Unique -> Maybe ClassDefaults
    forall {k} (key :: k) elt. UniqFM key elt -> Unique -> Maybe elt
    lookupUFM_Directly DefaultEnv
    env (Unique -> Maybe ClassDefaults)
    -> (Name -> Unique) -> Name -> Maybe ClassDefaults
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Name -> Unique
    nameUnique

    filterDefaultEnv :: (ClassDefaults -> Bool) -> DefaultEnv -> DefaultEnv
    filterDefaultEnv :: (ClassDefaults -> Bool) -> DefaultEnv -> DefaultEnv
    filterDefaultEnv = (ClassDefaults -> Bool) -> DefaultEnv -> DefaultEnv
    forall elt. (elt -> Bool) -> NameEnv elt -> NameEnv elt
    filterNameEnv

    plusDefaultEnv :: DefaultEnv -> DefaultEnv -> DefaultEnv
    plusDefaultEnv :: DefaultEnv -> DefaultEnv -> DefaultEnv
    plusDefaultEnv = DefaultEnv -> DefaultEnv -> DefaultEnv
    forall a. NameEnv a -> NameEnv a -> NameEnv a
    plusNameEnv

    -- | Create a 'DefaultEnv' from a list of (Name, ClassDefaults) pairs
    -- it is useful if we don't want to poke into the 'ClassDefaults' structure
    -- to get the 'Name' of the class, it can be problematic, see #25858
    mkDefaultEnv :: [(Name, ClassDefaults)] -> DefaultEnv
    mkDefaultEnv :: [(Name, ClassDefaults)] -> DefaultEnv
    mkDefaultEnv = [(Name, ClassDefaults)] -> DefaultEnv
    forall a. [(Name, a)] -> NameEnv a
    mkNameEnv