Hi Gergo, Some things I noticed:
* The HPT only contains modules from the current home unit. It seems that registerModule ignores this so you break this invariant. * It seems that `Instance` contains an orphan, but you don't fill in the `deps` field when making a `ModIface`, which should contain all the orphan modules below the module you are compiling. I think that if you fill in `deps` correctly then things may work out. `Dependencies` eventually becomes `ImportAvail`, which gets consulted by `tcVisibleOrphanMods` which is called in `tcGetInstEnvs` which is called by `matchInstEnv`. Matt On Tue, Aug 24, 2021 at 3:20 AM Erdi, Gergo via ghc-devs <ghc-devs@haskell.org> wrote: > > PUBLIC > > > Hi, > > > > I am trying to typecheck & load three modules using the GHC API. The first > one defines a class, the second one defines an instance of said class, and > the third one uses the instance (attached as Class.src, Instance.src and > Use.src, respectively). The problem is that when I typecheck Use.src, it > complains about the missing instance. It should be noted that the class is > found, only the instance isn’t. > > > > My code is bypassing the normal GHC driver to feed it modules instead of > letting GHC itself come up with dependencies and then loading them from disk; > that is because in my real use case, some dependencies will have interfaces > generated on the fly (there is no underlying Haskell source code), or loaded > over HTTP, etc. So I am using parseModule and typeCheckModule on each module, > make a ModIface from each, and then I try to register them with GHC, by > extending the HPT, the moduleNameProvidersMap, and the EPS. Evidently, this > is not enough, and the instances should be registered somewhere else as well > – where is that place? > > > > I have attached a simplified version of my code as Main.hs; it is targeting > the GHC 9.0 API. It hardcodes the GHC 9.0 package.conf.d due to laziness on > my part; please change line 96 to your environment before running it. As > written, it fails when typechecing Use.src with: > > > > input/Use.src:7:7: error: > > • No instance for (C X) arising from a use of ‘method’ > > • In the expression: method > > In an equation for ‘foo’: foo = method > > | > > 7 | foo = method > > | ^^^^^^ > > > > Thanks, > > Gergo > > > 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. > _______________________________________________ > ghc-devs mailing list > ghc-devs@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs