diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2019-10-25 11:20:48 +0200 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2019-10-25 17:15:43 +0200 |
commit | bf053189060bacded949050f4efeeb279dc23cc4 (patch) | |
tree | ecda5e5bc78d0353d16eb57ffb0efa1ef6037030 /compiler/GHC/Hs/Lit.hs | |
parent | 6824f29aebd28571db118eb6877ef04eda630871 (diff) | |
download | haskell-wip/flexible-outputable.tar.gz |
Use FlexibleInstances for `Outputable (* p)` instead of match-all instances with equality constraintswip/flexible-outputable
In #17304, Richard and Simon dicovered that using `-XFlexibleInstances`
for `Outputable` instances of AST data types means users can provide orphan
`Outputable` instances for passes other than `GhcPass`.
Type inference doesn't currently to suffer, and Richard gave an example
in #17304 that shows how rare a case would be where the slightly worse
type inference would matter.
So I went ahead with the refactoring, attempting to fix #17304.
Diffstat (limited to 'compiler/GHC/Hs/Lit.hs')
-rw-r--r-- | compiler/GHC/Hs/Lit.hs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/GHC/Hs/Lit.hs b/compiler/GHC/Hs/Lit.hs index ab30de87ac..963bf0e2c0 100644 --- a/compiler/GHC/Hs/Lit.hs +++ b/compiler/GHC/Hs/Lit.hs @@ -9,6 +9,7 @@ {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types] -- in module GHC.Hs.PlaceHolder {-# LANGUAGE ConstraintKinds #-} @@ -227,7 +228,7 @@ instance Ord OverLitVal where compare (HsIsString _ _) (HsFractional _) = GT -- Instance specific to GhcPs, need the SourceText -instance p ~ GhcPass pass => Outputable (HsLit p) where +instance Outputable (HsLit (GhcPass p)) where ppr (HsChar st c) = pprWithSourceText st (pprHsChar c) ppr (HsCharPrim st c) = pp_st_suffix st primCharSuffix (pprPrimChar c) ppr (HsString st s) = pprWithSourceText st (pprHsString s) @@ -249,8 +250,8 @@ pp_st_suffix NoSourceText _ doc = doc pp_st_suffix (SourceText st) suffix _ = text st <> suffix -- in debug mode, print the expression that it's resolved to, too -instance (p ~ GhcPass pass, OutputableBndrId p) - => Outputable (HsOverLit p) where +instance OutputableBndrId p + => Outputable (HsOverLit (GhcPass p)) where ppr (OverLit {ol_val=val, ol_witness=witness}) = ppr val <+> (whenPprDebug (parens (pprExpr witness))) ppr (XOverLit x) = ppr x |