Skip to content

Commit e61b658

Browse files
mpickeringfgaz
authored andcommitted
Add support for loading multiple components into one repl session
There are several parts to this patch which are logically distinct but work together to support the overal goal of starting a GHCi session with multiple packages loaded at once. 1. When a user writes "cabal repl <target>" then if the user is using a compiler > ghc-9.4.* then we will attempt to start a multi-session which loads the selected targets into one multi-package session of GHC. 1a. The closure property states that in order to load components `p` and `q` into the same session that if `p` depends on `z` and `z` depends on `q` then `z` must also be loaded into the session. 1b. Only inplace packages are able to be loaded into a multi session (if a component `z` exists then it is already made into an inplace package by cabal). Therefore cabal has already engineered that there is source code locally available for all packages which we will want to load into a session. 2. The solver is unmodified, the solver is given the repl targets and creates a build plan as before. After the solver is completed then in `setRootTargets` and `pruneInstallPlan` we modify the install plan to enforce the closure property and mark which dependencies need to be promised. * Mark the current components as `BuildInPlaceOnly InMemory`, which indicates to the compiler that it is to be built in a GHC multi-session. * Augment the component repl targets to indicate that components required by the closure property (in addition to normal targets) will be loaded into the repl. * Modify the dependency edges in `compLibDependencies` to indicate which dependencies are the promised ones (which is precisely components which are `BuildInPlaceOnly InMemory` build styles). This is the field which is eventually used to populate the `--dependency` argument to `./Setup configure`. Fixes #8491
1 parent 272237c commit e61b658

File tree

71 files changed

+1319
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1319
-306
lines changed

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
2929
, testCase "GenericPackageDescription" $
3030
md5Check (Proxy :: Proxy GenericPackageDescription) 0xa3e9433662ecf0c7a3c26f6d75a53ba1
3131
, testCase "LocalBuildInfo" $
32-
md5Check (Proxy :: Proxy LocalBuildInfo) 0x91ffcd61bbd83525e8edba877435a031
32+
md5Check (Proxy :: Proxy LocalBuildInfo) 0x30ebb8fffa1af2aefa9432ff4028eef8
3333
#endif
3434
]
3535

Cabal/src/Distribution/Types/AnnotatedId.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveFunctor #-}
12
module Distribution.Types.AnnotatedId (
23
AnnotatedId(..)
34
) where
@@ -19,7 +20,7 @@ data AnnotatedId id = AnnotatedId {
1920
ann_cname :: ComponentName,
2021
ann_id :: id
2122
}
22-
deriving (Show)
23+
deriving (Show, Functor)
2324

2425
instance Eq id => Eq (AnnotatedId id) where
2526
x == y = ann_id x == ann_id y
@@ -29,6 +30,3 @@ instance Ord id => Ord (AnnotatedId id) where
2930

3031
instance Package (AnnotatedId id) where
3132
packageId = ann_pid
32-
33-
instance Functor AnnotatedId where
34-
fmap f (AnnotatedId pid cn x) = AnnotatedId pid cn (f x)

cabal-install-solver/src/Distribution/Solver/Types/ComponentDeps.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Distribution.Solver.Types.ComponentDeps (
2424
, insert
2525
, zip
2626
, filterDeps
27+
, mapDeps
2728
, fromLibraryDeps
2829
, fromSetupDeps
2930
, fromInstalled
@@ -149,6 +150,10 @@ zip (ComponentDeps d1) (ComponentDeps d2) =
149150
filterDeps :: (Component -> a -> Bool) -> ComponentDeps a -> ComponentDeps a
150151
filterDeps p = ComponentDeps . Map.filterWithKey p . unComponentDeps
151152

153+
-- | Keep only selected components (and their associated deps info).
154+
mapDeps :: (Component -> a -> b) -> ComponentDeps a -> ComponentDeps b
155+
mapDeps p = ComponentDeps . Map.mapWithKey p . unComponentDeps
156+
152157
-- | ComponentDeps containing library dependencies only
153158
fromLibraryDeps :: a -> ComponentDeps a
154159
fromLibraryDeps = singleton ComponentLib

cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ data ConstraintSource =
3636
-- target, when a more specific source is not known.
3737
| ConstraintSourceConfigFlagOrTarget
3838

39+
-- | Constraint introduced by --enable-multi-repl, which requires features
40+
-- from Cabal >= 3.11
41+
| ConstraintSourceMultiRepl
42+
3943
-- | The source of the constraint is not specified.
4044
| ConstraintSourceUnknown
4145

@@ -65,6 +69,8 @@ showConstraintSource ConstraintSourceNonUpgradeablePackage =
6569
showConstraintSource ConstraintSourceFreeze = "cabal freeze"
6670
showConstraintSource ConstraintSourceConfigFlagOrTarget =
6771
"config file, command line flag, or user target"
72+
showConstraintSource ConstraintSourceMultiRepl =
73+
"--enable-multi-repl"
6874
showConstraintSource ConstraintSourceUnknown = "unknown source"
6975
showConstraintSource ConstraintSetupCabalMinVersion =
7076
"minimum version of Cabal used by Setup.hs"

cabal-install/cabal-install.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ library
159159
Distribution.Client.ProjectPlanning.Types
160160
Distribution.Client.RebuildMonad
161161
Distribution.Client.Reconfigure
162+
Distribution.Client.ReplFlags
162163
Distribution.Client.Run
163164
Distribution.Client.Sandbox
164165
Distribution.Client.Sandbox.PackageEnvironment

cabal-install/src/Distribution/Client/CmdListBin.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
187187
-- here and in PlanOutput,
188188
-- use binDirectoryFor?
189189
bin_file' s =
190-
if elabBuildStyle elab == BuildInplaceOnly
190+
if isInplaceBuildStyle (elabBuildStyle elab)
191191
then dist_dir </> "build" </> prettyShow s </> prettyShow s <.> exeExtension plat
192192
else InstallDirs.bindir (elabInstallDirs elab) </> prettyShow s <.> exeExtension plat
193193

194194
flib_file' s =
195-
if elabBuildStyle elab == BuildInplaceOnly
195+
if isInplaceBuildStyle (elabBuildStyle elab)
196196
then dist_dir </> "build" </> prettyShow s </> ("lib" ++ prettyShow s) <.> dllExtension plat
197197
else InstallDirs.bindir (elabInstallDirs elab) </> ("lib" ++ prettyShow s) <.> dllExtension plat
198198

0 commit comments

Comments
 (0)