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

Ability to rewrite imports #33

Open
AriFordsham opened this issue Aug 8, 2021 · 2 comments
Open

Ability to rewrite imports #33

AriFordsham opened this issue Aug 8, 2021 · 2 comments

Comments

@AriFordsham
Copy link

This is motivated by the GHC API changes which, for a large part, change module names whilst leaving definitions unchanged.

It would be extremely useful to have the ability to change every import A to import B.

This issue involves a question:

  • Is this feasible with the current Retrie library? Can I have some guidance on what it would look like? I see a function getImports, but it's undocumented.

And a feature request:

  • Can we have this integrated in the interface/CLI?
@xich
Copy link
Contributor

xich commented Aug 18, 2021

Hmmm, this isn't currently supported, but wouldn't be hard to add.

I think we'd want to nail down exactly what we'd want to support, because it will inform the implementation. Some thoughts:

  1. We could have something like --change-import "Foo.Bar" "Baz.Quux" which is effectively a rewrite on the ModuleName type.
  2. We could support rewriting the whole import statement: --change-import "import Foo.Bar" "import Baz.Quux as Baz"
  3. Do we want to support rewriting explicit imports? (Maybe in v2 of this feature?) --change-import "import Foo.Bar (bar)" "import Baz.Quux (bar)"
  4. If we did support explicit imports, do we want quantifiers? --change-import "forall x y. import Foo.Bar (x, bar, y) = import Baz.Quux (y, bar, x)"

What do you think?

@AriFordsham
Copy link
Author

Regarding addressing the GHC use case, there are many ways of approaching the problem. Just implementing (1) if that is quicker/easier would definitely be already helpful.

In an ideal world, I'm not sure I understand (4) completely If it's just to reorder things, I don't see the point. It seems odd to index imported symbols by position/variable, as they're typically not thought of that way and the forall looks a bit confusing. However (3) seems great. What would be the drawback of providing extra power (besides development effort, which I can't really comment on?)

Some background on my GHC migration ideas: https://mail.haskell.org/pipermail/ghc-devs/2021-August/020099.html, although I don't have time to commit to this right now.

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

No branches or pull requests

2 participants