[GHC] #8407: Module re-exports at the package level

#8407: Module re-exports at the package level ------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- For various package reorganization purposes, especially for possibly turning `base` into a shim package that re-exports some modules from more specialized packages, good support for module re-exports would be nice. I wrote up a design spec at ModuleReexports; this bug is to track the progress. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): This is primarily a Cabal question, isn't it? If Cabal wants to move this way, I'd be happy for GHC to move to accommodate. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): I’ll open appropriate tickets against Cabal and haddock if there is consensus that the proposal is useful and the syntax and semantics are agreed on – currently, this is just a draft. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by ezyang): Hello nomeata, are you still working on this? This is on the hotpath for Backpack implementation work so I will probably go ahead and implement this if you are not working on it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by ezyang): * keywords: => backpack -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Not working on it here, so please do go ahead. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by ezyang): * owner: => ezyang -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by ezyang): Here is an annoying problem for implementing this functionality. Module reexports should roughly be analogous to how we deal with type/declaration reexports at the Haskell source level. To briefly overview how that mechanism works, we have a phase of compilation called "renaming", which takes all identifiers and figures out what true names they refer to. This is done by consulting the hi files associated with imported modules, which record the original name of any identifiers they export. By analogy, the installed package information file is like an "hi" file, and we would like it to store a pointer to the original name of the module (in this case, the InstalledPackageId and original module name, if renaming is allowed.) However, there is trouble in paradise. Entries in the InstalledPackageDb are created by the Cabal library; however, the Cabal library has no knowledge about module resolution (it only looks at the dependencies to do dependency resolution): all of this logic is in GHC proper (Packages and Finder). So at the time Cabal is writing the installed package info, it would need to consult GHC in order to figure out where modules actually came from! This seems like a design smell. The alternative is to do module resolution in GHC. Here, we augment the creation of our module map (when processing `-package` flags) so that when we see a reexport, we consult the existing map and insert a pointer to precisely the original import. If the packages are passed to us in topologically sorted order (which Cabal seems to do today), then we only pay the cost of a single map lookup for every reexported module we encounter. The downside is that this mechanism is now no longer symmetric with original names. It's not really clear which one is better. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by ezyang): Also, so minor UI things to watch out for: 1. Suppose a module Foo is defined by package a, and reexported by package b. I misspell my import and attempt to import module Fooo (sic). Clearly, when I give the list of corrections, I should only report Foo once. Now, suppose I have another module Foo defined by package c, so in our message we want to report that the module was found in multiple packages. In this case, we want to say "it was found in multiple packages: a (reexported by b), c" (and not just "a, c") 2. When we validate an entry in the installed package database, should we check if the reexported modules truly exist in the original package? Depending on what representation we have in the package database, this may not even be well defined. In any case, dependency validation should pick up most shenanigans. 3. In some functions, including packageDbModules from the GHC API, we asked to provide a `Module` for a re-exported module. Should the module returned be resolved to the original exporter, or still be the original name of the module? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by ezyang): SPJ thought of a good way around the implementation problem: we should implement a "mini" module finder in ghc-pkg, which simply takes all of the dependencies listed in the package, and reads their entries in order to resolve a module reexport. We hold the invariant that reexports in the installed package database point to the original name, so once we find the relevant entry, we know the original name. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: normal | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by ezyang): Initial CR: https://phabricator.haskell.org/D41 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: high | Milestone: Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by ezyang): * priority: normal => high -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level -------------------------------------+------------------------------------ Reporter: nomeata | Owner: ezyang Type: feature request | Status: new Priority: high | Milestone: 7.10.1 Component: Package system | Version: 7.6.3 Resolution: | Keywords: backpack Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by thoughtpolice): * milestone: => 7.10.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level
-------------------------------------+------------------------------------
Reporter: nomeata | Owner: ezyang
Type: feature request | Status: new
Priority: high | Milestone: 7.10.1
Component: Package system | Version: 7.6.3
Resolution: | Keywords: backpack
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Edward Z. Yang

#8407: Module re-exports at the package level -------------------------------------+------------------------------------- Reporter: nomeata | Owner: ezyang Type: feature | Status: closed request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: Package | Keywords: backpack system | Architecture: Unknown/Multiple Resolution: fixed | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner: ezyang
Type: feature | Status: closed
request | Milestone: 7.10.1
Priority: high | Version: 7.6.3
Component: Package | Keywords: backpack
system | Architecture: Unknown/Multiple
Resolution: fixed | Difficulty: Unknown
Operating System: | Blocked By:
Unknown/Multiple | Related Tickets:
Type of failure: |
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by jrp):
This fix seems to break the current master build on OS X:
{{{
compiler/main/Packages.lhs:867:16:
error: unterminated function-like macro invocation
where -- ASSERT(m == m' && pkg == pkg' && e == e'
^
compiler/HsVersions.h:39:9: note: macro 'ASSERT' defined here
#define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__
__LINE__) else
^
1 error generated.
<

#8407: Module re-exports at the package level -------------------------------------+------------------------------------- Reporter: nomeata | Owner: ezyang Type: feature | Status: closed request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: Package | Keywords: backpack system | Architecture: Unknown/Multiple Resolution: fixed | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by hvr): We really ought to switch to something like `cpphs` (which we can tweak to be better aware of Haskell syntax) for milestone:7.10.1 than having to keep in mind that there's now a 2nd `cpp` out there with slightly different semantics which keeps breaking builds... :-/ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8407#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8407: Module re-exports at the package level
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner: ezyang
Type: feature | Status: closed
request | Milestone: 7.10.1
Priority: high | Version: 7.6.3
Component: Package | Keywords: backpack
system | Architecture: Unknown/Multiple
Resolution: fixed | Difficulty: Unknown
Operating System: | Blocked By:
Unknown/Multiple | Related Tickets:
Type of failure: |
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by ezyang):
I pushed a bandaid fix
{{{
commit 9487305393307d5eb34069c5821c11bb98b5ec90
Author: Edward Z. Yang
participants (1)
-
GHC