Skip to content

Commit 56bd0c5

Browse files
committed
[stage1] remove hard ghc-internal/ghc-heap dependency from stage1
1 parent 060d619 commit 56bd0c5

File tree

10 files changed

+184
-8
lines changed

10 files changed

+184
-8
lines changed

cabal.project.stage1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ packages:
1717
libraries/ghc-platform
1818
libraries/ghc-boot
1919
libraries/ghc-boot-th-next
20-
libraries/ghc-heap
2120
libraries/ghci
2221
libraries/libffi-clib
2322
libraries/os-string

compiler/GHC/ByteCode/Types.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ import GHCi.ResolvedBCO ( BCOByteArray(..), mkBCOByteArray )
4949

5050
import Foreign
5151
import Data.ByteString (ByteString)
52+
#ifndef BOOTSTRAPPING
5253
import qualified GHC.Exts.Heap as Heap
54+
#endif
5355
import GHC.Cmm.Expr ( GlobalRegSet, emptyRegSet, regSetToList )
5456
import GHC.Unit.Module
5557

@@ -166,8 +168,13 @@ type AddrEnv = NameEnv (Name, AddrPtr)
166168
-- We need the Name in the range so we know which
167169
-- elements to filter out when unloading a module
168170

171+
#ifndef BOOTSTRAPPING
169172
newtype ItblPtr = ItblPtr (RemotePtr Heap.StgInfoTable)
170173
deriving (Show, NFData)
174+
#else
175+
newtype ItblPtr = ItblPtr (RemotePtr ())
176+
deriving (Show, NFData)
177+
#endif
171178
newtype AddrPtr = AddrPtr (RemotePtr ())
172179
deriving (NFData)
173180

compiler/GHC/Runtime/Heap/Inspect.hs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module GHC.Runtime.Heap.Inspect(
3434
constrClosToName -- exported to use in test T4891
3535
) where
3636

37+
#ifndef BOOTSTRAPPING
3738
import GHC.Prelude hiding (head, init, last, tail)
3839
import GHC.Platform
3940

@@ -1474,3 +1475,91 @@ quantifyType ty = ( filter isTyVar $
14741475
, ty)
14751476
where
14761477
(_tvs, _, rho) = tcSplitNestedSigmaTys ty
1478+
1479+
#else
1480+
import GHC.Prelude
1481+
import GHC.Types.Name
1482+
import GHC.Core.DataCon
1483+
import GHC.Core.Type
1484+
import GHC.Utils.Outputable
1485+
import GHC.Types.Var.Set
1486+
import GHC.Driver.Env
1487+
import GHCi.RemoteTypes
1488+
import GHC.InfoProv
1489+
import GHC.Types.Basic (Boxity)
1490+
import GHC.Utils.Panic
1491+
1492+
-- Dummy types
1493+
data ClosureType = DummyClosureType
1494+
data GenClosure a = DummyGenClosure
1495+
1496+
type RttiType = Type
1497+
1498+
data Term = Term { ty :: RttiType
1499+
, dc :: Either String DataCon
1500+
, val :: ForeignHValue
1501+
, subTerms :: [Term] }
1502+
| Prim { ty :: RttiType
1503+
, valRaw :: [Word] }
1504+
| Suspension { ctype :: ClosureType
1505+
, ty :: RttiType
1506+
, val :: ForeignHValue
1507+
, bound_to :: Maybe Name
1508+
, infoprov :: Maybe InfoProv
1509+
}
1510+
| NewtypeWrap{ ty :: RttiType
1511+
, dc :: Either String DataCon
1512+
, wrapped_term :: Term }
1513+
| RefWrap { ty :: RttiType
1514+
, wrapped_term :: Term }
1515+
1516+
-- Dummy functions
1517+
cvObtainTerm :: HscEnv -> Int -> Bool -> RttiType -> ForeignHValue -> IO Term
1518+
cvObtainTerm _ _ _ ty _ = return (Prim ty []) -- Dummy return
1519+
1520+
cvReconstructType :: HscEnv -> Int -> RttiType -> ForeignHValue -> IO (Maybe RttiType)
1521+
cvReconstructType _ _ _ _ = return Nothing
1522+
1523+
improveRTTIType :: HscEnv -> RttiType -> RttiType -> Maybe Subst
1524+
improveRTTIType _ _ _ = Nothing
1525+
1526+
isFullyEvaluatedTerm :: Term -> Bool
1527+
isFullyEvaluatedTerm _ = False
1528+
1529+
termType :: Term -> RttiType
1530+
termType t = ty t
1531+
1532+
mapTermType :: (RttiType -> Type) -> Term -> Term
1533+
mapTermType _ t = t
1534+
1535+
termTyCoVars :: Term -> TyCoVarSet
1536+
termTyCoVars _ = emptyVarSet
1537+
1538+
type TermProcessor a b = RttiType -> Either String DataCon -> ForeignHValue -> [a] -> b
1539+
1540+
data TermFold a = TermFold { fTerm :: TermProcessor a a
1541+
, fPrim :: RttiType -> [Word] -> a
1542+
, fSuspension :: ClosureType -> RttiType -> ForeignHValue
1543+
-> Maybe Name -> Maybe InfoProv -> a
1544+
, fNewtypeWrap :: RttiType -> Either String DataCon
1545+
-> a -> a
1546+
, fRefWrap :: RttiType -> a -> a
1547+
}
1548+
1549+
foldTerm :: TermFold a -> Term -> a
1550+
foldTerm _ _ = panic "foldTerm: bootstrapping"
1551+
1552+
type Precedence = Int
1553+
type TermPrinterM m = Precedence -> Term -> m SDoc
1554+
type CustomTermPrinter m = TermPrinterM m -> [Precedence -> Term -> m (Maybe SDoc)]
1555+
1556+
cPprTerm :: Monad m => CustomTermPrinter m -> Term -> m SDoc
1557+
cPprTerm _ _ = return (text "Bootstrapping Term")
1558+
1559+
cPprTermBase :: Monad m => CustomTermPrinter m
1560+
cPprTermBase _ = []
1561+
1562+
constrClosToName :: HscEnv -> GenClosure a -> IO (Either String Name)
1563+
constrClosToName _ _ = return (Left "Bootstrapping")
1564+
1565+
#endif

