[Git][ghc/ghc][wip/torsten.schmits/mod-origin-hidden-reexports-message-fix] 8 commits: Narrow before optimising MUL/DIV/REM into shifts
by Torsten Schmits (@torsten.schmits) 12 Dec '25
by Torsten Schmits (@torsten.schmits) 12 Dec '25
12 Dec '25
Torsten Schmits pushed to branch wip/torsten.schmits/mod-origin-hidden-reexports-message-fix at Glasgow Haskell Compiler / GHC
Commits:
fe2b79f4 by Recursion Ninja at 2025-12-10T08:34:18-05:00
Narrow before optimising MUL/DIV/REM into shifts
The MUL/DIV/REM operations can be optimised into shifts when one of the
operands is a constant power of 2. However, as literals in Cmm are
stored as 'Integer', for this to be correct we first need to narrow the
literal to the appropriate width before checking whether the literal is
a power of 2.
Fixes #25664
- - - - -
06c2349c by Recursion Ninja at 2025-12-10T08:34:58-05:00
Decouple 'Language.Haskell.Syntax.Type' from 'GHC.Utils.Panic'
- Remove the *original* defintion of 'hsQTvExplicit' defined within 'Language.Haskell.Syntax.Type'
- Redefine 'hsQTvExplicit' as 'hsq_explicit' specialized to 'GhcPass' exported by 'GHC.Utils.Panic'
- Define 'hsQTvExplicitBinders' as 'hsq_explicit' specialized to 'DocNameI' exported by 'Haddock.GhcUtils'.
- Replace all call sites of the original 'hsQTvExplicit' definition with either:
1. 'hsQTvExplicit' updated definition
2. 'hsQTvExplicitBinders'
All call sites never entered the 'XLHsQTyVars' constructor branch, but a call to 'panic' existed on this code path because the type system was not strong enought to guarantee that the 'XLHsQTyVars' construction was impossible.
These two specialized functions provide the type system with enough information to make that guarantee, and hence the dependancy on 'panic' can be removed.
- - - - -
ac0815d5 by sheaf at 2025-12-10T23:39:57-05:00
Quantify arg before mult in function arrows
As noted in #23764, we expect quantification order to be left-to-right,
so that in a type such as
a %m -> b
the inferred quantification order should be [a, m, b] and not [m, a, b].
This was addressed in commit d31fbf6c, but that commit failed to update
some other functions such as GHC.Core.TyCo.FVs.tyCoFVsOfType.
This affects Haddock, as whether we print an explicit forall or not
depends on whether the inferred quantification order matches the actual
quantification order.
- - - - -
2caf796e by sheaf at 2025-12-10T23:39:57-05:00
Haddock: improvements to ty-var quantification
This commit makes several improvements to how Haddock deals with the
quantification of type variables:
1. In pattern synonyms, Haddock used to jumble up universal and
existential quantification. That is now fixed, fixing #26252.
Tested in the 'PatternSyns2' haddock-html test.
2. The logic for computing whether to use an explicit kind annotation
for a type variable quantified in a forall was not even wrong.
This commit improves the heuristic, but it will always remain an
imperfect heuristic (lest we actually run kind inference again).
In the future (#26271), we hope to avoid reliance on this heuristic.
- - - - -
b14bdd59 by Teo Camarasu at 2025-12-10T23:40:38-05:00
Add explicit export list to GHC.Num
Let's make clear what this module exports to allow us to easily deprecate and remove some of these in the future. Resolves https://gitlab.haskell.org/ghc/ghc/-/issues/26625
- - - - -
d99f8326 by Cheng Shao at 2025-12-11T19:14:18-05:00
compiler: remove unused CPP code in foreign stub
This patch removes unused CPP code in the generated foreign stub:
- `#define IN_STG_CODE 0` is not needed, since `Rts.h` already
includes this definition
- The `if defined(__cplusplus)` code paths are not needed in the `.c`
file, since we don't generate C++ stubs and don't include C++
headers in our stubs. But it still needs to be present in the `.h`
header since it might be later included into C++ source files.
- - - - -
46c9746f by Cheng Shao at 2025-12-11T19:14:57-05:00
configure: bump LlvmMaxVersion to 22
This commit bumps LlvmMaxVersion to 22; 21.x releases have been
available since Aug 26th, 2025 and there's no regressions with 21.x so
far. This bump is also required for updating fedora image to 43.
- - - - -
ad2a0c1e by Torsten Schmits at 2025-12-12T13:04:33+01:00
Use the correct field of ModOrigin when formatting error message listing hidden reexports
- - - - -
29 changed files:
- compiler/GHC/Cmm/Opt.hs
- compiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Driver/CodeOutput.hs
- compiler/GHC/Hs/Type.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Unit/State.hs
- compiler/Language/Haskell/Syntax/Type.hs
- configure.ac
- libraries/base/src/GHC/Num.hs
- + testsuite/tests/cmm/opt/T25664.hs
- + testsuite/tests/cmm/opt/T25664.stdout
- testsuite/tests/cmm/opt/all.T
- 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/interface-stability/base-exports.stdout-ws-32
- utils/haddock/haddock-api/src/Haddock/Backends/LaTeX.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/GhcUtils.hs
- utils/haddock/html-test/ref/Bug1050.html
- utils/haddock/html-test/ref/LinearTypes.html
- utils/haddock/html-test/ref/PatternSyns.html
- + utils/haddock/html-test/ref/PatternSyns2.html
- utils/haddock/html-test/ref/TypeOperators.html
- + utils/haddock/html-test/src/PatternSyns2.hs
- utils/haddock/latex-test/ref/LinearTypes/LinearTypes.tex
Changes:
=====================================
compiler/GHC/Cmm/Opt.hs
=====================================
@@ -395,26 +395,39 @@ cmmMachOpFoldM platform mop [x, (CmmLit (CmmInt 1 rep))]
one = CmmLit (CmmInt 1 (wordWidth platform))
-- Now look for multiplication/division by powers of 2 (integers).
-
-cmmMachOpFoldM platform mop [x, (CmmLit (CmmInt n _))]
+--
+-- Naively this is as simple a matter as left/right bit shifts,
+-- but the Cmm representation if integral values quickly complicated the matter.
+--
+-- We must carefully narrow the value to be within the range of values for the
+-- type's logical bit-width. However, Cmm only represents values as *signed*
+-- integers internally yet the logical type may be unsigned. If we are dealing
+-- with a negative integer type at width @_w@, the only negative number that
+-- wraps around to be a positive power of 2 after calling narrowU is -2^(_w - 1)
+-- which wraps round to 2^(_w - 1), and multiplying by -2^(_w - 1) is indeed
+-- the same as a left shift by (w - 1), so this is OK.
+--
+-- ToDo: See #25664 (comment 605821) describing a change to the Cmm literal representation.
+-- When/If this is completed, this code must be refactored to account for the explicit width sizes.
+cmmMachOpFoldM platform mop [x, (CmmLit (CmmInt n _w))]
= case mop of
MO_Mul rep
- | Just p <- exactLog2 n ->
+ | Just p <- exactLog2 (narrowU rep n) ->
Just $! (cmmMachOpFold platform (MO_Shl rep) [x, CmmLit (CmmInt p $ wordWidth platform)])
MO_U_Quot rep
- | Just p <- exactLog2 n ->
+ | Just p <- exactLog2 (narrowU rep n) ->
Just $! (cmmMachOpFold platform (MO_U_Shr rep) [x, CmmLit (CmmInt p $ wordWidth platform)])
MO_U_Rem rep
- | Just _ <- exactLog2 n ->
+ | Just _ <- exactLog2 (narrowU rep n) ->
Just $! (cmmMachOpFold platform (MO_And rep) [x, CmmLit (CmmInt (n - 1) rep)])
MO_S_Quot rep
- | Just p <- exactLog2 n,
+ | Just p <- exactLog2 (narrowS rep n),
CmmReg _ <- x -> -- We duplicate x in signedQuotRemHelper, hence require
-- it is a reg. FIXME: remove this restriction.
Just $! (cmmMachOpFold platform (MO_S_Shr rep)
[signedQuotRemHelper rep p, CmmLit (CmmInt p $ wordWidth platform)])
MO_S_Rem rep
- | Just p <- exactLog2 n,
+ | Just p <- exactLog2 (narrowS rep n),
CmmReg _ <- x -> -- We duplicate x in signedQuotRemHelper, hence require
-- it is a reg. FIXME: remove this restriction.
-- We replace (x `rem` 2^p) by (x - (x `quot` 2^p) * 2^p).
=====================================
compiler/GHC/Core/TyCo/FVs.hs
=====================================
@@ -635,7 +635,9 @@ tyCoFVsOfType (TyConApp _ tys) f bound_vars acc = tyCoFVsOfTypes tys f bound_v
-- See Note [Free vars and synonyms]
tyCoFVsOfType (LitTy {}) f bound_vars acc = emptyFV f bound_vars acc
tyCoFVsOfType (AppTy fun arg) f bound_vars acc = (tyCoFVsOfType fun `unionFV` tyCoFVsOfType arg) f bound_vars acc
-tyCoFVsOfType (FunTy _ w arg res) f bound_vars acc = (tyCoFVsOfType w `unionFV` tyCoFVsOfType arg `unionFV` tyCoFVsOfType res) f bound_vars acc
+tyCoFVsOfType (FunTy _ w arg res) f bound_vars acc =
+ -- As per #23764, if we have 'a %m -> b', quantification order should be [a,m,b] not [m,a,b].
+ (tyCoFVsOfType arg `unionFV` tyCoFVsOfType w `unionFV` tyCoFVsOfType res) f bound_vars acc
tyCoFVsOfType (ForAllTy bndr ty) f bound_vars acc = tyCoFVsBndr bndr (tyCoFVsOfType ty) f bound_vars acc
tyCoFVsOfType (CastTy ty co) f bound_vars acc = (tyCoFVsOfType ty `unionFV` tyCoFVsOfCo co) f bound_vars acc
tyCoFVsOfType (CoercionTy co) f bound_vars acc = tyCoFVsOfCo co f bound_vars acc
@@ -958,7 +960,9 @@ invisibleVarsOfType = go
= go ty'
go (TyVarTy v) = go (tyVarKind v)
go (AppTy f a) = go f `unionFV` go a
- go (FunTy _ w ty1 ty2) = go w `unionFV` go ty1 `unionFV` go ty2
+ go (FunTy _ w ty1 ty2) =
+ -- As per #23764, order is: arg, mult, res.
+ go ty1 `unionFV` go w `unionFV` go ty2
go (TyConApp tc tys) = tyCoFVsOfTypes invisibles `unionFV`
invisibleVarsOfTypes visibles
where (invisibles, visibles) = partitionInvisibleTypes tc tys
=====================================
compiler/GHC/Core/TyCo/Rep.hs
=====================================
@@ -1984,7 +1984,9 @@ foldTyCo (TyCoFolder { tcf_view = view
go_ty _ (LitTy {}) = mempty
go_ty env (CastTy ty co) = go_ty env ty `mappend` go_co env co
go_ty env (CoercionTy co) = go_co env co
- go_ty env (FunTy _ w arg res) = go_ty env w `mappend` go_ty env arg `mappend` go_ty env res
+ go_ty env (FunTy _ w arg res) =
+ -- As per #23764, ordering is [arg, w, res].
+ go_ty env arg `mappend` go_ty env w `mappend` go_ty env res
go_ty env (TyConApp _ tys) = go_tys env tys
go_ty env (ForAllTy (Bndr tv vis) inner)
= let !env' = tycobinder env tv vis -- Avoid building a thunk here
=====================================
compiler/GHC/Driver/CodeOutput.hs
=====================================
@@ -329,15 +329,8 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs
stub_c_file_exists
<- outputForeignStubs_help stub_c stub_c_output_w
- ("#define IN_STG_CODE 0\n" ++
- "#include <Rts.h>\n" ++
- rts_includes ++
- ffi_includes ++
- cplusplus_hdr)
- cplusplus_ftr
- -- We're adding the default hc_header to the stub file, but this
- -- isn't really HC code, so we need to define IN_STG_CODE==0 to
- -- avoid the register variables etc. being enabled.
+ (rts_includes ++
+ ffi_includes) ""
return (stub_h_file_exists, if stub_c_file_exists
then Just stub_c
=====================================
compiler/GHC/Hs/Type.hs
=====================================
@@ -640,6 +640,9 @@ hsLTyVarName = hsTyVarName . unLoc
hsLTyVarNames :: [LHsTyVarBndr flag (GhcPass p)] -> [IdP (GhcPass p)]
hsLTyVarNames = mapMaybe hsLTyVarName
+hsQTvExplicit :: LHsQTyVars (GhcPass p) -> [LHsTyVarBndr (HsBndrVis (GhcPass p)) (GhcPass p)]
+hsQTvExplicit = hsq_explicit
+
hsForAllTelescopeBndrs :: HsForAllTelescope (GhcPass p) -> [LHsTyVarBndr ForAllTyFlag (GhcPass p)]
hsForAllTelescopeBndrs (HsForAllVis _ bndrs) = map (fmap (setHsTyVarBndrFlag Required)) bndrs
hsForAllTelescopeBndrs (HsForAllInvis _ bndrs) = map (fmap (updateHsTyVarBndrFlag Invisible)) bndrs
=====================================
compiler/GHC/Tc/Utils/TcMType.hs
=====================================
@@ -1432,7 +1432,7 @@ collect_cand_qtvs orig_ty is_dep cur_lvl bound dvs ty
-- Uses accumulating-parameter style
go dv (AppTy t1 t2) = foldlM go dv [t1, t2]
go dv (TyConApp tc tys) = go_tc_args dv (tyConBinders tc) tys
- go dv (FunTy _ w arg res) = foldlM go dv [w, arg, res]
+ go dv (FunTy _ w arg res) = foldlM go dv [arg, w, res]
go dv (LitTy {}) = return dv
go dv (CastTy ty co) = do { dv1 <- go dv ty
; collect_cand_qtvs_co orig_ty cur_lvl bound dv1 co }
=====================================
compiler/GHC/Tc/Utils/TcType.hs
=====================================
@@ -1009,8 +1009,8 @@ tcTyFamInstsAndVisX = go
go _ (LitTy {}) = []
go is_invis_arg (ForAllTy bndr ty) = go is_invis_arg (binderType bndr)
++ go is_invis_arg ty
- go is_invis_arg (FunTy _ w ty1 ty2) = go is_invis_arg w
- ++ go is_invis_arg ty1
+ go is_invis_arg (FunTy _ w ty1 ty2) = go is_invis_arg ty1
+ ++ go is_invis_arg w
++ go is_invis_arg ty2
go is_invis_arg ty@(AppTy _ _) =
let (ty_head, ty_args) = splitAppTys ty
=====================================
compiler/GHC/Unit/State.hs
=====================================
@@ -216,7 +216,7 @@ instance Outputable ModuleOrigin where
(if null rhs
then []
else [text "hidden reexport by" <+>
- sep (map (ppr . mkUnit) res)]) ++
+ sep (map (ppr . mkUnit) rhs)]) ++
(if f then [text "package flag"] else [])
))
=====================================
compiler/Language/Haskell/Syntax/Type.hs
=====================================
@@ -55,7 +55,6 @@ module Language.Haskell.Syntax.Type (
FieldOcc(..), LFieldOcc,
mapHsOuterImplicit,
- hsQTvExplicit,
isHsKindedTyVar
) where
@@ -68,7 +67,6 @@ import Language.Haskell.Syntax.Specificity
import GHC.Hs.Doc (LHsDoc)
import GHC.Data.FastString (FastString)
-import GHC.Utils.Panic( panic )
import Data.Data hiding ( Fixity, Prefix, Infix )
import Data.Maybe
@@ -326,10 +324,6 @@ data LHsQTyVars pass -- See Note [HsType binders]
}
| XLHsQTyVars !(XXLHsQTyVars pass)
-hsQTvExplicit :: LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
-hsQTvExplicit (HsQTvs { hsq_explicit = explicit_tvs }) = explicit_tvs
-hsQTvExplicit (XLHsQTyVars {}) = panic "hsQTvExplicit"
-
------------------------------------------------
-- HsOuterTyVarBndrs
-- Used to quantify the outermost type variable binders of a type that obeys
=====================================
configure.ac
=====================================
@@ -526,7 +526,7 @@ AC_SUBST(InstallNameToolCmd)
# versions of LLVM simultaneously, but that stopped working around
# 3.5/3.6 release of LLVM.
LlvmMinVersion=13 # inclusive
-LlvmMaxVersion=21 # not inclusive
+LlvmMaxVersion=22 # not inclusive
AC_SUBST([LlvmMinVersion])
AC_SUBST([LlvmMaxVersion])
=====================================
libraries/base/src/GHC/Num.hs
=====================================
@@ -1,3 +1,4 @@
+{-# LANGUAGE MagicHash #-}
{-# OPTIONS_HADDOCK not-home #-}
-- |
@@ -16,11 +17,190 @@ module GHC.Num
( Num(..)
, subtract
, quotRemInteger
- , module GHC.Num.Integer
- , module GHC.Num.Natural
+ , integerFromNatural
+ , integerToNaturalClamp
+ , integerToNaturalThrow
+ , integerToNatural
+ , integerToWord#
+ , integerToInt#
+ , integerToWord64#
+ , integerToInt64#
+ , integerAdd
+ , integerMul
+ , integerSub
+ , integerNegate
+ , integerAbs
+ , integerPopCount#
+ , integerQuot
+ , integerRem
+ , integerDiv
+ , integerMod
+ , integerDivMod#
+ , integerQuotRem#
+ , integerEncodeFloat#
+ , integerEncodeDouble#
+ , integerGcd
+ , integerLcm
+ , integerAnd
+ , integerOr
+ , integerXor
+ , integerComplement
+ , integerBit#
+ , integerTestBit#
+ , integerShiftL#
+ , integerShiftR#
+ , integerFromWord#
+ , integerFromWord64#
+ , integerFromInt64#
+ , Integer(..)
+ , integerBit
+ , integerCheck
+ , integerCheck#
+ , integerCompare
+ , integerDecodeDouble#
+ , integerDivMod
+ , integerEncodeDouble
+ , integerEq
+ , integerEq#
+ , integerFromAddr
+ , integerFromAddr#
+ , integerFromBigNat#
+ , integerFromBigNatNeg#
+ , integerFromBigNatSign#
+ , integerFromByteArray
+ , integerFromByteArray#
+ , integerFromInt
+ , integerFromInt#
+ , integerFromWord
+ , integerFromWordList
+ , integerFromWordNeg#
+ , integerFromWordSign#
+ , integerGcde
+ , integerGcde#
+ , integerGe
+ , integerGe#
+ , integerGt
+ , integerGt#
+ , integerIsNegative
+ , integerIsNegative#
+ , integerIsOne
+ , integerIsPowerOf2#
+ , integerIsZero
+ , integerLe
+ , integerLe#
+ , integerLog2
+ , integerLog2#
+ , integerLogBase
+ , integerLogBase#
+ , integerLogBaseWord
+ , integerLogBaseWord#
+ , integerLt
+ , integerLt#
+ , integerNe
+ , integerNe#
+ , integerOne
+ , integerPowMod#
+ , integerQuotRem
+ , integerRecipMod#
+ , integerShiftL
+ , integerShiftR
+ , integerSignum
+ , integerSignum#
+ , integerSizeInBase#
+ , integerSqr
+ , integerTestBit
+ , integerToAddr
+ , integerToAddr#
+ , integerToBigNatClamp#
+ , integerToBigNatSign#
+ , integerToInt
+ , integerToMutableByteArray
+ , integerToMutableByteArray#
+ , integerToWord
+ , integerZero
+ , naturalToWord#
+ , naturalPopCount#
+ , naturalShiftR#
+ , naturalShiftL#
+ , naturalAdd
+ , naturalSub
+ , naturalSubThrow
+ , naturalSubUnsafe
+ , naturalMul
+ , naturalQuotRem#
+ , naturalQuot
+ , naturalRem
+ , naturalAnd
+ , naturalAndNot
+ , naturalOr
+ , naturalXor
+ , naturalTestBit#
+ , naturalBit#
+ , naturalGcd
+ , naturalLcm
+ , naturalLog2#
+ , naturalLogBaseWord#
+ , naturalLogBase#
+ , naturalPowMod
+ , naturalSizeInBase#
+ , Natural(..)
+ , naturalBit
+ , naturalCheck
+ , naturalCheck#
+ , naturalClearBit
+ , naturalClearBit#
+ , naturalCompare
+ , naturalComplementBit
+ , naturalComplementBit#
+ , naturalEncodeDouble#
+ , naturalEncodeFloat#
+ , naturalEq
+ , naturalEq#
+ , naturalFromAddr
+ , naturalFromAddr#
+ , naturalFromBigNat#
+ , naturalFromByteArray#
+ , naturalFromWord
+ , naturalFromWord#
+ , naturalFromWord2#
+ , naturalFromWordList
+ , naturalGe
+ , naturalGe#
+ , naturalGt
+ , naturalGt#
+ , naturalIsOne
+ , naturalIsPowerOf2#
+ , naturalIsZero
+ , naturalLe
+ , naturalLe#
+ , naturalLog2
+ , naturalLogBase
+ , naturalLogBaseWord
+ , naturalLt
+ , naturalLt#
+ , naturalNe
+ , naturalNe#
+ , naturalNegate
+ , naturalOne
+ , naturalPopCount
+ , naturalQuotRem
+ , naturalSetBit
+ , naturalSetBit#
+ , naturalShiftL
+ , naturalShiftR
+ , naturalSignum
+ , naturalSqr
+ , naturalTestBit
+ , naturalToAddr
+ , naturalToAddr#
+ , naturalToBigNat#
+ , naturalToMutableByteArray#
+ , naturalToWord
+ , naturalToWordClamp
+ , naturalToWordClamp#
+ , naturalToWordMaybe#
+ , naturalZero
)
where
import GHC.Internal.Num
-import GHC.Num.Integer
-import GHC.Num.Natural
=====================================
testsuite/tests/cmm/opt/T25664.hs
=====================================
@@ -0,0 +1,17 @@
+{-# OPTIONS_GHC -O -fno-full-laziness #-}
+{-# LANGUAGE MagicHash #-}
+
+import GHC.Exts
+import GHC.Int
+
+mb8 :: Int8 -> Int8
+{-# OPAQUE mb8 #-}
+mb8 (I8# i) = I8# (i `quotInt8#` (noinline intToInt8# 128#))
+
+mb16 :: Int16 -> Int16
+{-# OPAQUE mb16 #-}
+mb16 (I16# i) = I16# (i `quotInt16#` (noinline intToInt16# 32768#))
+
+main :: IO ()
+main = print (mb8 minBound) >> print (mb16 minBound)
+
=====================================
testsuite/tests/cmm/opt/T25664.stdout
=====================================
@@ -0,0 +1,2 @@
+1
+1
=====================================
testsuite/tests/cmm/opt/all.T
=====================================
@@ -12,3 +12,6 @@ test('T25771', [cmm_src, only_ways(['optasm']),
grep_errmsg(r'(12\.345|0\.6640625)',[1]),
],
compile, ['-ddump-cmm'])
+
+# Cmm should correctly account for word size when performing MUL/DIV/REM by a power of 2 optimization.
+test('T25664', normal, compile_and_run, [''])
\ No newline at end of file
=====================================
testsuite/tests/interface-stability/base-exports.stdout
=====================================
@@ -8351,7 +8351,7 @@ module GHC.Natural where
xorNatural :: Natural -> Natural -> Natural
module GHC.Num where
- -- Safety: None
+ -- Safety: Safe-Inferred
type Integer :: *
data Integer = IS GHC.Internal.Prim.Int# | IP GHC.Internal.Prim.ByteArray# | IN GHC.Internal.Prim.ByteArray#
type Natural :: *
=====================================
testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
=====================================
@@ -11397,7 +11397,7 @@ module GHC.Natural where
xorNatural :: Natural -> Natural -> Natural
module GHC.Num where
- -- Safety: None
+ -- Safety: Safe-Inferred
type Integer :: *
data Integer = IS GHC.Internal.Prim.Int# | IP GHC.Internal.Prim.ByteArray# | IN GHC.Internal.Prim.ByteArray#
type Natural :: *
=====================================
testsuite/tests/interface-stability/base-exports.stdout-mingw32
=====================================
@@ -8569,7 +8569,7 @@ module GHC.Natural where
xorNatural :: Natural -> Natural -> Natural
module GHC.Num where
- -- Safety: None
+ -- Safety: Safe-Inferred
type Integer :: *
data Integer = IS GHC.Internal.Prim.Int# | IP GHC.Internal.Prim.ByteArray# | IN GHC.Internal.Prim.ByteArray#
type Natural :: *
=====================================
testsuite/tests/interface-stability/base-exports.stdout-ws-32
=====================================
@@ -8351,7 +8351,7 @@ module GHC.Natural where
xorNatural :: Natural -> Natural -> Natural
module GHC.Num where
- -- Safety: None
+ -- Safety: Safe-Inferred
type Integer :: *
data Integer = IS GHC.Internal.Prim.Int# | IP GHC.Internal.Prim.ByteArray# | IN GHC.Internal.Prim.ByteArray#
type Natural :: *
=====================================
utils/haddock/haddock-api/src/Haddock/Backends/LaTeX.hs
=====================================
@@ -435,7 +435,7 @@ ppFamHeader
| associated = id
| otherwise = (<+> keyword "family")
- famName = ppAppDocNameTyVarBndrs unicode name (hsq_explicit tvs)
+ famName = ppAppDocNameTyVarBndrs unicode name (hsQTvExplicitBinders tvs)
famSig = case result of
NoSig _ -> empty
@@ -644,7 +644,7 @@ ppTyVars :: RenderableBndrFlag flag => Bool -> [LHsTyVarBndr flag DocNameI] -> [
ppTyVars unicode tvs = map (ppHsTyVarBndr unicode . unLoc) tvs
tyvarNames :: LHsQTyVars DocNameI -> [Maybe Name]
-tyvarNames = map (fmap getName . hsLTyVarNameI) . hsQTvExplicit
+tyvarNames = map (fmap getName . hsLTyVarNameI) . hsQTvExplicitBinders
declWithDoc :: LaTeX -> Maybe LaTeX -> LaTeX
declWithDoc decl doc =
=====================================
utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
=====================================
@@ -468,7 +468,7 @@ ppTySyn
hdr =
hsep
( [keyword "type", ppBinder summary occ]
- ++ ppTyVars unicode qual (hsQTvExplicit ltyvars)
+ ++ ppTyVars unicode qual (hsQTvExplicitBinders ltyvars)
)
full = hdr <+> def
def = case unLoc ltype of
@@ -595,7 +595,7 @@ ppFamHeader
qual =
hsep
[ ppFamilyLeader associated info
- , ppAppDocNameTyVarBndrs summary unicode qual name (hsq_explicit tvs)
+ , ppAppDocNameTyVarBndrs summary unicode qual name (hsQTvExplicitBinders tvs)
, ppResultSig result unicode qual
, injAnn
, whereBit
@@ -760,7 +760,7 @@ ppClassHdr
ppClassHdr summ lctxt n tvs fds unicode qual =
keyword "class"
<+> (if not (null $ fromMaybeContext lctxt) then ppLContext lctxt unicode qual HideEmptyContexts else noHtml)
- <+> ppAppDocNameTyVarBndrs summ unicode qual n (hsQTvExplicit tvs)
+ <+> ppAppDocNameTyVarBndrs summ unicode qual n (hsQTvExplicitBinders tvs)
<+> ppFds fds unicode qual
ppFds :: [LHsFunDep DocNameI] -> Unicode -> Qualification -> Html
@@ -1656,7 +1656,7 @@ ppDataHeader
ppLContext ctxt unicode qual HideEmptyContexts
<+>
-- T a b c ..., or a :+: b
- ppAppDocNameTyVarBndrs summary unicode qual name (hsQTvExplicit tvs)
+ ppAppDocNameTyVarBndrs summary unicode qual name (hsQTvExplicitBinders tvs)
<+> case ks of
Nothing -> mempty
Just (L _ x) -> dcolon unicode <+> ppKind unicode qual x
=====================================
utils/haddock/haddock-api/src/Haddock/Convert.hs
=====================================
@@ -29,7 +29,7 @@ module Haddock.Convert
import Control.DeepSeq (force)
import Data.Either (lefts, partitionEithers, rights)
-import Data.Maybe (catMaybes, mapMaybe, maybeToList)
+import Data.Maybe (catMaybes, mapMaybe)
import GHC.Builtin.Names
( boxedRepDataConKey
, eqTyConKey
@@ -140,7 +140,7 @@ tyThingToLHsDecl prr t = case t of
hsq_explicit $
fdTyVars fd
, feqn_fixity = fdFixity fd
- , feqn_rhs = synifyType WithinType [] rhs
+ , feqn_rhs = synifyType WithinType emptyVarSet rhs
}
extractAtItem
@@ -179,7 +179,7 @@ tyThingToLHsDecl prr t = case t of
noLocA (MinimalSig (noAnn, NoSourceText) . noLocA $ classMinimalDef cl)
: [ noLocA tcdSig
| clsOp <- classOpItems cl
- , tcdSig <- synifyTcIdSig vs clsOp
+ , tcdSig <- synifyTcIdSig (mkVarSet vs) clsOp
]
, tcdMeths = [] -- ignore default method definitions, they don't affect signature
-- class associated-types are a subset of TyCon:
@@ -213,9 +213,9 @@ synifyAxBranch :: TyCon -> CoAxBranch -> TyFamInstEqn GhcRn
synifyAxBranch tc (CoAxBranch{cab_tvs = tkvs, cab_lhs = args, cab_rhs = rhs}) =
let name = synifyNameN tc
args_types_only = filterOutInvisibleTypes tc args
- typats = map (synifyType WithinType []) args_types_only
+ typats = map (synifyType WithinType emptyVarSet) args_types_only
annot_typats = zipWith3 annotHsType args_poly args_types_only typats
- hs_rhs = synifyType WithinType [] rhs
+ hs_rhs = synifyType WithinType emptyVarSet rhs
outer_bndrs = HsOuterImplicit{hso_ximplicit = map tyVarName tkvs}
in -- TODO: this must change eventually
FamEqn
@@ -344,7 +344,7 @@ synifyTyCon _prr coax tc
, tcdLName = synifyNameN tc
, tcdTyVars = synifyTyVars (tyConVisibleTyVars tc)
, tcdFixity = synifyFixity tc
- , tcdRhs = synifyType WithinType [] ty
+ , tcdRhs = synifyType WithinType emptyVarSet ty
}
-- (closed) newtype and data
| otherwise = do
@@ -578,8 +578,8 @@ synifyDataCon use_gadt_syntax dc =
linear_tys =
zipWith
( \(Scaled mult ty) (HsSrcBang st unp str) ->
- let tySyn = synifyType WithinType [] ty
- multSyn = synifyMultRec [] mult
+ let tySyn = synifyType WithinType emptyVarSet ty
+ multSyn = synifyMultRec emptyVarSet mult
in CDF (noAnn, st) unp str multSyn tySyn Nothing
)
arg_tys
@@ -620,7 +620,7 @@ synifyDataCon use_gadt_syntax dc =
, con_inner_bndrs = inner_bndrs
, con_mb_cxt = ctx
, con_g_args = hat
- , con_res_ty = synifyType WithinType [] res_ty
+ , con_res_ty = synifyType WithinType emptyVarSet res_ty
, con_doc = Nothing
}
else do
@@ -657,11 +657,11 @@ synifyIdSig
-> SynifyTypeState
-- ^ what to do with a 'forall'
-> [TyVar]
- -- ^ free variables in the type to convert
+ -- ^ type variables bound from an outer scope
-> Id
-- ^ the 'Id' from which to get the type signature
-> Sig GhcRn
-synifyIdSig prr s vs i = TypeSig noAnn [n] (synifySigWcType s vs t)
+synifyIdSig prr s boundTvs i = TypeSig noAnn [n] (synifySigWcType s boundTvs t)
where
!n = force $ synifyNameN i
t = defaultType prr (varType i)
@@ -669,18 +669,18 @@ synifyIdSig prr s vs i = TypeSig noAnn [n] (synifySigWcType s vs t)
-- | Turn a 'ClassOpItem' into a list of signatures. The list returned is going
-- to contain the synified 'ClassOpSig' as well (when appropriate) a default
-- 'ClassOpSig'.
-synifyTcIdSig :: [TyVar] -> ClassOpItem -> [Sig GhcRn]
-synifyTcIdSig vs (i, dm) =
+synifyTcIdSig :: TyVarSet -> ClassOpItem -> [Sig GhcRn]
+synifyTcIdSig boundTvs (i, dm) =
[ClassOpSig noAnn False [synifyNameN i] (mainSig (varType i))]
++ [ ClassOpSig noAnn True [noLocA dn] (defSig dt)
| Just (dn, GenericDM dt) <- [dm]
]
where
- mainSig t = synifySigType DeleteTopLevelQuantification vs t
- defSig t = synifySigType ImplicitizeForAll vs t
+ mainSig t = synifySigType DeleteTopLevelQuantification boundTvs t
+ defSig t = synifySigType ImplicitizeForAll boundTvs t
synifyCtx :: [PredType] -> LHsContext GhcRn
-synifyCtx ts = noLocA (map (synifyType WithinType []) ts)
+synifyCtx ts = noLocA (map (synifyType WithinType emptyVarSet) ts)
synifyTyVars :: [TyVar] -> LHsQTyVars GhcRn
synifyTyVars ktvs =
@@ -699,7 +699,7 @@ synifyTyVarBndr' :: VarSet -> VarBndr TyVar flag -> LHsTyVarBndr flag GhcRn
synifyTyVarBndr' no_kinds (Bndr tv spec) = synify_ty_var no_kinds spec tv
-- | Like 'synifyTyVarBndr', but accepts a set of variables for which to omit kind
--- signatures (even if they don't have the lifted type kind).
+-- signatures (even if they don't have kind 'Type').
synify_ty_var :: VarSet -> flag -> TyVar -> LHsTyVarBndr flag GhcRn
synify_ty_var no_kinds flag tv =
noLocA (HsTvb noAnn flag bndr_var bndr_kind)
@@ -726,7 +726,7 @@ annotHsType _ _ hs_ty@(L _ (HsKindSig{})) = hs_ty
annotHsType True ty hs_ty
| not $ isEmptyVarSet $ filterVarSet isTyVar $ tyCoVarsOfType ty =
let ki = typeKind ty
- hs_ki = synifyType WithinType [] ki
+ hs_ki = synifyType WithinType emptyVarSet ki
in noLocA (HsKindSig noAnn hs_ty hs_ki)
annotHsType _ _ hs_ty = hs_ty
@@ -768,14 +768,15 @@ data SynifyTypeState
-- the defining class gets to quantify all its functions for free!
DeleteTopLevelQuantification
-synifySigType :: SynifyTypeState -> [TyVar] -> Type -> LHsSigType GhcRn
+synifySigType :: SynifyTypeState -> TyVarSet -> Type -> LHsSigType GhcRn
-- The use of mkEmptySigType (which uses empty binders in OuterImplicit)
-- is a bit suspicious; what if the type has free variables?
-synifySigType s vs ty = mkEmptySigType (synifyType s vs ty)
+synifySigType s boundTvs ty = mkEmptySigType (synifyType s boundTvs ty)
synifySigWcType :: SynifyTypeState -> [TyVar] -> Type -> LHsSigWcType GhcRn
-- Ditto (see synifySigType)
-synifySigWcType s vs ty = mkEmptyWildCardBndrs (mkEmptySigType (rename (map getName vs) $ synifyType s vs ty))
+synifySigWcType s vs ty =
+ mkEmptyWildCardBndrs (mkEmptySigType (rename (map getName vs) $ synifyType s (mkVarSet vs) ty))
synifyPatSynSigType :: PatSyn -> LHsSigType GhcRn
-- Ditto (see synifySigType)
@@ -791,13 +792,13 @@ defaultType HideRuntimeRep = defaultRuntimeRepVars
synifyType
:: SynifyTypeState
-- ^ what to do with a 'forall'
- -> [TyVar]
- -- ^ free variables in the type to convert
+ -> TyVarSet
+ -- ^ bound type variables
-> Type
-- ^ the type to convert
-> LHsType GhcRn
synifyType _ _ (TyVarTy tv) = noLocA $ HsTyVar noAnn NotPromoted $ noLocA (noUserRdr $ getName tv)
-synifyType _ vs (TyConApp tc tys) =
+synifyType _ boundTvs (TyConApp tc tys) =
maybe_sig res_ty
where
res_ty :: LHsType GhcRn
@@ -819,24 +820,24 @@ synifyType _ vs (TyConApp tc tys) =
ConstraintTuple -> HsBoxedOrConstraintTuple
UnboxedTuple -> HsUnboxedTuple
)
- (map (synifyType WithinType vs) vis_tys)
+ (map (synifyType WithinType boundTvs) vis_tys)
| isUnboxedSumTyCon tc =
- noLocA $ HsSumTy noAnn (map (synifyType WithinType vs) vis_tys)
+ noLocA $ HsSumTy noAnn (map (synifyType WithinType boundTvs) vis_tys)
| Just dc <- isPromotedDataCon_maybe tc
, isTupleDataCon dc
, dataConSourceArity dc == length vis_tys =
- noLocA $ HsExplicitTupleTy noExtField IsPromoted (map (synifyType WithinType vs) vis_tys)
+ noLocA $ HsExplicitTupleTy noExtField IsPromoted (map (synifyType WithinType boundTvs) vis_tys)
-- ditto for lists
| getName tc == listTyConName
, [ty] <- vis_tys =
- noLocA $ HsListTy noAnn (synifyType WithinType vs ty)
+ noLocA $ HsListTy noAnn (synifyType WithinType boundTvs ty)
| tc == promotedNilDataCon
, [] <- vis_tys =
noLocA $ HsExplicitListTy noExtField IsPromoted []
| tc == promotedConsDataCon
, [ty1, ty2] <- vis_tys =
- let hTy = synifyType WithinType vs ty1
- in case synifyType WithinType vs ty2 of
+ let hTy = synifyType WithinType boundTvs ty1
+ in case synifyType WithinType boundTvs ty2 of
tTy
| L _ (HsExplicitListTy _ IsPromoted tTy') <- stripKindSig tTy ->
noLocA $ HsExplicitListTy noExtField IsPromoted (hTy : tTy')
@@ -846,7 +847,7 @@ synifyType _ vs (TyConApp tc tys) =
| tc `hasKey` ipClassKey
, [name, ty] <- tys
, Just x <- isStrLitTy name =
- noLocA $ HsIParamTy noAnn (noLocA $ HsIPName x) (synifyType WithinType vs ty)
+ noLocA $ HsIParamTy noAnn (noLocA $ HsIPName x) (synifyType WithinType boundTvs ty)
-- and equalities
| tc `hasKey` eqTyConKey
, [ty1, ty2] <- tys =
@@ -854,9 +855,9 @@ synifyType _ vs (TyConApp tc tys) =
HsOpTy
noExtField
NotPromoted
- (synifyType WithinType vs ty1)
+ (synifyType WithinType boundTvs ty1)
(noLocA $ noUserRdr eqTyConName)
- (synifyType WithinType vs ty2)
+ (synifyType WithinType boundTvs ty2)
-- and infix type operators
| isSymOcc (nameOccName (getName tc))
, ty1 : ty2 : tys_rest <- vis_tys =
@@ -864,9 +865,9 @@ synifyType _ vs (TyConApp tc tys) =
( HsOpTy
noExtField
prom
- (synifyType WithinType vs ty1)
+ (synifyType WithinType boundTvs ty1)
(noLocA $ noUserRdr $ getName tc)
- (synifyType WithinType vs ty2)
+ (synifyType WithinType boundTvs ty2)
)
tys_rest
-- Most TyCons:
@@ -880,7 +881,7 @@ synifyType _ vs (TyConApp tc tys) =
foldl
(\t1 t2 -> noLocA $ HsAppTy noExtField t1 t2)
(noLocA ty_app)
- ( map (synifyType WithinType vs) $
+ ( map (synifyType WithinType boundTvs) $
filterOut isCoercionTy ty_args
)
@@ -891,56 +892,57 @@ synifyType _ vs (TyConApp tc tys) =
maybe_sig ty'
| tyConAppNeedsKindSig False tc tys_len =
let full_kind = typeKind (mkTyConApp tc tys)
- full_kind' = synifyType WithinType vs full_kind
+ full_kind' = synifyType WithinType boundTvs full_kind
in noLocA $ HsKindSig noAnn ty' full_kind'
| otherwise = ty'
-synifyType _ vs ty@(AppTy{}) =
+synifyType _ boundTvs ty@(AppTy{}) =
let
(ty_head, ty_args) = splitAppTys ty
- ty_head' = synifyType WithinType vs ty_head
+ ty_head' = synifyType WithinType boundTvs ty_head
ty_args' =
- map (synifyType WithinType vs) $
+ map (synifyType WithinType boundTvs) $
filterOut isCoercionTy $
filterByList
(map isVisibleForAllTyFlag $ appTyForAllTyFlags ty_head ty_args)
ty_args
in
foldl (\t1 t2 -> noLocA $ HsAppTy noExtField t1 t2) ty_head' ty_args'
-synifyType s vs funty@(FunTy af w t1 t2)
- | isInvisibleFunArg af = synifySigmaType s vs funty
+synifyType s boundTvs funty@(FunTy af w t1 t2)
+ | isInvisibleFunArg af = synifySigmaType s boundTvs funty
| otherwise = noLocA $ HsFunTy noExtField w' s1 s2
where
- s1 = synifyType WithinType vs t1
- s2 = synifyType WithinType vs t2
- w' = synifyMultArrow vs w
-synifyType s vs forallty@(ForAllTy (Bndr _ argf) _ty) =
+ s1 = synifyType WithinType boundTvs t1
+ s2 = synifyType WithinType boundTvs t2
+ w' = synifyMultArrow boundTvs w
+synifyType s boundTvs forallty@(ForAllTy (Bndr _ argf) _ty) =
case argf of
- Required -> synifyVisForAllType vs forallty
- Invisible _ -> synifySigmaType s vs forallty
+ Required -> synifyVisForAllType boundTvs forallty
+ Invisible _ -> synifySigmaType s boundTvs forallty
synifyType _ _ (LitTy t) = noLocA $ HsTyLit noExtField $ synifyTyLit t
-synifyType s vs (CastTy t _) = synifyType s vs t
+synifyType s boundTvs (CastTy t _) = synifyType s boundTvs t
synifyType _ _ (CoercionTy{}) = error "synifyType:Coercion"
-- | Process a 'Type' which starts with a visible @forall@ into an 'HsType'
synifyVisForAllType
- :: [TyVar]
- -- ^ free variables in the type to convert
+ :: TyVarSet
+ -- ^ bound type variables
-> Type
-- ^ the forall type to convert
-> LHsType GhcRn
-synifyVisForAllType vs ty =
+synifyVisForAllType boundTvs ty =
let (tvs, rho) = tcSplitForAllTysReqPreserveSynonyms ty
- sTvs = map synifyTyVarBndr tvs
+ sTvs = map (synifyTyVarBndr' noKindSigTvs) tvs
+ noKindSigTvs = noKindSigTyVars ty
-- Figure out what the type variable order would be inferred in the
-- absence of an explicit forall
- tvs' = orderedFVs (mkVarSet vs) [rho]
+ tvs' = orderedFVs boundTvs [rho]
in noLocA $
HsForAllTy
{ hst_tele = mkHsForAllVisTele noAnn sTvs
, hst_xforall = noExtField
- , hst_body = synifyType WithinType (tvs' ++ vs) rho
+ , hst_body = synifyType WithinType (extendVarSetList boundTvs tvs') rho
}
-- | Process a 'Type' which starts with an invisible @forall@ or a constraint
@@ -948,18 +950,18 @@ synifyVisForAllType vs ty =
synifySigmaType
:: SynifyTypeState
-- ^ what to do with the 'forall'
- -> [TyVar]
- -- ^ free variables in the type to convert
+ -> TyVarSet
+ -- ^ bound type variables
-> Type
-- ^ the forall type to convert
-> LHsType GhcRn
-synifySigmaType s vs ty =
+synifySigmaType s boundTvs ty =
let (tvs, ctx, tau) = tcSplitSigmaTyPreserveSynonyms ty
sPhi =
HsQualTy
{ hst_ctxt = synifyCtx ctx
, hst_xqual = noExtField
- , hst_body = synifyType WithinType (tvs' ++ vs) tau
+ , hst_body = synifyType WithinType (extendVarSetList boundTvs tvs' ) tau
}
sTy =
@@ -969,49 +971,56 @@ synifySigmaType s vs ty =
, hst_body = noLocA sPhi
}
- sTvs = map synifyTyVarBndr tvs
+ sTvs = map (synifyTyVarBndr' noKindSigTvs) tvs
+
+ noKindSigTvs = noKindSigTyVars ty
-- Figure out what the type variable order would be inferred in the
-- absence of an explicit forall
- tvs' = orderedFVs (mkVarSet vs) (ctx ++ [tau])
+ tvs' = orderedFVs boundTvs (ctx ++ [tau])
in case s of
- DeleteTopLevelQuantification -> synifyType ImplicitizeForAll (tvs' ++ vs) tau
+ DeleteTopLevelQuantification -> synifyType ImplicitizeForAll (extendVarSetList boundTvs tvs') tau
-- Put a forall in if there are any type variables
WithinType
| not (null tvs) -> noLocA sTy
| otherwise -> noLocA sPhi
- ImplicitizeForAll -> implicitForAll [] vs tvs ctx (synifyType WithinType) tau
+ ImplicitizeForAll -> implicitForAll boundTvs tvs ctx (synifyType WithinType) tau
--- | Put a forall in if there are any type variables which require
--- explicit kind annotations or if the inferred type variable order
--- would be different.
+-- | Use an explicit forall if there are any type variables which require
+-- explicit kind annotations or if the inferred type variable quantification
+-- order would be different.
implicitForAll
- :: [TyCon]
- -- ^ type constructors that determine their args kinds
- -> [TyVar]
- -- ^ free variables in the type to convert
+ :: TyVarSet
+ -- ^ bound type variables (e.g. bound from an outer scope)
-> [InvisTVBinder]
-- ^ type variable binders in the forall
-> ThetaType
-- ^ constraints right after the forall
- -> ([TyVar] -> Type -> LHsType GhcRn)
+ -> (TyVarSet -> Type -> LHsType GhcRn)
-- ^ how to convert the inner type
-> Type
-- ^ inner type
-> LHsType GhcRn
-implicitForAll tycons vs tvs ctx synInner tau
- | any (isHsKindedTyVar . unLoc) sTvs = noLocA sTy
- | tvs' /= (binderVars tvs) = noLocA sTy
- | otherwise = noLocA sPhi
+implicitForAll boundTvs tvbs ctx synInner tau
+ | any (isHsKindedTyVar . unLoc) sTvs
+ -- Explicit forall: some type variable needs an explicit kind annotation.
+ = noLocA sTy
+ | tvs /= inferredFreeTvs
+ -- Explicit forall: the inferred quantification order would be different.
+ = noLocA sTy
+ | otherwise
+ -- Implicit forall.
+ = noLocA sPhi
where
- sRho = synInner (tvs' ++ vs) tau
+ tvs = binderVars tvbs
+ sRho = synInner (extendVarSetList boundTvs inferredFreeTvs) tau
sPhi
| null ctx = unLoc sRho
| otherwise =
HsQualTy
{ hst_ctxt = synifyCtx ctx
, hst_xqual = noExtField
- , hst_body = synInner (tvs' ++ vs) tau
+ , hst_body = sRho
}
sTy =
HsForAllTy
@@ -1020,84 +1029,129 @@ implicitForAll tycons vs tvs ctx synInner tau
, hst_body = noLocA sPhi
}
- no_kinds_needed = noKindTyVars tycons tau
- sTvs = map (synifyTyVarBndr' no_kinds_needed) tvs
+ no_kinds_needed = noKindSigTyVars tau
+ sTvs = map (synifyTyVarBndr' no_kinds_needed) tvbs
-- Figure out what the type variable order would be inferred in the
-- absence of an explicit forall
- tvs' = orderedFVs (mkVarSet vs) (ctx ++ [tau])
+ inferredFreeTvs = orderedFVs boundTvs (ctx ++ [tau])
--- | Find the set of type variables whose kind signatures can be properly
--- inferred just from their uses in the type signature. This means the type
--- variable to has at least one fully applied use @f x1 x2 ... xn@ where:
+-- | Returns a subset of the free type variables of the given type whose kinds
+-- can definitely be inferred from their occurrences in the type.
--
--- * @f@ has a function kind where the arguments have the same kinds
--- as @x1 x2 ... xn@.
+-- This function is only a simple heuristic, which is used in order to avoid
+-- needlessly cluttering Haddocks with explicit foralls that are not needed.
+-- This function may return some type variables for which we aren't sure
+-- (which will cause us to display the type with an explicit forall, just in
+-- case).
--
--- * @f@ has a function kind whose final return has lifted type kind
-noKindTyVars
- :: [TyCon]
- -- ^ type constructors that determine their args kinds
- -> Type
+-- In the future, we hope to address the issue of whether to print a type with
+-- an explicit forall by storing whether the user wrote the type with an
+-- explicit forall in the first place (see GHC ticket #26271).
+noKindSigTyVars
+ :: Type
-- ^ type to inspect
-> VarSet
- -- ^ set of variables whose kinds can be inferred from uses in the type
-noKindTyVars _ (TyVarTy var)
- | isLiftedTypeKind (tyVarKind var) = unitVarSet var
-noKindTyVars ts ty
- | (f, xs) <- splitAppTys ty
- , not (null xs) =
- let args = map (noKindTyVars ts) xs
- func = case f of
- TyVarTy var
- | (xsKinds, outKind) <- splitFunTys (tyVarKind var)
- , map scaledThing xsKinds `eqTypes` map typeKind xs
- , isLiftedTypeKind outKind ->
- unitVarSet var
- TyConApp t ks
- | t `elem` ts
- , all noFreeVarsOfType ks ->
- mkVarSet [v | TyVarTy v <- xs]
- _ -> noKindTyVars ts f
- in unionVarSets (func : args)
-noKindTyVars ts (ForAllTy _ t) = noKindTyVars ts t
-noKindTyVars ts (FunTy _ w t1 t2) =
- noKindTyVars ts w
- `unionVarSet` noKindTyVars ts t1
- `unionVarSet` noKindTyVars ts t2
-noKindTyVars ts (CastTy t _) = noKindTyVars ts t
-noKindTyVars _ _ = emptyVarSet
-
-synifyMultArrow :: [TyVar] -> Mult -> HsMultAnn GhcRn
-synifyMultArrow vs t = case t of
+ -- ^ set of variables whose kinds can definitely be inferred from occurrences in the type
+noKindSigTyVars ty
+ | Just ty' <- coreView ty
+ = noKindSigTyVars ty'
+ -- In a TyConApp 'T ty_1 ... ty_n', if 'ty_i = tv' is a type variable and the
+ -- i-th argument of the kind of 'T' is monomorphic, then the kind of 'tv'
+ -- is fully determined by its occurrence in the TyConApp.
+ | Just (tc, args) <- splitTyConApp_maybe ty
+ , let (tcArgBndrs, _tcResKi) = splitPiTys (tyConKind tc)
+ tcArgKis = map (\case { Named (Bndr b _) -> tyVarKind b; Anon (Scaled _ t) _ -> t}) tcArgBndrs
+ = mono_tvs tcArgKis args `unionVarSet` (mapUnionVarSet noKindSigTyVars args)
+ -- If we have 'f ty_1 ... ty_n' where 'f :: ki_1 -> ... -> ki_n -> Type'
+ -- then we can infer the kind of 'f' from the kinds of its arguments.
+ --
+ -- This special case handles common examples involving functors, monads...
+ -- with type signatures such as '(a -> b) -> (f a -> f b)'.
+ | (TyVarTy fun, args) <- splitAppTys ty
+ , not (null args)
+ , (funArgKinds, funResKind) <- splitFunTys (tyVarKind fun)
+ , map scaledThing funArgKinds `eqTypes` map typeKind args
+ , isLiftedTypeKind funResKind
+ = ( `extendVarSet` fun ) $ mapUnionVarSet noKindSigTyVars args
+ where
+ mono_tvs :: [Type] -> [Type] -> VarSet
+ mono_tvs (tcArgKi:tcArgKis) (arg:args)
+ | TyVarTy arg_tv <- arg
+ , noFreeVarsOfType tcArgKi
+ = ( `extendVarSet` arg_tv ) $ mono_tvs tcArgKis args
+ | otherwise
+ = mono_tvs tcArgKis args
+ mono_tvs _ _ = emptyVarSet
+noKindSigTyVars (ForAllTy _ t) = noKindSigTyVars t
+noKindSigTyVars (CastTy t _) = noKindSigTyVars t
+noKindSigTyVars _ = emptyVarSet
+
+synifyMultArrow :: TyVarSet -> Mult -> HsMultAnn GhcRn
+synifyMultArrow boundTvs t = case t of
OneTy -> HsLinearAnn noExtField
ManyTy -> HsUnannotated noExtField
- ty -> HsExplicitMult noExtField (synifyType WithinType vs ty)
+ ty -> HsExplicitMult noExtField (synifyType WithinType boundTvs ty)
-synifyMultRec :: [TyVar] -> Mult -> HsMultAnn GhcRn
-synifyMultRec vs t = case t of
+synifyMultRec :: TyVarSet -> Mult -> HsMultAnn GhcRn
+synifyMultRec boundTvs t = case t of
OneTy -> HsUnannotated noExtField
- ty -> HsExplicitMult noExtField (synifyType WithinType vs ty)
+ ty -> HsExplicitMult noExtField (synifyType WithinType boundTvs ty)
synifyPatSynType :: PatSyn -> LHsType GhcRn
synifyPatSynType ps =
- let (univ_tvs, req_theta, ex_tvs, prov_theta, arg_tys, res_ty) = patSynSigBndr ps
- ts = maybeToList (tyConAppTyCon_maybe res_ty)
+ let (univ_tvbs, req_theta, ex_tvbs, prov_theta, arg_tys, res_ty) = patSynSigBndr ps
+
+{- Recall that pattern synonyms have both "required" and "provided" constraints,
+e.g.
+
+ pattern P :: forall a b c. req => forall e f g => prov => arg_ty1 -> ... -> res_ty
+
+Here:
+
+ a, b, c are universal type variables
+ req are required constraints
- -- HACK: a HsQualTy with theta = [unitTy] will be printed as "() =>",
- -- i.e., an explicit empty context, which is what we need. This is not
- -- possible by taking theta = [], as that will print no context at all
+ e, f, g are existential type variables
+ prov are provided constraints
+
+The first pair comes from the outside, while the second pair is obtained upon
+a successful match on the pattern.
+
+Remarks:
+
+ 1. Both foralls are optional.
+
+ 2. If there is only one =>, we interpret the constraints as required.
+ Thus, if we want an empty set of required constraints and a non-empty set
+ of provided constraints, the type signature must be written like
+
+ () => prov => res_ty
+-}
+
+
+ -- Add an explicit "() => ..." when req_theta is empty but there are
+ -- existential variables or provided constraints.
req_theta'
| null req_theta
- , not (null prov_theta && null ex_tvs) =
+ , not (null prov_theta && null ex_tvbs) =
[unitTy]
| otherwise = req_theta
+ univ_tvs = mkVarSet $ binderVars univ_tvbs
+ ex_tvs = mkVarSet $ binderVars ex_tvbs
+
+
in implicitForAll
- ts
- []
- (univ_tvs ++ ex_tvs)
+ ex_tvs -- consider the ex_tvs non-free, so that we don't quantify over them here
+ univ_tvbs -- quantify only over the universals
req_theta'
- (\vs -> implicitForAll ts vs [] prov_theta (synifyType WithinType))
+ ( \_ ->
+ implicitForAll
+ univ_tvs -- the univ_tvs are already bound
+ ex_tvbs -- quantify only over the existentials
+ prov_theta
+ (synifyType WithinType)
+ )
(mkScaledFunTys arg_tys res_ty)
synifyTyLit :: TyLit -> HsTyLit GhcRn
@@ -1106,7 +1160,7 @@ synifyTyLit (StrTyLit s) = HsStrTy NoSourceText s
synifyTyLit (CharTyLit c) = HsCharTy NoSourceText c
synifyKindSig :: Kind -> LHsKind GhcRn
-synifyKindSig k = synifyType WithinType [] k
+synifyKindSig k = synifyType WithinType emptyVarSet k
stripKindSig :: LHsType GhcRn -> LHsType GhcRn
stripKindSig (L _ (HsKindSig _ t _)) = t
@@ -1119,7 +1173,7 @@ synifyInstHead (vs, preds, cls, types) associated_families =
, ihdTypes = map unLoc annot_ts
, ihdInstType =
ClassInst
- { clsiCtx = map (unLoc . synifyType WithinType []) preds
+ { clsiCtx = map (unLoc . synifyType WithinType emptyVarSet) preds
, clsiTyVars = synifyTyVars (tyConVisibleTyVars cls_tycon)
, clsiSigs = map synifyClsIdSig $ specialized_class_methods
, clsiAssocTys =
@@ -1132,7 +1186,7 @@ synifyInstHead (vs, preds, cls, types) associated_families =
where
cls_tycon = classTyCon cls
ts = filterOutInvisibleTypes cls_tycon types
- ts' = map (synifyType WithinType vs) ts
+ ts' = map (synifyType WithinType $ mkVarSet vs) ts
annot_ts = zipWith3 annotHsType args_poly ts ts'
args_poly = tyConArgsPolyKinded cls_tycon
synifyClsIdSig = synifyIdSig ShowRuntimeRep DeleteTopLevelQuantification vs
@@ -1151,7 +1205,7 @@ synifyFamInst fi opaque = do
where
ityp SynFamilyInst | opaque = return $ TypeInst Nothing
ityp SynFamilyInst =
- return . TypeInst . Just . unLoc $ synifyType WithinType [] fam_rhs
+ return . TypeInst . Just . unLoc $ synifyType WithinType emptyVarSet fam_rhs
ityp (DataFamilyInst c) =
DataInst <$> synifyTyCon HideRuntimeRep (Just $ famInstAxiom fi) c
fam_tc = famInstTyCon fi
@@ -1173,7 +1227,7 @@ synifyFamInst fi opaque = do
fam_lhs
ts = filterOutInvisibleTypes fam_tc eta_expanded_lhs
- synifyTypes = map (synifyType WithinType [])
+ synifyTypes = map (synifyType WithinType emptyVarSet)
ts' = synifyTypes ts
annot_ts = zipWith3 annotHsType args_poly ts ts'
args_poly = tyConArgsPolyKinded fam_tc
=====================================
utils/haddock/haddock-api/src/Haddock/GhcUtils.hs
=====================================
@@ -333,9 +333,12 @@ lHsQTyVarsToTypes tvs =
[ HsValArg noExtField $ noLocA (case hsLTyVarName tv of
Nothing -> HsWildCardTy noExtField
Just nm -> HsTyVar noAnn NotPromoted (noLocA $ noUserRdr nm))
- | tv <- hsQTvExplicit tvs
+ | tv <- hsq_explicit tvs
]
+hsQTvExplicitBinders :: LHsQTyVars DocNameI -> [LHsTyVarBndr (HsBndrVis DocNameI) DocNameI]
+hsQTvExplicitBinders = hsq_explicit
+
--------------------------------------------------------------------------------
-- * Making abstract declarations
@@ -853,8 +856,8 @@ tyCoFVsOfType' (TyConApp _ tys) a b c = tyCoFVsOfTypes' tys a b c
tyCoFVsOfType' (LitTy{}) a b c = emptyFV a b c
tyCoFVsOfType' (AppTy fun arg) a b c = (tyCoFVsOfType' arg `unionFV` tyCoFVsOfType' fun) a b c
tyCoFVsOfType' (FunTy _ w arg res) a b c =
- ( tyCoFVsOfType' w
- `unionFV` tyCoFVsOfType' res
+ ( tyCoFVsOfType' res
+ `unionFV` tyCoFVsOfType' w
`unionFV` tyCoFVsOfType' arg
)
a
=====================================
utils/haddock/html-test/ref/Bug1050.html
=====================================
@@ -99,11 +99,7 @@
>mkT</a
> :: <span class="keyword"
>forall</span
- > {k} {f :: <span class="keyword"
- >forall</span
- > k1. k1 -> <a href="#" title="Data.Kind"
- >Type</a
- >} {a :: k}. f a -> <a href="#" title="Bug1050"
+ > {k} {f} {a :: k}. f a -> <a href="#" title="Bug1050"
>T</a
> f a <a href="#" class="selflink"
>#</a
=====================================
utils/haddock/html-test/ref/LinearTypes.html
=====================================
@@ -64,11 +64,7 @@
><li class="src short"
><a href="#"
>poly</a
- > :: <span class="keyword"
- >forall</span
- > a (m :: <a href="#" title="GHC.Exts"
- >Multiplicity</a
- >) b. a %m -> b</li
+ > :: a %m -> b</li
><li class="src short"
><span class="keyword"
>data</span
@@ -163,11 +159,7 @@
><p class="src"
><a id="v:poly" class="def"
>poly</a
- > :: <span class="keyword"
- >forall</span
- > a (m :: <a href="#" title="GHC.Exts"
- >Multiplicity</a
- >) b. a %m -> b <a href="#" class="selflink"
+ > :: a %m -> b <a href="#" class="selflink"
>#</a
></p
><div class="doc"
=====================================
utils/haddock/html-test/ref/PatternSyns.html
=====================================
@@ -132,7 +132,9 @@
>pattern</span
> <a href="#"
>E</a
- > :: a <a href="#" title="PatternSyns"
+ > :: <span class="keyword"
+ >forall</span
+ > {k} {a} {b :: k}. a <a href="#" title="PatternSyns"
>><</a
> b</li
><li class="src short"
@@ -335,7 +337,9 @@
>pattern</span
> <a id="v:E" class="def"
>E</a
- > :: a <a href="#" title="PatternSyns"
+ > :: <span class="keyword"
+ >forall</span
+ > {k} {a} {b :: k}. a <a href="#" title="PatternSyns"
>><</a
> b <a href="#" class="selflink"
>#</a
=====================================
utils/haddock/html-test/ref/PatternSyns2.html
=====================================
@@ -0,0 +1,160 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+ ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+ /><meta name="viewport" content="width=device-width, initial-scale=1"
+ /><title
+ >PatternSyns2</title
+ ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+ /><link rel="stylesheet" type="text/css" href="#"
+ /><link rel="stylesheet" type="text/css" href="#"
+ /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+ ></script
+ ><script type="text/x-mathjax-config"
+ >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+ ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-…" type="text/javascript"
+ ></script
+ ></head
+ ><body
+ ><div id="package-header"
+ ><span class="caption empty"
+ > </span
+ ><ul class="links" id="page-menu"
+ ><li
+ ><a href="#"
+ >Contents</a
+ ></li
+ ><li
+ ><a href="#"
+ >Index</a
+ ></li
+ ></ul
+ ></div
+ ><div id="content"
+ ><div id="module-header"
+ ><table class="info"
+ ><tr
+ ><th
+ >Safe Haskell</th
+ ><td
+ >None</td
+ ></tr
+ ><tr
+ ><th
+ >Language</th
+ ><td
+ >Haskell2010</td
+ ></tr
+ ></table
+ ><p class="caption"
+ >PatternSyns2</p
+ ></div
+ ><div id="interface"
+ ><h1
+ >Documentation</h1
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P1" class="def"
+ >P1</a
+ > :: () => <a href="#" title="Prelude"
+ >Num</a
+ > a => a -> D <a href="#" title="Prelude"
+ >Num</a
+ > a <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P2" class="def"
+ >P2</a
+ > :: <a href="#" title="Prelude"
+ >Num</a
+ > a => a -> a <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P3" class="def"
+ >P3</a
+ > :: () => <span class="keyword"
+ >forall</span
+ > (e :: <a href="#" title="GHC.Exts"
+ >TYPE</a
+ > '<a href="#" title="GHC.Exts"
+ >DoubleRep</a
+ >). <span class="breakable"
+ >(<span class="unbreakable"
+ >PCIR a</span
+ >, <span class="unbreakable"
+ >PCDR e</span
+ >)</span
+ > => a -> e -> Q a <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P4" class="def"
+ >P4</a
+ > :: RCIR a => <span class="keyword"
+ >forall</span
+ > (e :: <a href="#" title="GHC.Exts"
+ >TYPE</a
+ > '<a href="#" title="GHC.Exts"
+ >DoubleRep</a
+ >). <span class="breakable"
+ >(<span class="unbreakable"
+ >PCIR a</span
+ >, <span class="unbreakable"
+ >PCDR e</span
+ >)</span
+ > => a -> e -> Q a <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P5" class="def"
+ >P5</a
+ > :: RCIR a => <span class="keyword"
+ >forall</span
+ > (e :: <a href="#" title="GHC.Exts"
+ >TYPE</a
+ > '<a href="#" title="GHC.Exts"
+ >DoubleRep</a
+ >). a -> e -> Q a <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ><div class="top"
+ ><p class="src"
+ ><span class="keyword"
+ >pattern</span
+ > <a id="v:P" class="def"
+ >P</a
+ > :: () => <span class="keyword"
+ >forall</span
+ > k (a :: k) b. <a href="#" title="Prelude"
+ >Show</a
+ > b => <a href="#" title="Data.Proxy"
+ >Proxy</a
+ > a -> b -> A <a href="#" class="selflink"
+ >#</a
+ ></p
+ ></div
+ ></div
+ ></div
+ ></body
+ ></html
+>
=====================================
utils/haddock/html-test/ref/TypeOperators.html
=====================================
@@ -185,17 +185,7 @@
><p class="src"
><a id="v:biO" class="def"
>biO</a
- > :: <span class="keyword"
- >forall</span
- > (g :: <a href="#" title="Data.Kind"
- >Type</a
- > -> <a href="#" title="Data.Kind"
- >Type</a
- >) (f :: <a href="#" title="Data.Kind"
- >Type</a
- > -> <a href="#" title="Data.Kind"
- >Type</a
- >) a. <a href="#" title="TypeOperators"
+ > :: <a href="#" title="TypeOperators"
>O</a
> g f a <a href="#" class="selflink"
>#</a
=====================================
utils/haddock/html-test/src/PatternSyns2.hs
=====================================
@@ -0,0 +1,60 @@
+{-# LANGUAGE Haskell2010 #-}
+
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE PatternSynonyms #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE StandaloneKindSignatures #-}
+
+module PatternSyns2
+ ( pattern P1, pattern P2, pattern P3, pattern P4, pattern P5
+ , pattern P
+ )
+ where
+
+import Data.Kind
+import Data.Proxy
+import GHC.Exts
+
+type D :: ( Type -> Constraint ) -> Type -> Type
+data D c a where
+ MkD :: c a => a -> D c a
+
+pattern P1 :: () => Num a => a -> D Num a
+pattern P1 a = MkD a
+
+pattern P2 :: Num a => () => a -> a
+pattern P2 a = a
+
+type RCIR :: TYPE IntRep -> Constraint
+class RCIR a where
+
+type PCIR :: TYPE IntRep -> Constraint
+class PCIR a where
+
+type PCDR :: TYPE DoubleRep -> Constraint
+class PCDR a where
+
+type Q :: TYPE IntRep -> Type
+data Q a where
+ MkQ :: forall ( a :: TYPE IntRep ) ( e :: TYPE DoubleRep )
+ . ( PCIR a, PCDR e )
+ => a -> e -> Q a
+
+pattern P3 :: forall (a :: TYPE IntRep). () => forall (e :: TYPE DoubleRep). (PCIR a, PCDR e) => a -> e -> Q a
+pattern P3 a e = MkQ a e
+
+pattern P4 :: forall (a :: TYPE IntRep). (RCIR a) => forall (e :: TYPE DoubleRep). (PCIR a, PCDR e) => a -> e -> Q a
+pattern P4 a e = MkQ a e
+
+pattern P5 :: forall (a :: TYPE IntRep). (RCIR a) => forall (e :: TYPE DoubleRep). () => a -> e -> Q a
+pattern P5 a e <- MkQ a e
+
+
+type A :: Type
+data A where
+ MkA :: forall k (a ::k) b. ( Show b ) => Proxy a -> b -> A
+
+pattern P :: forall . () => forall k (a :: k) b. ( Show b ) => Proxy a -> b -> A
+pattern P a b = MkA a b
=====================================
utils/haddock/latex-test/ref/LinearTypes/LinearTypes.tex
=====================================
@@ -24,7 +24,7 @@ Does something linear.\par}
\end{haddockdesc}
\begin{haddockdesc}
\item[\begin{tabular}{@{}l}
-poly :: forall a (m :: Multiplicity) b. a {\char '45}m -> b
+poly :: a {\char '45}m -> b
\end{tabular}]
{\haddockbegindoc
Does something polymorphic.\par}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b9233b299cdf3970dee2e735b92a05…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b9233b299cdf3970dee2e735b92a05…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/T26625] base: deprecate GHC internals in GHC.Num
by Teo Camarasu (@teo) 12 Dec '25
by Teo Camarasu (@teo) 12 Dec '25
12 Dec '25
Teo Camarasu pushed to branch wip/T26625 at Glasgow Haskell Compiler / GHC
Commits:
90813e70 by Teo Camarasu at 2025-12-12T10:51:35+00:00
base: deprecate GHC internals in GHC.Num
Implements CLC proposal: https://github.com/haskell/core-libraries-committee/issues/360
- - - - -
1 changed file:
- libraries/base/src/GHC/Num.hs
Changes:
=====================================
libraries/base/src/GHC/Num.hs
=====================================
@@ -15,191 +15,366 @@
module GHC.Num
( Num(..)
+ , Integer(..)
+ , Natural(..)
, subtract
, quotRemInteger
- , integerFromNatural
- , integerToNaturalClamp
- , integerToNaturalThrow
- , integerToNatural
- , integerToWord#
- , integerToInt#
- , integerToWord64#
- , integerToInt64#
- , integerAdd
- , integerMul
- , integerSub
- , integerNegate
- , integerAbs
- , integerPopCount#
- , integerQuot
- , integerRem
- , integerDiv
- , integerMod
- , integerDivMod#
- , integerQuotRem#
- , integerEncodeFloat#
- , integerEncodeDouble#
- , integerGcd
- , integerLcm
- , integerAnd
- , integerOr
- , integerXor
- , integerComplement
- , integerBit#
- , integerTestBit#
- , integerShiftL#
- , integerShiftR#
- , integerFromWord#
- , integerFromWord64#
- , integerFromInt64#
- , Integer(..)
- , integerBit
- , integerCheck
- , integerCheck#
- , integerCompare
- , integerDecodeDouble#
- , integerDivMod
- , integerEncodeDouble
- , integerEq
- , integerEq#
- , integerFromAddr
- , integerFromAddr#
- , integerFromBigNat#
- , integerFromBigNatNeg#
- , integerFromBigNatSign#
- , integerFromByteArray
- , integerFromByteArray#
- , integerFromInt
- , integerFromInt#
+ , integerToWord
, integerFromWord
- , integerFromWordList
- , integerFromWordNeg#
- , integerFromWordSign#
- , integerGcde
- , integerGcde#
- , integerGe
- , integerGe#
- , integerGt
- , integerGt#
- , integerIsNegative
- , integerIsNegative#
- , integerIsOne
- , integerIsPowerOf2#
- , integerIsZero
- , integerLe
- , integerLe#
- , integerLog2
- , integerLog2#
- , integerLogBase
- , integerLogBase#
- , integerLogBaseWord
- , integerLogBaseWord#
- , integerLt
- , integerLt#
- , integerNe
- , integerNe#
- , integerOne
- , integerPowMod#
- , integerQuotRem
- , integerRecipMod#
- , integerShiftL
- , integerShiftR
- , integerSignum
- , integerSignum#
- , integerSizeInBase#
- , integerSqr
- , integerTestBit
- , integerToAddr
- , integerToAddr#
- , integerToBigNatClamp#
- , integerToBigNatSign#
, integerToInt
- , integerToMutableByteArray
- , integerToMutableByteArray#
- , integerToWord
- , integerZero
- , naturalToWord#
- , naturalPopCount#
- , naturalShiftR#
- , naturalShiftL#
- , naturalAdd
- , naturalSub
- , naturalSubThrow
- , naturalSubUnsafe
- , naturalMul
- , naturalQuotRem#
- , naturalQuot
- , naturalRem
- , naturalAnd
- , naturalAndNot
- , naturalOr
- , naturalXor
- , naturalTestBit#
- , naturalBit#
- , naturalGcd
- , naturalLcm
- , naturalLog2#
- , naturalLogBaseWord#
- , naturalLogBase#
- , naturalPowMod
- , naturalSizeInBase#
- , Natural(..)
- , naturalBit
- , naturalCheck
- , naturalCheck#
- , naturalClearBit
- , naturalClearBit#
- , naturalCompare
- , naturalComplementBit
- , naturalComplementBit#
- , naturalEncodeDouble#
- , naturalEncodeFloat#
- , naturalEq
- , naturalEq#
- , naturalFromAddr
- , naturalFromAddr#
- , naturalFromBigNat#
- , naturalFromByteArray#
- , naturalFromWord
- , naturalFromWord#
- , naturalFromWord2#
- , naturalFromWordList
- , naturalGe
- , naturalGe#
- , naturalGt
- , naturalGt#
- , naturalIsOne
- , naturalIsPowerOf2#
- , naturalIsZero
- , naturalLe
- , naturalLe#
- , naturalLog2
- , naturalLogBase
- , naturalLogBaseWord
- , naturalLt
- , naturalLt#
- , naturalNe
- , naturalNe#
- , naturalNegate
- , naturalOne
- , naturalPopCount
- , naturalQuotRem
- , naturalSetBit
- , naturalSetBit#
- , naturalShiftL
- , naturalShiftR
- , naturalSignum
- , naturalSqr
- , naturalTestBit
- , naturalToAddr
- , naturalToAddr#
- , naturalToBigNat#
- , naturalToMutableByteArray#
- , naturalToWord
- , naturalToWordClamp
- , naturalToWordClamp#
- , naturalToWordMaybe#
- , naturalZero
+ , integerFromInt
+ , integerToNatural
+ , integerFromNatural
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToNaturalClamp
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToNaturalThrow
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToInt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToWord64#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToInt64#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerAdd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerMul
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerSub
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerNegate
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerAbs
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerPopCount#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerQuot
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerRem
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerDiv
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerMod
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerDivMod#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerQuotRem#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerEncodeFloat#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerEncodeDouble#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGcd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLcm
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerAnd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerOr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerXor
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerComplement
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerTestBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerShiftL#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerShiftR#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromWord64#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromInt64#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerCheck
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerCheck#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerCompare
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerDecodeDouble#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerDivMod
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerEncodeDouble
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerEq
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerEq#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromAddr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromAddr#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromBigNat#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromBigNatNeg#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromBigNatSign#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromByteArray
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromByteArray#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromInt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromWordList
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromWordNeg#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerFromWordSign#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGcde
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGcde#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGt
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerGt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerIsNegative
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerIsNegative#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerIsOne
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerIsPowerOf2#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerIsZero
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLog2
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLog2#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLogBase
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLogBase#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLogBaseWord
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLogBaseWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLt
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerLt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerNe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerNe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerOne
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerPowMod#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerQuotRem
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerRecipMod#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerShiftL
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerShiftR
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerSignum
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerSignum#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerSizeInBase#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerSqr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerTestBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToAddr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToAddr#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToBigNatClamp#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToBigNatSign#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToMutableByteArray
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerToMutableByteArray#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ integerZero
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalPopCount#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalShiftR#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalShiftL#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalAdd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSub
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSubThrow
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSubUnsafe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalMul
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalQuotRem#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalQuot
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalRem
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalAnd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalAndNot
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalOr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalXor
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalTestBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalGcd
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLcm
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLog2#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLogBaseWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLogBase#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalPowMod
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSizeInBase#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalCheck
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalCheck#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalClearBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalClearBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalCompare
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalComplementBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalComplementBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalEncodeDouble#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalEncodeFloat#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalEq
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalEq#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromAddr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromAddr#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromBigNat#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromByteArray#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromWord
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromWord#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromWord2#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalFromWordList
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalGe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalGe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalGt
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalGt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalIsOne
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalIsPowerOf2#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalIsZero
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLog2
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLogBase
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLogBaseWord
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLt
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalLt#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalNe
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalNe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalNegate
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalOne
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalPopCount
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalQuotRem
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSetBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSetBit#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalShiftL
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalShiftR
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSignum
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalSqr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalTestBit
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToAddr
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToAddr#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToBigNat#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToMutableByteArray#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToWord
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToWordClamp
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToWordClamp#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalToWordMaybe#
+ , {-# DEPRECATED ["The internals of big numbers will be removed in base-XXX.", "Use ghc-bignum instead."] #-}
+ naturalZero
)
where
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/90813e70496adc973b7ee7ad9bdd2cc…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/90813e70496adc973b7ee7ad9bdd2cc…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
Simon Peyton Jones pushed to branch wip/T23162-part2 at Glasgow Haskell Compiler / GHC
Commits:
bfff257c by Simon Peyton Jones at 2025-12-12T10:46:55+00:00
Wibbles
- - - - -
4 changed files:
- testsuite/tests/indexed-types/should_fail/T26176.stderr
- testsuite/tests/pmcheck/should_compile/T15753c.hs
- + testsuite/tests/pmcheck/should_compile/T22652.hs
- testsuite/tests/pmcheck/should_compile/all.T
Changes:
=====================================
testsuite/tests/indexed-types/should_fail/T26176.stderr
=====================================
@@ -1,9 +1,7 @@
-T26176.hs:18:7: error: [GHC-83865]
- • Couldn't match type ‘FA t’ with ‘5’
- Expected: SNat 5
- Actual: SNat (FA t)
- • In the expression: b
- In an equation for ‘a’: a = b
+T26176.hs:29:7: error: [GHC-64725]
+ • Cannot satisfy: FA t <= FB t
+ • In the expression: bar @t
+ In an equation for ‘x’: x = bar @t
In an equation for ‘foo’:
foo
= undefined
@@ -14,30 +12,4 @@ T26176.hs:18:7: error: [GHC-83865]
b = undefined
c :: SNat 3
...
- • Relevant bindings include
- b :: SNat (FA t) (bound at T26176.hs:21:3)
- d :: SNat (FB t) (bound at T26176.hs:27:3)
- x :: p0 t (bound at T26176.hs:29:3)
- foo :: p t (bound at T26176.hs:15:1)
-
-T26176.hs:24:7: error: [GHC-83865]
- • Couldn't match type ‘FB t’ with ‘3’
- Expected: SNat 3
- Actual: SNat (FB t)
- • In the expression: d
- In an equation for ‘c’: c = d
- In an equation for ‘foo’:
- foo
- = undefined
- where
- a :: SNat 5
- a = b
- b :: SNat (FA t)
- b = undefined
- c :: SNat 3
- ...
- • Relevant bindings include
- d :: SNat (FB t) (bound at T26176.hs:27:3)
- x :: p0 t (bound at T26176.hs:29:3)
- foo :: p t (bound at T26176.hs:15:1)
=====================================
testsuite/tests/pmcheck/should_compile/T15753c.hs
=====================================
@@ -34,6 +34,22 @@ type family F (u1 :: ()) (u2 :: ()) :: Type where
type family Case (u :: ()) :: Type where
Case '() = Int
+---------------------------------------
+-- The checker can (now, Dec 25) see that (F u1 u2 ~ Char) is
+-- unsatisfiable, so the empty pattern match is fine
+g1a :: F u1 u2 :~: Char -> SUnit u1 -> SUnit u2 -> Void
+g1a r _ _ = case r of {}
+
+{- Why [G] F u1 u2 ~ Char is unsatisfiable
+
+[G] F u1 u2 ~ Char =>rewrite [G] If (IsUnit u1) (Case u2) Int ~ Char
+ =>(fundep) [W] IsUnit u1 ~ True
+ [W] Case u2 ~ Char <<-- insoluble: no relevant eqns
+-}
+
+---------------------------------------
+-- This older test matches on Refl (which is unsatisfiable)
+-- but we now get complaints from inside
g1 :: F u1 u2 :~: Char
-> SUnit u1 -> SUnit u2
-> Void
@@ -41,21 +57,7 @@ g1 Refl su1 su2
| STrue <- sIsUnit su1
= case su2 of {}
--- g1a :: F u1 u2 :~: Char -> SUnit u1 -> SUnit u2 -> Void
--- g1a r _ _ = case r of {} -- Why does this complain about missing Refl
-{- [G] F u1 u2 ~ Char
- [W] SBool (IsUnit u1) ~ SBool True
-==>
- [W] IsUnit u1 ~ True
-==> fundep
- u1 ~ ()
-
-
-[G] F u1 u2 ~ Char =>(fundep) [W] If (IsUnit u1) (Case u2) Int ~ Char
- =>(fundep) [W] IsUnit u1 ~ True
- [W] Case u2 ~ Char <<-- insoluble: no relevant eqns
--}
g2 :: F u1 u2 :~: Char
-> SUnit u1 -> SUnit u2
@@ -64,4 +66,3 @@ g2 Refl su1 su2
= case sIsUnit su1 of
STrue ->
case su2 of {}
-
=====================================
testsuite/tests/pmcheck/should_compile/T22652.hs
=====================================
@@ -0,0 +1,17 @@
+{-# LANGUAGE DataKinds, TypeFamilies, GADTs #-}
+{-# OPTIONS_GHC -Wincomplete-patterns -Werror #-}
+
+module T22652 where
+
+data T = Z | S
+
+data ST n where
+ SZ :: ST Z
+ SS :: ST S
+
+type family F n where
+ F Z = Z
+ F S = Z
+
+f :: F m ~ n => ST m -> ST n -> ()
+f _ SZ = ()
=====================================
testsuite/tests/pmcheck/should_compile/all.T
=====================================
@@ -179,3 +179,4 @@ test('T24824', normal, compile, ['-package ghc -Wincomplete-record-selectors'])
test('T24891', normal, compile, ['-Wincomplete-record-selectors'])
test('T25257', normal, compile, [overlapping_incomplete])
test('T24845', [], compile, [overlapping_incomplete])
+test('T22652', [], compile, [overlapping_incomplete])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bfff257ca6d35572eec23ae84a8cb87…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bfff257ca6d35572eec23ae84a8cb87…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/ci-note-treeless] 3 commits: compiler: remove unused CPP code in foreign stub
by Magnus (@MangoIV) 12 Dec '25
by Magnus (@MangoIV) 12 Dec '25
12 Dec '25
Magnus pushed to branch wip/ci-note-treeless at Glasgow Haskell Compiler / GHC
Commits:
d99f8326 by Cheng Shao at 2025-12-11T19:14:18-05:00
compiler: remove unused CPP code in foreign stub
This patch removes unused CPP code in the generated foreign stub:
- `#define IN_STG_CODE 0` is not needed, since `Rts.h` already
includes this definition
- The `if defined(__cplusplus)` code paths are not needed in the `.c`
file, since we don't generate C++ stubs and don't include C++
headers in our stubs. But it still needs to be present in the `.h`
header since it might be later included into C++ source files.
- - - - -
46c9746f by Cheng Shao at 2025-12-11T19:14:57-05:00
configure: bump LlvmMaxVersion to 22
This commit bumps LlvmMaxVersion to 22; 21.x releases have been
available since Aug 26th, 2025 and there's no regressions with 21.x so
far. This bump is also required for updating fedora image to 43.
- - - - -
495389d3 by Cheng Shao at 2025-12-12T09:01:59+00:00
ci: use treeless fetch for perf notes
This patch improves the ci logic for fetching perf notes by using
treeless fetch
(https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-…)
to avoid downloading all blobs of the perf notes repo at once, and
only fetch the actually required blobs on-demand when needed. This
makes the initial `test-metrics.sh pull` operation much faster, and
also more robust, since we are seeing an increasing rate of 504 errors
in CI when fetching all perf notes at once, which is a major source of
CI flakiness at this point.
Co-authored-by: Codex <codex(a)openai.com>
- - - - -
3 changed files:
- .gitlab/test-metrics.sh
- compiler/GHC/Driver/CodeOutput.hs
- configure.ac
Changes:
=====================================
.gitlab/test-metrics.sh
=====================================
@@ -17,12 +17,14 @@ fail() {
function pull() {
local ref="refs/notes/$REF"
- # 2023-10-04: `git fetch` started failing, first on Darwin in CI and then on
- # Linux locally, both using git version 2.40.1. See #24055. One workaround is
- # to set a larger http.postBuffer, although this is definitely a workaround.
- # The default should work just fine. The error could be in git, GitLab, or
- # perhaps the networking tube (including all proxies etc) between the two.
- run git -c http.postBuffer=2097152 fetch -f "$NOTES_ORIGIN" "$ref:$ref"
+
+ # Fetch performance notes from a dedicated promisor remote using a
+ # treeless filter, so that individual note blobs are fetched lazily
+ # as needed.
+ git remote add perf-notes "$NOTES_ORIGIN" || true
+ git config fetch.recurseSubmodules false
+ git config remote.perf-notes.partialclonefilter tree:0
+ run git fetch --force perf-notes "$ref:$ref"
echo "perf notes ref $ref is $(git rev-parse $ref)"
}
@@ -81,4 +83,3 @@ case $1 in
pull) pull ;;
*) fail "Invalid mode $1" ;;
esac
-
=====================================
compiler/GHC/Driver/CodeOutput.hs
=====================================
@@ -329,15 +329,8 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs
stub_c_file_exists
<- outputForeignStubs_help stub_c stub_c_output_w
- ("#define IN_STG_CODE 0\n" ++
- "#include <Rts.h>\n" ++
- rts_includes ++
- ffi_includes ++
- cplusplus_hdr)
- cplusplus_ftr
- -- We're adding the default hc_header to the stub file, but this
- -- isn't really HC code, so we need to define IN_STG_CODE==0 to
- -- avoid the register variables etc. being enabled.
+ (rts_includes ++
+ ffi_includes) ""
return (stub_h_file_exists, if stub_c_file_exists
then Just stub_c
=====================================
configure.ac
=====================================
@@ -526,7 +526,7 @@ AC_SUBST(InstallNameToolCmd)
# versions of LLVM simultaneously, but that stopped working around
# 3.5/3.6 release of LLVM.
LlvmMinVersion=13 # inclusive
-LlvmMaxVersion=21 # not inclusive
+LlvmMaxVersion=22 # not inclusive
AC_SUBST([LlvmMinVersion])
AC_SUBST([LlvmMaxVersion])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/505caf1d6a41fe339dfec41c9e81a7…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/505caf1d6a41fe339dfec41c9e81a7…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 11 commits: compiler: remove unused CPP code in foreign stub
by Marge Bot (@marge-bot) 12 Dec '25
by Marge Bot (@marge-bot) 12 Dec '25
12 Dec '25
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
d99f8326 by Cheng Shao at 2025-12-11T19:14:18-05:00
compiler: remove unused CPP code in foreign stub
This patch removes unused CPP code in the generated foreign stub:
- `#define IN_STG_CODE 0` is not needed, since `Rts.h` already
includes this definition
- The `if defined(__cplusplus)` code paths are not needed in the `.c`
file, since we don't generate C++ stubs and don't include C++
headers in our stubs. But it still needs to be present in the `.h`
header since it might be later included into C++ source files.
- - - - -
46c9746f by Cheng Shao at 2025-12-11T19:14:57-05:00
configure: bump LlvmMaxVersion to 22
This commit bumps LlvmMaxVersion to 22; 21.x releases have been
available since Aug 26th, 2025 and there's no regressions with 21.x so
far. This bump is also required for updating fedora image to 43.
- - - - -
96fce8d0 by Cheng Shao at 2025-12-12T01:17:51+01:00
hadrian: add support for building with UndefinedBehaviorSanitizer
This patch adds a +ubsan flavour transformer to hadrian to build all
stage1+ C/C++ code with UndefinedBehaviorSanitizer. This is
particularly useful to catch potential undefined behavior in the RTS
codebase.
- - - - -
f7a06d8c by Cheng Shao at 2025-12-12T01:17:51+01:00
ci: update alpine/fedora & add ubsan job
This patch updates alpine image to 3.23, fedora image to 43, and adds
a `x86_64-linux-fedora43-validate+debug_info+ubsan` job that's run in
validate/nightly pipelines to catch undefined behavior in the RTS
codebase.
- - - - -
2ccd11ca by Cheng Shao at 2025-12-12T01:17:51+01:00
rts: fix zero-length VLA undefined behavior in interpretBCO
This commit fixes a zero-length VLA undefined behavior in interpretBCO, caught by UBSan:
```
+rts/Interpreter.c:3133:19: runtime variable length array bound evaluates to non-positive value 0
```
- - - - -
4156ed19 by Cheng Shao at 2025-12-12T01:17:51+01:00
rts: fix unaligned ReadSpB in interpretBCO
This commit fixes unaligned ReadSpB in interpretBCO, caught by UBSan:
```
+rts/Interpreter.c:2174:64: runtime load of misaligned address 0x004202059dd1 for type 'StgWord', which requires 8 byte alignment
```
To perform proper unaligned read, we define StgUnalignedWord as a type
alias of StgWord with aligned(1) attribute, and load StgUnalignedWord
instead of StgWord in ReadSpB, so the C compiler is aware that we're
not loading with natural alignment.
- - - - -
fef89fb9 by Cheng Shao at 2025-12-12T01:17:51+01:00
rts: fix signed integer overflow in subword arithmetic in interpretBCO
This commit fixes signed integer overflow in subword arithmetic in
interpretBCO, see added note for detailed explanation.
- - - - -
2a5bc4ba by sheaf at 2025-12-12T02:56:17-05:00
X86 CodeGen: fix assign_eax_sse_regs
We must set %al to the number of SSE2 registers that contain arguments
(in case we are dealing with a varargs function). The logic for counting
how many arguments reside in SSE2 registers was incorrect, as it used
'isFloatFormat', which incorrectly ignores vector registers.
We now instead do case analysis on the register class:
is_sse_reg r =
case targetClassOfReg platform r of
RcFloatOrVector -> True
RcInteger -> False
This change is necessary to prevent segfaults in T20030_test1j, because
subsequent commits change the format calculations, resulting in vector
formats more often.
- - - - -
feb9b195 by sheaf at 2025-12-12T02:56:17-05:00
Liveness analysis: consider register formats
This commit updates the register allocator to be a bit more careful in
situations in which a single register is used at multiple different
formats, e.g. when xmm1 is used both to store a Double# and a DoubleX2#.
This is done by introducing the 'Regs' newtype around 'UniqSet RegWithFormat',
for which the combining operations take the larger of the two formats
instead of overriding the format.
Operations on 'Regs' are defined in 'GHC.CmmToAsm.Reg.Regs'. There is
a modest compile-time cost for the additional overhead for tracking
register formats, which causes the metric increases of this commit.
The subtle aspects of the implementation are outlined in
Note [Register formats in liveness analysis] in GHC.CmmToAsm.Reg.Liveness.
Fixes #26411 #26611
-------------------------
Metric Increase:
T12707
T26425
T3294
-------------------------
- - - - -
36ee30f3 by sheaf at 2025-12-12T02:56:17-05:00
Register allocator: reload at same format as spill
This commit ensures that if we spill a register onto the stack at a
given format, we then always reload the register at this same format.
This ensures we don't end up in a situation where we spill F64x2 but end
up only reloading the lower F64. This first reload would make us believe
the whole data is in a register, thus silently losing the upper 64 bits
of the spilled register's contents.
Fixes #26526
- - - - -
02c25c49 by sheaf at 2025-12-12T02:56:17-05:00
Register allocation: writes redefine format
As explained in Note [Allocated register formats] in GHC.CmmToAsm.Reg.Linear,
we consider all writes to redefine the format of the register.
This ensures that in a situation such as
movsd .Ln6m(%rip),%v1
shufpd $0,%v1,%v1
we properly consider the broadcast operation to change the format of %v1
from F64 to F64x2.
This completes the fix to #26411 (test in T26411b).
- - - - -
35 changed files:
- .gitlab-ci.yml
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- .gitlab/rel_eng/fetch-gitlab-artifacts/fetch_gitlab.py
- .gitlab/rel_eng/mk-ghcup-metadata/mk_ghcup_metadata.py
- compiler/GHC/CmmToAsm/Reg/Graph.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Coalesce.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Spill.hs
- compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Linear/Base.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/Reg/Liveness.hs
- + compiler/GHC/CmmToAsm/Reg/Regs.hs
- compiler/GHC/CmmToAsm/Reg/Target.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Driver/CodeOutput.hs
- compiler/GHC/Types/Unique/FM.hs
- compiler/GHC/Types/Unique/Set.hs
- compiler/ghc.cabal.in
- configure.ac
- hadrian/doc/flavours.md
- hadrian/src/Flavour.hs
- + rts/.ubsan-suppressions
- rts/Interpreter.c
- rts/include/stg/Types.h
- rts/rts.cabal
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- + testsuite/tests/simd/should_run/T26411.hs
- + testsuite/tests/simd/should_run/T26411.stdout
- + testsuite/tests/simd/should_run/T26411b.hs
- + testsuite/tests/simd/should_run/T26411b.stdout
- testsuite/tests/simd/should_run/all.T
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2f18fba74b3878fcd0c4ae352611ed…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2f18fba74b3878fcd0c4ae352611ed…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
12 Dec '25
Cheng Shao pushed new branch wip/terrorjack/asan at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/terrorjack/asan
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc] Pushed new branch wip/torsten.schmits/mwb/perf-tuning
by Torsten Schmits (@torsten.schmits) 12 Dec '25
by Torsten Schmits (@torsten.schmits) 12 Dec '25
12 Dec '25
Torsten Schmits pushed new branch wip/torsten.schmits/mwb/perf-tuning at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/torsten.schmits/mwb/perf-tuni…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/torsten.schmits/mwb-25-07/perf-tuning] 4 commits: Various downsweep perf tweaks
by Torsten Schmits (@torsten.schmits) 12 Dec '25
by Torsten Schmits (@torsten.schmits) 12 Dec '25
12 Dec '25
Torsten Schmits pushed to branch wip/torsten.schmits/mwb-25-07/perf-tuning at Glasgow Haskell Compiler / GHC
Commits:
fd00538d by Matthew Pickering at 2025-12-12T01:48:57+01:00
Various downsweep perf tweaks
- - - - -
f2fab894 by Torsten Schmits at 2025-12-12T01:48:57+01:00
Abstract out parts of mkUnitState into a handler type
- - - - -
8a88d4ee by Torsten Schmits at 2025-12-12T01:48:57+01:00
Abstract out module provider queries into a handler type
- - - - -
66c776ea by Torsten Schmits at 2025-12-12T01:48:57+01:00
Use unit index for name printing
- - - - -
25 changed files:
- compiler/GHC.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/HsToCore.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Runtime/Context.hs
- compiler/GHC/Runtime/Loader.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Types/Name/Ppr.hs
- compiler/GHC/Unit/Env.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Module/Graph.hs
- compiler/GHC/Unit/State.hs
- compiler/cbits/genSym.c
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Monad.hs
- ghc/Main.hs
Changes:
=====================================
compiler/GHC.hs
=====================================
@@ -341,7 +341,7 @@ import GHC.Builtin.Types.Prim ( alphaTyVars )
import GHC.Data.StringBuffer
import GHC.Data.FastString
import qualified GHC.LanguageExtensions as LangExt
-import GHC.Rename.Names (renamePkgQual, renameRawPkgQual, gresFromAvails)
+import GHC.Rename.Names (gresFromAvails, hscRenamePkgQual, hscRenameRawPkgQual)
import GHC.Tc.Utils.Monad ( finalSafeMode, fixSafeInstances, initIfaceTcRn )
import GHC.Tc.Types
@@ -625,7 +625,8 @@ setUnitDynFlagsNoCheck uid dflags1 = do
let old_hue = ue_findHomeUnitEnv uid (hsc_unit_env hsc_env)
let cached_unit_dbs = homeUnitEnv_unit_dbs old_hue
- (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 cached_unit_dbs (hsc_all_home_unit_ids hsc_env)
+ index <- hscUnitIndex <$> getSession
+ (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 index cached_unit_dbs (hsc_all_home_unit_ids hsc_env)
updated_dflags <- liftIO $ updatePlatformConstants dflags1 mconstants
let upd hue =
@@ -760,6 +761,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
then do
-- additionally, set checked dflags so we don't lose fixes
old_unit_env <- ue_setFlags dflags0 . hsc_unit_env <$> getSession
+ ue_index <- hscUnitIndex <$> getSession
home_unit_graph <- forM (ue_home_unit_graph old_unit_env) $ \homeUnitEnv -> do
let cached_unit_dbs = homeUnitEnv_unit_dbs homeUnitEnv
@@ -767,7 +769,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
old_hpt = homeUnitEnv_hpt homeUnitEnv
home_units = unitEnv_keys (ue_home_unit_graph old_unit_env)
- (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags cached_unit_dbs home_units
+ (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags ue_index cached_unit_dbs home_units
updated_dflags <- liftIO $ updatePlatformConstants dflags0 mconstants
pure HomeUnitEnv
@@ -785,6 +787,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
, ue_home_unit_graph = home_unit_graph
, ue_current_unit = ue_currentUnit old_unit_env
, ue_eps = ue_eps old_unit_env
+ , ue_index
}
modifySession $ \h -> hscSetFlags dflags1 h{ hsc_unit_env = unit_env }
else modifySession (hscSetFlags dflags0)
@@ -1379,7 +1382,8 @@ getInsts = withSession $ \hsc_env ->
getNamePprCtx :: GhcMonad m => m NamePprCtx
getNamePprCtx = withSession $ \hsc_env -> do
- return $ icNamePprCtx (hsc_unit_env hsc_env) (hsc_IC hsc_env)
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ return $ icNamePprCtx (hsc_unit_env hsc_env) query (hsc_IC hsc_env)
-- | Container for information about a 'Module'.
data ModuleInfo = ModuleInfo {
@@ -1474,7 +1478,8 @@ mkNamePprCtxForModule ::
ModuleInfo ->
m NamePprCtx
mkNamePprCtxForModule mod minf = withSession $ \hsc_env -> do
- let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) (availsToGlobalRdrEnv hsc_env mod (minf_exports minf))
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query (availsToGlobalRdrEnv hsc_env mod (minf_exports minf))
ptc = initPromotionTickContext (hsc_dflags hsc_env)
return name_ppr_ctx
@@ -1711,10 +1716,10 @@ modNotLoadedError dflags m loc = throwGhcExceptionIO $ CmdLineError $ showSDoc d
parens (text (expectJust "modNotLoadedError" (ml_hs_file loc)))
renamePkgQualM :: GhcMonad m => ModuleName -> Maybe FastString -> m PkgQual
-renamePkgQualM mn p = withSession $ \hsc_env -> pure (renamePkgQual (hsc_unit_env hsc_env) mn p)
+renamePkgQualM mn p = withSession $ \hsc_env -> hscRenamePkgQual hsc_env mn p
renameRawPkgQualM :: GhcMonad m => ModuleName -> RawPkgQual -> m PkgQual
-renameRawPkgQualM mn p = withSession $ \hsc_env -> pure (renameRawPkgQual (hsc_unit_env hsc_env) mn p)
+renameRawPkgQualM mn p = withSession $ \hsc_env -> hscRenameRawPkgQual hsc_env mn p
-- | Like 'findModule', but differs slightly when the module refers to
-- a source file, and the file has not been loaded via 'load'. In
@@ -1738,7 +1743,8 @@ lookupQualifiedModule NoPkgQual mod_name = withSession $ \hsc_env -> do
let units = hsc_units hsc_env
let dflags = hsc_dflags hsc_env
let fopts = initFinderOpts dflags
- res <- findExposedPackageModule fc fopts units mod_name NoPkgQual
+ query <- hscUnitIndexQuery hsc_env
+ res <- findExposedPackageModule fc fopts units query mod_name NoPkgQual
case res of
Found _ m -> return m
err -> throwOneError $ noModError hsc_env noSrcSpan mod_name err
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -78,6 +78,8 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
, mg_rdr_env = rdr_env })
= do { let builtin_passes = getCoreToDo dflags hpt_rule_base extra_vars
uniq_tag = 's'
+ ; query <- hscUnitIndexQuery hsc_env
+ ; let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query rdr_env
; (guts2, stats) <- runCoreM hsc_env hpt_rule_base uniq_tag mod
name_ppr_ctx loc $
@@ -100,7 +102,6 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
home_pkg_rules = hptRules hsc_env (moduleUnitId mod) (GWIB { gwib_mod = moduleName mod
, gwib_isBoot = NotBoot })
hpt_rule_base = mkRuleBase home_pkg_rules
- name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) rdr_env
ptc = initPromotionTickContext dflags
-- mod: get the module out of the current HscEnv so we can retrieve it from the monad.
-- This is very convienent for the users of the monad (e.g. plugins do not have to
@@ -459,6 +460,7 @@ doCorePass pass guts = do
dflags <- getDynFlags
us <- getUniqueSupplyM
p_fam_env <- getPackageFamInstEnv
+ query <- liftIO $ hscUnitIndexQuery hsc_env
let platform = targetPlatform dflags
let fam_envs = (p_fam_env, mg_fam_inst_env guts)
let updateBinds f = return $ guts { mg_binds = f (mg_binds guts) }
@@ -471,6 +473,7 @@ doCorePass pass guts = do
mkNamePprCtx
(initPromotionTickContext dflags)
(hsc_unit_env hsc_env)
+ query
rdr_env
=====================================
compiler/GHC/Driver/Backpack.hs
=====================================
@@ -429,6 +429,7 @@ addUnit u = do
logger <- getLogger
let dflags0 = hsc_dflags hsc_env
let old_unit_env = hsc_unit_env hsc_env
+ ue_index = hscUnitIndex hsc_env
newdbs <- case ue_unit_dbs old_unit_env of
Nothing -> panic "addUnit: called too early"
Just dbs ->
@@ -437,7 +438,7 @@ addUnit u = do
, unitDatabaseUnits = [u]
}
in return (dbs ++ [newdb]) -- added at the end because ordering matters
- (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags0 (Just newdbs) (hsc_all_home_unit_ids hsc_env)
+ (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags0 ue_index (Just newdbs) (hsc_all_home_unit_ids hsc_env)
-- update platform constants
dflags <- liftIO $ updatePlatformConstants dflags0 mconstants
@@ -452,6 +453,7 @@ addUnit u = do
(homeUnitId home_unit)
(mkHomeUnitEnv dflags (ue_hpt old_unit_env) (Just home_unit))
, ue_eps = ue_eps old_unit_env
+ , ue_index
}
setSession $ hscSetFlags dflags $ hsc_env { hsc_unit_env = unit_env }
@@ -870,6 +872,8 @@ hsModuleToModSummary home_keys pn hsc_src modname
hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file location)
hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file location)
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+
-- Also copied from 'getImports'
let (src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource . unLoc) imps
@@ -882,7 +886,7 @@ hsModuleToModSummary home_keys pn hsc_src modname
implicit_imports = mkPrelImports modname loc
implicit_prelude imps
- rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) modname
+ rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query modname
convImport (L _ i) = (rn_pkg_qual (ideclPkgQual i), reLoc $ ideclName i)
extra_sig_imports <- liftIO $ findExtraSigImports hsc_env hsc_src modname
=====================================
compiler/GHC/Driver/Env.hs
=====================================
@@ -7,6 +7,8 @@ module GHC.Driver.Env
, hsc_home_unit
, hsc_home_unit_maybe
, hsc_units
+ , hscUnitIndex
+ , hscUnitIndexQuery
, hsc_HPT
, hsc_HUE
, hsc_HUG
@@ -118,6 +120,13 @@ hsc_home_unit_maybe = ue_homeUnit . hsc_unit_env
hsc_units :: HasDebugCallStack => HscEnv -> UnitState
hsc_units = ue_units . hsc_unit_env
+hscUnitIndex :: HscEnv -> UnitIndex
+hscUnitIndex = ue_index . hsc_unit_env
+
+hscUnitIndexQuery :: HscEnv -> IO UnitIndexQuery
+hscUnitIndexQuery hsc_env =
+ unitIndexQuery (hscUnitIndex hsc_env) (hscActiveUnitId hsc_env)
+
hsc_HPT :: HscEnv -> HomePackageTable
hsc_HPT = ue_hpt . hsc_unit_env
=====================================
compiler/GHC/Driver/Main.hs
=====================================
@@ -2665,9 +2665,10 @@ hscTidy hsc_env guts = do
$! {-# SCC "CoreTidy" #-} tidyProgram opts guts
-- post tidy pretty-printing and linting...
+ query <- hscUnitIndexQuery hsc_env
let tidy_rules = md_rules details
let all_tidy_binds = cg_binds cgguts
- let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) (mg_rdr_env guts)
+ let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query (mg_rdr_env guts)
ptc = initPromotionTickContext (hsc_dflags hsc_env)
endPassHscEnvIO hsc_env name_ppr_ctx CoreTidy all_tidy_binds tidy_rules
=====================================
compiler/GHC/Driver/Make.hs
=====================================
@@ -114,6 +114,8 @@ import Data.Either ( rights, partitionEithers, lefts )
import qualified Data.Map as Map
import qualified Data.Set as Set
+import GHC.Data.OsPath (OsPath)
+import qualified GHC.Data.OsPath as OsPath
import Control.Concurrent ( newQSem, waitQSem, signalQSem, ThreadId, killThread, forkIOWithUnmask )
import qualified GHC.Conc as CC
import Control.Concurrent.MVar
@@ -188,12 +190,13 @@ depanalE excluded_mods allow_dup_roots = do
if isEmptyMessages errs
then do
hsc_env <- getSession
+ query <- liftIO $ hscUnitIndexQuery hsc_env
let one_unit_messages get_mod_errs k hue = do
errs <- get_mod_errs
unknown_module_err <- warnUnknownModules (hscSetActiveUnitId k hsc_env) (homeUnitEnv_dflags hue) mod_graph
let unused_home_mod_err = warnMissingHomeModules (homeUnitEnv_dflags hue) (hsc_targets hsc_env) mod_graph
- unused_pkg_err = warnUnusedPackages (homeUnitEnv_units hue) (homeUnitEnv_dflags hue) mod_graph
+ unused_pkg_err = warnUnusedPackages (homeUnitEnv_units hue) query (homeUnitEnv_dflags hue) mod_graph
return $ errs `unionMessages` unused_home_mod_err
@@ -245,7 +248,7 @@ depanalPartial excluded_mods allow_dup_roots = do
liftIO $ flushFinderCaches (hsc_FC hsc_env) (hsc_unit_env hsc_env)
(errs, graph_nodes) <- liftIO $ downsweep
- hsc_env (mgModSummaries old_graph)
+ hsc_env (mgModSummaries old_graph) Nothing
excluded_mods allow_dup_roots
let
mod_graph = mkModuleGraph graph_nodes
@@ -511,15 +514,15 @@ loadWithCache cache diag_wrapper how_much = do
-- actually loaded packages. All the packages, specified on command line,
-- but never loaded, are probably unused dependencies.
-warnUnusedPackages :: UnitState -> DynFlags -> ModuleGraph -> DriverMessages
-warnUnusedPackages us dflags mod_graph =
+warnUnusedPackages :: UnitState -> UnitIndexQuery -> DynFlags -> ModuleGraph -> DriverMessages
+warnUnusedPackages us query dflags mod_graph =
let diag_opts = initDiagOpts dflags
home_mod_sum = filter (\ms -> homeUnitId_ dflags == ms_unitid ms) (mgModSummaries mod_graph)
-- Only need non-source imports here because SOURCE imports are always HPT
loadedPackages = concat $
- mapMaybe (\(fs, mn) -> lookupModulePackage us (unLoc mn) fs)
+ mapMaybe (\(fs, mn) -> lookupModulePackage us query (unLoc mn) fs)
$ concatMap ms_imps home_mod_sum
any_import_ghc_prim = any ms_ghc_prim_import home_mod_sum
@@ -1539,6 +1542,10 @@ warnUnnecessarySourceImports sccs = do
-- an import of this module mean.
type DownsweepCache = M.Map (UnitId, PkgQual, ModuleNameWithIsBoot) [Either DriverMessages ModSummary]
+moduleGraphNodeMap :: ModuleGraph -> M.Map NodeKey ModuleGraphNode
+moduleGraphNodeMap graph =
+ M.fromList [(mkNodeKey node, node) | node <- mgModSummaries' graph]
+
-----------------------------------------------------------------------------
--
-- | Downsweep (dependency analysis)
@@ -1557,6 +1564,8 @@ type DownsweepCache = M.Map (UnitId, PkgQual, ModuleNameWithIsBoot) [Either Driv
downsweep :: HscEnv
-> [ModSummary]
-- ^ Old summaries
+ -> Maybe ModuleGraph
+ -- ^ Existing module graph to reuse cached nodes from
-> [ModuleName] -- Ignore dependencies on these; treat
-- them as if they were package modules
-> Bool -- True <=> allow multiple targets to have
@@ -1566,10 +1575,10 @@ downsweep :: HscEnv
-- The non-error elements of the returned list all have distinct
-- (Modules, IsBoot) identifiers, unless the Bool is true in
-- which case there can be repeats
-downsweep hsc_env old_summaries excl_mods allow_dup_roots = do
+downsweep hsc_env old_summaries old_graph excl_mods allow_dup_roots = do
n_jobs <- mkWorkerLimit (hsc_dflags hsc_env)
new <- rootSummariesParallel n_jobs hsc_env summary
- downsweep_imports hsc_env old_summary_map excl_mods allow_dup_roots new
+ downsweep_imports hsc_env old_summary_map old_graph excl_mods allow_dup_roots new
where
summary = getRootSummary excl_mods old_summary_map
@@ -1578,22 +1587,23 @@ downsweep hsc_env old_summaries excl_mods allow_dup_roots = do
-- file was used in.
-- Reuse these if we can because the most expensive part of downsweep is
-- reading the headers.
- old_summary_map :: M.Map (UnitId, FilePath) ModSummary
+ old_summary_map :: M.Map (UnitId, OsPath) ModSummary
old_summary_map =
- M.fromList [((ms_unitid ms, msHsFilePath ms), ms) | ms <- old_summaries]
+ M.fromList [((ms_unitid ms, OsPath.unsafeEncodeUtf (msHsFilePath ms)), ms) | ms <- old_summaries]
downsweep_imports :: HscEnv
- -> M.Map (UnitId, FilePath) ModSummary
+ -> M.Map (UnitId, OsPath) ModSummary
+ -> Maybe ModuleGraph
-> [ModuleName]
-> Bool
-> ([(UnitId, DriverMessages)], [ModSummary])
-> IO ([DriverMessages], [ModuleGraphNode])
-downsweep_imports hsc_env old_summaries excl_mods allow_dup_roots (root_errs, rootSummariesOk)
+downsweep_imports hsc_env old_summaries old_graph excl_mods allow_dup_roots (root_errs, rootSummariesOk)
= do
let root_map = mkRootMap rootSummariesOk
checkDuplicates root_map
- (deps, map0) <- loopSummaries rootSummariesOk (M.empty, root_map)
- let closure_errs = checkHomeUnitsClosed (hsc_unit_env hsc_env)
+ let done0 = maybe M.empty moduleGraphNodeMap old_graph
+ (deps, map0) <- loopSummaries rootSummariesOk (done0, root_map)
let unit_env = hsc_unit_env hsc_env
let tmpfs = hsc_tmpfs hsc_env
@@ -1603,7 +1613,7 @@ downsweep_imports hsc_env old_summaries excl_mods allow_dup_roots (root_errs, ro
(other_errs, unit_nodes) = partitionEithers $ unitEnv_foldWithKey (\nodes uid hue -> nodes ++ unitModuleNodes downsweep_nodes uid hue) [] (hsc_HUG hsc_env)
all_nodes = downsweep_nodes ++ unit_nodes
all_errs = all_root_errs ++ downsweep_errs ++ other_errs
- all_root_errs = closure_errs ++ map snd root_errs
+ all_root_errs = map snd root_errs
-- if we have been passed -fno-code, we enable code generation
-- for dependencies of modules that have -XTemplateHaskell,
@@ -1723,7 +1733,7 @@ downsweep_imports hsc_env old_summaries excl_mods allow_dup_roots (root_errs, ro
getRootSummary ::
[ModuleName] ->
- M.Map (UnitId, FilePath) ModSummary ->
+ M.Map (UnitId, OsPath) ModSummary ->
HscEnv ->
Target ->
IO (Either (UnitId, DriverMessages) ModSummary)
@@ -2069,7 +2079,7 @@ mkRootMap summaries = Map.fromListWith (flip (++))
summariseFile
:: HscEnv
-> HomeUnit
- -> M.Map (UnitId, FilePath) ModSummary -- old summaries
+ -> M.Map (UnitId, OsPath) ModSummary -- old summaries
-> FilePath -- source file name
-> Maybe Phase -- start phase
-> Maybe (StringBuffer,UTCTime)
@@ -2078,7 +2088,7 @@ summariseFile
summariseFile hsc_env' home_unit old_summaries src_fn mb_phase maybe_buf
-- we can use a cached summary if one is available and the
-- source file hasn't changed,
- | Just old_summary <- M.lookup (homeUnitId home_unit, src_fn) old_summaries
+ | Just old_summary <- M.lookup (homeUnitId home_unit, src_fn_os) old_summaries
= do
let location = ms_location $ old_summary
@@ -2099,6 +2109,7 @@ summariseFile hsc_env' home_unit old_summaries src_fn mb_phase maybe_buf
where
-- change the main active unit so all operations happen relative to the given unit
hsc_env = hscSetActiveHomeUnit home_unit hsc_env'
+ src_fn_os = OsPath.unsafeEncodeUtf src_fn
-- src_fn does not necessarily exist on the filesystem, so we need to
-- check what kind of target we are dealing with
get_src_hash = case maybe_buf of
@@ -2188,7 +2199,7 @@ data SummariseResult =
summariseModule
:: HscEnv
-> HomeUnit
- -> M.Map (UnitId, FilePath) ModSummary
+ -> M.Map (UnitId, OsPath) ModSummary
-- ^ Map of old summaries
-> IsBootInterface -- True <=> a {-# SOURCE #-} import
-> Located ModuleName -- Imported module to be summarised
@@ -2249,7 +2260,7 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p
Right ms -> FoundHome ms
new_summary_cache_check loc mod src_fn h
- | Just old_summary <- Map.lookup ((toUnitId (moduleUnit mod), src_fn)) old_summary_map =
+ | Just old_summary <- Map.lookup ((toUnitId (moduleUnit mod), src_fn_os)) old_summary_map =
-- check the hash on the source file, and
-- return the cached summary if it hasn't changed. If the
@@ -2260,6 +2271,8 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p
Nothing ->
checkSummaryHash hsc_env (new_summary loc mod src_fn) old_summary loc h
| otherwise = new_summary loc mod src_fn h
+ where
+ src_fn_os = OsPath.unsafeEncodeUtf src_fn
new_summary :: ModLocation
-> Module
@@ -2328,7 +2341,8 @@ makeNewModSummary hsc_env MakeNewModSummary{..} = do
hie_timestamp <- modificationTimeIfExists (ml_hie_file nms_location)
extra_sig_imports <- findExtraSigImports hsc_env nms_hsc_src pi_mod_name
- (implicit_sigs, _inst_deps) <- implicitRequirementsShallow (hscSetActiveUnitId (moduleUnitId nms_mod) hsc_env) pi_theimps
+-- (implicit_sigs, _inst_deps) <- implicitRequirementsShallow (hscSetActiveUnitId (moduleUnitId nms_mod) hsc_env) pi_theimps
+ let implicit_sigs = []
return $
ModSummary
@@ -2386,7 +2400,8 @@ getPreprocessedImports hsc_env src_fn mb_phase maybe_buf = do
mimps <- getImports popts imp_prelude pi_hspp_buf pi_hspp_fn src_fn
let mopts = map unLoc $ snd $ getOptions popts pi_hspp_buf src_fn
pure $ ((, mopts) <$>) $ first (mkMessages . fmap mkDriverPsHeaderMessage . getMessages) mimps
- let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query
let rn_imps = fmap (\(pk, lmn@(L _ mn)) -> (rn_pkg_qual mn pk, lmn))
let pi_srcimps = rn_imps pi_srcimps'
let pi_theimps = rn_imps pi_theimps'
=====================================
compiler/GHC/Driver/Pipeline/Execute.hs
=====================================
@@ -692,9 +692,10 @@ runHscPhase pipe_env hsc_env0 input_fn src_flavour = do
-- gather the imports and module name
(hspp_buf,mod_name,imps,src_imps, ghc_prim_imp) <- do
buf <- hGetStringBuffer input_fn
+ query <- hscUnitIndexQuery hsc_env
let imp_prelude = xopt LangExt.ImplicitPrelude dflags
popts = initParserOpts dflags
- rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
+ rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query
rn_imps = fmap (\(rpk, lmn@(L _ mn)) -> (rn_pkg_qual mn rpk, lmn))
eimps <- getImports popts imp_prelude buf input_fn (basename <.> suff)
case eimps of
=====================================
compiler/GHC/HsToCore.hs
=====================================
@@ -149,7 +149,8 @@ deSugar hsc_env
= do { let dflags = hsc_dflags hsc_env
logger = hsc_logger hsc_env
ptc = initPromotionTickContext (hsc_dflags hsc_env)
- name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) rdr_env
+ ; query <- hscUnitIndexQuery hsc_env
+ ; let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query rdr_env
; withTiming logger
(text "Desugar"<+>brackets (ppr mod))
(const ()) $
=====================================
compiler/GHC/HsToCore/Monad.hs
=====================================
@@ -89,6 +89,7 @@ import GHC.Data.FastString
import GHC.Unit.Env
import GHC.Unit.External
+import GHC.Unit.State (UnitIndexQuery)
import GHC.Unit.Module
import GHC.Unit.Module.ModGuts
@@ -264,7 +265,8 @@ mkDsEnvsFromTcGbl hsc_env msg_var tcg_env
++ eps_complete_matches eps -- from imports
-- re-use existing next_wrapper_num to ensure uniqueness
next_wrapper_num_var = tcg_next_wrapper_num tcg_env
- ; return $ mkDsEnvs unit_env this_mod rdr_env type_env fam_inst_env ptc
+ ; query <- liftIO $ hscUnitIndexQuery hsc_env
+ ; return $ mkDsEnvs unit_env query this_mod rdr_env type_env fam_inst_env ptc
msg_var cc_st_var next_wrapper_num_var complete_matches
}
@@ -292,6 +294,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds
; next_wrapper_num <- newIORef emptyModuleEnv
; msg_var <- newIORef emptyMessages
; eps <- liftIO $ hscEPS hsc_env
+ ; query <- liftIO $ hscUnitIndexQuery hsc_env
; let unit_env = hsc_unit_env hsc_env
type_env = typeEnvFromEntities ids tycons patsyns fam_insts
ptc = initPromotionTickContext (hsc_dflags hsc_env)
@@ -303,7 +306,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds
bindsToIds (Rec binds) = map fst binds
ids = concatMap bindsToIds binds
- envs = mkDsEnvs unit_env this_mod rdr_env type_env
+ envs = mkDsEnvs unit_env query this_mod rdr_env type_env
fam_inst_env ptc msg_var cc_st_var
next_wrapper_num complete_matches
; runDs hsc_env envs thing_inside
@@ -342,12 +345,12 @@ initTcDsForSolver thing_inside
Just ret -> pure ret
Nothing -> pprPanic "initTcDsForSolver" (vcat $ pprMsgEnvelopeBagWithLocDefault (getErrorMessages msgs)) }
-mkDsEnvs :: UnitEnv -> Module -> GlobalRdrEnv -> TypeEnv -> FamInstEnv
+mkDsEnvs :: UnitEnv -> UnitIndexQuery -> Module -> GlobalRdrEnv -> TypeEnv -> FamInstEnv
-> PromotionTickContext
-> IORef (Messages DsMessage) -> IORef CostCentreState
-> IORef (ModuleEnv Int) -> CompleteMatches
-> (DsGblEnv, DsLclEnv)
-mkDsEnvs unit_env mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
+mkDsEnvs unit_env query mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
next_wrapper_num complete_matches
= let if_genv = IfGblEnv { if_doc = text "mkDsEnvs"
-- Failing tests here are `ghci` and `T11985` if you get this wrong.
@@ -364,7 +367,7 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
, ds_fam_inst_env = fam_inst_env
, ds_gbl_rdr_env = rdr_env
, ds_if_env = (if_genv, if_lenv)
- , ds_name_ppr_ctx = mkNamePprCtx ptc unit_env rdr_env
+ , ds_name_ppr_ctx = mkNamePprCtx ptc unit_env query rdr_env
, ds_msgs = msg_var
, ds_complete_matches = complete_matches
, ds_cc_st = cc_st_var
=====================================
compiler/GHC/Iface/Recomp.hs
=====================================
@@ -588,7 +588,8 @@ checkDependencies :: HscEnv -> ModSummary -> ModIface -> IfG RecompileRequired
checkDependencies hsc_env summary iface
= do
res_normal <- classify_import (findImportedModule hsc_env) (ms_textual_imps summary ++ ms_srcimps summary)
- res_plugin <- classify_import (\mod _ -> findPluginModule fc fopts units mhome_unit mod) (ms_plugin_imps summary)
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ res_plugin <- classify_import (\mod _ -> findPluginModule fc fopts units query mhome_unit mod) (ms_plugin_imps summary)
case sequence (res_normal ++ res_plugin ++ [Right (fake_ghc_prim_import)| ms_ghc_prim_import summary]) of
Left recomp -> return $ NeedsRecompile recomp
Right es -> do
=====================================
compiler/GHC/Linker/Loader.hs
=====================================
@@ -358,7 +358,7 @@ loadCmdLineLibs' interp hsc_env pls = snd <$>
let hsc' = hscSetActiveUnitId uid hsc_env
-- Load potential dependencies first
(done', pls') <- foldM (\(done', pls') uid -> load done' uid pls') (done, pls)
- (homeUnitDepends (hsc_units hsc'))
+ (Set.toList (homeUnitDepends (hsc_units hsc')))
pls'' <- loadCmdLineLibs'' interp hsc' pls'
return $ (Set.insert uid done', pls'')
=====================================
compiler/GHC/Rename/Names.hs
=====================================
@@ -27,6 +27,7 @@ module GHC.Rename.Names (
getMinimalImports,
printMinimalImports,
renamePkgQual, renameRawPkgQual,
+ hscRenamePkgQual, hscRenameRawPkgQual,
classifyGREs,
ImportDeclUsage,
) where
@@ -337,7 +338,8 @@ rnImportDecl this_mod
hsc_env <- getTopEnv
unit_env <- hsc_unit_env <$> getTopEnv
- let pkg_qual = renameRawPkgQual unit_env imp_mod_name raw_pkg_qual
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ let pkg_qual = renameRawPkgQual unit_env query imp_mod_name raw_pkg_qual
-- Check for self-import, which confuses the typechecker (#9032)
-- ghc --make rejects self-import cycles already, but batch-mode may not
@@ -447,14 +449,14 @@ rnImportDecl this_mod
-- | Rename raw package imports
-renameRawPkgQual :: UnitEnv -> ModuleName -> RawPkgQual -> PkgQual
-renameRawPkgQual unit_env mn = \case
+renameRawPkgQual :: UnitEnv -> UnitIndexQuery -> ModuleName -> RawPkgQual -> PkgQual
+renameRawPkgQual unit_env query mn = \case
NoRawPkgQual -> NoPkgQual
- RawPkgQual p -> renamePkgQual unit_env mn (Just (sl_fs p))
+ RawPkgQual p -> renamePkgQual unit_env query mn (Just (sl_fs p))
-- | Rename raw package imports
-renamePkgQual :: UnitEnv -> ModuleName -> Maybe FastString -> PkgQual
-renamePkgQual unit_env mn mb_pkg = case mb_pkg of
+renamePkgQual :: UnitEnv -> UnitIndexQuery -> ModuleName -> Maybe FastString -> PkgQual
+renamePkgQual unit_env query mn mb_pkg = case mb_pkg of
Nothing -> NoPkgQual
Just pkg_fs
| Just uid <- homeUnitId <$> ue_homeUnit unit_env
@@ -464,7 +466,7 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
| Just (uid, _) <- find (fromMaybe False . fmap (== pkg_fs) . snd) home_names
-> ThisPkg uid
- | Just uid <- resolvePackageImport (ue_units unit_env) mn (PackageName pkg_fs)
+ | Just uid <- resolvePackageImport (ue_units unit_env) query mn (PackageName pkg_fs)
-> OtherPkg uid
| otherwise
@@ -472,13 +474,35 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
-- not really correct as pkg_fs is unlikely to be a valid unit-id but
-- we will report the failure later...
where
- home_names = map (\uid -> (uid, mkFastString <$> thisPackageName (homeUnitEnv_dflags (ue_findHomeUnitEnv uid unit_env)))) hpt_deps
+ home_names =
+ [ (uid, mkFastString <$> thisPackageName (homeUnitEnv_dflags (ue_findHomeUnitEnv uid unit_env)))
+ | uid <- S.toList hpt_deps
+ ]
units = ue_units unit_env
- hpt_deps :: [UnitId]
+ hpt_deps :: S.Set UnitId
hpt_deps = homeUnitDepends units
+hscRenameRawPkgQual ::
+ MonadIO m =>
+ HscEnv ->
+ ModuleName ->
+ RawPkgQual ->
+ m PkgQual
+hscRenameRawPkgQual hsc_env name raw = do
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ pure (renameRawPkgQual (hsc_unit_env hsc_env) query name raw)
+
+hscRenamePkgQual ::
+ MonadIO m =>
+ HscEnv ->
+ ModuleName ->
+ Maybe FastString ->
+ m PkgQual
+hscRenamePkgQual hsc_env name package = do
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ pure (renamePkgQual (hsc_unit_env hsc_env) query name package)
-- | Calculate the 'ImportAvails' induced by an import of a particular
-- interface, but without 'imp_mods'.
=====================================
compiler/GHC/Runtime/Context.hs
=====================================
@@ -26,6 +26,7 @@ import GHC.Runtime.Eval.Types ( IcGlobalRdrEnv(..), Resume )
import GHC.Unit
import GHC.Unit.Env
+import GHC.Unit.State (UnitIndexQuery)
import GHC.Core.FamInstEnv
import GHC.Core.InstEnv
@@ -351,8 +352,8 @@ icInScopeTTs ictxt = filter in_scope_unqualified (ic_tythings ictxt)
]
-- | Get the NamePprCtx function based on the flags and this InteractiveContext
-icNamePprCtx :: UnitEnv -> InteractiveContext -> NamePprCtx
-icNamePprCtx unit_env ictxt = mkNamePprCtx ptc unit_env (icReaderEnv ictxt)
+icNamePprCtx :: UnitEnv -> UnitIndexQuery -> InteractiveContext -> NamePprCtx
+icNamePprCtx unit_env query ictxt = mkNamePprCtx ptc unit_env query (icReaderEnv ictxt)
where ptc = initPromotionTickContext (ic_dflags ictxt)
-- | extendInteractiveContext is called with new TyThings recently defined to update the
=====================================
compiler/GHC/Runtime/Loader.hs
=====================================
@@ -348,7 +348,8 @@ lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do
let unit_state = ue_units unit_env
let mhome_unit = hsc_home_unit_maybe hsc_env
-- First find the unit the module resides in by searching exposed units and home modules
- found_module <- findPluginModule fc fopts unit_state mhome_unit mod_name
+ query <- hscUnitIndexQuery hsc_env
+ found_module <- findPluginModule fc fopts unit_state query mhome_unit mod_name
case found_module of
Found _ mod -> do
-- Find the exports of the module
=====================================
compiler/GHC/Tc/Module.hs
=====================================
@@ -266,9 +266,11 @@ tcRnModuleTcRnM hsc_env mod_sum
; when (notNull prel_imports) $ do
addDiagnostic TcRnImplicitImportOfPrelude
+ ; query <- liftIO $ hscUnitIndexQuery hsc_env
+
; -- TODO This is a little skeevy; maybe handle a bit more directly
let { simplifyImport (L _ idecl) =
- ( renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName idecl) (ideclPkgQual idecl)
+ ( renameRawPkgQual (hsc_unit_env hsc_env) query (unLoc $ ideclName idecl) (ideclPkgQual idecl)
, reLoc $ ideclName idecl)
}
; raw_sig_imports <- liftIO
@@ -1996,11 +1998,13 @@ runTcInteractive hsc_env thing_inside
(loadSrcInterface (text "runTcInteractive") m
NotBoot mb_pkg)
+
; !orphs <- fmap (force . concat) . forM (ic_imports icxt) $ \i ->
case i of -- force above: see #15111
IIModule n -> getOrphans n NoPkgQual
- IIDecl i -> getOrphans (unLoc (ideclName i))
- (renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName i) (ideclPkgQual i))
+ IIDecl i -> do
+ qual <- hscRenameRawPkgQual hsc_env (unLoc $ ideclName i) (ideclPkgQual i)
+ getOrphans (unLoc (ideclName i)) qual
; let imports = emptyImportAvails { imp_orphs = orphs }
=====================================
compiler/GHC/Tc/Utils/Monad.hs
=====================================
@@ -869,7 +869,8 @@ getNamePprCtx
= do { ptc <- initPromotionTickContext <$> getDynFlags
; rdr_env <- getGlobalRdrEnv
; hsc_env <- getTopEnv
- ; return $ mkNamePprCtx ptc (hsc_unit_env hsc_env) rdr_env }
+ ; query <- liftIO $ hscUnitIndexQuery hsc_env
+ ; return $ mkNamePprCtx ptc (hsc_unit_env hsc_env) query rdr_env }
-- | Like logInfoTcRn, but for user consumption
printForUserTcRn :: SDoc -> TcRn ()
=====================================
compiler/GHC/Types/Name/Ppr.hs
=====================================
@@ -68,11 +68,11 @@ with some holes, we should try to give the user some more useful information.
-- | Creates some functions that work out the best ways to format
-- names for the user according to a set of heuristics.
-mkNamePprCtx :: Outputable info => PromotionTickContext -> UnitEnv -> GlobalRdrEnvX info -> NamePprCtx
-mkNamePprCtx ptc unit_env env
+mkNamePprCtx :: Outputable info => PromotionTickContext -> UnitEnv -> UnitIndexQuery -> GlobalRdrEnvX info -> NamePprCtx
+mkNamePprCtx ptc unit_env index env
= QueryQualify
(mkQualName env)
- (mkQualModule unit_state home_unit)
+ (mkQualModule unit_state index home_unit)
(mkQualPackage unit_state)
(mkPromTick ptc env)
where
@@ -206,8 +206,8 @@ Side note (int-index):
-- | Creates a function for formatting modules based on two heuristics:
-- (1) if the module is the current module, don't qualify, and (2) if there
-- is only one exposed package which exports this module, don't qualify.
-mkQualModule :: UnitState -> Maybe HomeUnit -> QueryQualifyModule
-mkQualModule unit_state mhome_unit mod
+mkQualModule :: UnitState -> UnitIndexQuery -> Maybe HomeUnit -> QueryQualifyModule
+mkQualModule unit_state index mhome_unit mod
| Just home_unit <- mhome_unit
, isHomeModule home_unit mod = False
@@ -218,7 +218,7 @@ mkQualModule unit_state mhome_unit mod
= False
| otherwise = True
- where lookup = lookupModuleInAllUnits unit_state (moduleName mod)
+ where lookup = lookupModuleInAllUnits unit_state index (moduleName mod)
-- | Creates a function for formatting packages based on two heuristics:
-- (1) don't qualify if the package in question is "main", and (2) only qualify
=====================================
compiler/GHC/Unit/Env.hs
=====================================
@@ -100,6 +100,8 @@ data UnitEnv = UnitEnv
, ue_namever :: !GhcNameVersion
-- ^ GHC name/version (used for dynamic library suffix)
+
+ , ue_index :: !UnitIndex
}
ueEPS :: UnitEnv -> IO ExternalPackageState
@@ -108,12 +110,14 @@ ueEPS = eucEPS . ue_eps
initUnitEnv :: UnitId -> HomeUnitGraph -> GhcNameVersion -> Platform -> IO UnitEnv
initUnitEnv cur_unit hug namever platform = do
eps <- initExternalUnitCache
+ ue_index <- newUnitIndex
return $ UnitEnv
{ ue_eps = eps
, ue_home_unit_graph = hug
, ue_current_unit = cur_unit
, ue_platform = platform
, ue_namever = namever
+ , ue_index
}
-- | Get home-unit
@@ -138,7 +142,7 @@ ue_transitiveHomeDeps uid unit_env = Set.toList (loop Set.empty [uid])
loop acc (uid:uids)
| uid `Set.member` acc = loop acc uids
| otherwise =
- let hue = homeUnitDepends (homeUnitEnv_units (ue_findHomeUnitEnv uid unit_env))
+ let hue = Set.toList (homeUnitDepends (homeUnitEnv_units (ue_findHomeUnitEnv uid unit_env)))
in loop (Set.insert uid acc) (hue ++ uids)
=====================================
compiler/GHC/Unit/Finder.hs
=====================================
@@ -36,6 +36,7 @@ module GHC.Unit.Finder (
lookupFileCache
) where
+import GHC.Driver.Env (hsc_mod_graph)
import GHC.Prelude
import GHC.Platform.Ways
@@ -67,8 +68,9 @@ import Control.Monad
import Data.Time
import qualified Data.Map as M
import GHC.Driver.Env
- ( hsc_home_unit_maybe, HscEnv(hsc_FC, hsc_dflags, hsc_unit_env) )
+ ( hsc_home_unit_maybe, HscEnv(hsc_FC, hsc_dflags, hsc_unit_env, hsc_mod_graph), hscUnitIndexQuery )
import GHC.Driver.Config.Finder
+import GHC.Unit.Module.Graph (mgHomeModuleMap, ModuleNameHomeMap)
import qualified Data.Set as Set
import qualified Data.List.NonEmpty as NE
@@ -162,28 +164,36 @@ findImportedModule hsc_env mod pkg_qual =
dflags = hsc_dflags hsc_env
fopts = initFinderOpts dflags
in do
- findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod pkg_qual
+ let home_module_map = mgHomeModuleMap (hsc_mod_graph hsc_env)
+ query <- hscUnitIndexQuery hsc_env
+ findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) query home_module_map mhome_unit mod pkg_qual
findImportedModuleNoHsc
:: FinderCache
-> FinderOpts
-> UnitEnv
+ -> UnitIndexQuery
+ -> ModuleNameHomeMap
-> Maybe HomeUnit
-> ModuleName
-> PkgQual
-> IO FindResult
-findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
+findImportedModuleNoHsc fc fopts ue query home_module_map mhome_unit mod_name mb_pkg =
case mb_pkg of
NoPkgQual -> unqual_import
ThisPkg uid | (homeUnitId <$> mhome_unit) == Just uid -> home_import
- | Just os <- lookup uid other_fopts -> home_pkg_import (uid, os)
+ | Just os <- M.lookup uid other_fopts_map -> home_pkg_import (uid, os)
| otherwise -> pprPanic "findImportModule" (ppr mod_name $$ ppr mb_pkg $$ ppr (homeUnitId <$> mhome_unit) $$ ppr uid $$ ppr (map fst all_opts))
OtherPkg _ -> pkg_import
where
+ (complete_units, module_name_map) = home_module_map
+ module_home_units = M.findWithDefault Set.empty mod_name module_name_map
+ current_unit_id = homeUnitId <$> mhome_unit
all_opts = case mhome_unit of
- Nothing -> other_fopts
- Just home_unit -> (homeUnitId home_unit, fopts) : other_fopts
+ Nothing -> other_fopts_list
+ Just home_unit -> (homeUnitId home_unit, fopts) : other_fopts_list
+ other_fopts_map = M.fromList other_fopts_list
home_import = case mhome_unit of
Just home_unit -> findHomeModule fc fopts home_unit mod_name
@@ -194,7 +204,7 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
-- If the module is reexported, then look for it as if it was from the perspective
-- of that package which reexports it.
| mod_name `Set.member` finder_reexportedModules opts =
- findImportedModuleNoHsc fc opts ue (Just $ DefiniteHomeUnit uid Nothing) mod_name NoPkgQual
+ findImportedModuleNoHsc fc opts ue query home_module_map (Just $ DefiniteHomeUnit uid Nothing) mod_name NoPkgQual
| mod_name `Set.member` finder_hiddenModules opts =
return (mkHomeHidden uid)
| otherwise =
@@ -203,32 +213,44 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
-- Do not be smart and change this to `foldr orIfNotFound home_import hs` as
-- that is not the same!! home_import is first because we need to look within ourselves
-- first before looking at the packages in order.
- any_home_import = foldr1 orIfNotFound (home_import: map home_pkg_import other_fopts)
+ any_home_import = foldr1 orIfNotFound (home_import: map home_pkg_import other_fopts_list)
- pkg_import = findExposedPackageModule fc fopts units mod_name mb_pkg
+ pkg_import = findExposedPackageModule fc fopts units query mod_name mb_pkg
unqual_import = any_home_import
`orIfNotFound`
- findExposedPackageModule fc fopts units mod_name NoPkgQual
+ findExposedPackageModule fc fopts units query mod_name NoPkgQual
units = case mhome_unit of
Nothing -> ue_units ue
Just home_unit -> homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId home_unit) ue
- hpt_deps :: [UnitId]
+ hpt_deps :: Set.Set UnitId
hpt_deps = homeUnitDepends units
- other_fopts = map (\uid -> (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))) hpt_deps
+ dep_providers = Set.intersection module_home_units hpt_deps
+ known_other_uids =
+ let providers = maybe dep_providers (\u -> Set.delete u dep_providers) current_unit_id
+ in Set.toList providers
+ unknown_units =
+ let candidates = Set.difference hpt_deps complete_units
+ excluded = maybe dep_providers (\u -> Set.insert u dep_providers) current_unit_id
+ in Set.toList (Set.difference candidates excluded)
+ other_home_uids = known_other_uids ++ unknown_units
+ other_fopts_list =
+ [ (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))
+ | uid <- other_home_uids
+ ]
-- | Locate a plugin module requested by the user, for a compiler
-- plugin. This consults the same set of exposed packages as
-- 'findImportedModule', unless @-hide-all-plugin-packages@ or
-- @-plugin-package@ are specified.
-findPluginModule :: FinderCache -> FinderOpts -> UnitState -> Maybe HomeUnit -> ModuleName -> IO FindResult
-findPluginModule fc fopts units (Just home_unit) mod_name =
+findPluginModule :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> Maybe HomeUnit -> ModuleName -> IO FindResult
+findPluginModule fc fopts units query (Just home_unit) mod_name =
findHomeModule fc fopts home_unit mod_name
`orIfNotFound`
- findExposedPluginPackageModule fc fopts units mod_name
-findPluginModule fc fopts units Nothing mod_name =
- findExposedPluginPackageModule fc fopts units mod_name
+ findExposedPluginPackageModule fc fopts units query mod_name
+findPluginModule fc fopts units query Nothing mod_name =
+ findExposedPluginPackageModule fc fopts units query mod_name
-- | Locate a specific 'Module'. The purpose of this function is to
-- create a 'ModLocation' for a given 'Module', that is to find out
@@ -284,15 +306,15 @@ homeSearchCache fc home_unit mod_name do_this = do
let mod = mkModule home_unit mod_name
modLocationCache fc mod do_this
-findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> PkgQual -> IO FindResult
-findExposedPackageModule fc fopts units mod_name mb_pkg =
+findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> ModuleName -> PkgQual -> IO FindResult
+findExposedPackageModule fc fopts units query mod_name mb_pkg =
findLookupResult fc fopts
- $ lookupModuleWithSuggestions units mod_name mb_pkg
+ $ lookupModuleWithSuggestions units query mod_name mb_pkg
-findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> IO FindResult
-findExposedPluginPackageModule fc fopts units mod_name =
+findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> ModuleName -> IO FindResult
+findExposedPluginPackageModule fc fopts units query mod_name =
findLookupResult fc fopts
- $ lookupPluginModuleWithSuggestions units mod_name NoPkgQual
+ $ lookupPluginModuleWithSuggestions units query mod_name NoPkgQual
findLookupResult :: FinderCache -> FinderOpts -> LookupResult -> IO FindResult
findLookupResult fc fopts r = case r of
=====================================
compiler/GHC/Unit/Module/Graph.hs
=====================================
@@ -18,6 +18,8 @@ module GHC.Unit.Module.Graph
, mgModSummaries
, mgModSummaries'
, mgLookupModule
+ , ModuleNameHomeMap
+ , mgHomeModuleMap
, showModMsg
, moduleGraphNodeModule
, moduleGraphNodeModSum
@@ -153,23 +155,31 @@ instance Outputable ModNodeKeyWithUid where
-- check that the module and its hs-boot agree.
--
-- The graph is not necessarily stored in topologically-sorted order. Use
+type ModuleNameHomeMap = (Set UnitId, Map.Map ModuleName (Set UnitId))
+
-- 'GHC.topSortModuleGraph' and 'GHC.Data.Graph.Directed.flattenSCC' to achieve this.
data ModuleGraph = ModuleGraph
{ mg_mss :: [ModuleGraphNode]
, mg_graph :: (ReachabilityIndex SummaryNode, NodeKey -> Maybe SummaryNode)
-- A cached transitive dependency calculation so that a lot of work is not
-- repeated whenever the transitive dependencies need to be calculated (for example, hptInstances)
+ , mg_home_map :: ModuleNameHomeMap
+ -- ^ For each module name, which home-unit UnitIds define it together with the set of units for which the listing is complete.
}
-- | Map a function 'f' over all the 'ModSummaries'.
-- To preserve invariants 'f' can't change the isBoot status.
mapMG :: (ModSummary -> ModSummary) -> ModuleGraph -> ModuleGraph
mapMG f mg@ModuleGraph{..} = mg
- { mg_mss = flip fmap mg_mss $ \case
- InstantiationNode uid iuid -> InstantiationNode uid iuid
- LinkNode uid nks -> LinkNode uid nks
- ModuleNode deps ms -> ModuleNode deps (f ms)
+ { mg_mss = new_mss
+ , mg_home_map = mkHomeModuleMap new_mss
}
+ where
+ new_mss =
+ flip fmap mg_mss $ \case
+ InstantiationNode uid iuid -> InstantiationNode uid iuid
+ LinkNode uid nks -> LinkNode uid nks
+ ModuleNode deps ms -> ModuleNode deps (f ms)
unionMG :: ModuleGraph -> ModuleGraph -> ModuleGraph
unionMG a b =
@@ -177,11 +187,27 @@ unionMG a b =
in ModuleGraph {
mg_mss = new_mss
, mg_graph = mkTransDeps new_mss
+ , mg_home_map = mkHomeModuleMap new_mss
}
mkTransDeps :: [ModuleGraphNode] -> (ReachabilityIndex SummaryNode, NodeKey -> Maybe SummaryNode)
mkTransDeps = first graphReachability {- module graph is acyclic -} . moduleGraphNodes False
+mkHomeModuleMap :: [ModuleGraphNode] -> ModuleNameHomeMap
+mkHomeModuleMap nodes =
+ (complete_units, provider_map)
+ where
+ provider_map =
+ Map.fromListWith Set.union
+ [ (ms_mod_name ms, Set.singleton (ms_unitid ms))
+ | ModuleNode _ ms <- nodes
+ ]
+ complete_units =
+ Set.fromList
+ [ ms_unitid ms
+ | ModuleNode _ ms <- nodes
+ ]
+
mgModSummaries :: ModuleGraph -> [ModSummary]
mgModSummaries mg = [ m | ModuleNode _ m <- mgModSummaries' mg ]
@@ -200,8 +226,11 @@ mgLookupModule ModuleGraph{..} m = listToMaybe $ mapMaybe go mg_mss
= Just ms
go _ = Nothing
+mgHomeModuleMap :: ModuleGraph -> ModuleNameHomeMap
+mgHomeModuleMap = mg_home_map
+
emptyMG :: ModuleGraph
-emptyMG = ModuleGraph [] (graphReachability emptyGraph, const Nothing)
+emptyMG = ModuleGraph [] (graphReachability emptyGraph, const Nothing) (Set.empty, Map.empty)
isTemplateHaskellOrQQNonBoot :: ModSummary -> Bool
isTemplateHaskellOrQQNonBoot ms =
@@ -213,9 +242,12 @@ isTemplateHaskellOrQQNonBoot ms =
-- not an element of the ModuleGraph.
extendMG :: ModuleGraph -> [NodeKey] -> ModSummary -> ModuleGraph
extendMG ModuleGraph{..} deps ms = ModuleGraph
- { mg_mss = ModuleNode deps ms : mg_mss
- , mg_graph = mkTransDeps (ModuleNode deps ms : mg_mss)
+ { mg_mss = new_mss
+ , mg_graph = mkTransDeps new_mss
+ , mg_home_map = mkHomeModuleMap new_mss
}
+ where
+ new_mss = ModuleNode deps ms : mg_mss
extendMGInst :: ModuleGraph -> UnitId -> InstantiatedUnit -> ModuleGraph
extendMGInst mg uid depUnitId = mg
=====================================
compiler/GHC/Unit/State.hs
=====================================
@@ -1,6 +1,6 @@
-- (c) The University of Glasgow, 2006
-{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE LambdaCase, RecordWildCards #-}
-- | Unit manipulation
module GHC.Unit.State (
@@ -49,6 +49,14 @@ module GHC.Unit.State (
closeUnitDeps',
mayThrowUnitErr,
+ UnitConfig (..),
+ UnitIndex (..),
+ UnitIndexQuery (..),
+ UnitVisibility (..),
+ VisibilityMap,
+ ModuleNameProvidersMap,
+ newUnitIndex,
+
-- * Module hole substitution
ShHoleSubst,
renameHoleUnit,
@@ -218,7 +226,7 @@ instance Outputable ModuleOrigin where
(if null rhs
then []
else [text "hidden reexport by" <+>
- sep (map (ppr . mkUnit) res)]) ++
+ sep (map (ppr . mkUnit) rhs)]) ++
(if f then [text "package flag"] else [])
))
@@ -458,7 +466,7 @@ data UnitState = UnitState {
-- -Wunused-packages warning.
explicitUnits :: [(Unit, Maybe PackageArg)],
- homeUnitDepends :: [UnitId],
+ homeUnitDepends :: Set UnitId,
-- | This is a full map from 'ModuleName' to all modules which may possibly
-- be providing it. These providers may be hidden (but we'll still want
@@ -493,7 +501,7 @@ emptyUnitState = UnitState {
unwireMap = emptyUniqMap,
preloadUnits = [],
explicitUnits = [],
- homeUnitDepends = [],
+ homeUnitDepends = Set.empty,
moduleNameProvidersMap = emptyUniqMap,
pluginModuleNameProvidersMap = emptyUniqMap,
requirementContext = emptyUniqMap,
@@ -577,10 +585,10 @@ searchPackageId pkgstate pid = filter ((pid ==) . unitPackageId)
-- | Find the UnitId which an import qualified by a package import comes from.
-- Compared to 'lookupPackageName', this function correctly accounts for visibility,
-- renaming and thinning.
-resolvePackageImport :: UnitState -> ModuleName -> PackageName -> Maybe UnitId
-resolvePackageImport unit_st mn pn = do
+resolvePackageImport :: UnitState -> UnitIndexQuery -> ModuleName -> PackageName -> Maybe UnitId
+resolvePackageImport unit_st query mn pn = do
-- 1. Find all modules providing the ModuleName (this accounts for visibility/thinning etc)
- providers <- filterUniqMap originVisible <$> lookupUniqMap (moduleNameProvidersMap unit_st) mn
+ providers <- filterUniqMap originVisible <$> findOrigin query unit_st mn False
-- 2. Get the UnitIds of the candidates
let candidates_uid = concatMap to_uid $ sortOn fst $ nonDetUniqMapToList providers
-- 3. Get the package names of the candidates
@@ -638,14 +646,14 @@ listUnitInfo state = nonDetEltsUniqMap (unitInfoMap state)
-- 'initUnits' can be called again subsequently after updating the
-- 'packageFlags' field of the 'DynFlags', and it will update the
-- 'unitState' in 'DynFlags'.
-initUnits :: Logger -> DynFlags -> Maybe [UnitDatabase UnitId] -> Set.Set UnitId -> IO ([UnitDatabase UnitId], UnitState, HomeUnit, Maybe PlatformConstants)
-initUnits logger dflags cached_dbs home_units = do
+initUnits :: Logger -> DynFlags -> UnitIndex -> Maybe [UnitDatabase UnitId] -> Set.Set UnitId -> IO ([UnitDatabase UnitId], UnitState, HomeUnit, Maybe PlatformConstants)
+initUnits logger dflags index cached_dbs home_units = do
let forceUnitInfoMap (state, _) = unitInfoMap state `seq` ()
(unit_state,dbs) <- withTiming logger (text "initializing unit database")
forceUnitInfoMap
- $ mkUnitState logger (initUnitConfig dflags cached_dbs home_units)
+ $ mkUnitState logger (homeUnitId_ dflags) (initUnitConfig dflags cached_dbs home_units) index
putDumpFileMaybe logger Opt_D_dump_mod_map "Module Map"
FormatText (updSDocContext (\ctx -> ctx {sdocLineLength = 200})
@@ -1484,9 +1492,11 @@ validateDatabase cfg pkg_map1 =
mkUnitState
:: Logger
+ -> UnitId
-> UnitConfig
+ -> UnitIndex
-> IO (UnitState,[UnitDatabase UnitId])
-mkUnitState logger cfg = do
+mkUnitState logger unit cfg index = do
{-
Plan.
@@ -1542,15 +1552,9 @@ mkUnitState logger cfg = do
-- if databases have not been provided, read the database flags
raw_dbs <- case unitConfigDBCache cfg of
- Nothing -> readUnitDatabases logger cfg
+ Nothing -> readDatabases index logger unit cfg
Just dbs -> return dbs
- -- distrust all units if the flag is set
- let distrust_all db = db { unitDatabaseUnits = distrustAllUnits (unitDatabaseUnits db) }
- dbs | unitConfigDistrustAll cfg = map distrust_all raw_dbs
- | otherwise = raw_dbs
-
-
-- This, and the other reverse's that you will see, are due to the fact that
-- packageFlags, pluginPackageFlags, etc. are all specified in *reverse* order
-- than they are on the command line.
@@ -1562,15 +1566,20 @@ mkUnitState logger cfg = do
let home_unit_deps = selectHomeUnits (unitConfigHomeUnits cfg) hpt_flags
-- Merge databases together, without checking validity
- (pkg_map1, prec_map) <- mergeDatabases logger dbs
+ (pkg_map1, prec_map) <- mergeDatabases logger raw_dbs
-- Now that we've merged everything together, prune out unusable
-- packages.
- let (pkg_map2, unusable, sccs) = validateDatabase cfg pkg_map1
+ let (initial_dbs, unusable, sccs) = validateDatabase cfg pkg_map1
reportCycles logger sccs
reportUnusable logger unusable
+ -- distrust all units if the flag is set
+ let distrust_all info = info {unitIsTrusted = False}
+ pkg_map2 | unitConfigDistrustAll cfg = distrust_all <$> initial_dbs
+ | otherwise = initial_dbs
+
-- Apply trust flags (these flags apply regardless of whether
-- or not packages are visible or not)
pkgs1 <- mayThrowUnitErr
@@ -1675,6 +1684,9 @@ mkUnitState logger cfg = do
-- likely to actually happen.
return (updateVisibilityMap wired_map plugin_vis_map2)
+ (moduleNameProvidersMap, pluginModuleNameProvidersMap) <-
+ computeProviders index logger unit cfg vis_map plugin_vis_map initial_dbs pkg_db (mkUnusableModuleNameProvidersMap unusable)
+
let pkgname_map = listToUFM [ (unitPackageName p, unitInstanceOf p)
| p <- pkgs2
]
@@ -1687,8 +1699,6 @@ mkUnitState logger cfg = do
req_ctx = mapUniqMap (Set.toList)
$ plusUniqMapListWith Set.union (map uv_requirements (nonDetEltsUniqMap vis_map))
-
- --
-- Here we build up a set of the packages mentioned in -package
-- flags on the command line; these are called the "preload"
-- packages. we link these packages in eagerly. The preload set
@@ -1711,19 +1721,15 @@ mkUnitState logger cfg = do
$ closeUnitDeps pkg_db
$ zip (map toUnitId preload3) (repeat Nothing)
- let mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet vis_map
- mod_map2 = mkUnusableModuleNameProvidersMap unusable
- mod_map = mod_map2 `plusUniqMap` mod_map1
-
-- Force the result to avoid leaking input parameters
let !state = UnitState
{ preloadUnits = dep_preload
, explicitUnits = explicit_pkgs
- , homeUnitDepends = Set.toList home_unit_deps
+ , homeUnitDepends = home_unit_deps
, unitInfoMap = pkg_db
, preloadClosure = emptyUniqSet
- , moduleNameProvidersMap = mod_map
- , pluginModuleNameProvidersMap = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet plugin_vis_map
+ , moduleNameProvidersMap
+ , pluginModuleNameProvidersMap
, packageNameMap = pkgname_map
, wireMap = wired_map
, unwireMap = listToUniqMap [ (v,k) | (k,v) <- nonDetUniqMapToList wired_map ]
@@ -1896,6 +1902,76 @@ addListTo = foldl' merge
mkModMap :: Unit -> ModuleName -> ModuleOrigin -> UniqMap Module ModuleOrigin
mkModMap pkg mod = unitUniqMap (mkModule pkg mod)
+-- -----------------------------------------------------------------------------
+-- Index
+
+data UnitIndexQuery =
+ UnitIndexQuery {
+ findOrigin :: UnitState -> ModuleName -> Bool -> Maybe (UniqMap Module ModuleOrigin),
+ moduleProviders :: UnitState -> ModuleNameProvidersMap
+ }
+
+data UnitIndex =
+ UnitIndex {
+ unitIndexQuery :: UnitId -> IO UnitIndexQuery,
+ readDatabases :: Logger -> UnitId -> UnitConfig -> IO [UnitDatabase UnitId],
+ computeProviders ::
+ Logger ->
+ UnitId ->
+ UnitConfig ->
+ VisibilityMap ->
+ VisibilityMap ->
+ UnitInfoMap ->
+ UnitInfoMap ->
+ ModuleNameProvidersMap ->
+ IO (ModuleNameProvidersMap, ModuleNameProvidersMap)
+ }
+
+queryFindOriginDefault ::
+ UnitState ->
+ ModuleName ->
+ Bool ->
+ Maybe (UniqMap Module ModuleOrigin)
+queryFindOriginDefault UnitState {moduleNameProvidersMap, pluginModuleNameProvidersMap} name plugins =
+ lookupUniqMap source name
+ where
+ source = if plugins then pluginModuleNameProvidersMap else moduleNameProvidersMap
+
+newUnitIndexQuery :: UnitId -> IO UnitIndexQuery
+newUnitIndexQuery _ =
+ pure UnitIndexQuery {
+ findOrigin = queryFindOriginDefault,
+ moduleProviders = moduleNameProvidersMap
+ }
+
+readDatabasesDefault :: Logger -> UnitId -> UnitConfig -> IO [UnitDatabase UnitId]
+readDatabasesDefault logger _ cfg =
+ readUnitDatabases logger cfg
+
+computeProvidersDefault ::
+ Logger ->
+ UnitId ->
+ UnitConfig ->
+ VisibilityMap ->
+ VisibilityMap ->
+ UnitInfoMap ->
+ UnitInfoMap ->
+ ModuleNameProvidersMap ->
+ IO (ModuleNameProvidersMap, ModuleNameProvidersMap)
+computeProvidersDefault logger _ cfg vis_map plugin_vis_map _initial_dbs pkg_db unusable =
+ pure (mod_map, plugin_mod_map)
+ where
+ mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet vis_map
+ mod_map = unusable `plusUniqMap` mod_map1
+ plugin_mod_map = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet plugin_vis_map
+
+newUnitIndex :: IO UnitIndex
+newUnitIndex =
+ pure UnitIndex {
+ unitIndexQuery = newUnitIndexQuery,
+ readDatabases = readDatabasesDefault,
+ computeProviders = computeProvidersDefault
+ }
-- -----------------------------------------------------------------------------
-- Package Utils
@@ -1903,10 +1979,11 @@ mkModMap pkg mod = unitUniqMap (mkModule pkg mod)
-- | Takes a 'ModuleName', and if the module is in any package returns
-- list of modules which take that name.
lookupModuleInAllUnits :: UnitState
+ -> UnitIndexQuery
-> ModuleName
-> [(Module, UnitInfo)]
-lookupModuleInAllUnits pkgs m
- = case lookupModuleWithSuggestions pkgs m NoPkgQual of
+lookupModuleInAllUnits pkgs query m
+ = case lookupModuleWithSuggestions pkgs query m NoPkgQual of
LookupFound a b -> [(a,fst b)]
LookupMultiple rs -> map f rs
where f (m,_) = (m, expectJust "lookupModule" (lookupUnit pkgs
@@ -1933,18 +2010,24 @@ data ModuleSuggestion = SuggestVisible ModuleName Module ModuleOrigin
| SuggestHidden ModuleName Module ModuleOrigin
lookupModuleWithSuggestions :: UnitState
+ -> UnitIndexQuery
-> ModuleName
-> PkgQual
-> LookupResult
-lookupModuleWithSuggestions pkgs
- = lookupModuleWithSuggestions' pkgs (moduleNameProvidersMap pkgs)
+lookupModuleWithSuggestions pkgs query name
+ = lookupModuleWithSuggestions' pkgs query name False
-- | The package which the module **appears** to come from, this could be
-- the one which reexports the module from it's original package. This function
-- is currently only used for -Wunused-packages
-lookupModulePackage :: UnitState -> ModuleName -> PkgQual -> Maybe [UnitInfo]
-lookupModulePackage pkgs mn mfs =
- case lookupModuleWithSuggestions' pkgs (moduleNameProvidersMap pkgs) mn mfs of
+lookupModulePackage ::
+ UnitState ->
+ UnitIndexQuery ->
+ ModuleName ->
+ PkgQual ->
+ Maybe [UnitInfo]
+lookupModulePackage pkgs query mn mfs =
+ case lookupModuleWithSuggestions' pkgs query mn False mfs of
LookupFound _ (orig_unit, origin) ->
case origin of
ModOrigin {fromOrigUnit, fromExposedReexport} ->
@@ -1960,19 +2043,21 @@ lookupModulePackage pkgs mn mfs =
_ -> Nothing
lookupPluginModuleWithSuggestions :: UnitState
+ -> UnitIndexQuery
-> ModuleName
-> PkgQual
-> LookupResult
-lookupPluginModuleWithSuggestions pkgs
- = lookupModuleWithSuggestions' pkgs (pluginModuleNameProvidersMap pkgs)
+lookupPluginModuleWithSuggestions pkgs query name
+ = lookupModuleWithSuggestions' pkgs query name True
lookupModuleWithSuggestions' :: UnitState
- -> ModuleNameProvidersMap
+ -> UnitIndexQuery
-> ModuleName
+ -> Bool
-> PkgQual
-> LookupResult
-lookupModuleWithSuggestions' pkgs mod_map m mb_pn
- = case lookupUniqMap mod_map m of
+lookupModuleWithSuggestions' pkgs query m onlyPlugins mb_pn
+ = case findOrigin query pkgs m onlyPlugins of
Nothing -> LookupNotFound suggestions
Just xs ->
case foldl' classify ([],[],[], []) (sortOn fst $ nonDetUniqMapToList xs) of
@@ -2033,16 +2118,16 @@ lookupModuleWithSuggestions' pkgs mod_map m mb_pn
all_mods :: [(String, ModuleSuggestion)] -- All modules
all_mods = sortBy (comparing fst) $
[ (moduleNameString m, suggestion)
- | (m, e) <- nonDetUniqMapToList (moduleNameProvidersMap pkgs)
+ | (m, e) <- nonDetUniqMapToList (moduleProviders query pkgs)
, suggestion <- map (getSuggestion m) (nonDetUniqMapToList e)
]
getSuggestion name (mod, origin) =
(if originVisible origin then SuggestVisible else SuggestHidden)
name mod origin
-listVisibleModuleNames :: UnitState -> [ModuleName]
-listVisibleModuleNames state =
- map fst (filter visible (nonDetUniqMapToList (moduleNameProvidersMap state)))
+listVisibleModuleNames :: UnitState -> UnitIndexQuery -> [ModuleName]
+listVisibleModuleNames unit_state query =
+ map fst (filter visible (nonDetUniqMapToList (moduleProviders query unit_state)))
where visible (_, ms) = anyUniqMap originVisible ms
-- | Takes a list of UnitIds (and their "parent" dependency, used for error
=====================================
compiler/cbits/genSym.c
=====================================
@@ -9,7 +9,19 @@
//
// The CPP is thus about the RTS version GHC is linked against, and not the
// version of the GHC being built.
-#if !MIN_VERSION_GLASGOW_HASKELL(9,9,0,0)
+
+#if MIN_VERSION_GLASGOW_HASKELL(9,9,0,0)
+// Unique64 patch was present in 9.10 and later
+#define HAVE_UNIQUE64 1
+#elif !MIN_VERSION_GLASGOW_HASKELL(9,9,0,0) && MIN_VERSION_GLASGOW_HASKELL(9,8,4,0)
+// Unique64 patch was backported to 9.8.4
+#define HAVE_UNIQUE64 1
+#elif !MIN_VERSION_GLASGOW_HASKELL(9,7,0,0) && MIN_VERSION_GLASGOW_HASKELL(9,6,7,0)
+// Unique64 patch was backported to 9.6.7
+#define HAVE_UNIQUE64 1
+#endif
+
+#if !defined(HAVE_UNIQUE64)
HsWord64 ghc_unique_counter64 = 0;
#endif
#if !MIN_VERSION_GLASGOW_HASKELL(9,3,0,0)
=====================================
ghc/GHCi/UI.hs
=====================================
@@ -3695,19 +3695,21 @@ completeBreakpoint = wrapCompleter spaces $ \w -> do -- #3000
completeModule = wrapIdentCompleterMod $ \w -> do
hsc_env <- GHC.getSession
- let pkg_mods = allVisibleModules (hsc_units hsc_env)
+ query <- liftIO $ hscUnitIndexQuery hsc_env
+ let pkg_mods = allVisibleModules (hsc_units hsc_env) query
loaded_mods <- liftM (map GHC.ms_mod_name) getLoadedModules
return $ filter (w `isPrefixOf`)
$ map (showPpr (hsc_dflags hsc_env)) $ loaded_mods ++ pkg_mods
completeSetModule = wrapIdentCompleterWithModifier "+-" $ \m w -> do
hsc_env <- GHC.getSession
+ query <- liftIO $ hscUnitIndexQuery hsc_env
modules <- case m of
Just '-' -> do
imports <- GHC.getContext
return $ map iiModuleName imports
_ -> do
- let pkg_mods = allVisibleModules (hsc_units hsc_env)
+ let pkg_mods = allVisibleModules (hsc_units hsc_env) query
loaded_mods <- liftM (map GHC.ms_mod_name) getLoadedModules
return $ loaded_mods ++ pkg_mods
return $ filter (w `isPrefixOf`) $ map (showPpr (hsc_dflags hsc_env)) modules
@@ -3775,8 +3777,8 @@ wrapIdentCompleterWithModifier modifChars fun = completeWordWithPrev Nothing wor
-- | Return a list of visible module names for autocompletion.
-- (NB: exposed != visible)
-allVisibleModules :: UnitState -> [ModuleName]
-allVisibleModules unit_state = listVisibleModuleNames unit_state
+allVisibleModules :: UnitState -> UnitIndexQuery -> [ModuleName]
+allVisibleModules us query = listVisibleModuleNames us query
completeExpression = completeQuotedWord (Just '\\') "\"" listFiles
completeIdentifier
=====================================
ghc/GHCi/UI/Monad.hs
=====================================
@@ -374,10 +374,11 @@ printForUserGlobalRdrEnv mb_rdr_env doc = do
where
mkNamePprCtxFromGlobalRdrEnv _ Nothing = GHC.getNamePprCtx
mkNamePprCtxFromGlobalRdrEnv dflags (Just rdr_env) =
- withSession $ \ hsc_env ->
+ withSession $ \ hsc_env -> do
+ query <- liftIO $ hscUnitIndexQuery hsc_env
let unit_env = hsc_unit_env hsc_env
ptc = initPromotionTickContext dflags
- in return $ Ppr.mkNamePprCtx ptc unit_env rdr_env
+ return $ Ppr.mkNamePprCtx ptc unit_env query rdr_env
printForUser :: GhcMonad m => SDoc -> m ()
printForUser doc = do
=====================================
ghc/Main.hs
=====================================
@@ -839,12 +839,13 @@ initMulti unitArgsFiles = do
let (initial_home_graph, mainUnitId) = createUnitEnvFromFlags unitDflags
home_units = unitEnv_keys initial_home_graph
+ ue_index = hscUnitIndex hsc_env
home_unit_graph <- forM initial_home_graph $ \homeUnitEnv -> do
let cached_unit_dbs = homeUnitEnv_unit_dbs homeUnitEnv
hue_flags = homeUnitEnv_dflags homeUnitEnv
dflags = homeUnitEnv_dflags homeUnitEnv
- (dbs,unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags cached_unit_dbs home_units
+ (dbs,unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags ue_index cached_unit_dbs home_units
updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
pure $ HomeUnitEnv
@@ -859,7 +860,7 @@ initMulti unitArgsFiles = do
let dflags = homeUnitEnv_dflags $ unitEnv_lookup mainUnitId home_unit_graph
unitEnv <- assertUnitEnvInvariant <$> (liftIO $ initUnitEnv mainUnitId home_unit_graph (ghcNameVersion dflags) (targetPlatform dflags))
- let final_hsc_env = hsc_env { hsc_unit_env = unitEnv }
+ let final_hsc_env = hsc_env { hsc_unit_env = unitEnv {ue_index} }
GHC.setSession final_hsc_env
@@ -892,7 +893,7 @@ checkUnitCycles :: DynFlags -> UnitEnvGraph HomeUnitEnv -> Ghc ()
checkUnitCycles dflags graph = processSCCs sccs
where
mkNode :: (UnitId, HomeUnitEnv) -> Node UnitId UnitId
- mkNode (uid, hue) = DigraphNode uid uid (homeUnitDepends (homeUnitEnv_units hue))
+ mkNode (uid, hue) = DigraphNode uid uid (Set.toList (homeUnitDepends (homeUnitEnv_units hue)))
nodes = map mkNode (unitEnv_elts graph)
sccs = stronglyConnCompFromEdgedVerticesOrd nodes
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ad80226bfaf896e5f8674b65f4acd5…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ad80226bfaf896e5f8674b65f4acd5…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/rts-mutex-static-initializer] rts: replace initMutex/closeMutex with static initializer
by Cheng Shao (@TerrorJack) 12 Dec '25
by Cheng Shao (@TerrorJack) 12 Dec '25
12 Dec '25
Cheng Shao pushed to branch wip/rts-mutex-static-initializer at Glasgow Haskell Compiler / GHC
Commits:
c2d9398a by Cheng Shao at 2025-12-12T01:41:00+01:00
rts: replace initMutex/closeMutex with static initializer
This patch drops all `initMutex`/`closeMutex` logic from the RTS, and
instead define and use a static initializer `MUTEX_INIT` to initialize
a `Mutex`. For both pthreads/win32 cases, a mutex is just a
process-private cheap resource that doesn't really need to be freed
upon RTS exit; it can be statically initialized inplace using either
`PTHREAD_MUTEX_INITIALIZER` or `SRWLOCK_INIT`, hence we define
`MUTEX_INIT` and prefer to use it to initialize a `Mutex`.
All `closeMutex` invocations are dropped. Most `initMutex` invocations
are dropped, except non-global ones, and the ones that need to be
re-initialized in the child process after `forkProcess`, these are
replaced by assigning `MUTEX_INIT`. The patch also drops
`initIpe`/`exitIpe`/`stat_exit` since they are now no-ops. Also cleans
up legacy wasm32 stub definitions, since wasi-libc started shipping
basic pthread stubs in wasip1 sysroot.
Sadly, we can't do the same for condition variables, since
`PTHREAD_COND_INITIALIZER` defaults to real-time but we want monotonic
time.
The main motivation of this patch is not just housecleaning: it is to
make it easier to acquire/release a global Mutex in C initializer
functions generated by GHC (some custom instrumentation for debugging
purpose). Now that a global Mutex can be statically initialized
in-place using `MUTEX_INIT`, the initializer code can acquire/release
it without worrying about Mutex initialization, otherwise it needs to
be initialized in another initializer function with higher priority,
which complicates the implementation.
Co-authored-by: Codex <codex(a)openai.com>
- - - - -
34 changed files:
- rts/Capability.c
- rts/FileLock.c
- rts/Globals.c
- rts/IPE.c
- rts/IPE.h
- rts/Linker.c
- rts/Pool.c
- rts/Profiling.c
- rts/RtsStartup.c
- rts/Schedule.c
- rts/StableName.c
- rts/StablePtr.c
- rts/StaticPtrTable.c
- rts/Stats.c
- rts/Stats.h
- rts/Task.c
- rts/TopHandler.c
- rts/Trace.c
- rts/adjustor/AdjustorPool.c
- rts/eventlog/EventLog.c
- rts/eventlog/EventLogWriter.c
- rts/include/rts/OSThreads.h
- rts/posix/OSThreads.c
- rts/posix/Signals.c
- rts/posix/ticker/Pthread.c
- rts/posix/ticker/TimerFd.c
- rts/sm/GC.c
- rts/sm/NonMoving.c
- rts/sm/NonMovingMark.c
- rts/sm/Storage.c
- rts/win32/OSThreads.c
- rts/win32/ThrIOManager.c
- testsuite/tests/ffi/should_run/IncallAffinity_c.c
- testsuite/tests/rts/RestartEventLogging_c.c
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c2d9398a059ea7487f18488d8aac813…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c2d9398a059ea7487f18488d8aac813…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc] Pushed new branch wip/rts-mutex-static-initializer
by Cheng Shao (@TerrorJack) 12 Dec '25
by Cheng Shao (@TerrorJack) 12 Dec '25
12 Dec '25
Cheng Shao pushed new branch wip/rts-mutex-static-initializer at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/rts-mutex-static-initializer
You're receiving this email because of your account on gitlab.haskell.org.
1
0