diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-08-12 15:47:27 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-08-12 15:47:27 -0400 |
commit | 7d699782bf6148c115a49b5f31ada9bd7c32a7d6 (patch) | |
tree | 5307e48a467a74c8d068117aba0d2d0bcce57742 /compiler/rename/RnExpr.hs | |
parent | 3f05e5f6becc2f7174898726b6f027105b12a780 (diff) | |
download | haskell-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/rename/RnExpr.hs')
-rw-r--r-- | compiler/rename/RnExpr.hs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs index 0e2022da47..6eabc8969d 100644 --- a/compiler/rename/RnExpr.hs +++ b/compiler/rename/RnExpr.hs @@ -57,6 +57,7 @@ import qualified GHC.LanguageExtensions as LangExt import Data.Ord import Data.Array +import qualified Data.List.NonEmpty as NE {- ************************************************************************ @@ -970,7 +971,7 @@ rnParallelStmts ctxt return_op segs thing_inside cmpByOcc n1 n2 = nameOccName n1 `compare` nameOccName n2 dupErr vs = addErr (text "Duplicate binding in parallel list comprehension for:" - <+> quotes (ppr (head vs))) + <+> quotes (ppr (NE.head vs))) lookupStmtName :: HsStmtContext Name -> Name -> RnM (SyntaxExpr GhcRn, FreeVars) -- Like lookupSyntaxName, but respects contexts |