<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p>Hi,</p>
<p>This part of the API is still awful and a bit in flux to make it
less so. Modifying the UnitState directly isn't currently
supported and seems difficult to do correctly (e.g. in your code
snippet below you don't modify the moduleNameProvidersMap field),
so it would probably be better to recreate the UnitState from
scratch with mkUnitState/initUnitConfig.<br>
</p>
<p>You may also have a look to
GHC.Driver.Backpack.{withBkpSession,buildUnit} in TcSession mode
which registers virtual units for Backpack's .bkp files similarly
to what you want to do. If you really don't want to use the
filesystem at all, however, I think you will have to deal with
moving MyLib from the HPT to the EPS and I don't know if it is
easily feasible (Backpack resets these tables via withTempSession
so that interface files are read from disk as usual instead iiuc).</p>
<p>Good luck :)<br>
Sylvain<br>
</p>
<br>
<div class="moz-cite-prefix">On 25/06/2021 11:17, Erdi, Gergo via
ghc-devs wrote:<br>
</div>
<blockquote type="cite"
cite="mid:HK0PR03MB4867143C018928AE9FE37A8FE9069@HK0PR03MB4867.apcprd03.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}@font-face
{font-family:"Lucida Console";
panose-1:2 11 6 9 4 5 4 2 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
{mso-style-priority:34;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
{mso-style-priority:34;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
{mso-style-priority:34;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}span.EmailStyle22
{mso-style-type:personal-compose;
font-family:"Arial",sans-serif;
color:windowtext;
font-weight:normal;
font-style:normal;}.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0in;}ul
{margin-bottom:0in;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<p class="msipheader7557e74b" style="margin:0" align="Left"><span
style="font-size:9.0pt;font-family:Arial;color:#317100">PUBLIC</span></p>
<br>
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">I
have the following to .hs files:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<ol style="margin-top:0in" type="1" start="1">
<li class="MsoListParagraphCxSpFirst"
style="margin-left:-.25in;mso-add-space:auto;mso-list:l2
level1 lfo4">
<span
style="font-size:10.0pt;font-family:"Arial",sans-serif">MyLib.hs:<br>
<br>
module MyLib where<br>
…<br>
<br>
<o:p></o:p></span></li>
<li class="MsoListParagraphCxSpLast"
style="margin-left:-.25in;mso-add-space:auto;mso-list:l2
level1 lfo4">
<span
style="font-size:10.0pt;font-family:"Arial",sans-serif">Test.hs:<br>
<br>
{-# LANGUAGE PackageImports #-}<br>
module Test where<br>
import “my-pkg” MyLib<br>
…<o:p></o:p></span></li>
</ol>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">I
would like to parse/typecheck/load MyLib.hs into some Unit
“my-unit”, then add that to the package “my-pkg”, and then
typecheck Test.hs, all in-proc using the GHC API, without
putting any other files on disk. How do I do that?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">What
I tried is loading MyLib.hs after setting the homeUnitId in
the DynFlags to “my-unit”, then editing the packageNameMap
in the unitState of the DynFlags to may “my-pkg” to
“my-unit”:<br>
<br>
</span><span style="font-size:10.0pt;font-family:Consolas">setHomeUnit
:: (GhcMonad m) => UnitId -> m ()<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">setHomeUnit
unitId = do<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> dflags
<- getSessionDynFlags<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
modifySession $ \h -> h{ hsc_dflags = dflags{ homeUnitId
= unitId } }<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">registerUnit
:: (GhcMonad m) => PackageName -> UnitId -> m ()<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">registerUnit
pkg unitId = modifySession $ \h -> h{ hsc_dflags =
addUnit $ hsc_dflags h }<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> where<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> addUnit
dflags = dflags<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> {
unitState = let us = unitState dflags in us<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> {
packageNameMap = M.insert pkg (Indefinite unitId Nothing) $
packageNameMap us<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">pipeline = do<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
setHomeUnit myUnit<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
loadModule =<< typecheckModule =<< parseModule
=<< modSumarryFor “MyLib”<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
registerUnit myPkg myUnit<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
setHomeUnit mainUnitId<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:Consolas">
typecheckModule =<< parseModule =<<
modSumarryFor “Test”<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">Alas,
this doesn’t work: the import of `MyLib` from `my-pkg` fails
with:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.0pt;font-family:"Lucida
Console"">input/linking/Test.hs:5:1: error:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.0pt;font-family:"Lucida
Console""> Could not find module ‘MyLib’<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Lucida
Console""> It is not a module in the current
program, or in any known package.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Lucida
Console""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">TBH
I’m not very surprised that it didn’t work – that
registerUnit function is doing some pretty deep surgery on
the unitState that probably breaks several invariants.
Still, I wasn’t able to find a better way – all the
functions in GHC.Unit.State seem to be for querying only.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Arial",sans-serif">
Gergo<o:p></o:p></span></p>
</div>
<br clear="all">
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<br>
<br>
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<br>
<br>
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.<br>
<br>
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.
<br>
<br>
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.<br>
<br>
Please visit https:
//www.sc.com/en/regulatory-disclosures/dodd-frank/ for important
information with respect to derivative products.<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
ghc-devs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</pre>
</blockquote>
</body>
</html>