Vladislav Zavialov pushed to branch wip/int-index/ie-refactor at Glasgow Haskell Compiler / GHC

Commits:

17 changed files:

Changes:

  • changelog.d/ie-refactor-27267
    1
    +section: ghc-lib
    
    2
    +synopsis: Refactor the definition of ``IEWrappedName``
    
    3
    +issues: #27267
    
    4
    +mrs: !17080
    
    5
    +
    
    6
    +description: {
    
    7
    +Move the constructors ``IEDefault`` and ``IEPattern`` from ``IEWrappedName`` to
    
    8
    +``IE``, reflecting the fact that ``pattern P`` and ``default C`` are never
    
    9
    +legal in subordinate export/import lists. Then simplify ``IEWrappedName`` by
    
    10
    +merging its remaining constructors ``IEName``, ``IEData``, and ``IEType`` into
    
    11
    +one constructor with a ``NamespaceSpecifier`` field.
    
    12
    +
    
    13
    +The ``-ddump-minimal-imports`` output now uses the ``data`` namespace specifier
    
    14
    +instead of the deprecated ``pattern``.
    
    15
    +}

  • compiler/GHC/Hs/ImpExp.hs
    ... ... @@ -233,10 +233,6 @@ instance (OutputableBndrId p
    233 233
     -}
    
    234 234
     
    
    235 235
     type instance XIEName    (GhcPass _) = NoExtField
    
    236
    -type instance XIEDefault (GhcPass _) = EpToken "default"
    
    237
    -type instance XIEPattern (GhcPass _) = EpToken "pattern"
    
    238
    -type instance XIEType    (GhcPass _) = EpToken "type"
    
    239
    -type instance XIEData    (GhcPass _) = EpToken "data"
    
    240 236
     type instance XXIEWrappedName (GhcPass _) = DataConCantHappen
    
    241 237
     
    
    242 238
     type instance XNoNamespaceSpecifier   (GhcPass _) = NoExtField
    
    ... ... @@ -283,6 +279,19 @@ type instance XIEThingWith GhcTc = IEThingWithAnns
    283 279
     
    
    284 280
     type IEThingWithAnns = (EpToken "(", EpToken "..", EpToken ",", EpToken ")")
    
    285 281
     
    
    282
    +-- The additional field of type 'Maybe (WarningTxt pass)' holds information
    
    283
    +-- about export deprecation annotations.
    
    284
    +type instance XIEDefault GhcPs = (Maybe (LWarningTxt GhcPs), EpToken "default")
    
    285
    +type instance XIEDefault GhcRn = Maybe (LWarningTxt GhcRn)
    
    286
    +type instance XIEDefault GhcTc = NoExtField
    
    287
    +
    
    288
    +-- The additional field of type 'Maybe (WarningTxt pass)' holds information
    
    289
    +-- about export deprecation annotations and is thus set to Nothing when `IE`
    
    290
    +-- is used in an import list (since export deprecation can only be used in exports)
    
    291
    +type instance XIEPattern GhcPs = (Maybe (LWarningTxt GhcPs), EpToken "pattern")
    
    292
    +type instance XIEPattern GhcRn = Maybe (LWarningTxt GhcRn)
    
    293
    +type instance XIEPattern GhcTc = NoExtField
    
    294
    +
    
    286 295
     -- The additional field of type 'Maybe (WarningTxt pass)' holds information
    
    287 296
     -- about export deprecation annotations and is thus set to Nothing when `IE`
    
    288 297
     -- is used in an import list (since export deprecation can only be used in exports)
    
    ... ... @@ -309,26 +318,46 @@ type instance XXIE (GhcPass _) = DataConCantHappen
    309 318
     type instance Anno (LocatedA (IE (GhcPass p))) = SrcSpanAnnA
    
    310 319
     
    
    311 320
     ieLIEWrappedName :: IE (GhcPass p) -> LIEWrappedName (GhcPass p)
    
    312
    -ieLIEWrappedName (IEVar _ n _)           = n
    
    313
    -ieLIEWrappedName (IEThingAbs  _ n _)     = n
    
    314
    -ieLIEWrappedName (IEThingWith _ n _ _ _) = n
    
    315
    -ieLIEWrappedName (IEThingAll  _ _ n _)   = n
    
    316
    -ieLIEWrappedName _ = panic "ieLIEWrappedName failed pattern match!"
    
    321
    +ieLIEWrappedName ie =
    
    322
    +  case ieLIEWrappedName_maybe ie of
    
    323
    +    Nothing -> panic "ieLIEWrappedName failed pattern match!"
    
    324
    +    Just name -> name
    
    325
    +
    
    326
    +ieLIEWrappedName_maybe :: IE (GhcPass p) -> Maybe (LIEWrappedName (GhcPass p))
    
    327
    +ieLIEWrappedName_maybe (IEVar _ n _)           = Just n
    
    328
    +ieLIEWrappedName_maybe (IEThingAbs  _ n _)     = Just n
    
    329
    +ieLIEWrappedName_maybe (IEThingWith _ n _ _ _) = Just n
    
    330
    +ieLIEWrappedName_maybe (IEThingAll  _ _ n _)   = Just n
    
    331
    +ieLIEWrappedName_maybe _ = Nothing
    
    317 332
     
    
    318 333
     ieName :: IE (GhcPass p) -> IdP (GhcPass p)
    
    319
    -ieName = lieWrappedName . ieLIEWrappedName
    
    334
    +ieName (IEPattern _ (L _ n) _) = n
    
    335
    +ieName (IEDefault _ (L _ n)) = n
    
    336
    +ieName ie = lieWrappedName (ieLIEWrappedName ie)
    
    320 337
     
    
    321 338
     ieNames :: IE (GhcPass p) -> [IdP (GhcPass p)]
    
    322 339
     ieNames (IEVar       _ (L _ n) _)      = [ieWrappedName n]
    
    323 340
     ieNames (IEThingAbs  _ (L _ n) _)      = [ieWrappedName n]
    
    324 341
     ieNames (IEThingAll  _ _ (L _ n) _)    = [ieWrappedName n]
    
    325 342
     ieNames (IEThingWith _ (L _ n) _ ns _) = ieWrappedName n : map (ieWrappedName . unLoc) ns
    
    343
    +ieNames (IEDefault _ (L _ n))          = [n]
    
    344
    +ieNames (IEPattern _ (L _ n) _)        = [n]
    
    326 345
     ieNames (IEWholeNamespace x _)         = iewn_names x
    
    327 346
     ieNames (IEModuleContents {})     = []
    
    328 347
     ieNames (IEGroup          {})     = []
    
    329 348
     ieNames (IEDoc            {})     = []
    
    330 349
     ieNames (IEDocNamed       {})     = []
    
    331 350
     
    
    351
    +iePatternNameSpec, ieDataNameSpec :: IE (GhcPass p) -> Bool
    
    352
    +iePatternNameSpec ie =
    
    353
    +  case ie of
    
    354
    +    IEPattern{} -> True
    
    355
    +    _ -> False
    
    356
    +ieDataNameSpec ie =
    
    357
    +  case ieLIEWrappedName_maybe ie of
    
    358
    +    Just (L _ (IEName _ DataNamespaceSpecifier{} _)) -> True
    
    359
    +    _ -> False
    
    360
    +
    
    332 361
     ieDeprecation :: forall p. IsPass p => IE (GhcPass p) -> Maybe (WarningTxt (GhcPass p))
    
    333 362
     ieDeprecation = fmap unLoc . ie_deprecation (ghcPass @p)
    
    334 363
       where
    
    ... ... @@ -337,24 +366,26 @@ ieDeprecation = fmap unLoc . ie_deprecation (ghcPass @p)
    337 366
         ie_deprecation GhcPs (IEThingAbs xie _ _) = xie
    
    338 367
         ie_deprecation GhcPs (IEThingAll xie _ _ _) = ieta_warning xie
    
    339 368
         ie_deprecation GhcPs (IEThingWith (xie, _) _ _ _ _) = xie
    
    369
    +    ie_deprecation GhcPs (IEDefault (xie, _) _) = xie
    
    370
    +    ie_deprecation GhcPs (IEPattern (xie, _) _ _) = xie
    
    340 371
         ie_deprecation GhcPs (IEModuleContents (xie, _) _) = xie
    
    341 372
         ie_deprecation GhcRn (IEVar xie _ _) = xie
    
    342 373
         ie_deprecation GhcRn (IEThingAbs xie _ _) = xie
    
    343 374
         ie_deprecation GhcRn (IEThingAll xie _ _ _) = ieta_warning xie
    
    344 375
         ie_deprecation GhcRn (IEThingWith (xie, _) _ _ _ _) = xie
    
    376
    +    ie_deprecation GhcRn (IEDefault xie _) = xie
    
    377
    +    ie_deprecation GhcRn (IEPattern xie _ _) = xie
    
    345 378
         ie_deprecation GhcRn (IEModuleContents xie _) = xie
    
    346 379
         ie_deprecation _ _ = Nothing
    
    347 380
     
    
    348 381
     ieWrappedLName :: IEWrappedName (GhcPass p) -> LIdP (GhcPass p)
    
    349
    -ieWrappedLName (IEDefault _ (L l n)) = L l n
    
    350
    -ieWrappedLName (IEName    _ (L l n)) = L l n
    
    351
    -ieWrappedLName (IEPattern _ (L l n)) = L l n
    
    352
    -ieWrappedLName (IEType    _ (L l n)) = L l n
    
    353
    -ieWrappedLName (IEData    _ (L l n)) = L l n
    
    382
    +ieWrappedLName (IEName _ _ n) = n
    
    354 383
     
    
    355 384
     ieWrappedName :: IEWrappedName (GhcPass p) -> IdP (GhcPass p)
    
    356 385
     ieWrappedName = unLoc . ieWrappedLName
    
    357 386
     
    
    387
    +ieWrappedNamespaceSpecifier :: IEWrappedName (GhcPass p) -> NamespaceSpecifier (GhcPass p)
    
    388
    +ieWrappedNamespaceSpecifier (IEName _ ns_spec _) = ns_spec
    
    358 389
     
    
    359 390
     lieWrappedName :: LIEWrappedName (GhcPass p) -> IdP (GhcPass p)
    
    360 391
     lieWrappedName (L _ n) = ieWrappedName n
    
    ... ... @@ -362,16 +393,6 @@ lieWrappedName (L _ n) = ieWrappedName n
    362 393
     ieLWrappedName :: LIEWrappedName (GhcPass p) -> LIdP (GhcPass p)
    
    363 394
     ieLWrappedName (L _ n) = ieWrappedLName n
    
    364 395
     
    
    365
    -replaceWrappedName :: IEWrappedName GhcPs -> IdP GhcRn -> IEWrappedName GhcRn
    
    366
    -replaceWrappedName (IEDefault r (L l _)) n = IEDefault r (L l n)
    
    367
    -replaceWrappedName (IEName    x (L l _)) n = IEName    x (L l n)
    
    368
    -replaceWrappedName (IEPattern r (L l _)) n = IEPattern r (L l n)
    
    369
    -replaceWrappedName (IEType    r (L l _)) n = IEType    r (L l n)
    
    370
    -replaceWrappedName (IEData    r (L l _)) n = IEData    r (L l n)
    
    371
    -
    
    372
    -replaceLWrappedName :: LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
    
    373
    -replaceLWrappedName (L l n) n' = L l (replaceWrappedName n n')
    
    374
    -
    
    375 396
     exportDocstring :: LHsDoc (GhcPass p) -> SDoc
    
    376 397
     exportDocstring doc = braces (text "docstring: " <> ppr doc)
    
    377 398
     
    
    ... ... @@ -404,6 +425,13 @@ instance OutputableBndrId p => Outputable (IE (GhcPass p)) where
    404 425
                   IEWildcard pos ->
    
    405 426
                     let (bs, as) = splitAt pos (map (ppr . unLoc) withs)
    
    406 427
                     in bs ++ [text ".."] ++ as
    
    428
    +    ppr ie@(IEPattern _ (L _ n) doc) =
    
    429
    +      sep $ catMaybes [ ppr <$> ieDeprecation ie
    
    430
    +                      , Just $ text "pattern" <+> pprPrefixOcc n
    
    431
    +                      , exportDocstring <$> doc
    
    432
    +                      ]
    
    433
    +    ppr ie@(IEDefault _ (L _ n))
    
    434
    +        = sep $ catMaybes [ppr <$> ieDeprecation ie, Just $ text "default" <+> pprPrefixOcc n]
    
    407 435
         ppr ie@(IEModuleContents _ mod')
    
    408 436
             = sep $ catMaybes [ppr <$> ieDeprecation ie, Just $ text "module" <+> ppr mod']
    
    409 437
         ppr (IEWholeNamespace _ ns_spec) = ppr ns_spec <+> text ".."
    
    ... ... @@ -420,11 +448,7 @@ instance OutputableBndrId p => OutputableBndr (IEWrappedName (GhcPass p)) where
    420 448
       pprInfixOcc  w = pprInfixOcc  (ieWrappedName w)
    
    421 449
     
    
    422 450
     instance OutputableBndrId p => Outputable (IEWrappedName (GhcPass p)) where
    
    423
    -  ppr (IEDefault _ (L _ n)) = text "default" <+> pprPrefixOcc n
    
    424
    -  ppr (IEName    _ (L _ n)) = pprPrefixOcc n
    
    425
    -  ppr (IEPattern _ (L _ n)) = text "pattern" <+> pprPrefixOcc n
    
    426
    -  ppr (IEType    _ (L _ n)) = text "type"    <+> pprPrefixOcc n
    
    427
    -  ppr (IEData    _ (L _ n)) = text "data"    <+> pprPrefixOcc n
    
    451
    +  ppr (IEName _ ns_spec (L _ n)) = ppr ns_spec <+> pprPrefixOcc n
    
    428 452
     
    
    429 453
     pprImpExp :: (HasOccName name, OutputableBndr name) => name -> SDoc
    
    430 454
     pprImpExp name = type_pref <+> pprPrefixOcc name
    

  • compiler/GHC/HsToCore/Docs.hs
    ... ... @@ -126,6 +126,8 @@ mkExportsDocs = foldMap f
    126 126
         ieExportDoc (IEThingAbs _ _ doc) = doc
    
    127 127
         ieExportDoc (IEThingAll _ _ _ doc) = doc
    
    128 128
         ieExportDoc (IEThingWith _ _ _ _ doc) = doc
    
    129
    +    ieExportDoc (IEPattern _ _ doc) = doc
    
    130
    +    ieExportDoc (IEDefault _ _) = Nothing
    
    129 131
         ieExportDoc (IEModuleContents _ _) = Nothing
    
    130 132
         ieExportDoc (IEWholeNamespace _ _) = Nothing
    
    131 133
         ieExportDoc (IEGroup _ _ _) = Nothing
    

  • compiler/GHC/Iface/Ext/Ast.hs
    ... ... @@ -2321,6 +2321,12 @@ instance ToHie (IEContext (LocatedA (IE GhcRn))) where
    2321 2321
             [ toHie $ IEC c n
    
    2322 2322
             , toHie $ map (IEC c) ns
    
    2323 2323
             ]
    
    2324
    +      IEDefault _ (L l p) ->
    
    2325
    +        [ toHie $ C (IEThing c) (L l p)
    
    2326
    +        ]
    
    2327
    +      IEPattern _ (L l p) _ ->
    
    2328
    +        [ toHie $ C (IEThing c) (L l p)
    
    2329
    +        ]
    
    2324 2330
           IEModuleContents _ n ->
    
    2325 2331
             [ toHie $ IEC c n
    
    2326 2332
             ]
    
    ... ... @@ -2331,19 +2337,7 @@ instance ToHie (IEContext (LocatedA (IE GhcRn))) where
    2331 2337
     
    
    2332 2338
     instance ToHie (IEContext (LocatedA (IEWrappedName GhcRn))) where
    
    2333 2339
       toHie (IEC c (L span iewn)) = concatM $ makeNodeA iewn span : case iewn of
    
    2334
    -      IEDefault _ (L l p) ->
    
    2335
    -        [ toHie $ C (IEThing c) (L l p)
    
    2336
    -        ]
    
    2337
    -      IEName _ (L l n) ->
    
    2338
    -        [ toHie $ C (IEThing c) (L l n)
    
    2339
    -        ]
    
    2340
    -      IEPattern _ (L l p) ->
    
    2341
    -        [ toHie $ C (IEThing c) (L l p)
    
    2342
    -        ]
    
    2343
    -      IEType _ (L l n) ->
    
    2344
    -        [ toHie $ C (IEThing c) (L l n)
    
    2345
    -        ]
    
    2346
    -      IEData _ (L l n) ->
    
    2340
    +      IEName _ _ (L l n) ->
    
    2347 2341
             [ toHie $ C (IEThing c) (L l n)
    
    2348 2342
             ]
    
    2349 2343
     
    

  • compiler/GHC/Parser.y
    ... ... @@ -1041,16 +1041,14 @@ export :: { LIE GhcPs }
    1041 1041
             : maybe_warning_pragma qcname_ext export_subspec {% do { let { span = (maybe comb2 comb3 $1) $2 $> }
    
    1042 1042
                                                               ; impExp <- mkModuleExp $1 (fst $ unLoc $3) $2 (snd $ unLoc $3)
    
    1043 1043
                                                               ; return $ reLoc $ sL span $ impExp } }
    
    1044
    -        | maybe_warning_pragma 'module' hsmodid          {% do { let { span = (maybe comb2 comb3 $1) $2 $>
    
    1045
    -                                                                     ; anchor = (maybe glR (\loc -> spanAsAnchor . comb2 loc) $1) $2 }
    
    1044
    +        | maybe_warning_pragma 'module' hsmodid          {% do { let { span = (maybe comb2 comb3 $1) $2 $> }
    
    1046 1045
                                                               ; locImpExp <- return (sL span (IEModuleContents ($1, (epTok $2)) $3))
    
    1047 1046
                                                               ; return $ reLoc $ locImpExp } }
    
    1048 1047
             | maybe_warning_pragma 'pattern' qcon            {% do { warnPatternNamespaceSpecifier (getLoc $2)
    
    1049 1048
                                                                    ; let span = (maybe comb2 comb3 $1) $2 $>
    
    1050
    -                                                               ; return $ reLoc $ sL span $ IEVar $1 (sLLa $2 $> (IEPattern (epTok $2) $3)) Nothing } }
    
    1049
    +                                                               ; return $ reLoc $ sL span $ IEPattern ($1, epTok $2) $3 Nothing } }
    
    1051 1050
             | maybe_warning_pragma 'default' qtycon          {% do { let { span = (maybe comb2 comb3 $1) $2 $> }
    
    1052
    -                                                          ; locImpExp <- return (sL span (IEThingAbs $1 (sLLa $2 $> (IEDefault (epTok $2) $3)) Nothing))
    
    1053
    -                                                          ; return $ reLoc $ locImpExp } }
    
    1051
    +                                                          ; return $ reLoc $ sL span (IEDefault ($1, epTok $2) $3) } }
    
    1054 1052
             | maybe_warning_pragma 'type' '..'               {% do { let { span = (maybe comb2 comb3 $1) $2 $> }
    
    1055 1053
                                                               ; locImpExp <- mkWholeTypeWcImpExp span $1 (epTok $2) (epTok $3)
    
    1056 1054
                                                               ; return $ reLoc locImpExp } }
    
    ... ... @@ -1237,7 +1235,7 @@ import :: { OrdList (LIE GhcPs) }
    1237 1235
             : qcname_ext export_subspec {% fmap (unitOL . reLoc . (sLL $1 $>)) $ mkModuleImp Nothing (fst $ unLoc $2) $1 (snd $ unLoc $2) }
    
    1238 1236
             | 'module' hsmodid          {% fmap (unitOL . reLoc) $ return (sLL $1 $> (IEModuleContents (Nothing, (epTok $1)) $2)) }
    
    1239 1237
             | 'pattern' qcon            {% do { warnPatternNamespaceSpecifier (getLoc $1)
    
    1240
    -                                          ; return $ unitOL $ reLoc $ sLL $1 $> $ IEVar Nothing (sLLa $1 $> (IEPattern (epTok $1) $2)) Nothing } }
    
    1238
    +                                          ; return $ unitOL $ reLoc $ sLL $1 $> (IEPattern (Nothing, epTok $1) $2 Nothing) } }
    
    1241 1239
             | 'type' '..'               {% fmap (unitOL . reLoc) $ mkWholeTypeWcImpExp (comb2 $1 $>) Nothing (epTok $1) (epTok $2) }
    
    1242 1240
             | 'data' '..'               {% fmap (unitOL . reLoc) $ mkWholeDataWcImpExp (comb2 $1 $>) Nothing (epTok $1) (epTok $2) }
    
    1243 1241
             | '..'                      {% do { addError $ mkPlainErrorMsgEnvelope (gl $1) PsErrPlainWildcardImport
    

  • compiler/GHC/Parser/PostProcess.hs
    ... ... @@ -3367,10 +3367,7 @@ mkModuleImpExp ctx warning (top, tcp) (L l specname) subs = do
    3367 3367
         ieNameVal ImpExpQcWildcard{}  = panic "ieNameVal got wildcard"
    
    3368 3368
     
    
    3369 3369
         ieNameFromSpec :: ImpExpQcSpec -> IEWrappedName GhcPs
    
    3370
    -    ieNameFromSpec (ImpExpQcName m_kw name) = case m_kw of
    
    3371
    -        Nothing                          -> IEName noExtField name
    
    3372
    -        Just (ExplicitTypeNamespace tok) -> IEType tok name
    
    3373
    -        Just (ExplicitDataNamespace tok) -> IEData tok name
    
    3370
    +    ieNameFromSpec (ImpExpQcName m_kw name) = IEName noExtField (namespaceSpecifierFromKw m_kw) name
    
    3374 3371
         ieNameFromSpec ImpExpQcWildcard{} = panic "ieNameFromSpec got wildcard"
    
    3375 3372
     
    
    3376 3373
         namespaceSpecifierFromKw :: Maybe ExplicitNamespaceKeyword -> NamespaceSpecifier GhcPs
    

  • compiler/GHC/Parser/PostProcess/Haddock.hs
    ... ... @@ -319,6 +319,7 @@ instance HasHaddock (LocatedA (IE GhcPs)) where
    319 319
                 IEThingAbs ext nm _            -> IEThingAbs ext nm mb_ldoc
    
    320 320
                 IEThingAll ext ns nm _         -> IEThingAll ext ns nm mb_ldoc
    
    321 321
                 IEThingWith ext nm wild subs _ -> IEThingWith ext nm wild subs mb_ldoc
    
    322
    +            IEPattern ext nm _             -> IEPattern ext nm mb_ldoc
    
    322 323
                 x                              -> x
    
    323 324
           pure $ L l_export ie'
    
    324 325
     
    

  • compiler/GHC/Rename/Names.hs
    ... ... @@ -25,7 +25,9 @@ module GHC.Rename.Names (
    25 25
             renamePkgQual, renameRawPkgQual,
    
    26 26
             classifyGREs,
    
    27 27
             ImportDeclUsage,
    
    28
    -        rnNamespaceSpecifier
    
    28
    +        rnNamespaceSpecifier,
    
    29
    +        replaceWrappedName,
    
    30
    +        replaceLWrappedName,
    
    29 31
         ) where
    
    30 32
     
    
    31 33
     import GHC.Prelude hiding ( head, init, last, tail )
    
    ... ... @@ -1222,6 +1224,13 @@ rnNamespaceSpecifier (NoNamespaceSpecifier _) = NoNamespaceSpecifier noExtFiel
    1222 1224
     rnNamespaceSpecifier (TypeNamespaceSpecifier x) = TypeNamespaceSpecifier x
    
    1223 1225
     rnNamespaceSpecifier (DataNamespaceSpecifier x) = DataNamespaceSpecifier x
    
    1224 1226
     
    
    1227
    +replaceWrappedName :: IEWrappedName GhcPs -> Name -> IEWrappedName GhcRn
    
    1228
    +replaceWrappedName (IEName x ns_spec (L l _)) n = IEName x (rnNamespaceSpecifier ns_spec) (L l n)
    
    1229
    +
    
    1230
    +replaceLWrappedName :: LIEWrappedName GhcPs -> Name -> LIEWrappedName GhcRn
    
    1231
    +replaceLWrappedName (L l n) n' = L l (replaceWrappedName n n')
    
    1232
    +
    
    1233
    +
    
    1225 1234
     filterImports
    
    1226 1235
         :: HasDebugCallStack
    
    1227 1236
         => HscEnv
    
    ... ... @@ -1347,18 +1356,12 @@ filterImports hsc_env iface decl_spec (Just (want_hiding, import_items))
    1347 1356
                   -> IELookupM ([(IE GhcRn, [GlobalRdrElt])], [IELookupWarning])
    
    1348 1357
         lookup_ie ie = handle_bad_import $
    
    1349 1358
           case ie of
    
    1350
    -        IEVar _ (L l n) _ -> do
    
    1351
    -            -- See Note [Importing DuplicateRecordFields]
    
    1352
    -            xs <- lookup_names ie (ieWrappedName n)
    
    1353
    -            let gres = map imp_item $ NE.toList xs
    
    1354
    -                export_depr_warns
    
    1355
    -                  | want_hiding == Exactly
    
    1356
    -                      = mapMaybe mk_depr_export_warning gres
    
    1357
    -                  | otherwise = []
    
    1358
    -            return ( [ (IEVar Nothing (L l (replaceWrappedName n name)) noDocstring, [gre])
    
    1359
    -                     | gre <- gres
    
    1360
    -                     , let name = greName gre ]
    
    1361
    -                   , export_depr_warns )
    
    1359
    +        IEVar _ (L l n) _ ->
    
    1360
    +          lookup_ie_var (ieWrappedName n) $ \name ->
    
    1361
    +            IEVar Nothing (L l (replaceWrappedName n name)) noDocstring
    
    1362
    +        IEPattern _ (L l n) _ ->
    
    1363
    +          lookup_ie_var n $ \name ->
    
    1364
    +            IEPattern Nothing (L l name) noDocstring
    
    1362 1365
     
    
    1363 1366
             IEThingAll x ns_spec (L l tc) _ -> do
    
    1364 1367
                 ImpOccItem { imp_item      = gre
    
    ... ... @@ -1468,6 +1471,19 @@ filterImports hsc_env iface decl_spec (Just (want_hiding, import_items))
    1468 1471
             -- all of those constitute errors.
    
    1469 1472
     
    
    1470 1473
           where
    
    1474
    +        lookup_ie_var n mk_ie = do
    
    1475
    +          -- See Note [Importing DuplicateRecordFields]
    
    1476
    +          xs <- lookup_names ie n
    
    1477
    +          let gres = map imp_item $ NE.toList xs
    
    1478
    +              export_depr_warns
    
    1479
    +                | want_hiding == Exactly
    
    1480
    +                    = mapMaybe mk_depr_export_warning gres
    
    1481
    +                | otherwise = []
    
    1482
    +          return ( [ (mk_ie name, [gre])
    
    1483
    +                   | gre <- gres
    
    1484
    +                   , let name = greName gre ]
    
    1485
    +                 , export_depr_warns )
    
    1486
    +
    
    1471 1487
             mkIEThingAbs tc l gre
    
    1472 1488
               = (IEThingAbs Nothing (L l (replaceWrappedName tc n)) noDocstring, [gre])
    
    1473 1489
               where n = greName gre
    
    ... ... @@ -1740,9 +1756,9 @@ lookupChildren all_kids rdr_items = (fails, successes)
    1740 1756
     
    
    1741 1757
         do_one :: LIEWrappedName GhcPs -> MaybeErr LookupChildError (NonEmpty (LocatedA GlobalRdrElt))
    
    1742 1758
         do_one item@(L l r) =
    
    1743
    -      case r of
    
    1744
    -        IEName{}
    
    1745
    -          -- IEName (unadorned name) places no restriction on the namespace of
    
    1759
    +      case ieWrappedNamespaceSpecifier r of
    
    1760
    +        NoNamespaceSpecifier{}
    
    1761
    +          -- An unadorned name places no restriction on the namespace of
    
    1746 1762
               -- the imported entity, so we look in both `val_gres` and `typ_gres`.
    
    1747 1763
               -- In case of conflict (punning), the value namespace takes priority.
    
    1748 1764
               -- See Note [Prioritise the value namespace in subordinate import lists]
    
    ... ... @@ -1750,24 +1766,21 @@ lookupChildren all_kids rdr_items = (fails, successes)
    1750 1766
               | (gre:gres) <- typ_gres -> Succeeded $ fmap (L l) (gre:|gres)
    
    1751 1767
               | otherwise              -> Failed $ LookupChildNotFound item
    
    1752 1768
     
    
    1753
    -        IEType{}
    
    1754
    -          -- IEType ('type' namespace specifier) restricts the lookup to the
    
    1769
    +        TypeNamespaceSpecifier{}
    
    1770
    +          -- The 'type' namespace specifier restricts the lookup to the
    
    1755 1771
               -- type namespace, i.e. to `typ_gres`. In case of failure, we check
    
    1756 1772
               -- `val_gres` to produce a more helpful error message.
    
    1757 1773
               | (gre:gres) <- typ_gres -> Succeeded $ fmap (L l) (gre:|gres)
    
    1758 1774
               | (gre:_)    <- val_gres -> Failed $ LookupChildNonType item gre
    
    1759 1775
               | otherwise              -> Failed $ LookupChildNotFound item
    
    1760 1776
     
    
    1761
    -        IEData{}
    
    1762
    -          -- IEData ('data' namespace specifier) restricts the lookup to the
    
    1777
    +        DataNamespaceSpecifier{}
    
    1778
    +          -- The 'data' namespace specifier restricts the lookup to the
    
    1763 1779
               -- data namespace, i.e. to `val_gres`. In case of failure, we check
    
    1764 1780
               -- `typ_gres` to produce a more helpful error message.
    
    1765 1781
               | (gre:gres) <- val_gres -> Succeeded $ fmap (L l) (gre:|gres)
    
    1766 1782
               | (gre:_)    <- typ_gres -> Failed $ LookupChildNonData item gre
    
    1767 1783
               | otherwise              -> Failed $ LookupChildNotFound item
    
    1768
    -
    
    1769
    -        IEPattern{} -> panic "lookupChildren: IEPattern"  -- Never happens (invalid syntax)
    
    1770
    -        IEDefault{} -> panic "lookupChildren: IEDefault"  -- Never happens (invalid syntax)
    
    1771 1784
           where
    
    1772 1785
             fs = (occNameFS . rdrNameOcc . ieWrappedName) r
    
    1773 1786
             gres = fromMaybe [] (lookupFsEnv kid_env fs)
    
    ... ... @@ -2058,6 +2071,7 @@ findImportUsage imports used_gres
    2058 2071
                     add_wc_all = case wc of
    
    2059 2072
                                 NoIEWildcard -> id
    
    2060 2073
                                 IEWildcard _ -> add_unused_all pn
    
    2074
    +        add_unused (IEPattern _ n _)  acc = add_unused_name (unLoc n) True acc
    
    2061 2075
             add_unused (IEWholeNamespace x ns_spec) acc = add_unused_wildcard ns_spec (iewn_names x) acc
    
    2062 2076
             add_unused _ acc = acc
    
    2063 2077
     
    
    ... ... @@ -2418,16 +2432,20 @@ printMinimalImports hsc_src imports_w_usage
    2418 2432
     
    
    2419 2433
     
    
    2420 2434
     to_ie_post_rn_var :: LocatedA (IdP GhcRn) -> LIEWrappedName GhcRn
    
    2421
    -to_ie_post_rn_var (L l n)
    
    2422
    -  | isDataOcc $ occName n = L l (IEPattern noAnn      (L (l2l l) n))
    
    2423
    -  | otherwise             = L l (IEName    noExtField (L (l2l l) n))
    
    2435
    +to_ie_post_rn_var (L l n) = L l (IEName noExtField ns_spec (L (l2l l) n))
    
    2436
    +  where
    
    2437
    +    ns_spec
    
    2438
    +      | isDataOcc $ occName n = DataNamespaceSpecifier noAnn
    
    2439
    +      | otherwise             = NoNamespaceSpecifier noExtField
    
    2424 2440
     
    
    2425 2441
     
    
    2426 2442
     to_ie_post_rn :: LocatedA (IdP GhcRn) -> LIEWrappedName GhcRn
    
    2427
    -to_ie_post_rn (L l n)
    
    2428
    -  | isTcOcc occ && isSymOcc occ = L l (IEType noAnn      (L (l2l l) n))
    
    2429
    -  | otherwise                   = L l (IEName noExtField (L (l2l l) n))
    
    2430
    -  where occ = occName n
    
    2443
    +to_ie_post_rn (L l n) = L l (IEName noExtField ns_spec (L (l2l l) n))
    
    2444
    +  where
    
    2445
    +    occ = occName n
    
    2446
    +    ns_spec
    
    2447
    +      | isTcOcc occ && isSymOcc occ = TypeNamespaceSpecifier noAnn
    
    2448
    +      | otherwise                   = NoNamespaceSpecifier noExtField
    
    2431 2449
     
    
    2432 2450
     {- Note [Do not warn about Prelude hiding]
    
    2433 2451
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -697,12 +697,10 @@ instance Diagnostic TcRnMessage where
    697 697
                   child_name_fs   = occNameFS (rdrNameOcc child_name)
    
    698 698
                   suggest_patsyn  = allow_patsyn && could_be_patsyn
    
    699 699
                   could_be_patsyn =
    
    700
    -                case unLoc wname of
    
    701
    -                  IEName{} -> isLexCon child_name_fs
    
    702
    -                  IEData{} -> isLexCon child_name_fs
    
    703
    -                  IEPattern{} -> True
    
    704
    -                  IEType{}    -> False
    
    705
    -                  IEDefault{} -> False
    
    700
    +                case ieWrappedNamespaceSpecifier (unLoc wname) of
    
    701
    +                  NoNamespaceSpecifier{}   -> isLexCon child_name_fs
    
    702
    +                  DataNamespaceSpecifier{} -> isLexCon child_name_fs
    
    703
    +                  TypeNamespaceSpecifier{} -> False
    
    706 704
                   basic_msg =
    
    707 705
                     what_parent <+> quotes (ppr parent_name)
    
    708 706
                     <+> "does not define a child named" <+> quotes (ppr child_name)
    
    ... ... @@ -3385,12 +3383,10 @@ instance Diagnostic TcRnMessage where
    3385 3383
             BadImportAvailTyCon
    
    3386 3384
               -- The three cases (TyOp, DataKw, PatternKw) are laid out
    
    3387 3385
               -- in Note [Reasons for BadImportAvailTyCon] in GHC.Tc.Errors.Types
    
    3388
    -          | isSymOcc occ    -> could_change_item ImportItemAddType        -- Case (TyOp)
    
    3389
    -          | otherwise       ->  -- Non-operator cases
    
    3390
    -              case unLoc (ieLIEWrappedName ie) of
    
    3391
    -                IEData{}    -> could_change_item ImportItemRemoveData     -- Case (DataKw)
    
    3392
    -                IEPattern{} -> could_change_item ImportItemRemovePattern  -- Case (PatternKw)
    
    3393
    -                _           -> panic "diagnosticHints: unexpected BadImportAvailTyCon"
    
    3386
    +          | isSymOcc occ         -> could_change_item ImportItemAddType        -- Case (TyOp)
    
    3387
    +          | iePatternNameSpec ie -> could_change_item ImportItemRemovePattern  -- Case (PatternKw)
    
    3388
    +          | ieDataNameSpec ie    -> could_change_item ImportItemRemoveData     -- Case (DataKw)
    
    3389
    +          | otherwise            -> panic "diagnosticHints: unexpected BadImportAvailTyCon"
    
    3394 3390
     
    
    3395 3391
             BadImportAvailDataCon par  ->
    
    3396 3392
               [ ImportSuggestion occ $
    

  • compiler/GHC/Tc/Gen/Export.hs
    ... ... @@ -228,7 +228,8 @@ rnExports explicit_mod exports
    228 228
                      | explicit_mod = exports
    
    229 229
                      | has_main
    
    230 230
                               = Just [noLocA (IEVar Nothing
    
    231
    -                                     (noLocA (IEName noExtField $ noLocA default_main)) Nothing)]
    
    231
    +                                     (noLocA (IEName noExtField (NoNamespaceSpecifier noExtField) $
    
    232
    +                                                noLocA default_main)) Nothing)]
    
    232 233
                             -- ToDo: the 'noLoc' here is unhelpful if 'main'
    
    233 234
                             --       turns out to be out of scope
    
    234 235
                      | otherwise = Nothing
    
    ... ... @@ -286,7 +287,7 @@ declarations, and neither does the re-export of a whole imported module.
    286 287
     
    
    287 288
     The export item `default IsString` is parsed into the `IE` item
    
    288 289
     
    
    289
    -    IEThingAbs ext (L loc (IEDefault ext "IsString")) doc
    
    290
    +    IEDefault ext "IsString"
    
    290 291
     
    
    291 292
     If exported, a default is imported automatically much like a class instance. For
    
    292 293
     example,
    
    ... ... @@ -532,65 +533,25 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
    532 533
     
    
    533 534
         -------------
    
    534 535
         lookup_ie :: ExportAccum -> LIE GhcPs -> RnM (Maybe (ExportAccum, LIE GhcRn, Maybe AvailInfo))
    
    536
    +    lookup_ie expacc (L loc ie@(IEVar warn_txt_ps l doc)) =
    
    537
    +      lookup_ie_var expacc loc ie warn_txt_ps what_look lrdr doc $
    
    538
    +         \warn_txt_rn name doc' -> IEVar warn_txt_rn (replaceLWrappedName l name) doc'
    
    539
    +      where { lrdr      = ieLWrappedName l
    
    540
    +            ; what_look = ieLWrappedNameWhatLooking l }
    
    541
    +    lookup_ie expacc (L loc ie@(IEPattern (warn_txt_ps, _) lrdr doc)) =
    
    542
    +      lookup_ie_var expacc loc ie warn_txt_ps WL_ConLike lrdr doc $
    
    543
    +        \warn_txt_rn name doc' -> IEPattern warn_txt_rn (L (getLoc lrdr) name) doc'
    
    535 544
         lookup_ie expacc@ExportAccum{
    
    536 545
                 expacc_exp_occs   = occs,
    
    537 546
                 expacc_warn_spans = export_warn_spans,
    
    538 547
                 expacc_dont_warn  = dont_warn_export
    
    539
    -          } (L loc ie@(IEVar warn_txt_ps l doc))
    
    540
    -        = do mb_gre <- lookupGreAvailRn (ieLWrappedNameWhatLooking l) $ lieWrappedName l
    
    541
    -             for mb_gre $ \ gre -> do
    
    542
    -               let avail = availFromGRE gre
    
    543
    -                   name = greName gre
    
    544
    -
    
    545
    -               checkThLocalNameNoLift $ ieLWrappedUserRdrName l gre
    
    546
    -               occs' <- check_occs occs ie [gre]
    
    547
    -               (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    548
    -                 <- process_warning export_warn_spans
    
    549
    -                                    dont_warn_export
    
    550
    -                                    [name]
    
    551
    -                                    warn_txt_ps
    
    552
    -                                    (locA loc)
    
    553
    -
    
    554
    -               doc' <- traverse rnLHsDoc doc
    
    555
    -               return ( expacc{ expacc_exp_occs   = occs'
    
    556
    -                              , expacc_warn_spans = export_warn_spans'
    
    557
    -                              , expacc_dont_warn  = dont_warn_export' }
    
    558
    -                      , L loc (IEVar warn_txt_rn (replaceLWrappedName l name) doc')
    
    559
    -                      , Just avail )
    
    560
    -
    
    561
    -    lookup_ie expacc@ExportAccum{
    
    562
    -            expacc_exp_occs   = occs,
    
    563
    -            expacc_exp_dflts  = exp_dflts,
    
    564
    -            expacc_warn_spans = export_warn_spans,
    
    565
    -            expacc_dont_warn  = dont_warn_export
    
    566 548
               } (L loc ie@(IEThingAbs warn_txt_ps l doc))
    
    567 549
             = do mb_gre <- lookupGreAvailRn (ieLWrappedNameWhatLooking l) $ lieWrappedName l
    
    568 550
                  for mb_gre $ \ gre -> do
    
    569 551
                    let avail = availFromGRE gre
    
    570 552
                        name = greName gre
    
    571 553
     
    
    572
    -               (mb_avail, occs', exp_dflts') <-
    
    573
    -                 case unLoc l of
    
    574
    -                   -- see Note [Default exports]
    
    575
    -                   IEDefault {} -> do
    
    576
    -                     defaults <- tcg_default <$> getGblEnv
    
    577
    -                     case lookupUFM_Directly defaults (nameUnique name) of
    
    578
    -                       Nothing ->
    
    579
    -                        do addErr $ TcRnExportHiddenDefault ie
    
    580
    -                           return (Nothing, occs, exp_dflts)
    
    581
    -                       Just cls_dflts -> do
    
    582
    -                         let cls = cd_class cls_dflts
    
    583
    -                         case lookupNameEnv exp_dflts (className cls) of
    
    584
    -                           Just (_, ie') -> do
    
    585
    -                             addDiagnostic $
    
    586
    -                               TcRnDuplicateNamedDefaultExport (classTyCon cls) ie ie'
    
    587
    -                             return (Nothing, occs, exp_dflts)
    
    588
    -                           Nothing ->
    
    589
    -                            return $ (Nothing, occs, extendNameEnv exp_dflts (className cls) (cls_dflts, ie))
    
    590
    -                   _ -> do
    
    591
    -                    occs' <- check_occs occs ie [gre]
    
    592
    -                    return (Just avail, occs', exp_dflts)
    
    593
    -
    
    554
    +               occs' <- check_occs occs ie [gre]
    
    594 555
                    checkThLocalNameNoLift (ieLWrappedUserRdrName l gre)
    
    595 556
                    (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    596 557
                      <- process_warning export_warn_spans
    
    ... ... @@ -601,11 +562,10 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
    601 562
     
    
    602 563
                    doc' <- traverse rnLHsDoc doc
    
    603 564
                    return ( expacc{ expacc_exp_occs   = occs'
    
    604
    -                              , expacc_exp_dflts  = exp_dflts'
    
    605 565
                                   , expacc_warn_spans = export_warn_spans'
    
    606 566
                                   , expacc_dont_warn  = dont_warn_export' }
    
    607 567
                           , L loc (IEThingAbs warn_txt_rn (replaceLWrappedName l name) doc')
    
    608
    -                      , mb_avail )
    
    568
    +                      , Just avail )
    
    609 569
     
    
    610 570
         lookup_ie expacc@ExportAccum{
    
    611 571
                 expacc_exp_occs   = occs,
    
    ... ... @@ -674,8 +634,74 @@ exports_from_avail (Just rdr_items) rdr_env imports this_mod
    674 634
                           , L loc (IEThingWith (warn_txt_rn, ann) (replaceLWrappedName l name) wc subs doc')
    
    675 635
                           , Just $ AvailTC name all_names )
    
    676 636
     
    
    637
    +    lookup_ie expacc@ExportAccum{
    
    638
    +            expacc_exp_dflts  = exp_dflts,
    
    639
    +            expacc_warn_spans = export_warn_spans,
    
    640
    +            expacc_dont_warn  = dont_warn_export
    
    641
    +          } (L loc ie@(IEDefault (warn_txt_ps, _) (L lrdr rdr)))
    
    642
    +                   -- see Note [Default exports]
    
    643
    +        = do mb_gre <- lookupGreAvailRn WL_TyCon rdr
    
    644
    +             for mb_gre $ \ gre -> do
    
    645
    +               let name = greName gre
    
    646
    +
    
    647
    +               defaults <- tcg_default <$> getGblEnv
    
    648
    +               exp_dflts' <- do
    
    649
    +                 case lookupUFM_Directly defaults (nameUnique name) of
    
    650
    +                   Nothing ->
    
    651
    +                    do addErr $ TcRnExportHiddenDefault ie
    
    652
    +                       return exp_dflts
    
    653
    +                   Just cls_dflts -> do
    
    654
    +                     let cls = cd_class cls_dflts
    
    655
    +                     case lookupNameEnv exp_dflts (className cls) of
    
    656
    +                       Just (_, ie') -> do
    
    657
    +                         addDiagnostic $
    
    658
    +                           TcRnDuplicateNamedDefaultExport (classTyCon cls) ie ie'
    
    659
    +                         return exp_dflts
    
    660
    +                       Nothing ->
    
    661
    +                        return $ (extendNameEnv exp_dflts (className cls) (cls_dflts, ie))
    
    662
    +
    
    663
    +               checkThLocalNameNoLift (L lrdr (WithUserRdr rdr gre))
    
    664
    +               (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    665
    +                 <- process_warning export_warn_spans
    
    666
    +                                    dont_warn_export
    
    667
    +                                    [name]
    
    668
    +                                    warn_txt_ps
    
    669
    +                                    (locA loc)
    
    670
    +
    
    671
    +               return ( expacc{ expacc_exp_dflts  = exp_dflts'
    
    672
    +                              , expacc_warn_spans = export_warn_spans'
    
    673
    +                              , expacc_dont_warn  = dont_warn_export' }
    
    674
    +                      , L loc (IEDefault warn_txt_rn (L lrdr name))
    
    675
    +                      , Nothing )
    
    676
    +
    
    677 677
         lookup_ie _ _ = panic "lookup_ie"    -- Other cases covered earlier
    
    678 678
     
    
    679
    +    -- Common logic for IEVar and IEPattern in lookup_ie above
    
    680
    +    lookup_ie_var expacc@ExportAccum{
    
    681
    +            expacc_exp_occs   = occs,
    
    682
    +            expacc_warn_spans = export_warn_spans,
    
    683
    +            expacc_dont_warn  = dont_warn_export
    
    684
    +          } loc ie warn_txt_ps what_look lrdr doc mk_ie
    
    685
    +        = do mb_gre <- lookupGreAvailRn what_look $ unLoc lrdr
    
    686
    +             for mb_gre $ \ gre -> do
    
    687
    +               let avail = availFromGRE gre
    
    688
    +                   name = greName gre
    
    689
    +
    
    690
    +               checkThLocalNameNoLift $ fmap @LocatedN (\rdr -> WithUserRdr rdr gre) lrdr
    
    691
    +               occs' <- check_occs occs ie [gre]
    
    692
    +               (export_warn_spans', dont_warn_export', warn_txt_rn)
    
    693
    +                 <- process_warning export_warn_spans
    
    694
    +                                    dont_warn_export
    
    695
    +                                    [name]
    
    696
    +                                    warn_txt_ps
    
    697
    +                                    (locA loc)
    
    698
    +
    
    699
    +               doc' <- traverse rnLHsDoc doc
    
    700
    +               return ( expacc{ expacc_exp_occs   = occs'
    
    701
    +                              , expacc_warn_spans = export_warn_spans'
    
    702
    +                              , expacc_dont_warn  = dont_warn_export' }
    
    703
    +                      , L loc (mk_ie warn_txt_rn name doc')
    
    704
    +                      , Just avail )
    
    679 705
     
    
    680 706
         lookup_ie_kids_with :: GlobalRdrElt -> [LIEWrappedName GhcPs]
    
    681 707
                        -> RnM ([LIEWrappedName GhcRn], [GlobalRdrElt])
    
    ... ... @@ -802,12 +828,11 @@ ieLWrappedUserRdrName l n = (\rdr -> WithUserRdr rdr n) <$> ieLWrappedName l
    802 828
     -- | In what namespaces should we go looking for an import/export item
    
    803 829
     -- that is out of scope, for suggestions in error messages?
    
    804 830
     ieWrappedNameWhatLooking :: IEWrappedName GhcPs -> WhatLooking
    
    805
    -ieWrappedNameWhatLooking = \case
    
    806
    -  IEName {}    -> WL_TyCon_or_TermVar
    
    807
    -  IEDefault {} -> WL_TyCon
    
    808
    -  IEType {}    -> WL_Type
    
    809
    -  IEData {}    -> WL_Term
    
    810
    -  IEPattern {} -> WL_ConLike
    
    831
    +ieWrappedNameWhatLooking wname =
    
    832
    +  case ieWrappedNamespaceSpecifier wname of
    
    833
    +    NoNamespaceSpecifier {}   -> WL_TyCon_or_TermVar
    
    834
    +    TypeNamespaceSpecifier {} -> WL_Type
    
    835
    +    DataNamespaceSpecifier {} -> WL_Term
    
    811 836
     
    
    812 837
     ieLWrappedNameWhatLooking :: LIEWrappedName GhcPs -> WhatLooking
    
    813 838
     ieLWrappedNameWhatLooking = ieWrappedNameWhatLooking . unLoc
    
    ... ... @@ -884,9 +909,9 @@ lookupChildrenExport parent_gre child_gres rdr_items = mapAndReportM doOne rdr_i
    884 909
                   -> RnM (LIEWrappedName GhcRn, GlobalRdrElt)
    
    885 910
             doOne n = do
    
    886 911
     
    
    887
    -          let all_ns = case unLoc n of
    
    888
    -                IEName{} -> True    -- Ignore the namespace iff the name is unadorned
    
    889
    -                _        -> False
    
    912
    +          let all_ns = case ieWrappedNamespaceSpecifier (unLoc n) of
    
    913
    +                NoNamespaceSpecifier{} -> True    -- Ignore the namespace iff the name is unadorned
    
    914
    +                _                      -> False
    
    890 915
               let bareName = lieWrappedName n
    
    891 916
                     -- Do not report export list declaration deprecations
    
    892 917
               name <-  lookupSubBndrOcc_helper False all_ns ExportDeprecationWarnings
    
    ... ... @@ -1114,6 +1139,7 @@ dupExport_ok child ie1 ie2
    1114 1139
     
    
    1115 1140
         single IEVar {}      = True
    
    1116 1141
         single IEThingAbs {} = True
    
    1142
    +    single IEPattern {}  = True
    
    1117 1143
         single _             = False
    
    1118 1144
     
    
    1119 1145
     failWithDcErr :: Name -> Name -> [Name] -> TcM a
    

  • compiler/Language/Haskell/Syntax/Extension.hs
    ... ... @@ -822,8 +822,6 @@ type family XXIE x
    822 822
     type family XIEName p
    
    823 823
     type family XIEDefault p
    
    824 824
     type family XIEPattern p
    
    825
    -type family XIEType p
    
    826
    -type family XIEData p
    
    827 825
     type family XXIEWrappedName p
    
    828 826
     
    
    829 827
     -- -------------------------------------
    

  • compiler/Language/Haskell/Syntax/ImpExp.hs
    ... ... @@ -124,6 +124,25 @@ data IE pass
    124 124
             -- module Mod ( Test(f, g) )
    
    125 125
             -- import Mod ( Test(f, g) )
    
    126 126
             -- @
    
    127
    +  | IEDefault (XIEDefault pass) (LIdP pass)
    
    128
    +        -- ^ Export of named defaults for a given class. Can only occur in export list.
    
    129
    +        --
    
    130
    +        -- @
    
    131
    +        -- module Mod ( default Cls )
    
    132
    +        -- @
    
    133
    +        --
    
    134
    +        -- See Note [Named default declarations] in GHC.Tc.Gen.Default
    
    135
    +  | IEPattern (XIEPattern pass) (LIdP pass) (Maybe (ExportDoc pass))
    
    136
    +        -- ^ Legacy syntax to import or export a pattern synonym or a data
    
    137
    +        -- constructor using the @pattern@ namespace specifier.
    
    138
    +        --
    
    139
    +        -- @
    
    140
    +        -- module Mod ( pattern P )
    
    141
    +        -- import Mod ( pattern P )
    
    142
    +        -- @
    
    143
    +        --
    
    144
    +        -- This form is deprecated in favour of the @data@ namespace specifier.
    
    145
    +        -- Its use is reported by @-Wpattern-namespace-specifier@.
    
    127 146
       | IEModuleContents  (XIEModuleContents pass) (XRec pass HsModuleName)
    
    128 147
             -- ^ Export of entire module. Can only occur in export list.
    
    129 148
             --
    
    ... ... @@ -180,11 +199,9 @@ data IEWildcard
    180 199
     -- adornments. Used primarily for accurate pretty printing of
    
    181 200
     -- ParsedSource, and API Annotation placement.
    
    182 201
     data IEWrappedName p
    
    183
    -  = IEName    (XIEName p)    (LIdP p)  -- ^ unadorned name, e.g @myFun@
    
    184
    -  | IEDefault (XIEDefault p) (LIdP p)  -- ^ @default X ()@, see Note [Named default declarations] in GHC.Tc.Gen.Default
    
    185
    -  | IEPattern (XIEPattern p) (LIdP p)  -- ^ @pattern X@
    
    186
    -  | IEType    (XIEType p)    (LIdP p)  -- ^ @type (:+:)@
    
    187
    -  | IEData    (XIEData p)    (LIdP p)  -- ^ @data (:+:)@
    
    202
    +  = IEName (XIEName p) (NamespaceSpecifier p) (LIdP p)
    
    203
    +      -- ^ A name with an optional namespace specifier,
    
    204
    +      --   e.g. @myFun@, @type (:+:)@, @data P@.
    
    188 205
       | XIEWrappedName !(XXIEWrappedName p)
    
    189 206
     
    
    190 207
     -- | Located name with possible adornment
    

  • testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr
    ... ... @@ -65,6 +65,8 @@
    65 65
              []))
    
    66 66
            (IEName
    
    67 67
             (NoExtField)
    
    68
    +        (NoNamespaceSpecifier
    
    69
    +         (NoExtField))
    
    68 70
             (L
    
    69 71
              (EpAnn
    
    70 72
               (EpaSpan { T17544_kw.hs:9:3-5 })
    
    ... ... @@ -100,6 +102,8 @@
    100 102
              []))
    
    101 103
            (IEName
    
    102 104
             (NoExtField)
    
    105
    +        (NoNamespaceSpecifier
    
    106
    +         (NoExtField))
    
    103 107
             (L
    
    104 108
              (EpAnn
    
    105 109
               (EpaSpan { T17544_kw.hs:10:3-5 })
    
    ... ... @@ -133,6 +137,8 @@
    133 137
              []))
    
    134 138
            (IEName
    
    135 139
             (NoExtField)
    
    140
    +        (NoNamespaceSpecifier
    
    141
    +         (NoExtField))
    
    136 142
             (L
    
    137 143
              (EpAnn
    
    138 144
               (EpaSpan { T17544_kw.hs:11:3-5 })
    

  • testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
    ... ... @@ -2903,6 +2903,8 @@
    2903 2903
                  []))
    
    2904 2904
                (IEName
    
    2905 2905
                 (NoExtField)
    
    2906
    +            (NoNamespaceSpecifier
    
    2907
    +             (NoExtField))
    
    2906 2908
                 (L
    
    2907 2909
                  (EpAnn
    
    2908 2910
                   (EpaSpan { DumpRenamedAst.hs:7:19-22 })
    

  • testsuite/tests/parser/should_compile/T14189.stderr
    ... ... @@ -360,6 +360,8 @@
    360 360
               []))
    
    361 361
             (IEName
    
    362 362
              (NoExtField)
    
    363
    +         (NoNamespaceSpecifier
    
    364
    +          (NoExtField))
    
    363 365
              (L
    
    364 366
               (EpAnn
    
    365 367
                (EpaSpan { T14189.hs:3:3-8 })
    
    ... ... @@ -379,6 +381,8 @@
    379 381
                []))
    
    380 382
              (IEName
    
    381 383
               (NoExtField)
    
    384
    +          (NoNamespaceSpecifier
    
    385
    +           (NoExtField))
    
    382 386
               (L
    
    383 387
                (EpAnn
    
    384 388
                 (EpaSpan { T14189.hs:3:11 })
    
    ... ... @@ -395,6 +399,8 @@
    395 399
                []))
    
    396 400
              (IEName
    
    397 401
               (NoExtField)
    
    402
    +          (NoNamespaceSpecifier
    
    403
    +           (NoExtField))
    
    398 404
               (L
    
    399 405
                (EpAnn
    
    400 406
                 (EpaSpan { T14189.hs:3:13-14 })
    

  • utils/check-exact/ExactPrint.hs
    ... ... @@ -2059,7 +2059,7 @@ instance ExactPrint (WarnDecl GhcPs) where
    2059 2059
     
    
    2060 2060
       exact (Warning (o,c) ns_spec lns (WarningTxt src mb_cat ls )) = do
    
    2061 2061
         mb_cat' <- markAnnotated mb_cat
    
    2062
    -    ns_spec' <- exactNsSpec ns_spec
    
    2062
    +    ns_spec' <- markAnnotated ns_spec
    
    2063 2063
         lns' <- mapM markAnnotated lns
    
    2064 2064
         o' <- markEpToken o
    
    2065 2065
         ls' <- mapM markAnnotated ls
    
    ... ... @@ -2067,22 +2067,13 @@ instance ExactPrint (WarnDecl GhcPs) where
    2067 2067
         return (Warning (o',c') ns_spec' lns' (WarningTxt src mb_cat' ls'))
    
    2068 2068
     
    
    2069 2069
       exact (Warning (o,c) ns_spec lns (DeprecatedTxt src ls)) = do
    
    2070
    -    ns_spec' <- exactNsSpec ns_spec
    
    2070
    +    ns_spec' <- markAnnotated ns_spec
    
    2071 2071
         lns' <- mapM markAnnotated lns
    
    2072 2072
         o' <- markEpToken o
    
    2073 2073
         ls' <- mapM markAnnotated ls
    
    2074 2074
         c' <- markEpToken c
    
    2075 2075
         return (Warning (o',c') ns_spec' lns' (DeprecatedTxt src ls'))
    
    2076 2076
     
    
    2077
    -exactNsSpec :: (Monad m, Monoid w) => NamespaceSpecifier GhcPs -> EP w m (NamespaceSpecifier GhcPs)
    
    2078
    -exactNsSpec (NoNamespaceSpecifier x) = pure (NoNamespaceSpecifier x)
    
    2079
    -exactNsSpec (TypeNamespaceSpecifier type_) = do
    
    2080
    -  type_' <- markEpToken type_
    
    2081
    -  pure (TypeNamespaceSpecifier type_')
    
    2082
    -exactNsSpec (DataNamespaceSpecifier data_) = do
    
    2083
    -  data_' <- markEpToken data_
    
    2084
    -  pure (DataNamespaceSpecifier data_')
    
    2085
    -
    
    2086 2077
     -- ---------------------------------------------------------------------
    
    2087 2078
     
    
    2088 2079
     instance ExactPrint (StringLiteral GhcPs) where
    
    ... ... @@ -4719,6 +4710,19 @@ instance ExactPrint (IE GhcPs) where
    4719 4710
         doc' <- markAnnotated doc
    
    4720 4711
         return (IEThingWith (depr', (op',dd',c',cp')) thing' wc' withs' doc')
    
    4721 4712
     
    
    4713
    +  exact (IEDefault (depr, r) n) = do
    
    4714
    +    depr' <- markAnnotated depr
    
    4715
    +    r' <- markEpToken r
    
    4716
    +    n' <- markAnnotated n
    
    4717
    +    return (IEDefault (depr', r') n')
    
    4718
    +
    
    4719
    +  exact (IEPattern (depr, r) n doc) = do
    
    4720
    +    depr' <- markAnnotated depr
    
    4721
    +    r' <- markEpToken r
    
    4722
    +    n' <- markAnnotated n
    
    4723
    +    doc' <- markAnnotated doc
    
    4724
    +    return (IEPattern (depr', r') n' doc')
    
    4725
    +
    
    4722 4726
       exact (IEModuleContents (depr, an) m) = do
    
    4723 4727
         depr' <- markAnnotated depr
    
    4724 4728
         an0 <- markEpToken an
    
    ... ... @@ -4746,25 +4750,10 @@ instance ExactPrint (IEWrappedName GhcPs) where
    4746 4750
       getAnnotationEntry = const NoEntryVal
    
    4747 4751
       setAnnotationAnchor a _ _ _ = a
    
    4748 4752
     
    
    4749
    -  exact (IEName x n) = do
    
    4750
    -    n' <- markAnnotated n
    
    4751
    -    return (IEName x n')
    
    4752
    -  exact (IEDefault r n) = do
    
    4753
    -    r' <- markEpToken r
    
    4754
    -    n' <- markAnnotated n
    
    4755
    -    return (IEDefault r' n')
    
    4756
    -  exact (IEPattern r n) = do
    
    4757
    -    r' <- markEpToken r
    
    4758
    -    n' <- markAnnotated n
    
    4759
    -    return (IEPattern r' n')
    
    4760
    -  exact (IEType r n) = do
    
    4761
    -    r' <- markEpToken r
    
    4762
    -    n' <- markAnnotated n
    
    4763
    -    return (IEType r' n')
    
    4764
    -  exact (IEData r n) = do
    
    4765
    -    r' <- markEpToken r
    
    4753
    +  exact (IEName x ns_spec n) = do
    
    4754
    +    ns_spec' <- markAnnotated ns_spec
    
    4766 4755
         n' <- markAnnotated n
    
    4767
    -    return (IEData r' n')
    
    4756
    +    return (IEName x ns_spec' n')
    
    4768 4757
     
    
    4769 4758
     -- ---------------------------------------------------------------------
    
    4770 4759
     
    

  • utils/check-exact/Main.hs
    ... ... @@ -865,8 +865,9 @@ addHiding1 _libdir (L l p) = do
    865 865
               [L li imp1,imp2] = hsmodImports p
    
    866 866
               n1 = L noAnnSrcSpanDP0 (mkVarUnqual (mkFastString "n1"))
    
    867 867
               n2 = L noAnnSrcSpanDP0 (mkVarUnqual (mkFastString "n2"))
    
    868
    -          v1 = L (addComma $ noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField n1)) Nothing)
    
    869
    -          v2 = L (           noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField n2)) Nothing)
    
    868
    +          v1 = L (addComma $ noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField ns_spec n1)) Nothing)
    
    869
    +          v2 = L (           noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField ns_spec n2)) Nothing)
    
    870
    +          ns_spec = NoNamespaceSpecifier noExtField
    
    870 871
               impHiding = [v1,v2]
    
    871 872
               impAnnList = (EpTok d1, EpTok d1, EpTok d0, [])
    
    872 873
               imp1' = imp1 { ideclExt
    
    ... ... @@ -892,8 +893,9 @@ addHiding2 _libdir top = do
    892 893
               Just (_, ns) = ideclImportList imp1
    
    893 894
               n1 = L (noAnnSrcSpanDP0) (mkVarUnqual (mkFastString "n1"))
    
    894 895
               n2 = L (noAnnSrcSpanDP0) (mkVarUnqual (mkFastString "n2"))
    
    895
    -          v1 = L (addComma $ noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField n1)) Nothing)
    
    896
    -          v2 = L (           noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField n2)) Nothing)
    
    896
    +          v1 = L (addComma $ noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField ns_spec n1)) Nothing)
    
    897
    +          v2 = L (           noAnnSrcSpanDP0) (IEVar Nothing (L noAnnSrcSpanDP0 (IEName noExtField ns_spec n2)) Nothing)
    
    898
    +          ns_spec = NoNamespaceSpecifier noExtField
    
    897 899
               L ln n = last ns
    
    898 900
               n' = L (addComma ln) n
    
    899 901
               impAnnList = (EpTok d1, EpTok d1, EpTok d0, [])