Simon Hengel pushed to branch wip/sol/reexported-error-message-refactor at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/Iface/Errors/Ppr.hs
    ... ... @@ -205,7 +205,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst
    205 205
                       provenance (ModOrigin{ fromOrigUnit = e,
    
    206 206
                                              fromExposedReexport = res,
    
    207 207
                                              fromPackageFlag = f })
    
    208
    -                    | Just True <- e
    
    208
    +                    | AvailableFromExposedUnit <- e
    
    209 209
                            = parens (text "from" <+> ppr (moduleUnit mod))
    
    210 210
                         | f && moduleName mod == m
    
    211 211
                            = parens (text "from" <+> ppr (moduleUnit mod))
    
    ... ... @@ -221,7 +221,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst
    221 221
                       provenance (ModUnusable _) = empty
    
    222 222
                       provenance (ModOrigin{ fromOrigUnit = e,
    
    223 223
                                              fromHiddenReexport = rhs })
    
    224
    -                    | Just False <- e
    
    224
    +                    | AvailableFromHiddenUnit <- e
    
    225 225
                            = parens (text "needs flag -package-id"
    
    226 226
                               <+> ppr (moduleUnit mod))
    
    227 227
                         | (pkg:_) <- rhs
    
    ... ... @@ -240,7 +240,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst
    240 240
           -> vcat (map pprMod mods)
    
    241 241
           where
    
    242 242
             unambiguousPackages = foldl' unambiguousPackage (Just []) mods
    
    243
    -        unambiguousPackage (Just xs) (m, ModOrigin (Just _) _ _ _)
    
    243
    +        unambiguousPackage (Just xs) (m, ModOrigin ((/= Renamed) -> True) _ _ _)
    
    244 244
                 = Just (moduleUnit m : xs)
    
    245 245
             unambiguousPackage _ _ = Nothing
    
    246 246
         GenericMissing pkg_hiddens mod_hiddens unusables files ->
    
    ... ... @@ -254,7 +254,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst
    254 254
         pprOrigin _ ModHidden = panic "cantFindErr: bound by mod hidden"
    
    255 255
         pprOrigin _ (ModUnusable _) = panic "cantFindErr: bound by mod unusable"
    
    256 256
         pprOrigin m (ModOrigin e res _ f) = sep $ punctuate comma (
    
    257
    -      if e == Just True
    
    257
    +      if e == AvailableFromExposedUnit
    
    258 258
               then [text "package" <+> ppr (moduleUnit m)]
    
    259 259
               else [] ++
    
    260 260
           map ((text "a reexport in package" <+>)
    

  • compiler/GHC/Unit/State.hs
    ... ... @@ -38,6 +38,7 @@ module GHC.Unit.State (
    38 38
             LookupResult(..),
    
    39 39
             ModuleSuggestion(..),
    
    40 40
             ModuleOrigin(..),
    
    41
    +        AvailableFromOriginalUnit(..),
    
    41 42
             UnusableUnit(..),
    
    42 43
             UnusableUnitReason(..),
    
    43 44
             pprReason,
    
    ... ... @@ -178,21 +179,26 @@ data ModuleOrigin =
    178 179
     
    
    179 180
         -- | Module is public, and could have come from some places.
    
    180 181
       | ModOrigin {
    
    181
    -        -- | @Just False@ means that this module is in
    
    182
    -        -- someone's @exported-modules@ list, but that package is hidden;
    
    183
    -        -- @Just True@ means that it is available; @Nothing@ means neither
    
    184
    -        -- applies.
    
    185
    -        fromOrigUnit :: Maybe Bool
    
    182
    +        fromOrigUnit :: AvailableFromOriginalUnit
    
    186 183
             -- | Is the module available from a reexport of an exposed package?
    
    187 184
             -- There could be multiple.
    
    188 185
           , fromExposedReexport :: [UnitInfo]
    
    189
    -        -- | Is the module available from a reexport of a hidden package?
    
    186
    +        -- | Is the module available from a reexport of a hidden unit?
    
    190 187
           , fromHiddenReexport :: [UnitInfo]
    
    191 188
             -- | Did the module export come from a package flag? (ToDo: track
    
    192 189
             -- more information.
    
    193 190
           , fromPackageFlag :: Bool
    
    194 191
           }
    
    195 192
     
    
    193
    +data AvailableFromOriginalUnit =
    
    194
    +    -- | the canonical module name is different from the requested name
    
    195
    +    Renamed
    
    196
    +    -- | the module is in someone's @exposed-modules@ list, but that unit is hidden
    
    197
    +  | AvailableFromHiddenUnit
    
    198
    +    -- | the module is available from the original unit under the requested name
    
    199
    +  | AvailableFromExposedUnit
    
    200
    +  deriving (Eq, Show)
    
    201
    +
    
    196 202
     -- | A unusable unit module origin
    
    197 203
     data UnusableUnit = UnusableUnit
    
    198 204
       { uuUnit        :: !Unit               -- ^ Unusable unit
    
    ... ... @@ -205,9 +211,9 @@ instance Outputable ModuleOrigin where
    205 211
         ppr (ModUnusable _) = text "unusable module"
    
    206 212
         ppr (ModOrigin e res rhs f) = sep (punctuate comma (
    
    207 213
             (case e of
    
    208
    -            Nothing -> []
    
    209
    -            Just False -> [text "hidden package"]
    
    210
    -            Just True -> [text "exposed package"]) ++
    
    214
    +            Renamed -> []
    
    215
    +            AvailableFromHiddenUnit -> [text "hidden package"]
    
    216
    +            AvailableFromExposedUnit -> [text "exposed package"]) ++
    
    211 217
             (if null res
    
    212 218
                 then []
    
    213 219
                 else [text "reexport by" <+>
    
    ... ... @@ -222,34 +228,36 @@ instance Outputable ModuleOrigin where
    222 228
     -- | Smart constructor for a module which is in @exposed-modules@.  Takes
    
    223 229
     -- as an argument whether or not the defining package is exposed.
    
    224 230
     fromExposedModules :: Bool -> ModuleOrigin
    
    225
    -fromExposedModules e = ModOrigin (Just e) [] [] False
    
    231
    +fromExposedModules True = ModOrigin AvailableFromExposedUnit [] [] False
    
    232
    +fromExposedModules False = ModOrigin AvailableFromHiddenUnit [] [] False
    
    226 233
     
    
    227 234
     -- | Smart constructor for a module which is in @reexported-modules@.  Takes
    
    228 235
     -- as an argument whether or not the reexporting package is exposed, and
    
    229 236
     -- also its 'UnitInfo'.
    
    230 237
     fromReexportedModules :: Bool -> UnitInfo -> ModuleOrigin
    
    231
    -fromReexportedModules True pkg = ModOrigin Nothing [pkg] [] False
    
    232
    -fromReexportedModules False pkg = ModOrigin Nothing [] [pkg] False
    
    238
    +fromReexportedModules True pkg = ModOrigin Renamed [pkg] [] False
    
    239
    +fromReexportedModules False pkg = ModOrigin Renamed [] [pkg] False
    
    233 240
     
    
    234 241
     -- | Smart constructor for a module which was bound by a package flag.
    
    235 242
     fromFlag :: ModuleOrigin
    
    236
    -fromFlag = ModOrigin Nothing [] [] True
    
    243
    +fromFlag = ModOrigin Renamed [] [] True
    
    237 244
     
    
    238 245
     instance Semigroup ModuleOrigin where
    
    239 246
         x@(ModOrigin e res rhs f) <> y@(ModOrigin e' res' rhs' f') =
    
    240 247
             ModOrigin (g e e') (res ++ res') (rhs ++ rhs') (f || f')
    
    241
    -      where g (Just b) (Just b')
    
    242
    -                | b == b'   = Just b
    
    243
    -                | otherwise = pprPanic "ModOrigin: package both exposed/hidden" $
    
    248
    +      where
    
    249
    +            g AvailableFromHiddenUnit AvailableFromHiddenUnit = AvailableFromHiddenUnit
    
    250
    +            g AvailableFromExposedUnit AvailableFromExposedUnit = AvailableFromExposedUnit
    
    251
    +            g Renamed x = x
    
    252
    +            g x Renamed = x
    
    253
    +            g _ _ = pprPanic "ModOrigin: package both exposed/hidden" $
    
    244 254
                         text "x: " <> ppr x $$ text "y: " <> ppr y
    
    245
    -            g Nothing x = x
    
    246
    -            g x Nothing = x
    
    247 255
     
    
    248 256
         x <> y = pprPanic "ModOrigin: module origin mismatch" $
    
    249 257
                      text "x: " <> ppr x $$ text "y: " <> ppr y
    
    250 258
     
    
    251 259
     instance Monoid ModuleOrigin where
    
    252
    -    mempty = ModOrigin Nothing [] [] False
    
    260
    +    mempty = ModOrigin Renamed [] [] False
    
    253 261
         mappend = (Semigroup.<>)
    
    254 262
     
    
    255 263
     -- | Is the name from the import actually visible? (i.e. does it cause
    
    ... ... @@ -257,12 +265,12 @@ instance Monoid ModuleOrigin where
    257 265
     originVisible :: ModuleOrigin -> Bool
    
    258 266
     originVisible ModHidden = False
    
    259 267
     originVisible (ModUnusable _) = False
    
    260
    -originVisible (ModOrigin b res _ f) = b == Just True || not (null res) || f
    
    268
    +originVisible (ModOrigin b res _ f) = b == AvailableFromExposedUnit || not (null res) || f
    
    261 269
     
    
    262 270
     -- | Are there actually no providers for this module?  This will never occur
    
    263 271
     -- except when we're filtering based on package imports.
    
    264 272
     originEmpty :: ModuleOrigin -> Bool
    
    265
    -originEmpty (ModOrigin Nothing [] [] False) = True
    
    273
    +originEmpty (ModOrigin Renamed [] [] False) = True
    
    266 274
     originEmpty _ = False
    
    267 275
     
    
    268 276
     -- | 'UniqFM' map from 'Unit' to a 'UnitVisibility'.
    
    ... ... @@ -586,7 +594,7 @@ resolvePackageImport unit_st mn pn = do
    586 594
         to_uid (mod, ModOrigin mo re_exps _ _) =
    
    587 595
           case mo of
    
    588 596
             -- Available directly, but also potentially from re-exports
    
    589
    -        Just True ->  (toUnitId (moduleUnit mod)) : map unitId re_exps
    
    597
    +        AvailableFromExposedUnit ->  (toUnitId (moduleUnit mod)) : map unitId re_exps
    
    590 598
             -- Just available from these re-exports
    
    591 599
             _ -> map unitId re_exps
    
    592 600
         to_uid _ = []
    
    ... ... @@ -1932,8 +1940,7 @@ lookupModulePackage pkgs mn mfs =
    1932 1940
             case origin of
    
    1933 1941
               ModOrigin {fromOrigUnit, fromExposedReexport} ->
    
    1934 1942
                 case fromOrigUnit of
    
    1935
    -              -- Just True means, the import is available from its original location
    
    1936
    -              Just True ->
    
    1943
    +              AvailableFromExposedUnit ->
    
    1937 1944
                     pure [orig_unit]
    
    1938 1945
                   -- Otherwise, it must be available from a reexport
    
    1939 1946
                   _ -> pure fromExposedReexport
    
    ... ... @@ -1974,19 +1981,21 @@ lookupModuleWithSuggestions' pkgs mod_map name mb_pn
    1974 1981
                 -> (hidden_pkg, x:hidden_mod, unusable, exposed)
    
    1975 1982
               ModUnusable _
    
    1976 1983
                 -> (hidden_pkg, hidden_mod, x:unusable, exposed)
    
    1977
    -          ModOrigin { fromOrigUnit = origAvailableUnderSameName, fromHiddenReexport }
    
    1984
    +          ModOrigin { fromOrigUnit, fromHiddenReexport }
    
    1978 1985
                 | originEmpty origin
    
    1979 1986
                 -> (hidden_pkg,   hidden_mod, unusable, exposed)
    
    1980 1987
                 | originVisible origin
    
    1981 1988
                 -> (hidden_pkg, hidden_mod, unusable, x:exposed)
    
    1982 1989
                 | otherwise
    
    1983
    -            -> (reexports ++ maybe id (:) origUnit hidden_pkg, hidden_mod, unusable, exposed)
    
    1990
    +            -> (reexports ++ maybe id (:) hiddenOrigUnit hidden_pkg, hidden_mod, unusable, exposed)
    
    1984 1991
                 where
    
    1985 1992
                   reexports :: [UnitInfo]
    
    1986 1993
                   reexports = sortOn unitId fromHiddenReexport
    
    1987 1994
     
    
    1988
    -              origUnit :: Maybe UnitInfo
    
    1989
    -              origUnit = origAvailableUnderSameName >> lookupUnit pkgs (moduleUnit m)
    
    1995
    +              hiddenOrigUnit :: Maybe UnitInfo
    
    1996
    +              hiddenOrigUnit = case fromOrigUnit of
    
    1997
    +                AvailableFromHiddenUnit -> lookupUnit pkgs (moduleUnit m)
    
    1998
    +                _ -> Nothing
    
    1990 1999
     
    
    1991 2000
         unit_lookup p = lookupUnit pkgs p `orElse` pprPanic "lookupModuleWithSuggestions" (ppr p <+> ppr name)
    
    1992 2001
         mod_unit = unit_lookup . moduleUnit
    
    ... ... @@ -2012,7 +2021,7 @@ lookupModuleWithSuggestions' pkgs mod_map name mb_pn
    2012 2021
               ModOrigin { fromOrigUnit = e, fromExposedReexport = res,
    
    2013 2022
                           fromHiddenReexport = rhs }
    
    2014 2023
                 -> ModOrigin
    
    2015
    -                { fromOrigUnit        = if match_pkg pkg then e else Nothing
    
    2024
    +                { fromOrigUnit        = if match_pkg pkg then e else Renamed
    
    2016 2025
                     , fromExposedReexport = filter match_pkg res
    
    2017 2026
                     , fromHiddenReexport  = filter match_pkg rhs
    
    2018 2027
                     , fromPackageFlag     = False -- always excluded
    

  • utils/haddock/haddock-api/src/Haddock/Interface/AttachInstances.hs
    ... ... @@ -85,7 +85,7 @@ attachInstances expInfo ifaces instIfaceMap isOneShot = do
    85 85
                       }
    
    86 86
                   ) <-
    
    87 87
                   nonDetUniqMapToList mod_map
    
    88
    -          , fromOrig == Just True || not (null reExp)
    
    88
    +          , fromOrig == AvailableFromExposedPackage || not (null reExp)
    
    89 89
               ]
    
    90 90
           mods_to_load = moduleSetElts mods
    
    91 91
           -- We need to ensure orphans in modules outside of this package are included.