Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC

Commits:

18 changed files:

Changes:

  • compiler/GHC/Builtin.hs
    ... ... @@ -372,11 +372,6 @@ Wrinkles
    372 372
        keeps types and classes in the global type envt, but `Id`s in the local type envt.
    
    373 373
        (Ids move to the global type env during zonking; see `zonkTopDecls`.)
    
    374 374
     
    
    375
    -(KN5) If we are not using -frebindable-known-names, yet GHC.Essentials is still not
    
    376
    -  in scope, then we don't add the `default Num (Integer, Double)` declaration
    
    377
    -  to the module being compiled. This relaxation makes it possible for a library
    
    378
    -  which does not use any known-key at all (namely: `composition`) to compile
    
    379
    -  successfully without a dependency on base nor ghc-internal.
    
    380 375
     
    
    381 376
     Note [Recipe for adding a known-occ name]
    
    382 377
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

  • compiler/GHC/Iface/Errors/Ppr.hs
    ... ... @@ -25,6 +25,7 @@ module GHC.Iface.Errors.Ppr
    25 25
     import GHC.Prelude
    
    26 26
     
    
    27 27
     import GHC.Builtin( knownKeyOccName_maybe )
    
    28
    +import GHC.Builtin.Modules( eSSENTIALS_NAME )
    
    28 29
     import GHC.Types.Error
    
    29 30
     import GHC.Types.Hint.Ppr () -- Outputable GhcHint
    
    30 31
     import GHC.Types.Error.Codes
    
    ... ... @@ -67,6 +68,7 @@ interfaceErrorHints = \ case
    67 68
       MissingKnownKey2 {} -> noHints
    
    68 69
       MissingKnownKey3 {} -> noHints
    
    69 70
       KnownKeyScopeError {} -> noHints
    
    71
    +  CantFindEssentials {} -> noHints
    
    70 72
     
    
    71 73
     missingInterfaceErrorHints :: MissingInterfaceError -> [GhcHint]
    
    72 74
     missingInterfaceErrorHints = \case
    
    ... ... @@ -93,6 +95,7 @@ interfaceErrorReason (MissingKnownKey1 {}) = ErrorWithoutFlag
    93 95
     interfaceErrorReason (MissingKnownKey2 {})   = ErrorWithoutFlag
    
    94 96
     interfaceErrorReason (MissingKnownKey3 {})   = ErrorWithoutFlag
    
    95 97
     interfaceErrorReason (KnownKeyScopeError {}) = ErrorWithoutFlag
    
    98
    +interfaceErrorReason (CantFindEssentials {}) = ErrorWithoutFlag
    
    96 99
     
    
    97 100
     missingInterfaceErrorReason :: MissingInterfaceError -> DiagnosticReason
    
    98 101
     missingInterfaceErrorReason = \ case
    
    ... ... @@ -321,6 +324,32 @@ interfaceErrorDiagnostic opts = \ case
    321 324
         -> hang (text "Known-key entity" <+> quotes (ppr occ))
    
    322 325
               2 (text "is ambiguous in the top-level global environment" $$ ppr gres)
    
    323 326
     
    
    327
    +  CantFindEssentials err reason ->
    
    328
    +    vcat
    
    329
    +      [ vcat [ hang (text "Failed to load the known-names module" <+> quotes (ppr eSSENTIALS_NAME) <+> text "from the visible packages")
    
    330
    +                  2 (case reason of
    
    331
    +                       UnknownLoadEssentialsReason -> empty
    
    332
    +                       LookingForKnownOcc occ      -> text "while looking for known-occ name" <+> quotes (ppr occ)
    
    333
    +                       LookingForKnownKey key      -> text "while looking for known-key" <+> quotes (pprKnownKey key)
    
    334
    +                       LookingForEssentialsModule  -> text "while trying to discover its package")
    
    335
    +             , text "Did you mean to use" <+> quotes (text "-package base") <> text "?" ]
    
    336
    +      , blankLine
    
    337
    +      , missingInterfaceErrorDiagnostic opts err
    
    338
    +      , blankLine
    
    339
    +      , case reason of
    
    340
    +          LookingForEssentialsModule
    
    341
    +            -> vcat [ text "This error was triggered while trying to discover the package of" <+> quotes (ppr eSSENTIALS_NAME) <> comma
    
    342
    +                    , text "rather than when looking up any specific known-name."
    
    343
    +                    , text "If you want to enforce" <+> quotes (ppr eSSENTIALS_NAME) <+> text "is not added to the module graph implicitly,"
    
    344
    +                    , text "you should use" <+> quotes (text "-frebindable-known-names")
    
    345
    +                    ]
    
    346
    +          _ -> hang (text "To lookup known-names in scope rather than in GHC.Essentials" <> comma)
    
    347
    +                  2 (vcat [ text "use" <+> quotes (text "-frebindable-known-names") <> comma <+> text "and import"
    
    348
    +                          , text "the necessary known-names definitions from" <+> quotes (text "ghc-internal") <> dot
    
    349
    +                          -- Alternatively, you may want to unsafely provide your own GHC.Essentials exposing the known-names you need in scope."
    
    350
    +                          ])
    
    351
    +      ]
    
    352
    +
    
    324 353
     lookingForHerald :: InterfaceLookingFor -> SDoc
    
    325 354
     lookingForHerald looking_for =
    
    326 355
         case looking_for of
    

  • compiler/GHC/Iface/Errors/Types.hs
    ... ... @@ -9,6 +9,7 @@ module GHC.Iface.Errors.Types (
    9 9
       , FindingModuleOrInterface(..)
    
    10 10
     
    
    11 11
       , BuildingCabalPackage(..)
    
    12
    +  , LoadEssentialsReason(..)
    
    12 13
     
    
    13 14
       , IfaceMessageOpts(..)
    
    14 15
     
    
    ... ... @@ -70,6 +71,15 @@ data IfaceMessage
    70 71
          -- We looked up a known-occ in the GlobalRdrEnv,
    
    71 72
          -- but did not find a unique hit
    
    72 73
          -- CallStack is so that we can get a backtrace
    
    74
    +
    
    75
    +   | CantFindEssentials MissingInterfaceError LoadEssentialsReason
    
    76
    +     -- We failed to find GHC.Essentials, the module exported from base which
    
    77
    +     -- exports all the compiler known-names. The 'MissingInterfaceError' is
    
    78
    +     -- the underlying reason the module could not be found. A 'KnownKey' is
    
    79
    +     -- attached if we were looking for one when we failed to load GHC.Essentials
    
    80
    +     --
    
    81
    +     -- Test cases:
    
    82
    +     --   tests/driver/T27013e
    
    73 83
       deriving Generic
    
    74 84
     
    
    75 85
     data MissingInterfaceError
    
    ... ... @@ -113,3 +123,11 @@ data BuildingCabalPackage
    113 123
       = YesBuildingCabalPackage
    
    114 124
       | NoBuildingCabalPackage
    
    115 125
       deriving Eq
    
    126
    +
    
    127
    +data LoadEssentialsReason
    
    128
    +  = LookingForKnownKey KnownKey
    
    129
    +  | LookingForKnownOcc KnownOcc
    
    130
    +  | LookingForEssentialsModule
    
    131
    +  | UnknownLoadEssentialsReason
    
    132
    +  deriving Generic
    
    133
    +

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -73,7 +73,6 @@ import GHC.Iface.Binary
    73 73
     import GHC.Iface.Rename
    
    74 74
     import GHC.Iface.Env
    
    75 75
     import GHC.Iface.Errors as Iface_Errors
    
    76
    -import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts, missingInterfaceErrorDiagnostic )
    
    77 76
     import GHC.Tc.Errors.Types
    
    78 77
     import GHC.Tc.Utils.Monad
    
    79 78
     
    
    ... ... @@ -188,8 +187,12 @@ lookupKnownKeyName :: HasDebugCallStack
    188 187
                        => KnownKey -> KnownEntitySource
    
    189 188
                        -> IfM lcl (MaybeErr IfaceMessage Name)
    
    190 189
     lookupKnownKeyName key KES_FromModule
    
    191
    -  = do { (kk_map, _) <- loadKnownKeyOccMaps
    
    192
    -       ; return $ lookupKnownKeysMap kk_map key }
    
    190
    +  = do { mb_maps <- loadKnownKeyOccMaps
    
    191
    +       ; return $ case mb_maps of
    
    192
    +           Failed (CantFindEssentials err UnknownLoadEssentialsReason) -- augment error
    
    193
    +             -> Failed (CantFindEssentials err (LookingForKnownKey key))
    
    194
    +           Failed err            -> Failed err
    
    195
    +           Succeeded (kk_map, _) -> lookupKnownKeysMap kk_map key }
    
    193 196
     
    
    194 197
     lookupKnownKeyName key (KES_InScope { ke_rdr_env = gbl_rdr_env })
    
    195 198
       -- Just gbl_rdr_env: we have -frebindable-known-names on, and
    
    ... ... @@ -240,10 +243,15 @@ lookupKnownOccName :: HasDebugCallStack
    240 243
                        => KnownOcc -> KnownEntitySource
    
    241 244
                        -> IfM lcl (MaybeErr IfaceMessage Name)
    
    242 245
     lookupKnownOccName occ KES_FromModule
    
    243
    -  = do { (_, occ_map) <- loadKnownKeyOccMaps
    
    244
    -       ; case lookupOccEnv occ_map occ of
    
    245
    -           Just name -> return (Succeeded name)
    
    246
    -           Nothing   -> return (Failed (MissingKnownKey3 occ)) }
    
    246
    +  = do { mb_maps <- loadKnownKeyOccMaps
    
    247
    +       ; return $ case mb_maps of
    
    248
    +           Failed (CantFindEssentials err UnknownLoadEssentialsReason) -- augment error
    
    249
    +             -> Failed (CantFindEssentials err (LookingForKnownOcc occ))
    
    250
    +           Failed err -> Failed err
    
    251
    +           Succeeded (_, occ_map) ->
    
    252
    +             case lookupOccEnv occ_map occ of
    
    253
    +               Just name -> Succeeded name
    
    254
    +               Nothing   -> Failed (MissingKnownKey3 occ) }
    
    247 255
     
    
    248 256
     lookupKnownOccName occ (KES_InScope { ke_rdr_env = gbl_rdr_env })
    
    249 257
       -- Just gbl_rdr_env: we have -frebindable-known-names on, and
    
    ... ... @@ -279,23 +287,29 @@ lookupKnownName kk_ns name
    279 287
       where
    
    280 288
         name_mod = nameModule name
    
    281 289
     
    
    282
    -loadKnownKeyOccMaps :: IfM lcl KnownKeyNameMaps
    
    290
    +loadKnownKeyOccMaps :: IfM lcl (MaybeErr IfaceMessage KnownKeyNameMaps)
    
    283 291
     loadKnownKeyOccMaps
    
    284 292
       = do { eps <- getEps
    
    285 293
            ; case eps_known_keys eps of {
    
    286
    -            Just (kk_maps, _) -> return kk_maps ;
    
    294
    +            Just (kk_maps, _) -> return (Succeeded kk_maps) ;
    
    287 295
                 Nothing ->
    
    288 296
     
    
    289 297
         -- We don't have a KnownKeyOccMap yet, so create it
    
    290 298
         -- from the interface file for KnownKeyName
    
    291 299
         do { hsc_env <- getTopEnv
    
    292 300
            ; mb_res <- liftIO $ findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual
    
    293
    -       ; iface <- case mb_res of
    
    294
    -           Found _ mod -> loadInterfaceWithException doc mod ImportBySystem
    
    295
    -           fr -> do { hsc_env <- getTopEnv
    
    296
    -                    ; pprPanic "loadKnownKeyOccMap" $
    
    297
    -                      missingInterfaceErrorDiagnostic defaultIfaceMessageOpts $
    
    298
    -                      cannotFindModule hsc_env eSSENTIALS_NAME fr }
    
    301
    +       ; case mb_res of
    
    302
    +           Found _ mod -> Succeeded <$> build_maps mod
    
    303
    +           fr -> return (Failed (CantFindEssentials
    
    304
    +                                  (cannotFindModule hsc_env eSSENTIALS_NAME fr)
    
    305
    +                                  UnknownLoadEssentialsReason))
    
    306
    +       } } }
    
    307
    +  where
    
    308
    +    doc = text "Need interface for KnownKeyNames"
    
    309
    +
    
    310
    +    build_maps :: Module -> IfM lcl KnownKeyNameMaps
    
    311
    +    build_maps mod
    
    312
    +      = do { iface <- loadInterfaceWithException doc mod ImportBySystem
    
    299 313
     
    
    300 314
            ; let kk_map :: UniqFM KnownKey Name
    
    301 315
                  -- Domain is just the KnownKeys in the knownKeyTable
    
    ... ... @@ -318,9 +332,7 @@ loadKnownKeyOccMaps
    318 332
                             (msg $$ text "Known-key occ-map" <+> ppr occ_map)
    
    319 333
                 Nothing  -> return ()
    
    320 334
     #endif
    
    321
    -       ; return (kk_map, occ_map) } } }
    
    322
    -  where
    
    323
    -    doc = text "Need interface for KnonwKeyNames"
    
    335
    +       ; return (kk_map, occ_map) }
    
    324 336
     
    
    325 337
     lookupKnownKeysMap :: UniqFM KnownKey Name -> KnownKey -> MaybeErr IfaceMessage Name
    
    326 338
     lookupKnownKeysMap kk_map key = case lookupUFM kk_map key of
    
    ... ... @@ -361,10 +373,13 @@ lookupKnownKeysModule hsc_env dflags = do
    361 373
       found_essentials <- findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual
    
    362 374
       let rebindable_kn = gopt Opt_RebindableKnownNames dflags
    
    363 375
       let essentials_uid
    
    364
    -        | rebindable_kn                   = Nothing
    
    365
    -        | Found _ mod <- found_essentials = Just mod
    
    366
    -        | otherwise                       = Nothing
    
    367
    -  return essentials_uid
    
    376
    +        | rebindable_kn                   = return Nothing
    
    377
    +        | Found _ mod <- found_essentials = return (Just mod)
    
    378
    +        | fr          <- found_essentials = do
    
    379
    +            throwOneError (initSourceErrorContext dflags) $
    
    380
    +              mkPlainErrorMsgEnvelope noSrcSpan $ GhcDriverMessage $ DriverInterfaceError $
    
    381
    +                CantFindEssentials (cannotFindModule hsc_env eSSENTIALS_NAME fr) LookingForEssentialsModule
    
    382
    +  essentials_uid
    
    368 383
     
    
    369 384
     {- *********************************************************************
    
    370 385
     *                                                                      *
    

  • compiler/GHC/Rename/Env.hs
    ... ... @@ -59,7 +59,7 @@ import GHC.Prelude
    59 59
     
    
    60 60
     import GHC.Iface.Load
    
    61 61
     import GHC.Iface.Env
    
    62
    -import GHC.Iface.Errors.Types( IfaceMessage(..) )
    
    62
    +import GHC.Iface.Errors.Types( IfaceMessage(..), LoadEssentialsReason (..) )
    
    63 63
     
    
    64 64
     import GHC.Hs
    
    65 65
     import GHC.Types.Name.Reader
    
    ... ... @@ -1044,10 +1044,15 @@ lookup_known_occ :: HasDebugCallStack
    1044 1044
                        => KnownEntitySource -> KnownOcc
    
    1045 1045
                        -> RnM (MaybeErr IfaceMessage Name)
    
    1046 1046
     lookup_known_occ KES_FromModule occ
    
    1047
    -  = do { (_, occ_map) <- initIfaceTcRn loadKnownKeyOccMaps
    
    1048
    -       ; case lookupOccEnv occ_map occ of
    
    1049
    -           Just name -> return (Succeeded name)
    
    1050
    -           Nothing   -> return (Failed (MissingKnownKey3 occ)) }
    
    1047
    +  = do { mb_maps <- initIfaceTcRn loadKnownKeyOccMaps
    
    1048
    +       ; return $ case mb_maps of
    
    1049
    +           Failed (CantFindEssentials err UnknownLoadEssentialsReason) -- augment error
    
    1050
    +                      -> Failed (CantFindEssentials err (LookingForKnownOcc occ))
    
    1051
    +           Failed err -> Failed err
    
    1052
    +           Succeeded (_, occ_map) ->
    
    1053
    +             case lookupOccEnv occ_map occ of
    
    1054
    +               Just name -> Succeeded name
    
    1055
    +               Nothing   -> Failed (MissingKnownKey3 occ) }
    
    1051 1056
     
    
    1052 1057
     lookup_known_occ (KES_InScope { ke_rdr_env = rdr_env }) occ
    
    1053 1058
       = case lookupKnownGRE rdr_env occ of
    

  • compiler/GHC/Tc/Solver/Default.hs
    ... ... @@ -1006,7 +1006,7 @@ applyDefaultingRules :: WantedConstraints -> TcS Bool
    1006 1006
     -- See Note [How type-class constraints are defaulted]
    
    1007 1007
     
    
    1008 1008
     applyDefaultingRules wanteds
    
    1009
    -  | isEmptyWC wanteds
    
    1009
    +  | isSolvedWC wanteds -- not isEmptyWC, see (SCS5) in Note [Shortcut solving]
    
    1010 1010
       = return False
    
    1011 1011
       | otherwise
    
    1012 1012
       = do { (default_env, extended_rules) <- getDefaultInfo
    

  • compiler/GHC/Tc/Solver/Dict.hs
    ... ... @@ -671,6 +671,10 @@ Some wrinkles:
    671 671
        don't want to reject short-cut solving just because we have some leftover
    
    672 672
        /solved/ implications.  #26805 was a case in point.
    
    673 673
     
    
    674
    +(SCS5) Similarly to (SCS4), `applyDefaultingRules` should use `isSolvedWC` not
    
    675
    +  `isEmptyWC`. This avoids unnecessarily trying defaulting rules on solved
    
    676
    +  constraints.
    
    677
    +
    
    674 678
     Note [Shortcut solving: incoherence]
    
    675 679
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    676 680
     This optimization relies on coherence of dictionaries to be correct. When we
    

  • compiler/GHC/Tc/Utils/Env.hs
    ... ... @@ -83,7 +83,6 @@ import GHC.Driver.DynFlags
    83 83
     import GHC.Builtin( isUnboundName )
    
    84 84
     import GHC.Builtin.KnownKeys
    
    85 85
     import GHC.Builtin.WiredIn.Types
    
    86
    -import GHC.Builtin.Modules ( eSSENTIALS_NAME )
    
    87 86
     
    
    88 87
     import GHC.Runtime.Context
    
    89 88
     
    
    ... ... @@ -116,7 +115,6 @@ import GHC.Unit.Home
    116 115
     import GHC.Unit.Home.Graph
    
    117 116
     import GHC.Unit.Home.ModInfo
    
    118 117
     import GHC.Unit.External
    
    119
    -import GHC.Unit.Finder
    
    120 118
     
    
    121 119
     import GHC.Utils.Outputable
    
    122 120
     import GHC.Utils.Panic
    
    ... ... @@ -139,7 +137,6 @@ import GHC.Types.Id
    139 137
     import GHC.Types.Id.Info ( RecSelParent(..) )
    
    140 138
     import GHC.Types.Name.Reader
    
    141 139
     import GHC.Types.TyThing
    
    142
    -import GHC.Types.PkgQual
    
    143 140
     import GHC.Types.Unique.Set ( nonDetEltsUniqSet )
    
    144 141
     import qualified GHC.LanguageExtensions as LangExt
    
    145 142
     
    
    ... ... @@ -1119,9 +1116,7 @@ tcGetDefaultTys :: TcM (DefaultEnv, -- Default classes and types
    1119 1116
                             Bool)        -- True <=> Use extended defaulting rules
    
    1120 1117
     tcGetDefaultTys
    
    1121 1118
       = do  { dflags <- getDynFlags
    
    1122
    -        ; hsc_env <- getTopEnv
    
    1123 1119
             ; let ovl_strings = xopt LangExt.OverloadedStrings dflags
    
    1124
    -              rebindable_kn = gopt Opt_RebindableKnownNames dflags
    
    1125 1120
                   extended_defaults = xopt LangExt.ExtendedDefaultRules dflags
    
    1126 1121
                                             -- See also #1974
    
    1127 1122
                   builtinDefaults cls tys = ClassDefaults{ cd_class = cls
    
    ... ... @@ -1133,17 +1128,11 @@ tcGetDefaultTys
    1133 1128
             ; user_defaults <- getDeclaredDefaultTys -- User-supplied defaults
    
    1134 1129
             ; this_module <- tcg_mod <$> getGblEnv
    
    1135 1130
             ; let this_unit = moduleUnit this_module
    
    1136
    -        ; found_essentials <- liftIO $ findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual
    
    1137
    -        ; case (found_essentials, rebindable_kn) of
    
    1138
    -            (NotFound{}, False) -> -- See Wrinkle (KN5) in Note [Overview of known entities]
    
    1139
    -              -- If GHC.Essentials isn't available at all when -fno-rebindable-known-names
    
    1140
    -              -- don't add the built-in defaulting, bc e.g. Num is a known-entity.
    
    1141
    -              return (user_defaults, extended_defaults)
    
    1142
    -            _ | this_unit == ghcInternalUnit ->
    
    1143
    -              -- see Remark [No built-in defaults in ghc-internal]
    
    1144
    -              -- in Note [Builtin class defaults] in GHC.Tc.Utils.Env
    
    1145
    -              return (user_defaults, extended_defaults)
    
    1146
    -            _ -> do
    
    1131
    +        ; if this_unit == ghcInternalUnit -- if we wanted, this needn't be about ghc-internal
    
    1132
    +          -- see Remark [No built-in defaults in ghc-internal]
    
    1133
    +          -- in Note [Builtin class defaults] in GHC.Tc.Utils.Env
    
    1134
    +          then return (user_defaults, extended_defaults)
    
    1135
    +          else do
    
    1147 1136
                   -- Not one of the built-in units
    
    1148 1137
                   -- @default Num (Integer, Double)@, plus extensions
    
    1149 1138
                   { extDef <- if extended_defaults
    

  • compiler/GHC/Types/Error/Codes.hs
    ... ... @@ -893,6 +893,7 @@ type family GhcDiagnosticCode c = n | n -> c where
    893 893
       GhcDiagnosticCode "MissingKnownKey2"                              = 71344
    
    894 894
       GhcDiagnosticCode "MissingKnownKey3"                              = 71345
    
    895 895
       GhcDiagnosticCode "KnownKeyScopeError"                            = 99040
    
    896
    +  GhcDiagnosticCode "CantFindEssentials"                            = 49917
    
    896 897
     
    
    897 898
       -- Out of scope errors
    
    898 899
       GhcDiagnosticCode "NotInScope"                                    = 76037
    

  • docs/users_guide/separate_compilation.rst
    ... ... @@ -1665,11 +1665,15 @@ flags:
    1665 1665
         :type: dynamic
    
    1666 1666
         :category:
    
    1667 1667
     
    
    1668
    -    This flag is off by default.  It is typically set when compiling modules
    
    1669
    -    in ``ghc-internal`` or ``base``, and tells GHC to look for a known
    
    1670
    -    entity in the current top-level scope.  When the flag is un-set, GHC looks
    
    1671
    -    for the module ``base:GHC.KnownKeyNames``, but this module does not exist
    
    1672
    -    when compiling ``ghc-internal`` or ``base``, which is why the flag is needed.
    
    1668
    +    This flag is off by default. It tells GHC to look for a known entity in
    
    1669
    +    the current top-level scope. When the flag is off, GHC looks for known
    
    1670
    +    entities in the exports of module ``GHC.Essentials``.
    
    1671
    +
    
    1672
    +    It is typically set when compiling modules in ``ghc-internal`` or ``base``,
    
    1673
    +    since ``GHC.Essentials`` does not yet exist when compiling those packages.
    
    1674
    +
    
    1675
    +    GHC must assume ``GHC.Essentials`` is an implicit module dependency when
    
    1676
    +    and only when ``-fno-rebindable-known-names``.
    
    1673 1677
     
    
    1674 1678
     .. ghc-flag:: -fdefines-known-key-names
    
    1675 1679
         :shortdesc: This module defines a known name
    

  • testsuite/tests/cabal/T27013a/Makefile
    ... ... @@ -6,16 +6,16 @@ SETUP=./Setup -v0
    6 6
     
    
    7 7
     # Reproducer for #27013 (!15899#note_676801).
    
    8 8
     #
    
    9
    -# The `composition` package depends on neither `base` nor `ghc-internal`
    
    10
    -# (see composition.cabal: no build-depends). It uses NoImplicitPrelude
    
    11
    -# and defines its own `(.)`. Building it should not require GHC to load
    
    12
    -# known-key modules from `base` such as `GHC.Essentials`.
    
    9
    +# `composition` depends on neither base nor ghc-internal and uses no known-key
    
    10
    +# names AT ALL. We pass -frebindable-known-names just so GHC doesn't force an
    
    11
    +# implicit GHC.Essentials dependency (which couldn't be solved because of
    
    12
    +# -hide-all-packages). See T27013f for the failure when the flag is omitted.
    
    13 13
     
    
    14 14
     T27013a: clean
    
    15 15
     	'$(GHC_PKG)' init tmp.d
    
    16 16
     	'$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
    
    17 17
     	$(SETUP) clean
    
    18
    -	$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --with-hc-pkg='$(GHC_PKG)' --ghc-options='$(TEST_HC_OPTS)' --package-db=tmp.d
    
    18
    +	$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --with-hc-pkg='$(GHC_PKG)' --ghc-options='$(TEST_HC_OPTS) -frebindable-known-names' --package-db=tmp.d
    
    19 19
     	$(SETUP) build
    
    20 20
     
    
    21 21
     clean :
    

  • testsuite/tests/cabal/T27013d/Makefile
    ... ... @@ -2,15 +2,18 @@ TOP=../../..
    2 2
     include $(TOP)/mk/boilerplate.mk
    
    3 3
     include $(TOP)/mk/test.mk
    
    4 4
     
    
    5
    -# Test that compiling Data.Composition without implicit Prelude does not
    
    6
    -# recompile the second or third time. The `composition` package's
    
    7
    -# Data.Composition uses NoImplicitPrelude and depends on neither base nor
    
    8
    -# ghc-internal. In !15899, it was recompiled because of an incorrect
    
    9
    -# "GHC.Essentials package changed".
    
    5
    +# Test that compiling Data.Composition with -hide-all-packages and
    
    6
    +# -XNoImplicitPrelude does not recompile the second or third time. In !15899,
    
    7
    +# it used to recompile because of an incorrect "GHC.Essentials package changed".
    
    8
    +#
    
    9
    +# We pass -frebindable-known-names so GHC doesn't force an implicit
    
    10
    +# GHC.Essentials dependency: despite this module not using known-key names,
    
    11
    +#  -hide-all-packages means we can't find GHC.Essentials when it is added as an
    
    12
    +#  implicit dependency.
    
    10 13
     clean:
    
    11 14
     	rm -f *.o *.hi
    
    12 15
     
    
    13 16
     T27013d: clean
    
    14
    -	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages
    
    15
    -	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages
    
    16
    -	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages
    17
    +	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages -frebindable-known-names
    
    18
    +	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages -frebindable-known-names
    
    19
    +	'$(TEST_HC)' $(TEST_HC_OPTS) Composition.hs -XNoImplicitPrelude -hide-all-packages -frebindable-known-names

  • testsuite/tests/driver/T27013e/T27013e.hs
    1
    +{-# LANGUAGE NoImplicitPrelude #-}
    
    2
    +
    
    3
    +-- This module is compiled with -hide-all-packages (see all.T), so neither
    
    4
    +-- base nor GHC.Essentials can be found.  The numeric literal forces GHC to
    
    5
    +-- look up the known-key 'fromInteger', which it tries to resolve via the
    
    6
    +-- exports of GHC.Essentials.  Since GHC.Essentials cannot be found and
    
    7
    +-- -frebindable-known-names is not in effect, this fails.
    
    8
    +--
    
    9
    +-- We want a structured, helpful error here rather than a panic; see
    
    10
    +-- GHC.Iface.Load.loadKnownKeyOccMaps.
    
    11
    +module T27013e where
    
    12
    +
    
    13
    +n = 0

  • testsuite/tests/driver/T27013e/T27013e.stderr
    1
    +T27013e.hs:13:5: error: [GHC-49917]
    
    2
    +    Failed to load the known-names module ‘GHC.Essentials’ from the visible packages
    
    3
    +      while looking for known-occ name ‘fromInteger’
    
    4
    +    Did you mean to use ‘-package base’?
    
    5
    +    
    
    6
    +    Could not load module ‘GHC.Essentials’.
    
    7
    +    It is a member of the hidden package ‘base-4.23.0.0’.
    
    8
    +    Use -v to see a list of the files searched for.
    
    9
    +    
    
    10
    +    To lookup known-names in scope rather than in GHC.Essentials,
    
    11
    +      use ‘-frebindable-known-names’, and import
    
    12
    +      the necessary known-names definitions from ‘ghc-internal’.
    
    13
    +

  • testsuite/tests/driver/T27013e/all.T
    1
    +test('T27013e', normalise_version('base'), compile_fail, ['-hide-all-packages'])

  • testsuite/tests/driver/T27013f/T27013f.hs
    1
    +{-# LANGUAGE NoImplicitPrelude #-}
    
    2
    +
    
    3
    +-- Counterpart to T27013a/T27013d (see #27013, !15899).
    
    4
    +--
    
    5
    +-- Like the `composition` package, this module needs no known-key.
    
    6
    +-- It is compiled with -hide-all-packages (see all.T) and WITHOUT
    
    7
    +-- -frebindable-known-names (unlike T27013{a,d}).
    
    8
    +--
    
    9
    +-- Under the default -fno-rebindable-known-names, GHC must assume
    
    10
    +-- GHC.Essentials is an implicit dependency and tries to discover its
    
    11
    +-- package, which fails because nothing provides it. We want a structured
    
    12
    +-- error here (not a panic) that points at -frebindable-known-names as the
    
    13
    +-- way to avoid forcing that dependency. See GHC.Iface.Load.
    
    14
    +module T27013f where
    
    15
    +
    
    16
    +(.) :: (b -> c) -> (a -> b) -> a -> c
    
    17
    +(f . g) x = f (g x)

  • testsuite/tests/driver/T27013f/T27013f.stderr
    1
    +<no location info>: error: [GHC-49917]
    
    2
    +    Failed to load the known-names module ‘GHC.Essentials’ from the visible packages
    
    3
    +      while trying to discover its package
    
    4
    +    Did you mean to use ‘-package base’?
    
    5
    +
    
    6
    +    Could not load module ‘GHC.Essentials’.
    
    7
    +    It is a member of the hidden package ‘base-4.23.0.0’.
    
    8
    +    Use -v to see a list of the files searched for.
    
    9
    +
    
    10
    +    This error was triggered while trying to discover the package of ‘GHC.Essentials’,
    
    11
    +    rather than when looking up any specific known-name.
    
    12
    +    If you want to enforce ‘GHC.Essentials’ is not added to the module graph implicitly,
    
    13
    +    you should use ‘-frebindable-known-names’

  • testsuite/tests/driver/T27013f/all.T
    1
    +test('T27013f', normalise_version('base'), compile_fail, ['-hide-all-packages'])