[Git][ghc/ghc][wip/sjakobi/T2057] 2 commits: testsuite: refactor T2057 test layout
by Simon Jakobi (@sjakobi2) 09 Mar '26
by Simon Jakobi (@sjakobi2) 09 Mar '26
09 Mar '26
Simon Jakobi pushed to branch wip/sjakobi/T2057 at Glasgow Haskell Compiler / GHC
Commits:
3180476f by Simon Jakobi at 2026-03-09T01:02:03+01:00
testsuite: refactor T2057 test layout
- - - - -
13ab42f4 by Simon Jakobi at 2026-03-09T01:02:21+01:00
testsuite: drop T2057 generated work files
- - - - -
14 changed files:
- + testsuite/tests/driver/T2057/.gitignore
- testsuite/tests/driver/T2057/Makefile
- testsuite/tests/driver/T2057/T2057.stderr
- testsuite/tests/driver/T2057/all.T
- testsuite/tests/driver/T2057/src/app/Main.hs → testsuite/tests/driver/T2057/app/Main.hs
- − testsuite/tests/driver/T2057/basepkg-v1.conf.in
- − testsuite/tests/driver/T2057/basepkg-v2.conf.in
- − testsuite/tests/driver/T2057/dep.conf.in
- + testsuite/tests/driver/T2057/pkgA1.conf.in
- testsuite/tests/driver/T2057/src/base-v1/Base.hs → testsuite/tests/driver/T2057/pkgA1/A.hs
- + testsuite/tests/driver/T2057/pkgA2.conf.in
- testsuite/tests/driver/T2057/src/base-v2/Base.hs → testsuite/tests/driver/T2057/pkgA2/A.hs
- + testsuite/tests/driver/T2057/pkgB.conf.in
- testsuite/tests/driver/T2057/src/dep/Dep.hs → testsuite/tests/driver/T2057/pkgB/B.hs
Changes:
=====================================
testsuite/tests/driver/T2057/.gitignore
=====================================
@@ -0,0 +1 @@
+work/
=====================================
testsuite/tests/driver/T2057/Makefile
=====================================
@@ -4,9 +4,9 @@ include $(TOP)/mk/test.mk
WORK = work
PKGDB = $(WORK)/pkgdb
-BASE_V1 = $(WORK)/basepkg-v1
-BASE_V2 = $(WORK)/basepkg-v2
-DEP = $(WORK)/dep
+PKGA1 = $(WORK)/pkgA1
+PKGA2 = $(WORK)/pkgA2
+PKGB = $(WORK)/pkgB
APP = $(WORK)/app
OUT = $(WORK)/T2057.out
@@ -15,29 +15,30 @@ OUT = $(WORK)/T2057.out
clean:
rm -rf $(WORK)
+# Dependency graph:
+# pkgB is built against pkgA1.
+# We then rebuild the same installed unit id (pkgA1-1) from the pkgA2 sources,
+# leaving pkgB with a stale unfolding that still references pkgA1's old API.
+# Compiling Main against pkgB should therefore stop at the interface error.
T2057: clean
@set -eu; \
BASE_ID=`'$(GHC_PKG)' field base id --simple-output`; \
- mkdir -p '$(BASE_V1)' '$(BASE_V2)' '$(DEP)' '$(APP)'; \
+ mkdir -p '$(PKGA1)' '$(PKGA2)' '$(PKGB)' '$(APP)'; \
'$(GHC_PKG)' init '$(PKGDB)'; \
- cp src/base-v1/Base.hs '$(BASE_V1)/Base.hs'; \
- cp src/base-v2/Base.hs '$(BASE_V2)/Base.hs'; \
- cp src/dep/Dep.hs '$(DEP)/Dep.hs'; \
- cp src/app/Main.hs '$(APP)/Main.hs'; \
- '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -this-unit-id basepkg-1 -O -c '$(BASE_V1)/Base.hs' -outputdir '$(BASE_V1)'; \
- ar q '$(BASE_V1)/libHSbasepkg-1.a' '$(BASE_V1)/Base.o' >/dev/null 2>&1; \
- sed "s|@BASE_ID@|$$BASE_ID|g" basepkg-v1.conf.in >'$(WORK)/basepkg-v1.conf'; \
- '$(GHC_PKG)' --package-db '$(PKGDB)' register '$(WORK)/basepkg-v1.conf' >/dev/null; \
- '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -package basepkg -this-unit-id dep-1 -O -c '$(DEP)/Dep.hs' -outputdir '$(DEP)'; \
- ar q '$(DEP)/libHSdep-1.a' '$(DEP)/Dep.o' >/dev/null 2>&1; \
- sed "s|@BASE_ID@|$$BASE_ID|g" dep.conf.in >'$(WORK)/dep.conf'; \
- '$(GHC_PKG)' --package-db '$(PKGDB)' register '$(WORK)/dep.conf' >/dev/null; \
- '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -this-unit-id basepkg-1 -O -c '$(BASE_V2)/Base.hs' -outputdir '$(BASE_V2)'; \
- ar q '$(BASE_V2)/libHSbasepkg-1.a' '$(BASE_V2)/Base.o' >/dev/null 2>&1; \
- sed "s|@BASE_ID@|$$BASE_ID|g" basepkg-v2.conf.in >'$(WORK)/basepkg-v2.conf'; \
- '$(GHC_PKG)' --package-db '$(PKGDB)' update '$(WORK)/basepkg-v2.conf' >/dev/null; \
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -this-unit-id pkgA1-1 -O -c pkgA1/A.hs -outputdir '$(PKGA1)'; \
+ ar q '$(PKGA1)/libHSpkgA1-1.a' '$(PKGA1)/A.o' >/dev/null 2>&1; \
+ sed "s|@BASE_ID@|$$BASE_ID|g" pkgA1.conf.in >'$(WORK)/pkgA1.conf'; \
+ '$(GHC_PKG)' --package-db '$(PKGDB)' register '$(WORK)/pkgA1.conf' >/dev/null; \
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -package pkgA1 -this-unit-id pkgB-1 -O -c pkgB/B.hs -outputdir '$(PKGB)'; \
+ ar q '$(PKGB)/libHSpkgB-1.a' '$(PKGB)/B.o' >/dev/null 2>&1; \
+ sed "s|@BASE_ID@|$$BASE_ID|g" pkgB.conf.in >'$(WORK)/pkgB.conf'; \
+ '$(GHC_PKG)' --package-db '$(PKGDB)' register '$(WORK)/pkgB.conf' >/dev/null; \
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -package-db '$(PKGDB)' -this-unit-id pkgA1-1 -O -c pkgA2/A.hs -outputdir '$(PKGA2)'; \
+ ar q '$(PKGA2)/libHSpkgA1-1.a' '$(PKGA2)/A.o' >/dev/null 2>&1; \
+ sed "s|@BASE_ID@|$$BASE_ID|g" pkgA2.conf.in >'$(WORK)/pkgA2.conf'; \
+ '$(GHC_PKG)' --package-db '$(PKGDB)' update '$(WORK)/pkgA2.conf' >/dev/null; \
status=0; \
- '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make '$(APP)/Main.hs' -O -fforce-recomp -package-db '$(PKGDB)' -package dep >'$(OUT)' 2>&1 || status=$$?; \
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make app/Main.hs -O -fforce-recomp -package-db '$(PKGDB)' -package pkgB >'$(OUT)' 2>&1 || status=$$?; \
if [ $$status -eq 0 ]; then \
echo "expected compilation failure" >&2; \
exit 1; \
=====================================
testsuite/tests/driver/T2057/T2057.stderr
=====================================
@@ -1,4 +1,4 @@
-work/dep/Dep.hi
+work/pkgB/B.hi
Declaration for saved
Unfolding of saved:
staleDependencyBinding ErrorWithoutFlag
=====================================
testsuite/tests/driver/T2057/all.T
=====================================
@@ -1,6 +1,6 @@
test(
'T2057',
- [ extra_files(['src', 'basepkg-v1.conf.in', 'basepkg-v2.conf.in', 'dep.conf.in'])
+ [ extra_files(['pkgA1', 'pkgA2', 'pkgB', 'app', 'pkgA1.conf.in', 'pkgA2.conf.in', 'pkgB.conf.in'])
, when(opsys('mingw32'), skip)
, js_skip
, wasm_skip
=====================================
testsuite/tests/driver/T2057/src/app/Main.hs → testsuite/tests/driver/T2057/app/Main.hs
=====================================
@@ -1,6 +1,6 @@
module Main where
-import Dep
+import B
main :: IO ()
main = print (saved 41)
=====================================
testsuite/tests/driver/T2057/basepkg-v1.conf.in deleted
=====================================
@@ -1,11 +0,0 @@
-name: basepkg
-version: 1.0
-id: basepkg-1
-key: basepkg-1
-exposed: True
-exposed-modules: Base
-import-dirs: ${pkgroot}/basepkg-v1
-library-dirs: ${pkgroot}/basepkg-v1
-dynamic-library-dirs: ${pkgroot}/basepkg-v1
-hs-libraries: HSbasepkg-1
-depends: @BASE_ID@
=====================================
testsuite/tests/driver/T2057/basepkg-v2.conf.in deleted
=====================================
@@ -1,11 +0,0 @@
-name: basepkg
-version: 1.0
-id: basepkg-1
-key: basepkg-1
-exposed: True
-exposed-modules: Base
-import-dirs: ${pkgroot}/basepkg-v2
-library-dirs: ${pkgroot}/basepkg-v2
-dynamic-library-dirs: ${pkgroot}/basepkg-v2
-hs-libraries: HSbasepkg-1
-depends: @BASE_ID@
=====================================
testsuite/tests/driver/T2057/dep.conf.in deleted
=====================================
@@ -1,11 +0,0 @@
-name: dep
-version: 1.0
-id: dep-1
-key: dep-1
-exposed: True
-exposed-modules: Dep
-import-dirs: ${pkgroot}/dep
-library-dirs: ${pkgroot}/dep
-dynamic-library-dirs: ${pkgroot}/dep
-hs-libraries: HSdep-1
-depends: basepkg-1 @BASE_ID@
=====================================
testsuite/tests/driver/T2057/pkgA1.conf.in
=====================================
@@ -0,0 +1,11 @@
+name: pkgA1
+version: 1.0
+id: pkgA1-1
+key: pkgA1-1
+exposed: True
+exposed-modules: A
+import-dirs: ${pkgroot}/pkgA1
+library-dirs: ${pkgroot}/pkgA1
+dynamic-library-dirs: ${pkgroot}/pkgA1
+hs-libraries: HSpkgA1-1
+depends: @BASE_ID@
=====================================
testsuite/tests/driver/T2057/src/base-v1/Base.hs → testsuite/tests/driver/T2057/pkgA1/A.hs
=====================================
@@ -1,4 +1,4 @@
-module Base (staleDependencyBinding) where
+module A (staleDependencyBinding) where
{-# INLINE staleDependencyBinding #-}
staleDependencyBinding :: Int -> Int
=====================================
testsuite/tests/driver/T2057/pkgA2.conf.in
=====================================
@@ -0,0 +1,11 @@
+name: pkgA1
+version: 1.0
+id: pkgA1-1
+key: pkgA1-1
+exposed: True
+exposed-modules: A
+import-dirs: ${pkgroot}/pkgA2
+library-dirs: ${pkgroot}/pkgA2
+dynamic-library-dirs: ${pkgroot}/pkgA2
+hs-libraries: HSpkgA1-1
+depends: @BASE_ID@
=====================================
testsuite/tests/driver/T2057/src/base-v2/Base.hs → testsuite/tests/driver/T2057/pkgA2/A.hs
=====================================
@@ -1,4 +1,4 @@
-module Base (replacementBinding) where
+module A (replacementBinding) where
replacementBinding :: Int -> Int
replacementBinding x = x + 100
=====================================
testsuite/tests/driver/T2057/pkgB.conf.in
=====================================
@@ -0,0 +1,11 @@
+name: pkgB
+version: 1.0
+id: pkgB-1
+key: pkgB-1
+exposed: True
+exposed-modules: B
+import-dirs: ${pkgroot}/pkgB
+library-dirs: ${pkgroot}/pkgB
+dynamic-library-dirs: ${pkgroot}/pkgB
+hs-libraries: HSpkgB-1
+depends: pkgA1-1 @BASE_ID@
=====================================
testsuite/tests/driver/T2057/src/dep/Dep.hs → testsuite/tests/driver/T2057/pkgB/B.hs
=====================================
@@ -1,6 +1,6 @@
-module Dep (saved) where
+module B (saved) where
-import Base
+import A
{-# INLINE saved #-}
saved :: Int -> Int
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/aacab4158c96a461eff6dd80010224…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/aacab4158c96a461eff6dd80010224…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
08 Mar '26
Simon Jakobi pushed new branch wip/sjakobi/T2057 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/T2057
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: compiler: add myCapabilityExpr to GHC.Cmm.Utils
by Marge Bot (@marge-bot) 08 Mar '26
by Marge Bot (@marge-bot) 08 Mar '26
08 Mar '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
176c0d27 by Cheng Shao at 2026-03-08T18:19:31-04:00
compiler: add myCapabilityExpr to GHC.Cmm.Utils
This commit adds `myCapabilityExpr` to `GHC.Cmm.Utils` which is
computed from `BaseReg`. It's convenient for codegen logic where one
needs to pass the current Capability's pointer.
- - - - -
db303e85 by Cheng Shao at 2026-03-08T18:19:31-04:00
compiler: lower tryPutMVar# into a ccall directly
This patch addresses an old TODO of `stg_tryPutMVarzh` by removing it
completely and making the compiler lower `tryPutMVar#` into a ccall to
`performTryPutMVar` directly, without landing into an intermediate C
or Cmm function. `performTryPutMVar` is promoted to a public RTS
function with default visibility, and the compiler lowering logic
takes into account the C ABI of `performTryPutMVar` and converts from
C Bool to primop's `Int#` result properly.
- - - - -
52957fe0 by Simon Hengel at 2026-03-08T18:19:33-04:00
Don't use #line in haddocks
This confuses the parser. Haddock output is unaffected by this change.
(read: this still produces the same documentation)
- - - - -
878dcddf by Wolfgang Jeltsch at 2026-03-08T18:19:35-04:00
Remove in-package dependencies on `GHC.Internal.System.IO`
This contribution eliminates all dependencies on
`GHC.Internal.System.IO` from within `ghc-internal`. It comprises the
following changes:
* Make `GHC.Internal.Fingerprint` independent of I/O support
* Tighten the dependencies of `GHC.Internal.Data.Version`
* Tighten the dependencies of `GHC.Internal.TH.Monad`
* Tighten the dependencies of `GHCi.Helpers`
* Move some code that needs `System.IO` to `template-haskell`
* Move the `GHC.ResponseFile` implementation into `base`
* Move the `System.Exit` implementation into `base`
* Move the `System.IO.OS` implementation into `base`
Metric Decrease:
size_hello_artifact
size_hello_artifact_gzip
size_hello_unicode
size_hello_unicode_gzip
- - - - -
0a1ff530 by Sylvain Henry at 2026-03-08T18:19:44-04:00
T18832: fix Windows CI failure by dropping removeDirectoryRecursive
On Windows, open file handles prevent deletion. After killThread, the
closer thread may not have called hClose yet, causing removeDirectoryRecursive
to fail with "permission denied". The test harness cleans up the run
directory anyway, so the call is redundant.
- - - - -
b52fbf43 by Cheng Shao at 2026-03-08T18:19:45-04:00
compiler: fix redundant import in GHC.StgToJS.Object
This patch fixes a redundant import in GHC.StgToJS.Object that causes
a build failure when compiling head from 9.14 with validate flavours.
Fixes #26991.
- - - - -
9c734a7e by Cheng Shao at 2026-03-08T18:19:46-04:00
wasm: fix `Illegal foreign declaration` failure when ghci loads modules with JSFFI exports
This patch fixes a wasm ghci error when loading modules with JSFFI
exports; the `backendValidityOfCExport` check in `tcCheckFEType`
should only makes sense and should be performed when not checking the
JavaScript calling convention; otherwise, when the calling convention
is JavaScript, the codegen logic should be trusted to backends that
actually make use of it. Fixes #26998.
- - - - -
29 changed files:
- compiler/GHC/Cmm/Utils.hs
- compiler/GHC/Iface/Ext/Utils.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/StgToJS/Object.hs
- compiler/GHC/Tc/Gen/Foreign.hs
- libraries/base/src/GHC/Fingerprint.hs
- libraries/base/src/GHC/ResponseFile.hs
- libraries/base/src/System/Exit.hs
- libraries/base/src/System/IO/OS.hs
- libraries/base/tests/IO/T18832.hs
- libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
- libraries/ghc-internal/ghc-internal.cabal.in
- libraries/ghc-internal/src/GHC/Internal/Data/Version.hs
- libraries/ghc-internal/src/GHC/Internal/Fingerprint.hs
- libraries/ghc-internal/src/GHC/Internal/GHCi/Helpers.hs
- − libraries/ghc-internal/src/GHC/Internal/ResponseFile.hs
- − libraries/ghc-internal/src/GHC/Internal/System/Exit.hs
- − libraries/ghc-internal/src/GHC/Internal/System/IO/OS.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Monad.hs
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- rts/PrimOps.cmm
- rts/RtsSymbols.c
- rts/Threads.c
- rts/Threads.h
- rts/include/rts/Threads.h
- rts/include/stg/MiscClosures.h
- testsuite/tests/ffi/should_compile/all.T
- + testsuite/tests/ghci-wasm/T26998.hs
- testsuite/tests/ghci-wasm/all.T
Changes:
=====================================
compiler/GHC/Cmm/Utils.hs
=====================================
@@ -37,6 +37,7 @@ module GHC.Cmm.Utils(
baseExpr, spExpr, hpExpr, spLimExpr, hpLimExpr,
currentTSOExpr, currentNurseryExpr, cccsExpr,
+ myCapabilityExpr,
-- Tagging
cmmTagMask, cmmPointerMask, cmmUntag, cmmIsTagged, cmmIsNotTagged,
@@ -569,7 +570,7 @@ blockTicks b = reverse $ foldBlockNodesF goStmt b []
-- Access to common global registers
baseExpr, spExpr, hpExpr, currentTSOExpr, currentNurseryExpr,
- spLimExpr, hpLimExpr, cccsExpr :: Platform -> CmmExpr
+ spLimExpr, hpLimExpr, cccsExpr, myCapabilityExpr :: Platform -> CmmExpr
baseExpr p = CmmReg $ baseReg p
spExpr p = CmmReg $ spReg p
spLimExpr p = CmmReg $ spLimReg p
@@ -578,3 +579,5 @@ hpLimExpr p = CmmReg $ hpLimReg p
currentTSOExpr p = CmmReg $ currentTSOReg p
currentNurseryExpr p = CmmReg $ currentNurseryReg p
cccsExpr p = CmmReg $ cccsReg p
+myCapabilityExpr p =
+ cmmRegOff (baseReg p) $ negate $ pc_OFFSET_Capability_r $ platformConstants p
=====================================
compiler/GHC/Iface/Ext/Utils.hs
=====================================
@@ -461,11 +461,11 @@ in which @foozball@ and @quuuuuux@ have overlapping spans:
@
module Baz where
-# line 3 "Baz.hs"
+# \line 3 "Baz.hs"
foozball :: Int
foozball = 0
-# line 3 "Baz.hs"
+# \line 3 "Baz.hs"
bar, quuuuuux :: Int
bar = 1
quuuuuux = 2
=====================================
compiler/GHC/StgToCmm/Prim.hs
=====================================
@@ -345,6 +345,25 @@ emitPrimOp cfg primop =
emitPrimCall [res] (MO_Xchg (wordWidth platform)) [dst, val]
emitDirtyMutVar mutv (CmmReg (CmmLocal res))
+ TryPutMVarOp -> \[mvar, val] -> inlinePrimop $ \[res] -> do
+ cres <- newTemp b8
+ emitCCall
+ [(cres, NoHint)]
+ ( CmmLit
+ ( CmmLabel
+ ( mkForeignLabel
+ (fsLit "performTryPutMVar")
+ ForeignLabelInExternalPackage
+ IsFunction
+ )
+ )
+ )
+ [(myCapabilityExpr platform, AddrHint), (mvar, AddrHint), (val, AddrHint)]
+ emitAssign (CmmLocal res) $
+ CmmMachOp
+ (MO_UU_Conv W8 (wordWidth platform))
+ [CmmReg (CmmLocal cres)]
+
-- #define sizzeofByteArrayzh(r,a) \
-- r = ((StgArrBytes *)(a))->bytes
SizeofByteArrayOp -> \[arg] -> inlinePrimop $ \[res] ->
@@ -1777,7 +1796,6 @@ emitPrimOp cfg primop =
TakeMVarOp -> alwaysExternal
TryTakeMVarOp -> alwaysExternal
PutMVarOp -> alwaysExternal
- TryPutMVarOp -> alwaysExternal
ReadMVarOp -> alwaysExternal
TryReadMVarOp -> alwaysExternal
IsEmptyMVarOp -> alwaysExternal
=====================================
compiler/GHC/StgToJS/Object.hs
=====================================
@@ -72,7 +72,6 @@ import Data.List (sortOn)
import qualified Data.List as List
import Data.Map (Map)
import qualified Data.Map as M
-import Data.Word
import Data.Semigroup
import System.IO
=====================================
compiler/GHC/Tc/Gen/Foreign.hs
=====================================
@@ -449,8 +449,9 @@ tcFExport d = pprPanic "tcFExport" (ppr d)
tcCheckFEType :: Type -> ForeignExport GhcRn -> TcM (ForeignExport GhcTc)
tcCheckFEType sig_ty edecl@(CExport src (L l (CExportStatic str cconv))) = do
- checkCg (Left edecl) backendValidityOfCExport
- when (cconv /= JavaScriptCallConv) $ checkTc (isCLabelString str) (TcRnInvalidCIdentifier str)
+ when (cconv /= JavaScriptCallConv) $ do
+ checkCg (Left edecl) backendValidityOfCExport
+ checkTc (isCLabelString str) (TcRnInvalidCIdentifier str)
cconv' <- checkCConv (Left edecl) cconv
checkForeignArgs isFFIExternalTy arg_tys
checkForeignRes nonIOok noCheckSafe isFFIExportResultTy res_ty
=====================================
libraries/base/src/GHC/Fingerprint.hs
=====================================
@@ -9,3 +9,45 @@ module GHC.Fingerprint (
) where
import GHC.Internal.Fingerprint
+
+import Data.Function (($))
+import Control.Monad (return, when)
+import Data.Bool (not, (&&))
+import Data.List ((++))
+import Data.Maybe (Maybe (Nothing, Just))
+import Data.Int (Int)
+import Data.Word (Word8)
+import Data.Eq ((/=))
+import Text.Show (show)
+import System.IO
+ (
+ IO,
+ FilePath,
+ IOMode (ReadMode),
+ withBinaryFile,
+ hGetBuf,
+ hIsEOF
+ )
+import Foreign.Ptr (Ptr)
+import GHC.Err (errorWithoutStackTrace)
+
+-- | Computes the hash of a given file.
+-- This function runs in constant memory.
+--
+-- @since base-4.7.0.0
+getFileHash :: FilePath -> IO Fingerprint
+getFileHash path = withBinaryFile path ReadMode $ \ hdl ->
+ let
+ readChunk :: Ptr Word8 -> Int -> IO (Maybe Int)
+ readChunk bufferPtr bufferSize = do
+ chunkSize <- hGetBuf hdl bufferPtr bufferSize
+ isFinished <- hIsEOF hdl
+ when (chunkSize /= bufferSize && not isFinished)
+ (
+ errorWithoutStackTrace $
+ "GHC.Fingerprint.getFileHash: could only read " ++
+ show chunkSize ++
+ " bytes, but more are available"
+ )
+ return (if isFinished then Just chunkSize else Nothing)
+ in fingerprintBufferedStream readChunk
=====================================
libraries/base/src/GHC/ResponseFile.hs
=====================================
@@ -1,3 +1,4 @@
+{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Safe #-}
-- |
@@ -19,4 +20,145 @@ module GHC.ResponseFile (
expandResponse
) where
-import GHC.Internal.ResponseFile
+import Control.Monad (return, (>>=), mapM)
+import Control.Exception (IOException, catch)
+import Data.Function (($), (.))
+import Data.Bool (Bool (False, True), otherwise, not, (||))
+import Data.Char (Char, isSpace)
+import Data.List ((++), map, filter, concat, reverse)
+import Data.String (String, unlines)
+import Data.Functor (fmap)
+import Data.Foldable (null, foldl')
+import Data.Eq ((==))
+import Text.Show (show)
+import System.Environment (getArgs)
+import System.IO (IO, hPutStrLn, readFile, stderr)
+import System.Exit (exitFailure)
+
+{-|
+Like 'getArgs', but can also read arguments supplied via response files.
+
+
+For example, consider a program @foo@:
+
+@
+main :: IO ()
+main = do
+ args <- getArgsWithResponseFiles
+ putStrLn (show args)
+@
+
+
+And a response file @args.txt@:
+
+@
+--one 1
+--\'two\' 2
+--"three" 3
+@
+
+Then the result of invoking @foo@ with @args.txt@ is:
+
+> > ./foo @args.txt
+> ["--one","1","--two","2","--three","3"]
+
+-}
+getArgsWithResponseFiles :: IO [String]
+getArgsWithResponseFiles = getArgs >>= expandResponse
+
+-- | Given a string of concatenated strings, separate each by removing
+-- a layer of /quoting/ and\/or /escaping/ of certain characters.
+--
+-- These characters are: any whitespace, single quote, double quote,
+-- and the backslash character. The backslash character always
+-- escapes (i.e., passes through without further consideration) the
+-- character which follows. Characters can also be escaped in blocks
+-- by quoting (i.e., surrounding the blocks with matching pairs of
+-- either single- or double-quotes which are not themselves escaped).
+--
+-- Any whitespace which appears outside of either of the quoting and
+-- escaping mechanisms, is interpreted as having been added by this
+-- special concatenation process to designate where the boundaries
+-- are between the original, un-concatenated list of strings. These
+-- added whitespace characters are removed from the output.
+--
+-- > unescapeArgs "hello\\ \\\"world\\\"\n" == ["hello \"world\""]
+unescapeArgs :: String -> [String]
+unescapeArgs = filter (not . null) . unescape
+
+-- | Given a list of strings, concatenate them into a single string
+-- with escaping of certain characters, and the addition of a newline
+-- between each string. The escaping is done by adding a single
+-- backslash character before any whitespace, single quote, double
+-- quote, or backslash character, so this escaping character must be
+-- removed. Unescaped whitespace (in this case, newline) is part
+-- of this "transport" format to indicate the end of the previous
+-- string and the start of a new string.
+--
+-- While 'unescapeArgs' allows using quoting (i.e., convenient
+-- escaping of many characters) by having matching sets of single- or
+-- double-quotes,'escapeArgs' does not use the quoting mechanism,
+-- and thus will always escape any whitespace, quotes, and
+-- backslashes.
+--
+-- > escapeArgs ["hello \"world\""] == "hello\\ \\\"world\\\"\n"
+escapeArgs :: [String] -> String
+escapeArgs = unlines . map escapeArg
+
+-- | Arguments which look like @\@foo@ will be replaced with the
+-- contents of file @foo@. A gcc-like syntax for response files arguments
+-- is expected. This must re-constitute the argument list by doing an
+-- inverse of the escaping mechanism done by the calling-program side.
+--
+-- We quit if the file is not found or reading somehow fails.
+-- (A convenience routine for haddock or possibly other clients)
+expandResponse :: [String] -> IO [String]
+expandResponse = fmap concat . mapM expand
+ where
+ expand :: String -> IO [String]
+ expand ('@':f) = readFileExc f >>= return . unescapeArgs
+ expand x = return [x]
+
+ readFileExc f =
+ readFile f `catch` \(e :: IOException) -> do
+ hPutStrLn stderr $ "Error while expanding response file: " ++ show e
+ exitFailure
+
+data Quoting = NoneQ | SngQ | DblQ
+
+unescape :: String -> [String]
+unescape args = reverse . map reverse $ go args NoneQ False [] []
+ where
+ -- n.b., the order of these cases matters; these are cribbed from gcc
+ -- case 1: end of input
+ go [] _q _bs a as = a:as
+ -- case 2: back-slash escape in progress
+ go (c:cs) q True a as = go cs q False (c:a) as
+ -- case 3: no back-slash escape in progress, but got a back-slash
+ go (c:cs) q False a as
+ | '\\' == c = go cs q True a as
+ -- case 4: single-quote escaping in progress
+ go (c:cs) SngQ False a as
+ | '\'' == c = go cs NoneQ False a as
+ | otherwise = go cs SngQ False (c:a) as
+ -- case 5: double-quote escaping in progress
+ go (c:cs) DblQ False a as
+ | '"' == c = go cs NoneQ False a as
+ | otherwise = go cs DblQ False (c:a) as
+ -- case 6: no escaping is in progress
+ go (c:cs) NoneQ False a as
+ | isSpace c = go cs NoneQ False [] (a:as)
+ | '\'' == c = go cs SngQ False a as
+ | '"' == c = go cs DblQ False a as
+ | otherwise = go cs NoneQ False (c:a) as
+
+escapeArg :: String -> String
+escapeArg = reverse . foldl' escape []
+
+escape :: String -> Char -> String
+escape cs c
+ | isSpace c
+ || '\\' == c
+ || '\'' == c
+ || '"' == c = c:'\\':cs -- n.b., our caller must reverse the result
+ | otherwise = c:cs
=====================================
libraries/base/src/System/Exit.hs
=====================================
@@ -21,4 +21,67 @@ module System.Exit
die
) where
-import GHC.Internal.System.Exit
\ No newline at end of file
+import GHC.IO.Exception
+ (
+ IOErrorType (InvalidArgument),
+ IOException (IOError),
+ ExitCode (ExitSuccess, ExitFailure)
+ )
+import Control.Monad ((>>))
+import Control.Exception (throwIO, ioError)
+import Data.Bool (otherwise)
+import Data.Maybe (Maybe (Nothing))
+import Data.String (String)
+import Data.Eq ((/=))
+import System.IO (IO, hPutStrLn, stderr)
+
+-- ---------------------------------------------------------------------------
+-- exitWith
+
+-- | Computation 'exitWith' @code@ throws 'ExitCode' @code@.
+-- Normally this terminates the program, returning @code@ to the
+-- program's caller.
+--
+-- On program termination, the standard 'Handle's 'stdout' and
+-- 'stderr' are flushed automatically; any other buffered 'Handle's
+-- need to be flushed manually, otherwise the buffered data will be
+-- discarded.
+--
+-- A program that fails in any other way is treated as if it had
+-- called 'exitFailure'.
+-- A program that terminates successfully without calling 'exitWith'
+-- explicitly is treated as if it had called 'exitWith' 'ExitSuccess'.
+--
+-- As an 'ExitCode' is an 'Control.Exception.Exception', it can be
+-- caught using the functions of "Control.Exception". This means that
+-- cleanup computations added with 'GHC.Internal.Control.Exception.bracket' (from
+-- "Control.Exception") are also executed properly on 'exitWith'.
+--
+-- Note: in GHC, 'exitWith' should be called from the main program
+-- thread in order to exit the process. When called from another
+-- thread, 'exitWith' will throw an 'ExitCode' as normal, but the
+-- exception will not cause the process itself to exit.
+--
+exitWith :: ExitCode -> IO a
+exitWith ExitSuccess = throwIO ExitSuccess
+exitWith code@(ExitFailure n)
+ | n /= 0 = throwIO code
+ | otherwise = ioError (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing Nothing)
+
+-- | The computation 'exitFailure' is equivalent to
+-- 'exitWith' @(@'ExitFailure' /exitfail/@)@,
+-- where /exitfail/ is implementation-dependent.
+exitFailure :: IO a
+exitFailure = exitWith (ExitFailure 1)
+
+-- | The computation 'exitSuccess' is equivalent to
+-- 'exitWith' 'ExitSuccess', It terminates the program
+-- successfully.
+exitSuccess :: IO a
+exitSuccess = exitWith ExitSuccess
+
+-- | Write given error message to `stderr` and terminate with `exitFailure`.
+--
+-- @since base-4.8.0.0
+die :: String -> IO a
+die err = hPutStrLn stderr err >> exitFailure
=====================================
libraries/base/src/System/IO/OS.hs
=====================================
@@ -1,4 +1,6 @@
{-# LANGUAGE Safe #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE RankNTypes #-}
{-|
This module bridges between Haskell handles and underlying operating-system
@@ -21,17 +23,293 @@ module System.IO.OS
)
where
-import GHC.Internal.System.IO.OS
+import Control.Monad (return)
+import Control.Concurrent.MVar (MVar)
+import Control.Exception (mask)
+import Data.Function (const, (.), ($))
+import Data.Functor (fmap)
+import Data.Maybe (Maybe (Nothing), maybe)
+#if defined(mingw32_HOST_OS)
+import Data.Bool (otherwise)
+import Data.Maybe (Maybe (Just))
+#endif
+import Data.List ((++))
+import Data.String (String)
+import Data.Typeable (Typeable, cast)
+import System.IO (IO)
+import GHC.IO.FD (fdFD)
+#if defined(mingw32_HOST_OS)
+import GHC.IO.Windows.Handle
(
- withFileDescriptorReadingBiased,
- withFileDescriptorWritingBiased,
- withWindowsHandleReadingBiased,
- withWindowsHandleWritingBiased,
- withFileDescriptorReadingBiasedRaw,
- withFileDescriptorWritingBiasedRaw,
- withWindowsHandleReadingBiasedRaw,
- withWindowsHandleWritingBiasedRaw
+ NativeHandle,
+ ConsoleHandle,
+ IoHandle,
+ toHANDLE
)
+#endif
+import GHC.IO.Handle.Types
+ (
+ Handle (FileHandle, DuplexHandle),
+ Handle__ (Handle__, haDevice)
+ )
+import GHC.IO.Handle.Internals (withHandle_', flushBuffer)
+import GHC.IO.Exception
+ (
+ IOErrorType (InappropriateType),
+ IOException (IOError),
+ ioException
+ )
+import Foreign.Ptr (Ptr)
+import Foreign.C.Types (CInt)
+
+-- * Obtaining POSIX file descriptors and Windows handles
+
+{-|
+ Executes a user-provided action on an operating-system handle that underlies
+ a Haskell handle. Before the user-provided action is run, user-defined
+ preparation based on the handle state that contains the operating-system
+ handle is performed. While the user-provided action is executed, further
+ operations on the Haskell handle are blocked to a degree that interference
+ with this action is prevented.
+
+ See [below](#with-ref-caveats) for caveats regarding this operation.
+-}
+withOSHandle :: String
+ -- ^ The name of the overall operation
+ -> (Handle -> MVar Handle__)
+ {-^
+ Obtaining of the handle state variable that holds the
+ operating-system handle
+ -}
+ -> (forall d. Typeable d => d -> IO a)
+ -- ^ Conversion of a device into an operating-system handle
+ -> (Handle__ -> IO ())
+ -- ^ The preparation
+ -> Handle
+ -- ^ The Haskell handle to use
+ -> (a -> IO r)
+ -- ^ The action to execute on the operating-system handle
+ -> IO r
+withOSHandle opName handleStateVar getOSHandle prepare handle act
+ = mask $ \ withOriginalMaskingState ->
+ withHandleState $ \ handleState@Handle__ {haDevice = dev} -> do
+ osHandle <- getOSHandle dev
+ prepare handleState
+ withOriginalMaskingState $ act osHandle
+ where
+
+ withHandleState = withHandle_' opName handle (handleStateVar handle)
+{-
+ The 'withHandle_'' operation, which we use here, already performs masking.
+ Still, we have to employ 'mask', in order do obtain the operation that
+ restores the original masking state. The user-provided action should be
+ executed with this original masking state, as there is no inherent reason to
+ generally perform it with masking in place. The masking that 'withHandle_''
+ performs is only for safely accessing handle state and thus constitutes an
+ implementation detail; it has nothing to do with the user-provided action.
+-}
+{-
+ The order of actions in 'withOSHandle' is such that any exception from
+ 'getOSHandle' is thrown before the user-defined preparation is performed.
+-}
+
+{-|
+ Obtains the handle state variable that underlies a handle or specifically
+ the handle state variable for reading if the handle uses different state
+ variables for reading and writing.
+-}
+handleStateVarReadingBiased :: Handle -> MVar Handle__
+handleStateVarReadingBiased (FileHandle _ var) = var
+handleStateVarReadingBiased (DuplexHandle _ readingVar _) = readingVar
+
+{-|
+ Obtains the handle state variable that underlies a handle or specifically
+ the handle state variable for writing if the handle uses different state
+ variables for reading and writing.
+-}
+handleStateVarWritingBiased :: Handle -> MVar Handle__
+handleStateVarWritingBiased (FileHandle _ var) = var
+handleStateVarWritingBiased (DuplexHandle _ _ writingVar) = writingVar
+
+{-|
+ Yields the result of another operation if that operation succeeded, and
+ otherwise throws an exception that signals that the other operation failed
+ because some Haskell handle does not use an operating-system handle of a
+ required type.
+-}
+requiringOSHandleOfType :: String
+ -- ^ The name of the operating-system handle type
+ -> Maybe a
+ {-^
+ The result of the other operation if it succeeded
+ -}
+ -> IO a
+requiringOSHandleOfType osHandleTypeName
+ = maybe (ioException osHandleOfTypeRequired) return
+ where
+
+ osHandleOfTypeRequired :: IOException
+ osHandleOfTypeRequired
+ = IOError Nothing
+ InappropriateType
+ ""
+ ("handle does not use " ++ osHandleTypeName ++ "s")
+ Nothing
+ Nothing
+
+{-|
+ Obtains the POSIX file descriptor of a device if the device contains one,
+ and throws an exception otherwise.
+-}
+getFileDescriptor :: Typeable d => d -> IO CInt
+getFileDescriptor = requiringOSHandleOfType "POSIX file descriptor" .
+ fmap fdFD . cast
+
+{-|
+ Obtains the Windows handle of a device if the device contains one, and
+ throws an exception otherwise.
+-}
+getWindowsHandle :: Typeable d => d -> IO (Ptr ())
+getWindowsHandle = requiringOSHandleOfType "Windows handle" .
+ toMaybeWindowsHandle
+ where
+
+ toMaybeWindowsHandle :: Typeable d => d -> Maybe (Ptr ())
+#if defined(mingw32_HOST_OS)
+ toMaybeWindowsHandle dev
+ | Just nativeHandle <- cast dev :: Maybe (IoHandle NativeHandle)
+ = Just (toHANDLE nativeHandle)
+ | Just consoleHandle <- cast dev :: Maybe (IoHandle ConsoleHandle)
+ = Just (toHANDLE consoleHandle)
+ | otherwise
+ = Nothing
+ {-
+ This is inspired by the implementation of
+ 'System.Win32.Types.withHandleToHANDLENative'.
+ -}
+#else
+ toMaybeWindowsHandle _ = Nothing
+#endif
+
+{-|
+ Executes a user-provided action on the POSIX file descriptor that underlies
+ a handle or specifically on the POSIX file descriptor for reading if the
+ handle uses different file descriptors for reading and writing. The
+ Haskell-managed buffers related to the file descriptor are flushed before
+ the user-provided action is run. While this action is executed, further
+ operations on the handle are blocked to a degree that interference with this
+ action is prevented.
+
+ If the handle does not use POSIX file descriptors, an exception is thrown.
+
+ See [below](#with-ref-caveats) for caveats regarding this operation.
+-}
+withFileDescriptorReadingBiased :: Handle -> (CInt -> IO r) -> IO r
+withFileDescriptorReadingBiased = withOSHandle "withFileDescriptorReadingBiased"
+ handleStateVarReadingBiased
+ getFileDescriptor
+ flushBuffer
+
+{-|
+ Executes a user-provided action on the POSIX file descriptor that underlies
+ a handle or specifically on the POSIX file descriptor for writing if the
+ handle uses different file descriptors for reading and writing. The
+ Haskell-managed buffers related to the file descriptor are flushed before
+ the user-provided action is run. While this action is executed, further
+ operations on the handle are blocked to a degree that interference with this
+ action is prevented.
+
+ If the handle does not use POSIX file descriptors, an exception is thrown.
+
+ See [below](#with-ref-caveats) for caveats regarding this operation.
+-}
+withFileDescriptorWritingBiased :: Handle -> (CInt -> IO r) -> IO r
+withFileDescriptorWritingBiased = withOSHandle "withFileDescriptorWritingBiased"
+ handleStateVarWritingBiased
+ getFileDescriptor
+ flushBuffer
+
+{-|
+ Executes a user-provided action on the Windows handle that underlies a
+ Haskell handle or specifically on the Windows handle for reading if the
+ Haskell handle uses different Windows handles for reading and writing. The
+ Haskell-managed buffers related to the Windows handle are flushed before the
+ user-provided action is run. While this action is executed, further
+ operations on the Haskell handle are blocked to a degree that interference
+ with this action is prevented.
+
+ If the Haskell handle does not use Windows handles, an exception is thrown.
+
+ See [below](#with-ref-caveats) for caveats regarding this operation.
+-}
+withWindowsHandleReadingBiased :: Handle -> (Ptr () -> IO r) -> IO r
+withWindowsHandleReadingBiased = withOSHandle "withWindowsHandleReadingBiased"
+ handleStateVarReadingBiased
+ getWindowsHandle
+ flushBuffer
+
+{-|
+ Executes a user-provided action on the Windows handle that underlies a
+ Haskell handle or specifically on the Windows handle for writing if the
+ Haskell handle uses different Windows handles for reading and writing. The
+ Haskell-managed buffers related to the Windows handle are flushed before the
+ user-provided action is run. While this action is executed, further
+ operations on the Haskell handle are blocked to a degree that interference
+ with this action is prevented.
+
+ If the Haskell handle does not use Windows handles, an exception is thrown.
+
+ See [below](#with-ref-caveats) for caveats regarding this operation.
+-}
+withWindowsHandleWritingBiased :: Handle -> (Ptr () -> IO r) -> IO r
+withWindowsHandleWritingBiased = withOSHandle "withWindowsHandleWritingBiased"
+ handleStateVarWritingBiased
+ getWindowsHandle
+ flushBuffer
+
+{-|
+ Like 'withFileDescriptorReadingBiased' except that Haskell-managed buffers
+ are not flushed.
+-}
+withFileDescriptorReadingBiasedRaw :: Handle -> (CInt -> IO r) -> IO r
+withFileDescriptorReadingBiasedRaw
+ = withOSHandle "withFileDescriptorReadingBiasedRaw"
+ handleStateVarReadingBiased
+ getFileDescriptor
+ (const $ return ())
+
+{-|
+ Like 'withFileDescriptorWritingBiased' except that Haskell-managed buffers
+ are not flushed.
+-}
+withFileDescriptorWritingBiasedRaw :: Handle -> (CInt -> IO r) -> IO r
+withFileDescriptorWritingBiasedRaw
+ = withOSHandle "withFileDescriptorWritingBiasedRaw"
+ handleStateVarWritingBiased
+ getFileDescriptor
+ (const $ return ())
+
+{-|
+ Like 'withWindowsHandleReadingBiased' except that Haskell-managed buffers
+ are not flushed.
+-}
+withWindowsHandleReadingBiasedRaw :: Handle -> (Ptr () -> IO r) -> IO r
+withWindowsHandleReadingBiasedRaw
+ = withOSHandle "withWindowsHandleReadingBiasedRaw"
+ handleStateVarReadingBiased
+ getWindowsHandle
+ (const $ return ())
+
+{-|
+ Like 'withWindowsHandleWritingBiased' except that Haskell-managed buffers
+ are not flushed.
+-}
+withWindowsHandleWritingBiasedRaw :: Handle -> (Ptr () -> IO r) -> IO r
+withWindowsHandleWritingBiasedRaw
+ = withOSHandle "withWindowsHandleWritingBiasedRaw"
+ handleStateVarWritingBiased
+ getWindowsHandle
+ (const $ return ())
-- ** Caveats
=====================================
libraries/base/tests/IO/T18832.hs
=====================================
@@ -41,7 +41,6 @@ test dir' = do
-- cleanup
mapM_ killThread [interrupter, deleter, closer]
- removeDirectoryRecursive dir
either throwIO (const $ putStrLn "No failures observed - success") result
=====================================
libraries/ghc-heap/GHC/Exts/Heap/Closures.hs
=====================================
@@ -1,17 +1,3 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE ForeignFunctionInterface #-}
-{-# LANGUAGE GHCForeignImportPrim #-}
-{-# LANGUAGE MagicHash #-}
-{-# LANGUAGE RecordWildCards #-}
-{-# LANGUAGE UnliftedFFITypes #-}
-{-# LANGUAGE DeriveGeneric #-}
-{-# LANGUAGE DeriveTraversable #-}
--- Late cost centres introduce a thunk in the asBox function, which leads to
--- an additional wrapper being added to any value placed inside a box.
--- This can be removed once our boot compiler is no longer affected by #25212
-{-# OPTIONS_GHC -fno-prof-late #-}
-{-# LANGUAGE NamedFieldPuns #-}
-
module GHC.Exts.Heap.Closures (
-- * Closures
Closure
=====================================
libraries/ghc-internal/ghc-internal.cabal.in
=====================================
@@ -284,7 +284,6 @@ Library
GHC.Internal.Read
GHC.Internal.Real
GHC.Internal.Records
- GHC.Internal.ResponseFile
GHC.Internal.RTS.Flags
GHC.Internal.RTS.Flags.Test
GHC.Internal.ST
@@ -324,10 +323,8 @@ Library
GHC.Internal.Numeric.Natural
GHC.Internal.System.Environment
GHC.Internal.System.Environment.Blank
- GHC.Internal.System.Exit
GHC.Internal.System.IO
GHC.Internal.System.IO.Error
- GHC.Internal.System.IO.OS
GHC.Internal.System.Mem
GHC.Internal.System.Mem.StableName
GHC.Internal.System.Posix.Internals
=====================================
libraries/ghc-internal/src/GHC/Internal/Data/Version.hs
=====================================
@@ -41,8 +41,7 @@ import GHC.Internal.Data.Eq
import GHC.Internal.Int ( Int )
import GHC.Internal.Data.List ( map, sort, concat, concatMap, intersperse, (++) )
import GHC.Internal.Data.Ord
-import GHC.Internal.Data.String ( String )
-import GHC.Internal.Base ( Applicative(..), (&&) )
+import GHC.Internal.Base ( Applicative(..), (&&), String )
import GHC.Internal.Generics
import GHC.Internal.Unicode ( isDigit, isAlphaNum )
import GHC.Internal.Read
=====================================
libraries/ghc-internal/src/GHC/Internal/Fingerprint.hs
=====================================
@@ -16,23 +16,22 @@ module GHC.Internal.Fingerprint (
fingerprintData,
fingerprintString,
fingerprintFingerprints,
- getFileHash
+ fingerprintBufferedStream
) where
import GHC.Internal.IO
import GHC.Internal.Base
import GHC.Internal.Bits
import GHC.Internal.Num
+import GHC.Internal.Data.Maybe
import GHC.Internal.List
import GHC.Internal.Real
import GHC.Internal.Word
-import GHC.Internal.Show
import GHC.Internal.Ptr
import GHC.Internal.Foreign.C.Types
import GHC.Internal.Foreign.Marshal.Alloc
import GHC.Internal.Foreign.Marshal.Array
import GHC.Internal.Foreign.Storable
-import GHC.Internal.System.IO
import GHC.Internal.Fingerprint.Type
@@ -71,41 +70,27 @@ fingerprintString str = unsafeDupablePerformIO $
fromIntegral (w32 `shiftR` 8),
fromIntegral w32]
--- | Computes the hash of a given file.
--- This function loops over the handle, running in constant memory.
---
--- @since base-4.7.0.0
-getFileHash :: FilePath -> IO Fingerprint
-getFileHash path = withBinaryFile path ReadMode $ \h ->
+-- | Reads data in chunks and computes its hash.
+-- This function runs in constant memory.
+fingerprintBufferedStream :: (Ptr Word8 -> Int -> IO (Maybe Int))
+ -> IO Fingerprint
+fingerprintBufferedStream readChunk =
allocaBytes SIZEOF_STRUCT_MD5CONTEXT $ \pctxt -> do
c_MD5Init pctxt
-
- processChunks h (\buf size -> c_MD5Update pctxt buf (fromIntegral size))
-
+ allocaBytes _BUFSIZE $ \arrPtr ->
+ let loop = do
+ maybeRemainderSize <- readChunk arrPtr _BUFSIZE
+ c_MD5Update pctxt
+ arrPtr
+ (fromIntegral (fromMaybe _BUFSIZE maybeRemainderSize))
+ when (isNothing maybeRemainderSize) loop
+ in loop
allocaBytes 16 $ \pdigest -> do
c_MD5Final pdigest pctxt
peek (castPtr pdigest :: Ptr Fingerprint)
-
where
_BUFSIZE = 4096
- -- Loop over _BUFSIZE sized chunks read from the handle,
- -- passing the callback a block of bytes and its size.
- processChunks :: Handle -> (Ptr Word8 -> Int -> IO ()) -> IO ()
- processChunks h f = allocaBytes _BUFSIZE $ \arrPtr ->
-
- let loop = do
- count <- hGetBuf h arrPtr _BUFSIZE
- eof <- hIsEOF h
- when (count /= _BUFSIZE && not eof) $ errorWithoutStackTrace $
- "GHC.Internal.Fingerprint.getFileHash: only read " ++ show count ++ " bytes"
-
- f arrPtr count
-
- when (not eof) loop
-
- in loop
-
data MD5Context
foreign import ccall unsafe "__hsbase_MD5Init"
=====================================
libraries/ghc-internal/src/GHC/Internal/GHCi/Helpers.hs
=====================================
@@ -24,9 +24,10 @@ module GHC.Internal.GHCi.Helpers
, evalWrapper
) where
-import GHC.Internal.Base
-import GHC.Internal.System.IO
-import GHC.Internal.System.Environment
+import GHC.Internal.Base (String, IO)
+import GHC.Internal.IO.Handle (BufferMode (NoBuffering), hSetBuffering, hFlush)
+import GHC.Internal.IO.StdHandles (stdin, stdout, stderr)
+import GHC.Internal.System.Environment (withProgName, withArgs)
disableBuffering :: IO ()
disableBuffering = do
=====================================
libraries/ghc-internal/src/GHC/Internal/ResponseFile.hs deleted
=====================================
@@ -1,163 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE Trustworthy #-}
-
------------------------------------------------------------------------------
--- |
--- Module : GHC.Internal.ResponseFile
--- License : BSD-style (see the file LICENSE)
---
--- Maintainer : libraries(a)haskell.org
--- Stability : internal
--- Portability : portable
---
--- GCC style response files.
---
--- @since base-4.12.0.0
-----------------------------------------------------------------------------
-
--- Migrated from Haddock.
-
-module GHC.Internal.ResponseFile (
- getArgsWithResponseFiles,
- unescapeArgs,
- escapeArgs, escapeArg,
- expandResponse
- ) where
-
-import GHC.Internal.Control.Exception
-import GHC.Internal.Data.Foldable (Foldable(..))
-import GHC.Internal.Base
-import GHC.Internal.Unicode (isSpace)
-import GHC.Internal.Data.List (filter, unlines, concat, reverse)
-import GHC.Internal.Text.Show (show)
-import GHC.Internal.System.Environment (getArgs)
-import GHC.Internal.System.Exit (exitFailure)
-import GHC.Internal.System.IO
-
-{-|
-Like 'getArgs', but can also read arguments supplied via response files.
-
-
-For example, consider a program @foo@:
-
-@
-main :: IO ()
-main = do
- args <- getArgsWithResponseFiles
- putStrLn (show args)
-@
-
-
-And a response file @args.txt@:
-
-@
---one 1
---\'two\' 2
---"three" 3
-@
-
-Then the result of invoking @foo@ with @args.txt@ is:
-
-> > ./foo @args.txt
-> ["--one","1","--two","2","--three","3"]
-
--}
-getArgsWithResponseFiles :: IO [String]
-getArgsWithResponseFiles = getArgs >>= expandResponse
-
--- | Given a string of concatenated strings, separate each by removing
--- a layer of /quoting/ and\/or /escaping/ of certain characters.
---
--- These characters are: any whitespace, single quote, double quote,
--- and the backslash character. The backslash character always
--- escapes (i.e., passes through without further consideration) the
--- character which follows. Characters can also be escaped in blocks
--- by quoting (i.e., surrounding the blocks with matching pairs of
--- either single- or double-quotes which are not themselves escaped).
---
--- Any whitespace which appears outside of either of the quoting and
--- escaping mechanisms, is interpreted as having been added by this
--- special concatenation process to designate where the boundaries
--- are between the original, un-concatenated list of strings. These
--- added whitespace characters are removed from the output.
---
--- > unescapeArgs "hello\\ \\\"world\\\"\n" == ["hello \"world\""]
-unescapeArgs :: String -> [String]
-unescapeArgs = filter (not . null) . unescape
-
--- | Given a list of strings, concatenate them into a single string
--- with escaping of certain characters, and the addition of a newline
--- between each string. The escaping is done by adding a single
--- backslash character before any whitespace, single quote, double
--- quote, or backslash character, so this escaping character must be
--- removed. Unescaped whitespace (in this case, newline) is part
--- of this "transport" format to indicate the end of the previous
--- string and the start of a new string.
---
--- While 'unescapeArgs' allows using quoting (i.e., convenient
--- escaping of many characters) by having matching sets of single- or
--- double-quotes,'escapeArgs' does not use the quoting mechanism,
--- and thus will always escape any whitespace, quotes, and
--- backslashes.
---
--- > escapeArgs ["hello \"world\""] == "hello\\ \\\"world\\\"\n"
-escapeArgs :: [String] -> String
-escapeArgs = unlines . map escapeArg
-
--- | Arguments which look like @\@foo@ will be replaced with the
--- contents of file @foo@. A gcc-like syntax for response files arguments
--- is expected. This must re-constitute the argument list by doing an
--- inverse of the escaping mechanism done by the calling-program side.
---
--- We quit if the file is not found or reading somehow fails.
--- (A convenience routine for haddock or possibly other clients)
-expandResponse :: [String] -> IO [String]
-expandResponse = fmap concat . mapM expand
- where
- expand :: String -> IO [String]
- expand ('@':f) = readFileExc f >>= return . unescapeArgs
- expand x = return [x]
-
- readFileExc f =
- readFile f `catch` \(e :: IOException) -> do
- hPutStrLn stderr $ "Error while expanding response file: " ++ show e
- exitFailure
-
-data Quoting = NoneQ | SngQ | DblQ
-
-unescape :: String -> [String]
-unescape args = reverse . map reverse $ go args NoneQ False [] []
- where
- -- n.b., the order of these cases matters; these are cribbed from gcc
- -- case 1: end of input
- go [] _q _bs a as = a:as
- -- case 2: back-slash escape in progress
- go (c:cs) q True a as = go cs q False (c:a) as
- -- case 3: no back-slash escape in progress, but got a back-slash
- go (c:cs) q False a as
- | '\\' == c = go cs q True a as
- -- case 4: single-quote escaping in progress
- go (c:cs) SngQ False a as
- | '\'' == c = go cs NoneQ False a as
- | otherwise = go cs SngQ False (c:a) as
- -- case 5: double-quote escaping in progress
- go (c:cs) DblQ False a as
- | '"' == c = go cs NoneQ False a as
- | otherwise = go cs DblQ False (c:a) as
- -- case 6: no escaping is in progress
- go (c:cs) NoneQ False a as
- | isSpace c = go cs NoneQ False [] (a:as)
- | '\'' == c = go cs SngQ False a as
- | '"' == c = go cs DblQ False a as
- | otherwise = go cs NoneQ False (c:a) as
-
-escapeArg :: String -> String
-escapeArg = reverse . foldl' escape []
-
-escape :: String -> Char -> String
-escape cs c
- | isSpace c
- || '\\' == c
- || '\'' == c
- || '"' == c = c:'\\':cs -- n.b., our caller must reverse the result
- | otherwise = c:cs
=====================================
libraries/ghc-internal/src/GHC/Internal/System/Exit.hs deleted
=====================================
@@ -1,81 +0,0 @@
-{-# LANGUAGE Trustworthy #-}
-
------------------------------------------------------------------------------
--- |
--- Module : GHC.Internal.System.Exit
--- Copyright : (c) The University of Glasgow 2001
--- License : BSD-style (see the file libraries/base/LICENSE)
---
--- Maintainer : libraries(a)haskell.org
--- Stability : provisional
--- Portability : portable
---
--- Exiting the program.
---
------------------------------------------------------------------------------
-
-module GHC.Internal.System.Exit
- (
- ExitCode(ExitSuccess,ExitFailure)
- , exitWith
- , exitFailure
- , exitSuccess
- , die
- ) where
-
-import GHC.Internal.System.IO
-
-import GHC.Internal.Base
-import GHC.Internal.IO
-import GHC.Internal.IO.Exception
-
--- ---------------------------------------------------------------------------
--- exitWith
-
--- | Computation 'exitWith' @code@ throws 'ExitCode' @code@.
--- Normally this terminates the program, returning @code@ to the
--- program's caller.
---
--- On program termination, the standard 'Handle's 'stdout' and
--- 'stderr' are flushed automatically; any other buffered 'Handle's
--- need to be flushed manually, otherwise the buffered data will be
--- discarded.
---
--- A program that fails in any other way is treated as if it had
--- called 'exitFailure'.
--- A program that terminates successfully without calling 'exitWith'
--- explicitly is treated as if it had called 'exitWith' 'ExitSuccess'.
---
--- As an 'ExitCode' is an 'Control.Exception.Exception', it can be
--- caught using the functions of "Control.Exception". This means that
--- cleanup computations added with 'GHC.Internal.Control.Exception.bracket' (from
--- "Control.Exception") are also executed properly on 'exitWith'.
---
--- Note: in GHC, 'exitWith' should be called from the main program
--- thread in order to exit the process. When called from another
--- thread, 'exitWith' will throw an 'ExitCode' as normal, but the
--- exception will not cause the process itself to exit.
---
-exitWith :: ExitCode -> IO a
-exitWith ExitSuccess = throwIO ExitSuccess
-exitWith code@(ExitFailure n)
- | n /= 0 = throwIO code
- | otherwise = ioError (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing Nothing)
-
--- | The computation 'exitFailure' is equivalent to
--- 'exitWith' @(@'ExitFailure' /exitfail/@)@,
--- where /exitfail/ is implementation-dependent.
-exitFailure :: IO a
-exitFailure = exitWith (ExitFailure 1)
-
--- | The computation 'exitSuccess' is equivalent to
--- 'exitWith' 'ExitSuccess', It terminates the program
--- successfully.
-exitSuccess :: IO a
-exitSuccess = exitWith ExitSuccess
-
--- | Write given error message to `stderr` and terminate with `exitFailure`.
---
--- @since base-4.8.0.0
-die :: String -> IO a
-die err = hPutStrLn stderr err >> exitFailure
=====================================
libraries/ghc-internal/src/GHC/Internal/System/IO/OS.hs deleted
=====================================
@@ -1,323 +0,0 @@
-{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE RankNTypes #-}
-
-{-|
- This module bridges between Haskell handles and underlying operating-system
- features.
--}
-module GHC.Internal.System.IO.OS
-(
- -- * Obtaining file descriptors and Windows handles
- withFileDescriptorReadingBiased,
- withFileDescriptorWritingBiased,
- withWindowsHandleReadingBiased,
- withWindowsHandleWritingBiased,
- withFileDescriptorReadingBiasedRaw,
- withFileDescriptorWritingBiasedRaw,
- withWindowsHandleReadingBiasedRaw,
- withWindowsHandleWritingBiasedRaw
-
- -- ** Caveats
- -- $with-ref-caveats
-)
-where
-
-#if defined(mingw32_HOST_OS)
-import GHC.Internal.Base (otherwise)
-#endif
-import GHC.Internal.Control.Monad (return)
-import GHC.Internal.Control.Concurrent.MVar (MVar)
-import GHC.Internal.Control.Exception (mask)
-import GHC.Internal.Data.Function (const, (.), ($))
-import GHC.Internal.Data.Functor (fmap)
-import GHC.Internal.Data.Maybe (Maybe (Nothing), maybe)
-#if defined(mingw32_HOST_OS)
-import GHC.Internal.Data.Maybe (Maybe (Just))
-#endif
-import GHC.Internal.Data.List ((++))
-import GHC.Internal.Data.String (String)
-import GHC.Internal.Data.Typeable (Typeable, cast)
-import GHC.Internal.System.IO (IO)
-import GHC.Internal.IO.FD (fdFD)
-#if defined(mingw32_HOST_OS)
-import GHC.Internal.IO.Windows.Handle
- (
- NativeHandle,
- ConsoleHandle,
- IoHandle,
- toHANDLE
- )
-#endif
-import GHC.Internal.IO.Handle.Types
- (
- Handle (FileHandle, DuplexHandle),
- Handle__ (Handle__, haDevice)
- )
-import GHC.Internal.IO.Handle.Internals (withHandle_', flushBuffer)
-import GHC.Internal.IO.Exception
- (
- IOErrorType (InappropriateType),
- IOException (IOError),
- ioException
- )
-import GHC.Internal.Foreign.Ptr (Ptr)
-import GHC.Internal.Foreign.C.Types (CInt)
-
--- * Obtaining POSIX file descriptors and Windows handles
-
-{-|
- Executes a user-provided action on an operating-system handle that underlies
- a Haskell handle. Before the user-provided action is run, user-defined
- preparation based on the handle state that contains the operating-system
- handle is performed. While the user-provided action is executed, further
- operations on the Haskell handle are blocked to a degree that interference
- with this action is prevented.
-
- See [below](#with-ref-caveats) for caveats regarding this operation.
--}
-withOSHandle :: String
- -- ^ The name of the overall operation
- -> (Handle -> MVar Handle__)
- {-^
- Obtaining of the handle state variable that holds the
- operating-system handle
- -}
- -> (forall d. Typeable d => d -> IO a)
- -- ^ Conversion of a device into an operating-system handle
- -> (Handle__ -> IO ())
- -- ^ The preparation
- -> Handle
- -- ^ The Haskell handle to use
- -> (a -> IO r)
- -- ^ The action to execute on the operating-system handle
- -> IO r
-withOSHandle opName handleStateVar getOSHandle prepare handle act
- = mask $ \ withOriginalMaskingState ->
- withHandleState $ \ handleState@Handle__ {haDevice = dev} -> do
- osHandle <- getOSHandle dev
- prepare handleState
- withOriginalMaskingState $ act osHandle
- where
-
- withHandleState = withHandle_' opName handle (handleStateVar handle)
-{-
- The 'withHandle_'' operation, which we use here, already performs masking.
- Still, we have to employ 'mask', in order do obtain the operation that
- restores the original masking state. The user-provided action should be
- executed with this original masking state, as there is no inherent reason to
- generally perform it with masking in place. The masking that 'withHandle_''
- performs is only for safely accessing handle state and thus constitutes an
- implementation detail; it has nothing to do with the user-provided action.
--}
-{-
- The order of actions in 'withOSHandle' is such that any exception from
- 'getOSHandle' is thrown before the user-defined preparation is performed.
--}
-
-{-|
- Obtains the handle state variable that underlies a handle or specifically
- the handle state variable for reading if the handle uses different state
- variables for reading and writing.
--}
-handleStateVarReadingBiased :: Handle -> MVar Handle__
-handleStateVarReadingBiased (FileHandle _ var) = var
-handleStateVarReadingBiased (DuplexHandle _ readingVar _) = readingVar
-
-{-|
- Obtains the handle state variable that underlies a handle or specifically
- the handle state variable for writing if the handle uses different state
- variables for reading and writing.
--}
-handleStateVarWritingBiased :: Handle -> MVar Handle__
-handleStateVarWritingBiased (FileHandle _ var) = var
-handleStateVarWritingBiased (DuplexHandle _ _ writingVar) = writingVar
-
-{-|
- Yields the result of another operation if that operation succeeded, and
- otherwise throws an exception that signals that the other operation failed
- because some Haskell handle does not use an operating-system handle of a
- required type.
--}
-requiringOSHandleOfType :: String
- -- ^ The name of the operating-system handle type
- -> Maybe a
- {-^
- The result of the other operation if it succeeded
- -}
- -> IO a
-requiringOSHandleOfType osHandleTypeName
- = maybe (ioException osHandleOfTypeRequired) return
- where
-
- osHandleOfTypeRequired :: IOException
- osHandleOfTypeRequired
- = IOError Nothing
- InappropriateType
- ""
- ("handle does not use " ++ osHandleTypeName ++ "s")
- Nothing
- Nothing
-
-{-|
- Obtains the POSIX file descriptor of a device if the device contains one,
- and throws an exception otherwise.
--}
-getFileDescriptor :: Typeable d => d -> IO CInt
-getFileDescriptor = requiringOSHandleOfType "POSIX file descriptor" .
- fmap fdFD . cast
-
-{-|
- Obtains the Windows handle of a device if the device contains one, and
- throws an exception otherwise.
--}
-getWindowsHandle :: Typeable d => d -> IO (Ptr ())
-getWindowsHandle = requiringOSHandleOfType "Windows handle" .
- toMaybeWindowsHandle
- where
-
- toMaybeWindowsHandle :: Typeable d => d -> Maybe (Ptr ())
-#if defined(mingw32_HOST_OS)
- toMaybeWindowsHandle dev
- | Just nativeHandle <- cast dev :: Maybe (IoHandle NativeHandle)
- = Just (toHANDLE nativeHandle)
- | Just consoleHandle <- cast dev :: Maybe (IoHandle ConsoleHandle)
- = Just (toHANDLE consoleHandle)
- | otherwise
- = Nothing
- {-
- This is inspired by the implementation of
- 'System.Win32.Types.withHandleToHANDLENative'.
- -}
-#else
- toMaybeWindowsHandle _ = Nothing
-#endif
-
-{-|
- Executes a user-provided action on the POSIX file descriptor that underlies
- a handle or specifically on the POSIX file descriptor for reading if the
- handle uses different file descriptors for reading and writing. The
- Haskell-managed buffers related to the file descriptor are flushed before
- the user-provided action is run. While this action is executed, further
- operations on the handle are blocked to a degree that interference with this
- action is prevented.
-
- If the handle does not use POSIX file descriptors, an exception is thrown.
-
- See [below](#with-ref-caveats) for caveats regarding this operation.
--}
-withFileDescriptorReadingBiased :: Handle -> (CInt -> IO r) -> IO r
-withFileDescriptorReadingBiased = withOSHandle "withFileDescriptorReadingBiased"
- handleStateVarReadingBiased
- getFileDescriptor
- flushBuffer
-
-{-|
- Executes a user-provided action on the POSIX file descriptor that underlies
- a handle or specifically on the POSIX file descriptor for writing if the
- handle uses different file descriptors for reading and writing. The
- Haskell-managed buffers related to the file descriptor are flushed before
- the user-provided action is run. While this action is executed, further
- operations on the handle are blocked to a degree that interference with this
- action is prevented.
-
- If the handle does not use POSIX file descriptors, an exception is thrown.
-
- See [below](#with-ref-caveats) for caveats regarding this operation.
--}
-withFileDescriptorWritingBiased :: Handle -> (CInt -> IO r) -> IO r
-withFileDescriptorWritingBiased = withOSHandle "withFileDescriptorWritingBiased"
- handleStateVarWritingBiased
- getFileDescriptor
- flushBuffer
-
-{-|
- Executes a user-provided action on the Windows handle that underlies a
- Haskell handle or specifically on the Windows handle for reading if the
- Haskell handle uses different Windows handles for reading and writing. The
- Haskell-managed buffers related to the Windows handle are flushed before the
- user-provided action is run. While this action is executed, further
- operations on the Haskell handle are blocked to a degree that interference
- with this action is prevented.
-
- If the Haskell handle does not use Windows handles, an exception is thrown.
-
- See [below](#with-ref-caveats) for caveats regarding this operation.
--}
-withWindowsHandleReadingBiased :: Handle -> (Ptr () -> IO r) -> IO r
-withWindowsHandleReadingBiased = withOSHandle "withWindowsHandleReadingBiased"
- handleStateVarReadingBiased
- getWindowsHandle
- flushBuffer
-
-{-|
- Executes a user-provided action on the Windows handle that underlies a
- Haskell handle or specifically on the Windows handle for writing if the
- Haskell handle uses different Windows handles for reading and writing. The
- Haskell-managed buffers related to the Windows handle are flushed before the
- user-provided action is run. While this action is executed, further
- operations on the Haskell handle are blocked to a degree that interference
- with this action is prevented.
-
- If the Haskell handle does not use Windows handles, an exception is thrown.
-
- See [below](#with-ref-caveats) for caveats regarding this operation.
--}
-withWindowsHandleWritingBiased :: Handle -> (Ptr () -> IO r) -> IO r
-withWindowsHandleWritingBiased = withOSHandle "withWindowsHandleWritingBiased"
- handleStateVarWritingBiased
- getWindowsHandle
- flushBuffer
-
-{-|
- Like 'withFileDescriptorReadingBiased' except that Haskell-managed buffers
- are not flushed.
--}
-withFileDescriptorReadingBiasedRaw :: Handle -> (CInt -> IO r) -> IO r
-withFileDescriptorReadingBiasedRaw
- = withOSHandle "withFileDescriptorReadingBiasedRaw"
- handleStateVarReadingBiased
- getFileDescriptor
- (const $ return ())
-
-{-|
- Like 'withFileDescriptorWritingBiased' except that Haskell-managed buffers
- are not flushed.
--}
-withFileDescriptorWritingBiasedRaw :: Handle -> (CInt -> IO r) -> IO r
-withFileDescriptorWritingBiasedRaw
- = withOSHandle "withFileDescriptorWritingBiasedRaw"
- handleStateVarWritingBiased
- getFileDescriptor
- (const $ return ())
-
-{-|
- Like 'withWindowsHandleReadingBiased' except that Haskell-managed buffers
- are not flushed.
--}
-withWindowsHandleReadingBiasedRaw :: Handle -> (Ptr () -> IO r) -> IO r
-withWindowsHandleReadingBiasedRaw
- = withOSHandle "withWindowsHandleReadingBiasedRaw"
- handleStateVarReadingBiased
- getWindowsHandle
- (const $ return ())
-
-{-|
- Like 'withWindowsHandleWritingBiased' except that Haskell-managed buffers
- are not flushed.
--}
-withWindowsHandleWritingBiasedRaw :: Handle -> (Ptr () -> IO r) -> IO r
-withWindowsHandleWritingBiasedRaw
- = withOSHandle "withWindowsHandleWritingBiasedRaw"
- handleStateVarWritingBiased
- getWindowsHandle
- (const $ return ())
-
--- ** Caveats
-
-{-$with-ref-caveats
- #with-ref-caveats#This subsection is just a dummy, whose purpose is to serve
- as the target of the hyperlinks above. The real documentation of the caveats
- is in the /Caveats/ subsection in the @base@ module @System.IO.OS@, which
- re-exports the above operations.
--}
=====================================
libraries/ghc-internal/src/GHC/Internal/TH/Monad.hs
=====================================
@@ -26,17 +26,19 @@ module GHC.Internal.TH.Monad
import Prelude
import Data.Data hiding (Fixity(..))
import Data.IORef
-import System.IO.Unsafe ( unsafePerformIO )
+import System.IO.Unsafe (unsafePerformIO)
import Control.Monad.IO.Class (MonadIO (..))
-import System.IO ( hPutStrLn, stderr )
+import System.IO (FilePath, hPutStrLn, stderr)
import qualified Data.Kind as Kind (Type)
-import GHC.Types (TYPE, RuntimeRep(..))
+import GHC.Types (TYPE, RuntimeRep(..))
#else
import GHC.Internal.Base hiding (NonEmpty(..),Type, Module, sequence)
import GHC.Internal.Data.Data hiding (Fixity(..))
import GHC.Internal.Data.Traversable
import GHC.Internal.IORef
-import GHC.Internal.System.IO
+import GHC.Internal.IO (FilePath)
+import GHC.Internal.IO.Handle.Text (hPutStrLn)
+import GHC.Internal.IO.StdHandles (stderr)
import GHC.Internal.Data.Foldable
import GHC.Internal.Data.Typeable
import GHC.Internal.Control.Monad.IO.Class
@@ -819,38 +821,6 @@ addTempFile suffix = Q (qAddTempFile suffix)
addTopDecls :: [Dec] -> Q ()
addTopDecls ds = Q (qAddTopDecls ds)
-
--- | Emit a foreign file which will be compiled and linked to the object for
--- the current module. Currently only languages that can be compiled with
--- the C compiler are supported, and the flags passed as part of -optc will
--- be also applied to the C compiler invocation that will compile them.
---
--- Note that for non-C languages (for example C++) @extern "C"@ directives
--- must be used to get symbols that we can access from Haskell.
---
--- To get better errors, it is recommended to use #line pragmas when
--- emitting C files, e.g.
---
--- > {-# LANGUAGE CPP #-}
--- > ...
--- > addForeignSource LangC $ unlines
--- > [ "#line " ++ show (__LINE__ + 1) ++ " " ++ show __FILE__
--- > , ...
--- > ]
-addForeignSource :: ForeignSrcLang -> String -> Q ()
-addForeignSource lang src = do
- let suffix = case lang of
- LangC -> "c"
- LangCxx -> "cpp"
- LangObjc -> "m"
- LangObjcxx -> "mm"
- LangAsm -> "s"
- LangJs -> "js"
- RawObject -> "a"
- path <- addTempFile suffix
- runIO $ writeFile path src
- addForeignFilePath lang path
-
-- | Same as 'addForeignSource', but expects to receive a path pointing to the
-- foreign file instead of a 'String' of its contents. Consider using this in
-- conjunction with 'addTempFile'.
=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -209,7 +209,7 @@ import Data.List.NonEmpty (NonEmpty(..))
import GHC.Lexeme ( startsVarSym, startsVarId )
-- This module completely re-exports 'GHC.Boot.TH.Syntax',
--- and exports additionally functions that depend on filepath.
+-- and exports additionally functions that depend on @filepath@ or @System.IO@.
-- |
addForeignFile :: ForeignSrcLang -> String -> Q ()
@@ -218,6 +218,37 @@ addForeignFile = addForeignSource
"Use 'Language.Haskell.TH.Syntax.addForeignSource' instead"
#-} -- deprecated in 8.6
+-- | Emit a foreign file which will be compiled and linked to the object for
+-- the current module. Currently only languages that can be compiled with
+-- the C compiler are supported, and the flags passed as part of -optc will
+-- be also applied to the C compiler invocation that will compile them.
+--
+-- Note that for non-C languages (for example C++) @extern "C"@ directives
+-- must be used to get symbols that we can access from Haskell.
+--
+-- To get better errors, it is recommended to use #line pragmas when
+-- emitting C files, e.g.
+--
+-- > {-# LANGUAGE CPP #-}
+-- > ...
+-- > addForeignSource LangC $ unlines
+-- > [ "#line " ++ show (__LINE__ + 1) ++ " " ++ show __FILE__
+-- > , ...
+-- > ]
+addForeignSource :: ForeignSrcLang -> String -> Q ()
+addForeignSource lang src = do
+ let suffix = case lang of
+ LangC -> "c"
+ LangCxx -> "cpp"
+ LangObjc -> "m"
+ LangObjcxx -> "mm"
+ LangAsm -> "s"
+ LangJs -> "js"
+ RawObject -> "a"
+ path <- addTempFile suffix
+ runIO $ writeFile path src
+ addForeignFilePath lang path
+
-- | The input is a filepath, which if relative is offset by the package root.
makeRelativeToProject :: FilePath -> Q FilePath
makeRelativeToProject fp | isRelative fp = do
=====================================
rts/PrimOps.cmm
=====================================
@@ -1927,95 +1927,6 @@ loop:
}
-// NOTE: there is another implementation of this function in
-// Threads.c:performTryPutMVar(). Keep them in sync! It was
-// measurably slower to call the C function from here (70% for a
-// tight loop doing tryPutMVar#).
-//
-// TODO: we could kill the duplication by making tryPutMVar# into an
-// inline primop that expands into a C call to performTryPutMVar().
-stg_tryPutMVarzh ( P_ mvar, /* :: MVar a */
- P_ val, /* :: a */ )
-{
- W_ info, tso, q, qinfo;
-
- LOCK_CLOSURE(mvar, info);
-
- if (StgMVar_value(mvar) != stg_END_TSO_QUEUE_closure) {
-#if defined(THREADED_RTS)
- unlockClosure(mvar, info);
-#endif
- return (0);
- }
-
- q = StgMVar_head(mvar);
-loop:
- if (q == stg_END_TSO_QUEUE_closure) {
- /* No further takes, the MVar is now full. */
- if (info == stg_MVAR_CLEAN_info) {
- ccall dirty_MVAR(BaseReg "ptr", mvar "ptr", StgMVar_value(mvar) "ptr");
- }
-
- StgMVar_value(mvar) = val;
- unlockClosure(mvar, stg_MVAR_DIRTY_info);
- return (1);
- }
-
- qinfo = GET_INFO_ACQUIRE(q);
-
- if (qinfo == stg_IND_info ||
- qinfo == stg_MSG_NULL_info) {
- q = %acquire StgInd_indirectee(q);
- goto loop;
- }
-
- // There are takeMVar(s) waiting: wake up the first one
-
- tso = StgMVarTSOQueue_tso(q);
- q = StgMVarTSOQueue_link(q);
- StgMVar_head(mvar) = q;
- if (q == stg_END_TSO_QUEUE_closure) {
- StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
- } else {
- if (info == stg_MVAR_CLEAN_info) {
- // Resolve #18919.
- ccall dirty_MVAR(BaseReg "ptr", mvar "ptr",
- StgMVar_value(mvar) "ptr");
- info = stg_MVAR_DIRTY_info;
- }
- }
-
- // save why_blocked here, because waking up the thread destroys
- // this information
- W_ why_blocked;
- why_blocked = TO_W_(StgTSO_why_blocked(tso)); // TODO: Missing barrier
- ASSERT(StgTSO_block_info(tso) == mvar);
-
- // actually perform the takeMVar
- W_ stack;
- stack = StgTSO_stackobj(tso);
- if (IS_STACK_CLEAN(stack)) {
- ccall dirty_STACK(MyCapability() "ptr", stack "ptr");
- }
- PerformTake(stack, val);
-
- // indicate that the MVar operation has now completed.
- StgTSO__link(tso) = stg_END_TSO_QUEUE_closure;
-
- ccall tryWakeupThread(MyCapability() "ptr", tso);
-
- // If it was a readMVar, then we can still do work,
- // so loop back. (XXX: This could take a while)
- if (why_blocked == BlockedOnMVarRead)
- goto loop;
-
- ASSERT(why_blocked == BlockedOnMVar);
-
- unlockClosure(mvar, info);
- return (1);
-}
-
-
stg_readMVarzh ( P_ mvar, /* :: MVar a */ )
{
W_ val, info, tso, q;
=====================================
rts/RtsSymbols.c
=====================================
@@ -678,6 +678,7 @@ extern char **environ;
SymI_HasDataProto(stg_readTVarIOzh) \
SymI_HasProto(resumeThread) \
SymI_HasProto(setNumCapabilities) \
+ SymI_HasProto(performTryPutMVar) \
SymI_HasProto(getNumberOfProcessors) \
SymI_HasProto(resolveObjs) \
SymI_HasDataProto(stg_retryzh) \
@@ -869,7 +870,6 @@ extern char **environ;
SymI_HasDataProto(stg_takeMVarzh) \
SymI_HasDataProto(stg_readMVarzh) \
SymI_HasDataProto(stg_threadStatuszh) \
- SymI_HasDataProto(stg_tryPutMVarzh) \
SymI_HasDataProto(stg_tryTakeMVarzh) \
SymI_HasDataProto(stg_tryReadMVarzh) \
SymI_HasDataProto(stg_unmaskAsyncExceptionszh) \
=====================================
rts/Threads.c
=====================================
@@ -795,8 +795,6 @@ threadStackUnderflow (Capability *cap, StgTSO *tso)
/* ----------------------------------------------------------------------------
Implementation of tryPutMVar#
-
- NOTE: this should be kept in sync with stg_tryPutMVarzh in PrimOps.cmm
------------------------------------------------------------------------- */
bool performTryPutMVar(Capability *cap, StgMVar *mvar, StgClosure *value)
=====================================
rts/Threads.h
=====================================
@@ -24,7 +24,7 @@ void migrateThread (Capability *from, StgTSO *tso, Capability *to);
//
#if defined(THREADED_RTS)
void wakeupThreadOnCapability (Capability *cap,
- Capability *other_cap,
+ Capability *other_cap,
StgTSO *tso);
#endif
@@ -40,8 +40,6 @@ StgBool isThreadBound (StgTSO* tso);
void threadStackOverflow (Capability *cap, StgTSO *tso);
W_ threadStackUnderflow (Capability *cap, StgTSO *tso);
-bool performTryPutMVar(Capability *cap, StgMVar *mvar, StgClosure *value);
-
#if defined(DEBUG)
void printThreadBlockage (StgTSO *tso);
void printThreadStatus (StgTSO *t);
=====================================
rts/include/rts/Threads.h
=====================================
@@ -90,3 +90,5 @@ extern Capability MainCapability;
// current value at the moment).
//
extern void setNumCapabilities (uint32_t new_);
+
+bool performTryPutMVar(Capability *cap, StgMVar *mvar, StgClosure *value);
=====================================
rts/include/stg/MiscClosures.h
=====================================
@@ -512,7 +512,6 @@ RTS_FUN_DECL(stg_takeMVarzh);
RTS_FUN_DECL(stg_putMVarzh);
RTS_FUN_DECL(stg_readMVarzh);
RTS_FUN_DECL(stg_tryTakeMVarzh);
-RTS_FUN_DECL(stg_tryPutMVarzh);
RTS_FUN_DECL(stg_tryReadMVarzh);
RTS_FUN_DECL(stg_waitReadzh);
=====================================
testsuite/tests/ffi/should_compile/all.T
=====================================
@@ -33,6 +33,7 @@ test(
compile,
[
'-optc=-DC -optcxx=-DCXX -optcxx=-std=c++11'
+ + ' -package=template-haskell'
+ (' -optcxx=-stdlib=libc++' if opsys('darwin') else '')
],
)
=====================================
testsuite/tests/ghci-wasm/T26998.hs
=====================================
@@ -0,0 +1,4 @@
+main :: IO ()
+main = pure ()
+
+foreign export javascript "my_main" main :: IO ()
=====================================
testsuite/tests/ghci-wasm/all.T
=====================================
@@ -10,3 +10,5 @@ test('T26430', [
extra_hc_opts('-L. -lT26430B')]
, compile_and_run, ['']
)
+
+test('T26998', [], compile_and_run, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a2567c46e7bfe5a746f415f1561826…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a2567c46e7bfe5a746f415f1561826…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/ani/kill-SrcCodeOrigin] 37 commits: Check for negative type literals in the type checker (#26861)
by Apoorv Ingle (@ani) 08 Mar '26
by Apoorv Ingle (@ani) 08 Mar '26
08 Mar '26
Apoorv Ingle pushed to branch wip/ani/kill-SrcCodeOrigin at Glasgow Haskell Compiler / GHC
Commits:
bd3eba86 by Vladislav Zavialov at 2026-02-27T05:48:01-05:00
Check for negative type literals in the type checker (#26861)
GHC disallows negative type literals (e.g., -1), as tested by T8306 and
T8412. This check is currently performed in the renamer:
rnHsTyLit tyLit@(HsNumTy x i) = do
when (i < 0) $
addErr $ TcRnNegativeNumTypeLiteral tyLit
However, this check can be bypassed using RequiredTypeArguments
(see the new test case T26861). Prior to this patch, such programs
caused the compiler to hang instead of reporting a proper error.
This patch addresses the issue by adding an equivalent check in
the type checker, namely in tcHsType.
The diff is deliberately minimal to facilitate backporting. A more
comprehensive rework of HsTyLit is planned for a separate commit.
- - - - -
faf14e0c by Vladislav Zavialov at 2026-02-27T05:48:45-05:00
Consistent pretty-printing of HsString, HsIsString, HsStrTy
Factor out a helper to pretty-print string literals, thus fixing newline
handling for overloaded string literals and type literals.
Test cases: T26860ppr T26860ppr_overloaded T26860ppr_tylit
Follow up to ddf1434ff9bb08cfef3c93f23de6b83ec698aa27
- - - - -
f108a972 by Arnaud Spiwack at 2026-02-27T12:53:01-05:00
Make list comprehension completely non-linear
Fixes #25081
From the note:
The usefulness of list comprehension in conjunction with linear types is dubious.
After all, statements are made to be run many times, for instance in
```haskell
[u | y <- [0,1], stmts]
```
both `u` and `stmts` are going to be run several times.
In principle, though, there are some position in a monad comprehension
expression which could be considered linear. We could try and make it so that
these positions are considered linear by the typechecker, but in practice the
desugarer doesn't take enough care to ensure that these are indeed desugared to
linear sites. We tried in the past, and it turned out that we'd miss a
desugaring corner case (#25772).
Until there's a demand for this very specific improvement, let's instead be
conservative, and consider list comprehension to be completely non-linear.
- - - - -
ae799cab by Simon Jakobi at 2026-02-27T12:53:54-05:00
PmAltConSet: Use Data.Set instead of Data.Map
...to store `PmLit`s.
The Map was only used to map keys to themselves.
Changing the Map to a Set saves a Word of memory per entry.
Resolves #26756.
- - - - -
dcd7819c by Vladislav Zavialov at 2026-02-27T18:46:03-05:00
Drop HsTyLit in favor of HsLit (#26862, #25121)
This patch is a small step towards unification of HsExpr and HsType,
taking care of literals (HsLit) and type literals (HsTyLit).
Additionally, it improves error messages for unsupported type literals,
such as unboxed or fractional literals (test cases: T26862, T26862_th).
Changes to the AST:
* Use HsLit where HsTyLit was previously used
* Use HsChar where HsCharTy was previously used
* Use HsString where HsStrTy was previously used
* Use HsNatural (NEW) where HsNumTy was previously used
* Use HsDouble (NEW) to represent unsupported fractional type literals
Changes to logic:
* Parse unboxed and fractional type literals (to be rejected later)
* Drop the check for negative literals in the renamer (rnHsTyLit)
in favor of checking in the type checker (tc_hs_lit_ty)
* Check for invalid type literals in TH (repTyLit) and report
unrepresentable literals with ThUnsupportedTyLit
* Allow negative type literals in TH (numTyLit). This is fine as
these will be taken care of at splice time (test case: T8306_th)
- - - - -
c927954f by Vladislav Zavialov at 2026-02-27T18:46:50-05:00
Increase test coverage of diagnostics
Add test cases for the previously untested diagnostics:
[GHC-01239] PsErrIfInFunAppExpr
[GHC-04807] PsErrProcInFunAppExpr
[GHC-08195] PsErrInvalidRecordCon
[GHC-16863] PsErrUnsupportedBoxedSumPat
[GHC-18910] PsErrSemiColonsInCondCmd
[GHC-24737] PsErrInvalidWhereBindInPatSynDecl
[GHC-25037] PsErrCaseInFunAppExpr
[GHC-25078] PsErrPrecedenceOutOfRange
[GHC-28021] PsErrRecordSyntaxInPatSynDecl
[GHC-35827] TcRnNonOverloadedSpecialisePragma
[GHC-40845] PsErrUnpackDataCon
[GHC-45106] PsErrInvalidInfixHole
[GHC-50396] PsErrInvalidRuleActivationMarker
[GHC-63930] MultiWayIfWithoutAlts
[GHC-65536] PsErrNoSingleWhereBindInPatSynDecl
[GHC-67630] PsErrMDoInFunAppExpr
[GHC-70526] PsErrLetCmdInFunAppCmd
[GHC-77808] PsErrDoCmdInFunAppCmd
[GHC-86934] ClassPE
[GHC-90355] PsErrLetInFunAppExpr
[GHC-91745] CasesExprWithoutAlts
[GHC-92971] PsErrCaseCmdInFunAppCmd
[GHC-95644] PsErrBangPatWithoutSpace
[GHC-97005] PsErrIfCmdInFunAppCmd
Remove unused error constructors:
[GHC-44524] PsErrExpectedHyphen
[GHC-91382] TcRnIllegalKindSignature
- - - - -
3a9470fd by Torsten Schmits at 2026-02-27T18:47:34-05:00
Avoid expensive computation for debug logging in `mergeDatabases` when log level is low
This computed and traversed a set intersection for every single
dependency unconditionally.
- - - - -
ea4c2cbd by Brandon Chinn at 2026-02-27T16:22:38-08:00
Implement QualifiedStrings (#26503)
See Note [Implementation of QualifiedStrings]
- - - - -
08bc245b by sheaf at 2026-03-01T11:11:54-05:00
Clean up join points, casts & ticks
This commit shores up the logic dealing with casts and ticks occurring
in between a join point binding and a jump.
Fixes #26642 #26929 #26693
Makes progress on #14610 #26157 #26422
Changes:
- Remove 'GHC.Types.Tickish.TickishScoping' in favour of simpler
predicates 'tickishHasNoScope'/'tickishHasSoftScope', as things were
before commit 993975d3. This makes the code easier to read and
document (fewer indirections).
- Introduce 'canCollectArgsThroughTick' for consistent handling of
ticks around PrimOps and other 'Id's that cannot be eta-reduced.
See overhauled Note [Ticks and mandatory eta expansion].
- New Note [JoinId vs TailCallInfo] in GHC.Core.SimpleOpt that explains
robustness of JoinId vs fragility of TailCallInfo.
- Allow casts/non-soft-scoped ticks to occur in between a join point
binder and a jump, but only in Core Prep.
See Note [Join points, casts, and ticks] and
Note [Join points, casts, and ticks... in Core Prep]
in GHC.Core.Opt.Simplify.Iteration.
Also update Core Lint to account for this.
See Note [Linting join points with casts or ticks] in GHC.Core.Lint.
- Update 'GHC.Core.Utils.mergeCaseAlts' to avoid pushing a cast in
between a join point binding and its jumps. This fixes #26642.
See the new (MC5) and (MC6) in Note [Merge Nested Cases].
- Update float out to properly handle source note ticks. They are now
properly floated out instead of being discarded.
This increases the number of ticks in certain tests with -g.
Test cases: T26642 and TrickyJoins.
Metric increase due to more source note ticks with -g:
-------------------------
Metric Increase:
libdir
size_hello_artifact
size_hello_unicode
-------------------------
- - - - -
476c4cdf by Sean D. Gillespie at 2026-03-02T10:14:37-05:00
Add SIMD absolute value on x86 and LLVM
On x86, absolute value of 32 bits or less is implemented with
PABSB/PABSW/PABSD if SSSE3 is available. Otherwise, there is a fallback
for SSE2. For 64 bit integers it uses VPABSQ, required by AVX-512VL,
with fallbacks for SSE4.2 and SSE2.
There is no dedicated instruction for floating point absolute value on
x86, so it is simulated using bitwise AND.
Absolute value for signed integers and floats are implemented by the
"llvm.abs/llvm.fabs" standard library intrinsics. This implementation
uses MachOps constructors, unlike non-vector floating point absolute
value, which uses CallishMachOps.
- - - - -
709448c0 by Sean D. Gillespie at 2026-03-02T10:14:46-05:00
Add SIMD floating point square root
On x86, this is implemented with the SQRTPS and SQRTPD instructions. On
LLVM, it uses the sqrt library intrinstic.
- - - - -
0deadf66 by Sean D. Gillespie at 2026-03-02T10:14:47-05:00
Improve error message for SIMD on aarch64
When encountering vector literals on aarch64, previously it would
throw:
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.15.20251219:
getRegister' (CmmLit:CmmVec):
Now it is more consistent with the other vector operations:
<no location info>: error:
sorry! (unimplemented feature or known bug)
GHC version 9.15.20251219:
SIMD operations on AArch64 currently require the LLVM backend
- - - - -
7d64031b by Vladislav Zavialov at 2026-03-03T11:09:28-05:00
Replace maybeAddSpace with spaceIfSingleQuote
Simplify pretty-printing of HsTypes by using spaceIfSingleQuote.
This allows us to drop the unwieldy lhsTypeHasLeadingPromotionQuote
helper function.
Follow-up to 178c1fd830c78377ef5d338406a41e1d8eb5f0da
- - - - -
598db847 by Wolfgang Jeltsch at 2026-03-06T06:25:25-05:00
Correct `hIsReadable` and `hIsWritable` for duplex handles
This contribution implements CLC proposal #371. It changes `hIsReadable`
and `hIsWritable` such that they always throw a respective exception
when encountering a closed or semi-closed handle, not just in the case
of a file handle.
- - - - -
b90201e5 by Wolfgang Jeltsch at 2026-03-06T06:25:25-05:00
Document `SemiClosedHandle`
- - - - -
c9df72b5 by Wolfgang Jeltsch at 2026-03-06T06:25:25-05:00
Tell users what “semi-closed” means for duplex handles
- - - - -
a8aa1868 by Ilias Tsitsimpis at 2026-03-06T06:26:29-05:00
Fix determinism of linker arguments
The switch from Data.Map to UniqMap in 3b5be05ac29 introduced
non-determinism in the order of packages passed to the linker.
This resulted in non-reproducible builds where the DT_NEEDED entries in
dynamic libraries were ordered differently across builds.
Fix the regression by explicitly sorting the package list derived from
UniqMap.
Fixes #26838
- - - - -
9b64ad3a by Matthew Pickering at 2026-03-06T06:27:16-05:00
determinism: Use a deterministic renaming when writing bytecode files
Now when writing the bytecode file, a counter and substitution are used
to provide deterministic keys to local variables (rather than relying on
uniques). This change ensures that `.gbc` are produced
deterministically.
Fixes #26499
- - - - -
d29800e0 by Teo Camarasu at 2026-03-06T06:28:46-05:00
ghc-internal: delete Version hs-boot loop
Version has a Read instance which needs Unicode but part of the Unicode interface is the unicode version. This is easy to resolve. We simply don't re-export the version from the Unicode module.
Resolves #26940
- - - - -
ad25af90 by Sylvain Henry at 2026-03-06T06:30:33-05:00
Linker: implement support for COMMON symbols (#6107)
Add some support for COMMON symbols. We don't support common symbols
having different sizes where the larger one is allocated after the
smaller one. The linker will fail with an appropriate error message if
it happens.
- - - - -
3b59f158 by Cheng Shao at 2026-03-06T06:31:16-05:00
compiler: fix redundant import of GHC.Hs.Lit
This patch removes a redundant import of `GHC.Hs.Lit` which causes a
ghc build failure with validate flavours when bootstrapping from 9.14.
Fixes #26972.
- - - - -
148d36f3 by Cheng Shao at 2026-03-06T06:32:01-05:00
compiler: avoid unneeded traversals in GHC.Unit.State
Following !15591, this patch avoids unneeded traversals in
`reportCycles`/`reportUnusable` when log verbosity is below given
threshold. Also applies `logVerbAtLeast` when appropriate.
Co-authored-by: Codex <codex(a)openai.com>
- - - - -
7e31367c by Cheng Shao at 2026-03-06T06:32:46-05:00
ghc-internal: fix redundant import in GHC.Internal.Event.Windows.ManagedThreadPool
This patch fixes redundant import in
`GHC.Internal.Event.Windows.ManagedThreadPool` that causes a
compilation error when building windows target with validate flavours
and bootstrapping from 9.14. Fixes #26976.
- - - - -
fc8b8e27 by sheaf at 2026-03-06T06:33:28-05:00
System.Info.fullCompilerVersion: add 'since' annot
Fixes #26973
- - - - -
c8238375 by Sylvain Henry at 2026-03-06T06:34:23-05:00
Hadrian: deprecate --bignum and automatically enable +native_bignum for JS
Deprecate --bignum=... to select the bignum backend. It's only used to
select the native backend, and this can be done with the +native_bignum
flavour transformer.
Additionally, we automatically enable +native_bignum for the JS target
because the GMP backend isn't supported.
- - - - -
a3ac7074 by Sylvain Henry at 2026-03-06T06:35:17-05:00
JS: fix putEnum/fromEnum (#24593)
Don't go through Word16 when serializing Enums.
- - - - -
0b36e96c by Andreas Klebinger at 2026-03-06T06:35:58-05:00
Docs: Document -fworker-wrapper-cbv default setting.
Fixes #26841
- - - - -
eca445e7 by mangoiv at 2026-03-07T05:02:36-05:00
drop deb9/10 from CI, add deb13
debian 9 and 10 are end of life, hence we drop them
from our CI, but we do add debian 13. Jobs that were
previously run on 9 and 10 run on 13, too, jobs that
were run on 10, are run on 11 now. Jobs that were
previously run on debian 12 are run on debian 13 now.
This MR also updates hadrian's bootstrap plans for that
reason.
Metric Decrease:
T9872d
- - - - -
12f8b829 by Luite Stegeman at 2026-03-07T05:03:33-05:00
Fix GHC.Internal.Prim haddock
Haddock used to parse Haskell source to generate documentation,
but switched to using interface files instead. This broke documentation
of the GHC.Internal.Prim module, since it's a wired-in interface that
didn't provide a document structure.
This patch adds the missing document structure and updates genprimopcode
to make the section headers and descriptions available.
fixes #26954
- - - - -
f87e5e57 by Luite Stegeman at 2026-03-07T05:03:33-05:00
Remove obsolete --make-haskell-source from genprimopcode
Now that haddock uses the wired-in interface for GHC.Internal.Prim,
the generated Haskell source file is no longer needed. Remove the
--make-haskell-source code generator from genprimopcode and replace
the generated GHC/Internal/Prim.hs with a minimal static source file.
- - - - -
4a7ddc7b by Sylvain Henry at 2026-03-07T05:04:59-05:00
JS: fix linking of exposed but non-preload units (#24886)
Units exposed in the unit database but not explicitly passed on the
command-line were not considered by the JS linker. This isn't an issue
for cabal which passes every unit explicitly but it is an issue when
using GHC directly (cf T24886 test).
- - - - -
689aafcd by mangoiv at 2026-03-07T05:05:52-05:00
testsuite: double foundation timeout multiplier
The runtime timeout in the foundation test was regularly hit by code
generated by the wasm backend - we increase the timout since the high
runtime is expected on the wasm backend for this rather complex test.
Resolves #26938
- - - - -
f2bfed15 by Apoorv Ingle at 2026-03-08T16:08:46-05:00
Work for #25001
Notes added [Error Context Stack] [Typechecking by expansion: overview]
Notes updated Note [Expanding HsDo with XXExprGhcRn]
-------------------------
Metric Decrease:
T9020
-------------------------
* Streamlines implementations of `tcExpr` and `tcXExpr` to work on `XExpr`
* Kills `VACtxt` (and its associated `VAExpansion` and `VACall`) datatype, it is subsumed by simply a `SrcSpan`.
* Kills the function `addHeadCtxt` as it is now mearly setting a location
* The function `tcValArgs` does its own argument number management
* Makes `splitHsApps` not look through `XExpr`
* `tcExprSigma` is called if the head of the expression after calling `splitHsApps` turns out to be an `XExpr`
* Removes location information from `OrigPat` payload
* Removes special case of tcBody from `tcLambdaMatches`
* Removes special case of `dsExpr` for `ExpandedThingTc`
* Rename `HsThingRn` to `SrcCodeCtxt`
* Kills `tcl_in_gen_code` and `tcl_err_ctxt`. It is subsumed by `ErrCtxtStack`
* Kills `ExpectedFunTyOrig`. It is subsumed by `CtOrigin`
* Fixes `CtOrigin` for `HsProjection` case in `exprCtOrigin`. It was previously assigned to be `SectionOrigin`. It is now just the expression
* Adds a new `CtOrigin.ExpansionOrigin` for storing the original syntax
* Adds a new `CtOrigin.ExpectedTySyntax` as a replacement for `ExpectedTySyntaxOp`. Cannot kill the former yet because of `ApplicativeDo`
* Renames `tcMonoExpr` -> `tcMonoLExpr`, `tcMonoExprNC` -> `tcMonoLExpr`
* Renames `EValArg`, `EValArgQL` fields: `ea_ctxt` -> `ea_loc_span` and `eaql_ctx` -> `eaql_loc_span`
* kill `PopErrCtxt` from `XXExprGhcRn`
* simplify `addArgCtxt` and push `setSrcSpan` inside `addLExprCtxt`. Make sure addExprCtxt is not called by itself
* fun_orig in tcApp depends on the SrcSpan of the head of the application chain (similar to addArgCtxt)
* rename fun_ctxt to fun_lspan, fun_orig passed in tcInstFun to default to app chain head if its user located, fall back to srcCodeOrigin if it's a generated location
* fix quickLookArg function to blame the correct application chain head. The arguments application chain head should be blamed, not the original head when we quick look arg
* Make sure only expression wrapped around generated src span are ignored while adding them to the error context stack
* `getDeepSubsumptionFlag_DataConHead` performs a non-trivial traversal if the expression passed to it is complex.
This traversal is necessary if the head of the function is an `XExpr` and `splitHsApps` does not look through them
- The deepsubsumption flag is stored in EVAlArgQL to reduce the need to call `getDeepSubsumptionFlag_DataConHead`
- `getDeepSubsumptionFlag_DataConHead` is called in `tcExprSigma` and `tcInferAppHead` to reduce AST traversals
* Make a new variant `GeneratedSrcSpan` in `SrcSpan` for HIEAst Nodes
* wrap `fromListN` with a generated src span with GeneratedSrcSpanDetails field to store the original srcspan
* remove `UnhelpfulGenerated` from `UnhelpfulSpanReason` and into new datatype `GeneratedSrcSpanDetails`
- - - - -
466e162c by Apoorv Ingle at 2026-03-08T16:11:02-05:00
trying to remove SrcCodeOrigin
- - - - -
2949e4c3 by Simon Peyton Jones at 2026-03-08T16:11:03-05:00
Improvements in ErrCtxt
- - - - -
5ed13f95 by Apoorv Ingle at 2026-03-08T16:11:04-05:00
ErrCtxtMsg to CtOrigin
- - - - -
b7beec74 by Apoorv Ingle at 2026-03-08T16:11:05-05:00
remove CtOrigin.ExpansionOrigin in favour of errCtxtCtOrigin, remove CtOrign from ErrMsgCtxt.FunTysCtxt
- - - - -
368 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.hs
- compiler/GHC/Builtin/PrimOps.hs
- compiler/GHC/Builtin/Types.hs
- compiler/GHC/Builtin/Utils.hs
- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/CmmToC.hs
- compiler/GHC/CmmToLlvm/CodeGen.hs
- compiler/GHC/Core.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/FloatIn.hs
- compiler/GHC/Core/Opt/FloatOut.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Config/Core/Lint.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Hs/DocString.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Expr.hs-boot
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/Hs/Pat.hs
- compiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/Hs/Type.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Errors/Ppr.hs
- compiler/GHC/HsToCore/Errors/Types.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Pmc/Solver/Types.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Iface/Ext/Utils.hs
- compiler/GHC/Iface/Tidy.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Errors/Ppr.hs
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/HaddockLex.x
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/String.hs
- compiler/GHC/Rename/Bind.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/HsType.hs
- + compiler/GHC/Rename/Lit.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Runtime/Debugger/Breakpoints.hs
- compiler/GHC/Runtime/Interpreter/JS.hs
- compiler/GHC/StgToCmm/Expr.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/StgToJS/Object.hs
- compiler/GHC/StgToJS/Prim.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/App.hs
- + compiler/GHC/Tc/Gen/App.hs-boot
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Do.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Expr.hs-boot
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Gen/Match.hs-boot
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Solver/Solve.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Class.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/BasicTypes.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/CtLoc.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/Tc/Types/LclEnv.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Types/Origin.hs-boot
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Tc/Utils/TcType.hs-boot
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Validity.hs
- compiler/GHC/Tc/Zonk/Type.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Basic.hs
- compiler/GHC/Types/Error.hs
- + compiler/GHC/Types/Error.hs-boot
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Types/SourceText.hs
- compiler/GHC/Types/SrcLoc.hs
- compiler/GHC/Types/Tickish.hs
- compiler/GHC/Unit/State.hs
- + compiler/GHC/Unit/State.hs-boot
- compiler/GHC/Utils/Binary.hs
- compiler/GHC/Utils/Error.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- compiler/Language/Haskell/Syntax/Lit.hs
- compiler/Language/Haskell/Syntax/Pat.hs
- compiler/Language/Haskell/Syntax/Type.hs
- compiler/ghc.cabal.in
- docs/users_guide/9.16.1-notes.rst
- + docs/users_guide/exts/qualified_strings.rst
- docs/users_guide/using-optimisation.rst
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Info.hs
- hadrian/README.md
- hadrian/bootstrap/generate_bootstrap_plans
- hadrian/bootstrap/plan-9_10_1.json
- hadrian/bootstrap/plan-9_10_2.json
- + hadrian/bootstrap/plan-9_10_3.json
- hadrian/bootstrap/plan-bootstrap-9_10_1.json
- hadrian/bootstrap/plan-bootstrap-9_10_2.json
- + hadrian/bootstrap/plan-bootstrap-9_10_3.json
- hadrian/src/CommandLine.hs
- hadrian/src/Main.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Settings.hs
- hadrian/src/Settings/Builders/GenPrimopCode.hs
- libraries/base/changelog.md
- libraries/base/src/GHC/Base.hs
- libraries/base/src/GHC/Exts.hs
- libraries/base/src/GHC/Unicode.hs
- libraries/base/src/System/Info.hs
- libraries/ghc-experimental/CHANGELOG.md
- libraries/ghc-internal/ghc-internal.cabal.in
- − libraries/ghc-internal/src/GHC/Internal/Data/Version.hs-boot
- libraries/ghc-internal/src/GHC/Internal/Event/Windows/ManagedThreadPool.hs
- libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs
- libraries/ghc-internal/src/GHC/Internal/IO/Handle/Text.hs
- libraries/ghc-internal/src/GHC/Internal/IO/Handle/Types.hs
- libraries/ghc-internal/src/GHC/Internal/LanguageExtensions.hs
- + libraries/ghc-internal/src/GHC/Internal/Prim.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Lib.hs
- libraries/ghc-internal/src/GHC/Internal/Unicode.hs
- libraries/ghc-internal/src/GHC/Internal/Unicode/Version.hs
- libraries/ghc-internal/tools/ucd2haskell/exe/UCD2Haskell/ModuleGenerators.hs
- rts/Linker.c
- rts/LinkerInternals.h
- rts/linker/Elf.c
- rts/linker/MachO.c
- rts/linker/PEi386.c
- testsuite/driver/perf_notes.py
- testsuite/tests/codeGen/should_compile/debug.stdout
- + testsuite/tests/dependent/should_fail/SelfDepCls.hs
- + testsuite/tests/dependent/should_fail/SelfDepCls.stderr
- testsuite/tests/dependent/should_fail/all.T
- testsuite/tests/diagnostic-codes/codes.stdout
- testsuite/tests/driver/T4437.hs
- testsuite/tests/ghc-api/annotations-literals/literals.stdout
- testsuite/tests/ghc-api/annotations-literals/parsed.hs
- testsuite/tests/ghci/should_run/all.T
- testsuite/tests/indexed-types/should_fail/T2693.stderr
- testsuite/tests/indexed-types/should_fail/T5439.stderr
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- testsuite/tests/interface-stability/ghc-prim-exports.stdout
- testsuite/tests/interface-stability/ghc-prim-exports.stdout-mingw32
- testsuite/tests/interface-stability/template-haskell-exports.stdout
- + testsuite/tests/javascript/T24886.hs
- + testsuite/tests/javascript/T24886.stderr
- + testsuite/tests/javascript/T24886.stdout
- testsuite/tests/javascript/all.T
- − testsuite/tests/linear/should_compile/LinearListComprehension.hs
- testsuite/tests/linear/should_compile/all.T
- testsuite/tests/linear/should_fail/T25081.hs
- testsuite/tests/linear/should_fail/T25081.stderr
- testsuite/tests/module/all.T
- + testsuite/tests/module/mod70b.hs
- + testsuite/tests/module/mod70b.stderr
- testsuite/tests/numeric/should_run/all.T
- testsuite/tests/overloadedrecflds/should_compile/all.T
- testsuite/tests/overloadedrecflds/should_fail/T26480b.stderr
- testsuite/tests/overloadedrecflds/should_run/all.T
- + testsuite/tests/parser/should_fail/NoBlockArgumentsFail4.hs
- + testsuite/tests/parser/should_fail/NoBlockArgumentsFail4.stderr
- testsuite/tests/parser/should_fail/NoBlockArgumentsFailArrowCmds.hs
- testsuite/tests/parser/should_fail/NoBlockArgumentsFailArrowCmds.stderr
- + testsuite/tests/parser/should_fail/NoDoAndIfThenElseArrowCmds.hs
- + testsuite/tests/parser/should_fail/NoDoAndIfThenElseArrowCmds.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail10.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail11.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail8.stderr
- + testsuite/tests/parser/should_fail/T26860ppr_overloaded.hs
- + testsuite/tests/parser/should_fail/T26860ppr_overloaded.stderr
- + testsuite/tests/parser/should_fail/T26860ppr_tylit.hs
- + testsuite/tests/parser/should_fail/T26860ppr_tylit.stderr
- testsuite/tests/parser/should_fail/all.T
- + testsuite/tests/parser/should_fail/badRuleMarker.hs
- + testsuite/tests/parser/should_fail/badRuleMarker.stderr
- + testsuite/tests/parser/should_fail/patFail010.hs
- + testsuite/tests/parser/should_fail/patFail010.stderr
- + testsuite/tests/parser/should_fail/patFail011.hs
- + testsuite/tests/parser/should_fail/patFail011.stderr
- + testsuite/tests/parser/should_fail/precOutOfRange.hs
- + testsuite/tests/parser/should_fail/precOutOfRange.stderr
- + testsuite/tests/parser/should_fail/unpack_data_con.hs
- + testsuite/tests/parser/should_fail/unpack_data_con.stderr
- testsuite/tests/patsyn/should_fail/T10426.stderr
- testsuite/tests/patsyn/should_fail/all.T
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail1.hs
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail1.stderr
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail2.hs
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail2.stderr
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail3.hs
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail3.stderr
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail4.hs
- + testsuite/tests/patsyn/should_fail/patsyn_where_fail4.stderr
- testsuite/tests/plugins/test-defaulting-plugin.stderr
- testsuite/tests/pmcheck/should_compile/T11303.hs
- testsuite/tests/printer/T17697.stderr
- + testsuite/tests/qualified-strings/Makefile
- + testsuite/tests/qualified-strings/should_compile/Example/Length.hs
- + testsuite/tests/qualified-strings/should_compile/all.T
- + testsuite/tests/qualified-strings/should_compile/qstrings_redundant_pattern.hs
- + testsuite/tests/qualified-strings/should_compile/qstrings_redundant_pattern.stderr
- + testsuite/tests/qualified-strings/should_fail/Example/Length.hs
- + testsuite/tests/qualified-strings/should_fail/Makefile
- + testsuite/tests/qualified-strings/should_fail/all.T
- + testsuite/tests/qualified-strings/should_fail/qstrings_bad_expr.hs
- + testsuite/tests/qualified-strings/should_fail/qstrings_bad_expr.stderr
- + testsuite/tests/qualified-strings/should_fail/qstrings_bad_pat.hs
- + testsuite/tests/qualified-strings/should_fail/qstrings_bad_pat.stderr
- + testsuite/tests/qualified-strings/should_fail/qstrings_multiline_no_ext.hs
- + testsuite/tests/qualified-strings/should_fail/qstrings_multiline_no_ext.stderr
- + testsuite/tests/qualified-strings/should_run/Example/ByteStringAscii.hs
- + testsuite/tests/qualified-strings/should_run/Example/ByteStringUtf8.hs
- + testsuite/tests/qualified-strings/should_run/Example/Text.hs
- + testsuite/tests/qualified-strings/should_run/Makefile
- + testsuite/tests/qualified-strings/should_run/all.T
- + testsuite/tests/qualified-strings/should_run/qstrings_expr.hs
- + testsuite/tests/qualified-strings/should_run/qstrings_expr.stdout
- + testsuite/tests/qualified-strings/should_run/qstrings_pat.hs
- + testsuite/tests/qualified-strings/should_run/qstrings_pat.stdout
- + testsuite/tests/qualified-strings/should_run/qstrings_th.hs
- + testsuite/tests/qualified-strings/should_run/qstrings_th.stdout
- testsuite/tests/quasiquotation/qq005/test.T
- testsuite/tests/quasiquotation/qq006/test.T
- testsuite/tests/rebindable/rebindable6.stderr
- testsuite/tests/rep-poly/RepPolyDoBind.stderr
- testsuite/tests/rep-poly/RepPolyDoBody1.stderr
- testsuite/tests/rep-poly/RepPolyDoBody2.stderr
- testsuite/tests/rep-poly/RepPolyRecordUpdate.stderr
- testsuite/tests/rts/linker/Makefile
- + testsuite/tests/rts/linker/T6107.hs
- + testsuite/tests/rts/linker/T6107.stdout
- + testsuite/tests/rts/linker/T6107_sym1.s
- + testsuite/tests/rts/linker/T6107_sym2.s
- testsuite/tests/rts/linker/all.T
- testsuite/tests/saks/should_compile/all.T
- testsuite/tests/showIface/all.T
- testsuite/tests/simd/should_run/doublex2_arith.hs
- testsuite/tests/simd/should_run/doublex2_arith.stdout
- testsuite/tests/simd/should_run/doublex2_arith_baseline.hs
- testsuite/tests/simd/should_run/doublex2_arith_baseline.stdout
- testsuite/tests/simd/should_run/floatx4_arith.hs
- testsuite/tests/simd/should_run/floatx4_arith.stdout
- testsuite/tests/simd/should_run/floatx4_arith_baseline.hs
- testsuite/tests/simd/should_run/floatx4_arith_baseline.stdout
- testsuite/tests/simd/should_run/int16x8_arith.hs
- testsuite/tests/simd/should_run/int16x8_arith.stdout
- testsuite/tests/simd/should_run/int16x8_arith_baseline.hs
- testsuite/tests/simd/should_run/int16x8_arith_baseline.stdout
- testsuite/tests/simd/should_run/int32x4_arith.hs
- testsuite/tests/simd/should_run/int32x4_arith.stdout
- testsuite/tests/simd/should_run/int32x4_arith_baseline.hs
- testsuite/tests/simd/should_run/int32x4_arith_baseline.stdout
- testsuite/tests/simd/should_run/int64x2_arith.hs
- testsuite/tests/simd/should_run/int64x2_arith.stdout
- testsuite/tests/simd/should_run/int64x2_arith_baseline.hs
- testsuite/tests/simd/should_run/int64x2_arith_baseline.stdout
- testsuite/tests/simd/should_run/int8x16_arith.hs
- testsuite/tests/simd/should_run/int8x16_arith.stdout
- testsuite/tests/simd/should_run/int8x16_arith_baseline.hs
- testsuite/tests/simd/should_run/int8x16_arith_baseline.stdout
- + testsuite/tests/simplCore/should_compile/T26642.hs
- + testsuite/tests/simplCore/should_compile/TrickyJoins.hs
- testsuite/tests/simplCore/should_compile/all.T
- + testsuite/tests/th/T26862_th.script
- + testsuite/tests/th/T26862_th.stderr
- + testsuite/tests/th/T8306_th.script
- + testsuite/tests/th/T8306_th.stderr
- + testsuite/tests/th/T8306_th.stdout
- testsuite/tests/th/T8412.stderr
- + testsuite/tests/th/TH_EmptyLamCases.hs
- + testsuite/tests/th/TH_EmptyLamCases.stderr
- + testsuite/tests/th/TH_EmptyMultiIf.hs
- + testsuite/tests/th/TH_EmptyMultiIf.stderr
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/ExpansionQLIm.hs
- testsuite/tests/typecheck/should_compile/T14590.stderr
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_compile/valid_hole_fits.stderr
- testsuite/tests/typecheck/should_fail/DoExpansion1.stderr
- testsuite/tests/typecheck/should_fail/DoExpansion2.stderr
- testsuite/tests/typecheck/should_fail/T10971d.stderr
- testsuite/tests/typecheck/should_fail/T13311.stderr
- + testsuite/tests/typecheck/should_fail/T26861.hs
- + testsuite/tests/typecheck/should_fail/T26861.stderr
- + testsuite/tests/typecheck/should_fail/T26862.hs
- + testsuite/tests/typecheck/should_fail/T26862.stderr
- testsuite/tests/typecheck/should_fail/T3323.stderr
- testsuite/tests/typecheck/should_fail/T3613.stderr
- testsuite/tests/typecheck/should_fail/T6069.stderr
- testsuite/tests/typecheck/should_fail/T7851.stderr
- testsuite/tests/typecheck/should_fail/T7857.stderr
- testsuite/tests/typecheck/should_fail/T8306.stderr
- testsuite/tests/typecheck/should_fail/T8603.stderr
- testsuite/tests/typecheck/should_fail/T9612.stderr
- testsuite/tests/typecheck/should_fail/all.T
- testsuite/tests/typecheck/should_fail/tcfail102.stderr
- testsuite/tests/typecheck/should_fail/tcfail128.stderr
- testsuite/tests/typecheck/should_fail/tcfail140.stderr
- testsuite/tests/typecheck/should_fail/tcfail181.stderr
- testsuite/tests/unboxedsums/all.T
- + testsuite/tests/unboxedsums/unboxedsums4p.hs
- + testsuite/tests/unboxedsums/unboxedsums4p.stderr
- testsuite/tests/vdq-rta/should_compile/all.T
- + testsuite/tests/warnings/should_compile/SpecMultipleTysMono.hs
- + testsuite/tests/warnings/should_compile/SpecMultipleTysMono.stderr
- testsuite/tests/warnings/should_compile/all.T
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Parsers.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
- utils/genprimopcode/Main.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
- 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/Backends/Xhtml/Utils.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f9ab1b23f2e2611bfd0a2a5d6c5fd7…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f9ab1b23f2e2611bfd0a2a5d6c5fd7…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/ani/kill-SrcCodeOrigin] remove CtOrigin.ExpansionOrigin in favour of errCtxtCtOrigin, remove CtOrign...
by Apoorv Ingle (@ani) 08 Mar '26
by Apoorv Ingle (@ani) 08 Mar '26
08 Mar '26
Apoorv Ingle pushed to branch wip/ani/kill-SrcCodeOrigin at Glasgow Haskell Compiler / GHC
Commits:
f9ab1b23 by Apoorv Ingle at 2026-03-08T16:05:19-05:00
remove CtOrigin.ExpansionOrigin in favour of errCtxtCtOrigin, remove CtOrign from ErrMsgCtxt.FunTysCtxt
- - - - -
12 changed files:
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Types/Origin.hs-boot
- compiler/GHC/Tc/Utils/Unify.hs
Changes:
=====================================
compiler/GHC/Tc/Errors.hs
=====================================
@@ -83,7 +83,6 @@ import qualified GHC.Data.Strict as Strict
import Language.Haskell.Syntax.Basic (FieldLabelString(..))
-import Language.Haskell.Syntax (HsExpr (RecordUpd, HsGetField, HsProjection))
import Control.Monad ( when, foldM, forM_ )
import Data.Bifunctor ( bimap )
@@ -2778,10 +2777,6 @@ isHasFieldOrigin = \case
RecordUpdOrigin {} -> True
RecordFieldProjectionOrigin {} -> True
GetFieldOrigin {} -> True
- ExpansionOrigin (ExprCtxt e)
- | HsGetField{} <- e -> True
- | RecordUpd{} <- e -> True
- | HsProjection{} <- e -> True
_ -> False
-----------------------
=====================================
compiler/GHC/Tc/Errors/Ppr.hs
=====================================
@@ -7795,7 +7795,7 @@ pprErrCtxtMsg = \case
<+> text "is applied to too many arguments"
| otherwise
- -> empty
+ -> text "Debug" <+> vcat [ppr fun, ppr n_val_args, ppr res_fun, ppr res_env, ppr n_fun, ppr n_env]
where
not_fun ty -- ty is definitely not an arrow type,
-- and cannot conceivably become one
=====================================
compiler/GHC/Tc/Gen/App.hs
=====================================
@@ -907,10 +907,10 @@ tcInstFun do_ql inst_final ds_flag (fun_orig, rn_fun, fun_lspan) tc_fun fun_sigm
; return (mkScaled mult_ty arg_nu) }
- mk_herald :: HsExpr GhcTc -> HsExpr GhcRn -> CtOrigin
+ mk_herald :: HsExpr GhcTc -> HsExpr GhcRn -> ExpectedFunTyOrigin
mk_herald tc_fun arg
= case fun_orig of
- ExpansionOrigin (StmtErrCtxt{}) -> ExpectedTySyntax DoStmtOrigin arg
+ DoStmtOrigin -> ExpectedTySyntax DoStmtOrigin arg
_ -> ExpectedFunTyArg (HsExprTcThing tc_fun) arg
-- Is the argument supposed to instantiate a forall?
=====================================
compiler/GHC/Tc/Gen/Expr.hs
=====================================
@@ -1067,7 +1067,7 @@ tcSynArgE orig op sigma_ty syn_ty thing_inside
-- fixed RuntimeRep, as needed to call mkWpFun.
; return (result, match_wrapper <.> fun_wrap) }
where
- herald = ExpectedFunTySyntaxOp 1 orig op
+ herald = ExpectedFunTySyntaxOp orig op
go rho_ty (SynType the_ty)
= do { wrap <- tcSubTypePat orig GenSigCtxt the_ty rho_ty
@@ -1096,7 +1096,7 @@ tcSynArgA orig op sigma_ty arg_shapes res_shape thing_inside
thing_inside (arg_results ++ res_results) (map scaledMult arg_tys ++ arg_res_mults)
; return (result, match_wrapper, arg_wrappers, res_wrapper) }
where
- herald = ExpectedFunTySyntaxOp (length arg_shapes) orig op
+ herald = ExpectedFunTySyntaxOp orig op
tc_syn_args_e :: [TcSigmaTypeFRR] -> [SyntaxOpType]
-> ([TcSigmaTypeFRR] -> [Mult] -> TcM a)
@@ -1848,4 +1848,3 @@ checkMissingFields con_like rbinds arg_tys
field_strs = conLikeImplBangs con_like
fl `elemField` flds = any (\ fl' -> flSelector fl == fl') flds
-
=====================================
compiler/GHC/Tc/Gen/Head.hs
=====================================
@@ -465,7 +465,7 @@ tcInferAppHead_maybe fun = case fun of
-- visible type applications in the argument.
-- c.f. T19167
(\ (e, ds_flag, ty) -> (mkExpandedTc o e, ds_flag, ty)) <$>
- tcExprSigma False (ExpansionOrigin o) e
+ tcExprSigma False (errCtxtCtOrigin o) e
)
_ -> return Nothing
=====================================
compiler/GHC/Tc/Gen/Match.hs
=====================================
@@ -114,7 +114,7 @@ tcFunBindMatches ctxt fun_name mult matches invis_pat_tys exp_ty
= assertPpr (funBindPrecondition matches) (pprMatches matches) $
do { -- Check that they all have the same no of arguments
arity <- checkArgCounts matches
- ; let herald = ExpectedFunTyMatches arity (NameThing fun_name) matches
+ ; let herald = ExpectedFunTyMatches (NameThing fun_name) matches
; traceTc "tcFunBindMatches 1" (ppr fun_name $$ ppr mult $$ ppr exp_ty $$ ppr arity)
; (wrap_fun, r)
=====================================
compiler/GHC/Tc/Gen/Pat.hs
=====================================
@@ -703,7 +703,7 @@ tc_pat scaled_exp_pat_ty@(Scaled w_pat exp_pat_ty) penv ps_pat thing_inside =
-- 'view_expr' must be a function; expose its argument/result types
-- using 'matchActualFunTy'.
- ; let herald = ExpectedFunTyViewPat 1 $ unLoc view_expr
+ ; let herald = ExpectedFunTyViewPat $ unLoc view_expr
; (view_expr_co1, Scaled _mult view_arg_ty, view_res_ty)
<- matchActualFunTy herald (Just . HsExprRnThing $ unLoc view_expr)
(1, view_expr_rho) view_expr_rho
=====================================
compiler/GHC/Tc/Instance/Class.hs
=====================================
@@ -20,7 +20,7 @@ import GHC.Tc.Instance.Typeable
import GHC.Tc.Utils.TcMType
import GHC.Tc.Types.Evidence
import GHC.Tc.Types.CtLoc
-import GHC.Tc.Types.Origin ( InstanceWhat (..), SafeOverlapping, CtOrigin(ExpansionOrigin) )
+import GHC.Tc.Types.Origin ( InstanceWhat (..), SafeOverlapping, CtOrigin(GetFieldOrigin) )
import GHC.Tc.Instance.Family( tcGetFamInstEnvs, tcLookupDataFamInst, FamInstEnvs )
import GHC.Rename.Env( addUsedGRE, addUsedDataCons, DeprecationWarnings (..) )
@@ -1288,7 +1288,7 @@ warnIncompleteRecSel dflags sel_id ct_loc
-- GHC.Tc.Gen.App.tcInstFun arranges that the CtOrigin of (r.x) is GetFieldOrigin,
-- despite the expansion to (getField @"x" r)
- isGetFieldOrigin (ExpansionOrigin (ExprCtxt (HsGetField {}))) = True
+ isGetFieldOrigin GetFieldOrigin{} = True
isGetFieldOrigin _ = False
lookupHasFieldLabel
=====================================
compiler/GHC/Tc/Types/ErrCtxt.hs
=====================================
@@ -21,7 +21,7 @@ import GHC.Hs.Extension
import GHC.Parser.Annotation ( LocatedN, SrcSpanAnnA )
import GHC.Tc.Errors.Types.PromotionErr ( TermLevelUseCtxt )
-import {-# SOURCE #-} GHC.Tc.Types.Origin ( CtOrigin )
+import {-# SOURCE #-} GHC.Tc.Types.Origin ( CtOrigin, ExpectedFunTyOrigin )
import GHC.Tc.Utils.TcType ( TcType, TcTyCon, ExpType )
import GHC.Types.Basic ( TyConFlavour )
@@ -283,7 +283,7 @@ data ErrCtxtMsg
-- | In a function application.
| FunAppCtxt !FunAppCtxtFunArg !Int
-- | In a function call.
- | FunTysCtxt !CtOrigin !Type !Int !Int
+ | FunTysCtxt !ExpectedFunTyOrigin !Type !Int !Int
-- | In the result of a function call.
| FunResCtxt !(HsExpr GhcTc) !Int !Type !Type !Int !Int
-- | In the declaration of a type constructor.
=====================================
compiler/GHC/Tc/Types/Origin.hs
=====================================
@@ -9,9 +9,8 @@ module GHC.Tc.Types.Origin (
-- * CtOrigin
CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
- srcCodeOriginCtOrigin,
+ srcCodeOriginCtOrigin, errCtxtCtOrigin,
invisibleOrigin_maybe, isVisibleOrigin, toInvisibleOrigin,
- updatePositionCtOrigin,
pprCtOrigin, pprCtOriginBriefly, isGivenOrigin,
defaultReprEqOrigins, isWantedSuperclassOrigin,
ClsInstOrQC(..), NakedScFlag(..), NonLinearPatternReason(..),
@@ -37,7 +36,7 @@ module GHC.Tc.Types.Origin (
FRRArrowContext(..), pprFRRArrowContext,
-- ** ExpectedFunTy FixedRuntimeRepOrigin
- pprExpectedFunTyHerald,
+ ExpectedFunTyOrigin(..), pprExpectedFunTyOrigin, pprExpectedFunTyHerald,
-- * InstanceWhat
InstanceWhat(..), SafeOverlapping
@@ -511,72 +510,6 @@ data CtOrigin
| AmbiguityCheckOrigin UserTypeCtxt
| ImplicitLiftOrigin HsImplicitLiftSplice
- | ExpansionOrigin ErrCtxtMsg -- This is due to an expansion of the original thing given by the ErrCtxtMsg
-
- | ExpectedTySyntax !CtOrigin (HsExpr GhcRn)
-
- -- | A rebindable syntax operator is expected to have a function type.
- --
- -- Test cases for representation-polymorphism checks:
- -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
- | forall (p :: Pass)
- . (OutputableBndrId p)
- => ExpectedFunTySyntaxOp Int
- !CtOrigin !(HsExpr (GhcPass p))
- -- ^ rebindable syntax operator
-
- -- | A view pattern must have a function type.
- --
- -- Test cases for representation-polymorphism checks:
- -- RepPolyBinder
- | ExpectedFunTyViewPat Int
- !(HsExpr GhcRn)
- -- ^ function used in the view pattern
-
- -- | Need to be able to extract an argument type from a function type.
- --
- -- Test cases for representation-polymorphism checks:
- -- RepPolyApp
- | forall (p :: Pass)
- . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
- !TypedThing
- -- ^ function
- !(HsExpr (GhcPass p))
- -- ^ argument
-
- -- | Ensure that a function defined by equations indeed has a function type
- -- with the appropriate number of arguments.
- --
- -- Test cases for representation-polymorphism checks:
- -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
- | ExpectedFunTyMatches Int
- !TypedThing
- -- ^ name of the function
- !(MatchGroup GhcRn (LHsExpr GhcRn))
- -- ^ equations
-
- -- | Ensure that a lambda abstraction has a function type.
- --
- -- Test cases for representation-polymorphism checks:
- -- RepPolyLambda, RepPolyMatch
- | ExpectedFunTyLam HsLamVariant
- !(HsExpr GhcRn)
- -- ^ the entire lambda-case expression
-
- -- | A partial application of the constructor of a representation-polymorphic
- -- unlifted newtype in which the argument type does not have a fixed
- -- runtime representation.
- --
- -- Test cases: UnliftedNewtypesLevityBinder, UnliftedNewtypesCoerceFail.
- | FRRRepPolyUnliftedNewtype !DataCon
-
-
-updatePositionCtOrigin :: Int -> CtOrigin -> CtOrigin
-updatePositionCtOrigin i (ExpectedFunTySyntaxOp _ c e) = ExpectedFunTySyntaxOp i c e
-updatePositionCtOrigin i (ExpectedFunTyViewPat _ e) = ExpectedFunTyViewPat i e
-updatePositionCtOrigin i (ExpectedFunTyMatches _ t e) = ExpectedFunTyMatches i t e
-updatePositionCtOrigin _ c = c
-
data NonLinearPatternReason
= LazyPatternReason
@@ -678,18 +611,18 @@ exprCtOrigin (HsTypedBracket {}) = Shouldn'tHappenOrigin "TH typed bracket"
exprCtOrigin (HsUntypedBracket {}) = Shouldn'tHappenOrigin "TH untyped bracket"
exprCtOrigin (HsTypedSplice {}) = Shouldn'tHappenOrigin "TH typed splice"
exprCtOrigin (HsUntypedSplice {}) = Shouldn'tHappenOrigin "TH untyped splice"
-exprCtOrigin (HsProc {}) = Shouldn'tHappenOrigin "proc"
-exprCtOrigin (HsStatic {}) = Shouldn'tHappenOrigin "static expression"
-exprCtOrigin (HsEmbTy {}) = Shouldn'tHappenOrigin "type expression"
-exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression"
-exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
-exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
-exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
-exprCtOrigin e@(ExplicitList {}) = ExpansionOrigin (ExprCtxt e)
-exprCtOrigin e@(HsIf {}) = ExpansionOrigin (ExprCtxt e)
-exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (ExprCtxt e)
-exprCtOrigin e@(RecordUpd{}) = ExpansionOrigin (ExprCtxt e)
-exprCtOrigin e@(HsGetField{}) = ExpansionOrigin (ExprCtxt e)
+exprCtOrigin (HsProc {}) = Shouldn'tHappenOrigin "proc"
+exprCtOrigin (HsStatic {}) = Shouldn'tHappenOrigin "static expression"
+exprCtOrigin (HsEmbTy {}) = Shouldn'tHappenOrigin "type expression"
+exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression"
+exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
+exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
+exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
+exprCtOrigin (ExplicitList {}) = ListOrigin
+exprCtOrigin (HsIf {}) = IfThenElseOrigin
+exprCtOrigin (HsProjection _ p) = RecordFieldProjectionOrigin (FieldLabelStrings $ fmap noLocA p)
+exprCtOrigin (RecordUpd _ _ flds) = RecordUpdOrigin flds
+exprCtOrigin (HsGetField _ _ f) = GetFieldOrigin (fmap field_label $ dfoLabel (unLoc f))
exprCtOrigin (XExpr (ExpandedThingRn o _)) = errCtxtCtOrigin o
exprCtOrigin (XExpr (HsRecSelRn f)) = OccurrenceOfRecSel $ L (getLoc $ foLabel f) (foExt f)
@@ -734,31 +667,6 @@ pprCtOrigin :: CtOrigin -> SDoc
pprCtOrigin (GivenOrigin sk)
= ctoHerald <+> ppr sk
-pprCtOrigin (ExpansionOrigin o)
- = ctoHerald <+> what
- where
- what :: SDoc
- what = case o of
- StmtErrCtxt{} ->
- text "a do statement"
- DoStmtErrCtxt{} ->
- text "a do statement"
- StmtErrCtxtPat _ _ p ->
- text "a do statement" $$
- text "with the failable pattern" <+> quotes (ppr p)
- ExprCtxt (HsGetField _ _ (L _ f)) ->
- hsep [text "selecting the field", quotes (ppr f)]
- ExprCtxt (HsOverLabel _ l) ->
- hsep [text "the overloaded label" , quotes (char '#' <> ppr l)]
- ExprCtxt (RecordUpd{}) -> text "a record update"
- ExprCtxt (ExplicitList{}) -> text "an overloaded list"
- ExprCtxt (HsIf{}) -> text "an if-then-else expression"
- ExprCtxt (HsProjection _ p) -> text "the record selector" <+>
- quotes (ppr ((FieldLabelStrings $ fmap noLocA p)))
- ExprCtxt e -> text "the expression" <+> (ppr e)
- RecordUpdCtxt{} -> text "a record update"
- _ -> text "shouldn't happen ExpansionOrigin pprCtOrigin"
-
pprCtOrigin (GivenSCOrigin sk d blk)
= vcat [ ctoHerald <+> pprSkolInfo sk
, whenPprDebug (braces (text "given-sc:" <+> ppr d <> comma <> ppr blk)) ]
@@ -865,46 +773,9 @@ pprCtOrigin (NonLinearPatternOrigin reason pat)
= hang (ctoHerald <+> text "a non-linear pattern" <+> quotes (ppr pat))
2 (pprNonLinearPatternReason reason)
-pprCtOrigin (ExpectedTySyntax orig arg)
- = vcat [ text "The expression" <+> quotes (ppr arg)
- , nest 2 (ppr orig) ]
-
-pprCtOrigin (ExpectedFunTySyntaxOp i orig op) =
- vcat [ sep [ the_arg_of i
- , text "the rebindable syntax operator"
- , quotes (ppr op) ]
- , nest 2 (ppr orig) ]
-
-pprCtOrigin (ExpectedFunTyViewPat i expr) =
- vcat [ the_arg_of i <+> text "the view pattern"
- , nest 2 (ppr expr) ]
-pprCtOrigin (ExpectedFunTyArg fun arg) =
- sep [ text "The argument"
- , quotes (ppr arg)
- , text "of"
- , quotes (ppr fun) ]
-pprCtOrigin (ExpectedFunTyMatches i fun (MG { mg_alts = L _ alts }))
- | null alts
- = the_arg_of i <+> quotes (ppr fun)
- | otherwise
- = text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
- <+> text "for" <+> quotes (ppr fun)
-pprCtOrigin (ExpectedFunTyLam lam_variant _) = binder_of $ lamCaseKeyword lam_variant
-pprCtOrigin (FRRRepPolyUnliftedNewtype dc) =
- vcat [ text "Unsaturated use of a representation-polymorphic unlifted newtype."
- , text "The argument of the newtype constructor" <+> quotes (ppr dc) ]
-
pprCtOrigin simple_origin
= ctoHerald <+> pprCtOriginBriefly simple_origin
-the_arg_of :: Int -> SDoc
-the_arg_of i = text "The" <+> speakNth i <+> text "argument of"
-
-binder_of :: SDoc -> SDoc
-binder_of what = text "The binder of the" <+> what <+> text "expression"
-
-
-
-- | Print CtOrigin briefly, with a one-liner
pprCtOriginBriefly :: CtOrigin -> SDoc
pprCtOriginBriefly = ppr_br -- ppr_br is a local function with a short name!
@@ -976,22 +847,6 @@ ppr_br (InstanceSigOrigin {}) = text "a type signature in an instance"
ppr_br (AmbiguityCheckOrigin {}) = text "a type ambiguity check"
ppr_br (ImpedanceMatching {}) = text "combining required constraints"
ppr_br (NonLinearPatternOrigin _ pat) = hsep [text "a non-linear pattern" <+> quotes (ppr pat)]
-ppr_br (ExpansionOrigin (ExprCtxt (HsOverLabel _ l))) = hsep [text "the overloaded label", quotes (char '#' <> ppr l)]
-ppr_br (ExpansionOrigin (ExprCtxt (RecordUpd{}))) = text "a record update"
-ppr_br (ExpansionOrigin (ExprCtxt (ExplicitList{}))) = text "an overloaded list"
-ppr_br (ExpansionOrigin (ExprCtxt (HsIf{}))) = text "an if-then-else expression"
-ppr_br (ExpansionOrigin (ExprCtxt e)) = text "an expression" <+> ppr e
-ppr_br (ExpansionOrigin (StmtErrCtxt{})) = text "a do statement"
-ppr_br (ExpansionOrigin (StmtErrCtxtPat{})) = text "a do statement"
-ppr_br (ExpansionOrigin{}) = text "shouldn't happen ExpansionOrigin ppr_br"
-ppr_br (ExpectedTySyntax o _) = ppr_br o
-ppr_br (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator"
-ppr_br (ExpectedFunTyViewPat{}) = text "a view pattern"
-ppr_br (ExpectedFunTyArg{}) = text "a funtion head"
-ppr_br (ExpectedFunTyMatches{}) = text "a match statement"
-ppr_br (ExpectedFunTyLam{}) = text "a lambda expression"
-ppr_br (FRRRepPolyUnliftedNewtype{}) = text "a unlifted newtype"
-
pprNonLinearPatternReason :: HasDebugCallStack => NonLinearPatternReason -> SDoc
pprNonLinearPatternReason LazyPatternReason = parens (text "non-variable lazy pattern aren't linear")
@@ -1224,7 +1079,7 @@ data FixedRuntimeRepContext
--
-- See 'ExpectedFunTyOrigin' for more details.
| FRRExpectedFunTy
- !CtOrigin
+ !ExpectedFunTyOrigin
!Int
-- ^ argument position (1-indexed)
@@ -1311,7 +1166,7 @@ pprFixedRuntimeRepContext FRRBindStmtGuard
pprFixedRuntimeRepContext (FRRArrow arrowContext)
= pprFRRArrowContext arrowContext
pprFixedRuntimeRepContext (FRRExpectedFunTy funTyOrig _)
- = pprCtOrigin funTyOrig
+ = pprExpectedFunTyHerald funTyOrig
pprFixedRuntimeRepContext (FRRDeepSubsumption is_exp pos mb_fun)
= hsep [ text "The", what, text "type of the"
, ppr (Argument pos)
@@ -1537,15 +1392,136 @@ instance Outputable FRRArrowContext where
ppr = pprFRRArrowContext
-pprExpectedFunTyHerald :: CtOrigin -> SDoc
+{- *********************************************************************
+* *
+ FixedRuntimeRep: ExpectedFunTy origin
+* *
+********************************************************************* -}
+
+-- | In what context are we calling 'matchExpectedFunTys'
+-- or 'matchActualFunTy'?
+--
+-- Used for two things:
+--
+-- 1. Reporting error messages which explain that a function has been
+-- given an unexpected number of arguments.
+-- Uses 'pprExpectedFunTyHerald'.
+-- See Note [Herald for matchExpectedFunTys] in GHC.Tc.Utils.Unify.
+--
+-- 2. Reporting representation-polymorphism errors when a function argument
+-- doesn't have a fixed RuntimeRep as per Note [Fixed RuntimeRep]
+-- in GHC.Tc.Utils.Concrete.
+-- Uses 'pprExpectedFunTyOrigin'.
+-- See 'FixedRuntimeRepContext' for the situations in which
+-- representation-polymorphism checks are performed.
+data ExpectedFunTyOrigin
+
+ -- | A rebindable syntax operator is expected to have a function type.
+ --
+ -- Test cases for representation-polymorphism checks:
+ -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
+ = forall (p :: Pass)
+ . (OutputableBndrId p)
+ => ExpectedFunTySyntaxOp !CtOrigin !(HsExpr (GhcPass p))
+ -- ^ rebindable syntax operator
+
+ -- |
+ | ExpectedTySyntax !CtOrigin !(HsExpr GhcRn)
+
+ -- | A view pattern must have a function type.
+ --
+ -- Test cases for representation-polymorphism checks:
+ -- RepPolyBinder
+ | ExpectedFunTyViewPat
+ !(HsExpr GhcRn)
+ -- ^ function used in the view pattern
+
+ -- | Need to be able to extract an argument type from a function type.
+ --
+ -- Test cases for representation-polymorphism checks:
+ -- RepPolyApp
+ | forall (p :: Pass)
+ . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
+ !TypedThing
+ -- ^ function
+ !(HsExpr (GhcPass p))
+ -- ^ argument
+
+ -- | Ensure that a function defined by equations indeed has a function type
+ -- with the appropriate number of arguments.
+ --
+ -- Test cases for representation-polymorphism checks:
+ -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
+ | ExpectedFunTyMatches
+ !TypedThing
+ -- ^ name of the function
+ !(MatchGroup GhcRn (LHsExpr GhcRn))
+ -- ^ equations
+
+ -- | Ensure that a lambda abstraction has a function type.
+ --
+ -- Test cases for representation-polymorphism checks:
+ -- RepPolyLambda, RepPolyMatch
+ | ExpectedFunTyLam HsLamVariant
+ !(HsExpr GhcRn)
+ -- ^ the entire lambda-case expression
+
+ -- | A partial application of the constructor of a representation-polymorphic
+ -- unlifted newtype in which the argument type does not have a fixed
+ -- runtime representation.
+ --
+ -- Test cases: UnliftedNewtypesLevityBinder, UnliftedNewtypesCoerceFail.
+ | FRRRepPolyUnliftedNewtype !DataCon
+
+pprExpectedFunTyOrigin :: ExpectedFunTyOrigin
+ -> Int -- ^ argument position (starting at 1)
+ -> SDoc
+pprExpectedFunTyOrigin funTy_origin i =
+ case funTy_origin of
+ ExpectedFunTySyntaxOp orig op ->
+ vcat [ sep [ the_arg_of
+ , text "the rebindable syntax operator"
+ , quotes (ppr op) ]
+ , nest 2 (ppr orig) ]
+ ExpectedTySyntax orig arg ->
+ vcat [ text "the expression" <+> quotes (ppr arg)
+ , nest 2 (ppr orig) ]
+ ExpectedFunTyViewPat expr ->
+ vcat [ the_arg_of <+> text "the view pattern"
+ , nest 2 (ppr expr) ]
+ ExpectedFunTyArg fun arg ->
+ sep [ text "The argument"
+ , quotes (ppr arg)
+ , text "of"
+ , quotes (ppr fun) ]
+ ExpectedFunTyMatches fun (MG { mg_alts = L _ alts })
+ | null alts
+ -> the_arg_of <+> quotes (ppr fun)
+ | otherwise
+ -> text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
+ <+> text "for" <+> quotes (ppr fun)
+ ExpectedFunTyLam lam_variant _ -> binder_of $ lamCaseKeyword lam_variant
+ FRRRepPolyUnliftedNewtype dc ->
+ vcat [ text "Unsaturated use of a representation-polymorphic unlifted newtype."
+ , text "The argument of the newtype constructor" <+> quotes (ppr dc) ]
+ where
+ the_arg_of :: SDoc
+ the_arg_of = text "The" <+> speakNth i <+> text "argument of"
+
+ binder_of :: SDoc -> SDoc
+ binder_of what = text "The binder of the" <+> what <+> text "expression"
+
+pprExpectedFunTyHerald :: ExpectedFunTyOrigin -> SDoc
pprExpectedFunTyHerald (ExpectedFunTySyntaxOp {})
= text "This rebindable syntax expects a function with"
+pprExpectedFunTyHerald (ExpectedTySyntax orig _)
+ = pprCtOriginBriefly orig
pprExpectedFunTyHerald (ExpectedFunTyViewPat {})
= text "A view pattern expression expects"
pprExpectedFunTyHerald (ExpectedFunTyArg fun _)
= sep [ text "The function" <+> quotes (ppr fun)
, text "is applied to" ]
-pprExpectedFunTyHerald (ExpectedFunTyMatches _ fun (MG { mg_alts = L _ alts }))
+pprExpectedFunTyHerald (ExpectedFunTyMatches fun (MG { mg_alts = L _ alts }))
= text "The equation" <> plural alts <+> text "for" <+> quotes (ppr fun) <+> hasOrHave alts
pprExpectedFunTyHerald (ExpectedFunTyLam lam_variant expr)
= sep [ text "The" <+> lamCaseKeyword lam_variant <+> text "expression"
@@ -1554,7 +1530,6 @@ pprExpectedFunTyHerald (ExpectedFunTyLam lam_variant expr)
, text "has" ]
pprExpectedFunTyHerald (FRRRepPolyUnliftedNewtype dc)
= text "The unlifted newtype" <+> quotes (ppr dc) <+> text "expects"
-pprExpectedFunTyHerald orig = ppr (Shouldn'tHappenOrigin "pprExpectedFunTyHerald") <+> ppr orig
{- *******************************************************************
* *
=====================================
compiler/GHC/Tc/Types/Origin.hs-boot
=====================================
@@ -5,6 +5,7 @@ import GHC.Utils.Misc ( HasDebugCallStack )
import {-# SOURCE #-} GHC.Core.TyCo.Rep ( Type )
data CtOrigin
+data ExpectedFunTyOrigin
data SkolemInfoAnon
data SkolemInfo
data FixedRuntimeRepContext
=====================================
compiler/GHC/Tc/Utils/Unify.hs
=====================================
@@ -139,7 +139,7 @@ import Data.Traversable (for)
--
-- See Note [Return arguments with a fixed RuntimeRep].
matchActualFunTy
- :: CtOrigin
+ :: ExpectedFunTyOrigin
-- ^ See Note [Herald for matchExpectedFunTys]
-> Maybe TypedThing
-- ^ The thing with type TcSigmaType
@@ -178,7 +178,7 @@ matchActualFunTy herald mb_thing err_info fun_ty
go (FunTy { ft_af = af, ft_mult = w, ft_arg = arg_ty, ft_res = res_ty })
= assert (isVisibleFunArg af) $
- do { (arg_co, arg_ty) <- hasFixedRuntimeRep (FRRExpectedFunTy (updatePositionCtOrigin 1 herald) 1) arg_ty
+ do { (arg_co, arg_ty) <- hasFixedRuntimeRep (FRRExpectedFunTy herald 1) arg_ty
; let fun_co = mkFunCo Nominal af
(mkReflCo Nominal w)
arg_co
@@ -249,7 +249,7 @@ Ugh!
-- INVARIANT: the returned argument types all have a syntactically fixed RuntimeRep
-- in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.
-- See Note [Return arguments with a fixed RuntimeRep].
-matchActualFunTys :: CtOrigin -- ^ See Note [Herald for matchExpectedFunTys]
+matchActualFunTys :: ExpectedFunTyOrigin -- ^ See Note [Herald for matchExpectedFunTys]
-> CtOrigin
-> Arity
-> TcSigmaType
@@ -793,7 +793,7 @@ Example:
-- in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.
-- See Note [Return arguments with a fixed RuntimeRep].
matchExpectedFunTys :: forall a.
- CtOrigin -- See Note [Herald for matchExpectedFunTys]
+ ExpectedFunTyOrigin -- See Note [Herald for matchExpectedFunTys]
-> UserTypeCtxt
-> VisArity
-> ExpSigmaType
@@ -875,7 +875,7 @@ matchExpectedFunTys herald ctx arity (Check top_ty) thing_inside
, ft_arg = arg_ty, ft_res = res_ty })
= assert (isVisibleFunArg af) $
do { let arg_pos = arity - n_req + 1 -- 1 for the first argument etc
- ; (arg_co, arg_ty_frr) <- hasFixedRuntimeRep (FRRExpectedFunTy (updatePositionCtOrigin arg_pos herald) arg_pos) arg_ty
+ ; (arg_co, arg_ty_frr) <- hasFixedRuntimeRep (FRRExpectedFunTy herald arg_pos) arg_ty
; let scaled_arg_ty_frr = Scaled mult arg_ty_frr
; (res_wrap, result) <- check (n_req - 1)
(mkCheckExpFunPatTy scaled_arg_ty_frr : rev_pat_tys)
@@ -947,19 +947,19 @@ matchExpectedFunTys herald ctx arity (Check top_ty) thing_inside
; co <- unifyType Nothing (mkScaledFunTys more_arg_tys res_ty) fun_ty
; return (mkWpCastN co, result) }
-new_infer_arg_ty :: CtOrigin -> Int -> TcM (Scaled ExpRhoTypeFRR)
+new_infer_arg_ty :: ExpectedFunTyOrigin -> Int -> TcM (Scaled ExpRhoTypeFRR)
new_infer_arg_ty herald arg_pos -- position for error messages only
= do { mult <- newFlexiTyVarTy multiplicityTy
- ; inf_hole <- newInferExpTypeFRR IIF_DeepRho (FRRExpectedFunTy (updatePositionCtOrigin arg_pos herald) arg_pos)
+ ; inf_hole <- newInferExpTypeFRR IIF_DeepRho (FRRExpectedFunTy herald arg_pos)
; return (mkScaled mult inf_hole) }
-new_check_arg_ty :: CtOrigin -> Int -> TcM (Scaled TcType)
+new_check_arg_ty :: ExpectedFunTyOrigin -> Int -> TcM (Scaled TcType)
new_check_arg_ty herald arg_pos -- Position for error messages only, 1 for first arg
= do { mult <- newFlexiTyVarTy multiplicityTy
- ; arg_ty <- newOpenFlexiFRRTyVarTy (FRRExpectedFunTy (updatePositionCtOrigin arg_pos herald) arg_pos)
+ ; arg_ty <- newOpenFlexiFRRTyVarTy (FRRExpectedFunTy herald arg_pos)
; return (mkScaled mult arg_ty) }
-mkFunTysMsg :: CtOrigin
+mkFunTysMsg :: ExpectedFunTyOrigin
-> (VisArity, TcType)
-> ErrCtxtMsg
-- See Note [Reporting application arity errors]
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f9ab1b23f2e2611bfd0a2a5d6c5fd77…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f9ab1b23f2e2611bfd0a2a5d6c5fd77…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/andreask/ghc_par] Fix an issue with dependency analysis with boot files
by Andreas Klebinger (@AndreasK) 08 Mar '26
by Andreas Klebinger (@AndreasK) 08 Mar '26
08 Mar '26
Andreas Klebinger pushed to branch wip/andreask/ghc_par at Glasgow Haskell Compiler / GHC
Commits:
ec5be442 by Andreas Klebinger at 2026-03-08T17:53:50+00:00
Fix an issue with dependency analysis with boot files
- - - - -
1 changed file:
- compiler/GHC/Core/Opt/Split.hs
Changes:
=====================================
compiler/GHC/Core/Opt/Split.hs
=====================================
@@ -10,16 +10,18 @@ import GHC.Prelude hiding ( head, init, last )
import GHC.Core
import GHC.Core.FVs
import GHC.Core.Opt.OccurAnal (occurAnalyseCompUnit)
+import GHC.Core.Stats (coreBindsSize)
import GHC.Data.Graph.Directed (SCC(..), Node(..), stronglyConnCompFromEdgedVerticesUniq)
import GHC.Data.Maybe (orElse)
import GHC.Types.Unique.Set
-import GHC.Types.Name (isExternalName, nameModule)
-import GHC.Types.Id (realIdUnfolding)
+import GHC.Types.Name (Name, isExternalName, nameModule)
+import GHC.Types.Id (isDFunId, realIdUnfolding)
import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Types.Var
+import GHC.Types.Name.Env
import GHC.Utils.Outputable
import GHC.Utils.Panic
@@ -100,25 +102,40 @@ bindSplitFreeVars :: VarSet -> CoreBind -> VarSet
bindSplitFreeVars local_top_bndrs bind =
close_over_imported_unfoldings (bindMentionedVars bind `unionVarSet` bindBndrInfoVars bind)
where
+ local_name_env :: NameEnv Var
+ local_name_env = mkNameEnv [ (varName v, v) | v <- nonDetEltsUniqSet local_top_bndrs ]
+
close_over_imported_unfoldings fvs = go emptyVarSet fvs
go !seen !fvs =
case pick_new_import (fvs `minusVarSet` seen) of
Nothing -> fvs
Just v ->
- let unfolding_fvs = unfoldingRefs v
+ let unfolding_fvs = localizeLocalRefs (unfoldingRefs v)
local_unfolding_fvs = unfolding_fvs `intersectVarSet` local_top_bndrs
in go (extendVarSet seen v) (fvs `unionVarSet` local_unfolding_fvs `unionVarSet` unfolding_fvs)
pick_new_import vars =
find pickable (nonDetEltsUniqSet vars)
- pickable v = isId v && not (v `elemVarSet` local_top_bndrs)
+ pickable v = isId v && isDFunId v && not (v `elemVarSet` local_top_bndrs)
unfoldingRefs v =
- case maybeUnfoldingTemplate (realIdUnfolding v) of
- Just rhs -> exprSomeFreeVars (const True) rhs
- Nothing -> emptyVarSet
+ case realIdUnfolding v of
+ BootUnfolding -> emptyVarSet
+ unf ->
+ case maybeUnfoldingTemplate unf of
+ Just rhs -> exprSomeFreeVars (const True) rhs
+ Nothing -> emptyVarSet
+
+ localizeLocalRefs :: VarSet -> VarSet
+ localizeLocalRefs vars = mkVarSet (map localizeVar (nonDetEltsUniqSet vars))
+
+ localizeVar :: Var -> Var
+ localizeVar v =
+ case lookupNameEnv local_name_env (varName v) of
+ Just local_v -> local_v
+ Nothing -> v
bindMentionedVars :: CoreBind -> VarSet
bindMentionedVars (NonRec _ rhs) = exprSomeFreeVars (const True) rhs
@@ -219,8 +236,10 @@ pprVarWithModule v
splitCompUnit :: Module -> [CoreRule] -> CoreCompUnit -> ([CoreCompUnit], [CoreRule])
splitCompUnit this_module imp_rules unit
= let comp_units = map mk_comp_unit components_with_rules
- in checkNameClashes comp_units `seq`
- (comp_units, rules_for_imps ++ rules_without_component)
+ result = (comp_units, rules_for_imps ++ rules_without_component)
+ in -- pprTrace "CoreSplitTrace" (pprSplitTrace comp_units) $
+ checkNameClashes comp_units `seq`
+ result
where
CoreCompUnit occ_binds unit_rules =
occurAnalyseCompUnit this_module (const True) (const True) imp_rules unit
@@ -269,3 +288,24 @@ checkNameClashes comp_units
go seen (b:bs)
| b `elemVarSet` seen = b : go seen bs
| otherwise = go (extendVarSet seen b) bs
+
+pprSplitTrace :: [CoreCompUnit] -> SDoc
+pprSplitTrace comp_units =
+ text (show (length comp_units))
+ <+> text "Unit; CoreSizes:"
+ <+> pprIntList sizes
+ <> semi
+ <+> text "RelativeSize:"
+ <+> pprPercentList rel_sizes
+ where
+ sizes = map (coreBindsSize . coreCompUnitBinds) comp_units
+ total_size = sum sizes
+ rel_sizes
+ | total_size == 0 = replicate (length sizes) 0
+ | otherwise = map (\sz -> (100 * sz) `div` total_size) sizes
+
+pprIntList :: [Int] -> SDoc
+pprIntList xs = brackets (hcat (punctuate comma (map int xs)))
+
+pprPercentList :: [Int] -> SDoc
+pprPercentList xs = brackets (hcat (punctuate comma [ int x <> char '%' | x <- xs ]))
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ec5be4425b0ee8c19f4a817d36236bd…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ec5be4425b0ee8c19f4a817d36236bd…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
08 Mar '26
Simon Jakobi pushed new branch wip/sjakobi/T1216 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/T1216
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/sjakobi/regression-tests-3] Add regression test for #10381
by Simon Jakobi (@sjakobi2) 08 Mar '26
by Simon Jakobi (@sjakobi2) 08 Mar '26
08 Mar '26
Simon Jakobi pushed to branch wip/sjakobi/regression-tests-3 at Glasgow Haskell Compiler / GHC
Commits:
8490e918 by Simon Jakobi at 2026-03-08T17:44:55+01:00
Add regression test for #10381
Closes #10381.
- - - - -
2 changed files:
- + testsuite/tests/rebindable/T10381.hs
- testsuite/tests/rebindable/all.T
Changes:
=====================================
testsuite/tests/rebindable/T10381.hs
=====================================
@@ -0,0 +1,43 @@
+{-# LANGUAGE RebindableSyntax, RankNTypes #-}
+
+module T10381 where
+
+import Prelude ( String, undefined )
+
+newtype Cont r a = Cont { runCont :: (forall i. a i -> r) -> r }
+
+(>>=) :: Cont r a -> (forall i. a i -> Cont r b) -> Cont r b
+ma >>= fmb
+ = Cont (\k -> runCont ma (\a -> runCont (fmb a) k))
+
+fail :: String -> Cont r a
+fail = undefined
+
+return :: a i -> Cont r a
+return x = Cont (\k -> k x)
+
+foo :: Cont r []
+foo = do
+ bar <- foo
+ return bar
+
+{- Previously, GHC used to reject this program with:
+
+ Couldn't match type ‘i0’ with ‘i’
+ because type variable ‘i’ would escape its scope
+ This (rigid, skolem) type variable is bound by
+ a type expected by the context: [i] -> Cont r []
+ at Bug.hs:21:3-12
+ Expected type: Cont r [] -> ([i0] -> Cont r []) -> Cont r []
+ Actual type: Cont r []
+ -> (forall i. [i] -> Cont r []) -> Cont r []
+ In a stmt of a 'do' block: bar <- foo
+ In the expression:
+ do { bar <- foo;
+ return bar }
+ In an equation for ‘foo’:
+ foo
+ = do { bar <- foo;
+ return bar }
+-}
+
=====================================
testsuite/tests/rebindable/all.T
=====================================
@@ -35,6 +35,7 @@ test('T4851', normal, compile, [''])
test('T5908', normal, compile, [''])
test('T10112', normal, compile, [''])
+test('T10381', normal, compile, [''])
test('T11216', normal, compile, [''])
test('T11216A', normal, compile, [''])
test('T12080', normal, compile, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8490e91890ba3d4f5627edf6e4dbebe…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8490e91890ba3d4f5627edf6e4dbebe…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/romes/hadrian-cross-stage2-rebase_SVEN_FINAL] 5 commits: getTestExePath: Cleanup
by Sven Tennie (@supersven) 08 Mar '26
by Sven Tennie (@supersven) 08 Mar '26
08 Mar '26
Sven Tennie pushed to branch wip/romes/hadrian-cross-stage2-rebase_SVEN_FINAL at Glasgow Haskell Compiler / GHC
Commits:
2e1c0782 by Sven Tennie at 2026-03-08T11:18:20+00:00
getTestExePath: Cleanup
- - - - -
78f81994 by Sven Tennie at 2026-03-08T11:35:56+00:00
Delete obsolete comment
- - - - -
2c480368 by Sven Tennie at 2026-03-08T11:41:47+00:00
Rules.Test.testEnv: Improve diff
- - - - -
d12e83fa by Sven Tennie at 2026-03-08T11:48:01+00:00
includeCcArgs: Align with master
- - - - -
83e7dc2e by Sven Tennie at 2026-03-08T12:01:16+00:00
Move comment about mandatory static and cross
- - - - -
6 changed files:
- hadrian/src/Oracles/Flavour.hs
- hadrian/src/Oracles/TestSettings.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Test.hs
- hadrian/src/Settings/Builders/DeriveConstants.hs
- hadrian/src/Settings/Program.hs
Changes:
=====================================
hadrian/src/Oracles/Flavour.hs
=====================================
@@ -28,6 +28,8 @@ oracles = do
void $ addOracle $ \(DynGhcPrograms stage) -> do
cross <- crossStage stage
from_flavour <- flip dynamicGhcPrograms stage =<< flavour
+ -- Have to build static if it's a cross stage as we won't distribute the
+ -- libraries built for the host.
return (from_flavour && not cross)
void $ addOracle $ \(GhcProfiled stage) ->
ghcProfiled <$> flavour <*> pure (succStage stage)
=====================================
hadrian/src/Oracles/TestSettings.hs
=====================================
@@ -142,10 +142,9 @@ getTestCross testGhc =
Just stg -> crossStage stg
Nothing -> getBooleanSetting TestCrossCompiling
-
--- Given the testGhc string, either a stage0..stage1..stage2 etc or a path to
--- a compiler. Compute the absolute path to the relevant executable provided by
--- the package in the second argument.
+-- | Given the @testGhc@ `String` (either `stage1`, `stage2`, `stage3` or a
+-- path to a compiler). Compute the absolute path to the relevant executable
+-- provided by the package @pkg@ in the second argument.
getTestExePath :: String -> Package -> Action FilePath
getTestExePath testGhc pkg = do
case stageOfTestCompiler testGhc of
@@ -154,10 +153,8 @@ getTestExePath testGhc pkg = do
bindir <- getBinaryDirectory testGhc
compiler_path <- getCompilerPath testGhc
cross <- getBooleanSetting TestCrossCompiling
- let cross_prefix = if cross then dropWhileEnd ((/=) '-') (takeFileName compiler_path) else ""
- -- get relative path for the given program in the given stage
+ let cross_prefix = if cross then dropWhileEnd ('-' /=) (takeFileName compiler_path) else ""
let make_absolute rel_path = do
abs_path <- liftIO (makeAbsolute rel_path)
fixAbsolutePathOnWindows abs_path
make_absolute (bindir </> (cross_prefix ++ programBasename pkg) <.> exe)
- -- get relative path for the given program in the given stage
=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -526,7 +526,6 @@ generateConfigHs = do
stage <- getStage
let chooseSetting x y = case stage of { Stage0 {} -> x; _ -> y }
let queryTarget f = f <$> expr (targetStage stage)
- -- Not right for stage3
buildPlatform <- chooseSetting (queryBuild targetPlatformTriple) (queryHost targetPlatformTriple)
hostPlatform <- queryTarget targetPlatformTriple
trackGenerateHs
=====================================
hadrian/src/Rules/Test.hs
=====================================
@@ -197,18 +197,16 @@ testRules = do
testEnv :: Stage -> Action [(String, String)]
testEnv stg = do
-
testGhc <- testCompiler <$> userSetting defaultTestArgs
-
cross <- getTestCross testGhc
- prog_ghc_pkg <- getTestExePath testGhc ghcPkg
- prog_hsc2hs <- getTestExePath testGhc hsc2hs
- prog_hp2ps <- getTestExePath testGhc hp2ps
- prog_haddock <- getTestExePath testGhc haddock
- prog_hpc <- getTestExePath testGhc hpc
- prog_runghc <- getTestExePath testGhc runGhc
makePath <- builderPath $ Make ""
+ prog_ghc_pkg <- getTestExePath testGhc ghcPkg
+ prog_hsc2hs <- getTestExePath testGhc hsc2hs
+ prog_hp2ps <- getTestExePath testGhc hp2ps
+ prog_haddock <- getTestExePath testGhc haddock
+ prog_hpc <- getTestExePath testGhc hpc
+ prog_runghc <- getTestExePath testGhc runGhc
root <- buildRoot
args <- userSetting defaultTestArgs
=====================================
hadrian/src/Settings/Builders/DeriveConstants.hs
=====================================
@@ -48,4 +48,4 @@ includeCcArgs = do
, arg "-Irts/include"
, arg $ "-I" ++ rtsPath </> "include"
, notM (targetSupportsSMP stage) ? arg "-DNOSMP"
- , arg "-fcommon" ]
+ ]
=====================================
hadrian/src/Settings/Program.hs
=====================================
@@ -19,11 +19,10 @@ programContext :: Stage -> Package -> Action Context
programContext stage pkg = do
profiled <- askGhcProfiled stage
dynGhcProgs <- askDynGhcPrograms stage
- -- Have to build static if it's a cross stage as we won't distribute the libraries built for the host.
return $ Context stage pkg (wayFor profiled dynGhcProgs) Final
where wayFor prof dyn
- | prof && dyn = profilingDynamic
+ | prof && dyn = profilingDynamic
| pkg == ghc && prof && notStage0 stage = profiling
| dyn && notStage0 stage = dynamic
| otherwise = vanilla
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0ccee36aebfd046affa9d124aa87c8…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0ccee36aebfd046affa9d124aa87c8…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/andreask/ghc_par] 9 commits: Refactored splitting.
by Andreas Klebinger (@AndreasK) 08 Mar '26
by Andreas Klebinger (@AndreasK) 08 Mar '26
08 Mar '26
Andreas Klebinger pushed to branch wip/andreask/ghc_par at Glasgow Haskell Compiler / GHC
Commits:
cde2e390 by Andreas Klebinger at 2026-03-07T13:39:29+00:00
Refactored splitting.
Broke it into parts to make it easier to understand.
- - - - -
82d089c0 by Andreas Klebinger at 2026-03-07T16:48:25+00:00
Make sure CoreMerge reattaches unstable unfoldings
- - - - -
8de36fbf by Andreas Klebinger at 2026-03-07T21:14:07+00:00
testsuite: Ignore compilation unit header in output comparison
- - - - -
775a5b9f by Andreas Klebinger at 2026-03-07T21:50:09+00:00
Some useless checks
- - - - -
dd3df12c by Andreas Klebinger at 2026-03-07T22:57:33+00:00
Possible fixes to simplifier/specConstr from the bot
- - - - -
5527b495 by Andreas Klebinger at 2026-03-08T09:29:51+00:00
merge/split around late cse
- - - - -
15a3537c by Andreas Klebinger at 2026-03-08T09:35:41+00:00
Make CSE work independently over compilation units
- - - - -
e02db7ea by Andreas Klebinger at 2026-03-08T10:00:25+00:00
Keep rules attributed to units in the simplifier
- - - - -
08faa984 by Andreas Klebinger at 2026-03-08T13:42:08+00:00
Some vibe based fixes
- - - - -
12 changed files:
- compiler/GHC/Core/Opt/CSE.hs
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/Specialise.hs
- + compiler/GHC/Core/Opt/Split.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/Subst.hs
- compiler/ghc.cabal.in
- testsuite/driver/testlib.py
Changes:
=====================================
compiler/GHC/Core/Opt/CSE.hs
=====================================
@@ -380,18 +380,18 @@ body/rest of the module.
-}
cseProgram :: CoreProgram -> CoreProgram
-cseProgram comp_units
- = snd (mapAccumL cse_comp_unit init_env comp_units)
+cseProgram = map cseCoreCompUnit
+
+cseCoreCompUnit :: CoreCompUnit -> CoreCompUnit
+cseCoreCompUnit (CoreCompUnit unit_binds unit_rules)
+ = CoreCompUnit binds' unit_rules
where
- init_env = emptyCSEnv $
- mkInScopeSetList (bindersOfBinds (concatMap coreCompUnitBinds comp_units))
- -- Put all top-level binders into scope; it is possible to have
- -- forward references. See Note [Glomming] in GHC.Core.Opt.OccurAnal
- -- Missing this caused #25468
-
- cse_comp_unit env (CoreCompUnit binds unit_rules)
- = let (env', binds') = mapAccumL (cseBind TopLevel) env binds
- in (env', CoreCompUnit binds' unit_rules)
+ init_env = emptyCSEnv $
+ mkInScopeSetList (bindersOfBinds unit_binds)
+ -- Put all top-level binders in this compilation unit into
+ -- scope; it is possible to have forward references.
+ -- See Note [Glomming] in GHC.Core.Opt.OccurAnal.
+ (_env', binds') = mapAccumL (cseBind TopLevel) init_env unit_binds
cseBind :: TopLevelFlag -> CSEnv -> CoreBind -> (CSEnv, CoreBind)
cseBind toplevel env (NonRec b e)
=====================================
compiler/GHC/Core/Opt/Monad.hs
=====================================
@@ -16,7 +16,7 @@ module GHC.Core.Opt.Monad (
-- ** Reading from the monad
getModule,
- initRuleEnv, getExternalRuleBase,
+ initRuleEnv, getHomeRuleBase, getExternalRuleBase,
getDynFlags, getPackageFamInstEnv,
getInteractiveContext,
getUniqTag,
=====================================
compiler/GHC/Core/Opt/OccurAnal.hs
=====================================
@@ -28,7 +28,6 @@ core expression with (hopefully) improved usage information.
module GHC.Core.Opt.OccurAnal (
occurAnalysePgm,
occurAnalyseCompUnit,
- occurSplitPgm,
occurAnalyseExpr, occurAnalyseExpr_Prep,
zapLambdaBndrs
) where
@@ -57,7 +56,6 @@ import GHC.Types.Id.Info
import GHC.Types.InlinePragma ( ActivationGhc, isAlwaysActive )
import GHC.Types.Basic
import GHC.Types.Tickish
-import GHC.Types.Name (isExternalName, nameModule)
import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Types.Var
@@ -70,14 +68,12 @@ import GHC.Utils.Misc
import GHC.Builtin.Names( runRWKey )
import GHC.Unit.Module( Module )
-import qualified Data.IntMap.Strict as IntMap
-import qualified Data.IntSet as IntSet
import Data.List (mapAccumL)
{-
************************************************************************
* *
- occurAnalysePgm, occurAnalyseExpr, occurSplitPgm
+ occurAnalysePgm, occurAnalyseExpr
* *
************************************************************************
@@ -99,140 +95,6 @@ occurAnalyseExpr_Prep expr = expr'
where
WUD _ expr' = occAnal (initOccEnv { occ_allow_weak_joins = True }) expr
--- After optimizations a rule might no longer reference binders from this module.
--- In these cases we return them here and then add them to mg_rules.
-occurSplitPgm :: Module -> [CoreRule] -> CoreCompUnit -> ([CoreCompUnit], [CoreRule])
-occurSplitPgm mod imp_rules (CoreCompUnit unit_binds unit_rules)
- =
- -- pprTrace "occurSplitPgm"
- -- ( vcat [
- -- text "imp",
- -- ppr imp_rules,
- -- text "unit",
- -- ppr (unit_rules, unit_binds)
- -- ]
- -- )
- (zipWith mk_comp_unit comp_pairs [0..], rules_for_imps)
- where
- CoreCompUnit occ_binds _ =
- occurAnalyseCompUnit mod (const True) (const True) imp_rules
- (CoreCompUnit unit_binds unit_rules)
-
- pairs = flattenBinds occ_binds
- bndrs = map fst pairs
- bndr_set = mkVarSet bndrs
-
- imp_rule_edges :: ImpRuleEdges
- imp_rule_edges = mkImpRuleEdges imp_rules
-
- -- If a unit rule mentions multiple local binders, they must end up in
- -- the same component; otherwise the rule cannot be attached to any one
- -- split unit without creating cross-unit references.
- rule_fv_edges :: IdEnv VarSet
- rule_fv_edges
- = foldr (plusVarEnv_C unionVarSet) emptyVarEnv
- [ mapVarEnv (const local_rule_fvs) (getUniqSet local_rule_fvs)
- | rule <- unit_rules
- , let local_rule_fvs = ruleFreeVars rule `intersectVarSet` bndr_set
- ]
-
- dir_nodes :: [Node Unique (Id, CoreExpr)]
- dir_nodes = map mk_dir_node pairs
-
- mk_dir_node (bndr, rhs)
- = DigraphNode { node_payload = (bndr, rhs)
- , node_key = varUnique bndr
- , node_dependencies = nonDetKeysUniqSet deps
- }
- where
- deps = traced_fvs `intersectVarSet` bndr_set
-
- traced_fvs = -- pprTrace "occurSplitPgm: binder fvs before unit assignment"
- -- (ppr bndr $$ text "fvs:" <+> ppr dep_fvs)
- dep_fvs
-
- dep_fvs = exprFreeIds rhs
- `unionVarSet` bndrRuleAndUnfoldingIds bndr
- `unionVarSet` localRuleDeps bndr
- `unionVarSet` impRuleDeps bndr
-
- impRuleDeps b = foldr unionVarSet emptyVarSet [ vs | (_, vs) <- lookupImpRules imp_rule_edges b ]
-
- localRuleDeps b = lookupVarEnv rule_fv_edges b `orElse` emptyVarSet
-
- incoming_edges :: UniqFM Unique [Unique]
- incoming_edges = foldr add_incoming emptyUFM dir_nodes
- where
- add_incoming DigraphNode { node_key = src, node_dependencies = dests } incoming
- = foldr (\dest acc -> addToUFM_C (++) acc dest [src]) incoming dests
- -- TODO: AI Garbage? -
- -- We probably really should just do this on a undirected graph instead.
- undir_nodes :: [Node Unique (Id, CoreExpr)]
- undir_nodes =
- [ node { node_dependencies = node_dependencies node ++ lookupWithDefaultUFM incoming_edges [] (node_key node) }
- | node <- dir_nodes
- ]
-
- comp_pairs :: [[(Id, CoreExpr)]]
- comp_pairs = map scc_payloads (stronglyConnCompFromEdgedVerticesUniq undir_nodes)
-
- component_bndrs :: [[Id]]
- component_bndrs = map (map fst) comp_pairs
-
- mk_comp_unit prs i = CoreCompUnit (mk_comp_binds prs) (component_rules i)
-
- mk_comp_binds [pr] = [NonRec (fst pr) (snd pr)]
- mk_comp_binds prs = [Rec prs]
-
- (component_rule_map, rules_for_imps) = foldr assign_rule (IntMap.empty, []) unit_rules
-
- assign_rule rule (rule_map, imp_rules_acc)
- = case rule_comp_index rule of
- Just i -> (IntMap.insertWith (++) i [rule] rule_map, imp_rules_acc)
- Nothing -> (rule_map, rule : imp_rules_acc)
-
- component_rules i = IntMap.findWithDefault [] i component_rule_map
-
- rule_comp_index rule
- = case rule_component_indices of
- [i] -> Just i
- [] -> Nothing
- is -> pprPanic "occurSplitPgm"
- (text "Rule free vars span multiple components"
- $$ text "rule:" <+> ppr rule
- $$ text "components:" <+> ppr is
- $$ text "rule_fvs:" <+> pprVarsWithModule (nonDetEltsUniqSet rule_fvs)
- $$ vcat [ text "component" <+> int i <> colon <+> ppr hits
- | (i, hits) <- component_hits ])
- where
- rule_component_indices :: [Int]
- rule_component_indices = IntSet.toList $ IntSet.fromList
- [ i
- | (ids, i) <- zip component_bndrs [0..]
- , not (isEmptyVarSet (local_rule_fvs `intersectVarSet` mkVarSet ids))
- ]
-
- rule_fvs = ruleFreeVars rule
- local_rule_fvs = rule_fvs `intersectVarSet` bndr_set
- component_hits =
- [ (i, local_rule_fvs `intersectVarSet` mkVarSet ids)
- | (ids, i) <- zip component_bndrs [0..]
- , not (isEmptyVarSet (local_rule_fvs `intersectVarSet` mkVarSet ids))
- ]
-
- scc_payloads (AcyclicSCC p) = [p]
- scc_payloads (CyclicSCC ps) = ps
-
- pprVarsWithModule :: [Var] -> SDoc
- pprVarsWithModule vars = braces (fsep (punctuate comma (map pprVarWithModule vars)))
-
- pprVarWithModule :: Var -> SDoc
- pprVarWithModule v
- | isExternalName n = ppr v <+> parens (ppr (nameModule n))
- | otherwise = ppr v
- where
- n = varName v
-
occurAnalyseCompUnit
:: Module
-> (Id -> Bool)
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -14,7 +14,7 @@ import GHC.Driver.DynFlags
import GHC.Driver.Plugins ( withPlugins, installCoreToDos )
import GHC.Driver.Env
import GHC.Driver.Config (initSimpleOpts)
-import GHC.Driver.Config.Core.Lint ( endPass )
+import GHC.Driver.Config.Core.Lint ( endPass, initLintConfig )
import GHC.Driver.Config.Core.Opt.LiberateCase ( initLiberateCaseOpts )
import GHC.Driver.Config.Core.Opt.Simplify ( initSimplifyOpts, initSimplMode, initGentleSimplMode )
import GHC.Driver.Config.Core.Opt.WorkWrap ( initWorkWrapOpts )
@@ -22,12 +22,12 @@ import GHC.Driver.Config.Core.Rules ( initRuleOpts )
import GHC.Platform.Ways ( hasWay, Way(WayProf) )
import GHC.Core
-import GHC.Core.SimpleOpt (simpleOptPgm)
+import GHC.Core.SimpleOpt (simpleOptPgm, defaultSimpleOpts, so_inline, so_uf_opts)
import GHC.Core.Opt.CSE ( cseProgram )
import GHC.Core.Rules ( RuleBase, ruleCheckProgram, getRules )
import GHC.Core.Ppr ( pprCoreProgram, pprRules )
import GHC.Core.Utils ( dumpIdInfoOfProgram )
-import GHC.Core.Lint ( lintAnnots )
+import GHC.Core.Lint ( lintAnnots, lintCoreProgram', displayLintResults )
import GHC.Core.Lint.Interactive ( interactiveInScope )
import GHC.Core.Opt.Simplify ( simplifyExpr, simplifyPgm )
import GHC.Core.Opt.Simplify.Monad
@@ -43,7 +43,7 @@ import GHC.Core.Opt.DmdAnal
import GHC.Core.Opt.CprAnal ( cprAnalProgram )
import GHC.Core.Opt.CallArity ( callArityAnalProgram )
import GHC.Core.Opt.Exitify ( exitifyProgram )
-import GHC.Core.Opt.OccurAnal ( occurSplitPgm )
+import GHC.Core.Opt.Split ( splitCompUnit, checkNameClashes )
import GHC.Core.Opt.WorkWrap ( wwTopBinds )
import GHC.Core.Opt.CallerCC ( addCallerCostCentres )
import GHC.Core.LateCC.TopLevelBinds (topLevelBindsCCMG)
@@ -320,7 +320,11 @@ getCoreToDo dflags hpt_rule_base extra_vars
-- in wheel-sieve1), and I'm guessing that SpecConstr can too
-- And CSE is a very cheap pass. So it seems worth doing here.
runWhen ((liberate_case || spec_constr) && cse) $ CoreDoPasses
- [ CoreCSE, simplify "post-final-cse" ],
+ [ runWhen split_core CoreMerge
+ , CoreCSE
+ , runWhen split_core CoreSplit
+ , simplify "post-final-cse"
+ ],
--------- End of -O2 passes --------------
@@ -457,6 +461,7 @@ doCorePass pass guts = do
dflags <- getDynFlags
us <- getUniqueSupplyM
p_fam_env <- getPackageFamInstEnv
+ let extra_vars = interactiveInScope (hsc_IC 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) }
@@ -478,14 +483,16 @@ doCorePass pass guts = do
updateBindsAndRulesM (desugarOpt dflags logger (mg_module guts))
CoreSplit -> {-# SCC "CoreSplit" #-}
- do { let split_res = map (occurSplitPgm (mg_module guts) (mg_rules guts)) (mg_binds guts)
+ do { let split_res = map (splitCompUnit (mg_module guts) (mg_rules guts)) (mg_binds guts)
binds' = concatMap fst split_res
rules' = mg_rules guts ++ concatMap snd split_res
; return guts { mg_binds = binds', mg_rules = rules' } }
CoreMerge -> {-# SCC "CoreMerge" #-}
do { let binds_before = mg_binds guts
+ _ = checkNameClashes binds_before
binds_after = flattenCoreProgram binds_before
+ _ = checkNameClashes binds_after
; liftIO $
Logger.putDumpFileMaybe logger Opt_D_dump_split_core
"Core before merge"
@@ -497,7 +504,33 @@ doCorePass pass guts = do
"Core after merge"
FormatCore
(pprCoreProgram binds_after)
- ; return $ guts { mg_binds = binds_after } }
+ ; liftIO $ do
+ let warns_and_errs = lintCoreProgram'
+ (initLintConfig dflags extra_vars)
+ binds_after
+ (mg_rules guts)
+ True
+ displayLintResults logger
+ (text "CoreMerge after flattenCoreProgram")
+ (pprCoreProgram binds_after)
+ warns_and_errs
+ ; let minimal_things = defaultSimpleOpts
+ { so_inline = False
+ , so_uf_opts = unfoldingOpts dflags }
+ (binds_w_unfolds, rules_for_imps, occ_anald_binds) = simpleOptPgm
+ minimal_things
+ (mg_module guts)
+ binds_after
+ (mg_rules guts)
+ _ = checkNameClashes binds_w_unfolds
+ ; liftIO $
+ Logger.putDumpFileMaybe logger Opt_D_dump_split_core
+ "Core after re-attaching unfolds"
+ FormatCore
+ (pprCoreProgram occ_anald_binds)
+
+ ; return $ guts { mg_binds = binds_w_unfolds
+ , mg_rules = rules_for_imps } }
CoreDoSimplify opts -> {-# SCC "Simplify" #-}
liftIOWithCount $ simplifyPgm logger (hsc_unit_env hsc_env) name_ppr_ctx opts guts
=====================================
compiler/GHC/Core/Opt/Simplify.hs
=====================================
@@ -10,6 +10,7 @@ import GHC.Prelude
import GHC.Driver.Flags
import GHC.Core
+import GHC.Core.FVs (ruleFreeVars)
import GHC.Core.Rules
import GHC.Core.Ppr ( pprCoreBindings, pprCoreExpr )
import GHC.Core.Opt.OccurAnal ( occurAnalysePgm, occurAnalyseExpr )
@@ -38,10 +39,10 @@ import GHC.Unit.Module.ModGuts
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Types.InlinePragma
-import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Types.Tickish
import GHC.Types.Unique.FM
+import GHC.Types.Var.Set
import Control.Monad
import Data.Foldable ( for_ )
@@ -240,7 +241,7 @@ simplifyPgm' logger unit_env name_ppr_ctx opts
-- number of iterations we actually completed
return ( "Simplifier bailed out", iteration_no - 1
, totalise counts_so_far
- , dyn_no_binds { dsd_binds = [CoreCompUnit bind_list unit_rules], dsd_rules = local_rules } )
+ , dyn_no_binds { dsd_binds = binds, dsd_rules = local_rules } )
-- Try and force thunks off the binds; significantly reduces
-- space usage, especially with -O. JRS, 000620.
@@ -271,38 +272,19 @@ simplifyPgm' logger unit_env name_ppr_ctx opts
-- (b) local rules (substituted), including unit rules from `binds`
-- Forcing base_rule_env to avoid unnecessary allocations.
-- Not doing so results in +25.6% allocations of LargeRecord.
- ; !base_rule_env = updLocalRules hpt_rule_env (local_rules ++ unit_rules)
-
- ; read_eps_rules :: IO PackageRuleBase
- ; read_eps_rules = eps_rule_base <$> ueEPS unit_env
-
- ; read_rule_env :: IO RuleEnv
- ; read_rule_env = updExternalPackageRules base_rule_env <$> read_eps_rules
-
; fam_envs = (eps_fam_inst_env eps, fam_inst_env)
; simpl_env = mkSimplEnv mode fam_envs } ;
- -- Simplify the program
- ((binds1, rules1, unit_rules1), counts1) <-
- initSmpl logger read_rule_env top_env_cfg sz $
- do { (floats, env1) <- {-# SCC "SimplTopBinds" #-}
- simplTopBinds simpl_env tagged_bind_list
-
- -- Apply the substitution to rules defined in this module
- -- for imported Ids. Eg RULE map my_f = blah
- -- If we have a substitution my_f :-> other_f, we'd better
- -- apply it to the rule to, or it'll never match
- ; rules1 <- simplImpRules env1 local_rules
- ; unit_rules1 <- simplImpRules env1 unit_rules
-
- ; return (getTopFloatBinds floats, rules1, unit_rules1) } ;
+ -- Simplify each compilation unit independently
+ ((binds1, rules1), counts1) <-
+ simpl_comp_units simpl_env local_rules tagged_binds sz ;
-- Stop if nothing happened; don't dump output
-- See Note [Which transformations are innocuous] in GHC.Core.Opt.Stats
if isZeroSimplCount counts1 then
return ( "Simplifier reached fixed point", iteration_no
, totalise (counts1 : counts_so_far) -- Include "free" ticks
- , dyn_no_binds { dsd_binds = [CoreCompUnit binds1 unit_rules1], dsd_rules = rules1 } )
+ , dyn_no_binds { dsd_binds = binds1, dsd_rules = rules1 } )
else do {
-- Short out indirections
-- We do this *after* at least one run of the simplifier
@@ -312,26 +294,77 @@ simplifyPgm' logger unit_env name_ppr_ctx opts
--
-- ToDo: alas, this means that indirection-shorting does not happen at all
-- if the simplifier does nothing (not common, I know, but unsavoury)
- let { binds2 = {-# SCC "ZapInd" #-} shortOutIndirections binds1 } ;
+ let { binds2 = {-# SCC "ZapInd" #-}
+ [ CoreCompUnit (shortOutIndirections unit_binds) unit_rules'
+ | CoreCompUnit unit_binds unit_rules' <- binds1 ] } ;
-- Dump the result of this iteration
dump_end_iteration logger dump_core_sizes name_ppr_ctx iteration_no counts1
- [CoreCompUnit binds2 unit_rules1] rules1 ;
+ binds2 rules1 ;
for_ (so_pass_result_cfg opts) $ \pass_result_cfg ->
- lintPassResult logger pass_result_cfg [CoreCompUnit binds2 unit_rules1] rules1 ;
+ lintPassResult logger pass_result_cfg binds2 rules1 ;
-- Loop
- do_iteration (iteration_no + 1) (counts1:counts_so_far) [CoreCompUnit binds2 unit_rules1] rules1
+ do_iteration (iteration_no + 1) (counts1:counts_so_far) binds2 rules1
} }
where
bind_list = concatMap coreCompUnitBinds binds
- unit_rules = concatMap cu_rules binds
-- Remember the counts_so_far are reversed
totalise :: [SimplCount] -> SimplCount
totalise = foldr (\c acc -> acc `plusSimplCount` c)
(zeroSimplCount $ logHasDumpFlag logger Opt_D_dump_simpl_stats)
+ -- Keep top-level in-scope sets per-unit until CoreMerge.
+ simpl_comp_units
+ :: SimplEnv
+ -> [CoreRule]
+ -> CoreProgram
+ -> Int
+ -> IO ((CoreProgram, [CoreRule]), SimplCount)
+ simpl_comp_units simpl_env rules0 units0 sz = go rules0 [] zero_counts units0
+ where
+ zero_counts = zeroSimplCount $ logHasDumpFlag logger Opt_D_dump_simpl_stats
+
+ go !rules acc !counts [] = return ((reverse acc, rules), counts)
+ go !rules acc !counts (CoreCompUnit unit_binds unit_rules' : rest) = do
+ let unit_bndrs = mkVarSet (bindersOfBinds unit_binds)
+ (visible_rules, hidden_rules) = partitionVisibleImpRules unit_bndrs rules
+ !base_rule_env = updLocalRules hpt_rule_env (visible_rules ++ unit_rules')
+ read_eps_rules = eps_rule_base <$> ueEPS unit_env
+ read_rule_env = updExternalPackageRules base_rule_env <$> read_eps_rules
+
+ ((unit1, visible_rules1), counts1) <-
+ initSmpl logger read_rule_env top_env_cfg sz $ do
+ (floats, env1) <- {-# SCC "SimplTopBindsUnit" #-}
+ simplTopBinds simpl_env unit_binds
+
+ -- Apply substitutions from this unit to imported-head rules and
+ -- the unit's own rules. Keep each unit's local rules separate.
+ visible_rules1 <- simplImpRules env1 visible_rules
+ unit_rules1 <- simplImpRules env1 unit_rules'
+
+ let unit_binds1 = getTopFloatBinds floats
+ pure (CoreCompUnit unit_binds1 unit_rules1, visible_rules1)
+
+ let rules1 = visible_rules1 ++ hidden_rules
+ go rules1 (unit1 : acc) (counts `plusSimplCount` counts1) rest
+
+ partitionVisibleImpRules :: VarSet -> [CoreRule] -> ([CoreRule], [CoreRule])
+ partitionVisibleImpRules unit_bndrs = foldr go_rule ([], [])
+ where
+ go_rule rule (visible, hidden)
+ | rule_mentions_unit = (rule : visible, hidden)
+ | rule_has_local_fvs = (visible, rule : hidden)
+ | otherwise = (rule : visible, hidden)
+ where
+ local_fvs = ruleFreeVars rule `intersectVarSet` all_local_bndrs
+ rule_has_local_fvs = not (isEmptyVarSet local_fvs)
+ rule_mentions_unit = not (isEmptyVarSet (local_fvs `intersectVarSet` unit_bndrs))
+
+ all_local_bndrs :: VarSet
+ all_local_bndrs = mkVarSet (bindersOfBinds (concatMap coreCompUnitBinds (dsd_binds dyn)))
+
dump_end_iteration :: Logger -> Bool -> NamePprCtx -> Int
-> SimplCount -> CoreProgram -> [CoreRule] -> IO ()
dump_end_iteration logger dump_core_sizes name_ppr_ctx iteration_no counts binds rules
=====================================
compiler/GHC/Core/Opt/SpecConstr.hs
=====================================
@@ -794,9 +794,12 @@ specConstrProgram guts
scTopCompUnits :: ScEnv -> CoreProgram -> UniqSM (ScUsage, CoreProgram, [SpecFailWarning])
scTopCompUnits _env [] = return (nullUsage, [], [])
scTopCompUnits env (CoreCompUnit unit_binds unit_rules:units) = do
- (unit_usg, unit_binds', unit_warnings) <- scTopBinds env unit_binds
- (units_usg, units', units_warnings) <- scTopCompUnits env units
- return (unit_usg `combineUsage` units_usg, CoreCompUnit unit_binds' unit_rules : units', unit_warnings ++ units_warnings)
+ let unit_env = initScCompUnitEnv env unit_binds
+ (_unit_usg, unit_binds', unit_warnings) <- scTopBinds unit_env unit_binds
+ (_units_usg, units', units_warnings) <- scTopCompUnits env units
+ -- Before CoreMerge, different compilation units may legitimately reuse the
+ -- same top-level Id/Unique, so we must not combine ScUsage across units.
+ return (nullUsage, CoreCompUnit unit_binds' unit_rules : units', unit_warnings ++ units_warnings)
scTopBinds :: ScEnv -> [InBind] -> UniqSM (ScUsage, [OutBind], [SpecFailWarning])
scTopBinds _env [] = return (nullUsage, [], [])
@@ -1009,18 +1012,19 @@ initScEnv guts
; this_mod <- getModule
; return (SCE { sc_opts = initScOpts dflags this_mod,
sc_force = False,
- sc_subst = init_subst,
+ sc_subst = mkEmptySubst emptyInScopeSet,
sc_how_bound = emptyVarEnv,
sc_vals = emptyVarEnv,
sc_annotations = anns }) }
+
+initScCompUnitEnv :: ScEnv -> [InBind] -> ScEnv
+initScCompUnitEnv env unit_binds
+ = env { sc_subst = mkEmptySubst in_scope }
where
- init_subst = mkEmptySubst $ foldl' addCompUnitBndrs emptyInScopeSet (mg_binds guts)
- -- Acccount for top-level bindings that are not in dependency order;
- -- see Note [Glomming] in GHC.Core.Opt.OccurAnal
- -- Easiest thing is to bring all the top level binders into scope at once,
- -- as if at once, as if all the top-level decls were mutually recursive.
- addCompUnitBndrs scope (CoreCompUnit unit_binds _) =
- scope `extendInScopeSetBndrs` unit_binds
+ in_scope = emptyInScopeSet `extendInScopeSetBndrs` unit_binds
+ -- Account for top-level bindings that are not in dependency order;
+ -- see Note [Glomming] in GHC.Core.Opt.OccurAnal.
+ -- Crucially, only add binders from the current compilation unit.
data HowBound = RecFun -- These are the recursive functions for which
-- we seek interesting call patterns
@@ -1443,7 +1447,8 @@ scBind top_lvl env (NonRec bndr rhs) do_body
-- but found some regressions (see !8135). So I backed off.
= do { (rhs_usage, rhs', ws_rhs) <- scExpr env rhs
- -- At top level, we've already put all binders into scope; see initScEnv
+ -- At top level, we've already put the current compilation unit's
+ -- binders into scope; see initScCompUnitEnv.
-- Hence no need to call `extendBndr`. But we still want to
-- extend the `ValueEnv` to record the value of this binder.
; let body_env = extendValEnv env bndr (isValue (sc_vals env) rhs')
@@ -1491,7 +1496,8 @@ scBind top_lvl env (Rec prs) do_body
(rhs_env1,bndrs') | isTopLevel top_lvl = (env, bndrs)
| otherwise = extendRecBndrs env bndrs
- -- At top level, we've already put all binders into scope; see initScEnv
+ -- At top level, we've already put the current compilation unit's
+ -- binders into scope; see initScCompUnitEnv.
rhs_env2 = extendHowBound rhs_env1 bndrs' RecFun
=====================================
compiler/GHC/Core/Opt/Specialise.hs
=====================================
@@ -65,6 +65,7 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Unit.Module( Module )
+import GHC.Unit.Module.Deps ( Dependencies )
import GHC.Unit.Module.ModGuts
import GHC.Core.Unfold
@@ -641,10 +642,9 @@ Hence, the invariant is this:
-- | Specialise calls to type-class overloaded functions occurring in a program.
specProgram :: ModGuts -> CoreM ModGuts
specProgram guts = do
- rule_env <- initRuleEnv guts
let static = StaticSpecInput
{ ssi_module = mg_module guts
- , ssi_rule_env = rule_env
+ , ssi_deps = mg_deps guts
}
dyn = DynamicSpecData
{ dsd_binds = mg_binds guts
@@ -655,7 +655,7 @@ specProgram guts = do
data StaticSpecInput = StaticSpecInput
{ ssi_module :: !Module
- , ssi_rule_env :: !RuleEnv
+ , ssi_deps :: !Dependencies
}
data DynamicSpecData = DynamicSpecData
@@ -680,20 +680,26 @@ specProgram' static dyn
-- | Specialise calls to type-class overloaded functions occurring in a program.
specCompUnit :: StaticSpecInput -> DynFlags -> CoreCompUnit -> CoreM CoreCompUnit
specCompUnit static dflags (CoreCompUnit unit_binds unit_rules)
- = do { (unit_binds', uds) <- runSpecM (go unit_binds)
+ = do { hpt_rules <- getHomeRuleBase
+ ; eps_rules <- getExternalRuleBase
+ ; let rule_env = mkRuleEnv (ssi_module static) (ssi_deps static) [] [unit]
+ eps_rules hpt_rules
+ top_env = SE { se_subst = Core.mkEmptySubst in_scope
+ , se_module = ssi_module static
+ , se_rules = rule_env
+ , se_dflags = dflags }
+ ; (unit_binds', uds) <- runSpecM (go top_env unit_binds)
; (spec_rules, spec_binds) <- specImports top_env uds
; return (CoreCompUnit (spec_binds ++ unit_binds') (spec_rules ++ unit_rules)) }
where
- top_env = SE { se_subst = Core.mkEmptySubst in_scope
- , se_module = ssi_module static
- , se_rules = ssi_rule_env static
- , se_dflags = dflags }
+ unit = CoreCompUnit unit_binds unit_rules
in_scope = mkInScopeSetBndrs unit_binds
- go [] = return ([], emptyUDs)
- go (bind:binds) = do (bind', binds', uds') <- specBind TopLevel top_env bind $ \_ ->
- go binds
- return (bind' ++ binds', uds')
+ go _ [] = return ([], emptyUDs)
+ go env (bind:binds)
+ = do (bind', binds', uds') <- specBind TopLevel env bind $ \_ ->
+ go env binds
+ return (bind' ++ binds', uds')
{-
Note [Wrap bindings returned by specImports]
=====================================
compiler/GHC/Core/Opt/Split.hs
=====================================
@@ -0,0 +1,271 @@
+{-# LANGUAGE ViewPatterns #-}
+
+module GHC.Core.Opt.Split
+ ( splitCompUnit
+ , checkNameClashes
+ ) where
+
+import GHC.Prelude hiding ( head, init, last )
+
+import GHC.Core
+import GHC.Core.FVs
+import GHC.Core.Opt.OccurAnal (occurAnalyseCompUnit)
+
+import GHC.Data.Graph.Directed (SCC(..), Node(..), stronglyConnCompFromEdgedVerticesUniq)
+import GHC.Data.Maybe (orElse)
+
+import GHC.Types.Unique.Set
+import GHC.Types.Name (isExternalName, nameModule)
+import GHC.Types.Id (realIdUnfolding)
+import GHC.Types.Var.Set
+import GHC.Types.Var.Env
+import GHC.Types.Var
+
+import GHC.Utils.Outputable
+import GHC.Utils.Panic
+
+import GHC.Unit.Module (Module)
+
+import qualified Data.IntMap.Strict as IntMap
+import qualified Data.IntSet as IntSet
+import Data.List (find)
+
+{- Note [Splitting core programs]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+splitCompUnit splits a single compilation unit into multiple.
+To do so we:
+
+Initially we run OccAnal on the compilation unit. I don't think it's strictly neccessary
+but it zaps fragile unfoldings which speeds up and gets rid of glomming.
+We will try getting rid of this later.
+
+We split imported rules into those which only concern imported rules and those mentioning
+local binders (called unit_rules).
+
+Rules mentioning local binders introduce edges between any local binders they mention.
+
+Next we build the graph nodes from binders:
+* Fully nodes have one key, the first Id the binder defines. Their node data is the binder itself.
+* Pseudo nodes for every id the binder defines (tail $ bindersOf bind) with no data.
+
+Now we introduce edges:
+ * For binders from the first id to all other defined ids and those it mentions as fv
+ let key = (head bindersOf bind)
+ let edges = map (\x -> (key, x)) bindersOf bind ++ map (\x -> (key, x)) (bindFreeVars bind)
+ * For rules if they mention local binders introduce edges between any local binders they mention.
+
+* All edges computed so far are directional. So we take all edges and also add their reversed version.
+
+* After this we split the graph into independent components.
+
+* As the last step we assign each unit rule to a unit from which it mentions variables
+-}
+
+data DepGraphNode
+ = BindNode
+ { depNodeKey :: !Var
+ , depNodeBind :: CoreBind
+ }
+ | PseudoNode
+ { depNodeKey :: !Var }
+
+type Edge = (Var, Var)
+
+-- | Is the given variable defined in the given module.
+varFromModule :: Module -> Var -> Bool
+varFromModule _ var = isLocalId var
+
+maybeRuleEdges :: Module -> CoreRule -> Maybe [Edge]
+maybeRuleEdges this_module rule =
+ case local_fvs of
+ [] -> Nothing
+ [_] -> Just []
+ _ -> Just (zip local_fvs (drop 1 local_fvs))
+ where
+ local_fvs = filter (varFromModule this_module) (nonDetEltsUniqSet (ruleFreeVars rule))
+
+bindNode :: VarSet -> CoreBind -> ([DepGraphNode], [Edge])
+bindNode local_top_bndrs bind =
+ case bindersOf bind of
+ [] -> ([], [])
+ key:rest ->
+ let split_fvs = bindSplitFreeVars local_top_bndrs bind
+ intern_edges = map (\v -> (key, v)) rest
+ ext_edges = map (\v -> (key, v)) (nonDetEltsUniqSet split_fvs)
+ node = BindNode key bind
+ pseudo_nodes = map PseudoNode rest
+ in (node : pseudo_nodes, intern_edges ++ ext_edges)
+
+bindSplitFreeVars :: VarSet -> CoreBind -> VarSet
+bindSplitFreeVars local_top_bndrs bind =
+ close_over_imported_unfoldings (bindMentionedVars bind `unionVarSet` bindBndrInfoVars bind)
+ where
+ close_over_imported_unfoldings fvs = go emptyVarSet fvs
+
+ go !seen !fvs =
+ case pick_new_import (fvs `minusVarSet` seen) of
+ Nothing -> fvs
+ Just v ->
+ let unfolding_fvs = unfoldingRefs v
+ local_unfolding_fvs = unfolding_fvs `intersectVarSet` local_top_bndrs
+ in go (extendVarSet seen v) (fvs `unionVarSet` local_unfolding_fvs `unionVarSet` unfolding_fvs)
+
+ pick_new_import vars =
+ find pickable (nonDetEltsUniqSet vars)
+
+ pickable v = isId v && not (v `elemVarSet` local_top_bndrs)
+
+ unfoldingRefs v =
+ case maybeUnfoldingTemplate (realIdUnfolding v) of
+ Just rhs -> exprSomeFreeVars (const True) rhs
+ Nothing -> emptyVarSet
+
+bindMentionedVars :: CoreBind -> VarSet
+bindMentionedVars (NonRec _ rhs) = exprSomeFreeVars (const True) rhs
+bindMentionedVars (Rec prs) = exprsSomeFreeVars (const True) (map snd prs)
+
+bindBndrInfoVars :: CoreBind -> VarSet
+bindBndrInfoVars bind =
+ mkVarSet $
+ concatMap (dVarSetElems . bndrRuleAndUnfoldingVarsDSet) (bindersOf bind)
+
+type Edges = IdEnv [Var]
+
+-- Split core binders takes directed edges treating them as undirected by adding the reverse edge internally.
+splitCoreBinders :: [DepGraphNode] -> [Edge] -> [(VarSet, [CoreBind])]
+splitCoreBinders nodes edges =
+ [ (mkVarSet (concatMap bindersOf binds), binds)
+ | comp_nodes <- map scc_payloads (stronglyConnCompFromEdgedVerticesUniq (map mk_graph_node nodes))
+ , let binds = [ b | BindNode { depNodeBind = b } <- comp_nodes ]
+ ]
+ where
+ key_set = mkVarSet (map depNodeKey nodes)
+ undirected_edges = foldr add_edge emptyVarEnv (edges ++ map reverse_edge edges)
+
+ add_edge :: Edge -> Edges -> Edges
+ add_edge (src, dst) env = extendVarEnv_C (++) env src [dst]
+
+ reverse_edge :: Edge -> Edge
+ reverse_edge (src, dst) = (dst, src)
+
+ mk_graph_node node
+ = DigraphNode
+ { node_payload = node
+ , node_key = varUnique key
+ , node_dependencies =
+ [ varUnique dst
+ | dst <- lookupVarEnv undirected_edges key `orElse` []
+ , elemVarSet dst key_set
+ ]
+ }
+ where
+ key = depNodeKey node
+
+ scc_payloads (AcyclicSCC p) = [p]
+ scc_payloads (CyclicSCC ps) = ps
+
+assignLocalRules
+ :: [CoreRule]
+ -> [(VarSet, [CoreBind])]
+ -> ([(VarSet, [CoreBind], [CoreRule])], [CoreRule])
+assignLocalRules unit_rules binder_components =
+ (components_with_rules, rules_without_component)
+ where
+ (component_rule_map, rules_without_component)
+ = foldr assign_rule (IntMap.empty, []) unit_rules
+
+ assign_rule rule (rule_map, no_comp_rules)
+ = case rule_comp_indices rule of
+ [i] -> (IntMap.insertWith (++) i [rule] rule_map, no_comp_rules)
+ [] -> (rule_map, rule : no_comp_rules)
+ is -> pprPanic "splitCompUnit"
+ ( text "Rule free vars span multiple components"
+ $$ text "rule:" <+> ppr rule
+ $$ text "components:" <+> ppr is
+ $$ text "rule_fvs:" <+> pprVarsWithModule (nonDetEltsUniqSet (ruleFreeVars rule))
+ $$ vcat [ text "component" <+> int i <> colon <+> ppr hits
+ | (i, hits) <- comp_hits rule ] )
+
+ rule_comp_indices rule
+ = IntSet.toList $ IntSet.fromList
+ [ i
+ | ((bndrs, _), i) <- zip binder_components [0..]
+ , not (isEmptyVarSet (ruleFreeVars rule `intersectVarSet` bndrs))
+ ]
+
+ comp_hits rule =
+ [ (i, ruleFreeVars rule `intersectVarSet` bndrs)
+ | ((bndrs, _), i) <- zip binder_components [0..]
+ , not (isEmptyVarSet (ruleFreeVars rule `intersectVarSet` bndrs))
+ ]
+
+ components_with_rules =
+ [ (bndrs, binds, IntMap.findWithDefault [] i component_rule_map)
+ | ((bndrs, binds), i) <- zip binder_components [0..]
+ ]
+
+pprVarsWithModule :: [Var] -> SDoc
+pprVarsWithModule vars = braces (fsep (punctuate comma (map pprVarWithModule vars)))
+
+pprVarWithModule :: Var -> SDoc
+pprVarWithModule v
+ | isExternalName n = ppr v <+> parens (ppr (nameModule n))
+ | otherwise = ppr v
+ where
+ n = varName v
+
+-- After optimizations a rule might no longer reference binders from this module.
+-- In these cases we return them here and then add them to mg_rules.
+splitCompUnit :: Module -> [CoreRule] -> CoreCompUnit -> ([CoreCompUnit], [CoreRule])
+splitCompUnit this_module imp_rules unit
+ = let comp_units = map mk_comp_unit components_with_rules
+ in checkNameClashes comp_units `seq`
+ (comp_units, rules_for_imps ++ rules_without_component)
+ where
+ CoreCompUnit occ_binds unit_rules =
+ occurAnalyseCompUnit this_module (const True) (const True) imp_rules unit
+
+ top_level_bndrs = bindersOfBinds occ_binds
+ checked_bndrs =
+ assertPpr (all isLocalVar top_level_bndrs)
+ ( text "splitCompUnit: non-local top-level binder(s)"
+ $$ ppr top_level_bndrs )
+ top_level_bndrs
+
+ local_top_bndrs = mkVarSet checked_bndrs
+
+ (bind_nodes, bind_edges)
+ = checked_bndrs `seq`
+ foldr (\b (ns, es) -> let (ns', es') = bindNode local_top_bndrs b in (ns' ++ ns, es' ++ es))
+ ([], [])
+ occ_binds
+
+ rule_edge_pairs = [ (r, maybeRuleEdges this_module r) | r <- unit_rules ]
+ rule_edges = concat [ es | (_, Just es) <- rule_edge_pairs ]
+ rules_for_imps = [ r | (r, Nothing) <- rule_edge_pairs ]
+ unit_rules_local = [ r | (r, Just _) <- rule_edge_pairs ]
+
+ all_edges = bind_edges ++ rule_edges
+ binder_components = splitCoreBinders bind_nodes all_edges
+ (components_with_rules, rules_without_component) =
+ assignLocalRules unit_rules_local binder_components
+
+ mk_comp_unit (_, binds, rules) = CoreCompUnit binds rules
+
+checkNameClashes :: [CoreCompUnit] -> ()
+checkNameClashes comp_units
+ | null dup_bndrs = ()
+ | otherwise
+ = pprPanic "checkNameClashes"
+ ( text "Duplicate top-level binders across split compilation units"
+ $$ ppr dup_bndrs )
+ where
+ all_bndrs = concatMap (bindersOfBinds . coreCompUnitBinds) comp_units
+
+ dup_bndrs :: [Var]
+ dup_bndrs = go emptyVarSet all_bndrs
+
+ go _ [] = []
+ go seen (b:bs)
+ | b `elemVarSet` seen = b : go seen bs
+ | otherwise = go (extendVarSet seen b) bs
=====================================
compiler/GHC/Core/SimpleOpt.hs
=====================================
@@ -205,7 +205,8 @@ simpleOptPgm opts this_mod binds rules =
do_unit (env, comp_units') (CoreCompUnit unit_binds unit_rules)
= let (env', unit_binds') = foldl' do_one (env, []) unit_binds
- in (env', CoreCompUnit (reverse unit_binds') unit_rules : comp_units')
+ unit_rules' = map (substRule (soe_subst env') id) unit_rules
+ in (env', CoreCompUnit (reverse unit_binds') unit_rules' : comp_units')
do_one (env, binds') bind
= case simple_opt_bind env bind TopLevel of
=====================================
compiler/GHC/Core/Subst.hs
=====================================
@@ -13,7 +13,7 @@ module GHC.Core.Subst (
-- ** Substituting into expressions and related types
deShadowBinds, deShadowCompUnits,
- substRuleInfo, substRulesForImportedIds,
+ substRule, substRuleInfo, substRulesForImportedIds,
substTyUnchecked, substCo, substExpr, substExprSC, substBind, substBindSC,
substUnfolding, substUnfoldingSC,
lookupIdSubst, lookupIdSubst_maybe, substIdType, substIdOcc,
=====================================
compiler/ghc.cabal.in
=====================================
@@ -393,6 +393,7 @@ Library
GHC.Core.Opt.Simplify.Utils
GHC.Core.Opt.SpecConstr
GHC.Core.Opt.Specialise
+ GHC.Core.Opt.Split
GHC.Core.Opt.StaticArgs
GHC.Core.Opt.Stats
GHC.Core.Opt.WorkWrap
=====================================
testsuite/driver/testlib.py
=====================================
@@ -2842,7 +2842,21 @@ def _normalised_outputs(expected_file: Path,
return expected, actual
def _sorted_lines(s: str) -> str:
- return '\n'.join(sorted(s.splitlines()))
+ return '\n'.join(sorted(_drop_split_comp_unit_headers(s.splitlines())))
+
+def _drop_split_comp_unit_headers(lines: List[str]) -> List[str]:
+ kept: List[str] = []
+ i = 0
+ while i < len(lines):
+ # Ignore an empty line immediately followed by the split-core unit header.
+ if i + 1 < len(lines) \
+ and lines[i] == '' \
+ and lines[i + 1].startswith('=== Start of new compilation unit'):
+ i += 2
+ continue
+ kept.append(lines[i])
+ i += 1
+ return kept
def _is_reordered_output_mismatch(expected_file: Path,
actual_file: Path,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/452dc62605ce22373b537529ae385d…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/452dc62605ce22373b537529ae385d…
You're receiving this email because of your account on gitlab.haskell.org.
1
0