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

Commits:

4 changed files:

Changes:

  • compiler/GHC/Tc/Types.hs
    ... ... @@ -1250,14 +1250,17 @@ emptyTcMPluginsShutdown = TcMPluginsShutdown
    1250 1250
     data TcMPluginsState
    
    1251 1251
       -- | The 'TcM' plugins have not been started.
    
    1252 1252
       = TcMPluginsUninitialised
    
    1253
    -  -- | The 'TcM' plugins have been initialised and not yet stopped.
    
    1253
    +  -- | The 'TcM' plugins have been initialised and not yet stopped,
    
    1254
    +  -- or there were no 'TcM' plugins to start with.
    
    1254 1255
       --
    
    1255 1256
       -- We may be in the middle of typechecker, or have finished typechecking
    
    1256 1257
       -- and be in the middle of desugaring.
    
    1257 1258
       | TcMPluginsRunning !RunningTcMPlugins
    
    1258
    -  -- | The 'TcM' plugins have been stopped.
    
    1259
    +  -- | There were 'TcM' plugins that were running, but they have been stopped.
    
    1259 1260
       | TcMPluginsStopped
    
    1260 1261
     
    
    1262
    +-- | A (possibly empty) collection of 'TcM' plugin @run@, @post-tc@ and
    
    1263
    +-- @shutdown@ actions.
    
    1261 1264
     data RunningTcMPlugins =
    
    1262 1265
       RunningTcMPlugins
    
    1263 1266
         { rtcmp_run      :: TcMPluginsRun
    
    ... ... @@ -1281,11 +1284,20 @@ tcMPluginsShutdownActions = rtcmp_shutdown
    1281 1284
     
    
    1282 1285
     -- | Retrieve the 'TcM' plugins from a 'TcMPluginsState'.
    
    1283 1286
     --
    
    1284
    --- Assumes the plugins have been already started and not yet stopped.
    
    1287
    +-- Assumes the plugins (if any) have been already started and not yet stopped.
    
    1285 1288
     runningTcMPlugins
    
    1286 1289
        :: HasDebugCallStack
    
    1287 1290
        => TcMPluginsState -> RunningTcMPlugins
    
    1288 1291
     runningTcMPlugins = \case
    
    1289
    -  TcMPluginsUninitialised -> panic "runningTcMPlugins: TcM plugins not started"
    
    1290
    -  TcMPluginsStopped -> panic "runningTcMPlugins: TcM plugins already stopped"
    
    1292
    +  TcMPluginsUninitialised ->
    
    1293
    +    pprPanic "TcM plugins have not been started" $
    
    1294
    +      vcat [ text "If you are a GHC API user, make sure to use an appropriate 'TcMPluginHandling'"
    
    1295
    +           , text "to ensure that TcM plugins (if any) are initialised before typechecking."
    
    1296
    +           ]
    
    1297
    +  TcMPluginsStopped ->
    
    1298
    +    pprPanic "TcM plugins already stopped" $
    
    1299
    +      vcat [ text "If you are a GHC API user and want to proceed to desugaring after typechecking,"
    
    1300
    +           , text "make sure you are not using the 'StartAndStopTcMPlugins' 'TcMPluginHandling',"
    
    1301
    +           , text "as that stops TcM plugins after typechecking."
    
    1302
    +           ]
    
    1291 1303
       TcMPluginsRunning plugins -> plugins

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -790,9 +790,10 @@ withoutTcMPlugins thing_inside = do
    790 790
           tcg_env <- getGblEnv
    
    791 791
           writeTcRef (tcg_plugins tcg_env) $
    
    792 792
             TcMPluginsRunning emptyRunningTcMPlugins
    
    793
    -    teardown = do
    
    794
    -      tcg_env <- getGblEnv
    
    795
    -      writeTcRef (tcg_plugins tcg_env) TcMPluginsStopped
    
    793
    +    teardown =
    
    794
    +      -- Don't set 'tcg_plugins' to 'TcMPluginsStopped', as that should only
    
    795
    +      -- be used when there were 'TcM' plugins to start with (#27273).
    
    796
    +      return ()
    
    796 797
     
    
    797 798
     -- | Initialise 'TcM' plugins.
    
    798 799
     initTcMPlugins :: HscEnv -> TcM ()
    
    ... ... @@ -946,32 +947,20 @@ shutdownTcMPlugins = \case
    946 947
           runPluginShutdowns (tcs ++ defs)
    
    947 948
     
    
    948 949
     solverTcMPlugins :: HasDebugCallStack => TcMPluginsState -> [TcPluginSolver]
    
    949
    -solverTcMPlugins = \case
    
    950
    -  TcMPluginsUninitialised -> panic "solverTcMPlugins: TcM plugins not started"
    
    951
    -  TcMPluginsStopped -> panic "solverTcMPlugins: TcM plugins already stopped"
    
    952
    -  TcMPluginsRunning plugins ->
    
    953
    -    tcmp_solvers (tcMPluginsRunActions plugins)
    
    950
    +solverTcMPlugins =
    
    951
    +  tcmp_solvers . tcMPluginsRunActions . runningTcMPlugins
    
    954 952
     
    
    955 953
     rewriterTcMPlugins :: HasDebugCallStack => TcMPluginsState -> UniqFM TyCon [TcPluginRewriter]
    
    956
    -rewriterTcMPlugins = \case
    
    957
    -  TcMPluginsUninitialised -> panic "rewriterTcMPlugins: TcM plugins not started"
    
    958
    -  TcMPluginsStopped -> panic "rewriterTcMPlugins: TcM plugins already stopped"
    
    959
    -  TcMPluginsRunning plugins ->
    
    960
    -    tcmp_rewriters (tcMPluginsRunActions plugins)
    
    954
    +rewriterTcMPlugins =
    
    955
    +  tcmp_rewriters . tcMPluginsRunActions . runningTcMPlugins
    
    961 956
     
    
    962 957
     defaultingTcMPlugins :: HasDebugCallStack => TcMPluginsState -> [FillDefaulting]
    
    963
    -defaultingTcMPlugins = \case
    
    964
    -  TcMPluginsUninitialised -> panic "defaultingTcMPlugins: TcM plugins not started"
    
    965
    -  TcMPluginsStopped -> panic "defaultingTcMPlugins: TcM plugins already stopped"
    
    966
    -  TcMPluginsRunning plugins ->
    
    967
    -    tcmp_defaulters (tcMPluginsRunActions plugins)
    
    958
    +defaultingTcMPlugins =
    
    959
    +  tcmp_defaulters . tcMPluginsRunActions . runningTcMPlugins
    
    968 960
     
    
    969 961
     holeFitTcMPlugins :: HasDebugCallStack => TcMPluginsState -> [HoleFitPlugin]
    
    970
    -holeFitTcMPlugins = \case
    
    971
    -  TcMPluginsUninitialised -> panic "holeFitTcMPlugins: TcM plugins not started"
    
    972
    -  TcMPluginsStopped -> panic "holeFitTcMPlugins: TcM plugins already stopped"
    
    973
    -  TcMPluginsRunning plugins ->
    
    974
    -    tcmp_hole_fits (tcMPluginsRunActions plugins)
    
    962
    +holeFitTcMPlugins =
    
    963
    +  tcmp_hole_fits . tcMPluginsRunActions . runningTcMPlugins
    
    975 964
     
    
    976 965
     {-
    
    977 966
     ************************************************************************
    

  • testsuite/tests/ghc-api/T27273.hs
    1
    +module Main where
    
    2
    +
    
    3
    +-- base
    
    4
    +import Control.Monad
    
    5
    +import Control.Monad.IO.Class (liftIO)
    
    6
    +import System.Environment (getArgs)
    
    7
    +
    
    8
    +-- time
    
    9
    +import Data.Time (getCurrentTime)
    
    10
    +
    
    11
    +-- ghc
    
    12
    +import qualified GHC as GHC
    
    13
    +import qualified GHC.Core as GHC
    
    14
    +import qualified GHC.Data.StringBuffer as GHC
    
    15
    +import qualified GHC.Unit.Module.ModGuts as GHC
    
    16
    +import qualified GHC.Unit.Types as GHC
    
    17
    +
    
    18
    +--------------------------------------------------------------------------------
    
    19
    +
    
    20
    +main :: IO ()
    
    21
    +main = do
    
    22
    +    let inputSource = unlines
    
    23
    +          [ "module NumLitDesugaring where"
    
    24
    +          , "f :: Num a => a" -- !!! Succeeds if type signature is f :: Int
    
    25
    +          , "f = 1"
    
    26
    +          ]
    
    27
    +
    
    28
    +    void $ compileToCore "NumLitDesugaring" inputSource
    
    29
    +
    
    30
    +compileToCore :: String -> String -> IO [GHC.CoreBind]
    
    31
    +compileToCore modName inputSource = do
    
    32
    +    [libdir] <- getArgs
    
    33
    +    GHC.runGhc (Just libdir) $ do
    
    34
    +      (_ms, tcMod) <- typecheckSourceCode modName inputSource
    
    35
    +      dsMod <- GHC.desugarModule tcMod
    
    36
    +      return $ GHC.mg_binds $ GHC.dm_core_module dsMod
    
    37
    +
    
    38
    +typecheckSourceCode
    
    39
    +  :: GHC.GhcMonad m => String -> String -> m (GHC.ModSummary, GHC.TypecheckedModule)
    
    40
    +typecheckSourceCode modName inputSource = do
    
    41
    +    now <- liftIO getCurrentTime
    
    42
    +    df1 <- GHC.getSessionDynFlags
    
    43
    +    GHC.setSessionDynFlags $ df1 { GHC.backend = GHC.bytecodeBackend }
    
    44
    +    let target = GHC.Target
    
    45
    +               { GHC.targetId           = GHC.TargetFile (modName ++ ".hs") Nothing
    
    46
    +               , GHC.targetUnitId       = GHC.homeUnitId_ df1
    
    47
    +               , GHC.targetAllowObjCode = False
    
    48
    +               , GHC.targetContents     = Just (GHC.stringToStringBuffer inputSource, now)
    
    49
    +               }
    
    50
    +    GHC.setTargets [target]
    
    51
    +    void $ GHC.depanal [] False
    
    52
    +
    
    53
    +    ms <- GHC.getModSummary
    
    54
    +            (GHC.mkModule GHC.mainUnit (GHC.mkModuleName modName))
    
    55
    +    tm <- GHC.parseModule ms >>= GHC.typecheckModule GHC.NoTcMPlugins
    
    56
    +    return (ms, tm)

  • testsuite/tests/ghc-api/all.T
    ... ... @@ -82,3 +82,6 @@ test('TypeMapStringLiteral', normal, compile_and_run, ['-package ghc'])
    82 82
     
    
    83 83
     test('T25121_status', normal, compile_and_run, ['-package ghc'])
    
    84 84
     test('T24386', [extra_run_opts(f'"{config.libdir}"')], compile_and_run, ['-package ghc'])
    
    85
    +test('T27273', [extra_run_opts(f'"{config.libdir}"')],
    
    86
    +               compile_and_run,
    
    87
    +               ['-package ghc'])