Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC Commits: ec0da2ed by fendor at 2026-11-30T13:24:11+01:00 Add testcase for one-shot and bytecode - - - - - 11 changed files: - testsuite/tests/bytecode/T25090/Makefile - testsuite/tests/bytecode/T25090/all.T - + testsuite/tests/driver/one-shot-boot/A.hs - + testsuite/tests/driver/one-shot-boot/B.hs - + testsuite/tests/driver/one-shot-boot/Fam.hs - + testsuite/tests/driver/one-shot-boot/M.hs - + testsuite/tests/driver/one-shot-boot/M.hs-boot - + testsuite/tests/driver/one-shot-boot/Main.hs - + testsuite/tests/driver/one-shot-boot/Makefile - + testsuite/tests/driver/one-shot-boot/all.T - + testsuite/tests/driver/one-shot-boot/one-shot-boot.stdout Changes: ===================================== testsuite/tests/bytecode/T25090/Makefile ===================================== @@ -16,6 +16,22 @@ T25090a: '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A.o -o exe ./exe +# Like T25090a, but without .gbc files: the bytecode for the splice has to be +# compiled from the Core stored in the interface files +# (-fwrite-if-simplified-core). See Note [Interface Files with Core Definitions]. +T25090c: + '$(TEST_HC)' -c -fwrite-if-simplified-core C.hs-boot + '$(TEST_HC)' -c -fwrite-if-simplified-core B.hs + '$(TEST_HC)' -c -fwrite-if-simplified-core C.hs + echo 'corrupt' > B.o + echo 'corrupt' > C.o + echo 'corrupt' > C.o-boot + '$(TEST_HC)' -c -fwrite-if-simplified-core D.hs + echo 'corrupt' > D.o + '$(TEST_HC)' -c -fwrite-if-simplified-core -fprefer-byte-code A.hs + '$(TEST_HC)' A.o -o exe + ./exe + T25090b: '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0 ./exe ===================================== testsuite/tests/bytecode/T25090/all.T ===================================== @@ -4,7 +4,7 @@ # the warning is added to the expected stderr for debugged builds. def test_T25090(name): assert_warn_spec = {'stderr': 'T25090-debug.stderr'} - extra_specs = assert_warn_spec if name == 'T25090a' and compiler_debugged() else {} + extra_specs = assert_warn_spec if name in ('T25090a', 'T25090c') and compiler_debugged() else {} return test(name, [extra_files(['A.hs', 'B.hs', 'C.hs-boot', 'C.hs', 'D.hs']), req_th, @@ -16,3 +16,4 @@ def test_T25090(name): test_T25090('T25090a') test_T25090('T25090b') +test_T25090('T25090c') ===================================== testsuite/tests/driver/one-shot-boot/A.hs ===================================== @@ -0,0 +1,8 @@ +{-# LANGUAGE TypeFamilies #-} +module A where + +import Fam +import {-# SOURCE #-} M (T) + +-- This instance mentions 'T' from M's boot file. +type instance F T = Int ===================================== testsuite/tests/driver/one-shot-boot/B.hs ===================================== @@ -0,0 +1,10 @@ +{-# LANGUAGE TypeFamilies #-} +module B where + +import Fam + +-- A second family-instance module for 'F', so that compiling M has to check +-- the consistency of A's and B's instances. That check forces 'T', which +-- makes GHC load M.hi-boot while compiling M itself. +-- See Note [Loading your own hi-boot file] in GHC.Iface.Load. +type instance F Bool = Char ===================================== testsuite/tests/driver/one-shot-boot/Fam.hs ===================================== @@ -0,0 +1,4 @@ +{-# LANGUAGE TypeFamilies #-} +module Fam where + +type family F a ===================================== testsuite/tests/driver/one-shot-boot/M.hs ===================================== @@ -0,0 +1,17 @@ +{-# LANGUAGE TypeFamilies #-} +module M where + +import Fam +import A () +import B () + +data T = MkT Int + +-- Also declared in M.hs-boot: loading M.hi-boot while compiling M must not +-- cause a duplicate instance error. +instance Show T where + show (MkT n) = "MkT " ++ show n + +-- Not part of M.hs-boot. Needs A's instance of 'F' to typecheck. +onlyInM :: F T +onlyInM = 42 ===================================== testsuite/tests/driver/one-shot-boot/M.hs-boot ===================================== @@ -0,0 +1,5 @@ +module M where + +data T + +instance Show T ===================================== testsuite/tests/driver/one-shot-boot/Main.hs ===================================== @@ -0,0 +1,8 @@ +module Main where + +import M + +main :: IO () +main = do + print (onlyInM :: Int) + print (MkT 1) ===================================== testsuite/tests/driver/one-shot-boot/Makefile ===================================== @@ -0,0 +1,28 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# One-shot compilation of a SOURCE-import cycle where type family instances +# mention the type from the boot file. Every module is compiled by its own +# invocation of GHC. +OneShotBootFamInst: + '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot + '$(TEST_HC)' $(TEST_HC_OPTS) -c A.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c B.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c Main.hs + '$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main + ./main + +# Like OneShotBootFamInst, but M and Main are compiled by the same invocation. +# Compiling M loads M.hi-boot (see Note [Loading your own hi-boot file]); that +# must not make Main see the boot interface of M instead of the real one. +OneShotBootSameInvocation: + '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot + '$(TEST_HC)' $(TEST_HC_OPTS) -c A.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c B.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs Main.hs + '$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main + ./main ===================================== testsuite/tests/driver/one-shot-boot/all.T ===================================== @@ -0,0 +1,14 @@ +# Compiling M loads M.hi-boot, which triggers a warnPprTrace in debug builds. +# See Note [Loading your own hi-boot file] in GHC.Iface.Load. +def test_one_shot_boot(name): + return test(name, + [extra_files(['Fam.hs', 'M.hs-boot', 'A.hs', 'B.hs', 'M.hs', 'Main.hs']), + js_skip, + when(compiler_debugged(), ignore_stderr), + use_specs(dict(stdout = 'one-shot-boot.stdout')), + ], + makefile_test, + []) + +test_one_shot_boot('OneShotBootFamInst') +test_one_shot_boot('OneShotBootSameInvocation') ===================================== testsuite/tests/driver/one-shot-boot/one-shot-boot.stdout ===================================== @@ -0,0 +1,2 @@ +42 +MkT 1 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ec0da2ed23f9f91cd7db674ce619ec20... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ec0da2ed23f9f91cd7db674ce619ec20... 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