-
Notifications
You must be signed in to change notification settings - Fork 841
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
GHCI fails to load in latest rc (2.5.0.1) #5407
Comments
Quoting @tfausak from sol/hpack#303 (comment) in case someone runs into the same problem and needs a quick fix:
I am interested to see if there may be a better or different solution since technically we're seeing a breaking change across stack versions (even if it does fix a different bug). Anyways feel free to close if this is the expected solution. |
For what it's worth, I'm not sure Stack is doing anything wrong here. If I have a package with two components that define the same module and then I try to load that package in GHCi, what should happen? Here's proof that you can run into the same problem with manually generated modules: > stack --version
Version 2.3.3, Git revision cb44d51bed48b723a5deb08c3348c0b3ccfc437e x86_64 hpack-0.33.0 > cat stack.yaml
resolver: ghc-8.10.2 > cat gh5407.cabal
name: gh5407
version: 0
build-type: Simple
cabal-version: >= 1.2
library
build-depends: base
hs-source-dirs: lib
other-modules: Problem
executable gh5407
build-depends: base
main-is: Main.hs
hs-source-dirs: exe
other-modules: Problem > cat exe/Main.hs
main = pure () > cat exe/Problem.hs
module Problem where > cat lib/Problem.hs
module Problem where > stack ghci
Using main module: 1. Package `gh5407' component gh5407:exe:gh5407 with main-is file: /tmp/tmp.TjAmpcgNF3/exe/Main.hs
Configuring GHCi with the following packages: gh5407
* * * * * * * *
Error: Multiple files use the same module name:
* Problem found at the following paths
* /tmp/tmp.TjAmpcgNF3/exe/Problem.hs (gh5407:exe:gh5407)
* /tmp/tmp.TjAmpcgNF3/lib/Problem.hs (gh5407:lib)
* * * * * * * *
Not attempting to start ghci due to these duplicate modules.
Use --no-load to try to start it anyway, without loading any modules (but these are still likely to cause errors) Even though the files happen to be identical, GHCi refuses to load both of them at the same time. In this particular situation you can work around the problem by putting the shared module in a common place that both components can use. That way GHCi isn't trying to load the same module twice from different paths. That suggests that perhaps Stack should be generating at most one |
Interesting. Here's how this happens, I think:
My question at this point: Why does I modified @tfausak's example a little by adding
Now let's run GHCi directly, thus bypassing
Now let's swap the two directories,
So, GHCi seems to be perfectly able to deal with ambiguous modules. It seems to disambiguate via the order in which the directories are given on the command line. That's why I'm wondering why If it's not strictly needed, then removing the check should fix @aschmois's issue, i.e., it should fix things for people who have to run GHCi with multiple components that provide more than one Or maybe just turn a failed duplicate check into a warning instead of completely getting rid of it? |
@uncle-betty I'm not familiar with this code path. If you think disabling this check will address this problem, can you open a PR? The alternative will be backing out #5393 for the 2.5 release. |
Thanks, @snoyberg, for the feedback. I'll try to learn a little more and then come back with a proposal. @mgsloan - quick question: You seem to have contributed the duplicate module check for Background: For a package This wasn't an issue in earlier I recently submitted PR #5393 to change this behavior to improve I think that I am now facing two options:
As shown in my previous comment, it seems that GHCi doesn't mind duplicate modules. It seems to disambiguate by simply visiting the directories given by |
@uncle-betty The duplicate module check is because ghci cannot load modules with the same name, at least as far as I recall. Most of the checks in the implementation of |
@mgsloan, thanks for looking into this and for sharing your insights. Yes, it seems that GHCi cannot load multiple different modules of the same name. As far as I can see, you'll always end up with the first matching module of that name, where "first" is defined by the order in which So, in your opinion, would it be correct to say that the duplicate check is there to prevent users from accidentally ending up in confusion situations where they are in GHCi, |
@uncle-betty I don't recall the particular behavior of multiple modules. But, if it does not cause an error, then it will certainly cause confusing, inconsistent behavior. If code you are loading depends on both modules that share the same name, then one will be used instead, hopefully causing a type error. Worst case, there is some compatibility between the interfaces of the two modules, and you actually get wrong behavior from your program. Behavioral differences and type errors that don't happen in a regular build are quite bad, definitely not the kind of property we want from a tool. I haven't read this issue's discussion, but I saw it has something to do with Paths_ modules and cabal components. If the redundant Paths_ modules do not vary in content between components, then I suggest picking one via some heuristic such as "most recently updated file". |
Would it be reasonable to change the duplicate module check from an error into a warning? There's a similar check for components having different |
That sounds like a great solution @tfausak. @uncle-betty would you be interested in sending a PR? It would be great to get this in sooner rather than later, since this is the last issue holding up the 2.5 release. |
For what it's worth it looks like GHC will soon be able to support multiple home units, which might address this problem: https://mpickering.github.io/ide/posts/2020-10-12-multiple-home-units.html |
Turns out that was a lot simpler than I thought. PR here if others can test it: #5413 |
…odules Warn, not error, on duplicate modules (fixes #5407)
General summary/comments (optional)
On the newest rc ghci can no longer be run for multiple components with autogen files.
Steps to reproduce
I have prepared a small repo to reproduce:
Expected
In version 2.3.3 ghci loaded fine.
Actual
In version 2.5.0.1 rc ghci failed to load with:
Stack version
Method of installation
The text was updated successfully, but these errors were encountered: