Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't find modules after switch from v0.9.0.4 to v0.9.0.5 #142

Closed
polymorphicengine opened this issue Feb 21, 2022 · 7 comments · Fixed by #147
Closed

can't find modules after switch from v0.9.0.4 to v0.9.0.5 #142

polymorphicengine opened this issue Feb 21, 2022 · 7 comments · Fixed by #147

Comments

@polymorphicengine
Copy link

Hey,
I made some changes to my gui project for tidal recently and decided to publish a new release. I didn't change anything relating to hint, so I thought that the workflow I had should be still fine. I also decicded to use the newest version of hint (previously I used 0.9.0.4).

But I noticed that in the new release hint wasn't able to find any of the haskell modules. This makes me think something changed in the way the interpreter is called with arguments? The arguments I use with my interpreter are:

args:: String -> [String]
args lib = ["-clear-package-db", "-package-db", lib ++ "haskell-libs/package.conf.d", "-package-db", lib ++ "haskell-libs/package.db", "-v"]

where lib is dependent on the location of the binary file. This works fine with hint 0.9.0.4, but is apprently broken with the latest version.

@polymorphicengine polymorphicengine changed the title can't find packages after switch from v0.9.0.4 to v0.9.0.5 can't find modules after switch from v0.9.0.4 to v0.9.0.5 Feb 21, 2022
@gelisam
Copy link
Contributor

gelisam commented Mar 6, 2022

I confirm that I can reproduce this locally.

The only two changes which happened in 0.9.0.5 are to add support for ghc-9.2.1 and to refactor the code to make this support easier to add. Perhaps that refactoring accidentally broke something?

In any case, the first step is to write a test case so that this regression doesn't occur again!

@gelisam
Copy link
Contributor

gelisam commented Mar 6, 2022

git bisect blames a73aceb, which is indeed a refactoring which shouldn't have changed anything; especially since it only affects logging!

Pinging @brandon-leapyear, who authored the refactoring. Any idea how that refactoring could possibly affect which package databases the ghc library can see?

@brandon-leapyear
Copy link
Collaborator

brandon-leapyear commented Mar 6, 2022 via email

@gelisam
Copy link
Contributor

gelisam commented Mar 6, 2022

That fixes it, thanks!

@gelisam
Copy link
Contributor

gelisam commented Mar 6, 2022

I have a hypothesis as to how configuring a logger can possibly have an effect on package databases. Here's the relevant code:

GHC.modifyLogger (const logger)
...
(df2, ...) <- parseDynamicFlags ... ["-package-db=..."]
GHC.setSessionDynFlags df2

I'm using ghc-8.4.4, and so modifyLogger is implemented in terms of setSessionDynFlags:

df <- getSessionDynFlags
setSessionDynFlags df{log_action = const logger $ DynFlags.log_action df}
...
(df2, ...) <- runGhc $ parseDynamicFlags ... ["-package-db=..."]
GHC.setSessionDynFlags df2

Observe that setSessionDynFlags is called twice: once without the -package-db arguments, and once with them. According to its documentation, setSessionDynFlags does many things, including reading the package database unless it has already been read. So I think the first call reads the default package database and sets some packageDbHasBeenRead flag indicating that the package databases have been read, then the second call, which should normally be reading the package databases specified by the -package-db arguments, skips reading the package databases because of the packageDbHasBeenRead flag.

gelisam added a commit that referenced this issue Mar 6, 2022
'unsafeRunInterpreterWithArgs' is often used to specify the path to a
non-default package database, using the @-package-db@ flag.
Unfortunately, a previous refactoring accidentally broke this workflow.

The refactoring seems innocent on the surface, so it's worth explaining
how that refactoring managed to break anything.

The refactoring defined a 'modifyLogger' shim corresponding to the
ghc-9.2 function of the same name. In older versions of ghc,
'modifyLogger' is implemented using 'setSessionDynFlags'. As a result,
it now matters whether the logger is configured before other calls to
'setSessionDynFlags'.

In particular, the logger was configured too early, before the
@-package-db@ flags were given to ghc using a second call to
'setSessionDynFlags'. As a result, the first call to
'setSessionDynFlags', the one hidden inside 'modifyLogger', was reading
the default package databases and setting internal flag indicating that
the package databases have been read. Then, the second call to
'setSessionDynFlags' which specifies non-default package databases with
@-package-db@ flags, saw this internal flag and decided not to read the
package databases a second time.

fixes #142
@gelisam
Copy link
Contributor

gelisam commented Mar 30, 2022

Now fixed in HEAD; the next step is to release a new version on hackage. And maybe to deprecate the version which has the bug?

@gelisam
Copy link
Contributor

gelisam commented Mar 30, 2022

0.9.0.6 is now published, and 0.9.0.5 is now deprecated. Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants