[Git][ghc/ghc][master] Propagate annotations to simple interfaces
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: d538cac9 by Facundo Domínguez at 2026-10-09T20:26:38-04:00 Propagate annotations to simple interfaces This allows annotations to be visible to plugins when run by haddock. The LiquidHaskell plugin needs the annotations, in particular. Fixes #26761 - - - - - 7 changed files: - + changelog.d/26761 - compiler/GHC/Iface/Tidy.hs - + testsuite/tests/plugins/T26761.hs - + testsuite/tests/plugins/T26761.stderr - + testsuite/tests/plugins/T26761Plugin.hs - + testsuite/tests/plugins/T26761a.hs - testsuite/tests/plugins/all.T Changes: ===================================== changelog.d/26761 ===================================== @@ -0,0 +1,5 @@ +section: compiler +synopsis: Propagate annotations when producing simple interfaces. +description: Plugins that require annotations can now succeed even when run by Haddock. +mrs: !16754 +issues: #26761 ===================================== compiler/GHC/Iface/Tidy.hs ===================================== @@ -172,7 +172,8 @@ mkBootModDetailsTc logger tcg_fam_insts = fam_insts, tcg_complete_matches = complete_matches, tcg_mod = this_mod, - tcg_default_exports = default_exports + tcg_default_exports = default_exports, + tcg_anns = anns } = -- This timing isn't terribly useful since the result isn't forced, but -- the message is useful to locating oneself in the compilation process. @@ -184,7 +185,7 @@ mkBootModDetailsTc logger , md_insts = insts' , md_fam_insts = fam_insts , md_rules = [] - , md_anns = [] + , md_anns = anns , md_exports = exports , md_complete_matches = complete_matches }) ===================================== testsuite/tests/plugins/T26761.hs ===================================== @@ -0,0 +1,6 @@ +{-# OPTIONS_GHC -fplugin=T26761Plugin #-} +-- | A module that imports another module with an annotation. +-- We want to check that the annotation is found by the plugin even +-- when the imported module uses -fno-code. +module T26761 where +import T26761a ===================================== testsuite/tests/plugins/T26761.stderr ===================================== @@ -0,0 +1,4 @@ +[1 of 3] Compiling T26761Plugin ( T26761Plugin.hs, T26761Plugin.o ) +[2 of 3] Compiling T26761a ( T26761a.hs, nothing ) +[3 of 3] Compiling T26761 ( T26761.hs, T26761.o ) +Found 1 annotations for direct import: T26761a ===================================== testsuite/tests/plugins/T26761Plugin.hs ===================================== @@ -0,0 +1,42 @@ +-- | A GHC plugin that prints the annotations of direct imports of a module. +-- Also adds an annotation to the module itself. +module T26761Plugin where + +import Control.Monad (forM_) +import GHC +import GHC.Plugins +import GHC.Tc.Types +import GHC.Tc.Utils.Monad +import qualified Data.Map as Map +import Data.Word (Word8) +import System.IO (hFlush, stdout) + +plugin :: Plugin +plugin = defaultPlugin { typeCheckResultAction = typecheckPlugin } + where + typecheckPlugin :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv + typecheckPlugin opts summary gblEnv = do + hscEnv <- getTopEnv + let home_unit = hsc_home_unit hscEnv + directImports = + filter (isHomeModule home_unit) $ Map.keys $ imp_mods $ tcg_imports gblEnv + annEnv <- liftIO $ prepareAnnotations hscEnv Nothing + forM_ directImports $ \mod0 -> liftIO $ + case findAnns id annEnv (ModuleTarget mod0) of + [] -> pure () + anns -> do + putStrLn $ concat + [ "Found " + , show (length anns) + , " annotations for direct import: " + , moduleNameString (moduleName mod0) + ] + -- TODO: Remove #20791 + liftIO $ hFlush stdout + + -- Insert an annotation for the current module itself, so that we can + -- check that it is visible from other modules. + let ann = Annotation + (ModuleTarget $ tcg_mod gblEnv) + (toSerialized id [0]) + return gblEnv { tcg_anns = ann : tcg_anns gblEnv } ===================================== testsuite/tests/plugins/T26761a.hs ===================================== @@ -0,0 +1,5 @@ +{-# OPTIONS_GHC -fno-code -fplugin=T26761Plugin #-} +-- | A module with an annotation that we can find from a plugin. +-- The annotations should be visible even when using -fno-code. +-- The annotation is inserted by the plugin itself. +module T26761a where ===================================== testsuite/tests/plugins/all.T ===================================== @@ -154,6 +154,9 @@ test('T14335', ['-package-db simple-plugin/pkg.plugins01/local.package.conf -fplugin Simple.Plugin \ -fexternal-interpreter -package simple-plugin ' + config.plugin_way_flags]) +test('T26761', [extra_files(['T26761Plugin.hs', 'T26761a.hs'])], + multimod_compile, ['T26761', '-package ghc ' + config.plugin_way_flags ]) + test('plugin-recomp-pure', [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']), View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d538cac9aab579eb9e2db60512427b2c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d538cac9aab579eb9e2db60512427b2c... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Marge Bot (@marge-bot)