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" AGAIN!!!! #237

Merged

Conversation

9999years
Copy link
Member

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.

ghciwatch/src/ghci/mod.rs

Lines 698 to 699 in dbba61b

self.targets
.insert_source_path(path.clone(), TargetKind::Path);

This fixes the bug and adds an assert! to fail faster and more obviously if it happens again.

Prior art

9999years added 2 commits May 15, 2024 16:29
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.
Copy link

linear bot commented May 15, 2024

@github-actions github-actions bot added the patch Bug fixes or non-functional changes label May 15, 2024
@9999years 9999years added the module defined in multiple files The GHCi bug that keeps on giving! label May 15, 2024
@9999years 9999years requested a review from Gabriella439 May 15, 2024 23:33
@9999years 9999years enabled auto-merge (squash) May 15, 2024 23:36
///
/// This may either be a dotted module name like `My.Cool.Module` or a path like
/// `src/My/Cool/Module.hs`.
pub name: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but I think making the String a field for each of the Path and Module constructors for TargetKind would make it less likely to accidentally confuse the two types of Strings (i.e. using a module where a path was expected or vice versa). However, I realize that's a more extensive refactor

@9999years 9999years merged commit e1e37e8 into main May 16, 2024
30 checks passed
@9999years 9999years deleted the rebeccat/dux-2298-fix-module-defined-in-multiple-files branch May 16, 2024 00:00
Copy link
Contributor

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