Rodrigo Mesquita pushed to branch wip/romes/T25897 at Glasgow Haskell Compiler / GHC Commits: 6a35cfdf by Rodrigo Mesquita at 2025-07-21T14:41:45+01:00 hi: Don't sort re-exported module avails The order of the avails in a re-exported module should be the order in which they were exported from the original module. This order is already deterministic (inductively, since all base cases for module re-exports are either deterministic by being explicit or implictly sorted). If we have many imports for a re-exported module, like: module A (module B) where import B (b) import B (a) The order is unchanged from the order in which they are imported, which should be deterministic. We also add tests for this. Fixes #25897 - - - - - 15 changed files: - compiler/GHC/HsToCore/Docs.hs - + testsuite/tests/determinism/T25897d/A.hs - + testsuite/tests/determinism/T25897d/B.hs - + testsuite/tests/determinism/T25897d/C.hs - + testsuite/tests/determinism/T25897d/Makefile - + testsuite/tests/determinism/T25897d/T25897d.stdout - + testsuite/tests/determinism/T25897d/T25897e.stdout - + testsuite/tests/determinism/T25897d/all.T - testsuite/tests/showIface/HaddockIssue849.stdout - testsuite/tests/showIface/Makefile - + testsuite/tests/showIface/T25897.hs - + testsuite/tests/showIface/T25897.stdout - + testsuite/tests/showIface/T25897b.hs - + testsuite/tests/showIface/T25897c.hs - testsuite/tests/showIface/all.T Changes: ===================================== compiler/GHC/HsToCore/Docs.hs ===================================== @@ -173,7 +173,9 @@ mkDocStructureFromExportList mdl import_avails export_list = -> Avails -> DocStructureItem moduleExport alias avails = - DsiModExport (nubSortNE orig_names) (sortAvails (nubAvails avails)) + {- For module re-exports, use the original order (which is already deterministic) -} + DsiModExport (nubSortNE orig_names) + (DefinitelyDeterministicAvails (nubAvails avails)) where orig_names = M.findWithDefault aliasErr alias aliasMap aliasErr = error $ "mkDocStructureFromExportList: " ===================================== testsuite/tests/determinism/T25897d/A.hs ===================================== @@ -0,0 +1,12 @@ +module A + ( b, a, c + ) where + +a :: () +a = () + +b :: () +b = () + +c :: () +c = () ===================================== testsuite/tests/determinism/T25897d/B.hs ===================================== @@ -0,0 +1,8 @@ +module B + ( module A + ) where + +import A (a) +import A (b) +import A (c) + ===================================== testsuite/tests/determinism/T25897d/C.hs ===================================== @@ -0,0 +1,9 @@ +module B + ( module A + ) where + +-- The order of the imports is the order in the module re-exports +import A (a) +import A (c) +import A (b) + ===================================== testsuite/tests/determinism/T25897d/Makefile ===================================== @@ -0,0 +1,31 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +T25897d: + $(RM) A.hi A.o B.hi B.o + # Use -haddock to get docs: output in the interface file + '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -haddock B.hs + '$(TEST_HC)' --show-iface A.hi > A_clean_iface + '$(TEST_HC)' --show-iface B.hi > B_clean_iface + '$(TEST_HC)' $(TEST_HC_OPTS) -dinitial-unique=16777215 -dunique-increment=-1 -v0 -haddock A.hs B.hs -fforce-recomp + '$(TEST_HC)' --show-iface A.hi > A_dirty_iface + '$(TEST_HC)' --show-iface B.hi > B_dirty_iface + diff A_clean_iface A_dirty_iface + diff B_clean_iface B_dirty_iface + cat B_clean_iface | grep -A7 "documentation structure" + cat B_dirty_iface | grep -A7 "documentation structure" + +T25897e: + $(RM) A.hi A.o C.hi C.o + # Use -haddock to get docs: output in the interface file + '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -haddock C.hs + '$(TEST_HC)' --show-iface A.hi > A_clean_iface + '$(TEST_HC)' --show-iface C.hi > C_clean_iface + '$(TEST_HC)' $(TEST_HC_OPTS) -dinitial-unique=16777215 -dunique-increment=-1 -v0 -haddock A.hs C.hs -fforce-recomp + '$(TEST_HC)' --show-iface A.hi > A_dirty_iface + '$(TEST_HC)' --show-iface C.hi > C_dirty_iface + diff A_clean_iface A_dirty_iface + diff C_clean_iface C_dirty_iface + cat C_clean_iface | grep -A7 "documentation structure" + cat C_dirty_iface | grep -A7 "documentation structure" ===================================== testsuite/tests/determinism/T25897d/T25897d.stdout ===================================== @@ -0,0 +1,16 @@ + documentation structure: + re-exported module(s): [A] + [A.a, A.b, A.c] + named chunks: + haddock options: + language: + Nothing + language extensions: + documentation structure: + re-exported module(s): [A] + [A.a, A.b, A.c] + named chunks: + haddock options: + language: + Nothing + language extensions: ===================================== testsuite/tests/determinism/T25897d/T25897e.stdout ===================================== @@ -0,0 +1,16 @@ + documentation structure: + re-exported module(s): [A] + [A.a, A.c, A.b] + named chunks: + haddock options: + language: + Nothing + language extensions: + documentation structure: + re-exported module(s): [A] + [A.a, A.c, A.b] + named chunks: + haddock options: + language: + Nothing + language extensions: ===================================== testsuite/tests/determinism/T25897d/all.T ===================================== @@ -0,0 +1,2 @@ +test('T25897d', [extra_files(['A.hs', 'B.hs'])], makefile_test, ['T25897d']) +test('T25897e', [extra_files(['A.hs', 'C.hs'])], makefile_test, ['T25897e']) ===================================== testsuite/tests/showIface/HaddockIssue849.stdout ===================================== @@ -11,12 +11,12 @@ docs: re-exported module(s): [Data.Functor.Identity] [] re-exported module(s): [Data.Maybe] - [GHC.Internal.Data.Maybe.maybe, - GHC.Internal.Maybe.Maybe{GHC.Internal.Maybe.Maybe, - GHC.Internal.Maybe.Just, GHC.Internal.Maybe.Nothing}] + [GHC.Internal.Maybe.Maybe{GHC.Internal.Maybe.Maybe, + GHC.Internal.Maybe.Nothing, GHC.Internal.Maybe.Just}, + GHC.Internal.Data.Maybe.maybe] re-exported module(s): [Data.Tuple] - [GHC.Internal.Data.Tuple.curry, GHC.Internal.Data.Tuple.fst, - GHC.Internal.Data.Tuple.snd, GHC.Internal.Data.Tuple.swap, + [GHC.Internal.Data.Tuple.swap, GHC.Internal.Data.Tuple.curry, + GHC.Internal.Data.Tuple.fst, GHC.Internal.Data.Tuple.snd, GHC.Internal.Data.Tuple.uncurry] named chunks: haddock options: ===================================== testsuite/tests/showIface/Makefile ===================================== @@ -49,3 +49,7 @@ HaddockSpanIssueT24378: MagicHashInHaddocks: '$(TEST_HC)' $(TEST_HC_OPTS) -c -haddock MagicHashInHaddocks.hs '$(TEST_HC)' $(TEST_HC_OPTS) --show-iface MagicHashInHaddocks.hi | grep -A 200 'docs:' + +T25897: + '$(TEST_HC)' $(TEST_HC_OPTS) -haddock -v0 T25897.hs T25897b.hs T25897c.hs + '$(TEST_HC)' $(TEST_HC_OPTS) --show-iface T25897.hi | grep -A 4 'documentation structure:' ===================================== testsuite/tests/showIface/T25897.hs ===================================== @@ -0,0 +1,9 @@ +-- | Re-exports should display `b` first and `a` second, as per the explicit +-- exports of that module. +module T25897 + ( module T25897c + , module T25897b + ) where + +import T25897b +import T25897c ===================================== testsuite/tests/showIface/T25897.stdout ===================================== @@ -0,0 +1,5 @@ + documentation structure: + re-exported module(s): [T25897c] + [T25897c.d, T25897c.c] + re-exported module(s): [T25897b] + [T25897b.b, T25897b.a] ===================================== testsuite/tests/showIface/T25897b.hs ===================================== @@ -0,0 +1,14 @@ +-- #hide +module T25897b + ( b + , a + ) + where + +-- | This should appear in second, as per the explicit export list +a :: () +a = () + +-- | This should appear in first, as per the explicit export list +b :: () +b = () ===================================== testsuite/tests/showIface/T25897c.hs ===================================== @@ -0,0 +1,14 @@ +-- #hide +module T25897c + ( d + , c + ) + where + +-- | This should appear in second, as per the explicit export list +c :: () +c = () + +-- | This should appear in first, as per the explicit export list +d :: () +d = () ===================================== testsuite/tests/showIface/all.T ===================================== @@ -13,3 +13,4 @@ test('ReExports', extra_files(['Inner0.hs', 'Inner1.hs', 'Inner2.hs', 'Inner3.hs test('HaddockIssue849', normal, makefile_test, []) test('HaddockSpanIssueT24378', normal, makefile_test, []) test('MagicHashInHaddocks', normal, makefile_test, []) +test('T25897', extra_files(['T25897b.hs', 'T25897c.hs']), makefile_test, []) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a35cfdf06271018eebf3d75a70e9c70... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a35cfdf06271018eebf3d75a70e9c70... You're receiving this email because of your account on gitlab.haskell.org.