
[Git][ghc/ghc][master] Specialise: Don't float out constraint components.
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
c9abb87c by Andreas Klebinger at 2025-05-20T17:24:50-04:00
Specialise: Don't float out constraint components.
It was fairly complex to do so and it doesn't seem to improve anything.
Nofib allocations were unaffected as well.
See also Historical Note [Floating dictionaries out of cases]
- - - - -
1 changed file:
- compiler/GHC/Core/Opt/Specialise.hs
Changes:
=====================================
compiler/GHC/Core/Opt/Specialise.hs
=====================================
@@ -64,7 +64,7 @@ import GHC.Unit.Module.ModGuts
import GHC.Core.Unfold
import Data.List( partition )
-import Data.List.NonEmpty ( NonEmpty (..) )
+-- import Data.List.NonEmpty ( NonEmpty (..) )
import GHC.Core.Subst (substTickish)
{-
@@ -1277,67 +1277,8 @@ specCase :: SpecEnv
, OutId
, [OutAlt]
, UsageDetails)
-specCase env scrut' case_bndr [Alt con args rhs]
- | -- See Note [Floating dictionaries out of cases]
- interestingDict scrut' (idType case_bndr)
- , not (isDeadBinder case_bndr && null sc_args')
- = do { case_bndr_flt :| sc_args_flt <- mapM clone_me (case_bndr' :| sc_args')
-
- ; let case_bndr_flt' = case_bndr_flt `addDictUnfolding` scrut'
- scrut_bind = mkDB (NonRec case_bndr_flt scrut')
-
- sc_args_flt' = zipWith addDictUnfolding sc_args_flt sc_rhss
- sc_rhss = [ Case (Var case_bndr_flt') case_bndr' (idType sc_arg')
- [Alt con args' (Var sc_arg')]
- | sc_arg' <- sc_args' ]
- cb_set = unitVarSet case_bndr_flt'
- sc_binds = [ DB { db_bind = NonRec sc_arg_flt sc_rhs, db_fvs = cb_set }
- | (sc_arg_flt, sc_rhs) <- sc_args_flt' `zip` sc_rhss ]
-
- flt_binds = scrut_bind : sc_binds
-
- -- Extend the substitution for RHS to map the *original* binders
- -- to their floated versions.
- mb_sc_flts :: [Maybe DictId]
- mb_sc_flts = map (lookupVarEnv clone_env) args'
- clone_env = zipVarEnv sc_args' sc_args_flt'
-
- subst_prs = (case_bndr, Var case_bndr_flt)
- : [ (arg, Var sc_flt)
- | (arg, Just sc_flt) <- args `zip` mb_sc_flts ]
- subst' = se_subst env_rhs
- `Core.extendSubstInScopeList` (case_bndr_flt' : sc_args_flt')
- `Core.extendIdSubstList` subst_prs
- env_rhs' = env_rhs { se_subst = subst' }
-
- ; (rhs', rhs_uds) <- specExpr env_rhs' rhs
- ; let (free_uds, dumped_dbs) = dumpUDs (case_bndr':args') rhs_uds
- all_uds = flt_binds `consDictBinds` free_uds
- alt' = Alt con args' (wrapDictBindsE dumped_dbs rhs')
--- ; pprTrace "specCase" (ppr case_bndr $$ ppr scrut_bind) $
- ; return (Var case_bndr_flt, case_bndr', [alt'], all_uds) }
- where
- (env_rhs, (case_bndr':|args')) = substBndrs env (case_bndr:|args)
- sc_args' = filter is_flt_sc_arg args'
-
- clone_me bndr = do { uniq <- getUniqueM
- ; return (mkUserLocalOrCoVar occ uniq wght ty loc) }
- where
- name = idName bndr
- wght = idMult bndr
- ty = idType bndr
- occ = nameOccName name
- loc = getSrcSpan name
-
- arg_set = mkVarSet args'
- is_flt_sc_arg var = isId var
- && not (isDeadBinder var)
- && isDictTy var_ty
- && tyCoVarsOfType var_ty `disjointVarSet` arg_set
- where
- var_ty = idType var
-
-
+-- We used to float out super class selections here,
+-- but no longer do so. See Historical Note [Floating dictionaries out of cases]
specCase env scrut case_bndr alts
= do { (alts', uds_alts) <- mapAndCombineSM spec_alt alts
; return (scrut, case_bndr', alts', uds_alts) }
@@ -1414,36 +1355,36 @@ Note [tryRules: plan (BEFORE)] in the Simplifier (partly) redundant. That is,
if we run rules in the specialiser, does it matter if we make rules "win" over
inlining in the Simplifier? Yes, it does! See the discussion in #21851.
-Note [Floating dictionaries out of cases]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider
+Historical Note [Floating dictionaries out of cases]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Function `specCase` used to give special treatment to a case-expression
+that scrutinised a dictionary, like this:
g = \d. case d of { MkD sc ... -> ...(f sc)... }
-Naively we can't float d2's binding out of the case expression,
-because 'sc' is bound by the case, and that in turn means we can't
-specialise f, which seems a pity.
-
-So we invert the case, by floating out a binding
-for 'sc_flt' thus:
- sc_flt = case d of { MkD sc ... -> sc }
-Now we can float the call instance for 'f'. Indeed this is just
-what'll happen if 'sc' was originally bound with a let binding,
-but case is more efficient, and necessary with equalities. So it's
-good to work with both.
-
-You might think that this won't make any difference, because the
-call instance will only get nuked by the \d. BUT if 'g' itself is
-specialised, then transitively we should be able to specialise f.
-
-In general, given
- case e of cb { MkD sc ... -> ...(f sc)... }
-we transform to
- let cb_flt = e
- sc_flt = case cb_flt of { MkD sc ... -> sc }
- in
- case cb_flt of bg { MkD sc ... -> ....(f sc_flt)... }
-
-The "_flt" things are the floated binds; we use the current substitution
-to substitute sc -> sc_flt in the RHS
+But actually
+
+* We never explicitly case-analyse a dictionary; rather the class-op
+ rules select superclasses from it. (NB: worker/wrapper can unbox
+ tuple dictionaries -- see (DNB1) in Note [Do not unbox class dictionaries];
+ but that's only after worker/wrapper, and specialisation happens before
+ that.)
+
+* Calling `interestingDict` on every scrutinee is hardly sensible;
+ generally `interestingDict` is called only on Constraint-kinded things.
+
+* It was giving a Lint scope error in !14272
+
+So now there is no special case. This Note just records the change
+in case we ever want to reinstate it. The original note was
+added in
+
+ commit c107a00ccf1e641a2d008939cf477c71caa028d5
+ Author: Simon Peyton Jones <simonpj(a)microsoft.com>
+ Date: Thu Aug 12 13:11:33 2010 +0000
+
+ Improve the Specialiser, fixing Trac #4203
+
+End of Historical Note
+
************************************************************************
* *
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c9abb87ccc0c91cd94f42b3e3627015…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c9abb87ccc0c91cd94f42b3e3627015…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][master] Fix bugs in `integerRecipMod` and `integerPowMod`
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
8ded2330 by kwxm at 2025-05-20T17:24:07-04:00
Fix bugs in `integerRecipMod` and `integerPowMod`
This fixes #26017.
* `integerRecipMod x 1` now returns `(# 1 | #)` for all x; previously it
incorrectly returned `(# | () #)`, indicating failure.
* `integerPowMod 0 e m` now returns `(# | () #)` for e<0 and m>1, indicating
failure; previously it incorrectly returned `(# 0 | #)`.
- - - - -
7 changed files:
- libraries/base/changelog.md
- libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs
- + testsuite/tests/lib/integer/T26017.hs
- + testsuite/tests/lib/integer/T26017.stdout
- testsuite/tests/lib/integer/all.T
- testsuite/tests/lib/integer/integerRecipMod.hs
- testsuite/tests/lib/integer/integerRecipMod.stdout
Changes:
=====================================
libraries/base/changelog.md
=====================================
@@ -23,6 +23,9 @@
* `GHC.ExecutionStack.Internal`.
* Deprecate `GHC.JS.Prim.Internal.Build`, as per [CLC #329](https://github.com/haskell/core-libraries-committee/issues/329)
+ * Fix incorrect results of `integerPowMod` when the base is 0 and the exponent is negative, and `integerRecipMod` when the modulus is zero ([#26017](https://gitlab.haskell.org/ghc/ghc/-/issues/26017)).
+
+
## 4.21.0.0 *TBA*
* Change `SrcLoc` to be a strict and unboxed (finishing [CLC proposal #55](https://github.com/haskell/core-libraries-committee/issues/55))
* Introduce `Data.Bounded` module exporting the `Bounded` typeclass (finishing [CLC proposal #208](https://github.com/haskell/core-libraries-committee/issues/208))
=====================================
libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs
=====================================
@@ -1333,38 +1333,60 @@ integerGcde a b = case integerGcde# a b of
-- | Computes the modular inverse.
--
--- I.e. y = integerRecipMod# x m
--- = x^(-1) `mod` m
+-- @integerRecipMod# x m@ behaves as follows:
--
--- with 0 < y < |m|
+-- * If m > 1 and gcd x m = 1, it returns an integer y with 0 < y < m such
+-- that x*y is congruent to 1 modulo m.
--
+-- * If m > 1 and gcd x m > 1, it fails.
+--
+-- * If m = 1, it returns @0@ for all x. The computation effectively takes
+-- place in the zero ring, which has a single element 0 with 0+0 = 0*0 = 0:
+-- the element 0 is the multiplicative identity element and is its own
+-- multiplicative inverse.
+--
+-- * If m = 0, it fails.
+--
+-- NB. Successful evaluation returns a value of the form @(# n | #)@; failure is
+-- indicated by returning @(# | () #)@.
integerRecipMod#
:: Integer
-> Natural
-> (# Natural | () #)
integerRecipMod# x m
- | integerIsZero x = (# | () #)
| naturalIsZero m = (# | () #)
- | naturalIsOne m = (# | () #)
+ | naturalIsOne m = (# naturalZero | #)
+ | integerIsZero x = (# | () #)
| True = Backend.integer_recip_mod x m
-- | Computes the modular exponentiation.
--
--- I.e. y = integer_powmod b e m
--- = b^e `mod` m
+-- @integerPowMod# b e m@ behaves as follows:
--
--- with 0 <= y < abs m
+-- * If m > 1 and e >= 0, it returns an integer y with 0 <= y < m
+-- and y congruent to b^e modulo m.
--
--- If e is negative, we use `integerRecipMod#` to try to find a modular
--- multiplicative inverse (which may not exist).
+-- * If m > 1 and e < 0, it uses `integerRecipMod#` to try to find a modular
+-- multiplicative inverse b' (which only exists if gcd b m = 1) and then
+-- caculates (b')^(-e) modulo m (note that -e > 0); if the inverse does not
+-- exist then it fails.
+--
+-- * If m = 1, it returns @0@ for all b and e.
+--
+-- * If m = 0, it fails.
+--
+-- NB. Successful evaluation returns a value of the form @(# n | #)@; failure is
+-- indicated by returning @(# | () #)@.
+
integerPowMod# :: Integer -> Integer -> Natural -> (# Natural | () #)
integerPowMod# !b !e !m
- | naturalIsZero m = (# | () #)
- | naturalIsOne m = (# naturalZero | #)
- | integerIsZero e = (# naturalOne | #)
- | integerIsZero b = (# naturalZero | #)
- | integerIsOne b = (# naturalOne | #)
+ | naturalIsZero m = (# | () #)
+ | naturalIsOne m = (# naturalZero | #)
+ | integerIsZero e = (# naturalOne | #)
+ | integerIsZero b
+ && integerGt e 0 = (# naturalZero | #)
+ | integerIsOne b = (# naturalOne | #)
-- when the exponent is negative, try to find the modular multiplicative
-- inverse and use it instead
| integerIsNegative e = case integerRecipMod# b m of
=====================================
testsuite/tests/lib/integer/T26017.hs
=====================================
@@ -0,0 +1,39 @@
+{-# LANGUAGE UnboxedTuples #-}
+{-# LANGUAGE MagicHash #-}
+
+module Main (main) where
+
+import Data.List (group)
+import Data.Bits
+import Data.Word
+import Control.Monad
+
+import GHC.Word
+import GHC.Base
+import GHC.Num.Natural
+import GHC.Num.Integer
+
+integerPowMod :: Integer -> Integer -> Natural -> Maybe Natural
+integerPowMod b e m = case integerPowMod# b e m of
+ (# n | #) -> Just n
+ (# | () #) -> Nothing
+
+integerRecipMod :: Integer -> Natural -> Maybe Natural
+integerRecipMod b m =
+ case integerRecipMod# b m of
+ (# n | #) -> Just n
+ (# | () #) -> Nothing
+
+main :: IO ()
+main = do
+ print $ integerPowMod 0 (-1) 17
+ print $ integerPowMod 0 (-1) (2^1000)
+
+ print $ integerPowMod 0 (-100000) 17
+ print $ integerPowMod 0 (-100000) (2^1000)
+
+ print $ integerRecipMod 0 1
+ print $ integerRecipMod 1 1
+ print $ integerRecipMod 7819347813478123471346279134789352789578923 1
+ print $ integerRecipMod (-1) 1
+ print $ integerRecipMod (-7819347813478123471346279134789352789578923) 1
=====================================
testsuite/tests/lib/integer/T26017.stdout
=====================================
@@ -0,0 +1,9 @@
+Nothing
+Nothing
+Nothing
+Nothing
+Just 0
+Just 0
+Just 0
+Just 0
+Just 0
=====================================
testsuite/tests/lib/integer/all.T
=====================================
@@ -27,3 +27,4 @@ test('integerImportExport', normal, compile_and_run, [''])
test('T19345', [], compile_and_run, [''])
test('T20066', [exit_code(1)], compile_and_run, [''])
+test('T26017', [], compile_and_run, [''])
=====================================
testsuite/tests/lib/integer/integerRecipMod.hs
=====================================
@@ -28,6 +28,8 @@ main = do
-- positive modulo
print $ mapMaybe f [-7..71]
- -- modulo == 1 or 0
+ -- modulo == 1 -> succeed and return 0
print (recipModInteger 77 1)
+
+ -- modulo == 0 -> fail
print (recipModInteger 77 0)
=====================================
testsuite/tests/lib/integer/integerRecipMod.stdout
=====================================
@@ -1,3 +1,3 @@
[(-7,149867),(-5,167851),(-1,209813),(1,1),(5,41963),(7,59947),(13,177535),(19,143557),(23,182447),(25,134281),(29,7235),(31,33841),(35,95915),(37,113413),(41,61409),(43,24397),(47,174101),(49,158431),(53,193979),(59,188477),(61,185737),(65,35507),(67,118999),(71,186173)]
-Nothing
+Just 0
Nothing
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ded23300367c6e032b3c5a635fd506…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ded23300367c6e032b3c5a635fd506…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
f2b532bc by Peng Fan at 2025-05-20T17:23:15-04:00
hadrian: enable GHCi for loongarch64
- - - - -
1 changed file:
- hadrian/src/Oracles/Flag.hs
Changes:
=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -165,7 +165,7 @@ ghcWithInterpreter stage = do
anyTargetArch [ ArchX86, ArchX86_64, ArchPPC
, ArchAArch64, ArchS390X
, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2
- , ArchRISCV64
+ , ArchRISCV64, ArchLoongArch64
, ArchWasm32 ]
<*> isArmTarget
-- Maybe this should just be false for cross compilers. But for now
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2b532bc5a3f9a19d128cad1eb510e1…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2b532bc5a3f9a19d128cad1eb510e1…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][master] 9 commits: compiler: do not allocate strings in bytecode assembler
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
7147370b by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: do not allocate strings in bytecode assembler
This patch refactors the compiler to avoid allocating iserv buffers
for BCONPtrStr at assemble-time. Now BCONPtrStr ByteStrings are
recorded as a part of CompiledByteCode, and actual allocation only
happens at link-time. This refactoring is necessary for adding
bytecode serialization functionality, as explained by the revised
comments in this commit.
- - - - -
a67db612 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: make bc_strs serializable
This commit makes the bc_strs field in CompiledByteCode serializable;
similar to previous commit, we preserve the ByteString directly and
defer the actual allocation to link-time, as mentioned in updated
comment.
- - - - -
5faf34ef by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: make bc_itbls serializable
This commit makes bc_itbls in CompiledByteCode serializable. A
dedicated ConInfoTable datatype has been added in ghci which is the
recipe for dynamically making a datacon's info table, containing the
payload of the MkConInfoTable iserv message.
- - - - -
2abaf8c1 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: remove FFIInfo bookkeeping in BCO
This commit removes the bc_ffis field from CompiledByteCode
completely, as well as all the related bookkeeping logic in
GHC.StgToByteCode. bc_ffis is actually *unused* in the rest of GHC
codebase! It is merely a list of FFIInfo, which is just a remote
pointer of the libffi ffi_cif struct; once we allocate the ffi_cif
struct and put its pointer in a CCALL instruction, we'll never free it
anyway. So there is no point of bookkeeping.
- - - - -
adb9e4d2 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: make FFIInfo serializable in BCO
This commit makes all the FFIInfo needed in CCALL instructions
serializable. Previously, when doing STG to BCO lowering, we would
allocate a libffi ffi_cif struct and keep its remote pointer as
FFIInfo; but actually we can just keep the type signature as FFIInfo
and defer the actual allocation to link-time.
- - - - -
200f401b by Cheng Shao at 2025-05-20T17:22:19-04:00
ghci: remove redundant NewBreakModule message
This commit removes the redundant NewBreakModule message from ghci: it
just allocates two strings! This functionality can be implemented with
existing MallocStrings in one iserv call.
- - - - -
ddaadca6 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: make breakpoint module name and unit id serializable
This commit makes breakpoint module name and unit id serializable, in
BRK_FUN instructions as well as ModBreaks. We can simply keep the
module name and unit ids, and defer the buffer allocation to link
time.
- - - - -
a0fde202 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: remove unused newModule
This commit removes the now unused newModule function from GHC.
- - - - -
68c8f140 by Cheng Shao at 2025-05-20T17:22:19-04:00
compiler: add BCONPtrFS for interned top level string literals in BCO
This commit adds BCONPtrFS as a BCO non-pointer literal kind, which
has the same semantics of BCONPtrStr, except it contains a FastString
instead of a ByteString. By using BCONPtrFS to represent top level
string literals that are already FastString in the compilation
pipeline, we enjoy the FastString interning logic and avoid allocating
a bunch of redundant ByteStrings for the same FastStrings, especially
when we lower the BRK_FUN instruction.
- - - - -
13 changed files:
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/InfoTable.hs
- compiler/GHC/ByteCode/Instr.hs
- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/ByteCode/Types.hs
- compiler/GHC/HsToCore/Breakpoints.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/StgToByteCode.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Run.hs
- testsuite/tests/bytecode/T22376/all.T
- testsuite/tests/perf/should_run/ByteCodeAsm.hs
Changes:
=====================================
compiler/GHC/ByteCode/Asm.hs
=====================================
@@ -29,7 +29,6 @@ import GHC.ByteCode.Instr
import GHC.ByteCode.InfoTable
import GHC.ByteCode.Types
import GHCi.RemoteTypes
-import GHC.Runtime.Interpreter
import GHC.Runtime.Heap.Layout ( fromStgWord, StgWord )
import GHC.Types.Name
@@ -38,6 +37,7 @@ import GHC.Types.Literal
import GHC.Types.Unique.DSet
import GHC.Types.SptEntry
import GHC.Types.Unique.FM
+import GHC.Unit.Types
import GHC.Utils.Outputable
import GHC.Utils.Panic
@@ -52,6 +52,7 @@ import GHC.Cmm.Reg ( GlobalArgRegs(..) )
import GHC.Cmm.CallConv ( allArgRegsCover )
import GHC.Platform
import GHC.Platform.Profile
+import Language.Haskell.Syntax.Module.Name
import Control.Monad
import qualified Control.Monad.Trans.State.Strict as MTL
@@ -65,6 +66,7 @@ import Data.Array.Base ( unsafeWrite )
#endif
import Foreign hiding (shiftL, shiftR)
+import Data.ByteString (ByteString)
import Data.Char (ord)
import Data.Maybe (fromMaybe)
import GHC.Float (castFloatToWord32, castDoubleToWord64)
@@ -104,24 +106,21 @@ bcoFreeNames bco
-- Top level assembler fn.
assembleBCOs
- :: Interp
- -> Profile
+ :: Profile
-> FlatBag (ProtoBCO Name)
-> [TyCon]
- -> AddrEnv
+ -> [(Name, ByteString)]
-> Maybe ModBreaks
-> [SptEntry]
-> IO CompiledByteCode
-assembleBCOs interp profile proto_bcos tycons top_strs modbreaks spt_entries = do
+assembleBCOs profile proto_bcos tycons top_strs modbreaks spt_entries = do
-- TODO: the profile should be bundled with the interpreter: the rts ways are
-- fixed for an interpreter
- itblenv <- mkITbls interp profile tycons
+ let itbls = mkITbls profile tycons
bcos <- mapM (assembleBCO (profilePlatform profile)) proto_bcos
- bcos' <- mallocStrings interp bcos
return CompiledByteCode
- { bc_bcos = bcos'
- , bc_itbls = itblenv
- , bc_ffis = concatMap protoBCOFFIs proto_bcos
+ { bc_bcos = bcos
+ , bc_itbls = itbls
, bc_strs = top_strs
, bc_breaks = modbreaks
, bc_spt_entries = spt_entries
@@ -137,50 +136,17 @@ assembleBCOs interp profile proto_bcos tycons top_strs modbreaks spt_entries = d
-- memory for them, and bake the resulting addresses into the instruction stream
-- in the form of BCONPtrWord arguments.
--
--- Since we do this when assembling, we only allocate the memory when we compile
--- the module, not each time we relink it. However, we do want to take care to
--- malloc the memory all in one go, since that is more efficient with
--- -fexternal-interpreter, especially when compiling in parallel.
+-- We used to allocate remote buffers for BCONPtrStr ByteStrings when
+-- assembling, but this gets in the way of bytecode serialization: we
+-- want the ability to serialize and reload assembled bytecode, so
+-- it's better to preserve BCONPtrStr as-is, and only perform the
+-- actual allocation at link-time.
--
-- Note that, as with top-level string literal bindings, this memory is never
-- freed, so it just leaks if the BCO is unloaded. See Note [Generating code for
-- top-level string literal bindings] in GHC.StgToByteCode for some discussion
-- about why.
--
-mallocStrings :: Interp -> FlatBag UnlinkedBCO -> IO (FlatBag UnlinkedBCO)
-mallocStrings interp ulbcos = do
- let bytestrings = reverse (MTL.execState (mapM_ collect ulbcos) [])
- ptrs <- interpCmd interp (MallocStrings bytestrings)
- return (MTL.evalState (mapM splice ulbcos) ptrs)
- where
- splice bco@UnlinkedBCO{..} = do
- lits <- mapM spliceLit unlinkedBCOLits
- ptrs <- mapM splicePtr unlinkedBCOPtrs
- return bco { unlinkedBCOLits = lits, unlinkedBCOPtrs = ptrs }
-
- spliceLit (BCONPtrStr _) = do
- rptrs <- MTL.get
- case rptrs of
- (RemotePtr p : rest) -> do
- MTL.put rest
- return (BCONPtrWord (fromIntegral p))
- _ -> panic "mallocStrings:spliceLit"
- spliceLit other = return other
-
- splicePtr (BCOPtrBCO bco) = BCOPtrBCO <$> splice bco
- splicePtr other = return other
-
- collect UnlinkedBCO{..} = do
- mapM_ collectLit unlinkedBCOLits
- mapM_ collectPtr unlinkedBCOPtrs
-
- collectLit (BCONPtrStr bs) = do
- strs <- MTL.get
- MTL.put (bs:strs)
- collectLit _ = return ()
-
- collectPtr (BCOPtrBCO bco) = collect bco
- collectPtr _ = return ()
data RunAsmReader = RunAsmReader { isn_array :: {-# UNPACK #-} !(Array.IOUArray Int Word16)
, ptr_array :: {-# UNPACK #-} !(SmallMutableArrayIO BCOPtr)
@@ -736,15 +702,15 @@ assembleI platform i = case i of
ENTER -> emit_ bci_ENTER []
RETURN rep -> emit_ (return_non_tuple rep) []
RETURN_TUPLE -> emit_ bci_RETURN_T []
- CCALL off m_addr i -> do np <- addr m_addr
+ CCALL off ffi i -> do np <- lit1 $ BCONPtrFFIInfo ffi
emit_ bci_CCALL [wOp off, Op np, SmallOp i]
PRIMCALL -> emit_ bci_PRIMCALL []
BRK_FUN arr tick_mod tick_mod_id tickx info_mod info_mod_id infox cc ->
do p1 <- ptr (BCOPtrBreakArray arr)
- tick_addr <- addr tick_mod
- tick_unitid_addr <- addr tick_mod_id
- info_addr <- addr info_mod
- info_unitid_addr <- addr info_mod_id
+ tick_addr <- lit1 $ BCONPtrFS $ moduleNameFS tick_mod
+ info_addr <- lit1 $ BCONPtrFS $ moduleNameFS info_mod
+ tick_unitid_addr <- lit1 $ BCONPtrFS $ unitIdFS tick_mod_id
+ info_unitid_addr <- lit1 $ BCONPtrFS $ unitIdFS info_mod_id
np <- addr cc
emit_ bci_BRK_FUN [ Op p1
, Op tick_addr, Op info_addr
=====================================
compiler/GHC/ByteCode/InfoTable.hs
=====================================
@@ -13,11 +13,9 @@ import GHC.Prelude
import GHC.Platform
import GHC.Platform.Profile
-import GHC.ByteCode.Types
-import GHC.Runtime.Interpreter
+import GHCi.Message
import GHC.Types.Name ( Name, getName )
-import GHC.Types.Name.Env
import GHC.Types.RepType
import GHC.Core.DataCon ( DataCon, dataConRepArgTys, dataConIdentity )
@@ -35,33 +33,38 @@ import GHC.Utils.Panic
-}
-- Make info tables for the data decls in this module
-mkITbls :: Interp -> Profile -> [TyCon] -> IO ItblEnv
-mkITbls interp profile tcs =
- foldr plusNameEnv emptyNameEnv <$>
- mapM mkITbl (filter isDataTyCon tcs)
+mkITbls :: Profile -> [TyCon] -> [(Name, ConInfoTable)]
+mkITbls profile tcs = concatMap mkITbl (filter isDataTyCon tcs)
where
- mkITbl :: TyCon -> IO ItblEnv
+ mkITbl :: TyCon -> [(Name, ConInfoTable)]
mkITbl tc
| dcs `lengthIs` n -- paranoia; this is an assertion.
- = make_constr_itbls interp profile dcs
+ = make_constr_itbls profile dcs
where
dcs = tyConDataCons tc
n = tyConFamilySize tc
mkITbl _ = panic "mkITbl"
-mkItblEnv :: [(Name,ItblPtr)] -> ItblEnv
-mkItblEnv pairs = mkNameEnv [(n, (n,p)) | (n,p) <- pairs]
-
-- Assumes constructors are numbered from zero, not one
-make_constr_itbls :: Interp -> Profile -> [DataCon] -> IO ItblEnv
-make_constr_itbls interp profile cons =
+make_constr_itbls :: Profile -> [DataCon] -> [(Name, ConInfoTable)]
+make_constr_itbls profile cons =
-- TODO: the profile should be bundled with the interpreter: the rts ways are
-- fixed for an interpreter
- mkItblEnv <$> mapM (uncurry mk_itbl) (zip cons [0..])
- where
- mk_itbl :: DataCon -> Int -> IO (Name,ItblPtr)
- mk_itbl dcon conNo = do
- let rep_args = [ prim_rep
+ map (uncurry mk_itbl) (zip cons [0..])
+ where
+ mk_itbl :: DataCon -> Int -> (Name, ConInfoTable)
+ mk_itbl dcon conNo =
+ ( getName dcon,
+ ConInfoTable
+ tables_next_to_code
+ ptrs'
+ nptrs_really
+ conNo
+ (tagForCon platform dcon)
+ descr
+ )
+ where
+ rep_args = [ prim_rep
| arg <- dataConRepArgTys dcon
, prim_rep <- typePrimRep (scaledThing arg) ]
@@ -79,7 +82,3 @@ make_constr_itbls interp profile cons =
platform = profilePlatform profile
constants = platformConstants platform
tables_next_to_code = platformTablesNextToCode platform
-
- r <- interpCmd interp (MkConInfoTable tables_next_to_code ptrs' nptrs_really
- conNo (tagForCon platform dcon) descr)
- return (getName dcon, ItblPtr r)
=====================================
compiler/GHC/ByteCode/Instr.hs
=====================================
@@ -15,7 +15,6 @@ import GHC.Prelude
import GHC.ByteCode.Types
import GHCi.RemoteTypes
-import GHCi.FFI (C_ffi_cif)
import GHC.StgToCmm.Layout ( ArgRep(..) )
import GHC.Utils.Outputable
import GHC.Types.Name
@@ -51,9 +50,7 @@ data ProtoBCO a
protoBCOBitmapSize :: Word,
protoBCOArity :: Int,
-- what the BCO came from, for debugging only
- protoBCOExpr :: Either [CgStgAlt] CgStgRhs,
- -- malloc'd pointers
- protoBCOFFIs :: [FFIInfo]
+ protoBCOExpr :: Either [CgStgAlt] CgStgRhs
}
-- | A local block label (e.g. identifying a case alternative).
@@ -209,7 +206,7 @@ data BCInstr
-- For doing calls to C (via glue code generated by libffi)
| CCALL !WordOff -- stack frame size
- (RemotePtr C_ffi_cif) -- addr of the glue code
+ !FFIInfo -- libffi ffi_cif function prototype
!Word16 -- flags.
--
-- 0x1: call is interruptible
@@ -233,11 +230,11 @@ data BCInstr
-- Breakpoints
| BRK_FUN (ForeignRef BreakArray)
- (RemotePtr ModuleName) -- breakpoint tick module
- (RemotePtr UnitId) -- breakpoint tick module unit id
+ !ModuleName -- breakpoint tick module
+ !UnitId -- breakpoint tick module unit id
!Word16 -- breakpoint tick index
- (RemotePtr ModuleName) -- breakpoint info module
- (RemotePtr UnitId) -- breakpoint info module unit id
+ !ModuleName -- breakpoint info module
+ !UnitId -- breakpoint info module unit id
!Word16 -- breakpoint info index
(RemotePtr CostCentre)
@@ -266,10 +263,9 @@ instance Outputable a => Outputable (ProtoBCO a) where
, protoBCOBitmap = bitmap
, protoBCOBitmapSize = bsize
, protoBCOArity = arity
- , protoBCOExpr = origin
- , protoBCOFFIs = ffis })
+ , protoBCOExpr = origin })
= (text "ProtoBCO" <+> ppr name <> char '#' <> int arity
- <+> text (show ffis) <> colon)
+ <> colon)
$$ nest 3 (case origin of
Left alts ->
vcat (zipWith (<+>) (char '{' : repeat (char ';'))
@@ -393,9 +389,9 @@ instance Outputable BCInstr where
ppr (TESTEQ_P i lab) = text "TESTEQ_P" <+> ppr i <+> text "__" <> ppr lab
ppr CASEFAIL = text "CASEFAIL"
ppr (JMP lab) = text "JMP" <+> ppr lab
- ppr (CCALL off marshal_addr flags) = text "CCALL " <+> ppr off
+ ppr (CCALL off ffi flags) = text "CCALL " <+> ppr off
<+> text "marshal code at"
- <+> text (show marshal_addr)
+ <+> text (show ffi)
<+> (case flags of
0x1 -> text "(interruptible)"
0x2 -> text "(unsafe)"
=====================================
compiler/GHC/ByteCode/Linker.hs
=====================================
@@ -3,6 +3,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -optc-DNON_POSIX_SOURCE #-}
--
-- (c) The University of Glasgow 2002-2006
@@ -85,9 +86,15 @@ lookupLiteral interp pkgs_loaded le ptr = case ptr of
BCONPtrAddr nm -> do
Ptr a# <- lookupAddr interp pkgs_loaded (addr_env le) nm
return (W# (int2Word# (addr2Int# a#)))
- BCONPtrStr _ ->
- -- should be eliminated during assembleBCOs
- panic "lookupLiteral: BCONPtrStr"
+ BCONPtrStr bs -> do
+ RemotePtr p <- fmap head $ interpCmd interp $ MallocStrings [bs]
+ pure $ fromIntegral p
+ BCONPtrFS fs -> do
+ RemotePtr p <- fmap head $ interpCmd interp $ MallocStrings [bytesFS fs]
+ pure $ fromIntegral p
+ BCONPtrFFIInfo (FFIInfo {..}) -> do
+ RemotePtr p <- interpCmd interp $ PrepFFI ffiInfoArgs ffiInfoRet
+ pure $ fromIntegral p
lookupStaticPtr :: Interp -> FastString -> IO (Ptr ())
lookupStaticPtr interp addr_of_label_string = do
=====================================
compiler/GHC/ByteCode/Types.hs
=====================================
@@ -35,6 +35,7 @@ import GHC.Builtin.PrimOps
import GHC.Types.SptEntry
import GHC.Types.SrcLoc
import GHCi.BreakArray
+import GHCi.Message
import GHCi.RemoteTypes
import GHCi.FFI
import Control.DeepSeq
@@ -49,8 +50,8 @@ import qualified GHC.Exts.Heap as Heap
import GHC.Stack.CCS
import GHC.Cmm.Expr ( GlobalRegSet, emptyRegSet, regSetToList )
import GHC.Iface.Syntax
-import Language.Haskell.Syntax.Module.Name (ModuleName)
-import GHC.Unit.Types (UnitId)
+import Language.Haskell.Syntax.Module.Name (ModuleName, mkModuleNameFS)
+import GHC.Unit.Types (UnitId(..))
-- -----------------------------------------------------------------------------
-- Compiled Byte Code
@@ -59,13 +60,10 @@ data CompiledByteCode = CompiledByteCode
{ bc_bcos :: FlatBag UnlinkedBCO
-- ^ Bunch of interpretable bindings
- , bc_itbls :: ItblEnv
+ , bc_itbls :: [(Name, ConInfoTable)]
-- ^ Mapping from DataCons to their info tables
- , bc_ffis :: [FFIInfo]
- -- ^ ffi blocks we allocated
-
- , bc_strs :: AddrEnv
+ , bc_strs :: [(Name, ByteString)]
-- ^ top-level strings (heap allocated)
, bc_breaks :: Maybe ModBreaks
@@ -76,9 +74,10 @@ data CompiledByteCode = CompiledByteCode
-- BCOs. See Note [Grand plan for static forms] in
-- "GHC.Iface.Tidy.StaticPtrTable".
}
- -- ToDo: we're not tracking strings that we malloc'd
-newtype FFIInfo = FFIInfo (RemotePtr C_ffi_cif)
- deriving (Show, NFData)
+
+-- | A libffi ffi_cif function prototype.
+data FFIInfo = FFIInfo { ffiInfoArgs :: ![FFIType], ffiInfoRet :: !FFIType }
+ deriving (Show)
instance Outputable CompiledByteCode where
ppr CompiledByteCode{..} = ppr $ elemsFlatBag bc_bcos
@@ -88,9 +87,8 @@ instance Outputable CompiledByteCode where
seqCompiledByteCode :: CompiledByteCode -> ()
seqCompiledByteCode CompiledByteCode{..} =
rnf bc_bcos `seq`
- seqEltsNameEnv rnf bc_itbls `seq`
- rnf bc_ffis `seq`
- seqEltsNameEnv rnf bc_strs `seq`
+ rnf bc_itbls `seq`
+ rnf bc_strs `seq`
rnf (fmap seqModBreaks bc_breaks)
newtype ByteOff = ByteOff Int
@@ -200,10 +198,13 @@ data BCONPtr
-- | A reference to a top-level string literal; see
-- Note [Generating code for top-level string literal bindings] in GHC.StgToByteCode.
| BCONPtrAddr !Name
- -- | Only used internally in the assembler in an intermediate representation;
- -- should never appear in a fully-assembled UnlinkedBCO.
+ -- | A top-level string literal.
-- Also see Note [Allocating string literals] in GHC.ByteCode.Asm.
| BCONPtrStr !ByteString
+ -- | Same as 'BCONPtrStr' but with benefits of 'FastString' interning logic.
+ | BCONPtrFS !FastString
+ -- | A libffi ffi_cif function prototype.
+ | BCONPtrFFIInfo !FFIInfo
instance NFData BCONPtr where
rnf x = x `seq` ()
@@ -263,9 +264,9 @@ data ModBreaks
-- ^ Array pointing to cost centre for each breakpoint
, modBreaks_breakInfo :: IntMap CgBreakInfo
-- ^ info about each breakpoint from the bytecode generator
- , modBreaks_module :: RemotePtr ModuleName
+ , modBreaks_module :: !ModuleName
-- ^ info about the module in which we are setting the breakpoint
- , modBreaks_module_unitid :: RemotePtr UnitId
+ , modBreaks_module_unitid :: !UnitId
-- ^ The 'UnitId' of the 'ModuleName'
}
@@ -290,8 +291,8 @@ emptyModBreaks = ModBreaks
, modBreaks_decls = array (0,-1) []
, modBreaks_ccs = array (0,-1) []
, modBreaks_breakInfo = IntMap.empty
- , modBreaks_module = toRemotePtr nullPtr
- , modBreaks_module_unitid = toRemotePtr nullPtr
+ , modBreaks_module = mkModuleNameFS nilFS
+ , modBreaks_module_unitid = UnitId nilFS
}
{-
=====================================
compiler/GHC/HsToCore/Breakpoints.hs
=====================================
@@ -34,7 +34,6 @@ mkModBreaks interp mod extendedMixEntries
breakArray <- GHCi.newBreakArray interp count
ccs <- mkCCSArray interp mod count entries
- (mod_ptr, mod_id_ptr) <- GHCi.newModule interp mod
let
locsTicks = listArray (0,count-1) [ tick_loc t | t <- entries ]
varsTicks = listArray (0,count-1) [ tick_ids t | t <- entries ]
@@ -45,8 +44,8 @@ mkModBreaks interp mod extendedMixEntries
, modBreaks_vars = varsTicks
, modBreaks_decls = declsTicks
, modBreaks_ccs = ccs
- , modBreaks_module = mod_ptr
- , modBreaks_module_unitid = mod_id_ptr
+ , modBreaks_module = moduleName mod
+ , modBreaks_module_unitid = toUnitId $ moduleUnit mod
}
mkCCSArray
=====================================
compiler/GHC/Linker/Loader.hs
=====================================
@@ -54,7 +54,7 @@ import GHC.Tc.Utils.Monad
import GHC.Runtime.Interpreter
import GHCi.RemoteTypes
import GHC.Iface.Load
-import GHCi.Message (LoadedDLL)
+import GHCi.Message (ConInfoTable(..), LoadedDLL)
import GHC.ByteCode.Linker
import GHC.ByteCode.Asm
@@ -95,6 +95,7 @@ import GHC.Linker.Types
-- Standard libraries
import Control.Monad
+import Data.ByteString (ByteString)
import qualified Data.Set as Set
import Data.Char (isSpace)
import qualified Data.Foldable as Foldable
@@ -688,8 +689,10 @@ loadDecls interp hsc_env span linkable = do
else do
-- Link the expression itself
let le = linker_env pls
- le2 = le { itbl_env = foldl' (\acc cbc -> plusNameEnv acc (bc_itbls cbc)) (itbl_env le) cbcs
- , addr_env = foldl' (\acc cbc -> plusNameEnv acc (bc_strs cbc)) (addr_env le) cbcs }
+ le2_itbl_env <- linkITbls interp (itbl_env le) (concat $ map bc_itbls cbcs)
+ le2_addr_env <- foldlM (\env cbc -> allocateTopStrings interp (bc_strs cbc) env) (addr_env le) cbcs
+ let le2 = le { itbl_env = le2_itbl_env
+ , addr_env = le2_addr_env }
-- Link the necessary packages and linkables
new_bindings <- linkSomeBCOs interp (pkgs_loaded pls) le2 cbcs
@@ -911,9 +914,9 @@ dynLinkBCOs interp pls bcos = do
le1 = linker_env pls
- ie2 = foldr plusNameEnv (itbl_env le1) (map bc_itbls cbcs)
- ae2 = foldr plusNameEnv (addr_env le1) (map bc_strs cbcs)
- le2 = le1 { itbl_env = ie2, addr_env = ae2 }
+ ie2 <- linkITbls interp (itbl_env le1) (concatMap bc_itbls cbcs)
+ ae2 <- foldlM (\env cbc -> allocateTopStrings interp (bc_strs cbc) env) (addr_env le1) cbcs
+ let le2 = le1 { itbl_env = ie2, addr_env = ae2 }
names_and_refs <- linkSomeBCOs interp (pkgs_loaded pls) le2 cbcs
@@ -958,6 +961,11 @@ makeForeignNamedHValueRefs
makeForeignNamedHValueRefs interp bindings =
mapM (\(n, hvref) -> (n,) <$> mkFinalizedHValue interp hvref) bindings
+linkITbls :: Interp -> ItblEnv -> [(Name, ConInfoTable)] -> IO ItblEnv
+linkITbls interp = foldlM $ \env (nm, itbl) -> do
+ r <- interpCmd interp $ MkConInfoTable itbl
+ evaluate $ extendNameEnv env nm (nm, ItblPtr r)
+
{- **********************************************************************
Unload some object modules
@@ -1614,3 +1622,13 @@ maybePutStr logger s = maybePutSDoc logger (text s)
maybePutStrLn :: Logger -> String -> IO ()
maybePutStrLn logger s = maybePutSDoc logger (text s <> text "\n")
+
+-- | see Note [Generating code for top-level string literal bindings]
+allocateTopStrings ::
+ Interp -> [(Name, ByteString)] -> AddrEnv -> IO AddrEnv
+allocateTopStrings interp topStrings prev_env = do
+ let (bndrs, strings) = unzip topStrings
+ ptrs <- interpCmd interp $ MallocStrings strings
+ evaluate $ extendNameEnvList prev_env (zipWith mk_entry bndrs ptrs)
+ where
+ mk_entry nm ptr = (nm, (nm, AddrPtr ptr))
=====================================
compiler/GHC/Runtime/Interpreter.hs
=====================================
@@ -21,7 +21,6 @@ module GHC.Runtime.Interpreter
, mkCostCentres
, costCentreStackInfo
, newBreakArray
- , newModule
, storeBreakpoint
, breakpointStatus
, getBreakpointVar
@@ -376,14 +375,6 @@ newBreakArray interp size = do
breakArray <- interpCmd interp (NewBreakArray size)
mkFinalizedHValue interp breakArray
-newModule :: Interp -> Module -> IO (RemotePtr ModuleName, RemotePtr UnitId)
-newModule interp mod = do
- let
- mod_name = moduleNameString $ moduleName mod
- mod_id = fastStringToShortByteString $ unitIdFS $ toUnitId $ moduleUnit mod
- (mod_ptr, mod_id_ptr) <- interpCmd interp (NewBreakModule mod_name mod_id)
- pure (castRemotePtr mod_ptr, castRemotePtr mod_id_ptr)
-
storeBreakpoint :: Interp -> ForeignRef BreakArray -> Int -> Int -> IO ()
storeBreakpoint interp ref ix cnt = do -- #19157
withForeignRef ref $ \breakarray ->
=====================================
compiler/GHC/StgToByteCode.hs
=====================================
@@ -67,7 +67,6 @@ import GHC.Data.Bitmap
import GHC.Data.FlatBag as FlatBag
import GHC.Data.OrdList
import GHC.Data.Maybe
-import GHC.Types.Name.Env (mkNameEnv)
import GHC.Types.Tickish
import GHC.Types.SptEntry
@@ -82,7 +81,6 @@ import GHC.Unit.Home.PackageTable (lookupHpt)
import Data.Array
import Data.Coerce (coerce)
-import Data.ByteString (ByteString)
#if MIN_VERSION_rts(1,0,3)
import qualified Data.ByteString.Char8 as BS
#endif
@@ -118,19 +116,15 @@ byteCodeGen hsc_env this_mod binds tycs mb_modBreaks spt_entries
bnd <- binds
case bnd of
StgTopLifted bnd -> [Right bnd]
- StgTopStringLit b str -> [Left (b, str)]
+ StgTopStringLit b str -> [Left (getName b, str)]
flattenBind (StgNonRec b e) = [(b,e)]
flattenBind (StgRec bs) = bs
- stringPtrs <- allocateTopStrings interp strings
(BcM_State{..}, proto_bcos) <-
runBc hsc_env this_mod mb_modBreaks $ do
let flattened_binds = concatMap flattenBind (reverse lifted_binds)
FlatBag.fromList (fromIntegral $ length flattened_binds) <$> mapM schemeTopBind flattened_binds
- when (notNull ffis)
- (panic "GHC.StgToByteCode.byteCodeGen: missing final emitBc?")
-
putDumpFileMaybe logger Opt_D_dump_BCOs
"Proto-BCOs" FormatByteCode
(vcat (intersperse (char ' ') (map ppr $ elemsFlatBag proto_bcos)))
@@ -138,7 +132,7 @@ byteCodeGen hsc_env this_mod binds tycs mb_modBreaks spt_entries
let mod_breaks = case modBreaks of
Nothing -> Nothing
Just mb -> Just mb{ modBreaks_breakInfo = breakInfo }
- cbc <- assembleBCOs interp profile proto_bcos tycs stringPtrs mod_breaks spt_entries
+ cbc <- assembleBCOs profile proto_bcos tycs strings mod_breaks spt_entries
-- Squash space leaks in the CompiledByteCode. This is really
-- important, because when loading a set of modules into GHCi
@@ -152,22 +146,8 @@ byteCodeGen hsc_env this_mod binds tycs mb_modBreaks spt_entries
where dflags = hsc_dflags hsc_env
logger = hsc_logger hsc_env
- interp = hscInterp hsc_env
profile = targetProfile dflags
--- | see Note [Generating code for top-level string literal bindings]
-allocateTopStrings
- :: Interp
- -> [(Id, ByteString)]
- -> IO AddrEnv
-allocateTopStrings interp topStrings = do
- let !(bndrs, strings) = unzip topStrings
- ptrs <- interpCmd interp $ MallocStrings strings
- return $ mkNameEnv (zipWith mk_entry bndrs ptrs)
- where
- mk_entry bndr ptr = let nm = getName bndr
- in (nm, (nm, AddrPtr ptr))
-
{- Note [Generating code for top-level string literal bindings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As described in Note [Compilation plan for top-level string literals]
@@ -178,9 +158,9 @@ the bytecode compiler: (1) compiling the bindings themselves, and
we deal with them:
1. Top-level string literal bindings are separated from the rest of
- the module. Memory for them is allocated immediately, via
- interpCmd, in allocateTopStrings, and the resulting AddrEnv is
- recorded in the bc_strs field of the CompiledByteCode result.
+ the module. Memory is not allocated until bytecode link-time, the
+ bc_strs field of the CompiledByteCode result records [(Name, ByteString)]
+ directly.
2. When we encounter a reference to a top-level string literal, we
generate a PUSH_ADDR pseudo-instruction, which is assembled to
@@ -254,17 +234,15 @@ mkProtoBCO
-> WordOff -- ^ bitmap size
-> [StgWord] -- ^ bitmap
-> Bool -- ^ True <=> is a return point, rather than a function
- -> [FFIInfo]
-> ProtoBCO Name
-mkProtoBCO platform _add_bco_name nm instrs_ordlist origin arity bitmap_size bitmap is_ret ffis
+mkProtoBCO platform _add_bco_name nm instrs_ordlist origin arity bitmap_size bitmap is_ret
= ProtoBCO {
protoBCOName = nm,
protoBCOInstrs = maybe_add_bco_name $ maybe_add_stack_check peep_d,
protoBCOBitmap = bitmap,
protoBCOBitmapSize = fromIntegral bitmap_size,
protoBCOArity = arity,
- protoBCOExpr = origin,
- protoBCOFFIs = ffis
+ protoBCOExpr = origin
}
where
#if MIN_VERSION_rts(1,0,3)
@@ -334,7 +312,7 @@ schemeTopBind (id, rhs)
-- by just re-using the single top-level definition. So
-- for the worker itself, we must allocate it directly.
-- ioToBc (putStrLn $ "top level BCO")
- emitBc (mkProtoBCO platform add_bco_name
+ pure (mkProtoBCO platform add_bco_name
(getName id) (toOL [PACK data_con 0, RETURN P])
(Right rhs) 0 0 [{-no bitmap-}] False{-not alts-})
@@ -399,7 +377,7 @@ schemeR_wrk fvs nm original_body (args, body)
bitmap = mkBitmap platform bits
body_code <- schemeER_wrk sum_szsb_args p_init body
- emitBc (mkProtoBCO platform add_bco_name nm body_code (Right original_body)
+ pure (mkProtoBCO platform add_bco_name nm body_code (Right original_body)
arity bitmap_size bitmap False{-not alts-})
-- | Introduce break instructions for ticked expressions.
@@ -478,7 +456,7 @@ break_info hsc_env mod current_mod current_mod_breaks
where
check_mod_ptr mb
| mod_ptr <- modBreaks_module mb
- , fromRemotePtr mod_ptr /= nullPtr
+ , not $ nullFS $ moduleNameFS mod_ptr
= Just mb
| otherwise
= Nothing
@@ -546,7 +524,7 @@ returnUnliftedReps d s szb reps = do
-- otherwise use RETURN_TUPLE with a tuple descriptor
nv_reps -> do
let (call_info, args_offsets) = layoutNativeCall profile NativeTupleReturn 0 id nv_reps
- tuple_bco <- emitBc (tupleBCO platform call_info args_offsets)
+ tuple_bco = tupleBCO platform call_info args_offsets
return $ PUSH_UBX (mkNativeCallInfoLit platform call_info) 1 `consOL`
PUSH_BCO tuple_bco `consOL`
unitOL RETURN_TUPLE
@@ -1097,16 +1075,15 @@ doCase d s p scrut bndr alts
scrut_code <- schemeE (d + ret_frame_size_b + save_ccs_size_b)
(d + ret_frame_size_b + save_ccs_size_b)
p scrut
- alt_bco' <- emitBc alt_bco
if ubx_tuple_frame
- then do tuple_bco <- emitBc (tupleBCO platform call_info args_offsets)
- return (PUSH_ALTS_TUPLE alt_bco' call_info tuple_bco
+ then do let tuple_bco = tupleBCO platform call_info args_offsets
+ return (PUSH_ALTS_TUPLE alt_bco call_info tuple_bco
`consOL` scrut_code)
else let scrut_rep = case non_void_arg_reps of
[] -> V
[rep] -> rep
_ -> panic "schemeE(StgCase).push_alts"
- in return (PUSH_ALTS alt_bco' scrut_rep `consOL` scrut_code)
+ in return (PUSH_ALTS alt_bco scrut_rep `consOL` scrut_code)
-- -----------------------------------------------------------------------------
@@ -1398,7 +1375,7 @@ Note [unboxed tuple bytecodes and tuple_BCO]
-}
-tupleBCO :: Platform -> NativeCallInfo -> [(PrimRep, ByteOff)] -> [FFIInfo] -> ProtoBCO Name
+tupleBCO :: Platform -> NativeCallInfo -> [(PrimRep, ByteOff)] -> ProtoBCO Name
tupleBCO platform args_info args =
mkProtoBCO platform Nothing invented_name body_code (Left [])
0{-no arity-} bitmap_size bitmap False{-is alts-}
@@ -1419,7 +1396,7 @@ tupleBCO platform args_info args =
body_code = mkSlideW 0 1 -- pop frame header
`snocOL` RETURN_TUPLE -- and add it again
-primCallBCO :: Platform -> NativeCallInfo -> [(PrimRep, ByteOff)] -> [FFIInfo] -> ProtoBCO Name
+primCallBCO :: Platform -> NativeCallInfo -> [(PrimRep, ByteOff)] -> ProtoBCO Name
primCallBCO platform args_info args =
mkProtoBCO platform Nothing invented_name body_code (Left [])
0{-no arity-} bitmap_size bitmap False{-is alts-}
@@ -1528,7 +1505,7 @@ generatePrimCall d s p target _mb_unit _result_ty args
massert (off == dd + szb)
go (dd + szb) (push:pushes) cs
push_args <- go d [] shifted_args_offsets
- args_bco <- emitBc (primCallBCO platform args_info prim_args_offsets)
+ let args_bco = primCallBCO platform args_info prim_args_offsets
return $ mconcat push_args `appOL`
(push_target `consOL`
push_info `consOL`
@@ -1706,13 +1683,10 @@ generateCCall d0 s p (CCallSpec target _ safety) result_ty args
let ffires = primRepToFFIType platform r_rep
ffiargs = map (primRepToFFIType platform) a_reps
- interp <- hscInterp <$> getHscEnv
- token <- ioToBc $ interpCmd interp (PrepFFI ffiargs ffires)
- recordFFIBc token
let
-- do the call
- do_call = unitOL (CCALL stk_offset token flags)
+ do_call = unitOL (CCALL stk_offset (FFIInfo ffiargs ffires) flags)
where flags = case safety of
PlaySafe -> 0x0
PlayInterruptible -> 0x1
@@ -2311,8 +2285,6 @@ data BcM_State
{ bcm_hsc_env :: HscEnv
, thisModule :: Module -- current module (for breakpoints)
, nextlabel :: Word32 -- for generating local labels
- , ffis :: [FFIInfo] -- ffi info blocks, to free later
- -- Should be free()d when it is GCd
, modBreaks :: Maybe ModBreaks -- info about breakpoints
, breakInfo :: IntMap CgBreakInfo -- ^ Info at breakpoint occurrence.
@@ -2333,7 +2305,7 @@ runBc :: HscEnv -> Module -> Maybe ModBreaks
-> BcM r
-> IO (BcM_State, r)
runBc hsc_env this_mod modBreaks (BcM m)
- = m (BcM_State hsc_env this_mod 0 [] modBreaks IntMap.empty 0)
+ = m (BcM_State hsc_env this_mod 0 modBreaks IntMap.empty 0)
thenBc :: BcM a -> (a -> BcM b) -> BcM b
thenBc (BcM expr) cont = BcM $ \st0 -> do
@@ -2376,14 +2348,6 @@ shouldAddBcoName = do
then Just <$> getCurrentModule
else return Nothing
-emitBc :: ([FFIInfo] -> ProtoBCO Name) -> BcM (ProtoBCO Name)
-emitBc bco
- = BcM $ \st -> return (st{ffis=[]}, bco (ffis st))
-
-recordFFIBc :: RemotePtr C_ffi_cif -> BcM ()
-recordFFIBc a
- = BcM $ \st -> return (st{ffis = FFIInfo a : ffis st}, ())
-
getLabelBc :: BcM LocalLabel
getLabelBc
= BcM $ \st -> do let nl = nextlabel st
=====================================
libraries/ghci/GHCi/Message.hs
=====================================
@@ -11,6 +11,7 @@
--
module GHCi.Message
( Message(..), Msg(..)
+ , ConInfoTable(..)
, THMessage(..), THMsg(..)
, QResult(..)
, EvalStatus_(..), EvalStatus, EvalResult(..), EvalOpts(..), EvalExpr(..)
@@ -41,6 +42,7 @@ import GHC.ForeignSrcLang
import GHC.Fingerprint
import GHC.Conc (pseq, par)
import Control.Concurrent
+import Control.DeepSeq
import Control.Exception
#if MIN_VERSION_base(4,20,0)
import Control.Exception.Context
@@ -117,12 +119,7 @@ data Message a where
-- | Create an info table for a constructor
MkConInfoTable
- :: Bool -- TABLES_NEXT_TO_CODE
- -> Int -- ptr words
- -> Int -- non-ptr words
- -> Int -- constr tag
- -> Int -- pointer tag
- -> ByteString -- constructor desccription
+ :: !ConInfoTable
-> Message (RemotePtr Heap.StgInfoTable)
-- | Evaluate a statement
@@ -244,16 +241,23 @@ data Message a where
:: RemoteRef (ResumeContext ())
-> Message (EvalStatus ())
- -- | Allocate a string for a breakpoint module name.
- -- This uses an empty dummy type because @ModuleName@ isn't available here.
- NewBreakModule
- :: String -- ^ @ModuleName@
- -> BS.ShortByteString -- ^ @UnitId@ for the given @ModuleName@
- -> Message (RemotePtr BreakModule, RemotePtr BreakUnitId)
+deriving instance Show (Message a)
+-- | Used to dynamically create a data constructor's info table at
+-- run-time.
+data ConInfoTable = ConInfoTable {
+ conItblTablesNextToCode :: !Bool, -- ^ TABLES_NEXT_TO_CODE
+ conItblPtrs :: !Int, -- ^ ptr words
+ conItblNPtrs :: !Int, -- ^ non-ptr words
+ conItblConTag :: !Int, -- ^ constr tag
+ conItblPtrTag :: !Int, -- ^ pointer tag
+ conItblDescr :: !ByteString -- ^ constructor desccription
+}
+ deriving (Generic, Show)
-deriving instance Show (Message a)
+instance Binary ConInfoTable
+instance NFData ConInfoTable
-- | Template Haskell return values
data QResult a
@@ -568,7 +572,7 @@ getMessage = do
15 -> Msg <$> MallocStrings <$> get
16 -> Msg <$> (PrepFFI <$> get <*> get)
17 -> Msg <$> FreeFFI <$> get
- 18 -> Msg <$> (MkConInfoTable <$> get <*> get <*> get <*> get <*> get <*> get)
+ 18 -> Msg <$> MkConInfoTable <$> get
19 -> Msg <$> (EvalStmt <$> get <*> get)
20 -> Msg <$> (ResumeStmt <$> get <*> get)
21 -> Msg <$> (AbandonStmt <$> get)
@@ -589,9 +593,8 @@ getMessage = do
36 -> Msg <$> (Seq <$> get)
37 -> Msg <$> return RtsRevertCAFs
38 -> Msg <$> (ResumeSeq <$> get)
- 39 -> Msg <$> (NewBreakModule <$> get <*> get)
- 40 -> Msg <$> (LookupSymbolInDLL <$> get <*> get)
- 41 -> Msg <$> (WhereFrom <$> get)
+ 39 -> Msg <$> (LookupSymbolInDLL <$> get <*> get)
+ 40 -> Msg <$> (WhereFrom <$> get)
_ -> error $ "Unknown Message code " ++ (show b)
putMessage :: Message a -> Put
@@ -615,7 +618,7 @@ putMessage m = case m of
MallocStrings bss -> putWord8 15 >> put bss
PrepFFI args res -> putWord8 16 >> put args >> put res
FreeFFI p -> putWord8 17 >> put p
- MkConInfoTable tc p n t pt d -> putWord8 18 >> put tc >> put p >> put n >> put t >> put pt >> put d
+ MkConInfoTable itbl -> putWord8 18 >> put itbl
EvalStmt opts val -> putWord8 19 >> put opts >> put val
ResumeStmt opts val -> putWord8 20 >> put opts >> put val
AbandonStmt val -> putWord8 21 >> put val
@@ -636,9 +639,8 @@ putMessage m = case m of
Seq a -> putWord8 36 >> put a
RtsRevertCAFs -> putWord8 37
ResumeSeq a -> putWord8 38 >> put a
- NewBreakModule name unitid -> putWord8 39 >> put name >> put unitid
- LookupSymbolInDLL dll str -> putWord8 40 >> put dll >> put str
- WhereFrom a -> putWord8 41 >> put a
+ LookupSymbolInDLL dll str -> putWord8 39 >> put dll >> put str
+ WhereFrom a -> putWord8 40 >> put a
{-
Note [Parallelize CreateBCOs serialization]
=====================================
libraries/ghci/GHCi/Run.hs
=====================================
@@ -74,7 +74,7 @@ run m = case m of
UnloadObj str -> unloadObj str
AddLibrarySearchPath str -> toRemotePtr <$> addLibrarySearchPath str
RemoveLibrarySearchPath ptr -> removeLibrarySearchPath (fromRemotePtr ptr)
- MkConInfoTable tc ptrs nptrs tag ptrtag desc ->
+ MkConInfoTable (ConInfoTable tc ptrs nptrs tag ptrtag desc) ->
toRemotePtr <$> mkConInfoTable tc ptrs nptrs tag ptrtag desc
ResolveObjs -> resolveObjs
FindSystemLibrary str -> findSystemLibrary str
@@ -96,10 +96,6 @@ run m = case m of
MkCostCentres mod ccs -> mkCostCentres mod ccs
CostCentreStackInfo ptr -> ccsToStrings (fromRemotePtr ptr)
NewBreakArray sz -> mkRemoteRef =<< newBreakArray sz
- NewBreakModule name unitid -> do
- namePtr <- newModuleName name
- uidPtr <- newUnitId unitid
- pure (namePtr, uidPtr)
SetupBreakpoint ref ix cnt -> do
arr <- localRef ref;
_ <- setupBreakpoint arr ix cnt
@@ -440,13 +436,6 @@ mkString0 bs = B.unsafeUseAsCStringLen bs $ \(cstr,len) -> do
pokeElemOff (ptr :: Ptr CChar) len 0
return (castRemotePtr (toRemotePtr ptr))
-mkShortByteString0 :: BS.ShortByteString -> IO (RemotePtr ())
-mkShortByteString0 bs = BS.useAsCStringLen bs $ \(cstr,len) -> do
- ptr <- mallocBytes (len+1)
- copyBytes ptr cstr len
- pokeElemOff (ptr :: Ptr CChar) len 0
- return (castRemotePtr (toRemotePtr ptr))
-
mkCostCentres :: String -> [(String,String)] -> IO [RemotePtr CostCentre]
#if defined(PROFILING)
mkCostCentres mod ccs = do
@@ -464,14 +453,6 @@ foreign import ccall unsafe "mkCostCentre"
mkCostCentres _ _ = return []
#endif
-newModuleName :: String -> IO (RemotePtr BreakModule)
-newModuleName name =
- castRemotePtr . toRemotePtr <$> newCString name
-
-newUnitId :: BS.ShortByteString -> IO (RemotePtr BreakUnitId)
-newUnitId name =
- castRemotePtr <$> mkShortByteString0 name
-
getIdValFromApStack :: HValue -> Int -> IO (Maybe HValue)
getIdValFromApStack apStack (I# stackDepth) = do
case getApStackVal# apStack stackDepth of
=====================================
testsuite/tests/bytecode/T22376/all.T
=====================================
@@ -1,2 +1,2 @@
-test('T22376', [req_interp, extra_files(['A.hs', 'B.hs'])], multimod_compile_and_run,
+test('T22376', [extra_files(['A.hs', 'B.hs'])], multimod_compile_and_run,
['T22376', '-O1 -fwrite-if-simplified-core -fbyte-code-and-object-code -fprefer-byte-code'])
=====================================
testsuite/tests/perf/should_run/ByteCodeAsm.hs
=====================================
@@ -49,11 +49,11 @@ instrs = [ STKCHECK 1234
++ [ PUSH_G appAName | _ <- [0..100] ]
++ [ PUSH_BCO fake_proto2 ]
-fake_proto = ProtoBCO appAName instrs [] 0 0 (Left []) []
+fake_proto = ProtoBCO appAName instrs [] 0 0 (Left [])
instrs2 = [ STKCHECK 77, UNPACK 4, SLIDE 0 4, ENTER ]
-fake_proto2 = ProtoBCO appAName instrs2 [] 0 0 (Left []) []
+fake_proto2 = ProtoBCO appAName instrs2 [] 0 0 (Left [])
main :: IO ()
main = do
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/86406f48659a5ab61ce1fd2a2d427f…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/86406f48659a5ab61ce1fd2a2d427f…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc] Pushed new branch wip/romes/top-level-bcos-tag
by Rodrigo Mesquita (@alt-romes) 20 May '25
by Rodrigo Mesquita (@alt-romes) 20 May '25
20 May '25
Rodrigo Mesquita pushed new branch wip/romes/top-level-bcos-tag at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/romes/top-level-bcos-tag
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][wip/int-index/deprecate-pattern-namespace-specifier] 6 commits: Don't emit unprintable characters when printing Uniques
by Vladislav Zavialov (@int-index) 20 May '25
by Vladislav Zavialov (@int-index) 20 May '25
20 May '25
Vladislav Zavialov pushed to branch wip/int-index/deprecate-pattern-namespace-specifier at Glasgow Haskell Compiler / GHC
Commits:
3b3a5dec by Ben Gamari at 2025-05-15T16:10:01-04:00
Don't emit unprintable characters when printing Uniques
When faced with an unprintable tag we now instead print the codepoint
number.
Fixes #25989.
(cherry picked from commit e832b1fadee66e8d6dd7b019368974756f8f8c46)
- - - - -
e1ef8974 by Mike Pilgrem at 2025-05-16T16:09:14-04:00
Translate iff in Haddock documentation into everyday English
- - - - -
fd64667d by Vladislav Zavialov at 2025-05-20T03:25:08-04:00
Allow the 'data' keyword in import/export lists (#25899)
This patch introduces the 'data' namespace specifier in import and
export lists. The intended use is to import data constructors without
their parent type constructors, e.g.
import Data.Proxy as D (data Proxy)
type DP = D.Proxy -- promoted data constructor
Additionally, it is possible to use 'data' to explicitly qualify any
data constructors or terms, incl. operators and field selectors
import Prelude (Semigroup(data (<>)))
import Data.Function (data (&))
import Data.Monoid (data Dual, data getDual)
x = Dual "Hello" <> Dual "World" & getDual
The implementation mostly builds on top of the existing logic for the
'type' and 'pattern' namespace specifiers, plus there are a few tweaks
to how we generate suggestions in error messages.
- - - - -
acc86753 by Ben Gamari at 2025-05-20T03:25:51-04:00
compiler: Use field selectors when creating BCOs
This makes it easier to grep for these fields.
- - - - -
60a55fd7 by Ben Gamari at 2025-05-20T03:25:51-04:00
compiler: Clarify BCO size
Previously the semantics and size of StgBCO was a bit unclear.
Specifically, the `size` field was documented to contain the size of the
bitmap whereas it was actually the size of the closure *and* bitmap.
Additionally, it was not as clear as it could be that the bitmap was a
full StgLargeBitmap with its own `size` field.
- - - - -
c7cdd4ea by Vladislav Zavialov at 2025-05-20T21:42:47+03:00
Implement -Wpattern-namespace-specifier (#25900)
In accordance with GHC Proposal #581 "Namespace-specified imports",
section 2.3 "Deprecate use of pattern in import/export lists", the
`pattern` namespace specifier is now deprecated.
Test cases: T25900 T25900_noext
- - - - -
95 changed files:
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Errors/Ppr.hs
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Unique.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- compiler/Language/Haskell/Syntax/ImpExp.hs
- docs/users_guide/9.14.1-notes.rst
- docs/users_guide/exts/explicit_namespaces.rst
- docs/users_guide/exts/pattern_synonyms.rst
- docs/users_guide/using-warnings.rst
- hadrian/src/Flavour.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Maybe.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Typeable/Internal.hs
- libraries/ghc-internal/src/GHC/Internal/Type/Reflection.hs
- libraries/ghc-internal/src/GHC/Internal/TypeLits.hs
- libraries/ghc-internal/src/GHC/Internal/TypeNats.hs
- rts/PrimOps.cmm
- rts/include/rts/storage/Closures.h
- testsuite/tests/callarity/unittest/CallArity1.hs
- testsuite/tests/ghci/scripts/ghci024.stdout
- testsuite/tests/ghci/scripts/ghci024.stdout-mingw32
- testsuite/tests/module/T21826.stderr
- + testsuite/tests/parser/should_compile/T25900.hs
- + testsuite/tests/parser/should_compile/T25900.stderr
- + testsuite/tests/parser/should_compile/T25900_noext.hs
- + testsuite/tests/parser/should_compile/T25900_noext.stderr
- testsuite/tests/parser/should_compile/all.T
- testsuite/tests/patsyn/should_compile/ImpExp_Exp.hs
- testsuite/tests/patsyn/should_compile/T11959.hs
- testsuite/tests/patsyn/should_compile/T11959.stderr
- testsuite/tests/patsyn/should_compile/T11959Lib.hs
- testsuite/tests/patsyn/should_compile/T13350/boolean/Boolean.hs
- testsuite/tests/patsyn/should_compile/T22521.hs
- testsuite/tests/patsyn/should_compile/T9857.hs
- testsuite/tests/patsyn/should_compile/export.hs
- testsuite/tests/pmcheck/complete_sigs/T25115a.hs
- testsuite/tests/pmcheck/should_compile/T11822.hs
- testsuite/tests/polykinds/T14270.hs
- testsuite/tests/rename/should_compile/T12548.hs
- testsuite/tests/rename/should_compile/T22581d.stdout
- + testsuite/tests/rename/should_compile/T25899a.hs
- + testsuite/tests/rename/should_compile/T25899b.hs
- + testsuite/tests/rename/should_compile/T25899c.hs
- + testsuite/tests/rename/should_compile/T25899c_helper.hs
- + testsuite/tests/rename/should_compile/T25899d.script
- + testsuite/tests/rename/should_compile/T25899d.stdout
- testsuite/tests/rename/should_compile/all.T
- testsuite/tests/rename/should_fail/T22581a.stderr
- testsuite/tests/rename/should_fail/T22581b.stderr
- testsuite/tests/rename/should_fail/T25056.stderr
- testsuite/tests/rename/should_fail/T25056a.hs
- + testsuite/tests/rename/should_fail/T25899e1.hs
- + testsuite/tests/rename/should_fail/T25899e1.stderr
- + testsuite/tests/rename/should_fail/T25899e2.hs
- + testsuite/tests/rename/should_fail/T25899e2.stderr
- + testsuite/tests/rename/should_fail/T25899e3.hs
- + testsuite/tests/rename/should_fail/T25899e3.stderr
- + testsuite/tests/rename/should_fail/T25899e_helper.hs
- + testsuite/tests/rename/should_fail/T25899f.hs
- + testsuite/tests/rename/should_fail/T25899f.stderr
- + testsuite/tests/rename/should_fail/T25899f_helper.hs
- testsuite/tests/rename/should_fail/all.T
- testsuite/tests/simplCore/should_compile/T15186.hs
- testsuite/tests/simplCore/should_compile/T15186A.hs
- testsuite/tests/typecheck/should_compile/TypeRepCon.hs
- testsuite/tests/warnings/should_compile/DataToTagWarnings.hs
- testsuite/tests/warnings/should_compile/T14794a.hs
- testsuite/tests/warnings/should_compile/T14794a.stderr
- testsuite/tests/warnings/should_compile/T14794b.hs
- testsuite/tests/warnings/should_compile/T14794b.stderr
- testsuite/tests/warnings/should_compile/T14794c.hs
- testsuite/tests/warnings/should_compile/T14794c.stderr
- testsuite/tests/warnings/should_compile/T14794d.hs
- testsuite/tests/warnings/should_compile/T14794d.stderr
- testsuite/tests/warnings/should_compile/T14794e.hs
- testsuite/tests/warnings/should_compile/T14794e.stderr
- testsuite/tests/warnings/should_compile/T14794f.hs
- testsuite/tests/warnings/should_compile/T14794f.stderr
- testsuite/tests/wcompat-warnings/Template.hs
- + testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
- utils/check-exact/ExactPrint.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/edd1ca876e636772ea77f625175a28…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/edd1ca876e636772ea77f625175a28…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][wip/romes/per-thread-step-in] debugger: Allow toggling step-in per thread
by Rodrigo Mesquita (@alt-romes) 20 May '25
by Rodrigo Mesquita (@alt-romes) 20 May '25
20 May '25
Rodrigo Mesquita pushed to branch wip/romes/per-thread-step-in at Glasgow Haskell Compiler / GHC
Commits:
c44f60fd by Rodrigo Mesquita at 2025-05-20T16:54:12+01:00
debugger: Allow toggling step-in per thread
The RTS global flag `rts_stop_next_breakpoint` globally sets the
interpreter to stop at the immediate next breakpoint.
With this commit, single step mode can additionally be set per thread in
the TSO flag (TSO_STOP_NEXT_BREAKPOINT).
Being able to toggle "stop at next breakpoint" per thread is an
important requirement for implementing "stepping out" of a function in a
multi-threaded context.
And, more generally, having a per-thread flag for single-stepping paves the
way for multi-threaded debugging.
That said, when we want to enable "single step" mode for the whole
interpreted program we still want to stop at the immediate next
breakpoint, whichever thread it belongs to.
That's why we also keep the global `rts_stop_next_breakpoint` flag, with
`rts_enableStopNextBreakpointAll` and `rts_disableStopNextBreakpointAll` helpers.
Preparation for #26042
- - - - -
9 changed files:
- libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
- libraries/ghc-heap/GHC/Exts/Heap/FFIClosures_ProfilingDisabled.hsc
- libraries/ghc-heap/GHC/Exts/Heap/FFIClosures_ProfilingEnabled.hsc
- libraries/ghc-heap/tests/parse_tso_flags.hs
- libraries/ghci/GHCi/Run.hs
- rts/Interpreter.c
- rts/Interpreter.h
- rts/RtsSymbols.c
- rts/include/rts/Constants.h
Changes:
=====================================
libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
=====================================
@@ -624,6 +624,7 @@ data TsoFlags
| TsoMarked
| TsoSqueezed
| TsoAllocLimit
+ | TsoStopNextBreakpoint
| TsoFlagsUnknownValue Word32 -- ^ Please report this as a bug
deriving (Eq, Show, Generic, Ord)
=====================================
libraries/ghc-heap/GHC/Exts/Heap/FFIClosures_ProfilingDisabled.hsc
=====================================
@@ -87,6 +87,9 @@ parseTsoFlags w | isSet (#const TSO_LOCKED) w = TsoLocked : parseTsoFlags (unset
| isSet (#const TSO_MARKED) w = TsoMarked : parseTsoFlags (unset (#const TSO_MARKED) w)
| isSet (#const TSO_SQUEEZED) w = TsoSqueezed : parseTsoFlags (unset (#const TSO_SQUEEZED) w)
| isSet (#const TSO_ALLOC_LIMIT) w = TsoAllocLimit : parseTsoFlags (unset (#const TSO_ALLOC_LIMIT) w)
+#if __GLASGOW_HASKELL__ >= 913
+ | isSet (#const TSO_STOP_NEXT_BREAKPOINT) w = TsoStopNextBreakpoint : parseTsoFlags (unset (#const TSO_STOP_NEXT_BREAKPOINT) w)
+#endif
parseTsoFlags 0 = []
parseTsoFlags w = [TsoFlagsUnknownValue w]
=====================================
libraries/ghc-heap/GHC/Exts/Heap/FFIClosures_ProfilingEnabled.hsc
=====================================
@@ -87,6 +87,9 @@ parseTsoFlags w | isSet (#const TSO_LOCKED) w = TsoLocked : parseTsoFlags (unset
| isSet (#const TSO_MARKED) w = TsoMarked : parseTsoFlags (unset (#const TSO_MARKED) w)
| isSet (#const TSO_SQUEEZED) w = TsoSqueezed : parseTsoFlags (unset (#const TSO_SQUEEZED) w)
| isSet (#const TSO_ALLOC_LIMIT) w = TsoAllocLimit : parseTsoFlags (unset (#const TSO_ALLOC_LIMIT) w)
+#if __GLASGOW_HASKELL__ >= 913
+ | isSet (#const TSO_STOP_NEXT_BREAKPOINT) w = TsoStopNextBreakpoint : parseTsoFlags (unset (#const TSO_STOP_NEXT_BREAKPOINT) w)
+#endif
parseTsoFlags 0 = []
parseTsoFlags w = [TsoFlagsUnknownValue w]
=====================================
libraries/ghc-heap/tests/parse_tso_flags.hs
=====================================
@@ -13,5 +13,6 @@ main = do
assertEqual (parseTsoFlags 64) [TsoMarked]
assertEqual (parseTsoFlags 128) [TsoSqueezed]
assertEqual (parseTsoFlags 256) [TsoAllocLimit]
+ assertEqual (parseTsoFlags 512) [TsoStopNextBreakpoint]
assertEqual (parseTsoFlags 6) [TsoLocked, TsoBlockx]
=====================================
libraries/ghci/GHCi/Run.hs
=====================================
@@ -1,5 +1,5 @@
{-# LANGUAGE GADTs, RecordWildCards, MagicHash, ScopedTypeVariables, CPP,
- UnboxedTuples, LambdaCase #-}
+ UnboxedTuples, LambdaCase, UnliftedFFITypes #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
-- |
@@ -396,13 +396,21 @@ abandonStmt hvref = do
_ <- takeMVar resumeStatusMVar
return ()
-foreign import ccall "&rts_stop_next_breakpoint" stepFlag :: Ptr CInt
+foreign import ccall unsafe "rts_enableStopNextBreakpointAll"
+ rts_enableStopNextBreakpointAll :: IO ()
+
+foreign import ccall unsafe "rts_disableStopNextBreakpointAll"
+ rts_disableStopNextBreakpointAll :: IO ()
+
foreign import ccall "&rts_stop_on_exception" exceptionFlag :: Ptr CInt
+-- | Enables the single step mode for all threads, thus stopping at any
+-- existing breakpoint.
setStepFlag :: IO ()
-setStepFlag = poke stepFlag 1
+setStepFlag = rts_enableStopNextBreakpointAll
+
resetStepFlag :: IO ()
-resetStepFlag = poke stepFlag 0
+resetStepFlag = rts_disableStopNextBreakpointAll
type BreakpointCallback
= Addr# -- pointer to the breakpoint tick module name
=====================================
rts/Interpreter.c
=====================================
@@ -243,9 +243,25 @@ allocate_NONUPD (Capability *cap, int n_words)
return allocate(cap, stg_max(sizeofW(StgHeader)+MIN_PAYLOAD_SIZE, n_words));
}
+// A global toggle for single-step mode.
+// Unlike `TSO_STOP_NEXT_BREAKPOINT`, which sets single-step mode per-thread,
+// `rts_stop_next_breakpoint` globally enables single-step mode. If enabled, we
+// will stop at the immediate next breakpoint regardless of what thread it is in.
int rts_stop_next_breakpoint = 0;
int rts_stop_on_exception = 0;
+// Enable the global single step mode
+void rts_enableStopNextBreakpointAll()
+{
+ rts_stop_next_breakpoint = 1;
+}
+
+// Disable the global single step mode
+void rts_disableStopNextBreakpointAll()
+{
+ rts_stop_next_breakpoint = 0;
+}
+
#if defined(INTERP_STATS)
#define N_CODES 128
@@ -1250,7 +1266,7 @@ run_BCO:
int arg8_cc;
#endif
StgArrBytes *breakPoints;
- int returning_from_break;
+ int returning_from_break, stop_next_breakpoint;
// the io action to run at a breakpoint
StgClosure *ioAction;
@@ -1280,6 +1296,13 @@ run_BCO:
returning_from_break =
cap->r.rCurrentTSO->flags & TSO_STOPPED_ON_BREAKPOINT;
+ // check whether this thread is set to stop at the immediate next
+ // breakpoint -- either by the global `rts_stop_next_breakpoint`
+ // flag, or by the local `TSO_STOP_NEXT_BREAKPOINT`
+ stop_next_breakpoint =
+ rts_stop_next_breakpoint ||
+ cap->r.rCurrentTSO->flags & TSO_STOP_NEXT_BREAKPOINT;
+
#if defined(PROFILING)
cap->r.rCCCS = pushCostCentre(cap->r.rCCCS,
(CostCentre*)BCO_LIT(arg8_cc));
@@ -1291,20 +1314,20 @@ run_BCO:
{
breakPoints = (StgArrBytes *) BCO_PTR(arg1_brk_array);
- // stop the current thread if either the
- // "rts_stop_next_breakpoint" flag is true OR if the
- // ignore count for this particular breakpoint is zero
+ // stop the current thread if either `stop_next_breakpoint` is
+ // true OR if the ignore count for this particular breakpoint is zero
StgInt ignore_count = ((StgInt*)breakPoints->payload)[arg6_tick_index];
- if (rts_stop_next_breakpoint == false && ignore_count > 0)
+ if (stop_next_breakpoint == false && ignore_count > 0)
{
// decrement and write back ignore count
((StgInt*)breakPoints->payload)[arg6_tick_index] = --ignore_count;
}
- else if (rts_stop_next_breakpoint == true || ignore_count == 0)
+ else if (stop_next_breakpoint == true || ignore_count == 0)
{
// make sure we don't automatically stop at the
// next breakpoint
- rts_stop_next_breakpoint = false;
+ rts_stop_next_breakpoint = 0;
+ cap->r.rCurrentTSO->flags &= ~TSO_STOP_NEXT_BREAKPOINT;
// allocate memory for a new AP_STACK, enough to
// store the top stack frame plus an
=====================================
rts/Interpreter.h
=====================================
@@ -11,3 +11,6 @@
RTS_PRIVATE Capability *interpretBCO (Capability* cap);
void interp_startup ( void );
void interp_shutdown ( void );
+
+void rts_enableStopNextBreakpointAll ( void );
+void rts_disableStopNextBreakpointAll ( void );
=====================================
rts/RtsSymbols.c
=====================================
@@ -906,7 +906,8 @@ extern char **environ;
SymI_HasProto(revertCAFs) \
SymI_HasProto(RtsFlags) \
SymI_NeedsDataProto(rts_breakpoint_io_action) \
- SymI_NeedsDataProto(rts_stop_next_breakpoint) \
+ SymI_NeedsDataProto(rts_enableStopNextBreakpointAll) \
+ SymI_NeedsDataProto(rts_disableStopNextBreakpointAll) \
SymI_NeedsDataProto(rts_stop_on_exception) \
SymI_HasProto(stopTimer) \
SymI_HasProto(n_capabilities) \
=====================================
rts/include/rts/Constants.h
=====================================
@@ -328,6 +328,12 @@
*/
#define TSO_ALLOC_LIMIT 256
+/*
+ * Enables step-in mode for this thread -- it will stop at the immediate next
+ * breakpoint found in this thread.
+ */
+#define TSO_STOP_NEXT_BREAKPOINT 512
+
/*
* The number of times we spin in a spin lock before yielding (see
* #3758). To tune this value, use the benchmark in #3758: run the
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c44f60fda04f7e6e9a70318d107d41c…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c44f60fda04f7e6e9a70318d107d41c…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 14 commits: Track rewriter sets more accurately in constraint solving
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
ac9fb269 by Simon Peyton Jones at 2025-05-20T09:19:04-04:00
Track rewriter sets more accurately in constraint solving
This MR addresses #26003, by refactoring the arcane
intricacies of Note [Equalities with incompatible kinds].
NB: now retitled to
Note [Equalities with heterogeneous kinds].
and the main Note for this MR.
In particular:
* Abandon invariant (COERCION-HOLE) in Note [Unification preconditions] in
GHC.Tc.Utils.Unify.
* Abandon invariant (TyEq:CH)) in Note [Canonical equalities] in
GHC.Tc.Types.Constraint.
* Instead: add invariant (REWRITERS) to Note [Unification preconditions]:
unify only if the constraint has an empty rewriter set.
Implementation:
* In canEqCanLHSFinish_try_unification, skip trying unification if there is a
non-empty rewriter set.
* To do this, make sure the rewriter set is zonked; do so in selectNextWorkItem,
which also deals with prioritisation.
* When a coercion hole is filled, kick out inert equalities that have that hole
as a rewriter. It might now be unlocked and available to unify.
* Remove the ad-hoc `ch_hetero_kind` field of `CoercionHole`.
* In `selectNextWorkItem`, priorities equalities withan empty rewriter set.
* Defaulting: see (DE6) in Note [Defaulting equalities]
and Note [Limited defaulting in the ambiguity check]
* Concreteness checks: there is some extra faff to try to get decent
error messages when the FRR (representation-polymorphism) checks
fail. In partiular, add a "When unifying..." explanation when the
representation-polymorphism check arose from another constraint.
- - - - -
86406f48 by Cheng Shao at 2025-05-20T09:19:47-04:00
rts: fix rts_clearMemory logic when sanity checks are enabled
This commit fixes an RTS assertion failure when invoking
rts_clearMemory with +RTS -DS. -DS implies -DZ which asserts that free
blocks contain 0xaa as the designated garbage value. Also adds the
sanity way to rts_clearMemory test to prevent future regression.
Closes #26011.
ChatGPT Codex automatically diagnosed the issue and proposed the
initial patch in a single shot, given a GHC checkout and the following
prompt:
---
Someone is reporting the following error when attempting to use `rts_clearMemory` with the RTS option `-DS`:
```
test.wasm: internal error: ASSERTION FAILED: file rts/sm/Storage.c, line 1216
(GHC version 9.12.2.20250327 for wasm32_unknown_wasi)
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
```
What's the culprit? How do I look into this issue?
---
I manually reviewed & revised the patch, tested and submitted it.
- - - - -
2b795c2f by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: do not allocate strings in bytecode assembler
This patch refactors the compiler to avoid allocating iserv buffers
for BCONPtrStr at assemble-time. Now BCONPtrStr ByteStrings are
recorded as a part of CompiledByteCode, and actual allocation only
happens at link-time. This refactoring is necessary for adding
bytecode serialization functionality, as explained by the revised
comments in this commit.
- - - - -
2914d829 by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: make bc_strs serializable
This commit makes the bc_strs field in CompiledByteCode serializable;
similar to previous commit, we preserve the ByteString directly and
defer the actual allocation to link-time, as mentioned in updated
comment.
- - - - -
a6ec1765 by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: make bc_itbls serializable
This commit makes bc_itbls in CompiledByteCode serializable. A
dedicated ConInfoTable datatype has been added in ghci which is the
recipe for dynamically making a datacon's info table, containing the
payload of the MkConInfoTable iserv message.
- - - - -
a238a259 by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: remove FFIInfo bookkeeping in BCO
This commit removes the bc_ffis field from CompiledByteCode
completely, as well as all the related bookkeeping logic in
GHC.StgToByteCode. bc_ffis is actually *unused* in the rest of GHC
codebase! It is merely a list of FFIInfo, which is just a remote
pointer of the libffi ffi_cif struct; once we allocate the ffi_cif
struct and put its pointer in a CCALL instruction, we'll never free it
anyway. So there is no point of bookkeeping.
- - - - -
1f5cc26b by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: make FFIInfo serializable in BCO
This commit makes all the FFIInfo needed in CCALL instructions
serializable. Previously, when doing STG to BCO lowering, we would
allocate a libffi ffi_cif struct and keep its remote pointer as
FFIInfo; but actually we can just keep the type signature as FFIInfo
and defer the actual allocation to link-time.
- - - - -
20a60364 by Cheng Shao at 2025-05-20T09:51:24-04:00
ghci: remove redundant NewBreakModule message
This commit removes the redundant NewBreakModule message from ghci: it
just allocates two strings! This functionality can be implemented with
existing MallocStrings in one iserv call.
- - - - -
bbfd5a5c by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: make breakpoint module name and unit id serializable
This commit makes breakpoint module name and unit id serializable, in
BRK_FUN instructions as well as ModBreaks. We can simply keep the
module name and unit ids, and defer the buffer allocation to link
time.
- - - - -
aaaf4576 by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: remove unused newModule
This commit removes the now unused newModule function from GHC.
- - - - -
ea0f5482 by Cheng Shao at 2025-05-20T09:51:24-04:00
compiler: add BCONPtrFS for interned top level string literals in BCO
This commit adds BCONPtrFS as a BCO non-pointer literal kind, which
has the same semantics of BCONPtrStr, except it contains a FastString
instead of a ByteString. By using BCONPtrFS to represent top level
string literals that are already FastString in the compilation
pipeline, we enjoy the FastString interning logic and avoid allocating
a bunch of redundant ByteStrings for the same FastStrings, especially
when we lower the BRK_FUN instruction.
- - - - -
55b0dfd8 by Peng Fan at 2025-05-20T09:51:36-04:00
hadrian: enable GHCi for loongarch64
- - - - -
6c1c9110 by kwxm at 2025-05-20T09:51:45-04:00
Fix bugs in `integerRecipMod` and `integerPowMod`
This fixes #26017.
* `integerRecipMod x 1` now returns `(# 1 | #)` for all x; previously it
incorrectly returned `(# | () #)`, indicating failure.
* `integerPowMod 0 e m` now returns `(# | () #)` for e<0 and m>1, indicating
failure; previously it incorrectly returned `(# 0 | #)`.
- - - - -
0155f550 by Andreas Klebinger at 2025-05-20T09:51:46-04:00
Specialise: Don't float out constraint components.
It was fairly complex to do so and it doesn't seem to improve anything.
Nofib allocations were unaffected as well.
See also Historical Note [Floating dictionaries out of cases]
- - - - -
89 changed files:
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/InfoTable.hs
- compiler/GHC/ByteCode/Instr.hs
- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/ByteCode/Types.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/Predicate.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/HsToCore/Breakpoints.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/StgToByteCode.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Plugin.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Default.hs
- compiler/GHC/Tc/Solver/Equality.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Zonk/TcType.hs
- compiler/GHC/Types/Error/Codes.hs
- hadrian/src/Oracles/Flag.hs
- libraries/base/changelog.md
- libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Run.hs
- rts/sm/Storage.h
- testsuite/tests/bytecode/T22376/all.T
- testsuite/tests/dependent/should_fail/T11471.stderr
- testsuite/tests/diagnostic-codes/codes.stdout
- testsuite/tests/ffi/should_run/all.T
- testsuite/tests/indexed-types/should_fail/T8227.stderr
- testsuite/tests/indexed-types/should_fail/T9662.stderr
- + testsuite/tests/lib/integer/T26017.hs
- + testsuite/tests/lib/integer/T26017.stdout
- testsuite/tests/lib/integer/all.T
- testsuite/tests/lib/integer/integerRecipMod.hs
- testsuite/tests/lib/integer/integerRecipMod.stdout
- testsuite/tests/partial-sigs/should_fail/T14040a.stderr
- testsuite/tests/partial-sigs/should_fail/T14584.stderr
- testsuite/tests/perf/should_run/ByteCodeAsm.hs
- testsuite/tests/polykinds/T14172.stderr
- testsuite/tests/polykinds/T14846.stderr
- testsuite/tests/rep-poly/RepPolyArgument.stderr
- testsuite/tests/rep-poly/RepPolyBackpack1.stderr
- testsuite/tests/rep-poly/RepPolyBinder.stderr
- testsuite/tests/rep-poly/RepPolyDoBind.stderr
- testsuite/tests/rep-poly/RepPolyDoBody1.stderr
- testsuite/tests/rep-poly/RepPolyDoBody2.stderr
- testsuite/tests/rep-poly/RepPolyLeftSection2.stderr
- testsuite/tests/rep-poly/RepPolyMagic.stderr
- testsuite/tests/rep-poly/RepPolyMcBind.stderr
- testsuite/tests/rep-poly/RepPolyMcBody.stderr
- testsuite/tests/rep-poly/RepPolyMcGuard.stderr
- testsuite/tests/rep-poly/RepPolyNPlusK.stderr
- testsuite/tests/rep-poly/RepPolyPatBind.stderr
- testsuite/tests/rep-poly/RepPolyRecordUpdate.stderr
- testsuite/tests/rep-poly/RepPolyRightSection.stderr
- testsuite/tests/rep-poly/RepPolyRule1.stderr
- testsuite/tests/rep-poly/RepPolyTuple.stderr
- testsuite/tests/rep-poly/RepPolyTuple4.stderr
- testsuite/tests/rep-poly/RepPolyTupleSection.stderr
- testsuite/tests/rep-poly/RepPolyWrappedVar.stderr
- testsuite/tests/rep-poly/T11473.stderr
- testsuite/tests/rep-poly/T12709.stderr
- testsuite/tests/rep-poly/T12973.stderr
- testsuite/tests/rep-poly/T13233.stderr
- testsuite/tests/rep-poly/T13929.stderr
- testsuite/tests/rep-poly/T14561.stderr
- testsuite/tests/rep-poly/T14561b.stderr
- testsuite/tests/rep-poly/T17817.stderr
- testsuite/tests/rep-poly/T19615.stderr
- testsuite/tests/rep-poly/T19709b.stderr
- testsuite/tests/rep-poly/T21906.stderr
- testsuite/tests/rep-poly/T23903.stderr
- testsuite/tests/rep-poly/UnliftedNewtypesCoerceFail.stderr
- testsuite/tests/typecheck/no_skolem_info/T14040.stderr
- testsuite/tests/typecheck/should_compile/T25266a.stderr
- testsuite/tests/typecheck/should_fail/T16204c.stderr
- testsuite/tests/typecheck/should_fail/T7696.stderr
- testsuite/tests/typecheck/should_fail/T8603.stderr
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/482c7ce093c840e0e657f96f705efa…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/482c7ce093c840e0e657f96f705efa…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][master] rts: fix rts_clearMemory logic when sanity checks are enabled
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
86406f48 by Cheng Shao at 2025-05-20T09:19:47-04:00
rts: fix rts_clearMemory logic when sanity checks are enabled
This commit fixes an RTS assertion failure when invoking
rts_clearMemory with +RTS -DS. -DS implies -DZ which asserts that free
blocks contain 0xaa as the designated garbage value. Also adds the
sanity way to rts_clearMemory test to prevent future regression.
Closes #26011.
ChatGPT Codex automatically diagnosed the issue and proposed the
initial patch in a single shot, given a GHC checkout and the following
prompt:
---
Someone is reporting the following error when attempting to use `rts_clearMemory` with the RTS option `-DS`:
```
test.wasm: internal error: ASSERTION FAILED: file rts/sm/Storage.c, line 1216
(GHC version 9.12.2.20250327 for wasm32_unknown_wasi)
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
```
What's the culprit? How do I look into this issue?
---
I manually reviewed & revised the patch, tested and submitted it.
- - - - -
2 changed files:
- rts/sm/Storage.h
- testsuite/tests/ffi/should_run/all.T
Changes:
=====================================
rts/sm/Storage.h
=====================================
@@ -213,7 +213,8 @@ extern StgIndStatic * debug_caf_list;
extern StgIndStatic * revertible_caf_list;
INLINE_HEADER void clear_blocks(bdescr *bd) {
- memset(bd->start, 0, BLOCK_SIZE * bd->blocks);
+ memset(bd->start, RtsFlags.DebugFlags.zero_on_gc ? 0xaa : 0,
+ BLOCK_SIZE * bd->blocks);
}
#include "EndPrivate.h"
=====================================
testsuite/tests/ffi/should_run/all.T
=====================================
@@ -188,8 +188,8 @@ test('ffi023', [ omit_ghci,
test('rts_clearMemory', [
# We only care about different GC configurations under the
# single-threaded RTS for the time being.
- only_ways(['normal', 'optasm' ,'g1', 'nursery_chunks', 'nonmoving', 'compacting_gc']),
- extra_ways(['g1', 'nursery_chunks', 'nonmoving', 'compacting_gc']),
+ only_ways(['normal', 'optasm' ,'g1', 'nursery_chunks', 'nonmoving', 'compacting_gc', 'sanity']),
+ extra_ways(['g1', 'nursery_chunks', 'nonmoving', 'compacting_gc', 'sanity']),
# On windows, nonmoving way fails with bad exit code (2816)
when(opsys('mingw32'), fragile(23091)),
req_c,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/86406f48659a5ab61ce1fd2a2d427fa…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/86406f48659a5ab61ce1fd2a2d427fa…
You're receiving this email because of your account on gitlab.haskell.org.
1
0

[Git][ghc/ghc][master] Track rewriter sets more accurately in constraint solving
by Marge Bot (@marge-bot) 20 May '25
by Marge Bot (@marge-bot) 20 May '25
20 May '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
ac9fb269 by Simon Peyton Jones at 2025-05-20T09:19:04-04:00
Track rewriter sets more accurately in constraint solving
This MR addresses #26003, by refactoring the arcane
intricacies of Note [Equalities with incompatible kinds].
NB: now retitled to
Note [Equalities with heterogeneous kinds].
and the main Note for this MR.
In particular:
* Abandon invariant (COERCION-HOLE) in Note [Unification preconditions] in
GHC.Tc.Utils.Unify.
* Abandon invariant (TyEq:CH)) in Note [Canonical equalities] in
GHC.Tc.Types.Constraint.
* Instead: add invariant (REWRITERS) to Note [Unification preconditions]:
unify only if the constraint has an empty rewriter set.
Implementation:
* In canEqCanLHSFinish_try_unification, skip trying unification if there is a
non-empty rewriter set.
* To do this, make sure the rewriter set is zonked; do so in selectNextWorkItem,
which also deals with prioritisation.
* When a coercion hole is filled, kick out inert equalities that have that hole
as a rewriter. It might now be unlocked and available to unify.
* Remove the ad-hoc `ch_hetero_kind` field of `CoercionHole`.
* In `selectNextWorkItem`, priorities equalities withan empty rewriter set.
* Defaulting: see (DE6) in Note [Defaulting equalities]
and Note [Limited defaulting in the ambiguity check]
* Concreteness checks: there is some extra faff to try to get decent
error messages when the FRR (representation-polymorphism) checks
fail. In partiular, add a "When unifying..." explanation when the
representation-polymorphism check arose from another constraint.
- - - - -
65 changed files:
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Predicate.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Plugin.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Default.hs
- compiler/GHC/Tc/Solver/Equality.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Zonk/TcType.hs
- compiler/GHC/Types/Error/Codes.hs
- testsuite/tests/dependent/should_fail/T11471.stderr
- testsuite/tests/diagnostic-codes/codes.stdout
- testsuite/tests/indexed-types/should_fail/T8227.stderr
- testsuite/tests/indexed-types/should_fail/T9662.stderr
- testsuite/tests/partial-sigs/should_fail/T14040a.stderr
- testsuite/tests/partial-sigs/should_fail/T14584.stderr
- testsuite/tests/polykinds/T14172.stderr
- testsuite/tests/polykinds/T14846.stderr
- testsuite/tests/rep-poly/RepPolyArgument.stderr
- testsuite/tests/rep-poly/RepPolyBackpack1.stderr
- testsuite/tests/rep-poly/RepPolyBinder.stderr
- testsuite/tests/rep-poly/RepPolyDoBind.stderr
- testsuite/tests/rep-poly/RepPolyDoBody1.stderr
- testsuite/tests/rep-poly/RepPolyDoBody2.stderr
- testsuite/tests/rep-poly/RepPolyLeftSection2.stderr
- testsuite/tests/rep-poly/RepPolyMagic.stderr
- testsuite/tests/rep-poly/RepPolyMcBind.stderr
- testsuite/tests/rep-poly/RepPolyMcBody.stderr
- testsuite/tests/rep-poly/RepPolyMcGuard.stderr
- testsuite/tests/rep-poly/RepPolyNPlusK.stderr
- testsuite/tests/rep-poly/RepPolyPatBind.stderr
- testsuite/tests/rep-poly/RepPolyRecordUpdate.stderr
- testsuite/tests/rep-poly/RepPolyRightSection.stderr
- testsuite/tests/rep-poly/RepPolyRule1.stderr
- testsuite/tests/rep-poly/RepPolyTuple.stderr
- testsuite/tests/rep-poly/RepPolyTuple4.stderr
- testsuite/tests/rep-poly/RepPolyTupleSection.stderr
- testsuite/tests/rep-poly/RepPolyWrappedVar.stderr
- testsuite/tests/rep-poly/T11473.stderr
- testsuite/tests/rep-poly/T12709.stderr
- testsuite/tests/rep-poly/T12973.stderr
- testsuite/tests/rep-poly/T13233.stderr
- testsuite/tests/rep-poly/T13929.stderr
- testsuite/tests/rep-poly/T14561.stderr
- testsuite/tests/rep-poly/T14561b.stderr
- testsuite/tests/rep-poly/T17817.stderr
- testsuite/tests/rep-poly/T19615.stderr
- testsuite/tests/rep-poly/T19709b.stderr
- testsuite/tests/rep-poly/T21906.stderr
- testsuite/tests/rep-poly/T23903.stderr
- testsuite/tests/rep-poly/UnliftedNewtypesCoerceFail.stderr
- testsuite/tests/typecheck/no_skolem_info/T14040.stderr
- testsuite/tests/typecheck/should_compile/T25266a.stderr
- testsuite/tests/typecheck/should_fail/T16204c.stderr
- testsuite/tests/typecheck/should_fail/T7696.stderr
- testsuite/tests/typecheck/should_fail/T8603.stderr
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ac9fb269786a10221729731a4776c28…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ac9fb269786a10221729731a4776c28…
You're receiving this email because of your account on gitlab.haskell.org.
1
0