[commit: ghc] master: Make the order of fixities in the iface file deterministic (218fdf9)

git at git.haskell.org git at git.haskell.org
Wed Dec 2 13:18:29 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/218fdf92370021b900af1e78323764cceb7ac609/ghc

>---------------------------------------------------------------

commit 218fdf92370021b900af1e78323764cceb7ac609
Author: Bartosz Nitka <bnitka at fb.com>
Date:   Wed Dec 2 03:28:13 2015 -0800

    Make the order of fixities in the iface file deterministic
    
    This normalizes the order of written fixities by sorting by
    `OccName` making it independent of `Unique` order.
    
    Test Plan: I've added a new testcase
    
    Reviewers: austin, bgamari, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1557
    
    GHC Trac Issues: #4012


>---------------------------------------------------------------

218fdf92370021b900af1e78323764cceb7ac609
 compiler/iface/MkIface.hs                                    |  6 +++++-
 .../should_compile/read002.hs => determinism/determ010/A.hs} |  5 +++--
 .../tests/determinism/{typecheck => determ010}/Makefile      | 12 ++++++------
 testsuite/tests/determinism/{determ003 => determ010}/all.T   |  4 ++--
 testsuite/tests/determinism/determ010/determ010.stdout       |  2 ++
 5 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/compiler/iface/MkIface.hs b/compiler/iface/MkIface.hs
index d955fa5..e428b58 100644
--- a/compiler/iface/MkIface.hs
+++ b/compiler/iface/MkIface.hs
@@ -222,7 +222,11 @@ mkIface_ hsc_env maybe_old_fingerprint
                    nameIsLocalOrFrom this_mod name  ]
                       -- Sigh: see Note [Root-main Id] in TcRnDriver
 
-        fixities    = [(occ,fix) | FixItem occ fix <- nameEnvElts fix_env]
+        fixities    = sortBy (comparing fst)
+          [(occ,fix) | FixItem occ fix <- nameEnvElts fix_env]
+          -- The order of fixities returned from nameEnvElts is not
+          -- deterministic, so we sort by OccName to canonicalize it.
+          -- See Note [Deterministic UniqFM] in UniqDFM for more details.
         warns       = src_warns
         iface_rules = map coreRuleToIfaceRule rules
         iface_insts = map instanceToIfaceInst $ fixSafeInstances safe_mode insts
diff --git a/testsuite/tests/parser/should_compile/read002.hs b/testsuite/tests/determinism/determ010/A.hs
similarity index 75%
copy from testsuite/tests/parser/should_compile/read002.hs
copy to testsuite/tests/determinism/determ010/A.hs
index 8d9ea5e..b60f90a 100644
--- a/testsuite/tests/parser/should_compile/read002.hs
+++ b/testsuite/tests/determinism/determ010/A.hs
@@ -1,8 +1,8 @@
 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
-
--- !!! tests fixity reading and printing
 module ShouldCompile where
 
+-- tests deterministic order of fixities in the interface file
+
 infixl 1 `f`
 infixr 2 \\\
 infix  3 :==>
@@ -10,6 +10,7 @@ infix  4 `MkFoo`
 
 data Foo = MkFoo Int | Float :==> Double
 
+f :: a -> b -> a
 x `f` y = x
 
 (\\\) :: (Eq a) => [a] -> [a] -> [a]
diff --git a/testsuite/tests/determinism/typecheck/Makefile b/testsuite/tests/determinism/determ010/Makefile
similarity index 54%
copy from testsuite/tests/determinism/typecheck/Makefile
copy to testsuite/tests/determinism/determ010/Makefile
index ac98ea1..1f12622 100644
--- a/testsuite/tests/determinism/typecheck/Makefile
+++ b/testsuite/tests/determinism/determ010/Makefile
@@ -4,10 +4,10 @@ include $(TOP)/mk/test.mk
 
 TEST_HC_OPTS_NO_RECOMP = $(filter-out -fforce-recomp,$(TEST_HC_OPTS))
 
-determ005:
+determ010:
 	$(RM) A.hi A.o
-	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RECOMP) -dinitial-unique=0 -dunique-increment=1 -O A.hs
-	$(CP) A.hi A.old.hi
-	$(RM) A.o
-	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RECOMP) -dinitial-unique=16777206 -dunique-increment=-1 -O A.hs
-	diff A.hi A.old.hi
+	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RECOMP) -dinitial-unique=0 -dunique-increment=1 A.hs
+	$(CP) A.hi A.normal.hi
+	$(RM) A.hi A.o
+	'$(TEST_HC)' $(TEST_HC_OPTS_NO_RECOMP) -dinitial-unique=16777215 -dunique-increment=-1 A.hs
+	diff A.hi A.normal.hi
diff --git a/testsuite/tests/determinism/determ003/all.T b/testsuite/tests/determinism/determ010/all.T
similarity index 50%
copy from testsuite/tests/determinism/determ003/all.T
copy to testsuite/tests/determinism/determ010/all.T
index c00544d..030868f 100644
--- a/testsuite/tests/determinism/determ003/all.T
+++ b/testsuite/tests/determinism/determ010/all.T
@@ -1,4 +1,4 @@
-test('determ003',
+test('determ010',
      extra_clean(['A.o', 'A.hi', 'A.normal.hi']),
      run_command,
-     ['$MAKE -s --no-print-directory determ003'])
+     ['$MAKE -s --no-print-directory determ010'])
diff --git a/testsuite/tests/determinism/determ010/determ010.stdout b/testsuite/tests/determinism/determ010/determ010.stdout
new file mode 100644
index 0000000..9a2bb82
--- /dev/null
+++ b/testsuite/tests/determinism/determ010/determ010.stdout
@@ -0,0 +1,2 @@
+[1 of 1] Compiling ShouldCompile    ( A.hs, A.o )
+[1 of 1] Compiling ShouldCompile    ( A.hs, A.o )



More information about the ghc-commits mailing list