summaryrefslogtreecommitdiff
path: root/compiler/coreSyn
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2017-08-12 15:47:27 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2017-08-12 15:47:27 -0400
commit7d699782bf6148c115a49b5f31ada9bd7c32a7d6 (patch)
tree5307e48a467a74c8d068117aba0d2d0bcce57742 /compiler/coreSyn
parent3f05e5f6becc2f7174898726b6f027105b12a780 (diff)
downloadhaskell-7d699782bf6148c115a49b5f31ada9bd7c32a7d6.tar.gz
Use NonEmpty lists to represent lists of duplicate elements
Summary: Three functions in `ListSetOps` which compute duplicate elements represent lists of duplicates of `[a]`. This is a really bad way to go about things, because these lists are guaranteed to always have at least one element (the "representative" of the duplicates), and several places in the GHC API call `head` (a partial function) on these lists of duplicates to retrieve the representative. This changes the representation of duplicates to `NonEmpty` lists instead, which allow for many partial uses of `head` to be made total. Fixes #13823. Test Plan: ./validate Reviewers: bgamari, austin, goldfire Reviewed By: bgamari Subscribers: goldfire, rwbarton, thomie GHC Trac Issues: #13823 Differential Revision: https://phabricator.haskell.org/D3823
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r--compiler/coreSyn/CoreLint.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/coreSyn/CoreLint.hs b/compiler/coreSyn/CoreLint.hs
index 8b6be2e661..390a3173d7 100644
--- a/compiler/coreSyn/CoreLint.hs
+++ b/compiler/coreSyn/CoreLint.hs
@@ -66,6 +66,8 @@ import DynFlags
import Control.Monad
import qualified Control.Monad.Fail as MonadFail
import MonadUtils
+import Data.Foldable ( toList )
+import Data.List.NonEmpty ( NonEmpty )
import Data.Maybe
import Pair
import qualified GHC.LanguageExtensions as LangExt
@@ -2427,15 +2429,15 @@ pprLeftOrRight :: LeftOrRight -> MsgDoc
pprLeftOrRight CLeft = text "left"
pprLeftOrRight CRight = text "right"
-dupVars :: [[Var]] -> MsgDoc
+dupVars :: [NonEmpty Var] -> MsgDoc
dupVars vars
= hang (text "Duplicate variables brought into scope")
- 2 (ppr vars)
+ 2 (ppr (map toList vars))
-dupExtVars :: [[Name]] -> MsgDoc
+dupExtVars :: [NonEmpty Name] -> MsgDoc
dupExtVars vars
= hang (text "Duplicate top-level variables with the same qualified name")
- 2 (ppr vars)
+ 2 (ppr (map toList vars))
{-
************************************************************************