compiler/GHC/Runtime/Interpreter.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module GHC.Runtime.Interpreter
2424
, storeBreakpoint
2525
, breakpointStatus
2626
, getBreakpointVar
27+
#ifndef BOOTSTRAPPING
2728
, getClosure
29+
#endif
2830
, whereFrom
2931
, getModBreaks
3032
, readIModBreaks
@@ -107,7 +109,9 @@ import Control.Monad.Catch as MC (mask)
107109
import Data.Binary
108110
import Data.ByteString (ByteString)
109111
import Foreign hiding (void)
112+
#ifndef BOOTSTRAPPING
110113
import qualified GHC.Exts.Heap as Heap
114+
#endif
111115
import GHC.Stack.CCS (CostCentre,CostCentreStack)
112116
import System.Directory
113117
import System.Process
@@ -390,11 +394,13 @@ getBreakpointVar interp ref ix =
390394
mb <- interpCmd interp (GetBreakpointVar apStack ix)
391395
mapM (mkFinalizedHValue interp) mb
392396

397+
#ifndef BOOTSTRAPPING
393398
getClosure :: Interp -> ForeignHValue -> IO (Heap.GenClosure ForeignHValue)
394399
getClosure interp ref =
395400
withForeignRef ref $ \hval -> do
396401
mb <- interpCmd interp (GetClosure hval)
397402
mapM (mkFinalizedHValue interp) mb
403+
#endif
398404

399405
whereFrom :: Interp -> ForeignHValue -> IO (Maybe InfoProv.InfoProv)
400406
whereFrom interp ref =

compiler/ghc.cabal.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ Library
113113
rts,
114114
rts-headers,
115115
ghc-boot == @ProjectVersionMunged@,
116-
ghc-heap >=9.10.1 && <=@ProjectVersionMunged@,
117116
ghci == @ProjectVersionMunged@
118117

119118
if flag(bootstrap)
119+
CPP-Options: -DBOOTSTRAPPING
120120
Build-Depends:
121121
ghc-boot-th-next == @ProjectVersionMunged@
122122
else
123123
Build-Depends:
124124
ghc-boot-th == @ProjectVersionMunged@,
125125
ghc-internal == @[email protected],
126+
ghc-heap >= 9.10.1 && <=@ProjectVersionMunged@,
126127

