summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Gonzalez <Gabriel439@gmail.com>2016-02-17 10:59:09 +0100
committerBen Gamari <ben@smart-cactus.org>2016-02-17 21:04:31 +0100
commit67d22261da840c5ba90414496457b583df0a3911 (patch)
treec75c4f9fc2ecce77749e582299d8f42f70ce82a8
parenta6152159c9f14fc9cf0e86caff532906abd49b73 (diff)
downloadhaskell-67d22261da840c5ba90414496457b583df0a3911.tar.gz
Derive Eq and Ord instance for SrcLoc and RealSrcLoc
The Eq and Ord instance were previously hand-written and this change updates them to be automatically derived by the compiler. The derived behavior should be equivalent to the original. Reviewers: hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1913
-rw-r--r--compiler/basicTypes/SrcLoc.hs30
1 files changed, 2 insertions, 28 deletions
diff --git a/compiler/basicTypes/SrcLoc.hs b/compiler/basicTypes/SrcLoc.hs
index 04f7ec929e..2726f41b8b 100644
--- a/compiler/basicTypes/SrcLoc.hs
+++ b/compiler/basicTypes/SrcLoc.hs
@@ -105,11 +105,12 @@ data RealSrcLoc
= SrcLoc FastString -- A precise location (file name)
{-# UNPACK #-} !Int -- line number, begins at 1
{-# UNPACK #-} !Int -- column number, begins at 1
+ deriving (Eq, Ord)
data SrcLoc
= RealSrcLoc {-# UNPACK #-}!RealSrcLoc
| UnhelpfulLoc FastString -- Just a general indication
- deriving Show
+ deriving (Eq, Ord, Show)
{-
************************************************************************
@@ -164,36 +165,9 @@ advanceSrcLoc (SrcLoc f l c) _ = SrcLoc f l (c + 1)
************************************************************************
-}
--- SrcLoc is an instance of Ord so that we can sort error messages easily
-instance Eq SrcLoc where
- loc1 == loc2 = case loc1 `cmpSrcLoc` loc2 of
- EQ -> True
- _other -> False
-
-instance Eq RealSrcLoc where
- loc1 == loc2 = case loc1 `cmpRealSrcLoc` loc2 of
- EQ -> True
- _other -> False
-
-instance Ord SrcLoc where
- compare = cmpSrcLoc
-
-instance Ord RealSrcLoc where
- compare = cmpRealSrcLoc
-
sortLocated :: [Located a] -> [Located a]
sortLocated things = sortBy (comparing getLoc) things
-cmpSrcLoc :: SrcLoc -> SrcLoc -> Ordering
-cmpSrcLoc (UnhelpfulLoc s1) (UnhelpfulLoc s2) = s1 `compare` s2
-cmpSrcLoc (UnhelpfulLoc _) (RealSrcLoc _) = GT
-cmpSrcLoc (RealSrcLoc _) (UnhelpfulLoc _) = LT
-cmpSrcLoc (RealSrcLoc l1) (RealSrcLoc l2) = (l1 `compare` l2)
-
-cmpRealSrcLoc :: RealSrcLoc -> RealSrcLoc -> Ordering
-cmpRealSrcLoc (SrcLoc s1 l1 c1) (SrcLoc s2 l2 c2)
- = (s1 `compare` s2) `thenCmp` (l1 `compare` l2) `thenCmp` (c1 `compare` c2)
-
instance Outputable RealSrcLoc where
ppr (SrcLoc src_path src_line src_col)
= hcat [ pprFastFilePath src_path <> colon