Fix unusable units and module reexport interaction (#21097)
This commit fixes an issue with ModUnusable introduced in df0f148f. In mkUnusableModuleNameProvidersMap we traverse the list of unusable units and generate ModUnusable origin for all the modules they contain: exposed modules, hidden modules, and also re-exported modules. To do this we have a two-level map: ModuleName -> Unit:ModuleName (aka Module) -> ModuleOrigin So for each module name "M" in broken unit "u" we have: "M" -> u:M -> ModUnusable reason However in the case of module reexports we were using the *target* module as a key. E.g. if "u:M" is a reexport for "X" from unit "o": "M" -> o:X -> ModUnusable reason Case 1: suppose a reexport without module renaming (u:M -> o:M) from unusable unit u: "M" -> o:M -> ModUnusable reason Here it's claiming that the import of M is unusable because a reexport from u is unusable. But if unit o isn't unusable we could also have in the map: "M" -> o:M -> ModOrigin ... Issue: the Semigroup instance of ModuleOrigin doesn't handle the case (ModUnusable <> ModOrigin) Case 2: similarly we could have 2 unusable units reexporting the same module without renaming, say (u:M -> o:M) and (v:M -> o:M) with u and v unusable. It gives: "M" -> o:M -> ModUnusable ... (for u) "M" -> o:M -> ModUnusable ... (for v) Issue: the Semigroup instance of ModuleOrigin doesn't handle the case (ModUnusable <> ModUnusable). This led to #21097, #16996, #11050. To fix this, in this commit we make ModUnusable track whether the module used as key is a reexport or not (for better error messages) and we use the re-export module as key. E.g. if "u:M" is a reexport for "o:X" and u is unusable, we now record: "M" -> u:M -> ModUnusable reason reexported=True So now, we have two cases for a reexport u:M -> o:X: - u unusable: "M" -> u:M -> ModUnusable ... reexported=True - u usable: "M" -> o:X -> ModOrigin ... reexportedFrom=u:M The second case is indexed with o:X because in this case the Semigroup instance of ModOrigin is used to combine valid expositions of a module (directly or via reexports). Note that module lookup functions select usable modules first (those who have a ModOrigin value), so it doesn't matter if we add new ModUnusable entries in the map like this: "M" -> { u:M -> ModUnusable ... reexported=True o:M -> ModOrigin ... } The ModOrigin one will be used. Only if there is no ModOrigin or ModHidden entry will the ModUnusable error be printed. See T21097 for an example printing several reasons why an import is unusable.
Showing
- compiler/GHC/Iface/Errors/Ppr.hs 4 additions, 3 deletionscompiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Iface/Errors/Types.hs 2 additions, 2 deletionscompiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Unit/Finder.hs 1 addition, 1 deletioncompiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs 1 addition, 1 deletioncompiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Unit/State.hs 39 additions, 13 deletionscompiler/GHC/Unit/State.hs
- testsuite/tests/driver/T21097/Makefile 7 additions, 0 deletionstestsuite/tests/driver/T21097/Makefile
- testsuite/tests/driver/T21097/T21097.stderr 16 additions, 0 deletionstestsuite/tests/driver/T21097/T21097.stderr
- testsuite/tests/driver/T21097/Test.hs 3 additions, 0 deletionstestsuite/tests/driver/T21097/Test.hs
- testsuite/tests/driver/T21097/all.T 4 additions, 0 deletionstestsuite/tests/driver/T21097/all.T
- testsuite/tests/driver/T21097/pkgdb/a.conf 12 additions, 0 deletionstestsuite/tests/driver/T21097/pkgdb/a.conf
- testsuite/tests/driver/T21097/pkgdb/b.conf 12 additions, 0 deletionstestsuite/tests/driver/T21097/pkgdb/b.conf
- testsuite/tests/driver/T21097/pkgdb/c.conf 12 additions, 0 deletionstestsuite/tests/driver/T21097/pkgdb/c.conf
- testsuite/tests/driver/T21097b/Makefile 7 additions, 0 deletionstestsuite/tests/driver/T21097b/Makefile
- testsuite/tests/driver/T21097b/T21097b.stdout 5 additions, 0 deletionstestsuite/tests/driver/T21097b/T21097b.stdout
- testsuite/tests/driver/T21097b/Test.hs 3 additions, 0 deletionstestsuite/tests/driver/T21097b/Test.hs
- testsuite/tests/driver/T21097b/all.T 6 additions, 0 deletionstestsuite/tests/driver/T21097b/all.T
- testsuite/tests/driver/T21097b/pkgdb/a.conf 10 additions, 0 deletionstestsuite/tests/driver/T21097b/pkgdb/a.conf
- testsuite/tests/driver/T21097b/pkgdb/b.conf 12 additions, 0 deletionstestsuite/tests/driver/T21097b/pkgdb/b.conf
- testsuite/tests/driver/T21097b/pkgdb/c.conf 12 additions, 0 deletionstestsuite/tests/driver/T21097b/pkgdb/c.conf
Loading
Please register or sign in to comment