[Git][ghc/ghc][wip/unload-strategy] 13 commits: Identify Linkable with fingerprints of their contents rather than modtimes
by Zubin (@wz1000) 23 Nov '26
by Zubin (@wz1000) 23 Nov '26
23 Nov '26
Zubin pushed to branch wip/unload-strategy at Glasgow Haskell Compiler / GHC
Commits:
fb955b41 by Zubin Duggal at 2026-11-23T15:40:35+05:30
Identify Linkable with fingerprints of their contents rather than modtimes
- - - - -
4ea75aad by Zubin Duggal at 2026-11-23T15:40:35+05:30
Linker cleanup
delete a bunch of unused functions
- - - - -
f287326b by Zubin Duggal at 2026-11-23T15:40:35+05:30
Record constituent hashes for bytecode libraries
A bytecode library now records the combined hash of its constituents,
so relinking can be skipped when they haven't changed.
- - - - -
c3aa9324 by Zubin Duggal at 2026-11-23T15:40:35+05:30
bytecode: Give persistent bytecode files a fixed-size header with a hash
The header of .gbc and .bytecodelib files now consists of the magic word,
the compiler version and a hash, all with fixed-length encodings. The hash
is the gbc_hash of a bytecode file, or the inputs hash of a bytecode
library.
readBinByteCodeHash and readBytecodeLibInputsHash now read only the header
rather than the whole file. The version is written as its four numeric
components instead of as a string.
- - - - -
42a0bc2d by Zubin Duggal at 2026-11-23T15:40:35+05:30
driver: Refresh ms_bytecode_date when reusing a ModSummary
- - - - -
004c85d3 by Zubin Duggal at 2026-11-23T15:44:57+05:30
bytecode: Treat persistent bytecode files with a bad header as stale
- - - - -
58ad1f01 by Zubin Duggal at 2026-11-23T15:48:31+05:30
bytecode: Record the inputs hash in BytecodeLib
-------------------------
Metric Increase:
MultiLayerModulesRecomp
MultiLayerModulesTH_OneShot
-------------------------
- - - - -
ea8eb3b9 by Zubin Duggal at 2026-11-23T15:48:36+05:30
linker: refactor loader so that object suffixes get passed through in a sane way
- - - - -
814769c7 by Zubin Duggal at 2026-11-23T15:48:36+05:30
linker: Automatically reload stale linkables
Linked BCOs contain direct references to closures, so replacing only a
changed module can leave stale references in other modules. Take
-- A.hs
f = 1
-- B.hs
import A
g = f + 1
After loading A and B, change A so that f = 2 and recompile it. B does
not need to be recompiled, but its loaded BCO still refers to the old
closure for f. The next splice should see f = 2 and g = 3. To get the
correct result, we have to *reload* B, even though we didn't need to
recompile it.
The GHC driver calls unload before each upsweep, which unloads
everything, so this does not arise during an ordinary GHCi reload. API
clients such as HLS may instead want to keep the loader state while
recompiling individual modules. Forcing them to unload everything or
carefully keep track of what to unload is not ideal.
Now we automatically reload stale linkables, so that if we are asked
to link a module whose code has changed, the old code, and everything
that refers to it, is dropped and reloaded. See
Note [Automatically reloading stale linkables].
Dropped objects are now purged, not unloaded, so values built by the
old code and computations still using it keep working. The object
stays in memory, but new code will not be able to link against it.
This is a change in behaviour, objects were previously only ever
unloaded, all at once, in unload. See
Note [Unloading vs purging objects]
Fixes #27606
- - - - -
1a5173fb by Zubin Duggal at 2026-11-23T15:48:36+05:30
linker: Add unloadModules
Drop the given modules and every loaded module that transitively
refers to them. Reloading stale code does not need this, it happens
automatically. This is for API clients dropping modules they no
longer need. Interactive modules are ignored.
See Note [Automatically reloading stale linkables] in GHC.Linker.Loader
See Note [Unloading vs purging objects] in GHC.Runtime.Interpreter
- - - - -
9ee945cf by Zubin Duggal at 2026-11-23T15:48:37+05:30
iserv: Add a PurgeObj message
purgeObj no longer falls back to unloading on external interpreters.
See Note [Unloading vs purging objects] in GHC.Runtime.Interpreter.
- - - - -
25872c2c by Zubin Duggal at 2026-11-23T15:48:37+05:30
linker: Remove static pointer table entries when dropping modules
Entries were added by bytecode modules, but never removed. This meant
that every reload of a module with static forms leaked its old entries
and kept the old code alive, including in GHCi with :reload.
loaded_spt_keys now records the keys each loaded bytecode module
inserted. dropModules and unload remove them. We also add a new
RemoveSptEntry message to support this operation with the external
interpreter.
Object code manages its own entries with initialisers and finalisers,
so it was not changed.
Fixes #27740
- - - - -
97bd5029 by Zubin Duggal at 2026-11-23T15:48:37+05:30
Introduce -funload-strategy
When unloading object code, we have a choice to make. Do we call
purgeObj or unloadObj?
purgeObj clears the symbol tables associated with an object, so that
future objects can't link against it, but the object stays in memory
unloadObj does the above, but it also marks the object as needing to be
unloaded, so at some point in a future GC, the RTS may notice that it is
no longer used, and if so, unload it entirely, freeing up the memory.
Ideally we would always unload, but a number of bugs with the
implementation of unloadObj mean that it is fragile on many platforms.
This is documented in Note [Unloading vs purging objects]. So on these
platforms we purge instead.
We introduce the -funload-strategy flag, so that users can opt into
purging/unloading on platforms where we make the other choice by
default.
The distinction is moot when we are using the dynamic RTS, we don't do
either then.
Fixes #27741
- - - - -
51 changed files:
- + changelog.d/unload-strategy
- compiler/GHC.hs
- compiler/GHC/ByteCode/Binary.hs
- compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/Driver/Config/Interpreter.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Linker/ByteCode.hs
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Linker/Types.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/Init.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- compiler/GHC/Unit/Finder.hs
- docs/users_guide/ghci.rst
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/ObjLink.hs
- libraries/ghci/GHCi/Run.hs
- libraries/ghci/GHCi/StaticPtrTable.hs
- testsuite/tests/driver/bytecode-object/Makefile
- testsuite/tests/driver/bytecode-object/all.T
- + testsuite/tests/driver/bytecode-object/bytecode_object27.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object28.script
- + testsuite/tests/driver/bytecode-object/bytecode_object28.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object29.stdout
- + testsuite/tests/driver/recomp023/M.hs
- + testsuite/tests/driver/recomp023/M2.hs
- + testsuite/tests/driver/recomp023/Makefile
- + testsuite/tests/driver/recomp023/all.T
- + testsuite/tests/driver/recomp023/recomp023.stdout
- + testsuite/tests/ghc-api/T27606/B.hs
- + testsuite/tests/ghc-api/T27606/T27606a.hs
- + testsuite/tests/ghc-api/T27606/T27606a.stdout
- + testsuite/tests/ghc-api/T27606/T27606b.hs
- + testsuite/tests/ghc-api/T27606/T27606b.stdout
- + testsuite/tests/ghc-api/T27606/T27606c.hs
- + testsuite/tests/ghc-api/T27606/T27606c.stdout
- + testsuite/tests/ghc-api/T27606/T27606c_purge.stdout
- + testsuite/tests/ghc-api/T27606/T27606d.hs
- + testsuite/tests/ghc-api/T27606/T27606d.stdout
- + testsuite/tests/ghc-api/T27606/T27606e.hs
- + testsuite/tests/ghc-api/T27606/T27606e.stdout
- + testsuite/tests/ghc-api/T27606/all.T
- + testsuite/tests/ghc-api/T27740.hs
- + testsuite/tests/ghc-api/T27740.stdout
- testsuite/tests/ghc-api/all.T
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d7dc1974a79380adcdb756ab5bfe11…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d7dc1974a79380adcdb756ab5bfe11…
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
1
0
[Git][ghc/ghc][wip/linkable-hashes] 7 commits: Identify Linkable with fingerprints of their contents rather than modtimes
by Zubin (@wz1000) 23 Nov '26
by Zubin (@wz1000) 23 Nov '26
23 Nov '26
Zubin pushed to branch wip/linkable-hashes at Glasgow Haskell Compiler / GHC
Commits:
fb955b41 by Zubin Duggal at 2026-11-23T15:40:35+05:30
Identify Linkable with fingerprints of their contents rather than modtimes
- - - - -
4ea75aad by Zubin Duggal at 2026-11-23T15:40:35+05:30
Linker cleanup
delete a bunch of unused functions
- - - - -
f287326b by Zubin Duggal at 2026-11-23T15:40:35+05:30
Record constituent hashes for bytecode libraries
A bytecode library now records the combined hash of its constituents,
so relinking can be skipped when they haven't changed.
- - - - -
c3aa9324 by Zubin Duggal at 2026-11-23T15:40:35+05:30
bytecode: Give persistent bytecode files a fixed-size header with a hash
The header of .gbc and .bytecodelib files now consists of the magic word,
the compiler version and a hash, all with fixed-length encodings. The hash
is the gbc_hash of a bytecode file, or the inputs hash of a bytecode
library.
readBinByteCodeHash and readBytecodeLibInputsHash now read only the header
rather than the whole file. The version is written as its four numeric
components instead of as a string.
- - - - -
42a0bc2d by Zubin Duggal at 2026-11-23T15:40:35+05:30
driver: Refresh ms_bytecode_date when reusing a ModSummary
- - - - -
004c85d3 by Zubin Duggal at 2026-11-23T15:44:57+05:30
bytecode: Treat persistent bytecode files with a bad header as stale
- - - - -
58ad1f01 by Zubin Duggal at 2026-11-23T15:48:31+05:30
bytecode: Record the inputs hash in BytecodeLib
-------------------------
Metric Increase:
MultiLayerModulesRecomp
MultiLayerModulesTH_OneShot
-------------------------
- - - - -
21 changed files:
- compiler/GHC/ByteCode/Binary.hs
- compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Linker/ByteCode.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Linker/Types.hs
- compiler/GHC/Unit/Finder.hs
- testsuite/tests/driver/bytecode-object/Makefile
- testsuite/tests/driver/bytecode-object/all.T
- + testsuite/tests/driver/bytecode-object/bytecode_object27.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object28.script
- + testsuite/tests/driver/bytecode-object/bytecode_object28.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object29.stdout
- + testsuite/tests/driver/recomp023/M.hs
- + testsuite/tests/driver/recomp023/M2.hs
- + testsuite/tests/driver/recomp023/Makefile
- + testsuite/tests/driver/recomp023/all.T
- + testsuite/tests/driver/recomp023/recomp023.stdout
Changes:
=====================================
compiler/GHC/ByteCode/Binary.hs
=====================================
@@ -66,6 +66,7 @@ type BytecodeLib = BytecodeLibX (Maybe InterpreterLibrary)
-- | A bytecode library is a collection of CompiledByteCode objects and a .so file containing the combination of foreign stubs
data BytecodeLibX a = BytecodeLib {
bytecodeLibUnitId :: UnitId,
+ bytecodeLibInputsHash :: Fingerprint, -- ^ See Note [Hash of bytecode libs] in GHC.ByteCode.Serialize
bytecodeLibFiles :: [CompiledByteCode],
bytecodeLibForeign :: a -- A library file containing the combination of foreign stubs. (Ie arising from CApiFFI)
}
@@ -113,12 +114,14 @@ instance Binary OnDiskModuleByteCode where
instance Binary OnDiskBytecodeLib where
get bh = do
bytecodeLibUnitId <- get bh
+ bytecodeLibInputsHash <- get bh
bytecodeLibFiles <- get bh
bytecodeLibForeign <- get bh
pure BytecodeLib {..}
put_ bh BytecodeLib {..} = do
put_ bh bytecodeLibUnitId
+ put_ bh bytecodeLibInputsHash
put_ bh bytecodeLibFiles
put_ bh bytecodeLibForeign
=====================================
compiler/GHC/ByteCode/Serialize.hs
=====================================
@@ -6,7 +6,7 @@
{- | This module implements the serialization of bytecode objects to and from disk.
-}
module GHC.ByteCode.Serialize
- ( writeBinByteCode, readBinByteCode, readOnDiskModuleByteCode
+ ( writeBinByteCode, readBinByteCode, readBinByteCodeHash, readOnDiskModuleByteCode
, ModuleByteCode(..)
, BytecodeLibX(..)
, BytecodeLib
@@ -15,6 +15,8 @@ module GHC.ByteCode.Serialize
, InterpreterLibraryContents(..)
, writeBytecodeLib
, readBytecodeLib
+ , readBytecodeLibInputsHash
+ , fingerprintBytecodeLibInputs
, mkModuleByteCode
, fingerprintModuleByteCodeContents
, decodeOnDiskModuleByteCode
@@ -27,22 +29,25 @@ import GHC.Prelude
import GHC.ByteCode.Binary
import GHC.ByteCode.Recomp.Binary (computeFingerprint)
import GHC.ByteCode.Types
+import GHC.Data.Maybe (rightToMaybe)
import GHC.Driver.DynFlags
import GHC.Driver.Env
import GHC.Iface.Binary
import GHC.Iface.Recomp.Binary (putNameLiterally)
import GHC.Linker.Types
-import GHC.Settings.Constants (hiVersion)
import GHC.Unit.Types
import GHC.Utils.Binary
-import GHC.Utils.Fingerprint (Fingerprint)
+import GHC.Utils.Exception (tryIO)
+import GHC.Utils.Fingerprint (Fingerprint(..), fingerprintFingerprints)
import GHC.Utils.Logger
import GHC.Utils.Panic
import GHC.Utils.TmpFs
+import GHC.Version (cProjectVersionInt, cProjectPatchLevel1, cProjectPatchLevel2)
import Data.ByteString (ByteString)
import Data.ByteString qualified as BS
import Data.Char (ord)
+import Data.List (intercalate, sort)
import Data.Traversable
import Data.Word
import System.Directory
@@ -84,6 +89,7 @@ The ticket where bytecode objects were dicussed is #26298
See Note [-fwrite-byte-code is not the default]
See Note [Recompilation avoidance with bytecode objects]
See Note [Persistent bytecode file headers]
+See Note [Hash of bytecode libs]
Note [Persistent bytecode file headers]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -92,30 +98,59 @@ are version-specific binary formats. Without a small file-level header, stale
or corrupt files are only discovered once we start deserialising the payload,
which can lead to confusing failures.
-To make these failures explicit, we write a file-kind-specific magic word and
-the current `hiVersion` ahead of the binary payload. Readers validate this
-header before setting up the normal `Name`/`FastString` deserialisation
-machinery. This follows the same approach as normal interface files.
+To make these failures explicit, we write a header ahead of the binary payload:
+
+ * a file-kind-specific magic word,
+ * the version of the compiler (`PersistentBytecodeVersion`),
+ * a hash: the `gbc_hash` of a bytecode file, or the inputs hash of a
+ bytecode library (see Note [Hash of bytecode libs]).
+
+We ensure everthing has a fixed length encoding (see
+`persistentBytecodeHeaderSize`, so that `readPersistentBytecodeHash` can read
+the hash without reading the rest of the file.
+
+Note [Hash of bytecode libs]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+A bytecode library records the combined hash of its constituents, so
+that relinking can be skipped when they haven't changed.
+
+We can't hash the library file itself: we would have to build the
+library to know which hash to expect. So we compare the inputs.
+
+The hash is part of the file header, see Note [Persistent bytecode file
+headers]. The constituent hashes are sorted before they are combined, so
+the order of the modules doesn't matter.
-}
+-- | The 'bytecodeLibInputsHash' of a bytecode library, given the hash of each
+-- constituent.
+-- See Note [Hash of bytecode libs]
+fingerprintBytecodeLibInputs :: [Fingerprint] -> Fingerprint
+fingerprintBytecodeLibInputs = fingerprintFingerprints . sort
+
writeBytecodeLib :: BytecodeLib -> FilePath -> IO ()
writeBytecodeLib lib path = do
odbco <- encodeBytecodeLib lib
createDirectoryIfMissing True (takeDirectory path)
bh' <- openBinMem initBinMemSize
bh <- addBinNameWriter bh'
- writePersistentBytecodeHeader BytecodeLibraryFile bh
+ writePersistentBytecodeHeader BytecodeLibraryFile (bytecodeLibInputsHash lib) bh
putWithUserData QuietBinIFace NormalCompression bh odbco
writeBinMem bh path
readBytecodeLib :: HscEnv -> FilePath -> IO OnDiskBytecodeLib
readBytecodeLib hsc_env path = do
bh' <- readBinMem path
- readPersistentBytecodeHeader BytecodeLibraryFile path bh'
+ _inputs_hash <- readPersistentBytecodeHeader BytecodeLibraryFile path bh'
bh <- addBinNameReader (hsc_NC hsc_env) bh'
res <- getWithUserData (hsc_NC hsc_env) bh
pure res
+-- | 'Nothing' if the file can't be read or its header is not valid.
+-- See Note [Hash of bytecode libs]
+readBytecodeLibInputsHash :: FilePath -> IO (Maybe Fingerprint)
+readBytecodeLibInputsHash = readPersistentBytecodeHash BytecodeLibraryFile
+
-- | Convert an 'OnDiskModuleByteCode' to an 'ModuleByteCode'.
-- 'OnDiskModuleByteCode' is the representation which we read from a file,
-- the 'ModuleByteCode' is the representation which is manipulated by program logic.
@@ -139,6 +174,7 @@ decodeOnDiskBytecodeLib hsc_env odbco = do
foreign_contents <- traverse (writeInterpreterLibraryFile (hsc_logger hsc_env) (hsc_tmpfs hsc_env) (tmpDir (hsc_dflags hsc_env))) (bytecodeLibForeign odbco)
pure $ BytecodeLib {
bytecodeLibUnitId = bytecodeLibUnitId odbco,
+ bytecodeLibInputsHash = bytecodeLibInputsHash odbco,
bytecodeLibFiles = bytecodeLibFiles odbco,
bytecodeLibForeign = foreign_contents
}
@@ -148,6 +184,7 @@ encodeBytecodeLib (BytecodeLib {..}) = do
foreign_contents <- traverse readInterpreterLibraryFile bytecodeLibForeign
pure $ BytecodeLib {
bytecodeLibUnitId = bytecodeLibUnitId,
+ bytecodeLibInputsHash = bytecodeLibInputsHash,
bytecodeLibFiles = bytecodeLibFiles,
bytecodeLibForeign = foreign_contents
}
@@ -200,10 +237,15 @@ readBinByteCode hsc_env f = do
odbco <- readOnDiskModuleByteCode hsc_env f
decodeOnDiskModuleByteCode hsc_env odbco
+-- | Read the hash of a bytecode file, without reading the rest of the file.
+-- 'Nothing' if the file can't be read or its header is not valid.
+readBinByteCodeHash :: FilePath -> IO (Maybe Fingerprint)
+readBinByteCodeHash = readPersistentBytecodeHash ModuleByteCodeFile
+
readOnDiskModuleByteCode :: HscEnv -> FilePath -> IO OnDiskModuleByteCode
readOnDiskModuleByteCode hsc_env f = do
bh' <- readBinMem f
- readPersistentBytecodeHeader ModuleByteCodeFile f bh'
+ _hash <- readPersistentBytecodeHeader ModuleByteCodeFile f bh'
bh <- addBinNameReader (hsc_NC hsc_env) bh'
getWithUserData (hsc_NC hsc_env) bh
@@ -214,7 +256,7 @@ writeBinByteCode f cbc = do
bh' <- openBinMem initBinMemSize
bh <- addBinNameWriter bh'
odbco <- encodeOnDiskModuleByteCode cbc
- writePersistentBytecodeHeader ModuleByteCodeFile bh
+ writePersistentBytecodeHeader ModuleByteCodeFile (gbc_hash cbc) bh
putWithUserData QuietBinIFace NormalCompression bh odbco
writeBinMem bh f
@@ -242,30 +284,82 @@ data PersistentBytecodeFile
= ModuleByteCodeFile
| BytecodeLibraryFile
+-- | The version of the compiler: major, minor, patch1, patch2
+data PersistentBytecodeVersion
+ = PersistentBytecodeVersion !Word32 !Word32 !Word32 !Word32
+ deriving Eq
+
+instance Binary PersistentBytecodeVersion where
+ put_ bh (PersistentBytecodeVersion a b c d) =
+ mapM_ (put_ bh . FixedLengthEncoding) [a, b, c, d]
+ get bh = PersistentBytecodeVersion <$> field <*> field <*> field <*> field
+ where field = unFixedLength <$> get bh
+
+persistentBytecodeVersion :: PersistentBytecodeVersion
+persistentBytecodeVersion =
+ PersistentBytecodeVersion
+ (version_int `div` 100) (version_int `mod` 100)
+ (read cProjectPatchLevel1) (read cProjectPatchLevel2)
+ where
+ version_int = read cProjectVersionInt
+
+showPersistentBytecodeVersion :: PersistentBytecodeVersion -> String
+showPersistentBytecodeVersion (PersistentBytecodeVersion a b c d) =
+ intercalate "." (map show [a, b, c, d])
+
+-- | The size in bytes of the header: the magic word, the version and the hash.
-- See Note [Persistent bytecode file headers]
-writePersistentBytecodeHeader :: PersistentBytecodeFile -> WriteBinHandle -> IO ()
-writePersistentBytecodeHeader file_kind bh = do
- put_ bh (persistentBytecodeMagic file_kind)
- put_ bh (show hiVersion)
+persistentBytecodeHeaderSize :: Int
+persistentBytecodeHeaderSize = 4 + 4 * 4 + 2 * 8
-readPersistentBytecodeHeader :: PersistentBytecodeFile -> FilePath -> ReadBinHandle -> IO ()
-readPersistentBytecodeHeader file_kind path bh = do
- let mismatch what expected actual =
- throwGhcExceptionIO $ ProgramError $
- persistentBytecodeFileDescription file_kind ++ " header mismatch in " ++ path ++
- ": " ++ what ++ " (expected " ++ expected ++ ", got " ++ actual ++ ")"
+-- See Note [Persistent bytecode file headers]
+writePersistentBytecodeHeader :: PersistentBytecodeFile -> Fingerprint -> WriteBinHandle -> IO ()
+writePersistentBytecodeHeader file_kind (Fingerprint w1 w2) bh = do
+ put_ bh (persistentBytecodeMagic file_kind)
+ put_ bh persistentBytecodeVersion
+ put_ bh (FixedLengthEncoding w1)
+ put_ bh (FixedLengthEncoding w2)
+-- | Read only the header of a persistent bytecode file.
+getPersistentBytecodeHeader :: PersistentBytecodeFile -> ReadBinHandle -> IO (Either String Fingerprint)
+getPersistentBytecodeHeader file_kind bh = do
magic <- get bh
- let expected_magic = persistentBytecodeMagic file_kind
- if unFixedLength magic == unFixedLength expected_magic
- then pure ()
- else mismatch "magic" (show $ unFixedLength expected_magic) (show $ unFixedLength magic)
-
- version <- get bh
- let expected_version = show hiVersion
- if version == expected_version
- then pure ()
- else mismatch "version" expected_version version
+ if unFixedLength magic /= unFixedLength expected_magic
+ then mismatch "magic" (show $ unFixedLength expected_magic) (show $ unFixedLength magic)
+ else do
+ version <- get bh
+ if version /= persistentBytecodeVersion
+ then mismatch "version"
+ (showPersistentBytecodeVersion persistentBytecodeVersion)
+ (showPersistentBytecodeVersion version)
+ else do
+ w1 <- get bh
+ w2 <- get bh
+ pure $ Right (Fingerprint (unFixedLength w1) (unFixedLength w2))
+ where
+ expected_magic = persistentBytecodeMagic file_kind
+ mismatch what expected actual =
+ pure $ Left $ what ++ " (expected " ++ expected ++ ", got " ++ actual ++ ")"
+
+-- | Validate the header of a persistent bytecode file, and return its hash.
+readPersistentBytecodeHeader :: PersistentBytecodeFile -> FilePath -> ReadBinHandle -> IO Fingerprint
+readPersistentBytecodeHeader file_kind path bh = do
+ r <- getPersistentBytecodeHeader file_kind bh
+ case r of
+ Right hash -> pure hash
+ Left what -> throwGhcExceptionIO $ ProgramError $
+ persistentBytecodeFileDescription file_kind ++ " header mismatch in " ++ path ++
+ ": " ++ what
+
+-- | Read the hash from the header of a persistent bytecode file, without
+-- reading the rest of the file. 'Nothing' if the file can't be read or its
+-- header is not valid.
+readPersistentBytecodeHash :: PersistentBytecodeFile -> FilePath -> IO (Maybe Fingerprint)
+readPersistentBytecodeHash file_kind path = do
+ r <- tryIO $ readBinMemN persistentBytecodeHeaderSize path
+ case r of
+ Right (Just bh) -> rightToMaybe <$> getPersistentBytecodeHeader file_kind bh
+ _ -> pure Nothing
persistentBytecodeFileDescription :: PersistentBytecodeFile -> String
persistentBytecodeFileDescription ModuleByteCodeFile = "bytecode file"
=====================================
compiler/GHC/Driver/Downsweep.hs
=====================================
@@ -1835,12 +1835,14 @@ checkSummaryHash
obj_timestamp <- modificationTimeIfExists (ml_obj_file_ospath location)
hi_timestamp <- modificationTimeIfExists (ml_hi_file_ospath location)
hie_timestamp <- modificationTimeIfExists (ml_hie_file_ospath location)
+ bytecode_timestamp <- modificationTimeIfExists (ml_bytecode_file_ospath location)
return $ Right
( old_summary
{ ms_obj_date = obj_timestamp
, ms_iface_date = hi_timestamp
, ms_hie_date = hie_timestamp
+ , ms_bytecode_date = bytecode_timestamp
}
)
=====================================
compiler/GHC/Driver/Main/Compile.hs
=====================================
@@ -131,7 +131,6 @@ import GHC.Data.OsPath (unsafeEncodeUtf)
import qualified GHC.Data.Stream as Stream
-import Data.Traversable (for)
import Control.Monad
import Data.IORef
import System.Directory
@@ -140,7 +139,6 @@ import Data.Map (Map)
import qualified Data.Set as S
import GHC.Unit.Module.WholeCoreBindings
import GHC.Types.TypeEnv
-import Data.Time
import System.IO.Unsafe ( unsafeInterleaveIO )
import GHC.Iface.Env ( trace_if )
@@ -217,12 +215,7 @@ loadIfaceByteCode hsc_env iface location type_env =
where
compile decls = do
bco <- compileWholeCoreBindings hsc_env type_env decls
- linkable $ pure $ DotGBC bco
-
- linkable parts = do
- if_time <- modificationTimeIfExists (ml_hi_file_ospath location)
- time <- maybe getCurrentTime pure if_time
- return $! Linkable time (mi_module iface) parts
+ return $! Linkable (gbc_hash bco) (mi_module iface) (pure (DotGBC bco))
loadIfaceByteCodeLazy ::
HscEnv ->
@@ -239,12 +232,7 @@ loadIfaceByteCodeLazy hsc_env iface location type_env =
compile decls = do
bco <- unsafeInterleaveIO $ do
compileWholeCoreBindings hsc_env type_env decls
- linkable bco
-
- linkable parts = do
- if_time <- modificationTimeIfExists (ml_hi_file_ospath location)
- time <- maybe getCurrentTime pure if_time
- return $!Linkable time (mi_module iface) parts
+ return $! Linkable (gbc_hash bco) (mi_module iface) bco
-- | If the 'Linkable' contains Core bindings loaded from an interface, replace
-- them with a lazy IO thunk that compiles them to bytecode and foreign objects,
@@ -282,12 +270,13 @@ initWholeCoreBindings hsc_env iface details (RecompLinkables bc o) = do
go :: RecompBytecodeLinkable -> IO (Maybe (LinkableWith ModuleByteCode))
go (NormalLinkable l) = pure l
- go (WholeCoreBindingsLinkable wcbl) =
- fmap Just $ for wcbl $ \wcb -> do
- add_iface_to_hpt iface details hsc_env
- bco <- unsafeInterleaveIO $ do
- compileWholeCoreBindings hsc_env type_env wcb
- pure bco
+ go (WholeCoreBindingsLinkable wcbl) = do
+ add_iface_to_hpt iface details hsc_env
+ bco <- unsafeInterleaveIO $ do
+ compileWholeCoreBindings hsc_env type_env (linkableParts wcbl)
+ -- We need to fill in the hash over here, replacing the panic
+ -- because WholeCoreBindingsLinkable doesn't have a hash.
+ pure $ Just $ Linkable (gbc_hash bco) (linkableModule wcbl) bco
-- | Hydrate interface Core bindings and compile them to bytecode.
--
@@ -842,11 +831,7 @@ make user's opt into writing the files.
generateAndWriteByteCodeLinkable :: HscEnv -> CgInteractiveGuts -> ModLocation -> IO (LinkableWith ModuleByteCode)
generateAndWriteByteCodeLinkable hsc_env cgguts mod_location = do
bco_object <- generateAndWriteByteCode hsc_env cgguts mod_location
- -- Either, get the same time as the .gbc file if it exists, or just the current time.
- -- It's important the time of the linkable matches the time of the .gbc file for recompilation
- -- checking.
- bco_time <- maybe getCurrentTime pure =<< modificationTimeIfExists (ml_bytecode_file_ospath mod_location)
- return $ mkOnlyModuleByteCodeLinkable bco_time bco_object
+ return $ mkOnlyModuleByteCodeLinkable bco_object
mkModuleByteCode :: HscEnv -> Module -> ModLocation -> CgInteractiveGuts -> IO ModuleByteCode
mkModuleByteCode hsc_env mod mod_location cgguts = do
@@ -861,9 +846,8 @@ generateFreshByteCodeLinkable :: HscEnv
-> ModLocation
-> IO Linkable
generateFreshByteCodeLinkable hsc_env mod_name cgguts mod_location = do
- bco_time <- getCurrentTime
bco_object <- mkModuleByteCode hsc_env (mkHomeModule (hsc_home_unit hsc_env) mod_name) mod_location cgguts
- return $ mkModuleByteCodeLinkable bco_time bco_object
+ return $ mkModuleByteCodeLinkable bco_object
------------------------------
hscCompileCmmFile :: HscEnv -> FilePath -> FilePath -> FilePath -> IO (Maybe FilePath)
=====================================
compiler/GHC/Driver/Main/Passes.hs
=====================================
@@ -153,7 +153,7 @@ import GHC.Types.Unique.Set
import GHC.Types.Var.Env ( mkEmptyTidyEnv )
import GHC.Types.Var.Set
-import GHC.Utils.Fingerprint ( Fingerprint )
+import GHC.Utils.Fingerprint ( Fingerprint, getFileHash )
import GHC.Utils.Panic
import GHC.Utils.Error
import GHC.Utils.Outputable
@@ -168,8 +168,8 @@ import GHC.Data.Maybe
import qualified GHC.Data.Strict as Strict
import qualified Data.Array as A
-import Data.List ( nub, isPrefixOf, partition )
import qualified Data.List.NonEmpty as NE
+import Data.List ( nub, isPrefixOf, partition )
import Control.Monad
import Data.IORef
import System.FilePath as FilePath
@@ -180,7 +180,6 @@ import Data.Set (Set)
import Control.DeepSeq (force)
import Control.Exception as E (mask_, finally)
import Data.List.NonEmpty (NonEmpty ((:|)))
-import Data.Time
import System.IO.Unsafe ( unsafeInterleaveIO )
import GHC.Iface.Env ( trace_if )
@@ -707,15 +706,24 @@ checkObjects dflags mb_old_linkable summary = do
-- Not in dynamic-too mode
else k
+ -- We check by date first, even though we have the hash
+ -- If a compilation is interupted after writing the .hi
+ -- but before writing the .o, then we catch this through
+ -- modtimes.
+ -- If the object file is newer than the .hi file, and the
+ -- .hi file is up to date, we also assume the object file
+ -- is up to date.
checkDynamicObj $
case (,) <$> mb_obj_date <*> mb_if_date of
Just (obj_date, if_date)
- | obj_date >= if_date ->
+ | obj_date >= if_date -> do
+ disk_hash <- getFileHash obj_fn
case mb_old_linkable of
Just old_linkable
- | linkableIsNativeCodeOnly old_linkable, linkableTime old_linkable == obj_date
+ | linkableIsNativeCodeOnly old_linkable
+ , linkableHash old_linkable == disk_hash
-> return $ UpToDateItem old_linkable
- _ -> UpToDateItem <$> findObjectLinkable this_mod obj_fn obj_date
+ _ -> return $ UpToDateItem (mkObjectLinkable this_mod obj_fn disk_hash)
_ -> return $ outOfDateItemBecause MissingObjectFile Nothing
-- | Check to see if we can reuse the old linkable, by this point we will
@@ -724,15 +732,22 @@ checkObjects dflags mb_old_linkable summary = do
checkByteCodeInMemory :: HscEnv -> ModSummary -> Maybe (LinkableWith ModuleByteCode) -> IO (MaybeValidated (LinkableWith ModuleByteCode))
checkByteCodeInMemory hsc_env mod_sum mb_old_linkable =
case mb_old_linkable of
- Just old_linkable
+ Just old_linkable -> do
-- If `-fwrite-byte-code` is enabled, then check that the .gbc file is
-- up-to-date with the linkable we have in our hand.
-- If ms_bytecode_date is Nothing, then the .gbc file does not exist yet.
- -- Otherwise, check that the date matches the linkable date exactly.
- | if gopt Opt_WriteByteCode (hsc_dflags hsc_env)
- then maybe False (linkableTime old_linkable ==) (ms_bytecode_date mod_sum)
- else True
- -> return $ (UpToDateItem old_linkable)
+ -- Otherwise, check that the hash matches the disk.
+ ok <- if gopt Opt_WriteByteCode (hsc_dflags hsc_env)
+ then case ms_bytecode_date mod_sum of
+ Nothing -> pure False
+ Just _ -> do
+ disk_hash <- ByteCode.readBinByteCodeHash
+ (ml_bytecode_file (ms_location mod_sum))
+ pure (disk_hash == Just (linkableHash old_linkable))
+ else pure True
+ if ok
+ then return (UpToDateItem old_linkable)
+ else return $ outOfDateItemBecause MissingBytecode Nothing
_ -> return $ outOfDateItemBecause MissingBytecode Nothing
-- | Load bytecode from a ".gbc" object file if it exists and is up-to-date
@@ -745,12 +760,17 @@ checkByteCodeFromObject hsc_env mod_sum = do
case (,) <$> obj_date <*> if_date of
Just (obj_date, if_date)
| obj_date >= if_date -> do
- -- Don't force this if we reuse the linkable already loaded into memory, but we have to check
- -- that the one we have on disk would be suitable as well.
- linkable <- unsafeInterleaveIO $ do
- bco <- ByteCode.readBinByteCode hsc_env obj_fn
- return $ mkOnlyModuleByteCodeLinkable obj_date bco
- return $ UpToDateItem linkable
+ -- A file without a valid header is treated as missing
+ mb_disk_hash <- ByteCode.readBinByteCodeHash obj_fn
+ case mb_disk_hash of
+ Nothing -> return $ outOfDateItemBecause MissingBytecode Nothing
+ Just _ -> do
+ -- Don't force this if we reuse the linkable already loaded into memory, but we have to check
+ -- that the one we have on disk would be suitable as well.
+ linkable <- unsafeInterleaveIO $ do
+ bco <- ByteCode.readBinByteCode hsc_env obj_fn
+ return $ mkOnlyModuleByteCodeLinkable bco
+ return $ UpToDateItem linkable
_ -> return $ outOfDateItemBecause MissingBytecode Nothing
-- | Attempt to load bytecode from whole core bindings in the interface if they exist.
@@ -759,9 +779,11 @@ checkByteCodeFromIfaceCoreBindings :: HscEnv -> ModIface -> ModSummary -> IO (Ma
checkByteCodeFromIfaceCoreBindings _hsc_env iface mod_sum = do
let
this_mod = ms_mod mod_sum
- if_date = fromJust $ ms_iface_date mod_sum
+ -- This hash isn't used, initWholeCoreBindings will replace it
+ -- with a real linkable with bytecode that has a hash.
+ wcb_hash = panic "linkableHash: WholeCoreBindingsLinkable"
case iface_core_bindings iface (ms_location mod_sum) of
- Just fi -> return $ UpToDateItem (Linkable if_date this_mod fi)
+ Just fi -> return $ UpToDateItem (Linkable wcb_hash this_mod fi)
_ -> return $ outOfDateItemBecause MissingBytecode Nothing
@@ -1621,10 +1643,9 @@ hscCompileCoreExpr' hsc_env srcspan ds_expr = do
Strict.Nothing -- no hpc info
{- load it -}
- bco_time <- getCurrentTime
mbc <- ByteCode.mkModuleByteCode this_mod bcos []
(mods_needed, units_needed) <- loadDecls interp hsc_env srcspan $
- Linkable bco_time this_mod $ NE.singleton (DotGBC mbc)
+ mkModuleByteCodeLinkable mbc
-- Get the foreign reference to the name we should have just loaded.
mhvs <- lookupFromLoadedEnv interp (idName binding_id)
{- Get the HValue for the root -}
=====================================
compiler/GHC/Driver/Pipeline.hs
=====================================
@@ -128,7 +128,8 @@ import qualified Data.Set as Set
import qualified Data.List.NonEmpty as NE
import Data.List.NonEmpty (NonEmpty(..))
-import Data.Time ( getCurrentTime )
+import GHC.Utils.Fingerprint ( getFileHash )
+import GHC.ByteCode.Serialize ( fingerprintBytecodeLibInputs, readBytecodeLibInputsHash )
import GHC.Tc.Utils.Monad (shutdownTcMPluginsIO, FrontendResult (..), tcg_plugins)
@@ -547,11 +548,13 @@ checkBytecodeLibraryLinkingNeeded _logger dflags unit_env linkables _pkg_deps =
e_bytecode_lib_time <- modificationTimeIfExists exe_file_os
case e_bytecode_lib_time of
Nothing -> return $ NeedsRecompile MustCompile
- Just t -> do
- let bytecode_times = map linkableTime linkables
- if any (t <) bytecode_times
- then return $ needsRecompileBecause ObjectsChanged
- else return UpToDate
+ Just _ -> do
+ -- See Note [Hash of bytecode libs] in GHC.ByteCode.Serialize
+ recorded <- readBytecodeLibInputsHash exe_file
+ let current = fingerprintBytecodeLibInputs (map linkableHash linkables)
+ if recorded == Just current
+ then return UpToDate
+ else return $ needsRecompileBecause ObjectsChanged
checkNativeLibraryLinkingNeeded :: Bool -> Logger -> DynFlags -> UnitEnv -> [Linkable] -> [UnitId] -> IO RecompileRequired
checkNativeLibraryLinkingNeeded staticLink _ dflags unit_env linkables pkg_deps = do
@@ -576,8 +579,9 @@ checkNativeLibraryLinkingNeeded staticLink _ dflags unit_env linkables pkg_deps
Just t -> do
-- first check object files and extra_ld_inputs
let extra_ld_inputs = [ f | FileOption _ f <- ldInputs dflags ]
- (errs,extra_times) <- partitionWithM (tryIO . getModificationUTCTime) extra_ld_inputs
- let obj_times = map linkableTime linkables ++ extra_times
+ obj_files = concatMap linkableFiles linkables
+ (errs,obj_times) <- partitionWithM (tryIO . getModificationUTCTime)
+ (obj_files ++ extra_ld_inputs)
if not (null errs) || any (t <) obj_times
then return $ needsRecompileBecause ObjectsChanged
else do
@@ -936,9 +940,9 @@ hscGenBackendPipeline pipe_env hsc_env mod_sum result = do
-- No object file produced, bytecode or NoBackend
Nothing -> return mlinkable
Just o_fp -> do
- part_time <- liftIO getCurrentTime
final_object <- use (T_MergeForeign pipe_env hsc_env o_fp fos)
- let !linkable = Linkable part_time (ms_mod mod_sum) (NE.singleton (DotO final_object ModuleObject))
+ !obj_hash <- liftIO $ getFileHash final_object
+ let !linkable = Linkable obj_hash (ms_mod mod_sum) (NE.singleton (DotO final_object ModuleObject))
-- Add the object linkable to the potential bytecode linkable which was generated in HscBackend.
return (mlinkable { homeMod_object = Just linkable })
=====================================
compiler/GHC/Linker/ByteCode.hs
=====================================
@@ -37,6 +37,8 @@ linkBytecodeLib hsc_env gbcs = do
let bytecodeLib' = BytecodeLib {
bytecodeLibUnitId = homeUnitId_ dflags,
+ bytecodeLibInputsHash = fingerprintBytecodeLibInputs
+ [ gbc_hash m | m <- on_disk_bcos ++ gbcs ],
bytecodeLibFiles = all_cbcs,
bytecodeLibForeign = interpreter_foreign_lib
}
=====================================
compiler/GHC/Linker/Loader.hs
=====================================
@@ -44,7 +44,6 @@ where
import GHC.Prelude
import GHC.Settings
-import GHC.Utils.Misc
import GHC.Platform
import GHC.Platform.Ways
@@ -673,14 +672,13 @@ findWholeCoreBindings hsc_env mod = do
findBytecodeLinkableMaybe :: HscEnv -> ModLocation -> IO (Maybe Linkable)
findBytecodeLinkableMaybe hsc_env locn = do
- let bytecode_fn = ml_bytecode_file locn
- bytecode_fn_os = ml_bytecode_file_ospath locn
- maybe_bytecode_time <- modificationTimeIfExists bytecode_fn_os
- case maybe_bytecode_time of
- Nothing -> return Nothing
- Just bytecode_time -> do
+ let bytecode_fn = ml_bytecode_file locn
+ exists <- doesFileExist bytecode_fn
+ if not exists
+ then return Nothing
+ else do
bco <- readBinByteCode hsc_env bytecode_fn
- return $ Just $ mkModuleByteCodeLinkable bytecode_time bco
+ return $ Just $ mkModuleByteCodeLinkable bco
get_reachable_nodes :: HscEnv -> [Module] -> IO ([Module], UniqDSet UnitId)
get_reachable_nodes hsc_env mods
@@ -834,7 +832,7 @@ linkableInSet :: Linkable -> LinkableSet LinkableUsage -> Bool
linkableInSet l objs_loaded =
case lookupModuleEnv objs_loaded (linkableModule l) of
Nothing -> False
- Just m -> linkableTime l == linkableTime m
+ Just m -> linkableHash l == linkableHash m
{- **********************************************************************
@@ -1390,7 +1388,7 @@ loadBytecodeLibrary :: HscEnv -> Interp -> LoaderState -> FilePath -> IO LoaderS
loadBytecodeLibrary hsc_env interp pls path = do
path' <- canonicalizePath path -- Note [loadObj and relative paths]
-- 1. Read the bytecode library
- (BytecodeLib uid cbcs stubs_so) <- decodeOnDiskBytecodeLib hsc_env =<< readBytecodeLib hsc_env path'
+ (BytecodeLib uid _hash cbcs stubs_so) <- decodeOnDiskBytecodeLib hsc_env =<< readBytecodeLib hsc_env path'
debugTraceMsg (hsc_logger hsc_env) 3 $ text "loadBytecodeLibrary: " $$ vcat [ text "uid: " <+> ppr uid
, text "cbcs: " <+> ppr (length cbcs)
, text "stubs_so: " <+> ppr stubs_so ]
=====================================
compiler/GHC/Linker/Types.hs
=====================================
@@ -36,8 +36,6 @@ module GHC.Linker.Types
, LinkedBreaks(..)
, emptyLinkedBreaks
, LinkableSet
- , mkLinkableSet
- , unionLinkableSet
, ObjFile
, SptEntry(..)
, LibrarySpec(..)
@@ -58,8 +56,6 @@ module GHC.Linker.Types
, linkableBCOs
, linkablePartBCOs
, linkableModuleByteCodes
- , linkableNativeParts
- , linkablePartitionParts
, linkablePartPath
, isNativeCode
, linkableFilterByteCode
@@ -102,7 +98,6 @@ import Control.Applicative ((<|>))
import Control.Concurrent.MVar
import Data.Array
import Data.Functor.Identity
-import Data.Time ( UTCTime )
import Data.Maybe (mapMaybe)
import Data.List.NonEmpty (NonEmpty, nonEmpty)
import qualified Data.List.NonEmpty as NE
@@ -376,10 +371,10 @@ instance Outputable LoadedPkgInfo where
-- | Information we can use to dynamically link modules into the compiler
data LinkableWith parts = Linkable
- { linkableTime :: !UTCTime
- -- ^ Time at which this linkable was built
- -- (i.e. when the bytecodes were produced,
- -- or the mod date on the files)
+ { linkableHash :: Fingerprint
+ -- ^ The identity of the linkable, derived from the hash of its contents
+ -- Lazy because bytecode is compiled lazily (see 'loadIfaceByteCodeLazy'),
+ -- and inspecting the hash can force compiling the bytecode itself.
, linkableModule :: !Module
-- ^ The linkable module itself
@@ -396,22 +391,12 @@ type LinkableUsage = LinkableWith (NonEmpty LinkablePartUsage)
type LinkableSet = ModuleEnv
-mkLinkableSet :: [Linkable] -> LinkableSet Linkable
-mkLinkableSet ls = mkModuleEnv [(linkableModule l, l) | l <- ls]
-
--- | Union of LinkableSets.
---
--- In case of conflict, keep the most recent Linkable (as per linkableTime)
-unionLinkableSet :: LinkableSet (LinkableWith a) -> LinkableSet (LinkableWith a) -> LinkableSet (LinkableWith a)
-unionLinkableSet = plusModuleEnv_C go
- where
- go l1 l2
- | linkableTime l1 > linkableTime l2 = l1
- | otherwise = l2
instance Outputable a => Outputable (LinkableWith a) where
- ppr (Linkable when_made mod parts)
- = (text "Linkable" <+> parens (text (show when_made)) <+> ppr mod)
+ -- Don't print the hash, forcing it can trigger compilation
+ -- See the comment on 'linkableHash'
+ ppr (Linkable _ mod parts)
+ = (text "Linkable" <+> ppr mod)
$$ nest 3 (ppr parts)
type ObjFile = FilePath
@@ -452,13 +437,13 @@ data ModuleByteCode = ModuleByteCode { gbc_module :: Module
, gbc_hash :: !Fingerprint
}
-mkModuleByteCodeLinkable :: UTCTime -> ModuleByteCode -> Linkable
-mkModuleByteCodeLinkable linkable_time bco = do
- Linkable linkable_time (gbc_module bco) (pure (DotGBC bco))
+mkModuleByteCodeLinkable :: ModuleByteCode -> Linkable
+mkModuleByteCodeLinkable bco =
+ Linkable (gbc_hash bco) (gbc_module bco) (pure (DotGBC bco))
-mkOnlyModuleByteCodeLinkable :: UTCTime -> ModuleByteCode -> LinkableWith ModuleByteCode
-mkOnlyModuleByteCodeLinkable linkable_time bco = do
- Linkable linkable_time (gbc_module bco) bco
+mkOnlyModuleByteCodeLinkable :: ModuleByteCode -> LinkableWith ModuleByteCode
+mkOnlyModuleByteCodeLinkable bco =
+ Linkable (gbc_hash bco) (gbc_module bco) bco
instance Outputable ModuleByteCode where
ppr (ModuleByteCode mod _cbc _fos _) = text "ModuleByteCode" <+> ppr mod
@@ -484,21 +469,13 @@ linkableBCOs l = [ gbc_compiled_byte_code gbc | DotGBC gbc <- NE.toList (linkabl
linkableModuleByteCodes :: Linkable -> [ModuleByteCode]
linkableModuleByteCodes l = [ mbc | DotGBC mbc <- NE.toList (linkableParts l) ]
--- | List the native linkable parts (.o) of a linkable
-linkableNativeParts :: Linkable -> [LinkablePart]
-linkableNativeParts l = NE.filter isNativeCode (linkableParts l)
-
--- | Split linkable parts into (native code parts, BCOs parts)
-linkablePartitionParts :: Linkable -> ([LinkablePart],[LinkablePart])
-linkablePartitionParts l = NE.partition isNativeCode (linkableParts l)
-
-- | List the native objects (.o) of a linkable
linkableObjs :: Linkable -> [FilePath]
linkableObjs l = concatMap linkablePartObjectPaths (linkableParts l)
-- | List the paths of the native objects (.o)
linkableFiles :: Linkable -> [FilePath]
-linkableFiles l = concatMap linkablePartNativePaths (NE.toList (linkableParts l))
+linkableFiles l = mapMaybe linkablePartPath (NE.toList (linkableParts l))
-------------------------------------------
@@ -514,13 +491,6 @@ linkablePartPath = \case
DotO fn _ -> Just fn
DotGBC {} -> Nothing
--- | Return the paths of all object code files (.o) contained in this
--- 'LinkablePart'.
-linkablePartNativePaths :: LinkablePart -> [FilePath]
-linkablePartNativePaths = \case
- DotO fn _ -> [fn]
- DotGBC {} -> []
-
-- | Return the paths of all object files (.o) contained in this 'LinkablePart'.
linkablePartObjectPaths :: LinkablePart -> [FilePath]
linkablePartObjectPaths = \case
@@ -589,7 +559,9 @@ mkLinkableUsage lnk =
seqNonEmpty linkablesWithUsage linkablesWithUsage
}
in
- linkableParts lnkUsage `seq` lnkUsage
+ -- Also force the hash so that we don't retain the actual bytecode
+ -- from a LinkableUsage
+ linkableHash lnkUsage `seq` linkableParts lnkUsage `seq` lnkUsage
where
mkFileLinkablePartUsage m fp objs =
FileLinkablePartUsage
=====================================
compiler/GHC/Unit/Finder.hs
=====================================
@@ -42,7 +42,7 @@ module GHC.Unit.Finder (
mkStubPaths,
findObjectLinkableMaybe,
- findObjectLinkable,
+ mkObjectLinkable,
-- important that GHC.HsToCore.Usage uses the same hashing method for usage dirs as is used here.
getDirHash,
@@ -76,7 +76,6 @@ import GHC.Unit.State
import GHC.Unit.Finder.Cache
import GHC.Unit.Finder.Types
-import GHC.Utils.Misc
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
@@ -88,7 +87,6 @@ import GHC.Types.UnresolvedImport
import Control.Applicative ((<|>))
import Control.Exception (throwIO)
-import Control.Monad
import Control.Monad.IO.Class
import Data.IORef
import qualified Data.List as L(sort)
@@ -97,7 +95,6 @@ import qualified Data.List.NonEmpty as NE
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as Set (empty, intersection, difference, null, toList)
-import Data.Time
import GHC.Fingerprint
import GHC.TypeError (ErrorMessage(..), Unsatisfiable, unsatisfiable)
import qualified System.Directory as SD
@@ -1088,15 +1085,15 @@ mkStubPaths fopts mod location = do
findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable)
findObjectLinkableMaybe mod locn
= do let obj_fn = ml_obj_file locn
- maybe_obj_time <- modificationTimeIfExists (ml_obj_file_ospath locn)
- case maybe_obj_time of
- Nothing -> return Nothing
- Just obj_time -> liftM Just (findObjectLinkable mod obj_fn obj_time)
-
--- Make an object linkable when we know the object file exists, and we know
--- its modification time.
-findObjectLinkable :: Module -> FilePath -> UTCTime -> IO Linkable
-findObjectLinkable mod obj_fn obj_time =
- pure (Linkable obj_time mod (NE.singleton (DotO obj_fn ModuleObject)))
+ exists <- doesFileExist (ml_obj_file_ospath locn)
+ if not exists
+ then return Nothing
+ else do
+ obj_hash <- getFileHash obj_fn
+ return (Just (mkObjectLinkable mod obj_fn obj_hash))
+
+mkObjectLinkable :: Module -> FilePath -> Fingerprint -> Linkable
+mkObjectLinkable mod obj_fn obj_hash =
+ Linkable obj_hash mod (NE.singleton (DotO obj_fn ModuleObject))
-- We used to look for _stub.o files here, but that was a bug (#706)
-- Now GHC merges the stub.o into the main .o (#3687)
=====================================
testsuite/tests/driver/bytecode-object/Makefile
=====================================
@@ -165,3 +165,19 @@ bytecode_object26:
@printf 'bad!' | dd of=BytecodeTest.gbc bs=1 count=4 conv=notrunc 2>/dev/null
! "$(TEST_HC)" $(TEST_HC_OPTS) -c -bytecodelib -o linked.bytecode BytecodeTest.gbc 2> bytecode_object26.stderr
@grep -F "bytecode file header mismatch" bytecode_object26.stderr >/dev/null
+
+# Test reloading in GHCi with the .gbc file written by the first load
+# The module should not be recompiled.
+bytecode_object27:
+ @echo ":reload" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -v1 -fno-hide-source-paths -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs
+
+# Test corrupting the header of the .gbc file and reloading in GHCi
+# The module should be recompiled.
+bytecode_object28:
+ @cat bytecode_object28.script | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -v1 -fno-hide-source-paths -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs
+
+# Test that a bytecode library with a corrupt header is linked again
+bytecode_object29:
+ "$(TEST_HC)" $(TEST_HC_OPTS) -bytecodelib -o linked.bytecode BytecodeTest.hs -fwrite-byte-code -fbyte-code -fwrite-interface
+ @printf 'bad!' | dd of=linked.bytecode bs=1 count=4 conv=notrunc 2>/dev/null
+ "$(TEST_HC)" $(TEST_HC_OPTS) -bytecodelib -o linked.bytecode BytecodeTest.hs -fwrite-byte-code -fbyte-code -fwrite-interface
=====================================
testsuite/tests/driver/bytecode-object/all.T
=====================================
@@ -27,3 +27,6 @@ test('bytecode_object23', bytecode_opts, makefile_test, ['bytecode_object23'])
test('bytecode_object24', bytecode_opts + [copy_files], makefile_test, ['bytecode_object24'])
test('bytecode_object25', [bytecode_opts, req_interp, extra_files(['BytecodeForeign.hs', 'BytecodeForeign.c'])], makefile_test, ['bytecode_object25'])
test('bytecode_object26', [bytecode_opts], makefile_test, ['bytecode_object26'])
+test('bytecode_object27', [bytecode_opts, req_interp, filter_stdout_lines(r'.*Compiling.*') ], makefile_test, ['bytecode_object27'])
+test('bytecode_object28', [bytecode_opts, req_interp, filter_stdout_lines(r'.*Compiling.*') ], makefile_test, ['bytecode_object28'])
+test('bytecode_object29', bytecode_opts, makefile_test, ['bytecode_object29'])
=====================================
testsuite/tests/driver/bytecode-object/bytecode_object27.stdout
=====================================
@@ -0,0 +1 @@
+[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main]
=====================================
testsuite/tests/driver/bytecode-object/bytecode_object28.script
=====================================
@@ -0,0 +1,3 @@
+System.IO.withBinaryFile "BytecodeTest.gbc" System.IO.ReadWriteMode (\h -> System.IO.hPutStr h "bad!")
+:reload
+:quit
=====================================
testsuite/tests/driver/bytecode-object/bytecode_object28.stdout
=====================================
@@ -0,0 +1,2 @@
+[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main]
+ghci> ghci> [1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main] [Missing bytecode]
=====================================
testsuite/tests/driver/bytecode-object/bytecode_object29.stdout
=====================================
@@ -0,0 +1,3 @@
+[1 of 2] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )
+[2 of 2] Linking linked.bytecode
+[2 of 2] Linking linked.bytecode [Objects changed]
=====================================
testsuite/tests/driver/recomp023/M.hs
=====================================
@@ -0,0 +1,4 @@
+module M where
+
+m :: Int
+m = 5
=====================================
testsuite/tests/driver/recomp023/M2.hs
=====================================
@@ -0,0 +1,4 @@
+module M where
+
+m :: Int
+m = 6
=====================================
testsuite/tests/driver/recomp023/Makefile
=====================================
@@ -0,0 +1,21 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+# Recompilation test for bytecode libraries: the library is only relinked
+# when one of its constituents changes
+
+BUILD = '$(TEST_HC)' $(TEST_HC_OPTS) --make -bytecodelib -fbyte-code \
+ -fwrite-interface -fwrite-byte-code -this-unit-id=recomp023 \
+ -o recomp023.bytecodelib M.hs
+
+clean:
+
+recomp023: clean
+ echo "first build"
+ $(BUILD)
+ echo "second build"
+ $(BUILD)
+ mv M2.hs M.hs
+ echo "third build"
+ $(BUILD)
=====================================
testsuite/tests/driver/recomp023/all.T
=====================================
@@ -0,0 +1,2 @@
+test('recomp023', [extra_files(['M.hs', 'M2.hs']), req_bco, normalise_slashes],
+ makefile_test, [])
=====================================
testsuite/tests/driver/recomp023/recomp023.stdout
=====================================
@@ -0,0 +1,7 @@
+first build
+[1 of 2] Compiling M ( M.hs, M.gbc )
+[2 of 2] Linking recomp023.bytecodelib
+second build
+third build
+[1 of 2] Compiling M ( M.hs, M.gbc ) [Source file changed]
+[2 of 2] Linking recomp023.bytecodelib [Objects changed]
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f3f5e98cc9cc5377bec357ec65bd44…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f3f5e98cc9cc5377bec357ec65bd44…
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
1
0
[Git][ghc/ghc][wip/romes/async-rpc] interp: close Mailbox when exiting sendTHComputation
by Andrea Vezzosi (@trac-Saizan) 23 Nov '26
by Andrea Vezzosi (@trac-Saizan) 23 Nov '26
23 Nov '26
Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
0c095fa9 by Andrea Vezzosi at 2026-11-23T10:39:42+01:00
interp: close Mailbox when exiting sendTHComputation
- - - - -
1 changed file:
- compiler/GHC/Runtime/Interpreter/Process.hs
Changes:
=====================================
compiler/GHC/Runtime/Interpreter/Process.hs
=====================================
@@ -51,23 +51,17 @@ sendTHComputation
-> (forall b. Binary b => (forall a. IO a -> IO a) -> THMessage b -> IO (Bool, b))
-- ^ Handle one message. Return True to end the loop.
-> IO a
-sendTHComputation i mkMsg reqHandler = mask $ \ restore -> do
- mbox <- newMailbox (pipeAsyncMngr (interpPipe proc))
- let msg = mkMsg mbox
- res <- remoteCallInterleaving (interpPipe proc) msg
- -- handle reverse requests until done
- (restore $ handlerLoop mbox)
- (dispose msg mbox)
- disposeMailbox mbox
- either throwIO pure res
+sendTHComputation i mkMsg reqHandler = mask $ \ restore ->
+ withMailbox (pipeAsyncMngr (interpPipe proc)) $ \ mbox -> do
+ let msg = mkMsg mbox
+ res <- remoteCallInterleaving (interpPipe proc) msg
+ -- handle reverse requests until done
+ (restore $ handlerLoop mbox)
+ (dispose msg)
+ either throwIO pure res
where
- disposeMailbox mbox = do
- -- non-blocking
- -- ext. interp. will cleanup on error response, so we don't need reqs.
- _reqs <- closeMailbox (interpPipe proc) mbox
- pure ()
- dispose msg mbox res = do
- disposeMailbox mbox
+ withMailbox am = bracket (newMailbox am) (closeMailbox (interpPipe proc))
+ dispose msg res = do
case res of
-- rethrown elsewhere where relevant.
Left _ -> pure ()
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0c095fa90b0bb4958e328c66b6cc11e…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0c095fa90b0bb4958e328c66b6cc11e…
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
1
0
[Git][ghc/ghc] Pushed new branch wip/sjakobi/ci-test-bootstrap-nightly-only
by Simon Jakobi (@sjakobi) 23 Nov '26
by Simon Jakobi (@sjakobi) 23 Nov '26
23 Nov '26
Simon Jakobi pushed new branch wip/sjakobi/ci-test-bootstrap-nightly-only at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/ci-test-bootstrap-nig…
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
1
0
[Git][ghc/ghc][wip/T27724] 13 commits: NCG: List each destination of a jump table once
by Simon Peyton Jones (@simonpj) 23 Nov '26
by Simon Peyton Jones (@simonpj) 23 Nov '26
23 Nov '26
Simon Peyton Jones pushed to branch wip/T27724 at Glasgow Haskell Compiler / GHC
Commits:
01a5b0ac by Sylvain Henry at 2026-11-22T16:35:34-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
e4498112 by Andreas Klebinger at 2026-11-22T16:35:34-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
f59fb957 by Sylvain Henry at 2026-11-22T16:35:34-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
2091b89a by fendor at 2026-11-22T16:36:17-05:00
`ghc -M`: Add support for link nodes to json output
`LinkNode`s are part of the module graph and indicate that a certain
linking artefact is to be produced from other module graph nodes.
We expose `LinkNode`s in the output of `ghc -M -dep-json`, allowing
consumers to see when a linking artefact is to be produced.
Only the JSON output format of `ghc -M` supports `LinkNode` as it is
unclear how the Makefile output should be retrofitted to express the
dependencies, and whether it would require a feature guard.
Closes #28007
- - - - -
cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
06e71ddf by Simon Peyton Jones at 2026-11-22T16:37:40-05:00
Better desugaring for bang patterns
Ticket #27862 showed that we were desugaring bang patterns in a
silly way, which led to bad code. This small fix makes it much
better.
I ended up refactoring `decomposeFirstPat` to be of type
(LPat -> LPat) instead of (Pat -> Pat)
which made it much easier to keep the locations correct.
On the way I also fixed #28137, a missing warning.
See Note [Tidying patterns] which has new (TP1) and (TP2)
and Note [Grouping equations] especially (GE1)
- - - - -
cd6c2a96 by Simon Jakobi at 2026-11-22T16:38:23-05:00
Cmm: drop eliminated blocks from the graph in CBE
Previously, common block elimination only made the eliminated blocks
unreachable. They stayed in the graph until stack layout discarded
them.
Removing these blocks right away reduces the potential for confusion
(e.g. #27368). It does not appear to make any significant difference
to compiler allocations.
Assisted-by: Claude Opus 5.5
- - - - -
c0764c69 by Hannes Siebenhandl at 2026-11-22T16:39:04-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
242f8daf by Alan Zimmerman at 2026-11-22T16:39:46-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
1e568190 by David Eichmann at 2026-11-22T16:40:28-05:00
Fix race condition in IOManager test
- - - - -
64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00
Fix a zonking bug
As #28135 showed, we were failing to zonk some type-variable
binders before doing scoped-sort dependency analysis, resulting
in chaos.
The fix is easy.
- - - - -
ed5124b3 by mangoiv at 2026-11-22T16:41:50-05:00
ci: nightly push can run on any arch
- - - - -
7e211c85 by Simon Peyton Jones at 2026-11-23T09:38:04+00:00
Redesign the noinline magic
The principal goal of this MR is to avoid `noinline` getting in the way
of strictness analysis and specialisation. It involves a bit of redesign.
Main idea:
* When simplifying `noinline (f e1 e2)`, switch off inlining when
simplifying `f`, but not when simplifying `e1` and `e2`.
* Mechanism: see `simplOutId`, the `noinlineIdKey` case
* If: we see `noinline (f e1) e2`, the simplifier moves the `e2` inside;
see the `splitContArgs` call. This is important so you can write
`noinline f e1 e2` and have it mean the same as `noinline (f e1 e2)`.
* Now `f` sees all its arguments, hence:
* Fixes #27724 (noinline inhibits specialisation)
* Fixes #23911 (noinline worsens demand signatures)
* Also fixes #27803 where we were not respecting `noinline` if the RHS
was trivial
See Note [noinlineId magic] for lots of specifics. It's surprisingly tricky!
For some reason a couple of perf tests allocate 1.2% less at compile time,n
namely T29872 and T8095. Geom mean decease of 0.1%
Metric Decrease:
T9872d
- - - - -
131 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/T27137
- + changelog.d/T27724
- + changelog.d/T27862
- + changelog.d/T28135
- + changelog.d/make-depends-link-nodes
- compiler/GHC/Builtin/WiredIn/Ids.hs
- compiler/GHC/Builtin/WiredIn/Prim.hs
- compiler/GHC/Builtin/WiredIn/Types/Box.hs
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/TyCo/Make.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/CoreToIface.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/HsToCore.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Solver/Types.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Parser.y
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/Types/Origin.hs
- + distrib/configure.ac
- docs/users_guide/make-depends-json-schema-1_0.json
- libraries/ghc-internal/src/GHC/Internal/Exts.hs
- libraries/ghc-internal/src/GHC/Internal/Magic.hs
- testsuite/tests/ado/T22483.stderr
- + testsuite/tests/codeGen/should_compile/T27694.hs
- + testsuite/tests/codeGen/should_compile/T27694c.hs
- + testsuite/tests/codeGen/should_compile/T27694d.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_run/T27694b.hs
- + testsuite/tests/codeGen/should_run/T27694b.stdout
- + testsuite/tests/codeGen/should_run/T27915.hs
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-32
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-64
- testsuite/tests/codeGen/should_run/all.T
- testsuite/tests/corelint/LintEtaExpand.hs
- + testsuite/tests/deSugar/should_compile/T27862.hs
- + testsuite/tests/deSugar/should_compile/T27862.stderr
- + testsuite/tests/deSugar/should_compile/T27862a.hs
- + testsuite/tests/deSugar/should_compile/T27862a.stderr
- + testsuite/tests/deSugar/should_compile/T27862b.hs
- + testsuite/tests/deSugar/should_compile/T27862b.stderr
- + testsuite/tests/deSugar/should_compile/T27862c.hs
- + testsuite/tests/deSugar/should_compile/T27862c.stderr
- + testsuite/tests/deSugar/should_compile/T27862d.hs
- + testsuite/tests/deSugar/should_compile/T27862d.stderr
- + testsuite/tests/deSugar/should_compile/T28137.hs
- + testsuite/tests/deSugar/should_compile/T28137.stderr
- testsuite/tests/deSugar/should_compile/all.T
- testsuite/tests/deSugar/should_run/dsrun008.stderr
- + testsuite/tests/dmdanal/should_compile/T23911.hs
- + testsuite/tests/dmdanal/should_compile/T23911.stderr
- testsuite/tests/dmdanal/should_compile/all.T
- testsuite/tests/driver/mkdepend/all.T
- + testsuite/tests/driver/mkdepend/mhu04/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu04/app/Utils.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu04/unitApp
- + testsuite/tests/driver/mkdepend/mhu04/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu05/test/Spec.hs
- + testsuite/tests/driver/mkdepend/mhu05/unitApp
- + testsuite/tests/driver/mkdepend/mhu05/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/unitTest
- + testsuite/tests/driver/mkdepend/mkdepend02.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend02/Main.hs
- + testsuite/tests/driver/mkdepend/mkdepend_bkp_01/bkp01.bkp
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-makefile
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-makefile
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- testsuite/tests/interface-stability/ghc-prim-exports.stdout
- testsuite/tests/interface-stability/ghc-prim-exports.stdout-mingw32
- testsuite/tests/pmcheck/should_compile/T24234.stderr
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/all.T
- testsuite/tests/simplCore/should_compile/T18995.stderr
- + testsuite/tests/simplCore/should_compile/T27724a.hs
- + testsuite/tests/simplCore/should_compile/T27724a.stderr
- + testsuite/tests/simplCore/should_compile/T27803.hs
- + testsuite/tests/simplCore/should_compile/T27803.stderr
- testsuite/tests/simplCore/should_compile/all.T
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/T17940.stderr
- testsuite/tests/typecheck/should_fail/tcfail203a.stderr
- utils/check-exact/ExactPrint.hs
- utils/genprimopcode/Main.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e10400389d626b43caaafaee4d4ddd…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e10400389d626b43caaafaee4d4ddd…
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
1
0
[Git][ghc/ghc][wip/T27212] 15 commits: NCG: List each destination of a jump table once
by Simon Peyton Jones (@simonpj) 23 Nov '26
by Simon Peyton Jones (@simonpj) 23 Nov '26
23 Nov '26
Simon Peyton Jones pushed to branch wip/T27212 at Glasgow Haskell Compiler / GHC
Commits:
01a5b0ac by Sylvain Henry at 2026-11-22T16:35:34-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
e4498112 by Andreas Klebinger at 2026-11-22T16:35:34-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
f59fb957 by Sylvain Henry at 2026-11-22T16:35:34-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
2091b89a by fendor at 2026-11-22T16:36:17-05:00
`ghc -M`: Add support for link nodes to json output
`LinkNode`s are part of the module graph and indicate that a certain
linking artefact is to be produced from other module graph nodes.
We expose `LinkNode`s in the output of `ghc -M -dep-json`, allowing
consumers to see when a linking artefact is to be produced.
Only the JSON output format of `ghc -M` supports `LinkNode` as it is
unclear how the Makefile output should be retrofitted to express the
dependencies, and whether it would require a feature guard.
Closes #28007
- - - - -
cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
06e71ddf by Simon Peyton Jones at 2026-11-22T16:37:40-05:00
Better desugaring for bang patterns
Ticket #27862 showed that we were desugaring bang patterns in a
silly way, which led to bad code. This small fix makes it much
better.
I ended up refactoring `decomposeFirstPat` to be of type
(LPat -> LPat) instead of (Pat -> Pat)
which made it much easier to keep the locations correct.
On the way I also fixed #28137, a missing warning.
See Note [Tidying patterns] which has new (TP1) and (TP2)
and Note [Grouping equations] especially (GE1)
- - - - -
cd6c2a96 by Simon Jakobi at 2026-11-22T16:38:23-05:00
Cmm: drop eliminated blocks from the graph in CBE
Previously, common block elimination only made the eliminated blocks
unreachable. They stayed in the graph until stack layout discarded
them.
Removing these blocks right away reduces the potential for confusion
(e.g. #27368). It does not appear to make any significant difference
to compiler allocations.
Assisted-by: Claude Opus 5.5
- - - - -
c0764c69 by Hannes Siebenhandl at 2026-11-22T16:39:04-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
242f8daf by Alan Zimmerman at 2026-11-22T16:39:46-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
1e568190 by David Eichmann at 2026-11-22T16:40:28-05:00
Fix race condition in IOManager test
- - - - -
64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00
Fix a zonking bug
As #28135 showed, we were failing to zonk some type-variable
binders before doing scoped-sort dependency analysis, resulting
in chaos.
The fix is easy.
- - - - -
ed5124b3 by mangoiv at 2026-11-22T16:41:50-05:00
ci: nightly push can run on any arch
- - - - -
6871ae45 by Simon Peyton Jones at 2026-11-23T08:45:17+00:00
Use a different herald for -ddump-simpl-trace
... so that we can more easily skip the high-volume ones
- - - - -
cd4644fa by Simon Peyton Jones at 2026-11-23T08:45:17+00:00
Update comments and user manual
This commit addresses the comment-related suggestions in #27973
- - - - -
bf36e2e0 by Simon Peyton Jones at 2026-11-23T08:45:17+00:00
Document and refactor eta-reduction documentation
Triggered by #27212, this patch does several related things.
* #27212 suggested that `findRhsArity` should ask for eta-expansion
whenever the RHS's `manifestArity` is less than the arity it finds.
That is a misconception: it deliberately compares with `exprArity`,
which counts PAPs, so that we do not eta-expand PAPs (#9020).
Switching to `manifestArity` makes compile time worse in T13960
and T13056.
So this patch changes no code here; we continue to expand only to
increase `exprArity` not `manifestArity`. Instead it documents the
design in `findRhsArity`, `tryEtaExpandRhs`, `wantEtaExpansion` and
Note [Do not eta-expand PAPs] (which now records the #27212
experiment).
* Refactor GHC.Core.Opt.Arity.tryEtaReduce, which was hard to
understand:
- Accumulate an MCoercion rather than a Coercion, so the common
no-cast case builds no coercions at all.
- Separate equations of `go` for type and value arguments. For
value arguments, the new `getTrivialHead_maybe` looks through any
nesting of casts and floatable ticks, and `mkEtaReduceFunCo` builds
the coercion.
- Make the FunCo with `mkFunCo2` and compute its right-hand
FunTyFlag from the coercion kinds. The cast can turn a Type-kinded
argument into a Constraint-kinded one. New test T27212 covers this.
- `mkEtaReduceForAllMCo` builds the ForAllCo for type arguments. It
is tiresomely similar to `mkEtaForAllMCo`, but with the visibilities
the other way round (#24014). It will go away again once !17006
lands.
- New helper `mCoToCo` in GHC.Core.TyCo.Make.
* Drop the checks on multiplicity in `tryEtaReduce`, which sometimes
disabled eta-reduction. For example, (\x. K x) has type Int -> T,
but the data constructor has type K :: Int %1 -> T, so we used to
refuse to eta-reduce it to K.
But Note [Linting linearity] in GHC.Core.Lint (EXAMPLE 4) already
says that we do not preserve linearity under eta-reduction, so this
change just puts that claim into practice. See (EtaMult) in
Note [Eta reduction soundness].
Consequences in the testsuite:
- T18052a: the pattern-synonym builder (\x y. (x,y)) is now just (,).
- T21888a: the NOINLINE function (f x = Just x) becomes (f = Just),
so f loses its CPR signature. The test is about demands, not CPR.
* Tidy up the documentation of eta-reduction:
- Relabel the criteria in Note [Eta reduction soundness] as (EtaA),
(EtaS), (EtaR), (EtaE), (EtaT), (EtaJ), (EtaB) and (EtaW), and
update all references to them. Also fix references to point (2) of
Note [Eta reduction makes sense], which no longer exists.
- Replace the confused "never reduce arity" bullet with an example in
(EtaA), cross-referenced from Note [Arity robustness].
- Add historical notes (EtaMult) and (EtaBot).
- Label the equations in Note [Eta reduction with casted arguments]
(ECA1-4), and point to the code that implements them.
LLM disclosure: I interacted with Claude a lot for this MR, but I
wrote all the code and docs myself.
- - - - -
116 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/T27137
- + changelog.d/T27212
- + changelog.d/T27862
- + changelog.d/T28135
- + changelog.d/make-depends-link-nodes
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Inline.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/TyCo/Make.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Parser.y
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- + distrib/configure.ac
- docs/users_guide/debug-info.rst
- docs/users_guide/make-depends-json-schema-1_0.json
- docs/users_guide/using-optimisation.rst
- testsuite/tests/ado/T22483.stderr
- + testsuite/tests/codeGen/should_compile/T27694.hs
- + testsuite/tests/codeGen/should_compile/T27694c.hs
- + testsuite/tests/codeGen/should_compile/T27694d.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_run/T27694b.hs
- + testsuite/tests/codeGen/should_run/T27694b.stdout
- + testsuite/tests/codeGen/should_run/T27915.hs
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-32
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-64
- testsuite/tests/codeGen/should_run/all.T
- + testsuite/tests/deSugar/should_compile/T27862.hs
- + testsuite/tests/deSugar/should_compile/T27862.stderr
- + testsuite/tests/deSugar/should_compile/T27862a.hs
- + testsuite/tests/deSugar/should_compile/T27862a.stderr
- + testsuite/tests/deSugar/should_compile/T27862b.hs
- + testsuite/tests/deSugar/should_compile/T27862b.stderr
- + testsuite/tests/deSugar/should_compile/T27862c.hs
- + testsuite/tests/deSugar/should_compile/T27862c.stderr
- + testsuite/tests/deSugar/should_compile/T27862d.hs
- + testsuite/tests/deSugar/should_compile/T27862d.stderr
- + testsuite/tests/deSugar/should_compile/T28137.hs
- + testsuite/tests/deSugar/should_compile/T28137.stderr
- testsuite/tests/deSugar/should_compile/all.T
- testsuite/tests/deSugar/should_run/dsrun008.stderr
- testsuite/tests/dmdanal/sigs/T21888a.stderr
- testsuite/tests/driver/mkdepend/all.T
- + testsuite/tests/driver/mkdepend/mhu04/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu04/app/Utils.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu04/unitApp
- + testsuite/tests/driver/mkdepend/mhu04/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu05/test/Spec.hs
- + testsuite/tests/driver/mkdepend/mhu05/unitApp
- + testsuite/tests/driver/mkdepend/mhu05/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/unitTest
- + testsuite/tests/driver/mkdepend/mkdepend02.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend02/Main.hs
- + testsuite/tests/driver/mkdepend/mkdepend_bkp_01/bkp01.bkp
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-makefile
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-makefile
- testsuite/tests/pmcheck/should_compile/T24234.stderr
- testsuite/tests/printer/T18052a.stderr
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/all.T
- testsuite/tests/simplCore/should_compile/T24726.stderr
- + testsuite/tests/simplCore/should_compile/T27212.hs
- testsuite/tests/simplCore/should_compile/all.T
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/tcfail203a.stderr
- utils/check-exact/ExactPrint.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cd190880ae1cfe2d45687c14328576…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cd190880ae1cfe2d45687c14328576…
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
1
0
[Git][ghc/ghc][wip/sjakobi/T27284-nonmoving-nightly] ci: Remove the non-moving GC job from the nightly pipeline
by Simon Jakobi (@sjakobi) 23 Nov '26
by Simon Jakobi (@sjakobi) 23 Nov '26
23 Nov '26
Simon Jakobi pushed to branch wip/sjakobi/T27284-nonmoving-nightly at Glasgow Haskell Compiler / GHC
Commits:
2f3ac43a by Simon Jakobi at 2026-11-23T09:36:17+01:00
ci: Remove the non-moving GC job from the nightly pipeline
The nightly x86_64-linux-deb13-validate+boot_nonmoving_gc-test job has
been running into its 8 hour timeout every night. This removes it along
with its build job.
MR pipelines can still run the non-moving GC jobs when the
"non-moving GC" label is set.
Context: #27284
Assisted-by: Claude Fable 5.2
- - - - -
2 changed files:
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
Changes:
=====================================
.gitlab/generate-ci/gen_ci.hs
=====================================
@@ -1255,6 +1255,10 @@ onlyRule t = modifyValidateJobs (onlyValidateJobRule t)
disableValidate :: JobGroup Job -> JobGroup Job
disableValidate = modifyValidateJobs (removeValidateJobRule FastCI . removeValidateJobRule FullCI)
+-- | Drop the nightly job from a 'JobGroup'.
+disableNightly :: JobGroup a -> JobGroup a
+disableNightly jg = jg { n = Nothing }
+
---------------------------------------------------------------------
-- NamedJob
---------------------------------------------------------------------
@@ -1349,7 +1353,8 @@ debian_x86 =
, onlyRule LLVMBackend (validateBuilds Amd64 (Linux validate_debian) llvm)
, addValidateRule TestPrimops (standardBuilds Amd64 (Linux validate_debian))
- , onlyRule NonmovingGc (validateBuilds Amd64 (Linux validate_debian) vanilla {validateNonmovingGc = True})
+ , -- No nightly while the test job times out: #27284
+ disableNightly (onlyRule NonmovingGc (validateBuilds Amd64 (Linux validate_debian) vanilla {validateNonmovingGc = True}))
, onlyRule IpeData (validateBuilds Amd64 (Linux validate_debian) zstdIpe)
]
where
=====================================
.gitlab/jobs.yaml
=====================================
@@ -5277,131 +5277,6 @@
"XZ_OPT": "-9"
}
},
- "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc": {
- "after_script": [
- ".gitlab/ci.sh save_cache",
- ".gitlab/ci.sh save_test_output",
- ".gitlab/ci.sh clean",
- "cat ci_timings.txt"
- ],
- "allow_failure": false,
- "artifacts": {
- "expire_in": "8 weeks",
- "paths": [
- "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc.tar.xz",
- "junit.xml",
- "unexpected-test-output.tar.gz",
- "_build/stage1/haddock-timing-files"
- ],
- "reports": {
- "junit": "junit.xml"
- },
- "when": "always"
- },
- "cache": {
- "key": "x86_64-linux-deb13-$CACHE_REV",
- "paths": [
- "cabal-cache",
- "toolchain"
- ]
- },
- "image": "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb13:$DOCKER_REV",
- "needs": [
- {
- "artifacts": false,
- "job": "hadrian-ghc-in-ghci"
- }
- ],
- "rules": [
- {
- "if": "(\"true\" == \"true\") && ($RELEASE_JOB != \"yes\") && ($NIGHTLY)",
- "when": "on_success"
- }
- ],
- "script": [
- "sudo chown ghc:ghc -R .",
- ".gitlab/ci.sh setup",
- ".gitlab/ci.sh configure",
- ".gitlab/ci.sh build_hadrian",
- ".gitlab/ci.sh test_hadrian_stage1"
- ],
- "stage": "full-build",
- "tags": [
- "x86_64-linux"
- ],
- "variables": {
- "BIGNUM_BACKEND": "gmp",
- "BIN_DIST_NAME": "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "BUILD_FLAVOUR": "validate+boot_nonmoving_gc",
- "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "RUNTEST_ARGS": "--way=nonmoving --way=nonmoving_thr --way=nonmoving_thr_sanity",
- "TEST_ENV": "x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "TEST_WAYS": "",
- "XZ_OPT": "-9"
- }
- },
- "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc-test": {
- "after_script": [
- ".gitlab/ci.sh save_cache",
- ".gitlab/ci.sh save_test_output",
- ".gitlab/ci.sh clean",
- "cat ci_timings.txt"
- ],
- "allow_failure": false,
- "artifacts": {
- "expire_in": "8 weeks",
- "paths": [
- "junit.xml",
- "unexpected-test-output.tar.gz"
- ],
- "reports": {
- "junit": "junit.xml"
- },
- "when": "always"
- },
- "cache": {
- "key": "x86_64-linux-deb13-$CACHE_REV",
- "paths": [
- "cabal-cache",
- "toolchain"
- ]
- },
- "image": "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb13:$DOCKER_REV",
- "needs": [
- {
- "artifacts": true,
- "job": "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc"
- }
- ],
- "rules": [
- {
- "if": "(\"true\" == \"true\") && ($RELEASE_JOB != \"yes\") && ($NIGHTLY)",
- "when": "on_success"
- }
- ],
- "script": [
- "sudo chown ghc:ghc -R .",
- ".gitlab/ci.sh setup",
- ".gitlab/ci.sh configure",
- ".gitlab/ci.sh test_hadrian"
- ],
- "stage": "testing",
- "tags": [
- "x86_64-linux"
- ],
- "variables": {
- "BIGNUM_BACKEND": "gmp",
- "BIN_DIST_NAME": "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "BUILD_FLAVOUR": "validate+boot_nonmoving_gc",
- "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "RUNTEST_ARGS": "--way=nonmoving --way=nonmoving_thr --way=nonmoving_thr_sanity",
- "TEST_ENV": "x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "TEST_WAYS": "",
- "XZ_OPT": "-9"
- }
- },
"nightly-x86_64-linux-deb13-validate+llvm": {
"after_script": [
".gitlab/ci.sh save_cache",
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2f3ac43ab2cdded81e6912375b453aa…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2f3ac43ab2cdded81e6912375b453aa…
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
1
0
[Git][ghc/ghc][wip/sjakobi/T27284-nonmoving-nightly] ci: Remove the non-moving GC job from the nightly pipeline
by Simon Jakobi (@sjakobi) 23 Nov '26
by Simon Jakobi (@sjakobi) 23 Nov '26
23 Nov '26
Simon Jakobi pushed to branch wip/sjakobi/T27284-nonmoving-nightly at Glasgow Haskell Compiler / GHC
Commits:
f2e02167 by Simon Jakobi at 2026-11-23T09:35:18+01:00
ci: Remove the non-moving GC job from the nightly pipeline
The nightly x86_64-linux-deb13-validate+boot_nonmoving_gc-test job has
been running into its 8 hour timeout every night. This removes it along
with its build job.
MR pipelines still run the non-moving GC jobs when the "non-moving GC"
label is set.
Context: #27284
Assisted-by: Claude Fable 5.2
- - - - -
2 changed files:
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
Changes:
=====================================
.gitlab/generate-ci/gen_ci.hs
=====================================
@@ -1255,6 +1255,10 @@ onlyRule t = modifyValidateJobs (onlyValidateJobRule t)
disableValidate :: JobGroup Job -> JobGroup Job
disableValidate = modifyValidateJobs (removeValidateJobRule FastCI . removeValidateJobRule FullCI)
+-- | Drop the nightly job from a 'JobGroup'.
+disableNightly :: JobGroup a -> JobGroup a
+disableNightly jg = jg { n = Nothing }
+
---------------------------------------------------------------------
-- NamedJob
---------------------------------------------------------------------
@@ -1349,7 +1353,8 @@ debian_x86 =
, onlyRule LLVMBackend (validateBuilds Amd64 (Linux validate_debian) llvm)
, addValidateRule TestPrimops (standardBuilds Amd64 (Linux validate_debian))
- , onlyRule NonmovingGc (validateBuilds Amd64 (Linux validate_debian) vanilla {validateNonmovingGc = True})
+ , -- No nightly while the test job times out: #27284
+ disableNightly (onlyRule NonmovingGc (validateBuilds Amd64 (Linux validate_debian) vanilla {validateNonmovingGc = True}))
, onlyRule IpeData (validateBuilds Amd64 (Linux validate_debian) zstdIpe)
]
where
=====================================
.gitlab/jobs.yaml
=====================================
@@ -5277,131 +5277,6 @@
"XZ_OPT": "-9"
}
},
- "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc": {
- "after_script": [
- ".gitlab/ci.sh save_cache",
- ".gitlab/ci.sh save_test_output",
- ".gitlab/ci.sh clean",
- "cat ci_timings.txt"
- ],
- "allow_failure": false,
- "artifacts": {
- "expire_in": "8 weeks",
- "paths": [
- "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc.tar.xz",
- "junit.xml",
- "unexpected-test-output.tar.gz",
- "_build/stage1/haddock-timing-files"
- ],
- "reports": {
- "junit": "junit.xml"
- },
- "when": "always"
- },
- "cache": {
- "key": "x86_64-linux-deb13-$CACHE_REV",
- "paths": [
- "cabal-cache",
- "toolchain"
- ]
- },
- "image": "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb13:$DOCKER_REV",
- "needs": [
- {
- "artifacts": false,
- "job": "hadrian-ghc-in-ghci"
- }
- ],
- "rules": [
- {
- "if": "(\"true\" == \"true\") && ($RELEASE_JOB != \"yes\") && ($NIGHTLY)",
- "when": "on_success"
- }
- ],
- "script": [
- "sudo chown ghc:ghc -R .",
- ".gitlab/ci.sh setup",
- ".gitlab/ci.sh configure",
- ".gitlab/ci.sh build_hadrian",
- ".gitlab/ci.sh test_hadrian_stage1"
- ],
- "stage": "full-build",
- "tags": [
- "x86_64-linux"
- ],
- "variables": {
- "BIGNUM_BACKEND": "gmp",
- "BIN_DIST_NAME": "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "BUILD_FLAVOUR": "validate+boot_nonmoving_gc",
- "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "RUNTEST_ARGS": "--way=nonmoving --way=nonmoving_thr --way=nonmoving_thr_sanity",
- "TEST_ENV": "x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "TEST_WAYS": "",
- "XZ_OPT": "-9"
- }
- },
- "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc-test": {
- "after_script": [
- ".gitlab/ci.sh save_cache",
- ".gitlab/ci.sh save_test_output",
- ".gitlab/ci.sh clean",
- "cat ci_timings.txt"
- ],
- "allow_failure": false,
- "artifacts": {
- "expire_in": "8 weeks",
- "paths": [
- "junit.xml",
- "unexpected-test-output.tar.gz"
- ],
- "reports": {
- "junit": "junit.xml"
- },
- "when": "always"
- },
- "cache": {
- "key": "x86_64-linux-deb13-$CACHE_REV",
- "paths": [
- "cabal-cache",
- "toolchain"
- ]
- },
- "image": "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb13:$DOCKER_REV",
- "needs": [
- {
- "artifacts": true,
- "job": "nightly-x86_64-linux-deb13-validate+boot_nonmoving_gc"
- }
- ],
- "rules": [
- {
- "if": "(\"true\" == \"true\") && ($RELEASE_JOB != \"yes\") && ($NIGHTLY)",
- "when": "on_success"
- }
- ],
- "script": [
- "sudo chown ghc:ghc -R .",
- ".gitlab/ci.sh setup",
- ".gitlab/ci.sh configure",
- ".gitlab/ci.sh test_hadrian"
- ],
- "stage": "testing",
- "tags": [
- "x86_64-linux"
- ],
- "variables": {
- "BIGNUM_BACKEND": "gmp",
- "BIN_DIST_NAME": "ghc-x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "BUILD_FLAVOUR": "validate+boot_nonmoving_gc",
- "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
- "RUNTEST_ARGS": "--way=nonmoving --way=nonmoving_thr --way=nonmoving_thr_sanity",
- "TEST_ENV": "x86_64-linux-deb13-validate+boot_nonmoving_gc",
- "TEST_WAYS": "",
- "XZ_OPT": "-9"
- }
- },
"nightly-x86_64-linux-deb13-validate+llvm": {
"after_script": [
".gitlab/ci.sh save_cache",
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2e02167f7b7a0b96bb33cb1d1b5c86…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2e02167f7b7a0b96bb33cb1d1b5c86…
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
1
0
23 Nov '26
Zubin pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
3e66b59c by Andrea Vezzosi at 2026-11-23T12:52:30+05:30
test case for #28104
(cherry picked from commit c032076a9cd2a6ce2fea66df98fd5f5c85e81aac)
- - - - -
d991ab3c by Zubin Duggal at 2026-11-23T14:02:49+05:30
loader: fix #28104
Ensure LoaderState is recorded accurately and consistent in the presence of failures
* loadObjects: when resolveObjs fails, unload only the objects freshly loaded
and return the old LoaderState. Before this we used to unload every home module with
unload_wkr, but then its callers threw inside `modifyLoaderState`, which
restored the old state, which contained objects that were already unloaded.
The objects loaded by `loadObjects` are also unloaded if loading or
resolving fails.
* loadName, loadDecls, loadModule: report failure after the transaction
has committed, so we don't mangle the loader state by restoring the old
state.
* unload: Keep track of things that were succefully unloaded on exception
and unload each object of a module only once. The foreign stub
objects of a bytecode module are recorded in both objs_loaded and
bcos_loaded, so with a non-dynamic interpreter unloading such a module
called unloadObj twice on the same object and failed.
Fixes #28104
- - - - -
19a4dfcd by Zubin Duggal at 2026-11-23T14:02:49+05:30
loader: make crucial sequences uninterruptible
Add masks so that we don't observe async exceptions
during sequences that can't deal with them.
- - - - -
10 changed files:
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Runtime/Interpreter.hs
- + testsuite/tests/ghci/linking/UnloadWkrA.hs
- + testsuite/tests/ghci/linking/UnloadWkrB.hs
- testsuite/tests/ghci/linking/all.T
- + testsuite/tests/ghci/linking/unload_wkr-throw-ext.stderr
- + testsuite/tests/ghci/linking/unload_wkr-throw-ext.stdout
- + testsuite/tests/ghci/linking/unload_wkr-throw.script
- + testsuite/tests/ghci/linking/unload_wkr-throw.stderr
- + testsuite/tests/ghci/linking/unload_wkr-throw.stdout
Changes:
=====================================
compiler/GHC/Linker/Loader.hs
=====================================
@@ -111,6 +111,7 @@ import GHC.Linker.Types
import Control.Monad
import Data.Array
+import Data.Containers.ListUtils (nubOrd)
import Data.ByteString (ByteString)
import qualified Data.Set as Set
import Data.Char (isSpace)
@@ -172,12 +173,12 @@ uninitialised = panic "Loader not initialised"
modifyLoaderState_ :: SafeInterp -> (Interp -> LoaderState -> IO LoaderState) -> IO ()
modifyLoaderState_ interp0 f = withInterp interp0 $ \ interp ->
- modifyMVar_ (loader_state (interpLoader interp))
+ modifyMVarMasked_ (loader_state (interpLoader interp))
(fmap pure . f interp . fromMaybe uninitialised)
modifyLoaderState :: SafeInterp -> (Interp -> LoaderState -> IO (LoaderState, a)) -> IO a
modifyLoaderState interp0 f = withInterp interp0 $ \ interp ->
- modifyMVar (loader_state (interpLoader interp))
+ modifyMVarMasked (loader_state (interpLoader interp))
(fmapFst pure . f interp . fromMaybe uninitialised)
where fmapFst f = fmap (\(x, y) -> (f x, y))
@@ -234,27 +235,27 @@ lookupFromLoadedEnv interp name = do
loadName :: SafeInterp -> HscEnv -> Name -> IO (ForeignHValue, [LinkableUsage], PkgsLoaded)
loadName interp0 hsc_env name = do
initLoaderState interp0 hsc_env
- modifyLoaderState interp0 $ \interp pls0 -> do
- (pls, links, pkgs) <- if not (isExternalName name)
- then return (pls0, [], emptyUDFM)
- else do
- (pls', ok, links, pkgs) <- loadDependencies interp hsc_env pls0 noSrcSpan
- [nameModule name]
- if failed ok
- then throwGhcExceptionIO (ProgramError "")
- else return (pls', links, pkgs)
-
- case lookupNameBytecodeState (bco_loader_state pls) name of
- Just (_,aa) -> return (pls,(aa, links, pkgs))
+ (ok, m, links, pkgs) <- modifyLoaderState interp0 $ \interp pls0 -> do
+ (pls, ok, links, pkgs) <- if not (isExternalName name)
+ then return (pls0, Succeeded, [], emptyUDFM)
+ else loadDependencies interp hsc_env pls0 noSrcSpan [nameModule name]
+
+ m <- case lookupNameBytecodeState (bco_loader_state pls) name of
+ _ | failed ok -> return Nothing
+ Just (_,aa) -> return (Just aa)
Nothing -> assertPpr (isExternalName name) (ppr name) $
- do let sym_to_find = IClosureSymbol name
- -- TODO: does not take loader state lock
- m <- lookupClosure interp sym_to_find
- r <- case m of
- Just fhv -> return fhv
- Nothing -> linkFail "GHC.Linker.Loader.loadName"
- (ppr sym_to_find)
- return (pls,(r, links, pkgs))
+ -- TODO: does not take loader state lock
+ interpUninterruptibleMask_ interp $
+ lookupClosure interp sym_to_find
+ return (pls, (ok, m, links, pkgs))
+
+ when (failed ok) $ throwGhcExceptionIO (ProgramError "")
+ case m of
+ Just fhv -> return (fhv, links, pkgs)
+ Nothing -> linkFail "GHC.Linker.Loader.loadName"
+ (ppr sym_to_find)
+ where
+ sym_to_find = IClosureSymbol name
-- | Restrict a 'PkgsLoaded' map to the packages directly needed and their
-- full transitive closure (via 'loaded_pkg_trans_deps').
@@ -465,7 +466,7 @@ loadCmdLineLibs'' interp hsc_env pls =
++ map Framework frameworks
if null cmdline_lib_specs
then return pls
- else do
+ else interpUninterruptibleMask_ interp $ do
-- Add directories to library search paths, this only has an effect
-- on Windows. On Unix OSes this function is a NOP.
let all_paths = let paths = takeDirectory (pgm_c dflags)
@@ -737,16 +738,19 @@ loadDecls interp0 hsc_env span linkable = do
initLoaderState interp0 hsc_env
-- Take lock for the actual work.
- modifyLoaderState interp0 $ \interp pls0 -> do
+ (ok, ok2, links_needed, units_needed) <- modifyLoaderState interp0 $ \interp pls0 -> do
-- Link the packages and modules required
(pls, ok, links_needed, units_needed) <- loadDependencies interp hsc_env pls0 span needed_mods
- if failed ok
- then throwGhcExceptionIO (ProgramError "could not load dependencies for decls")
- else do
- (pls2, ok2) <- loadInternalModuleLinkables interp hsc_env pls [linkable]
- when (failed ok2) $
- throwGhcExceptionIO (ProgramError "could not load linkable for decls")
- return (pls2, (links_needed, units_needed))
+ (pls2, ok2) <- if failed ok
+ then return (pls, Failed)
+ else loadInternalModuleLinkables interp hsc_env pls [linkable]
+ return (pls2, (ok, ok2, links_needed, units_needed))
+
+ when (failed ok) $
+ throwGhcExceptionIO (ProgramError "could not load dependencies for decls")
+ when (failed ok2) $
+ throwGhcExceptionIO (ProgramError "could not load linkable for decls")
+ return (links_needed, units_needed)
where
cbcs = linkableBCOs linkable
@@ -774,11 +778,11 @@ loadDecls interp0 hsc_env span linkable = do
loadModule :: SafeInterp -> HscEnv -> Module -> IO ()
loadModule interp0 hsc_env mod = do
initLoaderState interp0 hsc_env
- modifyLoaderState_ interp0 $ \interp pls -> do
+ ok <- modifyLoaderState interp0 $ \interp pls -> do
(pls', ok, _, _) <- loadDependencies interp hsc_env pls noSrcSpan [mod]
- if failed ok
- then throwGhcExceptionIO (ProgramError "could not load module")
- else return pls'
+ return (pls', ok)
+ when (failed ok) $
+ throwGhcExceptionIO (ProgramError "could not load module")
{- **********************************************************************
@@ -811,7 +815,7 @@ loadInternalModuleLinkables interp hsc_env pls linkables =
loadModuleLinkables :: Interp -> HscEnv -> LoaderState -> KeepModuleLinkableDefinitions -> [Linkable] -> IO (LoaderState, SuccessFlag)
loadModuleLinkables interp hsc_env pls keep_spec linkables
- = mask_ $ do -- don't want to be interrupted by ^C in here
+ = interpUninterruptibleMask_ interp $ do -- don't want to be interrupted by ^C in here
debugTraceMsg (hsc_logger hsc_env) 3 $
hang (text "Loading module linkables") 2 $ vcat [
@@ -862,18 +866,19 @@ loadObjects interp hsc_env pls objs = do
if interpreterDynamic interp
then do pls2 <- dynLoadObjs interp hsc_env pls1 wanted_objs
return (pls2, Succeeded)
- else do mapM_ (loadObj interp) wanted_objs
+ else do loaded <- newIORef []
+ let load obj = loadObj interp obj >> modifyIORef' loaded (obj :)
+ undo = readIORef loaded >>= mapM_ (unloadObj interp)
-- Link them all together
- ok <- resolveObjs interp
+ ok <- (mapM_ load wanted_objs >> resolveObjs interp)
+ `onException` undo
- -- If resolving failed, unload all our
- -- object modules and carry on
if succeeded ok then
return (pls1, Succeeded)
else do
- pls2 <- unload_wkr interp pls1
- return (pls2, Failed)
+ undo
+ return (pls, Failed)
-- | Create a shared library containing the given object files
@@ -1146,10 +1151,6 @@ What we need to avoid is having more in the 'LoaderState' than is actually
loaded. This can only happen while unloading, which is why purge the symbol cache
before the unload.
-We should also make sure the emptied out loader state returned from unload_wkr
-gets actually written to the loader state, the failure to do so is tracked by
-#28104.
-
-}
-- ---------------------------------------------------------------------------
@@ -1168,16 +1169,15 @@ unload interp0 hsc_env
-- Initialise the linker (if it's not been done already)
initLoaderState interp0 hsc_env
- _new_pls <- modifyLoaderState interp0 $ \interp pls -> do
- pls1 <- unload_wkr interp pls
- return (pls1, pls1)
-
- return ()
+ withInterp interp0 $ \_ -> do
+ err <- modifyLoaderState interp0 $ \interp ->
+ interpUninterruptibleMask_ interp . unload_wkr interp
+ mapM_ throwIO err
unload_wkr
:: Interp
-> LoaderState
- -> IO LoaderState
+ -> IO (LoaderState, Maybe SomeException)
-- Does the core unload business
-- (the wrapper blocks exceptions and deals with the LS get and put)
@@ -1186,41 +1186,47 @@ unload_wkr interp pls@LoaderState{..} = do
-- we're unloading some code. -fghci-leak-check with the tests in
-- testsuite/ghci can detect space leaks here.
- let linkables_to_unload = moduleEnvElts objs_loaded ++ moduleEnvElts bcos_loaded
+ let objs_to_unload = mapModuleEnv nubOrd $
+ plusModuleEnv_C (++) (mapModuleEnv linkableUsageObjs objs_loaded)
+ (mapModuleEnv linkableUsageObjs bcos_loaded)
-- If we unloaded any object files at all, we need to purge the cache
-- of lookupSymbol results.
-- We do so before actually unloading, so the cache is never stale.
--
-- See Note [LoaderState may lag the interpreter]
- when (not (null (filter (not . null . linkableUsageObjs) linkables_to_unload))) $
+ when (any (not . null) (moduleEnvElts objs_to_unload)) $
purgeLookupSymbolCache interp
- mapM_ unloadObjs linkables_to_unload
+ (objs_left, err) <- foldM unloadObjs (objs_loaded, Nothing) (moduleEnvToList objs_to_unload)
- -- FIXME: this emptied state should be committed even on exceptions, see #28104
let !new_pls = pls { bco_loader_state = modifyHomePackageBytecodeState bco_loader_state $ \_ -> emptyBytecodeState,
-- NB: we don't unload the external package
bcos_loaded = emptyModuleEnv,
- objs_loaded = emptyModuleEnv }
+ objs_loaded = objs_left }
- return new_pls
+ return (new_pls, err)
where
- unloadObjs :: LinkableUsage -> IO ()
- unloadObjs lnk
- | interpreterDynamic interp = return ()
+ unloadObjs
+ :: (LinkableSet LinkableUsage, Maybe SomeException)
+ -> (Module, [FilePath])
+ -> IO (LinkableSet LinkableUsage, Maybe SomeException)
+ unloadObjs acc@(_, Just _) _ = return acc
+ unloadObjs (objs_left, Nothing) (mod, objs)
+ | interpreterDynamic interp = return (delModuleEnv objs_left mod, Nothing)
-- We don't do any cleanup when linking objects with the
-- dynamic linker. Doing so introduces extra complexity for
-- not much benefit.
| otherwise
- = mapM_ (unloadObj interp) (linkableUsageObjs lnk)
+ = do r <- try $ mapM_ (unloadObj interp) objs
-- The components of a BCO linkable may contain
-- dot-o files (generated from C stubs).
--
-- But the BCO parts can be unlinked just by
-- letting go of them (plus of course depopulating
-- the symbol table which is done in the main body)
+ return (delModuleEnv objs_left mod, either Just (const Nothing) r)
showLS :: LibrarySpec -> String
showLS (Objects nms) = "(static) [" ++ intercalate ", " nms ++ "]"
@@ -1315,7 +1321,8 @@ loadPackages' :: Interp -> HscEnv -> [UnitId] -> LoaderState -> IO LoaderState
loadPackages' interp hsc_env new_pks pls = do
(reverse -> pkgs_info_list, pkgs_almost_loaded) <-
loadMoreUnits hsc_env new_pks (pkgs_loaded pls)
- loadPackage interp hsc_env pkgs_info_list (pls { pkgs_loaded = pkgs_almost_loaded })
+ interpUninterruptibleMask_ interp $
+ loadPackage interp hsc_env pkgs_info_list (pls { pkgs_loaded = pkgs_almost_loaded })
loadPackage :: Interp -> HscEnv -> [UnitInfo] -> LoaderState -> IO LoaderState
=====================================
compiler/GHC/Runtime/Interpreter.hs
=====================================
@@ -49,6 +49,7 @@ module GHC.Runtime.Interpreter
, interpCmd
, withInterpCmdMasked
+ , interpUninterruptibleMask_
, withExtInterp
, withExtInterpStatus
, withIServ
@@ -212,6 +213,17 @@ interpCmd interp msg = case interpInstance interp of
withInterpCmdMasked :: Binary a => Interp -> Message a -> (a -> IO b) -> IO b
withInterpCmdMasked interp msg own = mask_ $ interpCmd interp msg >>= own
+interpUninterruptibleMask_ :: Interp -> IO a -> IO a
+interpUninterruptibleMask_ interp act = do
+ case interpInstance interp of
+#if defined(HAVE_INTERNAL_INTERPRETER)
+ InternalInterp -> pure ()
+#endif
+ -- make sure the external interpreter process is running, so that the
+ -- interpreter is spawned outside the uninterruptibleMask
+ ExternalInterp ext -> withExtInterp ext $ \_ -> pure ()
+ uninterruptibleMask_ act
+
-- | Passes the `Interp` to the continuation while setting up a
-- 'PipeClosedException' handler that calls 'stopInterp'.
--
=====================================
testsuite/tests/ghci/linking/UnloadWkrA.hs
=====================================
@@ -0,0 +1,4 @@
+module UnloadWkrA where
+
+hello :: String
+hello = "hello from UnloadWkrA"
=====================================
testsuite/tests/ghci/linking/UnloadWkrB.hs
=====================================
@@ -0,0 +1,11 @@
+module UnloadWkrB where
+
+-- Deliberately refers to a symbol that does not exist anywhere, so that
+-- resolveObjs fails when this module's object code is linked into the
+-- interpreter. That is the only way to reach the unload_wkr call in
+-- GHC.Linker.Loader.loadObjects.
+foreign import ccall unsafe "unload_wkr_throw_missing_symbol"
+ c_boom :: IO ()
+
+boom :: IO ()
+boom = c_boom
=====================================
testsuite/tests/ghci/linking/all.T
=====================================
@@ -77,3 +77,53 @@ test('big-obj', [extra_files(['big-obj-c.c', 'big-obj.hs']),
makefile_test, ['big-obj'])
test('T25155', [req_c, req_th, req_interp, req_rts_linker, extra_files(['T25155_iserv_main.c', 'T25155_iserv.hs', 'T25155_TH.hs'])], makefile_test, [])
+
+# unload_wkr-throw{,-ext}: a link failure in one module must not silently
+# unload another module that was already linked.
+#
+# When resolveObjs fails, GHC.Linker.Loader.loadObjects calls unload_wkr, which
+# empties objs_loaded/bcos_loaded/bco_loader_state and returns the new state.
+# But every caller of unload_wkr except `unload` itself then throws on the
+# Failed result, so modifyLoaderState's modifyMVar restores the *old* state and
+# GHC goes on believing UnloadWkrA is loaded after the interpreter has dropped
+# it. Evaluating UnloadWkrA.hello then fails, and the :reload after it calls
+# unloadObj on an object the RTS has already unloaded.
+#
+# Only reachable when the interpreter is not dynamic: the dynamic branch of
+# loadObjects goes through dynLoadObjs and never calls resolveObjs at all.
+# For the internal interpreter that means a non-dynamic GHC (hostIsDynamic is
+# fixed at build time), hence the ghc_dynamic skip. The external interpreter
+# takes its way from the session, so -static is enough there.
+#
+# The expected output is the *fixed* behaviour: UnloadWkrB fails to link and
+# nothing else does, so UnloadWkrA keeps working and :reload succeeds.
+
+def normalise_unload_wkr(s):
+ import re
+ # The failing object is named with the full path of the test directory.
+ s = re.sub(r'(Could not load Object Code ).*(UnloadWkrB\.o)', r'\1\2', s)
+ # With -fexternal-interpreter the messages are prefixed with the name of
+ # the iserv binary, which GHC generates into a temporary directory.
+ # normalise_errmsg only knows how to normalise the compiler's own name.
+ s = re.sub(r'^ghc_tmp_\d+\.iserv:', 'ghc:', s, flags=re.M)
+ return s
+
+test('unload_wkr-throw',
+ [extra_files(['UnloadWkrA.hs', 'UnloadWkrB.hs']),
+ extra_run_opts('-fobject-code'),
+ only_ways(['ghci']),
+ unless(doing_ghci, skip),
+ req_rts_linker,
+ when(ghc_dynamic(), skip),
+ normalise_errmsg_fun(normalise_unload_wkr)],
+ ghci_script, ['unload_wkr-throw.script'])
+
+test('unload_wkr-throw-ext',
+ [extra_files(['UnloadWkrA.hs', 'UnloadWkrB.hs',
+ 'unload_wkr-throw.script']),
+ extra_run_opts('-static -fexternal-interpreter -fobject-code'),
+ only_ways(['ghci']),
+ unless(doing_ghci, skip),
+ req_rts_linker,
+ normalise_errmsg_fun(normalise_unload_wkr)],
+ ghci_script, ['unload_wkr-throw.script'])
=====================================
testsuite/tests/ghci/linking/unload_wkr-throw-ext.stderr
=====================================
@@ -0,0 +1,5 @@
+ghc: Failed to lookup symbol: unload_wkr_throw_missing_symbol, you might consider using --optimistic-linking
+
+ghc: Could not load Object Code UnloadWkrB.o.
+
+could not load dependencies for decls
=====================================
testsuite/tests/ghci/linking/unload_wkr-throw-ext.stdout
=====================================
@@ -0,0 +1,3 @@
+hello from UnloadWkrA
+hello from UnloadWkrA
+hello from UnloadWkrA
=====================================
testsuite/tests/ghci/linking/unload_wkr-throw.script
=====================================
@@ -0,0 +1,6 @@
+:load UnloadWkrA UnloadWkrB
+putStrLn UnloadWkrA.hello
+UnloadWkrB.boom
+putStrLn UnloadWkrA.hello
+:reload
+putStrLn UnloadWkrA.hello
=====================================
testsuite/tests/ghci/linking/unload_wkr-throw.stderr
=====================================
@@ -0,0 +1,5 @@
+ghc: Failed to lookup symbol: unload_wkr_throw_missing_symbol, you might consider using --optimistic-linking
+
+ghc: Could not load Object Code UnloadWkrB.o.
+
+could not load dependencies for decls
=====================================
testsuite/tests/ghci/linking/unload_wkr-throw.stdout
=====================================
@@ -0,0 +1,3 @@
+hello from UnloadWkrA
+hello from UnloadWkrA
+hello from UnloadWkrA
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/abdfbbf39d8704a3bccebca9ae231a…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/abdfbbf39d8704a3bccebca9ae231a…
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
1
0
[Git][ghc/ghc] Pushed new branch wip/sjakobi/T27284-nonmoving-nightly
by Simon Jakobi (@sjakobi) 23 Nov '26
by Simon Jakobi (@sjakobi) 23 Nov '26
23 Nov '26
Simon Jakobi pushed new branch wip/sjakobi/T27284-nonmoving-nightly at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/T27284-nonmoving-nigh…
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
1
0