diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-12-15 18:57:26 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-12-15 18:57:53 -0500 |
commit | 0d213c18b6962bb65e2b3035a258dd3f5bf454dd (patch) | |
tree | 6bb856c068bfb7c82584f913701f8d8081ae8482 /compiler/cbits | |
parent | cd4b202f24da928adf66c05443b457002ab6a3e1 (diff) | |
download | haskell-0d213c18b6962bb65e2b3035a258dd3f5bf454dd.tar.gz |
UniqSupply: Use full range of machine word
Currently uniques are 32-bits wide. 8 of these bits are for the unique
class, leaving only 24 for the unique number itself. This seems
dangerously small for a large project. Let's use the full range of the
native machine word.
We also add (now largely unnecessary) overflow check to ensure that the
unique number doesn't overflow.
Test Plan: Validate
Reviewers: simonmar, austin, niteria
Reviewed By: niteria
Subscribers: mpickering, thomie
Differential Revision: https://phabricator.haskell.org/D2844
GHC Trac Issues: #12944
Diffstat (limited to 'compiler/cbits')
-rw-r--r-- | compiler/cbits/genSym.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/compiler/cbits/genSym.c b/compiler/cbits/genSym.c index 70ea417c4b..725a310253 100644 --- a/compiler/cbits/genSym.c +++ b/compiler/cbits/genSym.c @@ -1,18 +1,35 @@ - +#include <assert.h> #include "Rts.h" +#include "Unique.h" static HsInt GenSymCounter = 0; static HsInt GenSymInc = 1; +#define UNIQUE_MASK ((1ULL << UNIQUE_BITS) - 1) + +STATIC_INLINE void checkUniqueRange(HsInt u STG_UNUSED) { +#if DEBUG + // Uh oh! We will overflow next time a unique is requested. + assert(h != UNIQUE_MASK); +#endif +} + HsInt genSym(void) { #if defined(THREADED_RTS) if (n_capabilities == 1) { - return GenSymCounter = (GenSymCounter + GenSymInc) & 0xFFFFFF; + GenSymCounter = (GenSymCounter + GenSymInc) & UNIQUE_MASK; + checkUniqueRange(GenSymCounter); + return GenSymCounter; } else { - return atomic_inc((StgWord *)&GenSymCounter, GenSymInc) & 0xFFFFFF; + HsInt n = atomic_inc((StgWord *)&GenSymCounter, GenSymInc) + & UNIQUE_MASK; + checkUniqueRange(n); + return n; } #else - return GenSymCounter = (GenSymCounter + GenSymInc) & 0xFFFFFF; + GenSymCounter = (GenSymCounter + GenSymInc) & UNIQUE_MASK; + checkUniqueRange(GenSymCounter); + return GenSymCounter; #endif } |