Simon Jakobi pushed to branch wip/sjakobi/T27459 at Glasgow Haskell Compiler / GHC Commits: b85976c9 by Simon Jakobi at 2026-08-15T13:27:20+02:00 testsuite: Add determ025, an error-message determinism test All existing tests in testsuite/tests/determinism compare interface files; none check that error messages are independent of the order of Uniques. Add a test that compiles a module producing an ambiguity error with two different unique supplies and compares the errors. Context: #27459, where lazy unifier enumeration made instance lists in error messages potentially unique-ordered. Assisted-by: Claude Fable 5 - - - - - 480e2cdf by Simon Jakobi at 2026-08-15T14:20:28+02:00 Sort the out-of-scope instances in potential-instance lists With -fprint-potential-instances, the "...plus N instances involving out-of-scope types" list was printed in the enumeration order of the instance environment, which the previous commit made unique-dependent: the list's order varied both under -dinitial-unique/-dunique-increment perturbation and from run to run with --make -j. Sort it with fuzzyClsInstCmp, like the in-scope lists. Also extend determ025 to cover -fprint-potential-instances. Assisted-by: Claude Fable 5 - - - - - 4 changed files: - compiler/GHC/Tc/Errors/Ppr.hs - + testsuite/tests/determinism/determ025/A.hs - + testsuite/tests/determinism/determ025/Makefile - + testsuite/tests/determinism/determ025/all.T Changes: ===================================== compiler/GHC/Tc/Errors/Ppr.hs ===================================== @@ -4999,10 +4999,12 @@ potentials_msg_with_options n_show_matches = 3 n_show_unifiers = 2 - (in_scope_matches, not_in_scope_matches) = partition inst_in_scope matches - (in_scope_unifiers, not_in_scope_unifiers) = partition inst_in_scope unifiers - sorted_matches = sortBy fuzzyClsInstCmp in_scope_matches - sorted_unifiers = sortBy fuzzyClsInstCmp in_scope_unifiers + -- Sort before partitioning so that the out-of-scope lists are also + -- shown in a deterministic order (#27459). + (sorted_matches, not_in_scope_matches) + = partition inst_in_scope (sortBy fuzzyClsInstCmp matches) + (sorted_unifiers, not_in_scope_unifiers) + = partition inst_in_scope (sortBy fuzzyClsInstCmp unifiers) (show_these_matches, show_these_unifiers) | show_all_potentials = (sorted_matches, sorted_unifiers) | otherwise = (take n_show_matches sorted_matches ===================================== testsuite/tests/determinism/determ025/A.hs ===================================== @@ -0,0 +1,13 @@ +module A where + +-- An ambiguity error whose message lists potential instances, both in-scope +-- and (via the instance-only imports) involving out-of-scope types. + +import Data.Functor.Const () +import Data.Functor.Identity () +import Data.Monoid () +import Data.Proxy () +import Data.Ord () + +v :: Int +v = foldr (+) 0 (pure 21) ===================================== testsuite/tests/determinism/determ025/Makefile ===================================== @@ -0,0 +1,18 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# Check that error messages don't depend on the order of Uniques (#27459): +# compile a module producing an ambiguity error with two unique supplies +# and compare the errors. +determ025: + $(RM) A.hi A.o + -'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -dinitial-unique=0 -dunique-increment=1 A.hs 2> A.err.normal + $(RM) A.hi A.o + -'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -dinitial-unique=16777215 -dunique-increment=-1 A.hs 2> A.err.reversed + diff A.err.normal A.err.reversed + $(RM) A.hi A.o + -'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -fprint-potential-instances -dinitial-unique=0 -dunique-increment=1 A.hs 2> A.err.all.normal + $(RM) A.hi A.o + -'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -fprint-potential-instances -dinitial-unique=16777215 -dunique-increment=-1 A.hs 2> A.err.all.reversed + diff A.err.all.normal A.err.all.reversed ===================================== testsuite/tests/determinism/determ025/all.T ===================================== @@ -0,0 +1,3 @@ +test('determ025', + [extra_files(['A.hs'])], + makefile_test, ['determ025']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/62cc6594f5e31e20dc473c3d7e9f161... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/62cc6594f5e31e20dc473c3d7e9f161... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Simon Jakobi (@sjakobi)