@@ -1,13 +1,56 @@
1+From d78e5ce3fb865ec1c1659817b0bba1a1bccc692c Mon Sep 17 00:00:00 2001
2+From: Matthew Bauer <mjbauer95@gmail.com>
3+Date: Sat, 1 Jun 2019 07:04:31 -0400
4+Subject: [PATCH] Make qNewUnique return a Uniq instead of an Int
5+
6+After GHC commit
7+https://gitlab.haskell.org/ghc/ghc/commit/4ba73e00c4887b58d85131601a15d00608acaa60,
8+`Uniq` is an `Integer` instead of `Int`. The `qNewUnique` function,
9+however, currently returns an `Int` by using `fromIntegral` to
10+convert the `Integer` to an `Int`. This is potentially dangerous,
11+however, as this could truncate large `Integer`s down into smaller
12+`Int`s, which has the potential to return non-unique `Int`s.
13+
14+Instead of doing this, let's simply make `qNewUnique` return a `Uniq`
15+without any modification. The only place where `singletons` uses
16+`qNewUnique` is for the purpose of turning the `Uniq` directly into
17+a `String` anyway, so this is a perfectly fine thing to do.
18+
19+This is originally Matthew Bauer's patch from #398, which was an
20+abandoned attempt at fixing a separate GHCJS bug. Since this patch is
21+useful on its own merits, I (@RyanGlScott) have modified the commit
22+message to reflect its new purpose.
23+
24+Co-authored-by: Matthew Bauer <mjbauer95@gmail.com>
25+Co-authored-by: Ryan Scott <ryan.gl.scott@gmail.com>
26+---
27+ src/Data/Singletons/Util.hs | 6 +++---
28+ 1 file changed, 3 insertions(+), 3 deletions(-)
29+
130diff --git a/src/Data/Singletons/Util.hs b/src/Data/Singletons/Util.hs
2−index 0f8f788..0ada2fe 100644
31+index 8ffdcf96..f28d6329 100644
332--- a/src/Data/Singletons/Util.hs
433+++ b/src/Data/Singletons/Util.hs
5−@@ -96,7 +96,7 @@ qNewUnique :: DsMonad q => q Int
34+@@ -91,11 +91,11 @@ qReportError :: Quasi q => String -> q ()
35+ qReportError = qReport True
36+
37+ -- | Generate a new Unique
38+-qNewUnique :: DsMonad q => q Int
39++qNewUnique :: DsMonad q => q Uniq
640 qNewUnique = do
741 Name _ flav <- qNewName "x"
842 case flav of
9−- NameU n -> return n
10−+ NameU n -> return (fromInteger n)
43+- NameU n -> return $ fromIntegral n
44++ NameU n -> return n
1145 _ -> error "Internal error: `qNewName` didn't return a NameU"
1246
1347 checkForRep :: Quasi q => [Name] -> q ()
48+@@ -202,7 +202,7 @@ suffixName ident symb n =
49+ -- convert a number into both alphanumeric and symoblic forms
50+ uniquePrefixes :: String -- alphanumeric prefix
51+ -> String -- symbolic prefix
52+- -> Int
53++ -> Uniq
54+ -> (String, String) -- (alphanum, symbolic)
55+ uniquePrefixes alpha symb n = (alpha ++ n_str, symb ++ convert n_str)
56+ where