From 158d2a91581d82dc1690a858b474eaab3a02e43e Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Tue, 27 Oct 2015 15:17:32 +0100 Subject: Make it possible to have different UniqSupply strategies To get reproducible/deterministic builds, the way that the Uniques are assigned shouldn't matter. This allows to test for that. It add 2 new flags: * `-dinitial-unique` * `-dunique-increment` And by varying these you can get interesting effects: * `-dinitial-unique=0 -dunique-increment 1` - current sequential UniqSupply * `-dinitial-unique=16777215 -dunique-increment -1` - UniqSupply that generates in decreasing order * `-dinitial-unique=1 -dunique-increment PRIME` - where PRIME big enough to overflow often - nonsequential order I haven't proven the usefullness of the last one yet and it's the reason why we have to mask the bits with `0xFFFFFF` in `genSym`, so I can remove it if it becomes contentious. Test Plan: validate on harbormaster Reviewers: simonmar, austin, ezyang, bgamari Reviewed By: austin, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1360 GHC Trac Issues: #4012 --- compiler/cbits/genSym.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'compiler/cbits/genSym.c') diff --git a/compiler/cbits/genSym.c b/compiler/cbits/genSym.c index 08d403d849..70ea417c4b 100644 --- a/compiler/cbits/genSym.c +++ b/compiler/cbits/genSym.c @@ -2,16 +2,21 @@ #include "Rts.h" static HsInt GenSymCounter = 0; +static HsInt GenSymInc = 1; HsInt genSym(void) { #if defined(THREADED_RTS) if (n_capabilities == 1) { - return GenSymCounter++; + return GenSymCounter = (GenSymCounter + GenSymInc) & 0xFFFFFF; } else { - return atomic_inc((StgWord *)&GenSymCounter, 1); + return atomic_inc((StgWord *)&GenSymCounter, GenSymInc) & 0xFFFFFF; } #else - return GenSymCounter++; + return GenSymCounter = (GenSymCounter + GenSymInc) & 0xFFFFFF; #endif } +void initGenSym(HsInt NewGenSymCounter, HsInt NewGenSymInc) { + GenSymCounter = NewGenSymCounter; + GenSymInc = NewGenSymInc; +} -- cgit v1.2.1