127128
if os(windows)
128129
Build-Depends: Win32 >= 2.3 && < 2.15

libraries/ghci/GHCi/InfoTable.hsc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import Foreign
1919
import Foreign.C
2020
import GHC.Ptr
2121
import GHC.Exts
22+
#ifndef BOOTSTRAPPING
2223
import GHC.Exts.Heap
24+
#endif
2325
import Data.ByteString (ByteString)
2426
import Control.Monad.Fail
2527
import qualified Data.ByteString as BS
@@ -36,11 +38,16 @@ mkConInfoTable
3638
-> Int -- constr tag
3739
-> Int -- pointer tag
3840
-> ByteString -- con desc
41+
#ifndef BOOTSTRAPPING
3942
-> IO (Ptr StgInfoTable)
43+
#else
44+
-> IO (Ptr ())
45+
#endif
4046
-- resulting info table is allocated with allocateExecPage(), and
4147
-- should be freed with freeExecPage().
4248

4349
mkConInfoTable tables_next_to_code ptr_words nonptr_words tag ptrtag con_desc = do
50+
#ifndef BOOTSTRAPPING
4451
let entry_addr = interpConstrEntry !! ptrtag
4552
code' <- if tables_next_to_code
4653
then Just <$> mkJumpToAddr entry_addr
@@ -57,8 +64,11 @@ mkConInfoTable tables_next_to_code ptr_words nonptr_words tag ptrtag con_desc =
5764
code = code'
5865
}
5966
castFunPtrToPtr <$> newExecConItbl tables_next_to_code itbl con_desc
67+
#else
68+
return nullPtr
69+
#endif
6070

61-
71+
#ifndef BOOTSTRAPPING
6272
-- -----------------------------------------------------------------------------
6373
-- Building machine code fragments for a constructor's entry code
6474

