[Git][ghc/ghc][master] hadrian: Persist the used flavour name in the build root (#20650)
by Marge Bot (@marge-bot) 06 Oct '26
by Marge Bot (@marge-bot) 06 Oct '26
06 Oct '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
b3b89d32 by mangoiv at 2026-10-05T22:03:32-04:00
hadrian: Persist the used flavour name in the build root (#20650)
This executes the idea proposed in #20650, teaching Hadrian to persist
the flavour used to build a build root. This both makes use of multiple
build roots more ergonomic (as the user no longer needs to repeat
themselves) and avoids a tiresome foot-gun (forgetting to specify a
flavour, often wholly invalidating a build root).
Closes #20650.
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
- - - - -
4 changed files:
- + changelog.d/hadrian-persist-flavour
- hadrian/doc/flavours.md
- hadrian/src/Rules.hs
- hadrian/src/Settings.hs
Changes:
=====================================
changelog.d/hadrian-persist-flavour
=====================================
@@ -0,0 +1,7 @@
+section: packaging
+synopsis: Hadrian now persists the flavour name in the build root. When
+ rebuilding, the previously used flavour is automatically restored, removing
+ the need to re-specify it on every invocation and avoiding accidental build
+ root invalidation.
+issues: #20650
+mrs: !7017
=====================================
hadrian/doc/flavours.md
=====================================
@@ -3,7 +3,14 @@
Hadrian supports a few predefined _build flavours_, i.e. collections of build
settings that fully define a GHC build (see `src/Flavour.hs`). Users can add their
own build flavours if need be, as described
-[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#build-flavour).
+[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#build-flavour) or modify existing flavours using the flavour transformers notion seem below.
+
+The flavour to be used for a build root can be specified on the command-line
+via the `--flavour` flag. Moreover, this flavour name is saved in the build
+root; future invocations of Hadrian without a `--flavour` flag will default to
+the last-used flavour.
+
+See `Note [Persisting the flavour]` in `hadrian/src/Settings.hs`
## Arguments
=====================================
hadrian/src/Rules.hs
=====================================
@@ -129,6 +129,7 @@ packageRules = do
buildRules :: Rules ()
buildRules = do
+ Settings.flavourFileRules
Rules.BinaryDist.bindistRules
Rules.Generate.copyRules
Rules.Generate.generateRules
=====================================
hadrian/src/Settings.hs
=====================================
@@ -1,10 +1,14 @@
+{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE TypeFamilies #-}
+
module Settings (
getExtraArgs, getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
findPackageByName, unsafeFindPackageByName, unsafeFindPackageByPath,
isLibrary, stagePackages, getBignumBackend, completeSetting,
queryBuildTarget, queryHostTarget,
queryBuild, queryHost,
- queryArch, queryOS, queryVendor
+ queryArch, queryOS, queryVendor,
+ flavourFileRules
) where
import CommandLine
@@ -58,6 +62,56 @@ hadrianFlavours =
, ghcInGhciFlavour, validateFlavour, slowValidateFlavour
]
+{-
+Note [Persisting the flavour]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Passing the flavour on the command-line means the user must consistently pass
+the same --flavour flag to all Hadrian invocations on a particular build root.
+Forgetting even once can result in a full rebuild of the tree.
+
+To avoid this we persist the flavour name in the build root itself
+(specifically, in `<build root>/flavour`). We refer to this file when looking
+up the active flavour, defaulting to it if the user does not specify a flavour
+name explicitly.
+-}
+
+-- | Oracle query type for the active flavour name.
+-- See Note [Persisting the flavour].
+newtype FlavourName = FlavourName ()
+ deriving (Binary, Eq, Hashable, NFData, Show)
+type instance RuleResult FlavourName = String
+
+flavourFileRules :: Rules ()
+flavourFileRules = do
+ root <- buildRootRules
+
+ -- Cache the flavour name lookup for the whole Shake run.
+ -- alwaysRerun ensures the oracle re-executes on every new invocation so
+ -- that a changed --flavour flag is never ignored due to a stale cross-run
+ -- cache entry (CLI args are not tracked as Shake dependencies).
+ -- See Note [Persisting the flavour].
+ void $ addOracleCache $ \(FlavourName _) -> do
+ alwaysRerun
+ let flavourFile = root -/- "flavour"
+ cmdFlavour >>= \case
+ Just nm -> do
+ putBuild $ "Flavour: " ++ nm
+ liftIO $ writeFile flavourFile nm
+ return nm
+ Nothing -> do
+ exists <- doesFileExist flavourFile
+ if exists
+ then do nm <- liftIO $ readFile flavourFile
+ putBuild $ "Flavour: " ++ nm ++ " (cached from last build, override by passing --flavour=... explicitly)"
+ return nm
+ else return userDefaultFlavour
+
+-- | Lookup the requested flavour name, referring to the persistent flavour
+-- file saved from the previous Hadrian execution if not specified.
+-- The result is cached for the whole Shake run via the 'FlavourName' oracle.
+getFlavourName :: Action String
+getFlavourName = askOracle (FlavourName ())
+
-- | This action looks up a flavour with the name given on the
-- command line with @--flavour@, defaulting to 'userDefaultFlavour'
-- when no explicit @--flavour@ is passed. It then applies any
@@ -66,7 +120,7 @@ hadrianFlavours =
-- syntax. See Note [Hadrian settings] at the bottom of this file.
flavour :: Action Flavour
flavour = do
- flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour
+ flavourName <- getFlavourName
when ("quickest" `isPrefixOf` flavourName) $
fail $ "The `quickest` flavour has been deprecated. Use `quick` instead.\n"
++ "Skip building dynamic libraries with `quick+no_dynamic_libs`\n"
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3b89d3245c4b4ed93508e69919e288…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3b89d3245c4b4ed93508e69919e288…
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
05 Oct '26
Simon Peyton Jones pushed to branch wip/T27737 at Glasgow Haskell Compiler / GHC
Commits:
66b289eb by Simon Peyton Jones at 2026-10-05T22:53:00+01:00
Fix in-scope set violation
- - - - -
1 changed file:
- compiler/GHC/Core/SimpleOpt.hs
Changes:
=====================================
compiler/GHC/Core/SimpleOpt.hs
=====================================
@@ -1716,7 +1716,7 @@ exprIsConApp_maybe ise@(ISE in_scope id_unf) expr
subst_bndr (Left in_scope) bndr
| bndr `elemInScopeSet` in_scope = subst_bndr1 (mkEmptySubst in_scope) bndr
- | otherwise = (Left in_scope, bndr)
+ | otherwise = (Left (in_scope `extendInScopeSet` bndr), bndr)
subst_bndr (Right subst) bndr = subst_bndr1 subst bndr
subst_bndr1 subst bndr
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66b289eb1c549eb96f88d7d697468b1…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66b289eb1c549eb96f88d7d697468b1…
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/marge_bot_batch_merge_job] 3 commits: hadrian: Persist the used flavour name in the build root (#20650)
by Marge Bot (@marge-bot) 05 Oct '26
by Marge Bot (@marge-bot) 05 Oct '26
05 Oct '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
afa5c414 by mangoiv at 2026-10-05T15:42:57-04:00
hadrian: Persist the used flavour name in the build root (#20650)
This executes the idea proposed in #20650, teaching Hadrian to persist
the flavour used to build a build root. This both makes use of multiple
build roots more ergonomic (as the user no longer needs to repeat
themselves) and avoids a tiresome foot-gun (forgetting to specify a
flavour, often wholly invalidating a build root).
Closes #20650.
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
- - - - -
4b89c7cc by mangoiv at 2026-10-05T15:42:58-04:00
configure: fix sed script and subst tooldir script
Fixes #27672
Adds sanity checking for SUBST_TOOLDIR
Metric Decrease:
LinkableUsage01
MultiLayerModulesTH_OneShot
T10547
T12234
T12425
T13035
T13820
T18140
T18730
T18923
T9198
TcPlugin_RewritePerf
mhu-perf
- - - - -
aee5101e by Hannes Siebenhandl at 2026-10-05T15:42:59-04:00
Prepend in-memory unit database for backpack
The packageDbFlags are stored in reverse order. Thus, prepending will
ensure that the in-memory unit database is the last item on the unit
database stack.
Further, the in-memory unit database needs to be able to shadow units
from earlier unit databases in the unit database stack.
Moreover, a `-clear-package-db` would remove the in-memory database if
it weren't the last item on the stack.
Closes #27835
- - - - -
11 changed files:
- + changelog.d/hadrian-persist-flavour
- changelog.d/unit-index
- compiler/GHC/Driver/Backpack.hs
- distrib/configure.ac.in
- hadrian/doc/flavours.md
- hadrian/src/Rules.hs
- hadrian/src/Settings.hs
- m4/subst_tooldir.m4
- + testsuite/tests/backpack/should_compile/T27835.bkp
- + testsuite/tests/backpack/should_compile/T27835.stderr
- testsuite/tests/backpack/should_compile/all.T
Changes:
=====================================
changelog.d/hadrian-persist-flavour
=====================================
@@ -0,0 +1,7 @@
+section: packaging
+synopsis: Hadrian now persists the flavour name in the build root. When
+ rebuilding, the previously used flavour is automatically restored, removing
+ the need to re-specify it on every invocation and avoiding accidental build
+ root invalidation.
+issues: #20650
+mrs: !7017
=====================================
changelog.d/unit-index
=====================================
@@ -1,7 +1,7 @@
section: compiler
synopsis: Use global ``UnitIndex`` to deduplicate ``UnitInfo``s over multiple home units
-issues: #27500 #26423 #27748 #27834
-mrs: !16115 !16598 !16743
+issues: #27500 #26423 #27748 #27834 #27835
+mrs: !16115 !16598 !16743 !16748
description: {
The ``UnitState`` used to be duplicated for all ``HomeUnitEnv``, not sharing any of the ``UnitInfo``s.
=====================================
compiler/GHC/Driver/Backpack.hs
=====================================
@@ -441,9 +441,11 @@ addInMemoryDatabase dflags u = do
}
let uic = hscUIC hsc_env
liftIO $ cacheExternalUnitDatabase uic newdb
- -- added at the end because ordering matters
+ -- Ordering matters here! We prepend the new unit database, because 'packageDBFlags'
+ -- works like a stack, where what's on top takes precedence over what's below (same as right-to-left when given at the CLI).
+ -- The new db needs highest precedence to overwrite any other in-memory units that potentially occur in the dbs below it.
pure dflags
- { packageDBFlags = packageDBFlags dflags ++ [PackageDB (PkgDbPath (unitDatabasePath newdb))]
+ { packageDBFlags = PackageDB (PkgDbPath (unitDatabasePath newdb)) : packageDBFlags dflags
}
-- | Register a new virtual unit database containing a single unit
=====================================
distrib/configure.ac.in
=====================================
@@ -103,7 +103,7 @@ AC_ARG_ENABLE(distro-toolchain,
AC_SUBST([EnableDistroToolchain])
if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"; then
- FP_SETUP_WINDOWS_TOOLCHAIN([$hardtop/mingw/], [\$\$topdir/../mingw/])
+ FP_SETUP_WINDOWS_TOOLCHAIN([$hardtop/mingw/], [\$topdir/../mingw/])
fi
=====================================
hadrian/doc/flavours.md
=====================================
@@ -3,7 +3,14 @@
Hadrian supports a few predefined _build flavours_, i.e. collections of build
settings that fully define a GHC build (see `src/Flavour.hs`). Users can add their
own build flavours if need be, as described
-[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#build-flavour).
+[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#build-flavour) or modify existing flavours using the flavour transformers notion seem below.
+
+The flavour to be used for a build root can be specified on the command-line
+via the `--flavour` flag. Moreover, this flavour name is saved in the build
+root; future invocations of Hadrian without a `--flavour` flag will default to
+the last-used flavour.
+
+See `Note [Persisting the flavour]` in `hadrian/src/Settings.hs`
## Arguments
=====================================
hadrian/src/Rules.hs
=====================================
@@ -129,6 +129,7 @@ packageRules = do
buildRules :: Rules ()
buildRules = do
+ Settings.flavourFileRules
Rules.BinaryDist.bindistRules
Rules.Generate.copyRules
Rules.Generate.generateRules
=====================================
hadrian/src/Settings.hs
=====================================
@@ -1,10 +1,14 @@
+{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE TypeFamilies #-}
+
module Settings (
getExtraArgs, getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
findPackageByName, unsafeFindPackageByName, unsafeFindPackageByPath,
isLibrary, stagePackages, getBignumBackend, completeSetting,
queryBuildTarget, queryHostTarget,
queryBuild, queryHost,
- queryArch, queryOS, queryVendor
+ queryArch, queryOS, queryVendor,
+ flavourFileRules
) where
import CommandLine
@@ -58,6 +62,56 @@ hadrianFlavours =
, ghcInGhciFlavour, validateFlavour, slowValidateFlavour
]
+{-
+Note [Persisting the flavour]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Passing the flavour on the command-line means the user must consistently pass
+the same --flavour flag to all Hadrian invocations on a particular build root.
+Forgetting even once can result in a full rebuild of the tree.
+
+To avoid this we persist the flavour name in the build root itself
+(specifically, in `<build root>/flavour`). We refer to this file when looking
+up the active flavour, defaulting to it if the user does not specify a flavour
+name explicitly.
+-}
+
+-- | Oracle query type for the active flavour name.
+-- See Note [Persisting the flavour].
+newtype FlavourName = FlavourName ()
+ deriving (Binary, Eq, Hashable, NFData, Show)
+type instance RuleResult FlavourName = String
+
+flavourFileRules :: Rules ()
+flavourFileRules = do
+ root <- buildRootRules
+
+ -- Cache the flavour name lookup for the whole Shake run.
+ -- alwaysRerun ensures the oracle re-executes on every new invocation so
+ -- that a changed --flavour flag is never ignored due to a stale cross-run
+ -- cache entry (CLI args are not tracked as Shake dependencies).
+ -- See Note [Persisting the flavour].
+ void $ addOracleCache $ \(FlavourName _) -> do
+ alwaysRerun
+ let flavourFile = root -/- "flavour"
+ cmdFlavour >>= \case
+ Just nm -> do
+ putBuild $ "Flavour: " ++ nm
+ liftIO $ writeFile flavourFile nm
+ return nm
+ Nothing -> do
+ exists <- doesFileExist flavourFile
+ if exists
+ then do nm <- liftIO $ readFile flavourFile
+ putBuild $ "Flavour: " ++ nm ++ " (cached from last build, override by passing --flavour=... explicitly)"
+ return nm
+ else return userDefaultFlavour
+
+-- | Lookup the requested flavour name, referring to the persistent flavour
+-- file saved from the previous Hadrian execution if not specified.
+-- The result is cached for the whole Shake run via the 'FlavourName' oracle.
+getFlavourName :: Action String
+getFlavourName = askOracle (FlavourName ())
+
-- | This action looks up a flavour with the name given on the
-- command line with @--flavour@, defaulting to 'userDefaultFlavour'
-- when no explicit @--flavour@ is passed. It then applies any
@@ -66,7 +120,7 @@ hadrianFlavours =
-- syntax. See Note [Hadrian settings] at the bottom of this file.
flavour :: Action Flavour
flavour = do
- flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour
+ flavourName <- getFlavourName
when ("quickest" `isPrefixOf` flavourName) $
fail $ "The `quickest` flavour has been deprecated. Use `quick` instead.\n"
++ "Skip building dynamic libraries with `quick+no_dynamic_libs`\n"
=====================================
m4/subst_tooldir.m4
=====================================
@@ -41,5 +41,5 @@ dnl ghc-toolchain.
# See Note [How we configure the bundled windows toolchain]
AC_DEFUN([SUBST_TOOLDIR],
[
- sed -i.bkp $1 's%'"$mingw_prefix"'%'"$mingw_install_prefix"'%g'
+ sed -i.bkp 's%'"$mingw_prefix"'%'"$mingw_install_prefix"'%g' $1
])
=====================================
testsuite/tests/backpack/should_compile/T27835.bkp
=====================================
@@ -0,0 +1,11 @@
+unit p where
+ module P where
+ p :: Int
+ p = 42
+
+unit q where
+ dependency p
+ module Q where
+ import P
+ q :: Int
+ q = p + 1
=====================================
testsuite/tests/backpack/should_compile/T27835.stderr
=====================================
@@ -0,0 +1,7 @@
+[1 of 2] Processing p
+ Instantiating p
+ [1 of 1] Compiling P ( p/P.hs, T27835.out/p/P.o )
+[2 of 2] Processing q
+ Instantiating q
+ [1 of 1] Including p
+ [1 of 1] Compiling Q ( q/Q.hs, T27835.out/q/Q.o )
=====================================
testsuite/tests/backpack/should_compile/all.T
=====================================
@@ -61,3 +61,4 @@ test('T13250', normal, backpack_compile, [''])
test('T13323', normal, backpack_compile, [''])
test('T20396', normal, backpack_compile, [''])
test('T23424', [ignore_stdout, ignore_stderr], backpack_compile, ['-ddump-rn-trace -ddump-if-trace -ddump-tc-trace'])
+test('T27835', normal, backpack_compile, ['-clear-package-db -global-package-db'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5dc8554c2797282fef4680bf0cacd…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5dc8554c2797282fef4680bf0cacd…
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/az/epa-tidy-locatedxxx-27] 3 commits: [CLC 341] Strict variants of mutable types
by Alan Zimmerman (@alanz) 05 Oct '26
by Alan Zimmerman (@alanz) 05 Oct '26
05 Oct '26
Alan Zimmerman pushed to branch wip/az/epa-tidy-locatedxxx-27 at Glasgow Haskell Compiler / GHC
Commits:
f8cfb1a5 by Hécate Kleidukos at 2026-10-04T19:36:39+02:00
[CLC 341] Strict variants of mutable types
This commit is the implementation of CLC Proposal 341
https://github.com/haskell/core-libraries-committee/issues/341
- - - - -
575c4bc6 by Rodrigo Mesquita at 2026-10-05T12:32:02-04:00
ttg: HsModuleName in the AST, ModuleName in GHC
This commit makes the AST fully independent from GHC by parsing a
"module name" as an `HsModuleName (= HText)` rather than constructing an
`ModuleName (= FastString)` straight away.
In the GHC side, everything remains as a `ModuleName`. We turn AST
`HsModuleName`s into fast strings with the cheap `mkFastStringShortText`
when we process the AST for manipulation within the compiler.
There are no performance regressions introduced by this approach.
This is the final piece of #21592
Alternative plans were discussed in
gitlab.haskell.org/ghc/ghc/-/merge_requests/16546#note_694647,
but the Simon suggested one won in simplicity and performance when
compared against my attempt at implementing my original plan of having
a family `ModuleNameP`.
- - - - -
fbf72978 by Alan Zimmerman at 2026-10-05T19:16:47+01:00
EPA: Start using vocurly as basis for AnnListLayout
For the existing cases that populate AnnList.
This uses AnnListBraces when braces are explicitly supplied, and
AnnListLayout when vocurly is used
The change also shows up AnnList usages that can never capture layout,
these are cleared up later.
- - - - -
102 changed files:
- + changelog.d/clc-341-strict-mutable-data-types
- compiler/GHC.hs
- compiler/GHC/Builtin/Modules.hs
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Show.hs
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/Opt/CallerCC/Types.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Pipeline.hs-boot
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Driver/Pipeline/Phases.hs
- compiler/GHC/Hs/Doc.hs
- compiler/GHC/Hs/Dump.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/HsToCore/Docs.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Iface/Ext/Debug.hs
- compiler/GHC/Iface/Ext/Types.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/String.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/StgToJS/Linker/Linker.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Unique.hs
- compiler/GHC/Types/UnresolvedImport.hs
- compiler/GHC/Unit/Home.hs
- compiler/GHC/Unit/Module.hs
- compiler/GHC/Unit/Module/Env.hs
- + compiler/GHC/Unit/Module/Name.hs
- compiler/GHC/Unit/Parser.hs
- compiler/GHC/Unit/Types.hs
- compiler/GHC/Unit/Types.hs-boot
- compiler/GHC/Utils/Binary.hs
- compiler/GHC/Utils/Outputable.hs
- compiler/Language/Haskell/Syntax.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/Language/Haskell/Syntax/ImpExp.hs
- compiler/Language/Haskell/Syntax/Lit.hs
- compiler/Language/Haskell/Syntax/Module/Name.hs
- compiler/Language/Haskell/Syntax/Text.hs
- compiler/ghc.cabal.in
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Info.hs
- libraries/base/base.cabal.in
- libraries/base/changelog.md
- libraries/base/src/Control/Concurrent/Chan.hs
- + libraries/base/src/Control/Concurrent/Chan/Strict.hs
- libraries/base/src/Control/Concurrent/MVar.hs
- + libraries/base/src/Control/Concurrent/MVar/Strict.hs
- libraries/base/src/Data/IORef.hs
- + libraries/base/src/Data/IORef/Strict.hs
- linters/lint-codes/LintCodes/Static.hs
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.hs
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/Test20239.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T24221.stderr
- testsuite/tests/hiefile/should_run/T24544.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T14189.stderr
- testsuite/tests/parser/should_compile/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20718b.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/parser/should_compile/T23315/T23315.stderr
- testsuite/tests/printer/AnnotationNoListTuplePuns.stdout
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/profiling/should_run/caller-cc/CallerCcParser.hs
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6d819a47f5b586195cf8e13bd5872a…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6d819a47f5b586195cf8e13bd5872a…
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/jeltsch/smaller-pit] Make `IfaceBinHandle` a type synonym family
by Wolfgang Jeltsch (@jeltsch) 05 Oct '26
by Wolfgang Jeltsch (@jeltsch) 05 Oct '26
05 Oct '26
Wolfgang Jeltsch pushed to branch wip/jeltsch/smaller-pit at Glasgow Haskell Compiler / GHC
Commits:
c767ce9a by Wolfgang Jeltsch at 2026-10-05T20:29:09+03:00
Make `IfaceBinHandle` a type synonym family
This brings the handling of `IfaceBinHandle` somewhat in line with how
other phase-dependent data is handled. Note that `mi_hi_bytes_` now
includes the `Strict.Maybe` layer itself, independently of the phase.
This is necessary, because with a type family instead of a GADT
`clear_mi_hi_bytes` cannot determine the phase at runtime anymore and
thus has to set `mi_hi_bytes_` to `Strict.Nothing` for every phase.
- - - - -
3 changed files:
- compiler/GHC/Iface/Binary.hs
- compiler/GHC/Iface/Make.hs
- compiler/GHC/Unit/Module/ModIface.hs
Changes:
=====================================
compiler/GHC/Iface/Binary.hs
=====================================
@@ -197,7 +197,7 @@ getIfaceWithExtFields name_cache bh = do
modIfaceBinData <- freezeBinHandle bh start
pure $ mod_iface
& set_mi_ext_fields extFields
- & set_mi_hi_bytes (FullIfaceBinHandle $ Strict.Just modIfaceBinData)
+ & set_mi_hi_bytes (Strict.Just modIfaceBinData)
-- | This performs a get action after reading the dictionary and symbol
-- table. It is necessary to run this before trying to deserialise any
@@ -276,10 +276,10 @@ writeBinIface profile traceBinIface compressionLevel hi_path mod_iface = do
putIfaceWithExtFields :: TraceBinIFace -> CompressionIFace -> WriteBinHandle -> ModIface -> IO ()
putIfaceWithExtFields traceBinIface compressionLevel bh mod_iface =
case mi_hi_bytes mod_iface of
- FullIfaceBinHandle Strict.Nothing -> do
+ Strict.Nothing -> do
forwardPutRel_ bh (\_ -> put_ bh (mi_ext_fields mod_iface)) $ do
putWithUserData traceBinIface compressionLevel bh mod_iface
- FullIfaceBinHandle (Strict.Just binData) -> putFullBinData bh binData
+ Strict.Just binData -> putFullBinData bh binData
-- | Put a piece of data with an initialised `UserData` field. This
-- is necessary if you want to serialise Names or FastStrings.
=====================================
compiler/GHC/Iface/Make.hs
=====================================
@@ -77,6 +77,7 @@ import GHC.Iface.Binary
import GHC.Data.FastString
import GHC.Data.Maybe
+import qualified GHC.Data.Strict as Strict
import GHC.HsToCore.Docs
import GHC.HsToCore.Usage
@@ -394,7 +395,7 @@ mkIface_ hsc_env
& set_mi_docs docs
& set_mi_abi_hashes ()
& set_mi_ext_fields emptyExtensibleFields
- & set_mi_hi_bytes PartialIfaceBinHandle
+ & set_mi_hi_bytes Strict.Nothing
where
cmp_rule = lexicalCompareFS `on` ifRuleName
=====================================
compiler/GHC/Unit/Module/ModIface.hs
=====================================
@@ -70,7 +70,7 @@ module GHC.Unit.Module.ModIface
, set_mi_hash_fn
, completePartialModIface
, shrinkModIface
- , IfaceBinHandle(..)
+ , IfaceBinHandle
, PartialModIface
, RetainedModIface
, IfaceAbiHashes (..)
@@ -160,6 +160,7 @@ import GHC.Utils.Binary
import Control.DeepSeq
import Control.Exception
+import Data.Void (Void)
{- Note [Interface file stages]
@@ -236,15 +237,10 @@ data ModIfacePhase
-- | In-memory byte array representation of a 'ModIface'.
--
-- See Note [Sharing of ModIface] for why we need this.
-data IfaceBinHandle (phase :: ModIfacePhase) where
- -- | A partial 'ModIface' cannot be serialised to disk.
- PartialIfaceBinHandle :: IfaceBinHandle 'ModIfaceCore
- -- | Optional 'FullBinData' that can be serialised to disk directly.
- --
- -- See Note [Private fields in ModIface] for when this fields needs to be cleared
- -- (e.g., set to 'Nothing').
- FullIfaceBinHandle :: !(Strict.Maybe FullBinData) -> IfaceBinHandle 'ModIfaceFinal
- RetainedIfaceBinHandle :: IfaceBinHandle 'ModIfaceRetained
+type family IfaceBinHandle (phase :: ModIfacePhase) where
+ IfaceBinHandle 'ModIfaceCore = Void
+ IfaceBinHandle 'ModIfaceFinal = FullBinData
+ IfaceBinHandle 'ModIfaceRetained = Void
type family IfaceSelfRecompData (phase :: ModIfacePhase) where
IfaceSelfRecompData 'ModIfaceCore = Maybe IfaceSelfRecomp
@@ -322,11 +318,12 @@ withSelfRecomp iface nk jk =
-- fields.
data ModIface_ (phase :: ModIfacePhase)
= PrivateModIface {
- mi_hi_bytes_ :: !(IfaceBinHandle phase),
+ mi_hi_bytes_ :: !(Strict.Maybe (IfaceBinHandle phase)),
-- ^ A serialised in-memory buffer of this 'ModIface'.
-- If this handle is given, we can avoid serialising the 'ModIface'
-- when writing this 'ModIface' to disk, and write this buffer to disk instead.
- -- See Note [Sharing of ModIface].
+ -- See Note [Sharing of ModIface] and
+ -- Note [Private fields in ModIface].
mi_iface_hash_ :: Fingerprint, -- A hash of the whole interface
mi_mod_info_ :: IfaceModInfo,
@@ -718,7 +715,7 @@ instance Binary ModIface where
-- We can't populate this field here, as we are
-- missing the 'mi_ext_fields_' field, which is
-- handled in 'getIfaceWithExtFields'.
- mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
+ mi_hi_bytes_ = Strict.Nothing
})
instance Binary IfaceModInfo where
@@ -833,7 +830,7 @@ emptyPartialModIface mod
= PrivateModIface
{ mi_mod_info_ = emptyIfaceModInfo mod,
mi_iface_hash_ = fingerprint0,
- mi_hi_bytes_ = PartialIfaceBinHandle,
+ mi_hi_bytes_ = Strict.Nothing,
mi_deps_ = noDependencies,
mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] (),
mi_simplified_core_ = Nothing,
@@ -907,7 +904,7 @@ emptyFullModIface :: Module -> ModIface
emptyFullModIface mod =
(emptyPartialModIface mod)
{ mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] emptyIfaceBackend
- , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
+ , mi_hi_bytes_ = Strict.Nothing
}
@@ -940,7 +937,7 @@ instance ( NFData (IfaceSelfRecompData phase)
, NFData (IfaceAbiHashesData phase)
) => NFData (ModIface_ phase) where
rnf (PrivateModIface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
- = (a1 :: IfaceBinHandle phase)
+ = a1
`seq` rnf a2
`seq` rnf a3
`seq` rnf a4
@@ -1051,7 +1048,7 @@ completePartialModIface :: PartialModIface
completePartialModIface partial iface_hash decls extra_decls final_exts cache = partial
{ mi_public_ = completePublicModIface decls final_exts cache (mi_public_ partial)
, mi_simplified_core_ = extra_decls
- , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
+ , mi_hi_bytes_ = Strict.Nothing
, mi_iface_hash_ = iface_hash
}
@@ -1072,7 +1069,7 @@ shrinkModIface :: ModIface -> RetainedModIface
shrinkModIface PrivateModIface {..}
= PrivateModIface
{
- mi_hi_bytes_ = RetainedIfaceBinHandle,
+ mi_hi_bytes_ = Strict.Nothing,
mi_public_ = shrinkIfacePublic mi_public_,
mi_self_recomp_ = (),
mi_simplified_core_ = (),
@@ -1100,7 +1097,7 @@ set_mi_mod_info val iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = val }
set_mi_self_recomp :: IfaceSelfRecompData phase -> ModIface_ phase -> ModIface_ phase
set_mi_self_recomp val iface = clear_mi_hi_bytes $ iface { mi_self_recomp_ = val }
-set_mi_hi_bytes :: IfaceBinHandle phase -> ModIface_ phase -> ModIface_ phase
+set_mi_hi_bytes :: Strict.Maybe (IfaceBinHandle phase) -> ModIface_ phase -> ModIface_ phase
set_mi_hi_bytes val iface = iface { mi_hi_bytes_ = val }
set_mi_deps :: Dependencies -> ModIface_ phase -> ModIface_ phase
@@ -1203,12 +1200,7 @@ set_mi_mod_info_field f iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = f (mi
-- | Invalidate any byte array buffer we might have.
clear_mi_hi_bytes :: ModIface_ phase -> ModIface_ phase
-clear_mi_hi_bytes iface = iface
- { mi_hi_bytes_ = case mi_hi_bytes iface of
- PartialIfaceBinHandle -> PartialIfaceBinHandle
- FullIfaceBinHandle _ -> FullIfaceBinHandle Strict.Nothing
- RetainedIfaceBinHandle -> RetainedIfaceBinHandle
- }
+clear_mi_hi_bytes iface = iface { mi_hi_bytes_ = Strict.Nothing }
-- ----------------------------------------------------------------------------
-- 'ModIface' pattern synonyms to keep breakage low.
@@ -1319,7 +1311,7 @@ pattern ModIface ::
-> Maybe Docs
-> IfaceAbiHashesData phase
-> ExtensibleFieldsData phase
- -> IfaceBinHandle phase
+ -> Strict.Maybe (IfaceBinHandle phase)
-> IfaceSelfRecompData phase
-> (OccName -> Maybe Fixity)
-> (OccName -> Maybe (OccName, Fingerprint))
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c767ce9a48c7401e2e5c772bf7741e5…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c767ce9a48c7401e2e5c772bf7741e5…
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/marge_bot_batch_merge_job] 3 commits: ttg: HsModuleName in the AST, ModuleName in GHC
by Marge Bot (@marge-bot) 05 Oct '26
by Marge Bot (@marge-bot) 05 Oct '26
05 Oct '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
575c4bc6 by Rodrigo Mesquita at 2026-10-05T12:32:02-04:00
ttg: HsModuleName in the AST, ModuleName in GHC
This commit makes the AST fully independent from GHC by parsing a
"module name" as an `HsModuleName (= HText)` rather than constructing an
`ModuleName (= FastString)` straight away.
In the GHC side, everything remains as a `ModuleName`. We turn AST
`HsModuleName`s into fast strings with the cheap `mkFastStringShortText`
when we process the AST for manipulation within the compiler.
There are no performance regressions introduced by this approach.
This is the final piece of #21592
Alternative plans were discussed in
gitlab.haskell.org/ghc/ghc/-/merge_requests/16546#note_694647,
but the Simon suggested one won in simplicity and performance when
compared against my attempt at implementing my original plan of having
a family `ModuleNameP`.
- - - - -
811dc21b by mangoiv at 2026-10-05T13:04:47-04:00
configure: fix sed script and subst tooldir script
Fixes #27672
Adds sanity checking for SUBST_TOOLDIR
Metric Decrease:
LinkableUsage01
MultiLayerModulesTH_OneShot
T10547
T12234
T12425
T13035
T13820
T18140
T18730
T18923
T9198
TcPlugin_RewritePerf
mhu-perf
- - - - -
c5dc8554 by Hannes Siebenhandl at 2026-10-05T13:04:48-04:00
Prepend in-memory unit database for backpack
The packageDbFlags are stored in reverse order. Thus, prepending will
ensure that the in-memory unit database is the last item on the unit
database stack.
Further, the in-memory unit database needs to be able to shadow units
from earlier unit databases in the unit database stack.
Moreover, a `-clear-package-db` would remove the in-memory database if
it weren't the last item on the stack.
Closes #27835
- - - - -
96 changed files:
- changelog.d/unit-index
- compiler/GHC.hs
- compiler/GHC/Builtin/Modules.hs
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Show.hs
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/Opt/CallerCC/Types.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Pipeline.hs-boot
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Driver/Pipeline/Phases.hs
- compiler/GHC/Hs/Doc.hs
- compiler/GHC/Hs/Dump.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/HsToCore/Docs.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Iface/Ext/Debug.hs
- compiler/GHC/Iface/Ext/Types.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/String.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/StgToJS/Linker/Linker.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Unique.hs
- compiler/GHC/Types/UnresolvedImport.hs
- compiler/GHC/Unit/Home.hs
- compiler/GHC/Unit/Module.hs
- compiler/GHC/Unit/Module/Env.hs
- + compiler/GHC/Unit/Module/Name.hs
- compiler/GHC/Unit/Parser.hs
- compiler/GHC/Unit/Types.hs
- compiler/GHC/Unit/Types.hs-boot
- compiler/GHC/Utils/Binary.hs
- compiler/GHC/Utils/Outputable.hs
- compiler/Language/Haskell/Syntax.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/Language/Haskell/Syntax/ImpExp.hs
- compiler/Language/Haskell/Syntax/Lit.hs
- compiler/Language/Haskell/Syntax/Module/Name.hs
- compiler/Language/Haskell/Syntax/Text.hs
- compiler/ghc.cabal.in
- distrib/configure.ac.in
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Info.hs
- linters/lint-codes/LintCodes/Static.hs
- m4/subst_tooldir.m4
- + testsuite/tests/backpack/should_compile/T27835.bkp
- + testsuite/tests/backpack/should_compile/T27835.stderr
- testsuite/tests/backpack/should_compile/all.T
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.hs
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/Test20239.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T24221.stderr
- testsuite/tests/hiefile/should_run/T24544.hs
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T14189.stderr
- testsuite/tests/parser/should_compile/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20718b.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/parser/should_compile/T23315/T23315.stderr
- testsuite/tests/printer/AnnotationNoListTuplePuns.stdout
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/profiling/should_run/caller-cc/CallerCcParser.hs
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d37fd8fd3d956e04280ef589b973e5…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d37fd8fd3d956e04280ef589b973e5…
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/jeltsch/smaller-pit] Statically enforce module interface reduction for the PIT
by Wolfgang Jeltsch (@jeltsch) 05 Oct '26
by Wolfgang Jeltsch (@jeltsch) 05 Oct '26
05 Oct '26
Wolfgang Jeltsch pushed to branch wip/jeltsch/smaller-pit at Glasgow Haskell Compiler / GHC
Commits:
714ac687 by Wolfgang Jeltsch at 2026-10-05T19:54:35+03:00
Statically enforce module interface reduction for the PIT
`GHC.Iface.Load.loadInterface` used to replace certain fields of each
fetched module interface by `panic` applications before storing it in
the PIT. With the present change, the absence of those fields in the PIT
is guaranteed statically.
See #27044 for the bigger picture.
- - - - -
22 changed files:
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main/Interactive.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Plugins.hs
- compiler/GHC/Driver/Session/Inspect.hs
- compiler/GHC/HsToCore/Usage.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Load.hs-boot
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Runtime/Loader.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Tc/Instance/Family.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Unit/External.hs
- compiler/GHC/Unit/Module/ModIface.hs
- ghc/Main.hs
- utils/count-deps/Main.hs
Changes:
=====================================
compiler/GHC/Driver/Downsweep.hs
=====================================
@@ -688,7 +688,8 @@ expandFixedModuleNode key loc = do
-- part of the compiler.
lookupIfaceByModuleHsc hsc_env (mnkToModule key) >>= \case
Just iface -> return (M.Succeeded iface)
- Nothing -> readIface (hsc_hooks hsc_env) (hsc_logger hsc_env) (hsc_dflags hsc_env) (hsc_NC hsc_env) (mnkToModule key) (ml_hi_file loc)
+ Nothing -> fmap shrinkModIface <$>
+ readIface (hsc_hooks hsc_env) (hsc_logger hsc_env) (hsc_dflags hsc_env) (hsc_NC hsc_env) (mnkToModule key) (ml_hi_file loc)
case read_result of
M.Succeeded iface -> do
-- Computer information about this node
=====================================
compiler/GHC/Driver/Env.hs
=====================================
@@ -372,10 +372,10 @@ lookupIfaceByModule
:: HomeUnitGraph
-> PackageIfaceTable
-> Module
- -> IO (Maybe ModIface)
+ -> IO (Maybe RetainedModIface)
lookupIfaceByModule hug pit mod
= HUG.lookupHugByModule mod hug >>= pure . \case
- Just hm -> Just (hm_iface hm)
+ Just hm -> Just (shrinkModIface (hm_iface hm))
Nothing -> lookupModuleEnv pit mod
-- If the module does come from the home package, why do we look in the PIT as well?
-- (a) In OneShot mode, even home-package modules accumulate in the PIT
@@ -384,7 +384,7 @@ lookupIfaceByModule hug pit mod
-- We could eliminate (b) if we wanted, by making GHC.Prim belong to a package
-- of its own, but it doesn't seem worth the bother.
-lookupIfaceByModuleHsc :: HscEnv -> Module -> IO (Maybe ModIface)
+lookupIfaceByModuleHsc :: HscEnv -> Module -> IO (Maybe RetainedModIface)
lookupIfaceByModuleHsc hsc_env mod = do
eps <- hscEPS hsc_env
lookupIfaceByModule (hsc_HUG hsc_env) (eps_PIT eps) mod
=====================================
compiler/GHC/Driver/Main/Interactive.hs
=====================================
@@ -148,7 +148,7 @@ hscIsGHCiMonad :: HscEnv -> String -> IO Name
hscIsGHCiMonad hsc_env name
= runHsc hsc_env $ ioMsgMaybe $ hoistTcRnMessage $ isGHCiMonad hsc_env name
-hscGetModuleInterface :: HscEnv -> Module -> IO ModIface
+hscGetModuleInterface :: HscEnv -> Module -> IO RetainedModIface
hscGetModuleInterface hsc_env0 mod = runInteractiveHsc hsc_env0 $ do
hsc_env <- getHscEnv
ioMsgMaybe $ hoistTcRnMessage $ getModuleInterface hsc_env mod
@@ -270,7 +270,7 @@ hscCheckSafe' m l = do
_ | isHomeModule home_unit mod -> True
_ -> isUnitTrusted unit_state (moduleUnit m)
- lookup' :: Module -> Hsc (Maybe ModIface)
+ lookup' :: Module -> Hsc (Maybe RetainedModIface)
lookup' m = do
hsc_env <- getHscEnv
iface <- liftIO $ lookupIfaceByModuleHsc hsc_env m
=====================================
compiler/GHC/Driver/Main/Passes.hs
=====================================
@@ -1335,7 +1335,7 @@ hscCheckSafe' m l = do
_ | isHomeModule home_unit mod -> True
_ -> isUnitTrusted unit_state (moduleUnit m)
- lookup' :: Module -> Hsc (Maybe ModIface)
+ lookup' :: Module -> Hsc (Maybe RetainedModIface)
lookup' m = do
hsc_env <- getHscEnv
iface <- liftIO $ lookupIfaceByModuleHsc hsc_env m
=====================================
compiler/GHC/Driver/Plugins.hs
=====================================
@@ -224,7 +224,7 @@ data PluginWithArgs = PluginWithArgs
data LoadedPlugin = LoadedPlugin
{ lpPlugin :: PluginWithArgs
-- ^ the actual plugin together with its commandline arguments
- , lpModule :: ModIface
+ , lpModule :: RetainedModIface
-- ^ the module containing the plugin
}
=====================================
compiler/GHC/Driver/Session/Inspect.hs
=====================================
@@ -87,7 +87,7 @@ data ModuleInfo = ModuleInfo {
minf_type_env :: TypeEnv,
minf_exports :: [AvailInfo],
minf_instances :: [ClsInst],
- minf_iface :: Maybe ModIface,
+ minf_iface :: Maybe RetainedModIface,
minf_safe :: SafeHaskellMode,
minf_modBreaks :: Maybe InternalModBreaks
}
@@ -140,7 +140,7 @@ getHomeModuleInfo hsc_env mdl =
Nothing -> return Nothing
Just hmi -> do
let details = hm_details hmi
- iface = hm_iface hmi
+ iface = shrinkModIface (hm_iface hmi)
return (Just (ModuleInfo {
minf_type_env = md_types details,
minf_exports = md_exports details,
@@ -187,7 +187,7 @@ modInfoLookupName minf name = withSession $ \hsc_env -> do
Just tyThing -> return (Just tyThing)
Nothing -> liftIO (lookupType hsc_env name)
-modInfoIface :: ModuleInfo -> Maybe ModIface
+modInfoIface :: ModuleInfo -> Maybe RetainedModIface
modInfoIface = minf_iface
-- | Retrieve module safe haskell mode
=====================================
compiler/GHC/HsToCore/Usage.hs
=====================================
@@ -276,7 +276,7 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
-- a) we used something from it; has something in used_names
-- b) we imported it, even if we used nothing from it
-- (need to recompile if its export list changes: export_fprint)
- mkUsage :: Module -> ModIface -> Maybe Usage
+ mkUsage :: Module -> RetainedModIface -> Maybe Usage
mkUsage mod iface
| toUnitId (moduleUnit mod) `Set.notMember` home_unit_ids
= Just $ UsagePackageModule{ usg_mod = mod,
@@ -302,9 +302,9 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
usg_entities = Map.toList ent_hashs,
usg_safe = imp_safe }
where
- finsts_mod = mi_finsts iface
+ finsts_mod = mi_abi_finsts (mi_abi_hashes iface)
hash_env = mi_hash_fn iface
- mod_hash = mi_mod_hash iface
+ mod_hash = mi_abi_mod_hash (mi_abi_hashes iface)
imported_exports
= if not depend_on_exports
then Nothing
@@ -312,9 +312,9 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
Just $
HomeModImport
{ hmiu_orphanLikeHash
- = mi_orphan_like_hash iface
+ = mi_abi_orphan_like_hash (mi_abi_hashes iface)
, hmiu_importedAvails
- = moduleImportedAvails mod (mi_export_avails_hash iface) imp_decls
+ = moduleImportedAvails mod (mi_abi_export_avails_hash (mi_abi_hashes iface)) imp_decls
}
by_is_safe (ImportedByUser imv) = imv_is_safe imv
=====================================
compiler/GHC/Iface/Load.hs
=====================================
@@ -308,7 +308,7 @@ loadKnownKeyOccMaps
known_key_maps :: Module -> IfM lcl KnownKeyNameMaps
known_key_maps mod
= do { iface <- loadInterfaceWithException doc mod ImportBySystem
- ; let !abi_hash = mi_mod_hash iface
+ ; let !abi_hash = mi_abi_mod_hash (mi_abi_hashes iface)
; eps <- getEps
; case lookupModuleEnv (eps_known_keys eps) mod of
Just (cached_hash, kk_maps)
@@ -321,7 +321,7 @@ loadKnownKeyOccMaps
(abi_hash, kk_maps) }
; return kk_maps } }
- build_maps :: ModIface -> KnownKeyNameMaps
+ build_maps :: RetainedModIface -> KnownKeyNameMaps
build_maps iface = (kk_map, occ_map)
where
kk_map :: UniqFM KnownKey Name
@@ -628,7 +628,7 @@ loadSrcInterface :: SDoc
-> ModuleName
-> IsBootInterface -- {-# SOURCE #-} ?
-> PkgQual -- "package", if any
- -> RnM ModIface
+ -> RnM RetainedModIface
loadSrcInterface doc scope mod want_boot maybe_pkg
= do { res <- loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
@@ -648,7 +648,7 @@ loadSrcInterface_maybe :: SDoc
-> ModuleName
-> IsBootInterface -- {-# SOURCE #-} ?
-> PkgQual -- "package", if any
- -> RnM (MaybeErr MissingInterfaceError ModIface)
+ -> RnM (MaybeErr MissingInterfaceError RetainedModIface)
loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
-- We must first find which Module this import refers to. This involves
@@ -667,7 +667,7 @@ loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
-- rare operation, but in particular it is used to load orphan modules
-- in order to pull their instances into the global package table and to
-- handle some operations in GHCi).
-loadModuleInterface :: SDoc -> Module -> TcM ModIface
+loadModuleInterface :: SDoc -> Module -> TcM RetainedModIface
loadModuleInterface doc mod = initIfaceTcRn (loadSysInterface doc mod)
-- | Load interfaces for a collection of modules.
@@ -681,7 +681,7 @@ loadModuleInterfaces doc mods
-- | Loads the interface for a given Name.
-- Should only be called for an imported name;
-- otherwise loadSysInterface may not find the interface
-loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
+loadInterfaceForName :: SDoc -> Name -> TcRn RetainedModIface
loadInterfaceForName doc name
= do { when debugIsOn $ -- Check pre-condition
do { this_mod <- getModule
@@ -690,7 +690,7 @@ loadInterfaceForName doc name
initIfaceTcRn $ loadSysInterface doc (nameModule name) }
-- | Loads the interface for a given Module.
-loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface
+loadInterfaceForModule :: SDoc -> Module -> TcRn RetainedModIface
loadInterfaceForModule doc m
= do
-- Should not be called with this module
@@ -724,23 +724,23 @@ loadWiredInHomeIface name
------------------
-- | Loads a system interface and throws an exception if it fails
-loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
+loadSysInterface :: SDoc -> Module -> IfM lcl RetainedModIface
loadSysInterface doc mod_name = loadInterfaceWithException doc mod_name ImportBySystem
------------------
-- | Loads a user interface and throws an exception if it fails. The first parameter indicates
-- whether we should import the boot variant of the module
-loadUserInterface :: IsBootInterface -> SDoc -> Module -> IfM lcl ModIface
+loadUserInterface :: IsBootInterface -> SDoc -> Module -> IfM lcl RetainedModIface
loadUserInterface is_boot doc mod_name
= loadInterfaceWithException doc mod_name (ImportByUser is_boot)
-loadPluginInterface :: SDoc -> Module -> IfM lcl ModIface
+loadPluginInterface :: SDoc -> Module -> IfM lcl RetainedModIface
loadPluginInterface doc mod_name
= loadInterfaceWithException doc mod_name ImportByPlugin
------------------
-- | A wrapper for 'loadInterface' that throws an exception if it fails
-loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl ModIface
+loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl RetainedModIface
loadInterfaceWithException doc mod_name where_from
= do
dflags <- getDynFlags
@@ -749,7 +749,7 @@ loadInterfaceWithException doc mod_name where_from
------------------
loadInterface :: SDoc -> Module -> WhereFrom
- -> IfM lcl (MaybeErr MissingInterfaceError ModIface)
+ -> IfM lcl (MaybeErr MissingInterfaceError RetainedModIface)
-- loadInterface looks in both the HPT and PIT for the required interface
-- If not found, it loads it, and puts it in the PIT (always).
@@ -796,7 +796,7 @@ loadInterface doc_str mod from
liftIO $ computeInterface hsc_env doc_str hi_boot_file mod
; case read_result of {
Failed err -> do
- { let fake_iface = emptyFullModIface mod
+ { let fake_iface = shrinkModIface (emptyFullModIface mod)
; updateEps_ $ \eps ->
eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
@@ -856,16 +856,7 @@ loadInterface doc_str mod from
; new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
; purged_hsc_env <- getTopEnv
- ; let final_iface = iface
- & set_mi_decls (panic "No mi_decls in PIT")
- & set_mi_insts (panic "No mi_insts in PIT")
- & set_mi_defaults (panic "No mi_defaults in PIT")
- & set_mi_fam_insts (panic "No mi_fam_insts in PIT")
- & set_mi_rules (panic "No mi_rules in PIT")
- & set_mi_anns (panic "No mi_anns in PIT")
- & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
-
- bad_boot = mi_boot iface == IsBoot
+ ; let bad_boot = mi_boot iface == IsBoot
&& isJust (lookupKnotVars (if_rec_types gbl_env) mod)
-- Warn against an EPS-updating import
-- of one's own boot file! (one-shot only)
@@ -892,7 +883,7 @@ loadInterface doc_str mod from
then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
else
eps {
- eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
+ eps_PIT = extendModuleEnv (eps_PIT eps) mod (shrinkModIface iface),
eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
eps_rule_base = extendRuleBaseList (eps_rule_base eps)
@@ -921,10 +912,8 @@ loadInterface doc_str mod from
eps_defaults = extendModuleEnv (eps_defaults eps) mod new_eps_defaults
}
- ; -- invoke plugins with *full* interface, not final_iface, to ensure
- -- that plugins have access to declarations, etc.
- res <- withPlugins (hsc_plugins hsc_env) (\p -> interfaceLoadAction p) iface
- ; return (Succeeded res)
+ ; res <- withPlugins (hsc_plugins hsc_env) (\p -> interfaceLoadAction p) iface
+ ; return (Succeeded (shrinkModIface res))
}}}}
{- Note [Loading your own hi-boot file]
=====================================
compiler/GHC/Iface/Load.hs-boot
=====================================
@@ -2,7 +2,7 @@ module GHC.Iface.Load where
import GHC.Unit.Module (Module)
import GHC.Tc.Utils.Monad (IfM)
-import GHC.Unit.Module.ModIface (ModIface)
+import GHC.Unit.Module.ModIface (RetainedModIface)
import GHC.Utils.Outputable (SDoc)
-loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
+loadSysInterface :: SDoc -> Module -> IfM lcl RetainedModIface
=====================================
compiler/GHC/Iface/Recomp.hs
=====================================
@@ -707,7 +707,7 @@ checkDependencies hsc_env summary iface
return $ needsRecompileBecause $ ModulePackageChanged new_name
-needInterface :: Module -> (ModIface -> IO RecompileRequired)
+needInterface :: Module -> (RetainedModIface -> IO RecompileRequired)
-> IfG RecompileRequired
needInterface mod continue
= do
@@ -727,7 +727,7 @@ needBytecode mod continue
Nothing -> return $ NeedsRecompile MustCompile
Just mbc -> liftIO $ continue mbc
-tryGetModIface :: String -> Module -> IfG (Maybe ModIface)
+tryGetModIface :: String -> Module -> IfG (Maybe RetainedModIface)
tryGetModIface doc_msg mod
= do -- Load the imported interface if possible
logger <- getLogger
@@ -779,7 +779,7 @@ checkModUsage _ UsagePackageModule{
logger <- getLogger
needInterface mod $ \iface -> do
let reason = ModuleChanged (moduleName mod)
- checkModuleFingerprint logger reason old_mod_hash (mi_mod_hash iface)
+ checkModuleFingerprint logger reason old_mod_hash (mi_abi_mod_hash (mi_abi_hashes iface))
-- We only track the ABI hash of package modules, rather than
-- individual entity usages, so if the ABI hash changes we must
-- recompile. This is safe but may entail more recompilation when
@@ -789,7 +789,7 @@ checkModUsage _ UsageMergedRequirement{ usg_mod = mod, usg_mod_hash = old_mod_ha
logger <- getLogger
needInterface mod $ \iface -> do
let reason = ModuleChangedRaw (moduleName mod)
- checkModuleFingerprint logger reason old_mod_hash (mi_mod_hash iface)
+ checkModuleFingerprint logger reason old_mod_hash (mi_abi_mod_hash (mi_abi_hashes iface))
checkModUsage _ UsageHomeModuleBytecode{ usg_mod_name = mod_name
, usg_unit_id = uid
, usg_bytecode_hash = old_bytecode_hash } = do
@@ -810,7 +810,7 @@ checkModUsage _ UsageHomeModule{
logger <- getLogger
needInterface mod $ \iface -> do
let
- new_mod_hash = mi_mod_hash iface
+ new_mod_hash = mi_abi_mod_hash (mi_abi_hashes iface)
new_decl_hash = mi_hash_fn iface
reason = ModuleChanged (moduleName mod)
@@ -864,7 +864,7 @@ checkModUsage fc UsageDirectory{ usg_dir_path = dir,
-- Does this require recompilation?
--
-- See Note [When to recompile when export lists change?]
-checkHomeModImport :: Logger -> RecompReason -> Maybe HomeModImport -> ModIface -> IO RecompileRequired
+checkHomeModImport :: Logger -> RecompReason -> Maybe HomeModImport -> RetainedModIface -> IO RecompileRequired
checkHomeModImport _ _ Nothing _ = return UpToDate
checkHomeModImport logger reason
(Just (HomeModImport old_orphan_like_hash old_avails))
@@ -901,8 +901,8 @@ checkHomeModImport logger reason
2 (ppr changes)
return $ needsRecompileBecause reason
where
- new_orphan_like_hash = mi_orphan_like_hash iface
- new_avails_hash = mi_export_avails_hash iface
+ new_orphan_like_hash = mi_abi_orphan_like_hash (mi_abi_hashes iface)
+ new_avails_hash = mi_abi_export_avails_hash (mi_abi_hashes iface)
new_exports = mi_exports iface
-- | The exported avails of a module have changed. Should this cause recompilation
@@ -1617,7 +1617,7 @@ getOrphanHashes hsc_env mods = do
get_orph_hash mod = do
iface <- initIfaceLoad hsc_env . withIfaceErr ctx
$ loadInterface (text "getOrphanHashes") mod ImportBySystem
- return (mi_orphan_hash iface)
+ return (mi_abi_orphan_hash (mi_abi_hashes iface))
mapM get_orph_hash mods
=====================================
compiler/GHC/Rename/Names.hs
=====================================
@@ -517,7 +517,7 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
-- interface, but without 'imp_mods'.
calculateAvails :: HomeUnit
-> S.Set UnitId
- -> ModIface
+ -> RetainedModIface
-> IsSafeImport
-> IsBootInterface
-> ImportedBy
@@ -525,8 +525,8 @@ calculateAvails :: HomeUnit
calculateAvails home_unit other_home_units iface mod_safe' want_boot imported_by =
let imp_mod = mi_module iface
imp_sem_mod= mi_semantic_module iface
- orph_iface = mi_orphan iface
- has_finsts = mi_finsts iface
+ orph_iface = mi_abi_orphan (mi_abi_hashes iface)
+ has_finsts = mi_abi_finsts (mi_abi_hashes iface)
deps = mi_deps iface
trust = getSafeMode $ mi_trust iface
trust_pkg = mi_trust_pkg iface
@@ -1209,7 +1209,7 @@ gresFromAvail hsc_env prov avail =
gresFromAvails :: HscEnv -> Maybe ImportSpec -> [AvailInfo] -> [GlobalRdrElt]
gresFromAvails hsc_env prov = concatMap (gresFromAvail hsc_env prov)
-importsFromIface :: HscEnv -> ModIface -> ImpDeclSpec -> Maybe NameSet -> GlobalRdrEnv
+importsFromIface :: HscEnv -> RetainedModIface -> ImpDeclSpec -> Maybe NameSet -> GlobalRdrEnv
importsFromIface hsc_env iface decl_spec hidden = mkGlobalRdrEnv $ case hidden of
Nothing -> all_gres
Just hidden_names -> filter (not . (`elemNameSet` hidden_names) . greName) all_gres
@@ -1225,7 +1225,7 @@ rnNamespaceSpecifier (DataNamespaceSpecifier x) = DataNamespaceSpecifier x
filterImports
:: HasDebugCallStack
=> HscEnv
- -> ModIface
+ -> RetainedModIface
-> ImpDeclSpec
-- ^ Import spec
-> Maybe (ImportListInterpretation, [LIE GhcPs])
@@ -2327,7 +2327,7 @@ getMinimalImports ie_decls
where
doc = text "Compute minimal imports for" <+> ppr decl
- to_ie :: GlobalRdrEnv -> ModIface -> AvailInfo -> RnM [IE GhcRn]
+ to_ie :: GlobalRdrEnv -> RetainedModIface -> AvailInfo -> RnM [IE GhcRn]
-- The main trick here is that if we're importing all the constructors
-- we want to say "T(..)", but if we're importing only a subset we want
-- to say "T(A,B,C)". So we have to find out what the module exports.
@@ -2529,7 +2529,7 @@ DRFPatSynExport for a test of this.
-}
badImportItemErr
- :: ModIface -> ImpDeclSpec -> IE GhcPs
+ :: RetainedModIface -> ImpDeclSpec -> IE GhcPs
-> IsSubordinateError
-> [AvailInfo]
-> TcRn (NonEmpty ImportLookupReason)
=====================================
compiler/GHC/Rename/Utils.hs
=====================================
@@ -534,7 +534,7 @@ warnIfDeclDeprecated gre@(GRE { gre_imp = iss })
definedMod = moduleName $ assertPpr (isExternalName name) (ppr name) (nameModule name)
doc = text "The name" <+> quotes (ppr occ) <+> text "is mentioned explicitly"
-lookupImpDeclDeprec :: ModIface -> GlobalRdrElt -> Maybe (WarningTxt GhcRn)
+lookupImpDeclDeprec :: RetainedModIface -> GlobalRdrElt -> Maybe (WarningTxt GhcRn)
lookupImpDeclDeprec iface gre
-- Bleat if the thing, or its parent, is warn'd
= mi_decl_warn_fn iface (greOccName gre) `mplus`
=====================================
compiler/GHC/Runtime/Loader.hs
=====================================
@@ -190,7 +190,7 @@ checkExternalInterpreter hsc_env = case interpInstance <$> hsc_interp hsc_env of
-> throwIO (InstallationError "Plugins require -fno-external-interpreter")
_ -> pure ()
-loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, ModIface, [LinkableUsage], PkgsLoaded)
+loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, RetainedModIface, [LinkableUsage], PkgsLoaded)
loadPlugin' occ_name plugin_name hsc_env mod_name
= do { let plugin_rdr_name = mkRdrQual mod_name occ_name
dflags = hsc_dflags hsc_env
@@ -341,7 +341,7 @@ lessUnsafeCoerce logger context what = do
-- Need the module as well to record information in the interface file
lookupRdrNameInModuleForPlugins :: HasDebugCallStack
=> HscEnv -> ModuleName -> RdrName
- -> IO (Maybe (Name, ModIface))
+ -> IO (Maybe (Name, RetainedModIface))
lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do
let dflags = hsc_dflags hsc_env
-- First find the unit the module resides in by searching exposed units and home modules
=====================================
compiler/GHC/Tc/Errors/Ppr.hs
=====================================
@@ -6386,7 +6386,7 @@ pprImportLookup :: ImportLookupReason -> SDoc
pprImportLookup = \case
ImportLookupBad k iface decl_spec ie _exts ->
let
- pprImpDeclSpec :: ModIface -> ImpDeclSpec -> SDoc
+ pprImpDeclSpec :: RetainedModIface -> ImpDeclSpec -> SDoc
pprImpDeclSpec iface decl_spec =
quotes (ppr (moduleName $ is_mod decl_spec)) <+> case mi_boot iface of
IsBoot -> text "(hi-boot interface)"
=====================================
compiler/GHC/Tc/Errors/Types.hs
=====================================
@@ -215,7 +215,7 @@ import GHC.Types.DefaultEnv (ClassDefaults)
import GHC.Unit.Types (Module)
import GHC.Unit.State (UnitState)
-import GHC.Unit.Module.ModIface (ModIface)
+import GHC.Unit.Module.ModIface (RetainedModIface)
import GHC.Utils.Outputable
@@ -6635,7 +6635,7 @@ data ImportLookupReason where
T9006, T11071, T9905fail2, T5385, T10668
-}
ImportLookupBad :: BadImportKind
- -> ModIface
+ -> RetainedModIface
-> ImpDeclSpec
-> IE GhcPs
-> ImportLookupExtensions
=====================================
compiler/GHC/Tc/Gen/Splice.hs
=====================================
@@ -1693,7 +1693,7 @@ lookupArgDoc i nm = do
_ -> pure Nothing
-- | Returns the module a Name belongs to, if it is isn't local.
-getExternalModIface :: Name -> TcM (Maybe ModIface)
+getExternalModIface :: Name -> TcM (Maybe RetainedModIface)
getExternalModIface nm = do
isLocal <- nameIsLocalOrFrom <$> getModule <*> pure nm
if isLocal
=====================================
compiler/GHC/Tc/Instance/Family.hs
=====================================
@@ -308,7 +308,7 @@ checkFamInstConsistency directlyImpMods
ifc <- modIface mod
deps <- dep_finsts . mi_deps <$> modIface mod
pure $
- if mi_finsts ifc
+ if mi_abi_finsts (mi_abi_hashes ifc)
then mod:deps
else deps
=====================================
compiler/GHC/Tc/Module.hs
=====================================
@@ -2964,7 +2964,7 @@ externaliseAndTidyId this_mod id
-- a package module with an interface on disk. If neither of these is
-- true, then the result will be an error indicating the interface
-- could not be found.
-getModuleInterface :: HscEnv -> Module -> IO (Messages TcRnMessage, Maybe ModIface)
+getModuleInterface :: HscEnv -> Module -> IO (Messages TcRnMessage, Maybe RetainedModIface)
getModuleInterface hsc_env mod
= runTcInteractive NoTcMPlugins hsc_env $
loadModuleInterface (text "getModuleInterface") mod
=====================================
compiler/GHC/Unit/External.hs
=====================================
@@ -49,7 +49,7 @@ type PackageAnnEnv = AnnEnv
type PackageCompleteMatches = CompleteMatches
-- | Helps us find information about modules in the imported packages
-type PackageIfaceTable = ModuleEnv ModIface
+type PackageIfaceTable = ModuleEnv RetainedModIface
-- Domain = modules in the imported packages
-- | Constructs an empty PackageIfaceTable
=====================================
compiler/GHC/Unit/Module/ModIface.hs
=====================================
@@ -2,6 +2,7 @@
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE RecordWildCards #-}
module GHC.Unit.Module.ModIface
( ModIface
@@ -68,19 +69,31 @@ module GHC.Unit.Module.ModIface
, set_mi_fix_fn
, set_mi_hash_fn
, completePartialModIface
+ , shrinkModIface
, IfaceBinHandle(..)
, PartialModIface
+ , RetainedModIface
, IfaceAbiHashes (..)
, IfaceSelfRecomp (..)
, IfaceCache (..)
, IfaceSimplifiedCore (..)
, withSelfRecomp
- , IfaceDeclExts
- , IfaceAbiHashesExts
+ , IfaceSelfRecompData
+ , IfaceSimplifiedCoreData
+ , ExtensibleFieldsData
+ , IfaceAnnotationsData
+ , IfaceDeclsData
+ , IfaceDefaultsData
+ , IfaceClsInstsData
+ , IfaceFamInstsData
+ , IfaceRulesData
+ , IfaceCompleteMatchesData
+ , IfaceAbiHashesData
, IfaceExport
, IfacePublic_(..)
, IfacePublic
, PartialIfacePublic
+ , RetainedIfacePublic
, IfaceModInfo(..)
, WhetherHasOrphans
, WhetherHasFamInst
@@ -167,9 +180,11 @@ We can build a full interface file two ways:
type PartialModIface = ModIface_ 'ModIfaceCore
type ModIface = ModIface_ 'ModIfaceFinal
+type RetainedModIface = ModIface_ 'ModIfaceRetained
type PartialIfacePublic = IfacePublic_ 'ModIfaceCore
type IfacePublic = IfacePublic_ 'ModIfaceFinal
+type RetainedIfacePublic = IfacePublic_ 'ModIfaceRetained
-- | Extends a PartialModIface with hashes of the ABI.
--
@@ -212,19 +227,11 @@ data IfaceCache = IfaceCache
data ModIfacePhase
= ModIfaceCore
- -- ^ Partial interface built based on output of core pipeline.
+ -- ^ Partial interface built from the output of the core pipeline
| ModIfaceFinal
-
--- | Selects a IfaceDecl representation.
--- For fully instantiated interfaces we also maintain
--- a fingerprint, which is used for recompilation checks.
-type family IfaceDeclExts (phase :: ModIfacePhase) = decl | decl -> phase where
- IfaceDeclExts 'ModIfaceCore = IfaceDecl
- IfaceDeclExts 'ModIfaceFinal = (Fingerprint, IfaceDecl)
-
-type family IfaceAbiHashesExts (phase :: ModIfacePhase) = bk | bk -> phase where
- IfaceAbiHashesExts 'ModIfaceCore = ()
- IfaceAbiHashesExts 'ModIfaceFinal = IfaceAbiHashes
+ -- ^ Complete interface
+ | ModIfaceRetained
+ -- ^ Interface shrunk to the parts that may be retained
-- | In-memory byte array representation of a 'ModIface'.
--
@@ -237,9 +244,66 @@ data IfaceBinHandle (phase :: ModIfacePhase) where
-- See Note [Private fields in ModIface] for when this fields needs to be cleared
-- (e.g., set to 'Nothing').
FullIfaceBinHandle :: !(Strict.Maybe FullBinData) -> IfaceBinHandle 'ModIfaceFinal
-
-
-withSelfRecomp :: ModIface_ phase -> r -> (IfaceSelfRecomp -> r) -> r
+ RetainedIfaceBinHandle :: IfaceBinHandle 'ModIfaceRetained
+
+type family IfaceSelfRecompData (phase :: ModIfacePhase) where
+ IfaceSelfRecompData 'ModIfaceCore = Maybe IfaceSelfRecomp
+ IfaceSelfRecompData 'ModIfaceFinal = Maybe IfaceSelfRecomp
+ IfaceSelfRecompData 'ModIfaceRetained = ()
+
+type family IfaceSimplifiedCoreData (phase :: ModIfacePhase) where
+ IfaceSimplifiedCoreData 'ModIfaceCore = Maybe IfaceSimplifiedCore
+ IfaceSimplifiedCoreData 'ModIfaceFinal = Maybe IfaceSimplifiedCore
+ IfaceSimplifiedCoreData 'ModIfaceRetained = ()
+
+type family ExtensibleFieldsData (phase :: ModIfacePhase) where
+ ExtensibleFieldsData 'ModIfaceCore = ExtensibleFields
+ ExtensibleFieldsData 'ModIfaceFinal = ExtensibleFields
+ ExtensibleFieldsData 'ModIfaceRetained = ()
+
+type family IfaceAnnotationsData (phase :: ModIfacePhase) where
+ IfaceAnnotationsData 'ModIfaceCore = [IfaceAnnotation]
+ IfaceAnnotationsData 'ModIfaceFinal = [IfaceAnnotation]
+ IfaceAnnotationsData 'ModIfaceRetained = ()
+
+-- | The fingerprint in the 'ModIfaceFinal' case is used for recompilation
+-- checks.
+type family IfaceDeclsData (phase :: ModIfacePhase) where
+ IfaceDeclsData 'ModIfaceCore = [IfaceDecl]
+ IfaceDeclsData 'ModIfaceFinal = [(Fingerprint, IfaceDecl)]
+ IfaceDeclsData 'ModIfaceRetained = ()
+
+type family IfaceDefaultsData (phase :: ModIfacePhase) where
+ IfaceDefaultsData 'ModIfaceCore = [IfaceDefault]
+ IfaceDefaultsData 'ModIfaceFinal = [IfaceDefault]
+ IfaceDefaultsData 'ModIfaceRetained = ()
+
+type family IfaceClsInstsData (phase :: ModIfacePhase) where
+ IfaceClsInstsData 'ModIfaceCore = [IfaceClsInst]
+ IfaceClsInstsData 'ModIfaceFinal = [IfaceClsInst]
+ IfaceClsInstsData 'ModIfaceRetained = ()
+
+type family IfaceFamInstsData (phase :: ModIfacePhase) where
+ IfaceFamInstsData 'ModIfaceCore = [IfaceFamInst]
+ IfaceFamInstsData 'ModIfaceFinal = [IfaceFamInst]
+ IfaceFamInstsData 'ModIfaceRetained = ()
+
+type family IfaceRulesData (phase :: ModIfacePhase) where
+ IfaceRulesData 'ModIfaceCore = [IfaceRule]
+ IfaceRulesData 'ModIfaceFinal = [IfaceRule]
+ IfaceRulesData 'ModIfaceRetained = ()
+
+type family IfaceCompleteMatchesData (phase :: ModIfacePhase) where
+ IfaceCompleteMatchesData 'ModIfaceCore = [IfaceCompleteMatch]
+ IfaceCompleteMatchesData 'ModIfaceFinal = [IfaceCompleteMatch]
+ IfaceCompleteMatchesData 'ModIfaceRetained = ()
+
+type family IfaceAbiHashesData (phase :: ModIfacePhase) where
+ IfaceAbiHashesData 'ModIfaceCore = ()
+ IfaceAbiHashesData 'ModIfaceFinal = IfaceAbiHashes
+ IfaceAbiHashesData 'ModIfaceRetained = IfaceAbiHashes
+
+withSelfRecomp :: ModIface -> r -> (IfaceSelfRecomp -> r) -> r
withSelfRecomp iface nk jk =
case mi_self_recomp_info iface of
Nothing -> nk
@@ -279,11 +343,11 @@ data ModIface_ (phase :: ModIfacePhase)
-- importing this module. The main, original part of an interface.
- mi_self_recomp_ :: Maybe IfaceSelfRecomp,
+ mi_self_recomp_ :: IfaceSelfRecompData phase,
-- ^ Information needed for checking self-recompilation.
-- See Note [Self recompilation information in interface files]
- mi_simplified_core_ :: Maybe IfaceSimplifiedCore,
+ mi_simplified_core_ :: IfaceSimplifiedCoreData phase,
-- ^ The part of the interface written when `-fwrite-if-simplified-core` is enabled.
-- These parts are used to restart bytecode generation.
@@ -301,7 +365,7 @@ data ModIface_ (phase :: ModIfacePhase)
-- defined by the user). Used for GHCi and for inspecting
-- the contents of modules via the GHC API only.
- mi_ext_fields_ :: ExtensibleFields
+ mi_ext_fields_ :: ExtensibleFieldsData phase
-- ^ Additional optional fields, where the Map key represents
-- the field name, resulting in a (size, serialized data) pair.
-- Because the data is intended to be serialized through the
@@ -334,12 +398,12 @@ data IfacePublic_ phase = IfacePublic {
-- ^ Warnings
-- NOT STRICT! we read this field lazily from the interface file
- mi_anns_ :: [IfaceAnnotation],
+ mi_anns_ :: IfaceAnnotationsData phase,
-- ^ Annotations
-- NOT STRICT! we read this field lazily from the interface file
- mi_decls_ :: [IfaceDeclExts phase],
+ mi_decls_ :: IfaceDeclsData phase,
-- ^ Type, class and variable declarations
-- The hash of an Id changes if its fixity or deprecations change
-- (as well as its type of course)
@@ -347,14 +411,14 @@ data IfacePublic_ phase = IfacePublic {
-- the hash of the parent class/tycon changes
- mi_defaults_ :: [IfaceDefault],
+ mi_defaults_ :: IfaceDefaultsData phase,
-- ^ default declarations exported by the module
-- Instance declarations and rules
- mi_insts_ :: [IfaceClsInst], -- ^ Sorted class instance
- mi_fam_insts_ :: [IfaceFamInst], -- ^ Sorted family instances
- mi_rules_ :: [IfaceRule], -- ^ Sorted rules
+ mi_insts_ :: IfaceClsInstsData phase, -- ^ Sorted class instance
+ mi_fam_insts_ :: IfaceFamInstsData phase, -- ^ Sorted family instances
+ mi_rules_ :: IfaceRulesData phase, -- ^ Sorted rules
mi_trust_ :: IfaceTrustInfo,
@@ -367,20 +431,20 @@ data IfacePublic_ phase = IfacePublic {
-- itself) but imports some trustworthy modules from its own
-- package (which does require its own package be trusted).
-- See Note [Trust Own Package] in GHC.Rename.Names
- mi_complete_matches_ :: [IfaceCompleteMatch],
+ mi_complete_matches_ :: IfaceCompleteMatchesData phase,
-- ^ {-# COMPLETE #-} declarations
mi_caches_ :: IfaceCache,
-- ^ Cached lookups of some parts of mi_public
- mi_abi_hashes_ :: (IfaceAbiHashesExts phase)
+ mi_abi_hashes_ :: IfaceAbiHashesData phase
-- ^ Either `()` or `IfaceAbiHashes` for
-- a fully instantiated interface.
-- These fields are hashes of different parts of the public interface.
}
mkIfacePublic :: [IfaceExport]
- -> [IfaceDeclExts 'ModIfaceFinal]
+ -> [(Fingerprint, IfaceDecl)]
-> [(OccName, Fixity)]
-> IfaceWarnings
-> [IfaceAnnotation]
@@ -501,22 +565,22 @@ That's why in GHC.Driver.Main.hscMaybeWriteIface there is the call to
forceModIface.
-}
-mi_flag_hash :: ModIface_ phase -> Maybe (FingerprintWithValue IfaceDynFlags)
+mi_flag_hash :: ModIface -> Maybe (FingerprintWithValue IfaceDynFlags)
mi_flag_hash = fmap mi_sr_flag_hash . mi_self_recomp_
-mi_opt_hash :: ModIface_ phase -> Maybe Fingerprint
+mi_opt_hash :: ModIface -> Maybe Fingerprint
mi_opt_hash = fmap mi_sr_opt_hash . mi_self_recomp_
-mi_hpc_hash :: ModIface_ phase -> Maybe Fingerprint
+mi_hpc_hash :: ModIface -> Maybe Fingerprint
mi_hpc_hash = fmap mi_sr_hpc_hash . mi_self_recomp_
-mi_src_hash :: ModIface_ phase -> Maybe Fingerprint
+mi_src_hash :: ModIface -> Maybe Fingerprint
mi_src_hash = fmap mi_sr_src_hash . mi_self_recomp_
-mi_usages :: ModIface_ phase -> Maybe [Usage]
+mi_usages :: ModIface -> Maybe [Usage]
mi_usages = fmap mi_sr_usages . mi_self_recomp_
-mi_plugin_hash :: ModIface_ phase -> Maybe Fingerprint
+mi_plugin_hash :: ModIface -> Maybe Fingerprint
mi_plugin_hash = fmap mi_sr_plugin_hash . mi_self_recomp_
-- | Accessor for the module hash of the ABI from a ModIface.
@@ -547,7 +611,7 @@ mi_orphan_hash iface = mi_abi_orphan_hash (mi_abi_hashes iface)
-- | Old-style accessor for whether or not the ModIface came from an hs-boot
-- file.
-mi_boot :: ModIface -> IsBootInterface
+mi_boot :: ModIface_ phase -> IsBootInterface
mi_boot iface = if mi_hsc_src iface == HsBootFile
then IsBoot
else NotBoot
@@ -557,7 +621,7 @@ mi_mnwib iface = GWIB (moduleName $ mi_module iface) (mi_boot iface)
-- | Lookups up a (possibly cached) fixity from a 'ModIface'. If one cannot be
-- found, 'defaultFixity' is returned instead.
-mi_fix :: ModIface -> OccName -> Fixity
+mi_fix :: ModIface_ phase -> OccName -> Fixity
mi_fix iface name = mi_fix_fn iface name `orElse` defaultFixity
-- | The semantic module for this interface; e.g., if it's a interface
@@ -573,7 +637,7 @@ mi_semantic_module iface = mi_mod_info_semantic_module (mi_mod_info iface)
-- | The "precise" free holes, e.g., the signatures that this
-- 'ModIface' depends on.
-mi_free_holes :: ModIface -> UniqDSet ModuleName
+mi_free_holes :: ModIface_ phase -> UniqDSet ModuleName
mi_free_holes iface =
case getModuleInstantiation (mi_module iface) of
(_, Just indef)
@@ -771,7 +835,7 @@ emptyPartialModIface mod
mi_iface_hash_ = fingerprint0,
mi_hi_bytes_ = PartialIfaceBinHandle,
mi_deps_ = noDependencies,
- mi_public_ = emptyPublicModIface (),
+ mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] (),
mi_simplified_core_ = Nothing,
mi_top_env_ = IfaceTopEnv emptyDetOrdAvails [] ,
mi_docs_ = Nothing,
@@ -787,24 +851,39 @@ emptyIfaceModInfo mod = IfaceModInfo
, mi_mod_info_hsc_src = HsSrcFile
}
-
-emptyPublicModIface :: IfaceAbiHashesExts phase -> IfacePublic_ phase
-emptyPublicModIface abi_hashes = IfacePublic
- { mi_exports_ = []
- , mi_decls_ = []
- , mi_fixities_ = []
- , mi_warns_ = IfWarnSome [] []
- , mi_anns_ = []
- , mi_defaults_ = []
- , mi_insts_ = []
- , mi_fam_insts_ = []
- , mi_rules_ = []
- , mi_abi_hashes_ = abi_hashes
- , mi_trust_ = noIfaceTrustInfo
- , mi_trust_pkg_ = False
- , mi_caches_ = emptyModIfaceCache
- , mi_complete_matches_ = []
- }
+emptyPublicModIface :: IfaceAnnotationsData phase
+ -> IfaceDeclsData phase
+ -> IfaceDefaultsData phase
+ -> IfaceClsInstsData phase
+ -> IfaceFamInstsData phase
+ -> IfaceRulesData phase
+ -> IfaceCompleteMatchesData phase
+ -> IfaceAbiHashesData phase
+ -> IfacePublic_ phase
+emptyPublicModIface anns
+ decls
+ defaults
+ insts
+ fam_insts
+ rules
+ complete_matches
+ abi_hashes
+ = IfacePublic
+ { mi_exports_ = []
+ , mi_fixities_ = []
+ , mi_warns_ = IfWarnSome [] []
+ , mi_anns_ = anns
+ , mi_decls_ = decls
+ , mi_defaults_ = defaults
+ , mi_insts_ = insts
+ , mi_fam_insts_ = fam_insts
+ , mi_rules_ = rules
+ , mi_trust_ = noIfaceTrustInfo
+ , mi_trust_pkg_ = False
+ , mi_complete_matches_ = complete_matches
+ , mi_caches_ = emptyModIfaceCache
+ , mi_abi_hashes_ = abi_hashes
+ }
emptyModIfaceCache :: IfaceCache
emptyModIfaceCache = IfaceCache {
@@ -827,7 +906,7 @@ emptyIfaceBackend = IfaceAbiHashes
emptyFullModIface :: Module -> ModIface
emptyFullModIface mod =
(emptyPartialModIface mod)
- { mi_public_ = emptyPublicModIface emptyIfaceBackend
+ { mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] emptyIfaceBackend
, mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
}
@@ -848,8 +927,17 @@ emptyIfaceHashCache _occ = Nothing
-- ModIface is completely forced since it will live in memory for a long time.
-- If forcing it uses a lot of memory, then store less things in ModIface.
-instance ( NFData (IfaceAbiHashesExts (phase :: ModIfacePhase))
- , NFData (IfaceDeclExts (phase :: ModIfacePhase))
+instance ( NFData (IfaceSelfRecompData phase)
+ , NFData (IfaceSimplifiedCoreData phase)
+ , NFData (ExtensibleFieldsData phase)
+ , NFData (IfaceAnnotationsData phase)
+ , NFData (IfaceDeclsData phase)
+ , NFData (IfaceDefaultsData phase)
+ , NFData (IfaceClsInstsData phase)
+ , NFData (IfaceFamInstsData phase)
+ , NFData (IfaceRulesData phase)
+ , NFData (IfaceCompleteMatchesData phase)
+ , NFData (IfaceAbiHashesData phase)
) => NFData (ModIface_ phase) where
rnf (PrivateModIface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
= (a1 :: IfaceBinHandle phase)
@@ -882,7 +970,15 @@ instance NFData IfaceAbiHashes where
`seq` rnf a5
`seq` rnf a6
-instance (NFData (IfaceAbiHashesExts phase), NFData (IfaceDeclExts phase)) => NFData (IfacePublic_ phase) where
+instance ( NFData (IfaceAnnotationsData phase)
+ , NFData (IfaceDeclsData phase)
+ , NFData (IfaceDefaultsData phase)
+ , NFData (IfaceClsInstsData phase)
+ , NFData (IfaceFamInstsData phase)
+ , NFData (IfaceRulesData phase)
+ , NFData (IfaceCompleteMatchesData phase)
+ , NFData (IfaceAbiHashesData phase)
+ ) => NFData (IfacePublic_ phase) where
rnf (IfacePublic a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14)
= rnf a1
`seq` rnf a2
@@ -958,7 +1054,6 @@ completePartialModIface partial iface_hash decls extra_decls final_exts cache =
, mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
, mi_iface_hash_ = iface_hash
}
- where
-- | Given a 'PartialIfacePublic', turn it into an 'IfacePublic' by completing
-- missing fields.
@@ -973,10 +1068,36 @@ completePublicModIface decls abi_hashes cache partial = partial
, mi_caches_ = cache
}
+shrinkModIface :: ModIface -> RetainedModIface
+shrinkModIface PrivateModIface {..}
+ = PrivateModIface
+ {
+ mi_hi_bytes_ = RetainedIfaceBinHandle,
+ mi_public_ = shrinkIfacePublic mi_public_,
+ mi_self_recomp_ = (),
+ mi_simplified_core_ = (),
+ mi_ext_fields_ = (),
+ ..
+ }
+
+shrinkIfacePublic :: IfacePublic -> RetainedIfacePublic
+shrinkIfacePublic IfacePublic {..}
+ = IfacePublic
+ {
+ mi_anns_ = (),
+ mi_decls_ = (),
+ mi_defaults_ = (),
+ mi_insts_ = (),
+ mi_fam_insts_ = (),
+ mi_rules_ = (),
+ mi_complete_matches_ = (),
+ ..
+ }
+
set_mi_mod_info :: IfaceModInfo -> ModIface_ phase -> ModIface_ phase
set_mi_mod_info val iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = val }
-set_mi_self_recomp :: Maybe IfaceSelfRecomp-> ModIface_ phase -> ModIface_ phase
+set_mi_self_recomp :: IfaceSelfRecompData phase -> ModIface_ phase -> ModIface_ phase
set_mi_self_recomp val iface = clear_mi_hi_bytes $ iface { mi_self_recomp_ = val }
set_mi_hi_bytes :: IfaceBinHandle phase -> ModIface_ phase -> ModIface_ phase
@@ -988,7 +1109,7 @@ set_mi_deps val iface = clear_mi_hi_bytes $ iface { mi_deps_ = val }
set_mi_public :: (IfacePublic_ phase -> IfacePublic_ phase) -> ModIface_ phase -> ModIface_ phase
set_mi_public f iface = clear_mi_hi_bytes $ iface { mi_public_ = f (mi_public_ iface) }
-set_mi_simplified_core :: Maybe IfaceSimplifiedCore -> ModIface_ phase -> ModIface_ phase
+set_mi_simplified_core :: IfaceSimplifiedCoreData phase -> ModIface_ phase -> ModIface_ phase
set_mi_simplified_core val iface = clear_mi_hi_bytes $ iface { mi_simplified_core_ = val }
set_mi_top_env :: IfaceTopEnv -> ModIface_ phase -> ModIface_ phase
@@ -997,7 +1118,7 @@ set_mi_top_env val iface = clear_mi_hi_bytes $ iface { mi_top_env_ = val }
set_mi_docs :: Maybe Docs -> ModIface_ phase -> ModIface_ phase
set_mi_docs val iface = clear_mi_hi_bytes $ iface { mi_docs_ = val }
-set_mi_ext_fields :: ExtensibleFields -> ModIface_ phase -> ModIface_ phase
+set_mi_ext_fields :: ExtensibleFieldsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_ext_fields val iface = clear_mi_hi_bytes $ iface { mi_ext_fields_ = val }
{- Settings for mi_public interface fields -}
@@ -1011,22 +1132,22 @@ set_mi_fixities val = set_mi_public (\iface -> iface { mi_fixities_ = val })
set_mi_warns :: IfaceWarnings -> ModIface_ phase -> ModIface_ phase
set_mi_warns val = set_mi_public (\iface -> iface { mi_warns_ = val })
-set_mi_anns :: [IfaceAnnotation] -> ModIface_ phase -> ModIface_ phase
+set_mi_anns :: IfaceAnnotationsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_anns val = set_mi_public (\iface -> iface { mi_anns_ = val })
-set_mi_insts :: [IfaceClsInst] -> ModIface_ phase -> ModIface_ phase
+set_mi_insts :: IfaceClsInstsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_insts val = set_mi_public (\iface -> iface { mi_insts_ = val })
-set_mi_fam_insts :: [IfaceFamInst] -> ModIface_ phase -> ModIface_ phase
+set_mi_fam_insts :: IfaceFamInstsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_fam_insts val = set_mi_public (\iface -> iface { mi_fam_insts_ = val })
-set_mi_rules :: [IfaceRule] -> ModIface_ phase -> ModIface_ phase
+set_mi_rules :: IfaceRulesData phase -> ModIface_ phase -> ModIface_ phase
set_mi_rules val = set_mi_public (\iface -> iface { mi_rules_ = val })
-set_mi_decls :: [IfaceDeclExts phase] -> ModIface_ phase -> ModIface_ phase
+set_mi_decls :: IfaceDeclsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_decls val = set_mi_public (\iface -> iface { mi_decls_ = val })
-set_mi_defaults :: [IfaceDefault] -> ModIface_ phase -> ModIface_ phase
+set_mi_defaults :: IfaceDefaultsData phase -> ModIface_ phase -> ModIface_ phase
set_mi_defaults val = set_mi_public (\iface -> iface { mi_defaults_ = val })
set_mi_trust :: IfaceTrustInfo -> ModIface_ phase -> ModIface_ phase
@@ -1035,10 +1156,10 @@ set_mi_trust val = set_mi_public (\iface -> iface { mi_trust_ = val })
set_mi_trust_pkg :: Bool -> ModIface_ phase -> ModIface_ phase
set_mi_trust_pkg val = set_mi_public (\iface -> iface { mi_trust_pkg_ = val })
-set_mi_complete_matches :: [IfaceCompleteMatch] -> ModIface_ phase -> ModIface_ phase
+set_mi_complete_matches :: IfaceCompleteMatchesData phase -> ModIface_ phase -> ModIface_ phase
set_mi_complete_matches val = set_mi_public (\iface -> iface { mi_complete_matches_ = val })
-set_mi_abi_hashes :: IfaceAbiHashesExts phase -> ModIface_ phase -> ModIface_ phase
+set_mi_abi_hashes :: IfaceAbiHashesData phase -> ModIface_ phase -> ModIface_ phase
set_mi_abi_hashes val = set_mi_public (\iface -> iface { mi_abi_hashes_ = val })
{- Setters for mi_caches interface fields -}
@@ -1084,8 +1205,9 @@ set_mi_mod_info_field f iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = f (mi
clear_mi_hi_bytes :: ModIface_ phase -> ModIface_ phase
clear_mi_hi_bytes iface = iface
{ mi_hi_bytes_ = case mi_hi_bytes iface of
- PartialIfaceBinHandle -> PartialIfaceBinHandle
- FullIfaceBinHandle _ -> FullIfaceBinHandle Strict.Nothing
+ PartialIfaceBinHandle -> PartialIfaceBinHandle
+ FullIfaceBinHandle _ -> FullIfaceBinHandle Strict.Nothing
+ RetainedIfaceBinHandle -> RetainedIfaceBinHandle
}
-- ----------------------------------------------------------------------------
@@ -1183,22 +1305,22 @@ pattern ModIface ::
-> [IfaceExport]
-> [(OccName, Fixity)]
-> IfaceWarnings
- -> [IfaceAnnotation]
- -> [IfaceDeclExts phase]
- -> Maybe IfaceSimplifiedCore
- -> [IfaceDefault]
+ -> IfaceAnnotationsData phase
+ -> IfaceDeclsData phase
+ -> IfaceSimplifiedCoreData phase
+ -> IfaceDefaultsData phase
-> IfaceTopEnv
- -> [IfaceClsInst]
- -> [IfaceFamInst]
- -> [IfaceRule]
+ -> IfaceClsInstsData phase
+ -> IfaceFamInstsData phase
+ -> IfaceRulesData phase
-> IfaceTrustInfo
-> Bool
- -> [IfaceCompleteMatch]
+ -> IfaceCompleteMatchesData phase
-> Maybe Docs
- -> IfaceAbiHashesExts phase
- -> ExtensibleFields
+ -> IfaceAbiHashesData phase
+ -> ExtensibleFieldsData phase
-> IfaceBinHandle phase
- -> Maybe IfaceSelfRecomp
+ -> IfaceSelfRecompData phase
-> (OccName -> Maybe Fixity)
-> (OccName -> Maybe (OccName, Fingerprint))
-> (OccName -> Maybe (WarningTxt GhcRn))
=====================================
ghc/Main.hs
=====================================
@@ -515,7 +515,7 @@ abiHash strs = do
put_ bh hiVersion
-- package hashes change when the compiler version changes (for now)
-- see #5328
- mapM_ (put_ bh . mi_mod_hash) ifaces
+ mapM_ (put_ bh . mi_abi_mod_hash . mi_abi_hashes) ifaces
f <- fingerprintBinMem bh
putStrLn (showPpr dflags f)
=====================================
utils/count-deps/Main.hs
=====================================
@@ -79,5 +79,5 @@ calcDeps modName libdir =
mkModule :: String -> ModuleName -> Module
mkModule ghcUnitId = Module (stringToUnit ghcUnitId)
- modDeps :: ModIface -> [ModuleName]
+ modDeps :: RetainedModIface -> [ModuleName]
modDeps mi = map (gwib_mod . (\(_, _, mn) -> mn)) $ Set.toList $ dep_direct_mods (mi_deps mi)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/714ac6876bd0a527fe0397c2391a2f5…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/714ac6876bd0a527fe0397c2391a2f5…
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/multi-threaded-debugger] 8 commits: Look up a thread's ResumeContext without taking a lock
by Rodrigo Mesquita (@alt-romes) 05 Oct '26
by Rodrigo Mesquita (@alt-romes) 05 Oct '26
05 Oct '26
Rodrigo Mesquita pushed to branch wip/romes/multi-threaded-debugger at Glasgow Haskell Compiler / GHC
Commits:
c3176c10 by Rodrigo Mesquita at 2026-09-23T17:27:47+01:00
Look up a thread's ResumeContext without taking a lock
modifyMVar is unnecessarily expensive and blocking when most often we
just care about reading without modifying. optimize for default case
(thread context already exists). It is called every single time a
breakpoint is hit (regardless of whether we stop there, e.g. in
interpreter_steplocal we do not stop there often)
-3.3% improvement over original regression
- - - - -
5d3cb7fa by Rodrigo Mesquita at 2026-09-23T17:28:04+01:00
Every thread resume-context keeps a var for its EvalStatus
Kill the global mapping from thread id to EvalStatus
Instead, keep the EvalStatus in the ResumeContext associated to a thread
in the threadContextVar (where entries are created on breakpoints being
hit and when writing an EvalComplete result)
Before, every breakpoint hit meant reading the global map TVar and
deleting a map entry which did a lot of allocations. Now, we have a
Nothing variable which we overwrite to "take" rather than deleting from
a Map and allocating the GlobalDbgMap too. Note that for every
breakpoint hit we'd have to insert the ThreadId entry in the map again
(because we deleted it last time we resumed), again allocating
unnecessarily. Now it's only a look up on the map and an update on the
variable directly.
And a LOT of breakpoints were hit on interpreter_steplocal, stress
testing the cost of hitting a breakpoint
The isolated threads move to their own top-level TVar Set.
-4.4% improvement over the regression
- - - - -
3ffdef29 by Rodrigo Mesquita at 2026-09-23T17:28:15+01:00
Move whether a thread is isolated to the same global map
Stops us from reconstructing the set every time this changed instead to
being a per thread variable just toggled on/off, by default non-isolated
like before (before it was Set.empty, Set.insert for True, Set.delete
for FALSE). This is more straightforward -- there's always an isolation
mode per thread and we can toggle it directly
reduces slightly allocations, but the main advantage is killing a second
global map and making it more uniform with just one thread map and no
membership check for toggledness.
- - - - -
4a826f19 by Rodrigo Mesquita at 2026-10-01T11:22:37+01:00
Prefer foldl' in readAnyThreadEvalBreak txn
retry 'orElse' next is just next, so we might as well use a strict fold
- - - - -
a3e3a66f by Rodrigo Mesquita at 2026-10-01T16:36:23+01:00
Add inline TODO about improving efficiency of readyAnyThreadBreak
It is currently O(N) in number of threads that have hit breakpoints
It should be number of *live* threads that have hit breaks, bc we still need to find a way to evacuate threads from the map
- - - - -
ee339734 by Rodrigo Mesquita at 2026-10-01T17:33:52+01:00
Set global breakpoint action in sandboxIO rather than withBreakAction
- - - - -
aa7ab6ca by Rodrigo Mesquita at 2026-10-01T17:35:10+01:00
TODO comment on breakOnException being global rather than per-thread
- - - - -
a7150ad3 by Rodrigo Mesquita at 2026-10-05T16:21:30+01:00
WIP: Asynchronous eval/resume
- - - - -
6 changed files:
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Runtime/Interpreter.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Run.hs
- libraries/ghci/GHCi/Run/Breakpoints.hs
- libraries/ghci/GHCi/Server.hs
Changes:
=====================================
compiler/GHC/Runtime/Eval.hs
=====================================
@@ -188,12 +188,13 @@ execOptions = ExecOptions
-- by default we just care about breakpoints hit in this eval thread
}
--- | Run a statement in the current interactive context.
+-- | Run a statement in the current interactive context, as a new thread in the interpreter.
+-- Returns an action which blocks waiting for the execution to finish and yield a result.
execStmt
:: GhcMonad m
=> String -- ^ a statement (bind or expression)
-> ExecOptions
- -> m ExecResult
+ -> m (m ExecResult)
execStmt input exec_opts@ExecOptions{..} = do
hsc_env <- getSession
@@ -204,13 +205,15 @@ execStmt input exec_opts@ExecOptions{..} = do
case mb_stmt of
-- empty statement / comment
- Nothing -> return (ExecComplete (Right []) 0)
+ Nothing -> pure (pure (ExecComplete (Right []) 0))
Just stmt -> execStmt' stmt input exec_opts
-- | Like `execStmt`, but takes a parsed statement as argument. Useful when
-- doing preprocessing on the AST before execution, e.g. in GHCi (see
-- GHCi.UI.runStmt).
-execStmt' :: GhcMonad m => GhciLStmt GhcPs -> String -> ExecOptions -> m ExecResult
+--
+-- Returns an action which blocks waiting for the execution to finish and yield a result.
+execStmt' :: GhcMonad m => GhciLStmt GhcPs -> String -> ExecOptions -> m (m ExecResult)
execStmt' stmt stmt_text ExecOptions{..} = do
hsc_env <- getSession
let interp = hscInterp hsc_env
@@ -226,21 +229,22 @@ execStmt' stmt stmt_text ExecOptions{..} = do
case r of
Nothing ->
-- empty statement / comment
- return (ExecComplete (Right []) 0)
+ pure (pure (ExecComplete (Right []) 0))
Just (ids, hval, fix_env) -> do
updateFixityEnv fix_env
let eval_opts = initEvalOpts idflags' (enableGhcStepMode execSingleStep)
(enableIsolateThreadBreaks execIsolateMode)
- status <- liftIO $ evalStmt interp eval_opts (execWrap hval)
+ rtid <- liftIO $ evalStmt interp eval_opts (execWrap hval)
let ic = hsc_IC hsc_env
bindings = (ic_tythings ic, ic_gre_cache ic)
size = ghciHistSize idflags'
-
- handleRunStatus execSingleStep eval_opts stmt_text bindings ids
- status (emptyHistory size)
+ pure $ do
+ status <- liftIO (waitThreadResult interp rtid)
+ handleRunStatus execSingleStep eval_opts stmt_text bindings ids
+ status (emptyHistory size)
runDecls :: GhcMonad m => String -> m [TyThing]
runDecls = runDeclsWithLocation "<interactive>" 1
@@ -326,16 +330,16 @@ handleRunStatus step eval_opts expr bindings final_ids status history0 = do
return (ExecComplete (Left (fromSerializableException e)) alloc)
-- Nothing case: we stopped when an exception was raised, not at a breakpoint.
- EvalBreak apStack_ref Nothing resume_ctxt ccs -> do
- resume_ctxt_fhv <- liftIO $ mkFinalizedHValue interp resume_ctxt
- apStack_fhv <- liftIO $ mkFinalizedHValue interp apStack_ref
+ EvalBreak apStack_ref Nothing resume_tid ccs -> do
+ resume_tid_fhv <- liftIO $ mkFinalizedHValue interp resume_tid
+ apStack_fhv <- liftIO $ mkFinalizedHValue interp apStack_ref
let span = mkGeneralSrcSpan (fsLit "<unknown>")
(hsc_env1, break_ids) <- liftIO $
bindLocalsAtBreakpoint hsc_env apStack_fhv span Nothing
let
resume = Resume
{ resumeStmt = expr
- , resumeContext = resume_ctxt_fhv
+ , resumeContext = resume_tid_fhv
, resumeBindings = bindings
, resumeFinalIds = final_ids
, resumeApStack = apStack_fhv
@@ -356,7 +360,7 @@ handleRunStatus step eval_opts expr bindings final_ids status history0 = do
-- The interpreter yields on a breakpoint if:
-- - the breakpoint was explicitly enabled (in @BreakArray@)
-- - or one of the stepping options in @EvalOpts@ caused us to stop at one
- EvalBreak apStack_ref (Just eval_break) resume_ctxt ccs -> do
+ EvalBreak apStack_ref (Just eval_break) resume_tid ccs -> do
let ibi = evalBreakpointToId eval_break
let hug = hsc_HUG hsc_env
info_brks <- liftIO $ readIModBreaks hug ibi
@@ -368,8 +372,8 @@ handleRunStatus step eval_opts expr bindings final_ids status history0 = do
breakArray <- getBreakArray interp ibi info_brks
breakpointStatus interp breakArray (ibi_info_index ibi)
- apStack_fhv <- liftIO $ mkFinalizedHValue interp apStack_ref
- resume_ctxt_fhv <- liftIO $ mkFinalizedHValue interp resume_ctxt
+ apStack_fhv <- liftIO $ mkFinalizedHValue interp apStack_ref
+ resume_tid_fhv <- liftIO $ mkFinalizedHValue interp resume_tid
-- This breakpoint is enabled or we mean to break here;
-- we want to stop instead of just logging it.
@@ -382,7 +386,7 @@ handleRunStatus step eval_opts expr bindings final_ids status history0 = do
let
resume = Resume
{ resumeStmt = expr
- , resumeContext = resume_ctxt_fhv
+ , resumeContext = resume_tid_fhv
, resumeBindings = bindings
, resumeFinalIds = final_ids
, resumeApStack = apStack_fhv
@@ -398,7 +402,9 @@ handleRunStatus step eval_opts expr bindings final_ids status history0 = do
return (ExecBreak break_ids (Just ibi) resume)
else do
-- resume with the same step type
- status <- liftIO $ GHCi.resumeStmt interp eval_opts resume_ctxt_fhv
+ status <- liftIO $ do
+ GHCi.resumeStmt interp eval_opts resume_tid_fhv
+ GHCi.waitThreadResult interp resume_tid_fhv
history <- if not tracing then pure history0 else do
history1 <- liftIO $ mkHistory hug apStack_fhv ibi
let !history' = history1 `consBL` history0
@@ -414,7 +420,9 @@ resumeExec :: GhcMonad m
-> ThreadBreaksIsolationMode
-> Maybe Int
-> Resume
- -> m ExecResult
+ -> m (m ExecResult)
+ -- ^ Returns an action which blocks waiting for the resumed thread
+ -- to break again or yield a result
resumeExec step isolateMode mbCnt r = do
hsc_env <- getSession
let ic = hsc_IC hsc_env
@@ -438,7 +446,7 @@ resumeExec step isolateMode mbCnt r = do
case r of
Resume { resumeStmt = expr
- , resumeContext = fhv
+ , resumeContext = rtid
, resumeBindings = bindings
, resumeFinalIds = final_ids
, resumeApStack = apStack
@@ -454,17 +462,19 @@ resumeExec step isolateMode mbCnt r = do
let eval_opts = initEvalOpts dflags (enableGhcStepMode step)
(enableIsolateThreadBreaks isolateMode)
- status <- liftIO $ GHCi.resumeStmt interp eval_opts fhv
- let prevHistoryLst = fromListBL 50 hist
- hug = hsc_HUG hsc_env
- hist' = case mb_brkpt of
- Nothing -> pure prevHistoryLst
- Just bi
- | breakHere False step span -> do
- hist1 <- liftIO (mkHistory hug apStack bi)
- return $ hist1 `consBL` fromListBL 50 hist
- | otherwise -> pure prevHistoryLst
- handleRunStatus step eval_opts expr bindings final_ids status =<< hist'
+ liftIO $ GHCi.resumeStmt interp eval_opts rtid
+ pure $ do
+ status <- liftIO $ GHCi.waitThreadResult interp rtid
+ let prevHistoryLst = fromListBL 50 hist
+ hug = hsc_HUG hsc_env
+ hist' = case mb_brkpt of
+ Nothing -> pure prevHistoryLst
+ Just bi
+ | breakHere False step span -> do
+ hist1 <- liftIO (mkHistory hug apStack bi)
+ return $ hist1 `consBL` fromListBL 50 hist
+ | otherwise -> pure prevHistoryLst
+ handleRunStatus step eval_opts expr bindings final_ids status =<< hist'
setupBreakpoint :: GhcMonad m => Interp -> InternalBreakpointId -> Int -> m () -- #19157
setupBreakpoint interp ibi cnt = do
@@ -1275,7 +1285,9 @@ compileParsedExprRemote expr@(L loc _) = withSession $ \hsc_env -> do
updateFixityEnv fix_env
let eval_opts = initEvalOpts dflags EvalStepNone True
- status <- liftIO $ evalStmt interp eval_opts (EvalThis hvals_io)
+ status <- liftIO $ do
+ rtid <- evalStmt interp eval_opts (EvalThis hvals_io)
+ waitThreadResult interp rtid
case status of
EvalComplete _ (EvalSuccess [hval]) -> return hval
EvalComplete _ (EvalException e) ->
=====================================
compiler/GHC/Runtime/Interpreter.hs
=====================================
@@ -11,6 +11,7 @@ module GHC.Runtime.Interpreter
, evalStmt, EvalStatus_(..), EvalStatus, EvalResult(..), EvalExpr(..)
, resumeStmt
, abandonStmt
+ , waitThreadResult
, evalIO
, evalString
, evalStringToIOString
@@ -286,11 +287,11 @@ evalStmt
:: Interp
-> EvalOpts
-> EvalExpr ForeignHValue
- -> IO (EvalStatus_ [ForeignHValue] [HValueRef])
+ -> IO (ForeignRef ThreadId)
evalStmt interp opts foreign_expr = do
- status <- withExpr foreign_expr $ \expr ->
+ r <- withExpr foreign_expr $ \expr ->
interpCmd interp (EvalStmt opts expr)
- handleEvalStatus interp status
+ mkFinalizedHValue interp r
where
withExpr :: EvalExpr ForeignHValue -> (EvalExpr HValueRef -> IO a) -> IO a
withExpr (EvalThis fhv) cont =
@@ -304,17 +305,25 @@ resumeStmt
:: Interp
-> EvalOpts
-> ForeignRef ThreadId
- -> IO (EvalStatus_ [ForeignHValue] [HValueRef])
+ -> IO ()
resumeStmt interp opts resume_tid = do
- status <- withForeignRef resume_tid $ \rhv ->
+ withForeignRef resume_tid $ \rhv ->
interpCmd interp (ResumeStmt opts rhv)
- handleEvalStatus interp status
abandonStmt :: Interp -> ForeignRef ThreadId -> IO ()
abandonStmt interp resume_tid =
withForeignRef resume_tid $ \rhv ->
interpCmd interp (AbandonStmt rhv)
+waitThreadResult
+ :: Interp
+ -> ForeignRef ThreadId
+ -> IO (EvalStatus_ [ForeignHValue] [HValueRef])
+waitThreadResult interp tid = do
+ status <- withForeignRef tid $ \rhv -> do
+ interpCmd interp (WaitThreadResult rhv)
+ handleEvalStatus interp status
+
handleEvalStatus
:: Interp
-> EvalStatus [HValueRef]
@@ -417,8 +426,9 @@ whereFrom interp ref =
seqHValue :: Interp -> UnitEnv -> Logger -> ForeignHValue -> IO (EvalResult ())
seqHValue interp unit_env logger ref =
withForeignRef ref $ \hval -> do
- status <- interpCmd interp (Seq hval)
- handleSeqHValueStatus interp unit_env logger status
+ rtid <- interpCmd interp (Seq hval)
+ status <- interpCmd interp (WaitThreadResult rtid)
+ handleSeqHValueStatus interp unit_env logger (clearEvalStatus status)
evalBreakpointToId :: EvalBreakpoint -> InternalBreakpointId
evalBreakpointToId eval_break =
@@ -460,9 +470,10 @@ handleSeqHValueStatus interp unit_env logger eval_status =
Just modbreaks -> put =<< getBreakLoc (readIModModBreaks hug) ibi modbreaks
-- resume the seq (:force) processing in the iserv process
- withForeignRef resume_ctxt_fhv $ \hval -> do
- status <- interpCmd interp (ResumeSeq hval)
- handleSeqHValueStatus interp unit_env logger status
+ withForeignRef resume_ctxt_fhv $ \rtid -> do
+ interpCmd interp (ResumeSeq rtid)
+ status <- interpCmd interp (WaitThreadResult rtid)
+ handleSeqHValueStatus interp unit_env logger (clearEvalStatus status)
(EvalComplete _ r) -> return r
@@ -771,3 +782,9 @@ readIModModBreaks hug mod = imodBreaks_modBreaks . expectJust <$> readIModBreaks
fromEvalResult :: EvalResult a -> IO a
fromEvalResult (EvalException e) = throwIO (fromSerializableException e)
fromEvalResult (EvalSuccess a) = return a
+
+clearEvalStatus :: EvalStatus a -> EvalStatus ()
+clearEvalStatus = \case
+ EvalComplete w (EvalException se) -> EvalComplete w (EvalException se)
+ EvalComplete w (EvalSuccess _) -> EvalComplete w (EvalSuccess ())
+ EvalBreak ap mb rt rccs -> EvalBreak ap mb rt rccs
=====================================
libraries/ghci/GHCi/Message.hs
=====================================
@@ -62,6 +62,8 @@ import Data.Dynamic
import Data.Typeable (TypeRep)
import Data.IORef
import Data.Map (Map)
+import Data.IntMap (IntMap)
+import qualified Data.IntMap as IM
import Foreign
import GHC.Generics
import GHC.Stack.CCS
@@ -132,13 +134,13 @@ data Message a where
EvalStmt
:: EvalOpts
-> EvalExpr HValueRef {- IO [a] -}
- -> Message (EvalStatus [HValueRef]) {- [a] -}
+ -> Message (RemoteRef ThreadId) {- [a] -}
-- | Resume evaluation of a statement after a breakpoint
ResumeStmt
:: EvalOpts
-> RemoteRef ThreadId
- -> Message (EvalStatus [HValueRef])
+ -> Message ()
-- | Abandon evaluation of a statement after a breakpoint
AbandonStmt
@@ -240,12 +242,23 @@ data Message a where
-- | Evaluate something. This is used to support :force in GHCi.
Seq
:: HValueRef
- -> Message (EvalStatus ())
+ -> Message (RemoteRef ThreadId)
-- | Resume forcing a free variable in a breakpoint (#2950)
ResumeSeq
:: RemoteRef ThreadId
- -> Message (EvalStatus ())
+ -> Message ()
+
+ WaitThreadResult
+ :: RemoteRef ThreadId
+ -> Message (EvalStatus [HValueRef])
+
+ WaitAnyThreadBreak
+ :: Message EvalBreak
+
+ WaitThreadResultOrAnyThreadBreak
+ :: RemoteRef ThreadId
+ -> Message (EvalStatus [HValueRef])
-- | User-defined request encoded as a tag/payload pair. This is left
-- uninterpreted by GHC and is meant for GHC API applications to be able to supply
@@ -724,6 +737,7 @@ data Pipe = Pipe
{ getSome :: !(IO ByteString)
, putAll :: !(B.Builder -> IO ())
, pipeLeftovers :: !(IORef (Maybe ByteString))
+ -- , waitingStatus :: !(IORef (Map (RemoteRef ThreadId) (MVar (EvalStatus ()))))
}
-- | Make a 'Pipe' from a 'Handle' to read and a 'Handle' to write.
@@ -744,8 +758,19 @@ mkPipeFromContinuations getSome putAll = do
remoteCall :: Binary a => Pipe -> Message a -> IO a
remoteCall pipe msg = do
- writePipe pipe (putMessage msg)
- readPipe pipe get
+ -- synchronous, write, read
+ writePipe pipe (putMessage msg) -- write goes in the handle
+ readPipe pipe get -- instead, this takes from the channel
+ -- the channel is fed from the handle by a different thread that creates a
+ -- stream of notifications and a stream of replies.
+ --
+ -- Since a reply will only come in response to a write request that happens
+ -- while the entire is thing is locked, we'll only get 1 reply per write, and
+ -- in fact the channel of replies is just 1 cell (MVar)
+ --
+ -- ATOMIC:
+ -- write pipe
+ -- read reply -- will never have more than 1 reply, because the Lock guarantees only 1 write.
writePipe :: Pipe -> Put -> IO ()
writePipe Pipe{..} put = putAll $ execPut put
@@ -755,6 +780,11 @@ remoteTHCall pipe msg = do
writePipe pipe (putTHMessage msg)
readPipe pipe get
+-- todo: this will have to drain the pipe and write to a queue?
+-- Normal replies pushed to reply channel
+-- Remote call instead of ReadPipe, reads from the channel.
+--
+-- We need to drain channel for notifications...
readPipe :: Pipe -> Get a -> IO a
readPipe Pipe{..} get = do
leftovers <- readIORef pipeLeftovers
=====================================
libraries/ghci/GHCi/Run.hs
=====================================
@@ -128,6 +128,15 @@ run m = case m of
Seq ref -> doSeq ref
ResumeSeq ref -> resumeSeq ref
+ WaitThreadResult tid -> localRef tid >>= atomically . readThreadEvalStatus
+ WaitAnyThreadBreak -> atomically $ readAnyThreadEvalBreak
+ WaitThreadResultOrAnyThreadBreak t -> do
+ tid <- localRef t
+ atomically $
+ readThreadEvalStatus tid
+ `orElse`
+ (EvalPaused <$> readAnyThreadEvalBreak)
+
Shutdown -> unexpectedMessage m
RunTH {} -> unexpectedMessage m
RunModFinalizers {} -> unexpectedMessage m
@@ -206,7 +215,7 @@ tryEval io = do
--------------------------------------------------------------------------------
-evalStmt :: EvalOpts -> EvalExpr HValueRef -> IO (EvalStatus [HValueRef])
+evalStmt :: EvalOpts -> EvalExpr HValueRef -> IO (RemoteRef ThreadId)
evalStmt opts expr = do
io <- mkIO expr
sandboxIO opts $ do
@@ -248,16 +257,16 @@ evalStringToString r str = do
-- The UI process has more and therefore also can show more
-- information about the breakpoint than the current iserv
-- process.
-doSeq :: RemoteRef a -> IO (EvalStatus ())
-doSeq ref = clearEvalStatus <$> do
+doSeq :: RemoteRef a -> IO (RemoteRef ThreadId)
+doSeq ref = do
sandboxIO evalOptsSeq $ do
_ <- (void $ evaluate =<< localRef ref)
return []
-- | Process a ResumeSeq message. Continue the :force processing #2950
-- after a breakpoint.
-resumeSeq :: RemoteRef ThreadId -> IO (EvalStatus ())
-resumeSeq hvref = clearEvalStatus <$> resumeStmt evalOptsSeq hvref
+resumeSeq :: RemoteRef ThreadId -> IO ()
+resumeSeq hvref = resumeStmt evalOptsSeq hvref
evalOptsSeq :: EvalOpts
evalOptsSeq = EvalOpts
@@ -296,15 +305,16 @@ abandonStmt hvref = do
--------------------------------------------------------------------------------
-resumeStmt :: EvalOpts -> RemoteRef ThreadId -> IO (EvalStatus [HValueRef])
+resumeStmt :: EvalOpts -> RemoteRef ThreadId -> IO ()
resumeStmt opts rtid = do
resumeThreadId <- localRef rtid
ResumeContext{..} <- getThreadResumeContext resumeThreadId
- withBreakAction opts resumeThreadId $ \waitForResult ->
- mask_ $ do
- putMVar resumeBreakMVar () -- this awakens the stopped thread...
- redirectInterrupts resumeThreadId $
- waitForResult
+ setBreakAction opts resumeThreadId -- See Note [TODO: all break options must be set every time]
+ -- withBreakAction opts resumeThreadId $ \waitForResult ->
+ -- mask_ $ do
+ putMVar resumeBreakMVar () -- this awakens the stopped thread...
+ -- redirectInterrupts resumeThreadId $
+ -- waitForResult
-- When running a computation, we redirect ^C exceptions to the running
-- thread. ToDo: we might want a way to continue even if the target
@@ -316,26 +326,51 @@ resumeStmt opts rtid = do
-- only while we execute the user's code. We can't afford to lose the final
-- putMVar, otherwise deadlock ensues. (#1583, #1922, #1946)
-sandboxIO :: EvalOpts -> IO [HValueRef] -> IO (EvalStatus [HValueRef])
+sandboxIO :: EvalOpts -> IO [HValueRef] -> IO (RemoteRef ThreadId)
sandboxIO opts io
| useSandboxThread opts
= do
wait <- newEmptyMVar
+ -- If we are evaluating expressions (sandboxIO), then make sure the
+ -- global breakpoint action is set.
+ --
+ -- TODO: Is this thread unsafe? Already running threads may access this
+ -- pointer as we write it when evaluating a new expression.
+ --
+ -- A solution would be to have an "initialize interpreter" command
+ -- which sets this at the start. A different solution is to have a
+ -- global lock and only write this once here, then lock.
+ poke breakPointIOAction globalBreakStablePtr
+
tid <- forkIO $ do
takeMVar wait -- don't run anything in this thread before
- -- `withBreakAction` has a chance to set up.
+ -- `setBreakAction` has a chance to set up.
tid <- myThreadId
labelThread tid "GHCi sandbox"
+
+ -- WHEN THE THREAD IS FINISHED, write the value itself.
+ --
+ -- we only write the TID status map in two places:
+ --
+ -- When the "main" thread finishes (here)
+ -- When any thread hits a breakpoint (global break action)
unsafeUnmask runIt >>= writeThreadEvalStatus tid
+ -- TODO: This unsafe-unmask is very dubious. Consult with Andrea. I
+ -- don't think we should be uninterruptable masking interp commands
+ -- somewhere else. This should just be runIt?
- -- We are running in uninterruptibleMask
- withBreakAction opts tid $ \waitForResult -> do
- putMVar wait ()
- redirectInterrupts tid $ unsafeUnmask $
- waitForResult
+ -- We are running in uninterruptibleMask -- TODO WHY??
+ setBreakAction opts tid
+ putMVar wait ()
+
+ mkRemoteRef tid
+ -- withBreakAction opts tid $ \waitForResult -> do
+ -- putMVar wait ()
+ -- redirectInterrupts tid $ unsafeUnmask $
+ -- waitForResult
| otherwise
= do
@@ -349,7 +384,17 @@ sandboxIO opts io
-- tracing, etc.) need the expression to be running in a
-- separate thread, so debugging is only enabled when
-- using the sandbox.
- runIt
+ tid <- forkIO (pure ())
+ runIt >>= writeThreadEvalStatus tid
+ mkRemoteRef tid
+ -- We `runIt` on the main thread, but fork a new thread to store to the
+ -- result with `writeThreadEvalStatus` to fit the asynchronous API. We
+ -- can't use myThreadId because if the user happens to runIt twice
+ -- before awaiting, the second result will clobber the first.
+
+ -- TODO We have to be careful evacuating this map bc there may be
+ -- uncollected results from finished threads. So the thread map can't
+ -- be weak refs ? Or maybe because of the RemoteRef it's fine. Ah, prob.
where
runIt = measureAlloc $ tryEval $ rethrow opts $ clearCCS io
@@ -404,17 +449,17 @@ sandboxIO opts io
-- whenever "main" or one of the threads spawned by "main" hit a breakpoint,
-- rather than just "main" being observed. This should be used for the main
-- debuggee execution of a debugger.
-withBreakAction :: EvalOpts -> ThreadId -> (IO (EvalStatus [HValueRef]) -> IO a) -> IO a
-withBreakAction opts tid@(ThreadId tid#) act
- = bracket setBreakAction resetBreakAction (\_ -> act waitForResult)
+-- withBreakAction :: EvalOpts -> ThreadId -> (IO (EvalStatus [HValueRef]) -> IO a) -> IO a
+-- withBreakAction opts tid@(ThreadId tid#) act = do
+
+setBreakAction :: EvalOpts -> ThreadId -> IO ()
+setBreakAction opts tid@(ThreadId tid#) = do
+ ctx <- getThreadResumeContext tid
+ setBreakAction' ctx
+ -- bracket _ (resetBreakAction ctx) (\_ -> act (waitForResult ctx))
where
- setBreakAction = do
- poke breakPointIOAction globalBreakStablePtr
- -- TODO: This is poke thread unsafe, as one thread might be accessing this
- -- global variable while this thread tries to overwrite it. We should
- -- rather do it when the interpreter process/internal is initialized
- -- somehow.
-
+ setBreakAction' ctx = do
+ -- TODO: TERRIBLY NOT MULTI-THREAD FRIENDLY. Each thread needs its own RTS flag exceptionFlag, like we have for step-in or step-out.
runIf breakOnException $ \_ -> poke exceptionFlag 1
-- Breaking on exceptions is not enabled by default, since it
-- might be a bit surprising. The exception flag is turned off
@@ -422,32 +467,34 @@ withBreakAction opts tid@(ThreadId tid#) act
runIf# singleStep rts_enableStopNextBreakpoint
runIf# stepOut rts_enableStopAfterReturn
- runIf isolateThreadBreaks setIsolatedThread
- resetBreakAction () = do
- poke exceptionFlag 0
+ runIfCtx ctx isolateThreadBreaks setIsolatedCtx
+
+ resetBreakAction ctx () = do
+ poke exceptionFlag 0 -- just wrong, expection flag should be per-thread
rts_disableStopAfterReturn tid#
rts_disableStopNextBreakpoint tid#
- runIf isolateThreadBreaks unsetIsolatedThread
+ runIfCtx ctx isolateThreadBreaks unsetIsolatedCtx
-- freeStablePtr stablePtr TODO: we never free the global stablePtr for
-- global action. Maybe we should have a de-init for clean up.
-- TODO: don't set it in `setBreakAction` either. Should be on
-- interpreter initialization.
- runIf pred what = when (pred opts) (what tid)
- runIf# pred what = when (pred opts) (what tid#)
+ runIf pred what = when (pred opts) (what tid)
+ runIf# pred what = when (pred opts) (what tid#)
+ runIfCtx ctx pred what = when (pred opts) (what ctx)
- waitForResult
+ waitForResult ctx
| isolateThreadBreaks opts
= atomically $
- readThreadEvalStatus tid
+ readCtxEvalStatus ctx
| otherwise
= atomically $
(EvalPaused <$> readAnyThreadEvalBreak)
`orElse`
- readThreadEvalStatus tid
+ readCtxEvalStatus ctx
-- While we're waiting for the sandbox thread to return a result, if
-- the current thread receives an asynchronous exception we re-throw
@@ -476,9 +523,3 @@ redirectInterrupts target wait = do
Nothing -> wait
Just target -> do throwTo target (e :: SomeException); wait
-clearEvalStatus :: EvalStatus a -> EvalStatus ()
-clearEvalStatus = \case
- EvalComplete w (EvalException se) -> EvalComplete w (EvalException se)
- EvalComplete w (EvalSuccess _) -> EvalComplete w (EvalSuccess ())
- EvalBreak ap mb rt rccs -> EvalBreak ap mb rt rccs
-
=====================================
libraries/ghci/GHCi/Run/Breakpoints.hs
=====================================
@@ -8,10 +8,12 @@ module GHCi.Run.Breakpoints
-- * Per-thread breakpoints
, readThreadEvalStatus, readAnyThreadEvalBreak
, writeThreadEvalStatus
+ , readCtxEvalStatus, writeCtxEvalStatus
-- ** Isolating thread breakpoints
, withIsolatedThread
, setIsolatedThread, unsetIsolatedThread
+ , setIsolatedCtx, unsetIsolatedCtx
-- ** Querying the global thread breakpoint map
, listOtherPausedThreads
@@ -29,18 +31,15 @@ import GHCi.Message
import GHCi.RemoteTypes
import qualified Data.Map as Map
-import qualified Data.Set as Set
import Control.Concurrent
import Control.Exception
import qualified Data.ByteString.Short.Internal as BS
-#if defined(PROFILING)
-import GHC.Data.ShortByteString
-#endif
import GHC.Exts
import GHC.Stack
import Foreign hiding (void)
import GHC.Conc.Sync
import GHC.IO hiding ( bracket )
+import Control.Monad
--------------------------------------------------------------------------------
-- * Global break action
@@ -72,7 +71,7 @@ globalBreakStablePtr = unsafePerformIO $ newStablePtr globalBreakAction
globalBreakAction :: BreakpointCallback
globalBreakAction info_mod# info_mod_uid# infox# is_exception apStack = do
tid <- myThreadId
- ResumeContext{..} <- getThreadResumeContext tid
+ ctx@ResumeContext{..} <- getThreadResumeContext tid
resume_r <- mkRemoteRef tid
apStack_r <- mkRemoteRef apStack
ccs <- toRemotePtr <$> getCCSOf apStack
@@ -83,7 +82,7 @@ globalBreakAction info_mod# info_mod_uid# infox# is_exception apStack = do
info_mod <- BS.packCString (Ptr info_mod#)
info_mod_uid <- BS.packCString (Ptr info_mod_uid#)
pure (Just (EvalBreakpoint info_mod info_mod_uid (I# infox#)))
- writeThreadEvalStatus tid $ EvalBreak apStack_r mb_breakpoint resume_r ccs
+ writeCtxEvalStatus ctx $ EvalBreak apStack_r mb_breakpoint resume_r ccs
-- Block until this thread is resumed (by the thread which took the
-- `ResumeContext` from the `statusMVar`).
@@ -109,14 +108,19 @@ globalBreakAction info_mod# info_mod_uid# infox# is_exception apStack = do
-- Succeeds when the given thread writes to the global debugger map an eval result.
readThreadEvalStatus :: ThreadId -> STM (EvalStatus [HValueRef])
readThreadEvalStatus tid = do
- GlobalDbgStatus{..} <- readTVar globalDbgStatusVar
- case Map.lookup tid threadEvalStatuses of
+ ctxs <- readTVar threadContextsVar
+ case Map.lookup tid ctxs of
+ Just ctx -> readCtxEvalStatus ctx
+ Nothing -> retry -- to write a thread break or result, the
+ -- 'threadContextsVar' entry will be created
+
+-- | Like 'readThreadEvalStatus', but when the 'ResumeContext' is already
+-- available (to avoid looking it up unnecessarily).
+readCtxEvalStatus :: ResumeContext -> STM (EvalStatus [HValueRef])
+readCtxEvalStatus ResumeContext{resumeEvalStatus} =
+ readTVar resumeEvalStatus >>= \case
Just r -> do
- writeTVar globalDbgStatusVar
- GlobalDbgStatus
- { threadEvalStatuses = Map.delete tid threadEvalStatuses -- clear it
- , isolatedThreads
- }
+ writeTVar resumeEvalStatus Nothing -- clear it
pure r
Nothing -> retry -- until someone writes the result for this thread
@@ -126,38 +130,46 @@ readThreadEvalStatus tid = do
-- The debugger will be waiting for threads to break using `readAnyThreadEvalBreak`.
--
-- Succeeds when any thread hits a breakpoint.
+--
+-- TODO: Instead of reading all elems of the map, we could have the global
+-- break action write breakpoints hit into a global `TChan ThreadId`, and then
+-- `readAnyThreadEvalBreak` would read off of this channel breakpoints that
+-- were hit, and do the lookup on the map by ThreadId, retrying if it has
+-- already been handled (i.e. set to Nothing)
readAnyThreadEvalBreak :: STM EvalBreak
readAnyThreadEvalBreak = do
- dbgs <- readTVar globalDbgStatusVar
+ ctxs <- readTVar threadContextsVar
-- try reading any thread's 'EvalBreak' and retry if none have yielded one yet
- foldr (\x next -> readStatus dbgs x `orElse` next) retry (Map.toList (threadEvalStatuses dbgs))
+ foldl' (\next ctx -> next `orElse` readBreak ctx) retry (Map.elems ctxs)
where
- readStatus GlobalDbgStatus{..} (tid, _) -- don't look at isolated threads
- | Set.member tid isolatedThreads
- = retry
-
- readStatus GlobalDbgStatus{..} (tid, status)
- = do
- case status of
- EvalComplete{} -> retry -- successes can be read with `readThreadEvalStatus`
- EvalPaused b -> do
- writeTVar globalDbgStatusVar
- GlobalDbgStatus
- { threadEvalStatuses = Map.delete tid threadEvalStatuses
- , isolatedThreads
- }
- pure b
+ readBreak ResumeContext{resumeEvalStatus, resumeIsolated} = do
+ isolated <- readTVar resumeIsolated
+ if isolated
+ then retry -- don't look at isolated threads
+ else readTVar resumeEvalStatus >>= \case
+ Just (EvalPaused b) -> do
+ writeTVar resumeEvalStatus Nothing
+ pure b
+ Just EvalComplete{} ->
+ retry -- successes can be read with `readThreadEvalStatus`
+ Nothing ->
+ retry -- no status for this thread yet
writeThreadEvalStatus :: ThreadId -> EvalStatus [HValueRef] -> IO ()
-writeThreadEvalStatus tid status =
+writeThreadEvalStatus tid status = do
+ -- get or create a 'ResumeContext' for the thread (e.g. we may write the
+ -- EvalComplete without breakpoints occurring, so the map won't have an entry):
+ ctx <- getThreadResumeContext tid
+ writeCtxEvalStatus ctx status
+
+-- | Like 'writeThreadEvalStatus', but for when the 'ResumeContext' is already
+-- available
+writeCtxEvalStatus :: ResumeContext -> EvalStatus [HValueRef] -> IO ()
+writeCtxEvalStatus ResumeContext{resumeEvalStatus} status =
atomically $ do
- GlobalDbgStatus{..} <- readTVar globalDbgStatusVar
- writeTVar globalDbgStatusVar $
- GlobalDbgStatus
- { threadEvalStatuses =
- Map.insertWith (\_ _ -> error "writeThreadEvalStatus: should be impossible")
- tid status threadEvalStatuses
- , isolatedThreads }
+ readTVar resumeEvalStatus >>= \case
+ Just{} -> error "writeCtxEvalStatus: should be impossible"
+ Nothing -> writeTVar resumeEvalStatus (Just status)
-- ** Isolating thread breakpoints ---------------------------------------------
@@ -174,23 +186,15 @@ withIsolatedThread tid = bracket_ (setIsolatedThread tid) (unsetIsolatedThread t
-- expression to run should not be seen at all by the debugger (e.g. when
-- evaluating an expr to :force a variable)
setIsolatedThread :: ThreadId -> IO ()
-setIsolatedThread tid = atomically $ do
- GlobalDbgStatus{..} <- readTVar globalDbgStatusVar
- writeTVar globalDbgStatusVar
- GlobalDbgStatus
- { threadEvalStatuses
- , isolatedThreads = Set.insert tid isolatedThreads
- }
+setIsolatedThread = getThreadResumeContext >=> setIsolatedCtx
-- | Undoes 'setIsolatedThread'
unsetIsolatedThread :: ThreadId -> IO ()
-unsetIsolatedThread tid = atomically $ do
- GlobalDbgStatus{..} <- readTVar globalDbgStatusVar
- writeTVar globalDbgStatusVar
- GlobalDbgStatus
- { threadEvalStatuses
- , isolatedThreads = Set.delete tid isolatedThreads
- }
+unsetIsolatedThread = getThreadResumeContext >=> unsetIsolatedCtx
+
+setIsolatedCtx, unsetIsolatedCtx :: ResumeContext -> IO ()
+setIsolatedCtx ctx = atomically $ writeTVar (resumeIsolated ctx) True
+unsetIsolatedCtx ctx = atomically $ writeTVar (resumeIsolated ctx) False
-- ** Querying the global thread breakpoint map --------------------------------
@@ -201,64 +205,74 @@ unsetIsolatedThread tid = atomically $ do
-- the global thread mapping) and are asking about which other threads are
-- paused to list them.
listOtherPausedThreads :: IO [ThreadId]
-listOtherPausedThreads = do
- m <- atomically $ readTVar globalDbgStatusVar
- pure $ Map.keys $ Map.filter isBreak (threadEvalStatuses m)
+listOtherPausedThreads = atomically $ do
+ ctxs <- readTVar threadContextsVar
+ paused <- mapM isBreak (Map.toList ctxs)
+ pure [tid | (tid, True) <- paused]
where
- isBreak EvalBreak{} = True
- isBreak EvalComplete{} = False
-
--- ** Global thread exec status map --------------------------------------------
-
--- | When we launch a new thread using the debugger, we map ... TODO ... all
--- threads launched by that main stmt may further spawn threads, and any of
--- them might hit a breakpoint (break array toggled, or per-thread step in
--- might be used, or pause button, etc...).
---
--- When we launch that main thread we also write its result to this map. So
--- this map will only contain the results of threads we explicitly care to
--- observe the result of. Not all threads will write their results here,
--- certainly not ones spawned unknowningly by the main stmt.
--- ...
--- todo words
-globalDbgStatusVar :: TVar GlobalDbgStatus
-globalDbgStatusVar = unsafePerformIO $ newTVarIO $ GlobalDbgStatus Map.empty Set.empty
-{-# NOINLINE globalDbgStatusVar #-}
-
-data GlobalDbgStatus = GlobalDbgStatus
- { threadEvalStatuses :: !(Map.Map ThreadId (EvalStatus [HValueRef]))
- -- ^ Whenever a thread hits a breakpoint it inserts in this map its 'EvalBreak'.
- -- We can additionally observe a thread's result by calling
- -- `writeThreadEvalStatus tid (EvalComplete ...)` when the main expression
- -- finishes evaluating, see e.g. 'sandboxIO'.
- , isolatedThreads :: !(Set.Set ThreadId)
- -- ^ Threads in this map are meant to be ignored by 'readAnyThreadEvalBreak'.
- -- That is, even if one of the threads in this set hits a breakpoint, we
- -- can only read its 'EvalBreak' with @'readThreadEvalStatus' tid@ directly.
- }
+ isBreak (tid, ResumeContext{resumeEvalStatus}) = do
+ status <- readTVar resumeEvalStatus
+ pure (tid, case status of
+ Just EvalBreak{} -> True
+ Just EvalComplete{} -> False
+ Nothing -> False)
--------------------------------------------------------------------------------
-- * Per-thread resume-ing
--------------------------------------------------------------------------------
getThreadResumeContext :: ThreadId -> IO ResumeContext
-getThreadResumeContext tid = modifyMVar globalBreakActionMap $ \gbm0 -> do
- case Map.lookup tid gbm0 of
+getThreadResumeContext tid = do
+ ctxs0 <- readTVarIO threadContextsVar
+ case Map.lookup tid ctxs0 of
+ Just ctx -> pure ctx -- common case: hence read without transaction
Nothing -> do
- r <- ResumeContext <$> newEmptyMVar
- let !gbm1 = Map.insert tid r gbm0
- pure (gbm1, r)
- Just ctx -> do
- pure (gbm0, ctx)
+ new_ctx <- ResumeContext <$> newEmptyMVar
+ <*> newTVarIO Nothing
+ <*> newTVarIO False
+ atomically $ do -- write new thread context atomically
+ ctxs1 <- readTVar threadContextsVar
+ case Map.lookup tid ctxs1 of
+ Just ctx -> pure ctx -- already exists
+ Nothing -> do
+ let !ctxs2 = Map.insert tid new_ctx ctxs1
+ writeTVar threadContextsVar ctxs2
+ pure new_ctx
--- | A global mapping from thread ids to the MVars on which they block when stopped.
-globalBreakActionMap :: MVar (Map.Map ThreadId ResumeContext)
-globalBreakActionMap = unsafePerformIO $ newMVar Map.empty
-{-# NOINLINE globalBreakActionMap #-}
+-- | A global mapping from threads to their per-thread state 'ResumeContext'
+-- (that e.g. contain the MVars on which they block when stopped)
+threadContextsVar :: TVar (Map.Map ThreadId ResumeContext)
+threadContextsVar = unsafePerformIO $ newTVarIO Map.empty
+{-# NOINLINE threadContextsVar #-}
-newtype ResumeContext = ResumeContext
- { resumeBreakMVar :: MVar ()
+-- | Global context for a thread, which is created and inserted in the global
+-- 'threadContextsVar' when a thread hits a breakpoint (and, thus, the
+-- 'globalBreakAction') is run, or when 'withBreakAction' sets the thread
+-- isolation (e.g. in 'sandboxIO'), or in other calls to
+-- 'getThreadResumeContext', the function which gets or creates a thread
+-- 'ResumeContext'.
+--
+-- TODO: Rename ResumeContext to something like ThreadContext or
+-- ThreadDbgContext or (Thread)BreakContext, and fields to something like
+-- dbgEvalStatus, threadIsolated, ...
+data ResumeContext = ResumeContext
+ { resumeBreakMVar :: !(MVar ())
-- ^ A thread that hits a breakpoint blocks reading its corresponding MVar
- -- (gotten from the 'globalBreakActionMap').
+ -- (gotten from the 'threadContextsVar').
-- The debugger can unblock that thread by signaling its MVar.
+ , resumeEvalStatus :: !(TVar (Maybe (EvalStatus [HValueRef])))
+ -- ^ When a thread hits a breakpoint, the 'globalBreakAction' is run and
+ -- writes an 'EvalBreak' in this @TVar@ (which was found in 'threadContextsVar').
+ --
+ -- Additionally, the 'EvalComplete' result of a thread may be written here
+ -- using `writeThreadEvalStatus tid (EvalComplete ...)` after the main
+ -- expression finishes evaluating, see e.g. 'sandboxIO'.
+ --
+ -- The variable should be emptied (i.e. set to 'Nothing') by whoever
+ -- reads the status.
+ , resumeIsolated :: !(TVar Bool)
+ -- ^ When set, this thread is meant to be ignored by 'readAnyThreadEvalBreak'.
+ -- That is, if a thread with resumeIsolated=True hits a breakpoint, its
+ -- 'EvalBreak' can only be read with @'readThreadEvalStatus' tid@ for this
+ -- thread's @tid@ directly.
}
=====================================
libraries/ghci/GHCi/Server.hs
=====================================
@@ -70,6 +70,14 @@ servWithCustom verbose hook pipe restore customHandler = loop
when verbose $ trace ("msg: " ++ (show msg))
case msg of
+ -- The expressions which block waiting for a result musn't block the
+ -- server thread, so send them off and notify over the wire when done.
+ --
+ -- The other end (see 'remoteCall') will be processing notifications, and
+ -- it will use the returned pointer as the index for the matching notification.
+ WaitThreadResult {} -> forkIO (run msg >>= (notification =<< myThreadId)) >>= reply . mkRemoteRef
+ WaitAnyThreadBreak {} -> forkIO (run msg >>= (notification =<< myThreadId)) >>= reply . mkRemoteRef
+ WaitThreadResultOrAnyThreadBreak {} -> forkIO (run msg >>= (notification =<< myThreadId)) >>= reply . mkRemoteRef
CustomMessage tag payload -> handleCustom tag payload
Shutdown -> return ()
RunTH st q ty loc -> wrapRunTH $ runTH pipe st q ty loc
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/64836f8c2dc5ec9cde23253cf1407d…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/64836f8c2dc5ec9cde23253cf1407d…
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][master] [CLC 341] Strict variants of mutable types
by Marge Bot (@marge-bot) 05 Oct '26
by Marge Bot (@marge-bot) 05 Oct '26
05 Oct '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
f8cfb1a5 by Hécate Kleidukos at 2026-10-04T19:36:39+02:00
[CLC 341] Strict variants of mutable types
This commit is the implementation of CLC Proposal 341
https://github.com/haskell/core-libraries-committee/issues/341
- - - - -
12 changed files:
- + changelog.d/clc-341-strict-mutable-data-types
- libraries/base/base.cabal.in
- libraries/base/changelog.md
- libraries/base/src/Control/Concurrent/Chan.hs
- + libraries/base/src/Control/Concurrent/Chan/Strict.hs
- libraries/base/src/Control/Concurrent/MVar.hs
- + libraries/base/src/Control/Concurrent/MVar/Strict.hs
- libraries/base/src/Data/IORef.hs
- + libraries/base/src/Data/IORef/Strict.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
Changes:
=====================================
changelog.d/clc-341-strict-mutable-data-types
=====================================
@@ -0,0 +1,9 @@
+section: base
+synopsis: Add strict variants to mutable types (IORef, Chan, MVar)
+issues: #27343
+mrs: !15450
+
+description: {
+ These new types prevent users from (easily) mis-using existing and dangerous APIs (writeIORef, modifyIORef, modifyMVar, etc) which can lead to space leaks when stored in mutable containers.
+ They also prevent invisible coercions to and from their lazy equivalents by not exposing their constructors.
+}
=====================================
libraries/base/base.cabal.in
=====================================
@@ -41,6 +41,7 @@ Library
Control.Applicative
, Control.Concurrent
, Control.Concurrent.Chan
+ , Control.Concurrent.Chan.Strict
, Control.Concurrent.QSem
, Control.Concurrent.QSemN
, Control.Monad.IO.Class
@@ -80,6 +81,7 @@ Library
, Control.Arrow
, Control.Category
, Control.Concurrent.MVar
+ , Control.Concurrent.MVar.Strict
, Control.Exception
, Control.Exception.Annotation
, Control.Exception.Backtrace
@@ -109,6 +111,7 @@ Library
, Data.Functor.Const
, Data.Functor.Identity
, Data.IORef
+ , Data.IORef.Strict
, Data.Int
, Data.Ix
, Data.Kind
=====================================
libraries/base/changelog.md
=====================================
@@ -12,6 +12,7 @@
* Add `withEmptyCallStack` to `GHC.Stack`. ([CLC proposal #428](https://github.com/haskell/core-libraries-committee/issues/428))
* Add new `Data.RealFloat` module re-exporting `RealFloat` from `GHC.Float` ([CLC proposal #394](https://github.com/haskell/core-libraries-committee/issues/394))
* Add `Infinity`, `NegInfinity`, and `NaN` pattern synonyms to `Data.RealFloat` ([CLC proposal #394](https://github.com/haskell/core-libraries-committee/issues/394))
+ * Add strict variants to mutable types (IORef, Chan, MVar). ([CLC Proposal #341](https://github.com/haskell/core-libraries-committee/issues/341))
## 4.23.0.0 *TBA*
* Add `System.IO.hGetNewlineMode`. ([CLC proposal #370](https://github.com/haskell/core-libraries-committee/issues/370))
=====================================
libraries/base/src/Control/Concurrent/Chan.hs
=====================================
@@ -18,6 +18,8 @@
-- @stm@ (software transactional memory) library has a more robust implementation
-- of channels called @TChan@s.
--
+-- A variant that forces its contents to weak head normal form is available in
+-- "Control.Concurrent.Chan.Strict".
-----------------------------------------------------------------------------
module Control.Concurrent.Chan
=====================================
libraries/base/src/Control/Concurrent/Chan/Strict.hs
=====================================
@@ -0,0 +1,81 @@
+-- | Unbounded channels whose contents are always in weak head normal form
+-- (WHNF).
+--
+-- This module is a thin wrapper around "Control.Concurrent.Chan": each
+-- operation has the same semantics as its counterpart there, except that the
+-- value written to the channel is forced to WHNF first.
+-- "Control.Concurrent.Chan" is the reference documentation for these
+-- operations; only the differences are repeated here.
+--
+-- The caveats of the lazy module apply unchanged. In particular a 'Chan' is
+-- /unbounded/: a producer that outruns its consumer makes the channel grow
+-- without limit. The @stm@ package offers channels with a different
+-- concurrency model, and @TBQueue@ in particular is bounded.
+--
+-- Note that WHNF is not deep: writing @Just <thunk>@ to a
+-- @'Chan' (Maybe a)@ still writes a thunk inside the @Just@.
+module Control.Concurrent.Chan.Strict
+ ( Chan
+
+ -- * Operations
+ , newChan
+ , writeChan
+ , readChan
+ , dupChan
+ , getChanContents
+ , writeList2Chan
+ ) where
+
+import Data.Foldable (mapM_)
+import Data.Functor
+import GHC.Base
+import qualified Control.Concurrent.Chan as Lazy
+
+-- | An unbounded FIFO channel, wrapping @Chan@ from "Control.Concurrent.Chan".
+--
+-- The values it holds are always in WHNF: every operation of this module forces
+-- a value before it is written.
+newtype Chan a = Chan (Lazy.Chan a)
+ deriving Eq
+
+-- | Build and return a new instance of 'Chan'.
+--
+-- See @newChan@ in "Control.Concurrent.Chan" for the full semantics.
+newChan :: IO (Chan a)
+newChan = Chan <$> Lazy.newChan
+
+-- | Write a value to a 'Chan'.
+--
+-- See @writeChan@ in "Control.Concurrent.Chan" for the full semantics.
+--
+-- The value is forced to WHNF before it is written.
+writeChan :: Chan a -> a -> IO ()
+writeChan (Chan chan) a = Lazy.writeChan chan =<< (pure $! a)
+
+-- | Read the next value from the 'Chan'. Blocks when the channel is empty.
+--
+-- See @readChan@ in "Control.Concurrent.Chan" for the full semantics, in
+-- particular for the fairness guarantees and for the
+-- 'Control.Exception.BlockedIndefinitelyOnMVar' exception.
+readChan :: Chan a -> IO a
+readChan (Chan chan) = Lazy.readChan chan
+
+-- | Duplicate a 'Chan'.
+--
+-- See @dupChan@ in "Control.Concurrent.Chan" for the full semantics.
+dupChan :: Chan a -> IO (Chan a)
+dupChan (Chan chan) = Chan <$> Lazy.dupChan chan
+
+-- | Return a lazy list representing the contents of the supplied 'Chan'.
+--
+-- See @getChanContents@ in "Control.Concurrent.Chan" for the full semantics.
+getChanContents :: Chan a -> IO [a]
+getChanContents (Chan chan) = Lazy.getChanContents chan
+
+-- | Write an entire list of items to a 'Chan'.
+--
+-- See @writeList2Chan@ in "Control.Concurrent.Chan" for the full semantics.
+--
+-- Evaluates the list elements to WHNF.
+writeList2Chan :: Chan a -> [a] -> IO ()
+writeList2Chan = mapM_ . writeChan
=====================================
libraries/base/src/Control/Concurrent/MVar.hs
=====================================
@@ -65,6 +65,11 @@
-- in an 'MVar' to the appropriate normal form, or utilize a strict
-- @MVar@ provided by the [strict-concurrency](https://hackage.haskell.org/package/strict-concurrency) package.
--
+-- A variant that forces its contents to weak head normal form is available in
+-- "Control.Concurrent.MVar.Strict". Note that weak head normal form is often
+-- not the appropriate normal form: it does not force the fields of the
+-- constructor it exposes.
+--
-- === Ordering
--
-- 'MVar' operations are always observed to take place in the order
=====================================
libraries/base/src/Control/Concurrent/MVar/Strict.hs
=====================================
@@ -0,0 +1,202 @@
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE TupleSections #-}
+
+-- | Synchronising variables whose contents are always in weak head normal form
+-- (WHNF).
+--
+-- This module is a thin wrapper around "Control.Concurrent.MVar": each
+-- operation has the same semantics as its counterpart there, except that the
+-- value put in the variable is forced to WHNF first.
+-- "Control.Concurrent.MVar" is the reference documentation for these
+-- operations — for the fairness and ordering guarantees, for the atomicity
+-- caveats of the \"bigger\" functions, and for worked examples; only the
+-- differences are repeated here.
+--
+-- Note that WHNF is not deep: putting @Just <thunk>@ in an
+-- @'MVar' (Maybe a)@ still puts a thunk inside the @Just@.
+
+module Control.Concurrent.MVar.Strict
+ ( MVar
+
+ -- * Operations
+ , newEmptyMVar
+ , newMVar
+ , takeMVar
+ , putMVar
+ , readMVar
+ , swapMVar
+ , tryTakeMVar
+ , tryPutMVar
+ , tryReadMVar
+ , isEmptyMVar
+ , withMVar
+ , withMVarMasked
+ , modifyMVar_
+ , modifyMVar
+ , modifyMVarMasked_
+ , modifyMVarMasked
+ , mkWeakMVar
+ ) where
+
+import Data.Functor
+import GHC.Base
+import GHC.Weak (Weak)
+import qualified Control.Concurrent.MVar as Lazy
+
+-- | A synchronising variable, wrapping @MVar@ from "Control.Concurrent.MVar".
+-- It can be thought of as a box, which may be empty or full.
+--
+-- The value it holds is always in WHNF: every operation of this module forces
+-- the value before it is put in the box.
+newtype MVar a = MVar (Lazy.MVar a)
+ deriving stock (Eq)
+
+-- | Create an 'MVar' which is initially empty.
+--
+-- See @newEmptyMVar@ in "Control.Concurrent.MVar" for the full semantics.
+newEmptyMVar :: IO (MVar a)
+newEmptyMVar = MVar <$> Lazy.newEmptyMVar
+
+-- | Create an 'MVar' which contains the supplied value.
+--
+-- See @newMVar@ in "Control.Concurrent.MVar" for the full semantics.
+--
+-- The initial value is forced to WHNF before it is stored.
+newMVar :: a -> IO (MVar a)
+newMVar a = fmap MVar . Lazy.newMVar =<< (pure $! a)
+
+-- | Return the contents of the 'MVar', leaving it empty. Blocks while the
+-- 'MVar' is empty.
+--
+-- See @takeMVar@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for the single-wakeup and FIFO guarantees.
+takeMVar :: MVar a -> IO a
+takeMVar (MVar var) = Lazy.takeMVar var
+
+-- | Atomically read the contents of an 'MVar'. Blocks while the 'MVar' is
+-- empty.
+--
+-- See @readMVar@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for the multiple-wakeup guarantee.
+readMVar :: MVar a -> IO a
+readMVar (MVar var) = Lazy.readMVar var
+
+-- | Put a value into an 'MVar'. Blocks while the 'MVar' is full.
+--
+-- See @putMVar@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for the single-wakeup and FIFO guarantees.
+--
+-- The value is forced to WHNF before it is put.
+putMVar :: MVar a -> a -> IO ()
+putMVar (MVar var) a = Lazy.putMVar var =<< (pure $! a)
+
+-- | A non-blocking version of 'takeMVar'.
+--
+-- See @tryTakeMVar@ in "Control.Concurrent.MVar" for the full semantics.
+tryTakeMVar :: MVar a -> IO (Maybe a)
+tryTakeMVar (MVar var) = Lazy.tryTakeMVar var
+
+-- | A non-blocking version of 'putMVar'.
+--
+-- See @tryPutMVar@ in "Control.Concurrent.MVar" for the full semantics.
+--
+-- The value is forced to WHNF before it is put. Note that it is forced whether
+-- or not the 'MVar' turns out to be empty.
+tryPutMVar :: MVar a -> a -> IO Bool
+tryPutMVar (MVar var) a = Lazy.tryPutMVar var =<< (pure $! a)
+
+-- | Take a value from an 'MVar', put a new value into the 'MVar' and return the
+-- value taken.
+--
+-- See @swapMVar@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for its atomicity caveat.
+--
+-- The new value is forced to WHNF before it is put.
+swapMVar :: MVar a -> a -> IO a
+swapMVar (MVar var) a = Lazy.swapMVar var =<< (pure $! a)
+
+-- | A non-blocking version of 'readMVar'.
+--
+-- See @tryReadMVar@ in "Control.Concurrent.MVar" for the full semantics.
+tryReadMVar :: MVar a -> IO (Maybe a)
+tryReadMVar (MVar var) = Lazy.tryReadMVar var
+
+-- | Check whether a given 'MVar' is empty.
+--
+-- See @isEmptyMVar@ in "Control.Concurrent.MVar" for the full semantics. The
+-- result is only a snapshot, so prefer 'tryTakeMVar' where possible.
+isEmptyMVar :: MVar a -> IO Bool
+isEmptyMVar (MVar var) = Lazy.isEmptyMVar var
+
+-- | An exception-safe wrapper for operating on the contents of an 'MVar'.
+--
+-- See @withMVar@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for its atomicity caveat.
+withMVar :: MVar a -> (a -> IO b) -> IO b
+withMVar (MVar var) action = Lazy.withMVar var action
+{-# INLINE withMVar #-}
+
+-- | Like 'withMVar', but the @IO@ action in the second argument is executed
+-- with asynchronous exceptions masked.
+--
+-- See @withMVarMasked@ in "Control.Concurrent.MVar" for the full semantics.
+withMVarMasked :: MVar a -> (a -> IO b) -> IO b
+withMVarMasked (MVar var) action = Lazy.withMVarMasked var action
+{-# INLINE withMVarMasked #-}
+
+-- | An exception-safe wrapper for modifying the contents of an 'MVar'.
+--
+-- See @modifyMVar_@ in "Control.Concurrent.MVar" for the full semantics, in
+-- particular for its atomicity caveat.
+--
+-- The new value is forced to WHNF before it is put back.
+modifyMVar_ :: MVar a -> (a -> IO a) -> IO ()
+modifyMVar_ (MVar var) action = Lazy.modifyMVar_ var $ \a0 -> do
+ a <- action a0
+ pure $! a
+{-# INLINE modifyMVar_ #-}
+
+-- | A slight variation on 'modifyMVar_' that allows a value to be returned
+-- (@b@) in addition to the modified value of the 'MVar'.
+--
+-- See @modifyMVar@ in "Control.Concurrent.MVar" for the full semantics.
+--
+-- The new value is forced to WHNF before it is put back. The returned value is
+-- not forced.
+modifyMVar :: MVar a -> (a -> IO (a, b)) -> IO b
+modifyMVar (MVar var) action = Lazy.modifyMVar var $ \a0 -> do
+ (a, b) <- action a0
+ (, b) <$> (pure $! a)
+{-# INLINE modifyMVar #-}
+
+-- | Like 'modifyMVar_', but the @IO@ action in the second argument is executed
+-- with asynchronous exceptions masked.
+--
+-- See @modifyMVarMasked_@ in "Control.Concurrent.MVar" for the full semantics.
+--
+-- The new value is forced to WHNF before it is put back.
+modifyMVarMasked_ :: MVar a -> (a -> IO a) -> IO ()
+modifyMVarMasked_ (MVar var) action = Lazy.modifyMVarMasked_ var $ \a0 -> do
+ a <- action a0
+ pure $! a
+{-# INLINE modifyMVarMasked_ #-}
+
+-- | Like 'modifyMVar', but the @IO@ action in the second argument is executed
+-- with asynchronous exceptions masked.
+--
+-- See @modifyMVarMasked@ in "Control.Concurrent.MVar" for the full semantics.
+--
+-- The new value is forced to WHNF before it is put back. The returned value is
+-- not forced.
+modifyMVarMasked :: MVar a -> (a -> IO (a, b)) -> IO b
+modifyMVarMasked (MVar var) action = Lazy.modifyMVarMasked var $ \a0 -> do
+ (a, b) <- action a0
+ (, b) <$> (pure $! a)
+{-# INLINE modifyMVarMasked #-}
+
+-- | Make a 'Weak' pointer to an 'MVar', using the second argument as a
+-- finalizer to run when the 'MVar' is garbage-collected.
+--
+-- See @mkWeakMVar@ in "Control.Concurrent.MVar" for the full semantics.
+mkWeakMVar :: MVar a -> IO () -> IO (Weak (MVar a))
+mkWeakMVar (MVar var) finalizer = coerce <$> Lazy.mkWeakMVar var finalizer
=====================================
libraries/base/src/Data/IORef.hs
=====================================
@@ -12,6 +12,8 @@
--
-- Mutable references in the IO monad.
--
+-- A variant that forces its contents to weak head normal form is available in
+-- "Data.IORef.Strict".
module Data.IORef
(-- * IORefs
=====================================
libraries/base/src/Data/IORef/Strict.hs
=====================================
@@ -0,0 +1,93 @@
+{-# LANGUAGE DerivingStrategies #-}
+
+-- | Mutable references in the IO monad whose contents are always in weak head
+-- normal form (WHNF).
+--
+-- This module is a thin wrapper around "Data.IORef": each operation has the
+-- same semantics as its counterpart there, except that the value put in the
+-- reference is forced to WHNF first. "Data.IORef" is the reference
+-- documentation for these operations; only the differences are repeated here.
+--
+-- Note that WHNF is not deep: storing @Just <thunk>@ in an
+-- @'IORef' (Maybe a)@ still stores a thunk inside the @Just@.
+
+module Data.IORef.Strict
+ ( IORef
+
+ -- * Operations
+ , newIORef
+ , readIORef
+ , writeIORef
+ , modifyIORef
+ , atomicModifyIORef
+ , atomicWriteIORef
+ , mkWeakIORef
+ ) where
+
+import GHC.Base
+import GHC.Weak (Weak)
+import qualified Data.IORef as Lazy
+
+-- | A mutable reference in the IO monad, wrapping @IORef@ from "Data.IORef".
+--
+-- The value it holds is always in WHNF: every operation of this module forces
+-- the value before it is written.
+newtype IORef a = IORef (Lazy.IORef a)
+ deriving stock (Eq)
+
+-- | Build a new 'IORef'.
+--
+-- See @newIORef@ in "Data.IORef" for the full semantics.
+--
+-- The initial value is forced to WHNF before it is stored.
+newIORef :: a -> IO (IORef a)
+newIORef a = fmap IORef . Lazy.newIORef =<< (pure $! a)
+
+-- | Read the value of an 'IORef'.
+--
+-- See @readIORef@ in "Data.IORef" for the full semantics, in particular for the
+-- memory model that applies to reads and writes.
+readIORef :: IORef a -> IO a
+readIORef (IORef var) = Lazy.readIORef var
+
+-- | Write a new value into an 'IORef'.
+--
+-- See @writeIORef@ in "Data.IORef" for the full semantics. This function does
+-- not create a memory barrier; use 'atomicWriteIORef' when that matters.
+--
+-- The new value is forced to WHNF before it is stored.
+writeIORef :: IORef a -> a -> IO ()
+writeIORef (IORef var) a = Lazy.writeIORef var =<< (pure $! a)
+
+-- | Mutate the contents of an 'IORef', combining 'readIORef' and 'writeIORef'.
+--
+-- See @modifyIORef@ in "Data.IORef" for the full semantics. This is not an
+-- atomic update; use 'atomicModifyIORef' in a multithreaded environment.
+--
+-- The new value is forced to WHNF before it is stored.
+modifyIORef :: IORef a -> (a -> a) -> IO ()
+modifyIORef (IORef var) f = Lazy.modifyIORef' var f
+
+-- | Atomically modify the contents of an 'IORef'.
+--
+-- See @atomicModifyIORef@ in "Data.IORef" for the full semantics, in particular
+-- for the atomicity and memory-barrier guarantees.
+--
+-- Both the new value and the returned value are forced to WHNF.
+atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b
+atomicModifyIORef (IORef var) f = Lazy.atomicModifyIORef' var f
+
+-- | Variant of 'writeIORef' that imposes a reordering barrier.
+--
+-- See @atomicWriteIORef@ in "Data.IORef" for the full semantics.
+--
+-- The new value is forced to WHNF before it is stored.
+atomicWriteIORef :: IORef a -> a -> IO ()
+atomicWriteIORef (IORef var) a = Lazy.atomicWriteIORef var =<< (pure $! a)
+
+-- | Make a 'Weak' pointer to an 'IORef', using the second argument as a
+-- finalizer to run when the 'IORef' is garbage-collected.
+--
+-- See @mkWeakIORef@ in "Data.IORef" for the full semantics.
+mkWeakIORef :: IORef a -> IO () -> IO (Weak (IORef a))
+mkWeakIORef (IORef var) finalizer = fmap coerce (Lazy.mkWeakIORef var finalizer)
=====================================
testsuite/tests/interface-stability/base-exports.stdout
=====================================
@@ -173,6 +173,17 @@ module Control.Concurrent.Chan where
writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+module Control.Concurrent.Chan.Strict where
+ -- Safety: None
+ type Chan :: * -> *
+ newtype Chan a = ...
+ dupChan :: forall a. Chan a -> GHC.Internal.Types.IO (Chan a)
+ getChanContents :: forall a. Chan a -> GHC.Internal.Types.IO [a]
+ newChan :: forall a. GHC.Internal.Types.IO (Chan a)
+ readChan :: forall a. Chan a -> GHC.Internal.Types.IO a
+ writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
+ writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+
module Control.Concurrent.MVar where
-- Safety: Safe
type MVar :: * -> *
@@ -196,6 +207,28 @@ module Control.Concurrent.MVar where
withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+module Control.Concurrent.MVar.Strict where
+ -- Safety: None
+ type MVar :: * -> *
+ newtype MVar a = ...
+ isEmptyMVar :: forall a. MVar a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ mkWeakMVar :: forall a. MVar a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (MVar a))
+ modifyMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ modifyMVar_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ newEmptyMVar :: forall a. GHC.Internal.Types.IO (MVar a)
+ newMVar :: forall a. a -> GHC.Internal.Types.IO (MVar a)
+ putMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO ()
+ readMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ swapMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO a
+ takeMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ tryPutMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ tryReadMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ tryTakeMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+ withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+
module Control.Concurrent.QSem where
-- Safety: Safe
type QSem :: *
@@ -1286,6 +1319,18 @@ module Data.IORef where
readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+module Data.IORef.Strict where
+ -- Safety: None
+ type IORef :: * -> *
+ newtype IORef a = ...
+ atomicModifyIORef :: forall a b. IORef a -> (a -> (a, b)) -> GHC.Internal.Types.IO b
+ atomicWriteIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+ mkWeakIORef :: forall a. IORef a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (IORef a))
+ modifyIORef :: forall a. IORef a -> (a -> a) -> GHC.Internal.Types.IO ()
+ newIORef :: forall a. a -> GHC.Internal.Types.IO (IORef a)
+ readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
+ writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+
module Data.Int where
-- Safety: Safe
type Int :: *
@@ -11232,6 +11277,8 @@ instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.MVar.MVar a) -- Defined
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.BlockReason -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadId -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadStatus -- Defined in ‘GHC.Internal.Conc.Sync’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.Chan.Strict.Chan a) -- Defined in ‘Control.Concurrent.Chan.Strict’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.MVar.Strict.MVar a) -- Defined in ‘Control.Concurrent.MVar.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ArrayException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.AsyncException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ExitCode -- Defined in ‘GHC.Internal.IO.Exception’
@@ -11291,6 +11338,7 @@ instance forall a. GHC.Internal.Classes.Eq a => GHC.Internal.Classes.Eq (GHC.Int
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Product.Product f g a) -- Defined in ‘Data.Functor.Product’
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Sum.Sum f g a) -- Defined in ‘Data.Functor.Sum’
instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.IORef.IORef a) -- Defined in ‘GHC.Internal.IORef’
+instance forall a. GHC.Internal.Classes.Eq (Data.IORef.Strict.IORef a) -- Defined in ‘Data.IORef.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int16 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int32 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int64 -- Defined in ‘GHC.Internal.Int’
=====================================
testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
=====================================
@@ -173,6 +173,17 @@ module Control.Concurrent.Chan where
writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+module Control.Concurrent.Chan.Strict where
+ -- Safety: None
+ type Chan :: * -> *
+ newtype Chan a = ...
+ dupChan :: forall a. Chan a -> GHC.Internal.Types.IO (Chan a)
+ getChanContents :: forall a. Chan a -> GHC.Internal.Types.IO [a]
+ newChan :: forall a. GHC.Internal.Types.IO (Chan a)
+ readChan :: forall a. Chan a -> GHC.Internal.Types.IO a
+ writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
+ writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+
module Control.Concurrent.MVar where
-- Safety: Safe
type MVar :: * -> *
@@ -196,6 +207,28 @@ module Control.Concurrent.MVar where
withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+module Control.Concurrent.MVar.Strict where
+ -- Safety: None
+ type MVar :: * -> *
+ newtype MVar a = ...
+ isEmptyMVar :: forall a. MVar a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ mkWeakMVar :: forall a. MVar a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (MVar a))
+ modifyMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ modifyMVar_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ newEmptyMVar :: forall a. GHC.Internal.Types.IO (MVar a)
+ newMVar :: forall a. a -> GHC.Internal.Types.IO (MVar a)
+ putMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO ()
+ readMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ swapMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO a
+ takeMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ tryPutMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ tryReadMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ tryTakeMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+ withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+
module Control.Concurrent.QSem where
-- Safety: Safe
type QSem :: *
@@ -1286,6 +1319,18 @@ module Data.IORef where
readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+module Data.IORef.Strict where
+ -- Safety: None
+ type IORef :: * -> *
+ newtype IORef a = ...
+ atomicModifyIORef :: forall a b. IORef a -> (a -> (a, b)) -> GHC.Internal.Types.IO b
+ atomicWriteIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+ mkWeakIORef :: forall a. IORef a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (IORef a))
+ modifyIORef :: forall a. IORef a -> (a -> a) -> GHC.Internal.Types.IO ()
+ newIORef :: forall a. a -> GHC.Internal.Types.IO (IORef a)
+ readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
+ writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+
module Data.Int where
-- Safety: Safe
type Int :: *
@@ -11264,6 +11309,8 @@ instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.MVar.MVar a) -- Defined
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.BlockReason -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadId -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadStatus -- Defined in ‘GHC.Internal.Conc.Sync’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.Chan.Strict.Chan a) -- Defined in ‘Control.Concurrent.Chan.Strict’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.MVar.Strict.MVar a) -- Defined in ‘Control.Concurrent.MVar.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ArrayException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.AsyncException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ExitCode -- Defined in ‘GHC.Internal.IO.Exception’
@@ -11323,6 +11370,7 @@ instance forall a. GHC.Internal.Classes.Eq a => GHC.Internal.Classes.Eq (GHC.Int
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Product.Product f g a) -- Defined in ‘Data.Functor.Product’
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Sum.Sum f g a) -- Defined in ‘Data.Functor.Sum’
instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.IORef.IORef a) -- Defined in ‘GHC.Internal.IORef’
+instance forall a. GHC.Internal.Classes.Eq (Data.IORef.Strict.IORef a) -- Defined in ‘Data.IORef.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int16 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int32 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int64 -- Defined in ‘GHC.Internal.Int’
=====================================
testsuite/tests/interface-stability/base-exports.stdout-mingw32
=====================================
@@ -173,6 +173,17 @@ module Control.Concurrent.Chan where
writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+module Control.Concurrent.Chan.Strict where
+ -- Safety: None
+ type Chan :: * -> *
+ newtype Chan a = ...
+ dupChan :: forall a. Chan a -> GHC.Internal.Types.IO (Chan a)
+ getChanContents :: forall a. Chan a -> GHC.Internal.Types.IO [a]
+ newChan :: forall a. GHC.Internal.Types.IO (Chan a)
+ readChan :: forall a. Chan a -> GHC.Internal.Types.IO a
+ writeChan :: forall a. Chan a -> a -> GHC.Internal.Types.IO ()
+ writeList2Chan :: forall a. Chan a -> [a] -> GHC.Internal.Types.IO ()
+
module Control.Concurrent.MVar where
-- Safety: Safe
type MVar :: * -> *
@@ -196,6 +207,28 @@ module Control.Concurrent.MVar where
withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+module Control.Concurrent.MVar.Strict where
+ -- Safety: None
+ type MVar :: * -> *
+ newtype MVar a = ...
+ isEmptyMVar :: forall a. MVar a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ mkWeakMVar :: forall a. MVar a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (MVar a))
+ modifyMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO (a, b)) -> GHC.Internal.Types.IO b
+ modifyMVarMasked_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ modifyMVar_ :: forall a. MVar a -> (a -> GHC.Internal.Types.IO a) -> GHC.Internal.Types.IO ()
+ newEmptyMVar :: forall a. GHC.Internal.Types.IO (MVar a)
+ newMVar :: forall a. a -> GHC.Internal.Types.IO (MVar a)
+ putMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO ()
+ readMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ swapMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO a
+ takeMVar :: forall a. MVar a -> GHC.Internal.Types.IO a
+ tryPutMVar :: forall a. MVar a -> a -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
+ tryReadMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ tryTakeMVar :: forall a. MVar a -> GHC.Internal.Types.IO (GHC.Internal.Maybe.Maybe a)
+ withMVar :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+ withMVarMasked :: forall a b. MVar a -> (a -> GHC.Internal.Types.IO b) -> GHC.Internal.Types.IO b
+
module Control.Concurrent.QSem where
-- Safety: Safe
type QSem :: *
@@ -1286,6 +1319,18 @@ module Data.IORef where
readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+module Data.IORef.Strict where
+ -- Safety: None
+ type IORef :: * -> *
+ newtype IORef a = ...
+ atomicModifyIORef :: forall a b. IORef a -> (a -> (a, b)) -> GHC.Internal.Types.IO b
+ atomicWriteIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+ mkWeakIORef :: forall a. IORef a -> GHC.Internal.Types.IO () -> GHC.Internal.Types.IO (GHC.Internal.Weak.Weak (IORef a))
+ modifyIORef :: forall a. IORef a -> (a -> a) -> GHC.Internal.Types.IO ()
+ newIORef :: forall a. a -> GHC.Internal.Types.IO (IORef a)
+ readIORef :: forall a. IORef a -> GHC.Internal.Types.IO a
+ writeIORef :: forall a. IORef a -> a -> GHC.Internal.Types.IO ()
+
module Data.Int where
-- Safety: Safe
type Int :: *
@@ -11490,6 +11535,8 @@ instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.MVar.MVar a) -- Defined
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.BlockReason -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadId -- Defined in ‘GHC.Internal.Conc.Sync’
instance GHC.Internal.Classes.Eq GHC.Internal.Conc.Sync.ThreadStatus -- Defined in ‘GHC.Internal.Conc.Sync’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.Chan.Strict.Chan a) -- Defined in ‘Control.Concurrent.Chan.Strict’
+instance forall a. GHC.Internal.Classes.Eq (Control.Concurrent.MVar.Strict.MVar a) -- Defined in ‘Control.Concurrent.MVar.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ArrayException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.AsyncException -- Defined in ‘GHC.Internal.IO.Exception’
instance GHC.Internal.Classes.Eq GHC.Internal.IO.Exception.ExitCode -- Defined in ‘GHC.Internal.IO.Exception’
@@ -11549,6 +11596,7 @@ instance forall a. GHC.Internal.Classes.Eq a => GHC.Internal.Classes.Eq (GHC.Int
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Product.Product f g a) -- Defined in ‘Data.Functor.Product’
instance [safe] forall k (f :: k -> *) (a :: k) (g :: k -> *). (GHC.Internal.Classes.Eq (f a), GHC.Internal.Classes.Eq (g a)) => GHC.Internal.Classes.Eq (Data.Functor.Sum.Sum f g a) -- Defined in ‘Data.Functor.Sum’
instance forall a. GHC.Internal.Classes.Eq (GHC.Internal.IORef.IORef a) -- Defined in ‘GHC.Internal.IORef’
+instance forall a. GHC.Internal.Classes.Eq (Data.IORef.Strict.IORef a) -- Defined in ‘Data.IORef.Strict’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int16 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int32 -- Defined in ‘GHC.Internal.Int’
instance GHC.Internal.Classes.Eq GHC.Internal.Int.Int64 -- Defined in ‘GHC.Internal.Int’
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f8cfb1a5eed7fce615b42bd783631c0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f8cfb1a5eed7fce615b42bd783631c0…
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][master] ttg: HsModuleName in the AST, ModuleName in GHC
by Marge Bot (@marge-bot) 05 Oct '26
by Marge Bot (@marge-bot) 05 Oct '26
05 Oct '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
575c4bc6 by Rodrigo Mesquita at 2026-10-05T12:32:02-04:00
ttg: HsModuleName in the AST, ModuleName in GHC
This commit makes the AST fully independent from GHC by parsing a
"module name" as an `HsModuleName (= HText)` rather than constructing an
`ModuleName (= FastString)` straight away.
In the GHC side, everything remains as a `ModuleName`. We turn AST
`HsModuleName`s into fast strings with the cheap `mkFastStringShortText`
when we process the AST for manipulation within the compiler.
There are no performance regressions introduced by this approach.
This is the final piece of #21592
Alternative plans were discussed in
gitlab.haskell.org/ghc/ghc/-/merge_requests/16546#note_694647,
but the Simon suggested one won in simplicity and performance when
compared against my attempt at implementing my original plan of having
a family `ModuleNameP`.
- - - - -
90 changed files:
- compiler/GHC.hs
- compiler/GHC/Builtin/Modules.hs
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Show.hs
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/Opt/CallerCC/Types.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Pipeline.hs-boot
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Driver/Pipeline/Phases.hs
- compiler/GHC/Hs/Doc.hs
- compiler/GHC/Hs/Dump.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/HsToCore/Docs.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Iface/Ext/Debug.hs
- compiler/GHC/Iface/Ext/Types.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/String.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/StgToJS/Linker/Linker.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Unique.hs
- compiler/GHC/Types/UnresolvedImport.hs
- compiler/GHC/Unit/Home.hs
- compiler/GHC/Unit/Module.hs
- compiler/GHC/Unit/Module/Env.hs
- + compiler/GHC/Unit/Module/Name.hs
- compiler/GHC/Unit/Parser.hs
- compiler/GHC/Unit/Types.hs
- compiler/GHC/Unit/Types.hs-boot
- compiler/GHC/Utils/Binary.hs
- compiler/GHC/Utils/Outputable.hs
- compiler/Language/Haskell/Syntax.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/Language/Haskell/Syntax/ImpExp.hs
- compiler/Language/Haskell/Syntax/Lit.hs
- compiler/Language/Haskell/Syntax/Module/Name.hs
- compiler/Language/Haskell/Syntax/Text.hs
- compiler/ghc.cabal.in
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Info.hs
- linters/lint-codes/LintCodes/Static.hs
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.hs
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/Test20239.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T24221.stderr
- testsuite/tests/hiefile/should_run/T24544.hs
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T14189.stderr
- testsuite/tests/parser/should_compile/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20718b.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/parser/should_compile/T23315/T23315.stderr
- testsuite/tests/printer/AnnotationNoListTuplePuns.stdout
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/profiling/should_run/caller-cc/CallerCcParser.hs
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/575c4bc6cb701a3b26982bf36998aad…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/575c4bc6cb701a3b26982bf36998aad…
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