Sort field labels before fingerprint hashing
authorBartosz Nitka <niteria@gmail.com>
Tue, 27 Oct 2015 15:19:48 +0000 (10:19 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 27 Oct 2015 15:19:54 +0000 (10:19 -0500)
commitffcdd84f86727c1621be0a0e522eb6a3a64e479f
tree248f97aeb7af6185a78ebeb0bf9baea65681953e
parentdc13467347fa9bf9e1a70389a2eccd9bd4853d21
Sort field labels before fingerprint hashing

`fsEnvElts :: FastStringEnv a -> [a]` returns a list of `[a]` in the order of
`Unique`s which is arbitrary. In this case it gives a list of record fields in
arbitrary order, from which we then extract the field labels to contribute to
the record fingerprint. The arbitrary ordering of field labels introduces
unnecessary nondeterminism in interface files as demonstrated by the test case.

We sort `FastString` here. It's safe, because the only way that the `Unique`
associated with the `FastString` is used in comparison is for equality. If the
`Unique`s are different it fallbacks to comparing the actual `ByteString`.

Reviewed By: ezyang, thomie, bgamari, austin

Differential Revision: https://phabricator.haskell.org/D1373

GHC Trac Issues: #4012
compiler/basicTypes/Unique.hs
compiler/iface/MkIface.hs
testsuite/tests/determinism/determ002/A.hs [new file with mode: 0644]
testsuite/tests/determinism/determ002/Makefile [new file with mode: 0644]
testsuite/tests/determinism/determ002/all.T [new file with mode: 0644]
testsuite/tests/determinism/determ002/determ002.stderr [new file with mode: 0644]
testsuite/tests/determinism/determ002/determ002.stdout [new file with mode: 0644]