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

Generate names directly? #12

Closed
tfausak opened this issue Mar 22, 2024 · 4 comments
Closed

Generate names directly? #12

tfausak opened this issue Mar 22, 2024 · 4 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@tfausak
Copy link
Owner

tfausak commented Mar 22, 2024

Currently Imp works by inserting import statements. However in theory it is possible for it to modify identifiers in place, changing them from Qual to Exact: https://hackage.haskell.org/package/ghc-9.8.2/docs/GHC-Types-Name-Reader.html#t:RdrName

I'm not sure how difficult this would be to pull off. An Exact is just a wrapper around a Name, and generating a Name requires a Unique. That should be possible with the name cache in the HSC env: https://hackage.haskell.org/package/ghc-9.8.2/docs/GHC-Driver-Env-Types.html#t:HscEnv

I'm also not sure if this would be "better" in any meaningful way or just different.

@tfausak tfausak added the question Further information is requested label Mar 22, 2024
@tfausak
Copy link
Owner Author

tfausak commented Mar 22, 2024

I forgot to mention that I made this issue because of #11 (comment) and more specifically https://gitlab.haskell.org/ghc/ghc/-/issues/21730#note_436908.

@tfausak
Copy link
Owner Author

tfausak commented Mar 24, 2024

I know how to do the scaffolding/refactoring part of this, but I'm not sure how to generate an Exact from a Qual. Summarizing my current thoughts:

  • A Qual is a ModuleName and an OccName together. Those are both essentially string-based. Nothing fancy going on.
  • An Exact is just a wrapper around a Name.
  • I think mkExternalName is the right constructor for making a Name in this situation. It requires four things: Unique, Module (not ModuleName), OccName, and SrcSpan.
  • Getting a Unique is easy. It's available through the HscEnv. Although it might be better to use one of the name cache helper functions instead of dealing with Unique directly.
  • Module is a tough one. We have a ModuleName, and it feels like the HscEnv should have enough context available to turn that into a Module. However I'm not familiar with this stuff and there's not a clear path forward for me. Conceptually I think I need to look up the module ID in some kind of table to find its associated package, then get the unit for that package. Or perhaps you can go directly from module name to unit.
  • OccName we already have from the Qual.
  • It's unclear if the SrcSpan is actually necessary or if it can be faked with something like generatedSrcSpan.

So really I just need something of type ModuleName -> Hsc Module and I would be able to try this out.

@tfausak
Copy link
Owner Author

tfausak commented Mar 31, 2024

I'm closing this as "not planned" for the reasons I outlined in #14. However if someone comes along and thinks this sounds interesting, I'm open to a PR.

@tfausak tfausak closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2024
@tfausak tfausak added the wontfix This will not be worked on label Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant