Commit 1019e3c6 authored by Edward Z. Yang's avatar Edward Z. Yang

When outputting list of available instances, sort it.

Summary:
The intent of this commit is to make test suite cases more stable, so that
it doesn't matter what order we load interface files in, the test output
doesn't change.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: validate

Reviewers: simonpj, austin

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D484
parent 483eeba4
......@@ -44,7 +44,7 @@ import StaticFlags ( opt_PprStyle_Debug )
import ListSetOps ( equivClasses )
import Data.Maybe
import Data.List ( partition, mapAccumL, zip4, nub )
import Data.List ( partition, mapAccumL, zip4, nub, sortBy )
\end{code}
%************************************************************************
......@@ -1062,7 +1062,7 @@ mk_dict_err fam_envs ctxt (ct, (matches, unifiers, safe_haskell))
hang (if isSingleton unifiers
then ptext (sLit "Note: there is a potential instance available:")
else ptext (sLit "Note: there are several potential instances:"))
2 (ppr_insts unifiers)
2 (ppr_insts (sortBy fuzzyClsInstCmp unifiers))
-- Report "potential instances" only when the constraint arises
-- directly from the user's use of an overloaded function
......
......@@ -15,6 +15,7 @@ module InstEnv (
ClsInst(..), DFunInstType, pprInstance, pprInstanceHdr, pprInstances,
instanceHead, instanceSig, mkLocalInstance, mkImportedInstance,
instanceDFunId, tidyClsInstDFun, instanceRoughTcs,
fuzzyClsInstCmp,
InstEnv, emptyInstEnv, extendInstEnv, deleteFromInstEnv, identicalInstHead,
extendInstEnvList, lookupUniqueInstEnv, lookupInstEnv', lookupInstEnv, instEnvElts,
......@@ -42,6 +43,9 @@ import Id
import FastString
import Data.Data ( Data, Typeable )
import Data.Maybe ( isJust, isNothing )
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid
#endif
\end{code}
......@@ -76,6 +80,18 @@ data ClsInst
-- the decl of BasicTypes.OverlapFlag
}
deriving (Data, Typeable)
-- | A fuzzy comparison function for class instances, intended for sorting
-- instances before displaying them to the user.
fuzzyClsInstCmp :: ClsInst -> ClsInst -> Ordering
fuzzyClsInstCmp x y =
stableNameCmp (is_cls_nm x) (is_cls_nm y) `mappend`
mconcat (map cmp (zip (is_tcs x) (is_tcs y)))
where
cmp (Nothing, Nothing) = EQ
cmp (Nothing, Just _) = LT
cmp (Just _, Nothing) = GT
cmp (Just x, Just y) = stableNameCmp x y
\end{code}
Note [Template tyvars are fresh]
......
......@@ -3,12 +3,14 @@ annfail10.hs:9:1:
No instance for (Data.Data.Data a0) arising from an annotation
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Data.Data.Data () -- Defined in ‘Data.Data’
instance (Data.Data.Data a, Data.Data.Data b) =>
Data.Data.Data (a, b)
Data.Data.Data (Either a b)
-- Defined in ‘Data.Data’
instance (Data.Data.Data a, Data.Data.Data b, Data.Data.Data c) =>
Data.Data.Data (a, b, c)
instance Data.Data.Data t => Data.Data.Data (Data.Proxy.Proxy t)
-- Defined in ‘Data.Data’
instance (GHC.Types.Coercible a b, Data.Data.Data a,
Data.Data.Data b) =>
Data.Data.Data (Data.Type.Coercion.Coercion a b)
-- Defined in ‘Data.Data’
...plus 31 others
In the annotation: {-# ANN f 1 #-}
......@@ -17,8 +19,8 @@ annfail10.hs:9:11:
No instance for (Num a0) arising from the literal ‘1’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
instance Num Int -- Defined in ‘GHC.Num
instance Num GHC.Int.Int16 -- Defined in ‘GHC.Int’
instance Num GHC.Int.Int32 -- Defined in ‘GHC.Int’
instance Num GHC.Int.Int64 -- Defined in ‘GHC.Int
...plus 11 others
In the annotation: {-# ANN f 1 #-}
......@@ -5,9 +5,9 @@
Use :print or :force to determine these types
Relevant bindings include it :: t1 (bound at <interactive>:6:1)
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float
instance Show Float -- Defined in ‘GHC.Float
instance Show () -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show
instance Show Ordering -- Defined in ‘GHC.Show
instance Show Integer -- Defined in ‘GHC.Show’
...plus 22 others
In a stmt of an interactive GHCi command: print it
......@@ -17,8 +17,8 @@
Use :print or :force to determine these types
Relevant bindings include it :: t1 (bound at <interactive>:8:1)
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float
instance Show Float -- Defined in ‘GHC.Float
instance Show () -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show
instance Show Ordering -- Defined in ‘GHC.Show
instance Show Integer -- Defined in ‘GHC.Show’
...plus 22 others
In a stmt of an interactive GHCi command: print it
......@@ -5,8 +5,8 @@
Use :print or :force to determine these types
Relevant bindings include it :: a1 (bound at <interactive>:11:1)
Note: there are several potential instances:
instance Show Unary -- Defined at ../Test.hs:37:29
instance Show a => Show (MkT2 a) -- Defined at ../Test.hs:20:12
instance Show a => Show (MkT a) -- Defined at ../Test.hs:17:13
instance Show TyCon -- Defined in ‘Data.Typeable.Internal’
instance Show TypeRep -- Defined in ‘Data.Typeable.Internal’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
...plus 30 others
In a stmt of an interactive GHCi command: print it
......@@ -69,9 +69,9 @@
No instance for (Num a1) arising from the literal ‘23’
The type variable ‘a1’ is ambiguous
Note: there are several potential instances:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
instance Num Int -- Defined in ‘GHC.Num’
...plus two others
In the first argument of ‘myOp’, namely ‘23’
In the expression: myOp 23
......
......@@ -3,9 +3,9 @@ overloadedlistsfail01.hs:5:8:
No instance for (Show a0) arising from a use of ‘print’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float
instance Show Float -- Defined in ‘GHC.Float
instance Show () -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show
instance Show Ordering -- Defined in ‘GHC.Show
instance Show Integer -- Defined in ‘GHC.Show’
...plus 22 others
In the expression: print [1]
In an equation for ‘main’: main = print [1]
......@@ -25,9 +25,9 @@ overloadedlistsfail01.hs:5:15:
arising from the literal ‘1’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
instance Num Int -- Defined in ‘GHC.Num’
...plus two others
In the expression: 1
In the first argument of ‘print’, namely ‘[1]’
......
......@@ -3,9 +3,9 @@ holes2.hs:3:5: Warning:
No instance for (Show a0) arising from a use of ‘show’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float
instance Show Float -- Defined in ‘GHC.Float
instance Show () -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show
instance Show Ordering -- Defined in ‘GHC.Show
instance Show Integer -- Defined in ‘GHC.Show’
...plus 22 others
In the expression: show _
In an equation for ‘f’: f = show _
......
......@@ -6,10 +6,10 @@ T7857.hs:8:11:
at T7857.hs:8:1-21
The type variable ‘r0’ is ambiguous
Note: there are several potential instances:
instance [safe] (PrintfArg a, PrintfType r) => PrintfType (a -> r)
-- Defined in ‘Text.Printf’
instance [safe] (a ~ ()) => PrintfType (IO a)
-- Defined in ‘Text.Printf’
instance [safe] (PrintfArg a, PrintfType r) => PrintfType (a -> r)
-- Defined in ‘Text.Printf’
instance [safe] IsChar c => PrintfType [c]
-- Defined in ‘Text.Printf’
In the second argument of ‘($)’, namely ‘printf "" i’
......
......@@ -4,9 +4,9 @@ tcfail008.hs:3:5:
The type variable ‘a0’ is ambiguous
Relevant bindings include o :: [a0] (bound at tcfail008.hs:3:1)
Note: there are several potential instances:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
instance Num Int -- Defined in ‘GHC.Num’
...plus two others
In the first argument of ‘(:)’, namely ‘1’
In the expression: 1 : 2
......
......@@ -29,8 +29,8 @@ tcfail043.hs:40:25:
a :: a0 (bound at tcfail043.hs:38:6)
search :: a0 -> [a0] -> Bool (bound at tcfail043.hs:37:1)
Note: there are several potential instances:
instance Eq_ a => Eq_ [a] -- Defined at tcfail043.hs:23:10
instance Eq_ Int -- Defined at tcfail043.hs:20:10
instance Eq_ a => Eq_ [a] -- Defined at tcfail043.hs:23:10
In the expression: eq a (hd bs)
In the expression: if eq a (hd bs) then True else search a (tl bs)
In the expression:
......
......@@ -8,8 +8,9 @@ tcfail072.hs:23:13:
The type variable ‘p0’ is ambiguous
Note: there are several potential instances:
instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Base’
instance Ord () -- Defined in ‘GHC.Classes’
instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’
instance Ord Ordering -- Defined in ‘GHC.Classes’
instance Ord integer-gmp-1.0.0.0:GHC.Integer.Type.BigNat
-- Defined in ‘integer-gmp-1.0.0.0:GHC.Integer.Type’
...plus 23 others
In the expression: g A
In an equation for ‘g’: g (B _ _) = g A
......@@ -6,10 +6,9 @@ tcfail133.hs:68:7:
No instance for (Show r0) arising from a use of ‘show’
The type variable ‘r0’ is ambiguous
Note: there are several potential instances:
instance Show Zero -- Defined at tcfail133.hs:8:29
instance Show One -- Defined at tcfail133.hs:9:28
instance (Show a, Show b, Number a, Digit b) => Show (a :@ b)
-- Defined at tcfail133.hs:11:54
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
...plus 25 others
In the expression: show
In the expression: show $ add (One :@ Zero) (One :@ One)
......
......@@ -7,9 +7,9 @@ tcfail181.hs:17:9:
at tcfail181.hs:17:1-30
The type variable ‘m0’ is ambiguous
Note: there are several potential instances:
instance Monad ((->) r) -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
...plus one other
In the expression: foo
In the expression: foo {bar = return True}
......
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