@@ -382,3 +392,4 @@ wORD_SIZE = (#const SIZEOF_HSINT)
382392

383393
conInfoTableSizeB :: Int
384394
conInfoTableSizeB = wORD_SIZE + itblSize
395+
#endif

libraries/ghci/GHCi/Message.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ import GHCi.ResolvedBCO
3737

3838
import GHC.LanguageExtensions
3939
import GHC.InfoProv
40-
#if MIN_VERSION_ghc_internal(9,1500,0)
41-
import qualified GHC.Exts.Heap as Heap
42-
#else
40+
#ifndef BOOTSTRAPPING
4341
import qualified GHC.Exts.Heap as Heap
4442
#endif
4543
import GHC.ForeignSrcLang
@@ -122,9 +120,15 @@ data Message a where
122120
FreeFFI :: RemotePtr C_ffi_cif -> Message ()
123121

124122
-- | Create an info table for a constructor
123+
#ifndef BOOTSTRAPPING
125124
MkConInfoTable
126125
:: !ConInfoTable
127126
-> Message (RemotePtr Heap.StgInfoTable)
127+
#else
128+
MkConInfoTable
129+
:: !ConInfoTable
130+
-> Message (RemotePtr ())
131+
#endif
128132

129133
-- | Evaluate a statement
130134
EvalStmt
@@ -225,9 +229,11 @@ data Message a where
225229
-- | Remote interface to GHC.Internal.Heap.getClosureData. This is used by
226230
-- the GHCi debugger to inspect values in the heap for :print and
227231
-- type reconstruction.
232+
#ifndef BOOTSTRAPPING
228233
GetClosure
229234
:: HValueRef
230235
-> Message (Heap.GenClosure HValueRef)
236+
#endif
231237

232238
-- | Remote interface to GHC.InfoProv.whereFrom. This is used by
233239
-- the GHCi debugger to inspect the provenance of thunks for :print.
@@ -522,11 +528,14 @@ instance Binary (FunPtr a) where
522528
put = put . castFunPtrToPtr
523529
get = castPtrToFunPtr <$> get
524530

531+
#ifndef BOOTSTRAPPING
532+
#if defined(MIN_VERSION_ghc_internal)
525533
#if MIN_VERSION_ghc_internal(9,1400,0)
526534
instance Binary Heap.HalfWord where
527535
put x = put (fromIntegral x :: Word32)
528536
get = fromIntegral <$> (get :: Get Word32)
529537
#endif
538+
#endif
530539

531540
-- Binary instances to support the GetClosure message
532541
instance Binary Heap.StgTSOProfInfo
@@ -541,6 +550,7 @@ instance Binary Heap.StgInfoTable
541550
instance Binary Heap.ClosureType
542551
instance Binary Heap.PrimType
543552
instance Binary a => Binary (Heap.GenClosure a)
553+
#endif
544554
instance Binary InfoProv where
545555
#if MIN_VERSION_base(4,20,0)
546556
get = InfoProv <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
@@ -593,7 +603,9 @@ getMessage = do
593603
32 -> Msg <$> (RunModFinalizers <$> get <*> get)
594604
33 -> Msg <$> (AddSptEntry <$> get <*> get)
595605
34 -> Msg <$> (RunTH <$> get <*> get <*> get <*> get)
606+
#ifndef BOOTSTRAPPING
596607
35 -> Msg <$> (GetClosure <$> get)
608+
#endif
597609
36 -> Msg <$> (Seq <$> get)
598610
37 -> Msg <$> return RtsRevertCAFs
599611
38 -> Msg <$> (ResumeSeq <$> get)
@@ -639,7 +651,9 @@ putMessage m = case m of
639651
RunModFinalizers a b -> putWord8 32 >> put a >> put b
640652
AddSptEntry a b -> putWord8 33 >> put a >> put b
641653
RunTH st q loc ty -> putWord8 34 >> put st >> put q >> put loc >> put ty
654+
#ifndef BOOTSTRAPPING
642655
GetClosure a -> putWord8 35 >> put a
656+
#endif
643657
Seq a -> putWord8 36 >> put a
644658
RtsRevertCAFs -> putWord8 37
645659
ResumeSeq a -> putWord8 38 >> put a

libraries/ghci/GHCi/Run.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import Data.ByteString (ByteString)
3737
import qualified Data.ByteString.Short as BS
3838
import qualified Data.ByteString.Unsafe as B
3939
import GHC.Exts
40+
#ifndef BOOTSTRAPPING
4041
import qualified GHC.Exts.Heap as Heap
42+
#endif
4143
import GHC.Stack
4244
import Foreign hiding (void)
4345
import Foreign.C
@@ -114,9 +116,11 @@ run m = case m of
114116
PrepFFI args res -> toRemotePtr <$> prepForeignCall args res
115117
FreeFFI p -> freeForeignCallInfo (fromRemotePtr p)
116118
StartTH -> startTH
119+
#ifndef BOOTSTRAPPING
117120
GetClosure ref -> do
118121
clos <- Heap.getClosureData =<< localRef ref
119122
mapM (\(Heap.Box x) -> mkRemoteRef (HValue x)) clos
123+
#endif
120124
WhereFrom ref ->
121125
InfoProv.whereFrom =<< localRef ref
122126
Seq ref -> doSeq ref

libraries/ghci/ghci.cabal.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ library
9797
deepseq >= 1.4 && < 1.6,
9898
filepath >= 1.4 && < 1.6,
9999
ghc-boot == @ProjectVersionMunged@,
100-
ghc-heap >= 9.10.1 && <=@ProjectVersionMunged@,
101100
transformers >= 0.5 && < 0.7
102101

103102
if !arch(javascript)
@@ -122,11 +121,13 @@ library
122121
CPP-Options: -DHAVE_GHC_INTERNAL
123122

124123
if flag(bootstrap)
124+
CPP-Options: -DBOOTSTRAPPING
125125
build-depends:
126126
ghc-boot-th-next == @ProjectVersionMunged@
127127
else
128128
build-depends:
129-
ghc-boot-th == @ProjectVersionMunged@
129+
ghc-boot-th == @ProjectVersionMunged@,
130+
ghc-heap >= 9.10.1 && <=@ProjectVersionMunged@
130131

131132
if !os(windows)
132133
Build-Depends: unix >= 2.7 && < 2.9

0 commit comments

Comments
 (0)