Commit e2c91738 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

Narrow scope of special-case for unqualified printing of names in core libraries

Commit 547c5971 modifies the
pretty-printer to render names from a set of core packages (`base`,
`ghc-prim`, `template-haskell`) as unqualified. The idea here was that
many of these names typically are not in scope but are well-known by the
user and therefore qualification merely introduces noise.

This, however, is a very large hammer and potentially breaks any
consumer who relies on parsing GHC output (hence #11208). This commit
partially reverts this change, now only printing `Constraint` (which
appears quite often in errors) as unqualified.

Fixes #11208.

Updates tests in `array` submodule.

Test Plan: validate

Reviewers: hvr, thomie, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1619

GHC Trac Issues: #11208
parent 947e44fe
......@@ -159,7 +159,9 @@ import CoAxiom
import ConLike
import DataCon
import PatSyn
import PrelNames ( gHC_PRIM, ioTyConName, printName, mkInteractiveModule )
import PrelNames ( gHC_PRIM, ioTyConName, printName, mkInteractiveModule
, eqTyConName )
import TysWiredIn
import Packages hiding ( Version(..) )
import DynFlags
import DriverPhases ( Phase, HscSource(..), isHsBootOrSig, hscSourceString )
......@@ -1562,27 +1564,26 @@ mkPrintUnqualified dflags env = QueryQualify qual_name
(mkQualPackage dflags)
where
qual_name mod occ
| [] <- unqual_gres
, moduleUnitId mod `elem` [primUnitId, baseUnitId, thUnitId]
, not (isDerivedOccName occ)
= NameUnqual -- For names from ubiquitous packages that come with GHC, if
-- there are no entities called unqualified 'occ', then
-- print unqualified. Doing so does not cause ambiguity,
-- and it reduces the amount of qualification in error
-- messages. We can't do this for all packages, because we
-- might get errors like "Can't unify T with T". But the
-- ubiquitous packages don't contain any such gratuitous
-- name clashes.
--
-- A motivating example is 'Constraint'. It's often not in
-- scope, but printing GHC.Prim.Constraint seems overkill.
| [gre] <- unqual_gres
, right_name gre
= NameUnqual -- If there's a unique entity that's in scope
-- unqualified with 'occ' AND that entity is
-- the right one, then we can use the unqualified name
| [] <- unqual_gres
, any is_name forceUnqualNames
, not (isDerivedOccName occ)
= NameUnqual -- Don't qualify names that come from modules
-- that come with GHC, often appear in error messages,
-- but aren't typically in scope. Doing this does not
-- cause ambiguity, and it reduces the amount of
-- qualification in error messages thus improving
-- readability.
--
-- A motivating example is 'Constraint'. It's often not
-- in scope, but printing GHC.Prim.Constraint seems
-- overkill.
| [gre] <- qual_gres
= NameQual (greQualModName gre)
......@@ -1595,6 +1596,15 @@ mkPrintUnqualified dflags env = QueryQualify qual_name
= NameNotInScope1 -- Can happen if 'f' is bound twice in the module
-- Eg f = True; g = 0; f = False
where
is_name :: Name -> Bool
is_name name = nameModule name == mod && nameOccName name == occ
forceUnqualNames :: [Name]
forceUnqualNames =
map tyConName [ constraintKindTyCon, heqTyCon, coercibleTyCon
, starKindTyCon, unicodeStarKindTyCon, ipTyCon ]
++ [ eqTyConName ]
right_name gre = nameModule_maybe (gre_name gre) == Just mod
unqual_gres = lookupGRE_RdrName (mkRdrUnqual occ) env
......
......@@ -68,7 +68,8 @@ module TysWiredIn (
-- * Kinds
typeNatKindCon, typeNatKind, typeSymbolKindCon, typeSymbolKind,
isLiftedTypeKindTyConName, liftedTypeKind, constraintKind,
starKindTyConName, unicodeStarKindTyConName,
starKindTyCon, starKindTyConName,
unicodeStarKindTyCon, unicodeStarKindTyConName,
liftedTypeKindTyCon, constraintKindTyCon,
-- * Parallel arrays
......
Subproject commit 4b43c95af80ed7e1567244527e5e459912d3e504
Subproject commit f643793b3fbffd7419f403bedc65b7ac06dff0cd
annfail05.hs:11:1:
No instance for (Data NoInstances) arising from an annotation
In the annotation: {-# ANN f NoInstances #-}
annfail05.hs:11:1: error:
• No instance for (Data.Data.Data NoInstances)
arising from an annotation
• In the annotation: {-# ANN f NoInstances #-}
annfail08.hs:9:1: error:
No instance for (Data (a0 -> a0)) arising from an annotation
(maybe you haven't applied a function to enough arguments?)
In the annotation: {-# ANN f (id + 1) #-}
• No instance for (Data.Data.Data (a0 -> a0))
arising from an annotation
(maybe you haven't applied a function to enough arguments?)
• In the annotation: {-# ANN f (id + 1) #-}
annfail08.hs:9:15: error:
No instance for (Num (a0 -> a0)) arising from a use of ‘+’
(maybe you haven't applied a function to enough arguments?)
In the annotation: {-# ANN f (id + 1) #-}
No instance for (Num (a0 -> a0)) arising from a use of ‘+’
(maybe you haven't applied a function to enough arguments?)
In the annotation: {-# ANN f (id + 1) #-}
annfail10.hs:9:1: error:
Ambiguous type variable ‘a0’ arising from an annotation
prevents the constraint ‘(Data a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance (Data a, Data b) => Data (Either a b)
-- Defined in ‘Data.Data’
instance Data All -- Defined in ‘Data.Data’
instance (Data (f a), Data a, Typeable f) => Data (Alt f a)
-- Defined in ‘Data.Data’
...plus 39 others
(use -fprint-potential-instances to see them all)
In the annotation: {-# ANN f 1 #-}
• Ambiguous type variable ‘a0’ arising from an annotation
prevents the constraint ‘(Data.Data.Data a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance (Data.Data.Data a, Data.Data.Data b) =>
Data.Data.Data (Either a b)
-- Defined in ‘Data.Data’
instance Data.Data.Data Ordering -- Defined in ‘Data.Data’
instance Data.Data.Data Integer -- Defined in ‘Data.Data’
...plus 15 others
...plus 24 instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
• In the annotation: {-# ANN f 1 #-}
annfail10.hs:9:11: error:
Ambiguous type variable ‘a0’ arising from the literal ‘1’
prevents the constraint ‘(Num a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance forall k (f :: k -> *) (a :: k).
Num (f a) =>
Num (Alt f a)
-- Defined in ‘Data.Monoid’
instance Num a => Num (Product a) -- Defined in ‘Data.Monoid’
instance Num a => Num (Sum a) -- Defined in ‘Data.Monoid’
...plus 14 others
(use -fprint-potential-instances to see them all)
In the annotation: {-# ANN f 1 #-}
• Ambiguous type variable ‘a0’ arising from the literal ‘1’
prevents the constraint ‘(Num a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
...plus two others
...plus 12 instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
• In the annotation: {-# ANN f 1 #-}
......@@ -10,43 +10,44 @@ T2431.$WRefl [InlPrag=INLINE] :: forall a. a :~: a
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=0,unsat_ok=False,boring_ok=False)
Tmpl= \ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a ~# a)}]
T2431.$WRefl = \ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a ~# a)
Tmpl= \ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a GHC.Prim.~# a)}]
T2431.$WRefl =
\ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a GHC.Prim.~# a)
-- RHS size: {terms: 2, types: 0, coercions: 0}
a :: TrName
a :: GHC.Types.TrName
[GblId, Caf=NoCafRefs, Str=DmdType]
a = TrNameS "main"#
a = GHC.Types.TrNameS "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0}
a1 :: TrName
a1 :: GHC.Types.TrName
[GblId, Caf=NoCafRefs, Str=DmdType]
a1 = TrNameS "T2431"#
a1 = GHC.Types.TrNameS "T2431"#
-- RHS size: {terms: 3, types: 0, coercions: 0}
T2431.$trModule :: Module
T2431.$trModule :: GHC.Types.Module
[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType]
T2431.$trModule = Module a a1
T2431.$trModule = GHC.Types.Module a a1
-- RHS size: {terms: 2, types: 0, coercions: 0}
a2 :: TrName
a2 :: GHC.Types.TrName
[GblId, Caf=NoCafRefs, Str=DmdType]
a2 = TrNameS "'Refl"#
a2 = GHC.Types.TrNameS "'Refl"#
-- RHS size: {terms: 5, types: 0, coercions: 0}
T2431.$tc'Refl :: TyCon
T2431.$tc'Refl :: GHC.Types.TyCon
[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType]
T2431.$tc'Refl = TyCon 0## 0## T2431.$trModule a2
T2431.$tc'Refl = GHC.Types.TyCon 0## 0## T2431.$trModule a2
-- RHS size: {terms: 2, types: 0, coercions: 0}
a3 :: TrName
a3 :: GHC.Types.TrName
[GblId, Caf=NoCafRefs, Str=DmdType]
a3 = TrNameS ":~:"#
a3 = GHC.Types.TrNameS ":~:"#
-- RHS size: {terms: 5, types: 0, coercions: 0}
T2431.$tc:~: :: TyCon
T2431.$tc:~: :: GHC.Types.TyCon
[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType]
T2431.$tc:~: = TyCon 0## 0## T2431.$trModule a3
T2431.$tc:~: = GHC.Types.TyCon 0## 0## T2431.$trModule a3
-- RHS size: {terms: 4, types: 8, coercions: 0}
absurd :: forall a. Int :~: Bool -> a
......
T4846.hs:29:1: error:
Couldn't match type ‘Bool’ with ‘BOOL’
arising from a use of ‘coerce’
In the expression: coerce (mkExpr :: Expr Bool) :: Expr BOOL
In an equation for ‘mkExpr’:
mkExpr = coerce (mkExpr :: Expr Bool) :: Expr BOOL
When typechecking the code for ‘mkExpr’
in a derived instance for ‘B BOOL’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘B BOOL’
• Couldn't match type ‘Bool’ with ‘BOOL’
arising from a use of ‘GHC.Prim.coerce’
• In the expression:
GHC.Prim.coerce (mkExpr :: Expr Bool) :: Expr BOOL
In an equation for ‘mkExpr’:
mkExpr = GHC.Prim.coerce (mkExpr :: Expr Bool) :: Expr BOOL
When typechecking the code for ‘mkExpr’
in a derived instance for ‘B BOOL’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘B BOOL’
Test10268.hs:5:6: error: Variable not in scope: footemplate :: ExpQ
Test10268.hs:7:14: error:
Not in scope: type constructor or class ‘Pattern’
Test10268.hs:10:10: error:
Not in scope: type constructor or class ‘Pattern’
Test10268.hs:5:6: error:
Variable not in scope: footemplate :: Language.Haskell.TH.Lib.ExpQ
Test10268.hs:7:14: error:
Not in scope: type constructor or class ‘Pattern’
Test10268.hs:10:10: error:
Not in scope: type constructor or class ‘Pattern’
<interactive>:5:1: error:
No instance for (Show t) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t’
Use :print or :force to determine these types
Relevant bindings include it :: t (bound at <interactive>:5:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show All -- Defined in ‘Data.Monoid’
instance forall k (f :: k -> *) (a :: k).
Show (f a) =>
Show (Alt f a)
-- Defined in ‘Data.Monoid’
...plus 36 others
(use -fprint-potential-instances to see them all)
In a stmt of an interactive GHCi command: print it
• No instance for (Show t) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t’
Use :print or :force to determine these types
Relevant bindings include it :: t (bound at <interactive>:5:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
...plus 23 others
...plus 13 instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it
<interactive>:7:1: error:
No instance for (Show t) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t’
Use :print or :force to determine these types
Relevant bindings include it :: t (bound at <interactive>:7:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show All -- Defined in ‘Data.Monoid’
instance forall k (f :: k -> *) (a :: k).
Show (f a) =>
Show (Alt f a)
-- Defined in ‘Data.Monoid’
...plus 36 others
(use -fprint-potential-instances to see them all)
In a stmt of an interactive GHCi command: print it
• No instance for (Show t) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘t’
Use :print or :force to determine these types
Relevant bindings include it :: t (bound at <interactive>:7:1)
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
...plus 23 others
...plus 13 instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it
Left user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(IOError Nothing UserError [] "error" Nothing Nothing)
*** Exception: user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(IOError Nothing UserError [] "error" Nothing Nothing)
*** Exception: user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(IOError Nothing UserError [] "error" Nothing Nothing)
Left user error (error)
Left user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(GHC.IO.Exception.IOError
Nothing GHC.IO.Exception.UserError [] "error" Nothing Nothing)
*** Exception: user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(GHC.IO.Exception.IOError
Nothing GHC.IO.Exception.UserError [] "error" Nothing Nothing)
*** Exception: user error (error)
Stopped at <exception thrown>
_exception :: e = _
_exception = SomeException
(GHC.IO.Exception.IOError
Nothing GHC.IO.Exception.UserError [] "error" Nothing Nothing)
Left user error (error)
<interactive>:10:1: error:
No instance for (Show a1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘a1’
Use :print or :force to determine these types
Relevant bindings include it :: a1 (bound at <interactive>:10:1)
These potential instances exist:
instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’
instance Show Module -- Defined in ‘GHC.Show’
instance Show Ordering -- Defined in ‘GHC.Show’
...plus 32 others
(use -fprint-potential-instances to see them all)
In a stmt of an interactive GHCi command: print it
• No instance for (Show a1) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘a1’
Use :print or :force to determine these types
Relevant bindings include it :: a1 (bound at <interactive>:10:1)
These potential instances exist:
instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show TyCon -- Defined in ‘GHC.Show’
...plus 30 others
...plus two instance involving out-of-scope typess
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it
l = (_t1::[Maybe Integer])
Just 1
r = IORef (STRef
(GHC.Prim.MutVar# (Just 1 : (_t2::[Maybe Integer]))))
r = IORef (STRef (GHC.Prim.MutVar# (Just 1 : _)))
l = (_t1::[Maybe Integer])
Just 1
r = GHC.IORef.IORef (GHC.STRef.STRef
(GHC.Prim.MutVar# (Just 1 : (_t2::[Maybe Integer]))))
r = GHC.IORef.IORef (GHC.STRef.STRef
(GHC.Prim.MutVar# (Just 1 : _)))
u = (_t1::(?callStack::CallStack) => ST s (forall s'. ST s' a))
u = (_t1::(?callStack::GHC.Stack.Types.CallStack) =>
ST s (forall s'. ST s' a))
module T11208 where
import qualified Prelude as P
f n = n P.+ 1
g h (P.Just x) = P.Just (h x)
g _ P.Nothing = P.Nothing
:load T11208
:browse T11208
\ No newline at end of file
f :: P.Num a => a -> a
g :: (r -> a) -> P.Maybe r -> P.Maybe a
<interactive>:7:1:
No instance for (Show Float) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:15:1:
No instance for (Show Float) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:7:1: error:
• No instance for (GHC.Show.Show Float)
arising from a use of ‘System.IO.print’
• In a stmt of an interactive GHCi command: System.IO.print it
<interactive>:15:1: error:
• No instance for (GHC.Show.Show Float)
arising from a use of ‘System.IO.print’
• In a stmt of an interactive GHCi command: System.IO.print it
data D2 = MkD2 (forall (p :: Any -> *) (a :: Any). p a -> Int)
data D2
= MkD2 (forall (p :: GHC.Prim.Any -> *) (a :: GHC.Prim.Any).
p a -> Int)
-- Defined at <interactive>:3:1
data D3 = MkD3 (forall k (p :: k -> *) (a :: k). p a -> Int)
-- Defined at <interactive>:4:1
data Int = I# Int# -- Defined in ‘GHC.Types’
instance Bounded Int -- Defined in ‘GHC.Enum’
instance Enum Int -- Defined in ‘GHC.Enum’
instance Eq Int -- Defined in ‘GHC.Classes’
instance Integral Int -- Defined in ‘GHC.Real’
instance Num Int -- Defined in ‘GHC.Num’
instance Ord Int -- Defined in ‘GHC.Classes’
instance Read Int -- Defined in ‘GHC.Read’
instance Real Int -- Defined in ‘GHC.Real’
instance Show Int -- Defined in ‘GHC.Show’
data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’
instance Bounded Int -- Defined in ‘GHC.Enum’
instance Enum Int -- Defined in ‘GHC.Enum’
instance Eq Int -- Defined in ‘GHC.Classes’
instance Integral Int -- Defined in ‘GHC.Real’
instance Num Int -- Defined in ‘GHC.Num’
instance Ord Int -- Defined in ‘GHC.Classes’
instance Read Int -- Defined in ‘GHC.Read’
instance Real Int -- Defined in ‘GHC.Real’
instance Show Int -- Defined in ‘GHC.Show’
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment