summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2014-11-10 16:25:58 -0800
committerEdward Z. Yang <ezyang@cs.stanford.edu>2014-11-18 17:33:18 -0800
commit1019e3c6f90e32785c6a75726282b7362e921047 (patch)
tree6394e140fb7e94b06d89355a76efe51a9124b913
parent483eeba47c8f761e5a0913c37823b640a624c6fb (diff)
downloadhaskell-1019e3c6f90e32785c6a75726282b7362e921047.tar.gz
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: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: simonpj, austin Subscribers: thomie, carter Differential Revision: https://phabricator.haskell.org/D484
-rw-r--r--compiler/typecheck/TcErrors.lhs4
-rw-r--r--compiler/types/InstEnv.lhs16
-rw-r--r--testsuite/tests/annotations/should_fail/annfail10.stderr16
-rw-r--r--testsuite/tests/ghci.debugger/scripts/break006.stderr12
-rw-r--r--testsuite/tests/ghci.debugger/scripts/print019.stderr6
-rw-r--r--testsuite/tests/ghci/scripts/Defer02.stderr2
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr8
-rw-r--r--testsuite/tests/typecheck/should_compile/holes2.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/T7857.stderr4
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail008.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail043.stderr2
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail072.stderr5
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail133.stderr7
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail181.stderr4
14 files changed, 56 insertions, 38 deletions
diff --git a/compiler/typecheck/TcErrors.lhs b/compiler/typecheck/TcErrors.lhs
index 9e9e5513ba..6be82c16ef 100644
--- a/compiler/typecheck/TcErrors.lhs
+++ b/compiler/typecheck/TcErrors.lhs
@@ -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
diff --git a/compiler/types/InstEnv.lhs b/compiler/types/InstEnv.lhs
index 6d03fbe094..411b006059 100644
--- a/compiler/types/InstEnv.lhs
+++ b/compiler/types/InstEnv.lhs
@@ -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]
diff --git a/testsuite/tests/annotations/should_fail/annfail10.stderr b/testsuite/tests/annotations/should_fail/annfail10.stderr
index 4723db19cb..baddbbd035 100644
--- a/testsuite/tests/annotations/should_fail/annfail10.stderr
+++ b/testsuite/tests/annotations/should_fail/annfail10.stderr
@@ -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 #-}
diff --git a/testsuite/tests/ghci.debugger/scripts/break006.stderr b/testsuite/tests/ghci.debugger/scripts/break006.stderr
index 6f4cbdfe19..035a38f4c4 100644
--- a/testsuite/tests/ghci.debugger/scripts/break006.stderr
+++ b/testsuite/tests/ghci.debugger/scripts/break006.stderr
@@ -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
diff --git a/testsuite/tests/ghci.debugger/scripts/print019.stderr b/testsuite/tests/ghci.debugger/scripts/print019.stderr
index 883768bbf9..0c92dba4e4 100644
--- a/testsuite/tests/ghci.debugger/scripts/print019.stderr
+++ b/testsuite/tests/ghci.debugger/scripts/print019.stderr
@@ -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
diff --git a/testsuite/tests/ghci/scripts/Defer02.stderr b/testsuite/tests/ghci/scripts/Defer02.stderr
index 746fa4eea2..cbd2f3b64d 100644
--- a/testsuite/tests/ghci/scripts/Defer02.stderr
+++ b/testsuite/tests/ghci/scripts/Defer02.stderr
@@ -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
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
index c5338bc43b..9f3a8325c2 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
@@ -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]’
diff --git a/testsuite/tests/typecheck/should_compile/holes2.stderr b/testsuite/tests/typecheck/should_compile/holes2.stderr
index 6161433f89..47ac776a21 100644
--- a/testsuite/tests/typecheck/should_compile/holes2.stderr
+++ b/testsuite/tests/typecheck/should_compile/holes2.stderr
@@ -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 _
diff --git a/testsuite/tests/typecheck/should_fail/T7857.stderr b/testsuite/tests/typecheck/should_fail/T7857.stderr
index 698d280ad9..d1e7d3bea2 100644
--- a/testsuite/tests/typecheck/should_fail/T7857.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7857.stderr
@@ -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’
diff --git a/testsuite/tests/typecheck/should_fail/tcfail008.stderr b/testsuite/tests/typecheck/should_fail/tcfail008.stderr
index 38682cc1e8..2fc79b2220 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail008.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail008.stderr
@@ -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
diff --git a/testsuite/tests/typecheck/should_fail/tcfail043.stderr b/testsuite/tests/typecheck/should_fail/tcfail043.stderr
index 6215ce6ad2..a058d87ff8 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail043.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail043.stderr
@@ -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:
diff --git a/testsuite/tests/typecheck/should_fail/tcfail072.stderr b/testsuite/tests/typecheck/should_fail/tcfail072.stderr
index c9b1d10b2b..aeb0e9ae71 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail072.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail072.stderr
@@ -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
diff --git a/testsuite/tests/typecheck/should_fail/tcfail133.stderr b/testsuite/tests/typecheck/should_fail/tcfail133.stderr
index 0198f3c67c..dc9c96d2db 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail133.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail133.stderr
@@ -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)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail181.stderr b/testsuite/tests/typecheck/should_fail/tcfail181.stderr
index 7ec625bac1..84ba8768f4 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail181.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail181.stderr
@@ -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}