-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix "module defined in multiple files" with eval commands #214
Merged
9999years
merged 2 commits into
main
from
rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files
Apr 15, 2024
Merged
Fix "module defined in multiple files" with eval commands #214
9999years
merged 2 commits into
main
from
rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files
Apr 15, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9999years
force-pushed
the
rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files
branch
2 times, most recently
from
April 11, 2024 22:25
8b93a0f
to
8cadd8a
Compare
9999years
force-pushed
the
rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files
branch
from
April 11, 2024 22:28
8cadd8a
to
ddeddbe
Compare
Gabriella439
approved these changes
Apr 15, 2024
9999years
deleted the
rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files
branch
April 15, 2024 20:04
9999years
added a commit
that referenced
this pull request
May 15, 2024
In #214, we had a situation where modules were loaded: ghci> :show targets Foo Bar Baz And then an eval comment in (e.g.) `Foo` causes the module to be added and explicitly interpreted by path: ghci> :add *src/Foo.hs Then, we have `Foo` loaded by name (`Foo`) and by path (`src/Foo.hs`), which triggers the dreaded bug. At the time I proposed this fix, correctly: > I think we can fix this by keeping track of how each module is added > to the session -- as a path or as a module name -- and then only using > that form going forward. I threaded some extra information to the `:show targets` parser to track if modules were listed as names or paths, **but then at the end of `Ghci::interpret_module` I would always insert the module into the target set as a `TargetKind::Path`,** meaning that the *next* time the comment was evaluated, the module would be loaded as a path, causing the error. https://github.com/MercuryTechnologies/ghciwatch/blob/dbba61bbdec9a86f97051b12647e51b7be4fd484/src/ghci/mod.rs#L698-L699 This fixes the bug and adds an `assert!` to fail faster and more obviously if it happens again.
9999years
added
the
module defined in multiple files
The GHCi bug that keeps on giving!
label
May 15, 2024
9999years
added a commit
that referenced
this pull request
May 16, 2024
In #214, we had a situation where modules were loaded: ghci> :show targets Foo Bar Baz And then an eval comment in (e.g.) `Foo` causes the module to be added and explicitly interpreted by path: ghci> :add *src/Foo.hs Then, we have `Foo` loaded by name (`Foo`) and by path (`src/Foo.hs`), which triggers the dreaded bug. At the time I proposed this fix, correctly: > I think we can fix this by keeping track of how each module is added to the session — as a path or as a module name — and then only using that form going forward. I threaded some extra information to the `:show targets` parser to track if modules were listed as names or paths, **but then at the end of `Ghci::interpret_module` I would always insert the module into the target set as a `TargetKind::Path`,** meaning that the *next* time the comment was evaluated, the module would be loaded as a path, causing the error. https://github.com/MercuryTechnologies/ghciwatch/blob/dbba61bbdec9a86f97051b12647e51b7be4fd484/src/ghci/mod.rs#L698-L699 This fixes the bug and adds an `assert!` to fail faster and more obviously if it happens again. ## Prior art - #37 - #77 - #125 - #214
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
module defined in multiple files
The GHCi bug that keeps on giving!
patch
Bug fixes or non-functional changes
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our favorite bug is back! We have a situation where
ghciwatch
loads all the modules at the start of the session, so they're all loaded:Then, an eval command in (for example) module
Foo
is executed. To start with, the module is added and explicitly interpreted:Unfortunately, this always uses the module path (see #171), so if
ghciwatch
wasn't the one to load the module (e.g. it was loaded at the start of the session), the module path and module name will conflict and lead tot he dreaded "module is defined in multiple files".See: https://gitlab.haskell.org/ghc/ghc/-/issues/13254#note_525037
Solution
I think we can fix this by keeping track of how each module is added to the session — as a path or as a module name — and then only using that form going forward.