diff options
author | Bartosz Nitka <niteria@gmail.com> | 2016-06-29 07:34:55 -0700 |
---|---|---|
committer | Bartosz Nitka <niteria@gmail.com> | 2016-06-30 05:55:51 -0700 |
commit | fb6e2c7fe213004c7398a13e3cc38d4428b66b12 (patch) | |
tree | 0bd461ec64d6eddb87ec40f0d01735ba5fbac85a /compiler/cmm/CmmNode.hs | |
parent | e8d62711e6cbc3065ee5e6f6a654667f02a0bcd1 (diff) | |
download | haskell-fb6e2c7fe213004c7398a13e3cc38d4428b66b12.tar.gz |
Delete Ord Unique
Ord Unique can be a source of invisible, accidental
nondeterminism as explained in Note [No Ord for Unique].
This removes it, leaving a note with rationale.
It's unfortunate that I had to write Ord instances for
codegen data structures by hand, but I believe that it's a
right trade-off here.
Test Plan: ./validate
Reviewers: simonmar, austin, bgamari
Reviewed By: simonmar
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2370
GHC Trac Issues: #4012
Diffstat (limited to 'compiler/cmm/CmmNode.hs')
-rw-r--r-- | compiler/cmm/CmmNode.hs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/cmm/CmmNode.hs b/compiler/cmm/CmmNode.hs index b2e5cfb546..bba9bd77c3 100644 --- a/compiler/cmm/CmmNode.hs +++ b/compiler/cmm/CmmNode.hs @@ -34,8 +34,10 @@ import qualified Unique as U import Compiler.Hoopl import Data.Maybe -import Data.List (tails,sort) +import Data.List (tails,sortBy) import Prelude hiding (succ) +import Unique (nonDetCmpUnique) +import Util ------------------------ @@ -652,15 +654,23 @@ instance Eq CmmTickScope where (SubScope u _) == (SubScope u' _) = u == u' (SubScope _ _) == _ = False _ == (SubScope _ _) = False - scope == scope' = sort (scopeUniques scope) == - sort (scopeUniques scope') + scope == scope' = + sortBy nonDetCmpUnique (scopeUniques scope) == + sortBy nonDetCmpUnique (scopeUniques scope') + -- This is still deterministic because + -- the order is the same for equal lists + +-- This is non-deterministic but we do not currently support deterministic +-- code-generation. See Note [Unique Determinism and code generation] +-- See Note [No Ord for Unique] instance Ord CmmTickScope where compare GlobalScope GlobalScope = EQ compare GlobalScope _ = LT compare _ GlobalScope = GT - compare (SubScope u _) (SubScope u' _) = compare u u' - compare scope scope' = compare (sort $ scopeUniques scope) - (sort $ scopeUniques scope') + compare (SubScope u _) (SubScope u' _) = nonDetCmpUnique u u' + compare scope scope' = cmpList nonDetCmpUnique + (sortBy nonDetCmpUnique $ scopeUniques scope) + (sortBy nonDetCmpUnique $ scopeUniques scope') instance Outputable CmmTickScope where ppr GlobalScope = text "global" |