Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

7 changed files:

Changes:

  • changelog.d/26761
    1
    +section: compiler
    
    2
    +synopsis: Propagate annotations when producing simple interfaces.
    
    3
    +description: Plugins that require annotations can now succeed even when run by Haddock.
    
    4
    +mrs: !16754
    
    5
    +issues: #26761

  • compiler/GHC/Iface/Tidy.hs
    ... ... @@ -172,7 +172,8 @@ mkBootModDetailsTc logger
    172 172
                       tcg_fam_insts        = fam_insts,
    
    173 173
                       tcg_complete_matches = complete_matches,
    
    174 174
                       tcg_mod              = this_mod,
    
    175
    -                  tcg_default_exports  = default_exports
    
    175
    +                  tcg_default_exports  = default_exports,
    
    176
    +                  tcg_anns             = anns
    
    176 177
                     }
    
    177 178
       = -- This timing isn't terribly useful since the result isn't forced, but
    
    178 179
         -- the message is useful to locating oneself in the compilation process.
    
    ... ... @@ -184,7 +185,7 @@ mkBootModDetailsTc logger
    184 185
                            , md_insts            = insts'
    
    185 186
                            , md_fam_insts        = fam_insts
    
    186 187
                            , md_rules            = []
    
    187
    -                       , md_anns             = []
    
    188
    +                       , md_anns             = anns
    
    188 189
                            , md_exports          = exports
    
    189 190
                            , md_complete_matches = complete_matches
    
    190 191
                            })
    

  • testsuite/tests/plugins/T26761.hs
    1
    +{-# OPTIONS_GHC -fplugin=T26761Plugin #-}
    
    2
    +-- | A module that imports another module with an annotation.
    
    3
    +-- We want to check that the annotation is found by the plugin even
    
    4
    +-- when the imported module uses -fno-code.
    
    5
    +module T26761 where
    
    6
    +import T26761a

  • testsuite/tests/plugins/T26761.stderr
    1
    +[1 of 3] Compiling T26761Plugin     ( T26761Plugin.hs, T26761Plugin.o )
    
    2
    +[2 of 3] Compiling T26761a          ( T26761a.hs, nothing )
    
    3
    +[3 of 3] Compiling T26761           ( T26761.hs, T26761.o )
    
    4
    +Found 1 annotations for direct import: T26761a

  • testsuite/tests/plugins/T26761Plugin.hs
    1
    +-- | A GHC plugin that prints the annotations of direct imports of a module.
    
    2
    +-- Also adds an annotation to the module itself.
    
    3
    +module T26761Plugin where
    
    4
    +
    
    5
    +import Control.Monad (forM_)
    
    6
    +import GHC
    
    7
    +import GHC.Plugins
    
    8
    +import GHC.Tc.Types
    
    9
    +import GHC.Tc.Utils.Monad
    
    10
    +import qualified Data.Map as Map
    
    11
    +import Data.Word (Word8)
    
    12
    +import System.IO (hFlush, stdout)
    
    13
    +
    
    14
    +plugin :: Plugin
    
    15
    +plugin = defaultPlugin { typeCheckResultAction = typecheckPlugin }
    
    16
    +  where
    
    17
    +    typecheckPlugin :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
    
    18
    +    typecheckPlugin opts summary gblEnv = do
    
    19
    +      hscEnv <- getTopEnv
    
    20
    +      let home_unit = hsc_home_unit hscEnv
    
    21
    +          directImports =
    
    22
    +            filter (isHomeModule home_unit) $ Map.keys $ imp_mods $ tcg_imports gblEnv
    
    23
    +      annEnv <- liftIO $ prepareAnnotations hscEnv Nothing
    
    24
    +      forM_ directImports $ \mod0 -> liftIO $
    
    25
    +        case findAnns id annEnv (ModuleTarget mod0) of
    
    26
    +          [] -> pure ()
    
    27
    +          anns -> do
    
    28
    +            putStrLn $ concat
    
    29
    +              [ "Found "
    
    30
    +              , show (length anns)
    
    31
    +              , " annotations for direct import: "
    
    32
    +              , moduleNameString (moduleName mod0)
    
    33
    +              ]
    
    34
    +            -- TODO: Remove #20791
    
    35
    +            liftIO $ hFlush stdout
    
    36
    +
    
    37
    +      -- Insert an annotation for the current module itself, so that we can
    
    38
    +      -- check that it is visible from other modules.
    
    39
    +      let ann = Annotation
    
    40
    +                  (ModuleTarget $ tcg_mod gblEnv)
    
    41
    +                  (toSerialized id [0])
    
    42
    +      return gblEnv { tcg_anns = ann : tcg_anns gblEnv }

  • testsuite/tests/plugins/T26761a.hs
    1
    +{-# OPTIONS_GHC -fno-code -fplugin=T26761Plugin #-}
    
    2
    +-- | A module with an annotation that we can find from a plugin.
    
    3
    +-- The annotations should be visible even when using -fno-code.
    
    4
    +-- The annotation is inserted by the plugin itself.
    
    5
    +module T26761a where

  • testsuite/tests/plugins/all.T
    ... ... @@ -154,6 +154,9 @@ test('T14335',
    154 154
          ['-package-db simple-plugin/pkg.plugins01/local.package.conf -fplugin Simple.Plugin \
    
    155 155
            -fexternal-interpreter -package simple-plugin ' + config.plugin_way_flags])
    
    156 156
     
    
    157
    +test('T26761', [extra_files(['T26761Plugin.hs', 'T26761a.hs'])],
    
    158
    +     multimod_compile, ['T26761', '-package ghc ' + config.plugin_way_flags ])
    
    159
    +
    
    157 160
     test('plugin-recomp-pure',
    
    158 161
          [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
    
    159 162