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

Fix "module defined in multiple files" with eval commands #214

Conversation

9999years
Copy link
Member

@9999years 9999years commented Apr 11, 2024

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:

ghci> :show targets
Foo
Bar
Baz

Then, an eval command in (for example) module Foo is executed. To start with, the module is added and explicitly interpreted:

ghci> :add *src/Foo.hs

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.

Copy link

linear bot commented Apr 11, 2024

@github-actions github-actions bot added the patch Bug fixes or non-functional changes label Apr 11, 2024
@9999years 9999years force-pushed the rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files branch 2 times, most recently from 8b93a0f to 8cadd8a Compare April 11, 2024 22:25
@9999years 9999years force-pushed the rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files branch from 8cadd8a to ddeddbe Compare April 11, 2024 22:28
@9999years 9999years marked this pull request as ready for review April 11, 2024 22:31
@9999years 9999years merged commit 77ef929 into main Apr 15, 2024
28 checks passed
@9999years 9999years deleted the rebeccat/dux-2107-eval-commands-fail-with-module-is-defined-in-multiple-files branch April 15, 2024 20:04
Copy link
Contributor

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 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants