Migration guide for multiple home units
Erdi, Gergo
Gergo.Erdi at sc.com
Thu Jun 30 09:55:40 UTC 2022
PUBLIC
In case anyone finds this interesting, I ended up splitting the unit initialization into two parts: one where all units are registered, without any package dependencies, and one where the package dependencies of a single unit are registered. This allowed us to start with just knowing which units are in play, use summariseFile to discover module dependencies, and then use that to compute package dependencies. It's basically just a refactoring of Matt's code from his email up the chain.
setUnits :: [(UnitId, DynFlags -> DynFlags)] -> HscEnv -> IO HscEnv
setUnits units hsc_env = do
home_unit_graph <- createHomeUnitGraph hsc_env units'
setHomeUnitGraph hsc_env dummy_home_unit home_unit_graph
where
dflags0 = hsc_dflags hsc_env
units'@((dummy_home_unit, _):_) =
[ (unit_id, unitFlags dflags0{ homeUnitId_ = unit_id, packageFlags = [] })
| (unit_id, unitFlags) <- units
]
setUnitDeps :: UnitId -> [UnitId] -> HscEnv -> IO HscEnv
setUnitDeps unit_id deps hsc_env = do
home_unit_env <- fillHomeUnitEnv hsc_env home_units new_dflags
let home_unit_graph = unitEnv_insert unit_id home_unit_env home_unit_graph0
setHomeUnitGraph hsc_env unit_id home_unit_graph
where
old_dflags = ue_unitFlags unit_id $ hsc_unit_env hsc_env
new_dflags = old_dflags
{ packageFlags = [ ExposePackage "" (UnitIdArg (RealUnit $ Definite uid)) (ModRenaming True []) | uid <- deps]
}
home_unit_graph0 = ue_home_unit_graph . hsc_unit_env $ hsc_env
home_units = unitEnv_keys home_unit_graph0
setHomeUnitGraph :: HscEnv -> UnitId -> HomeUnitGraph -> IO HscEnv
setHomeUnitGraph hsc_env unit_id home_unit_graph = do
unit_env <- assertUnitEnvInvariant <$> initUnitEnv unit_id home_unit_graph (ghcNameVersion dflags0) (targetPlatform dflags0)
return $ hsc_env { hsc_unit_env = unit_env }
where
dflags0 = hsc_dflags hsc_env
createHomeUnitGraph :: HscEnv -> [(UnitId, DynFlags)] -> IO HomeUnitGraph
createHomeUnitGraph hsc_env units =
unitEnv_new <$> traverse (fillHomeUnitEnv hsc_env home_units) (Map.fromList units)
where
home_units = Set.fromList $ map fst units
fillHomeUnitEnv :: HscEnv -> Set.Set UnitId -> DynFlags -> IO HomeUnitEnv
fillHomeUnitEnv hsc_env home_units dflags = do
(dbs, unit_state, home_unit, _) <- initUnits logger dflags Nothing home_units
pure $ HomeUnitEnv
{ homeUnitEnv_units = unit_state
, homeUnitEnv_unit_dbs = Just dbs
, homeUnitEnv_dflags = dflags
, homeUnitEnv_hpt = emptyHomePackageTable
, homeUnitEnv_home_unit = Just home_unit
}
where
logger = hsc_logger hsc_env
-----Original Message-----
From: Erdi, Gergo
Sent: Tuesday, June 21, 2022 5:42 PM
To: Matthew Pickering <matthewtpickering at gmail.com>
Cc: ÉRDI Gergo <gergo at erdi.hu>; GHC Devs <ghc-devs at haskell.org>; Montelatici, Raphael Laurent <Raphael.Montelatici at sc.com>
Subject: Re: Migration guide for multiple home units
Thanks, based on this I got things going. I might have to come back to you if it turns out something's still broken in my original full application.
This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at https: //www.sc.com/en/our-locations
Where you have a Financial Markets relationship with Standard Chartered PLC, Standard Chartered Bank and their subsidiaries (the "Group"), information on the regulatory standards we adhere to and how it may affect you can be found in our Regulatory Compliance Statement at https: //www.sc.com/rcs/ and Regulatory Compliance Disclosures at http: //www.sc.com/rcs/fm
Insofar as this communication is not sent by the Global Research team and contains any market commentary, the market commentary has been prepared by the sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied on for any other purpose and is subject to the relevant disclaimers available at https: //www.sc.com/en/regulatory-disclosures/#market-disclaimer.
Insofar as this communication is sent by the Global Research team and contains any research materials prepared by members of the team, the research material is for information purpose only and shall not be relied on for any other purpose, and is subject to the relevant disclaimers available at https: //research.sc.com/research/api/application/static/terms-and-conditions.
Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction. We may at times also request you to sign the term sheet to acknowledge the same.
Please visit https: //www.sc.com/en/regulatory-disclosures/dodd-frank/ for important information with respect to derivative products.
More information about the ghc-devs
mailing list