Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 11a04cbb by Eric Lee at 2026-02-11T09:20:46-05:00 Derive Semigroup/Monoid for instances believed could be derived in #25871 - - - - - 15d9ce44 by Eric Lee at 2026-02-11T09:20:46-05:00 add Ghc.Data.Pair deriving - - - - - c85dc170 by Evan Piro at 2026-02-11T09:21:45-05:00 Linker.MacOS reduce options import - - - - - 3f354418 by Chris Wendt at 2026-02-11T10:25:29-05:00 Initialize plugins for `:set +c` in GHCi Fixes #23110. - - - - - dcf12dd8 by Cheng Shao at 2026-02-11T10:25:31-05:00 compiler: add Binary Text instance This patch adds `Binary` instance for strict `Text`, in preparation of making `Text` usable in certain GHC API use cases (e.g. haddock). This also introduces `text` as a direct dependency of the `ghc` package. - - - - - 6e38eec1 by Cheng Shao at 2026-02-11T10:25:32-05:00 ghc-toolchain: add C11 check This patch partially reverts commit b8307eab80c5809df5405d76c822bf86877f5960 that removed C99 check in autoconf/ghc-toolchain. Now we: - No longer re-implement `FP_SET_CFLAGS_C11` similar to `FP_SET_CFLAGS_C99` in the past, since autoconf doesn't provide a convenient `AC_PROG_CC_C11` function. ghc-toolchain will handle it anyway. - The Cmm CPP C99 check is relanded and repurposed for C11. - The C99 logic in ghc-toolchain is relanded and repurposed for C11. - The C99 check in Stg.h is corrected to check for C11. The obsolete _ISOC99_SOURCE trick is dropped. - Usages of `-std=gnu99` in the testsuite are corrected to use `-std=gnu11`. Closes #26908. - - - - - 25 changed files: - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Data/Pair.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/HsToCore/Pmc.hs - compiler/GHC/HsToCore/Pmc/Solver/Types.hs - compiler/GHC/Linker/MacOS.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Tc/Utils/TcMType.hs - compiler/GHC/Types/Unique/DSet.hs - compiler/GHC/Utils/Binary.hs - compiler/GHC/Utils/Ppr/Colour.hs - compiler/ghc.cabal.in - configure.ac - distrib/configure.ac.in - ghc/GHCi/UI/Info.hs - m4/fp_cmm_cpp_cmd_with_args.m4 - rts/include/Stg.h - testsuite/tests/ffi/should_run/all.T - + testsuite/tests/plugins/T23110.hs - + testsuite/tests/plugins/T23110.script - + testsuite/tests/plugins/T23110.stdout - testsuite/tests/plugins/all.T - utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs - utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs Changes: ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -2,6 +2,8 @@ {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE ParallelListComp #-} {-# LANGUAGE NondecreasingIndentation #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} ----------------------------------------------------------------------------- -- @@ -72,6 +74,8 @@ import GHC.Cmm.CLabel import GHC.Types.Tickish ( GenTickish(..) ) import GHC.Types.SrcLoc ( srcSpanFile, srcSpanStartLine, srcSpanStartCol ) +import GHC.Generics (Generic, Generically(..)) + -- The rest: import GHC.Data.Maybe ( expectJust ) import GHC.Types.ForeignCall ( CCallConv(..) ) @@ -429,7 +433,7 @@ getRegisterReg _ (CmmLocal lreg) = getLocalRegReg lreg getRegisterReg platform (CmmGlobal mid) = case globalRegMaybe platform $ globalRegUse_reg mid of - Just reg -> RegReal $ reg + Just reg -> RegReal reg Nothing -> pprPanic "getRegisterReg-memory" (ppr $ CmmGlobal mid) -- By this stage, the only MagicIds remaining should be the -- ones which map to a real machine register on this @@ -4776,11 +4780,8 @@ data LoadArgs -- | The code to assign arguments to registers used for argument passing. , assignArgsCode :: InstrBlock } -instance Semigroup LoadArgs where - LoadArgs a1 d1 r1 j1 <> LoadArgs a2 d2 r2 j2 - = LoadArgs (a1 ++ a2) (d1 ++ d2) (r1 ++ r2) (j1 S.<> j2) -instance Monoid LoadArgs where - mempty = LoadArgs [] [] [] nilOL + deriving (Generic) + deriving (Semigroup, Monoid) via Generically LoadArgs -- | An argument passed on the stack, either directly or by reference. -- ===================================== compiler/GHC/CmmToLlvm/CodeGen.hs ===================================== @@ -1,6 +1,8 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE MultiWayIf #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} -- | Handle conversion of CmmProc to LLVM code. module GHC.CmmToLlvm.CodeGen ( genLlvmProc ) where @@ -29,6 +31,8 @@ import GHC.Data.FastString import GHC.Data.Maybe (expectJust) import GHC.Data.OrdList +import GHC.Generics (Generic, Generically(..)) + import GHC.Types.ForeignCall import GHC.Types.Unique.DSM import GHC.Types.Unique @@ -2445,14 +2449,8 @@ getTBAARegMeta = getTBAAMeta . getTBAA -- | A more convenient way of accumulating LLVM statements and declarations. data LlvmAccum = LlvmAccum LlvmStatements [LlvmCmmDecl] - -instance Semigroup LlvmAccum where - LlvmAccum stmtsA declsA <> LlvmAccum stmtsB declsB = - LlvmAccum (stmtsA Semigroup.<> stmtsB) (declsA Semigroup.<> declsB) - -instance Monoid LlvmAccum where - mempty = LlvmAccum nilOL [] - mappend = (Semigroup.<>) + deriving (Generic) + deriving (Monoid, Semigroup) via Generically LlvmAccum liftExprData :: LlvmM ExprData -> WriterT LlvmAccum LlvmM LlvmVar liftExprData action = do ===================================== compiler/GHC/Data/Pair.hs ===================================== @@ -1,3 +1,6 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} + {- A simple homogeneous pair type with useful Functor, Applicative, and Traversable instances. @@ -20,8 +23,12 @@ import GHC.Prelude import GHC.Utils.Outputable import qualified Data.Semigroup as Semi +import GHC.Generics (Generic, Generically(..)) + data Pair a = Pair { pFst :: a, pSnd :: a } - deriving (Foldable, Functor, Traversable) + deriving (Foldable, Functor, Traversable, Generic) + deriving (Semigroup, Monoid) via Generically (Pair a) + -- Note that Pair is a *unary* type constructor -- whereas (,) is binary @@ -33,13 +40,6 @@ instance Applicative Pair where pure x = Pair x x (Pair f g) <*> (Pair x y) = Pair (f x) (g y) -instance Semi.Semigroup a => Semi.Semigroup (Pair a) where - Pair a1 b1 <> Pair a2 b2 = Pair (a1 Semi.<> a2) (b1 Semi.<> b2) - -instance (Semi.Semigroup a, Monoid a) => Monoid (Pair a) where - mempty = Pair mempty mempty - mappend = (Semi.<>) - instance Outputable a => Outputable (Pair a) where ppr (Pair a b) = ppr a <+> char '~' <+> ppr b ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -1,8 +1,8 @@ {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow] -- in module Language.Haskell.Syntax.Extension - +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} {-# OPTIONS_GHC -Wno-orphans #-} -- NamedThing, Outputable, OutputableBndrId {- @@ -116,6 +116,7 @@ import GHC.Core.Ppr ( pprOccWithTick) import GHC.Core.Type import GHC.Core.Multiplicity( pprArrowWithMultiplicity ) import GHC.Hs.Doc +import GHC.Generics (Generic, Generically(..)) import GHC.Types.Basic import GHC.Types.SrcLoc import GHC.Utils.Outputable @@ -231,6 +232,8 @@ data HsTyPatRnBuilder = hstpb_imp_tvs :: Bag Name, hstpb_exp_tvs :: Bag Name } + deriving (Generic) + deriving (Semigroup, Monoid) via Generically HsTyPatRnBuilder tpBuilderExplicitTV :: Name -> HsTyPatRnBuilder tpBuilderExplicitTV name = mempty {hstpb_exp_tvs = unitBag name} @@ -242,16 +245,6 @@ tpBuilderPatSig HsPSRn {hsps_nwcs, hsps_imp_tvs} = hstpb_imp_tvs = listToBag hsps_imp_tvs } -instance Semigroup HsTyPatRnBuilder where - HsTPRnB nwcs1 imp_tvs1 exptvs1 <> HsTPRnB nwcs2 imp_tvs2 exptvs2 = - HsTPRnB - (nwcs1 `unionBags` nwcs2) - (imp_tvs1 `unionBags` imp_tvs2) - (exptvs1 `unionBags` exptvs2) - -instance Monoid HsTyPatRnBuilder where - mempty = HsTPRnB emptyBag emptyBag emptyBag - buildHsTyPatRn :: HsTyPatRnBuilder -> HsTyPatRn buildHsTyPatRn HsTPRnB {hstpb_nwcs, hstpb_imp_tvs, hstpb_exp_tvs} = HsTPRn { ===================================== compiler/GHC/HsToCore/Pmc.hs ===================================== @@ -1,3 +1,6 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} + -- | This module coverage checks pattern matches. It finds -- -- * Uncovered patterns, certifying non-exhaustivity @@ -61,6 +64,7 @@ import {-# SOURCE #-} GHC.HsToCore.Expr (dsLExpr) import GHC.HsToCore.Monad import GHC.Data.Bag import GHC.Data.OrdList +import GHC.Generics (Generic, Generically(..)) import Control.Monad (when, unless, forM_) import qualified Data.Semigroup as Semi @@ -442,13 +446,8 @@ data CIRB , cirb_red :: !(OrdList SrcInfo) -- ^ Redundant clauses , cirb_bangs :: !(OrdList SrcInfo) -- ^ Redundant bang patterns } - -instance Semigroup CIRB where - CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) - where (<>) = (Semi.<>) - -instance Monoid CIRB where - mempty = CIRB mempty mempty mempty mempty + deriving (Generic) + deriving (Semigroup, Monoid) via Generically CIRB -- See Note [Determining inaccessible clauses] ensureOneNotRedundant :: CIRB -> CIRB ===================================== compiler/GHC/HsToCore/Pmc/Solver/Types.hs ===================================== @@ -2,6 +2,8 @@ {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} -- | Domain types used in "GHC.HsToCore.Pmc.Solver". -- The ultimate goal is to define 'Nabla', which models normalised refinement @@ -68,6 +70,7 @@ import GHC.Types.CompleteMatch import GHC.Types.SourceText (SourceText(..), mkFractionalLit, FractionalLit , fractionalLitFromRational , FractionalExponentBase(..)) +import GHC.Generics (Generic, Generically(..)) import Numeric (fromRat) import Data.Ratio @@ -104,19 +107,13 @@ instance Outputable Nabla where -- | A disjunctive bag of 'Nabla's, representing a refinement type. newtype Nablas = MkNablas (Bag Nabla) + -- deriving 'Outputable' removes `MkNablas` label + deriving (Generic, Outputable) + deriving (Semigroup, Monoid) via Generically Nablas initNablas :: Nablas initNablas = MkNablas (unitBag initNabla) -instance Outputable Nablas where - ppr (MkNablas nablas) = ppr nablas - -instance Semigroup Nablas where - MkNablas l <> MkNablas r = MkNablas (l `unionBags` r) - -instance Monoid Nablas where - mempty = MkNablas emptyBag - -- | The type oracle state. An 'GHC.Tc.Solver.Monad.InertSet' that we -- incrementally add local type constraints to, together with a sequence -- number that counts the number of times we extended it with new facts. ===================================== compiler/GHC/Linker/MacOS.hs ===================================== @@ -19,9 +19,9 @@ import GHC.SysTools.Tasks import GHC.Runtime.Interpreter +import GHC.Utils.CliOption import GHC.Utils.Exception import GHC.Utils.Logger -import GHC.Driver.Session import Data.List (isPrefixOf, nub, sort, intersperse, intercalate) import Data.Char ===================================== compiler/GHC/Parser/PostProcess/Haddock.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ApplicativeDo #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE TypeFamilies #-} @@ -61,6 +62,7 @@ import {-# SOURCE #-} GHC.Parser (parseIdentifier) import GHC.Parser.Lexer import GHC.Parser.HaddockLex import GHC.Parser.Errors.Types +import GHC.Generics (Generic, Generically(..)) import GHC.Utils.Misc (mergeListsBy, filterOut, (<&&>)) import qualified GHC.Data.Strict as Strict @@ -1347,13 +1349,8 @@ data LocRange = { loc_range_from :: !LowerLocBound, loc_range_to :: !UpperLocBound, loc_range_col :: !ColumnBound } - -instance Semigroup LocRange where - LocRange from1 to1 col1 <> LocRange from2 to2 col2 = - LocRange (from1 <> from2) (to1 <> to2) (col1 <> col2) - -instance Monoid LocRange where - mempty = LocRange mempty mempty mempty + deriving (Generic) + deriving (Semigroup, Monoid) via Generically LocRange -- The location range from the specified position to the end of the file. locRangeFrom :: Strict.Maybe BufPos -> LocRange ===================================== compiler/GHC/Tc/Utils/TcMType.hs ===================================== @@ -1,6 +1,8 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE RecursiveDo #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} {- @@ -145,6 +147,8 @@ import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Utils.Constants (debugIsOn) +import GHC.Generics (Generic, Generically(..)) + import Control.Monad import Data.IORef import GHC.Data.Maybe @@ -1267,17 +1271,8 @@ data CandidatesQTvs -- These are covars. Included only so that we don't repeatedly -- look at covars' kinds in accumulator. Not used by quantifyTyVars. } - -instance Semi.Semigroup CandidatesQTvs where - (DV { dv_kvs = kv1, dv_tvs = tv1, dv_cvs = cv1 }) - <> (DV { dv_kvs = kv2, dv_tvs = tv2, dv_cvs = cv2 }) - = DV { dv_kvs = kv1 `unionDVarSet` kv2 - , dv_tvs = tv1 `unionDVarSet` tv2 - , dv_cvs = cv1 `unionVarSet` cv2 } - -instance Monoid CandidatesQTvs where - mempty = DV { dv_kvs = emptyDVarSet, dv_tvs = emptyDVarSet, dv_cvs = emptyVarSet } - mappend = (Semi.<>) + deriving (Generic) + deriving (Semigroup, Monoid) via Generically CandidatesQTvs instance Outputable CandidatesQTvs where ppr (DV {dv_kvs = kvs, dv_tvs = tvs, dv_cvs = cvs }) ===================================== compiler/GHC/Types/Unique/DSet.hs ===================================== @@ -44,6 +44,7 @@ import GHC.Types.Unique import Data.Coerce import Data.Data +import Data.Semigroup -- See Note [UniqSet invariant] in GHC.Types.Unique.Set for why we want a newtype here. -- Beyond preserving invariants, we may also want to 'override' typeclass @@ -154,3 +155,9 @@ instance Outputable a => Outputable (UniqDSet a) where pprUniqDSet :: (a -> SDoc) -> UniqDSet a -> SDoc pprUniqDSet f = braces . pprWithCommas f . uniqDSetToList + +instance Semigroup (UniqDSet a) where + (<>) = unionUniqDSets + +instance Monoid (UniqDSet a) where + mempty = emptyUniqDSet ===================================== compiler/GHC/Utils/Binary.hs ===================================== @@ -150,6 +150,7 @@ import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Internal as BS import qualified Data.ByteString.Unsafe as BS import qualified Data.ByteString.Short.Internal as SBS +import qualified Data.Text.Internal as T import Data.IORef import Data.Char ( ord, chr ) import Data.List.NonEmpty ( NonEmpty(..)) @@ -1816,13 +1817,19 @@ putSBS :: WriteBinHandle -> SBS.ShortByteString -> IO () putSBS bh sbs = do let l = SBS.length sbs put_ bh l - putPrim bh l (\p -> SBS.copyToPtr sbs 0 p l) + putSBSOffLen bh sbs 0 l +putSBSOffLen :: WriteBinHandle -> SBS.ShortByteString -> Int -> Int -> IO () +putSBSOffLen bh sbs off len = + putPrim bh len $ \p -> SBS.copyToPtr sbs off p len getSBS :: ReadBinHandle -> IO SBS.ShortByteString getSBS bh = do l <- get bh :: IO Int - getPrim bh l (\src -> SBS.createFromPtr src l) + getSBSLen bh l + +getSBSLen :: ReadBinHandle -> Int -> IO SBS.ShortByteString +getSBSLen bh len = getPrim bh len $ \src -> SBS.createFromPtr src len putBS :: WriteBinHandle -> ByteString -> IO () putBS bh bs = @@ -1856,6 +1863,16 @@ instance Binary LBS.ByteString where get bh = LBS.fromStrict <$> get bh +instance Binary T.Text where + put_ bh (T.Text ba off len) = do + put_ bh len + putSBSOffLen bh (SBS.ShortByteString ba) off len + + get bh = do + len <- get bh + SBS.ShortByteString ba <- getSBSLen bh len + pure $ T.Text ba 0 len + instance Binary FastString where put_ bh f = case findUserDataWriter (Proxy :: Proxy FastString) bh of ===================================== compiler/GHC/Utils/Ppr/Colour.hs ===================================== @@ -1,21 +1,17 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} + module GHC.Utils.Ppr.Colour where import GHC.Prelude.Basic import Data.Maybe (fromMaybe) import GHC.Data.Bool -import Data.Semigroup as Semi +import GHC.Generics (Generic, Generically(..)) -- | A colour\/style for use with 'coloured'. newtype PprColour = PprColour { renderColour :: String } - -instance Semi.Semigroup PprColour where - PprColour s1 <> PprColour s2 = PprColour (s1 <> s2) - --- | Allow colours to be combined (e.g. bold + red); --- In case of conflict, right side takes precedence. -instance Monoid PprColour where - mempty = PprColour mempty - mappend = (<>) + deriving (Generic) + deriving (Semigroup, Monoid) via Generically PprColour renderColourAfresh :: PprColour -> String renderColourAfresh c = renderColour (colReset `mappend` c) ===================================== compiler/ghc.cabal.in ===================================== @@ -120,6 +120,7 @@ Library process >= 1 && < 1.7, bytestring >= 0.11 && < 0.13, binary == 0.8.*, + text >= 2.0 && < 2.2, time >= 1.4 && < 1.16, containers >= 0.6.2.1 && < 0.9, array >= 0.1 && < 0.6, ===================================== configure.ac ===================================== @@ -671,8 +671,8 @@ FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2]) # CPP, CPPFLAGS # --with-cpp/-with-cpp-flags -dnl Note that we must do this after setting and using the C99 CPPFLAGS, or -dnl otherwise risk trying to configure the C99 and LD flags using -E as a CPPFLAG +dnl Note that we must do this after setting and using the C11 CPPFLAGS, or +dnl otherwise risk trying to configure the C11 and LD flags using -E as a CPPFLAG FP_CPP_CMD_WITH_ARGS([$CC_STAGE0],[CPPCmd_STAGE0],[CONF_CPP_OPTS_STAGE0]) FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE1]) FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE2]) ===================================== distrib/configure.ac.in ===================================== @@ -313,8 +313,8 @@ FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2]) # CPP, CPPFLAGS # --with-cpp/-with-cpp-flags -dnl Note that we must do this after setting and using the C99 CPPFLAGS, or -dnl otherwise risk trying to configure the C99 and LD flags using -E as a CPPFLAG +dnl Note that we must do this after setting and using the C11 CPPFLAGS, or +dnl otherwise risk trying to configure the C11 and LD flags using -E as a CPPFLAG FP_CPP_CMD_WITH_ARGS([$CC_STAGE0],[CPPCmd_STAGE0],[CONF_CPP_OPTS_STAGE0]) FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE1]) FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE2]) ===================================== ghc/GHCi/UI/Info.hs ===================================== @@ -46,6 +46,8 @@ import GHC.Utils.Outputable import GHC.Types.SrcLoc import GHC.Types.Var import qualified GHC.Data.Strict as Strict +import GHC.Runtime.Loader (initializePlugins) +import Data.Containers.ListUtils (nubOrd) import GHCi.UI.Exception @@ -301,6 +303,13 @@ srcFilePath modSum = fromMaybe obj_fp src_fp getModInfo :: (GhcMonad m) => Module -> m ModInfo getModInfo m = do mod_summary <- getModSummary m + + -- Update the session plugins from the module summary + -- and initialize them (#23110). + modifySession $ hscUpdateFlags $ \dynFlags -> dynFlags + { pluginModNames = nubOrd $ pluginModNames dynFlags ++ pluginModNames (ms_hspp_opts mod_summary) } + modifySessionM (liftIO . initializePlugins) + p <- parseModule mod_summary typechecked <- typecheckModule p let allTypes = processAllTypeCheckedModule typechecked ===================================== m4/fp_cmm_cpp_cmd_with_args.m4 ===================================== @@ -56,6 +56,27 @@ else AC_MSG_RESULT([no]) fi +AC_MSG_CHECKING([the C-- preprocessor for C11 support]) +cat > conftest.c <<EOF +#include <stdio.h> +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "Compiler does not advertise C11 conformance" +#endif +EOF +if "$CMM_CPP_CMD" $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then + AC_MSG_RESULT([yes]) +else + # Try -std=gnu11 + if "$CMM_CPP_CMD" -std=gnu11 $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then + $3="-std=gnu11 $$3" + AC_MSG_RESULT([needs -std=gnu11]) + else + AC_MSG_ERROR([C11-compatible compiler needed]) + fi +fi +rm -f conftest.c conftest.o conftest + + $2="$CMM_CPP_CMD" $3="$$3 $CMM_CPP_ARGS" ===================================== rts/include/Stg.h ===================================== @@ -31,8 +31,8 @@ #define __STDC_VERSION__ 0 #endif -#if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus >= 201103L) -# error __STDC_VERSION__ does not advertise C99, C++11 or later +#if !(__STDC_VERSION__ >= 201112L) && !(__cplusplus >= 201103L) +# error __STDC_VERSION__ does not advertise C11, C++11 or later #endif /* @@ -49,10 +49,6 @@ #if !defined(IN_STG_CODE) # define IN_STG_CODE 1 -// Turn on C99 for .hc code. This gives us the INFINITY and NAN -// constants from math.h, which we occasionally need to use in .hc (#1861) -# define _ISOC99_SOURCE - // We need _BSD_SOURCE so that math.h defines things like gamma // on Linux # define _BSD_SOURCE ===================================== testsuite/tests/ffi/should_run/all.T ===================================== @@ -103,7 +103,7 @@ test('T2276_ghci', [ only_ghci, pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup ghciWayFlags=' + config.ghci_way_flags) ], compile_and_run, ['-fobject-code T2276_ghci_c.o']) -test('T2469', normal, compile_and_run, ['-optc-std=gnu99']) +test('T2469', normal, compile_and_run, ['-optc-std=gnu11']) test('T2594', [req_c], compile_and_run, ['T2594_c.c']) ===================================== testsuite/tests/plugins/T23110.hs ===================================== @@ -0,0 +1,6 @@ +{-# OPTIONS_GHC -fplugin=Simple.SourcePlugin #-} + +module Main where + +main :: IO () +main = return () ===================================== testsuite/tests/plugins/T23110.script ===================================== @@ -0,0 +1,3 @@ +:set +c +:load T23110.hs +-- The key thing is that plugins should be run AFTER "Collecting type info..." ===================================== testsuite/tests/plugins/T23110.stdout ===================================== @@ -0,0 +1,11 @@ +parsePlugin() +typeCheckPlugin (rn) +interfacePlugin: GHC.Internal.Tuple +interfacePlugin: GHC.Internal.Stack.Types +interfacePlugin: GHC.Internal.Exception.Context +interfacePlugin: GHC.Internal.TopHandler +typeCheckPlugin (tc) +Collecting type info for 1 module(s) ... +parsePlugin() +typeCheckPlugin (rn) +typeCheckPlugin (tc) ===================================== testsuite/tests/plugins/all.T ===================================== @@ -332,6 +332,19 @@ test('T20803b', compile_fail, ['-package-db T20803-plugin/pkg.T20803b/local.package.conf -fplugin AddErrorPlugin -package T20803-plugin ' + config.plugin_way_flags]) +# Check that we run the plugins for set +c. +# The .stdout file should contain a call to 'parsePlugin' AFTER +# the line 'Collecting type info...' +test('T23110' + , [ extra_files([ 'simple-plugin/']) + , only_ways(['ghci']) + , pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.simpleplug TOP={top}') + , extra_hc_opts('-package-db simple-plugin/pkg.simpleplug/local.package.conf') + ] + , ghci_script + , [ 'T23110.script' ] + ) + test('test-echo-in-turn', [extra_files(['echo-plugin/']), pre_cmd('$MAKE -s --no-print-directory -C echo-plugin package.test-echo-in-turn TOP={top}')], ===================================== utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs ===================================== @@ -11,6 +11,7 @@ module GHC.Toolchain.Tools.Cc , compileC , compileAsm , addPlatformDepCcFlags + , checkC11Support ) where import Control.Monad @@ -50,8 +51,12 @@ findCc archOs llvmTarget progOpt = do cc1 <- ignoreUnusedArgs cc0 cc2 <- ccSupportsTarget archOs llvmTarget cc1 checking "whether Cc works" $ checkCcWorks cc2 - checkCcSupportsExtraViaCFlags cc2 - return cc2 + cc3 <- oneOf "cc doesn't support C11" $ map checkC11Support + [ cc2 + , cc2 & _ccFlags %++ "-std=gnu11" + ] + checkCcSupportsExtraViaCFlags cc3 + return cc3 checkCcWorks :: Cc -> M () checkCcWorks cc = withTempDir $ \dir -> do @@ -83,6 +88,17 @@ ccSupportsTarget archOs target cc = checking "whether Cc supports --target" $ supportsTarget archOs _ccProgram checkCcWorks target cc +checkC11Support :: Cc -> M Cc +checkC11Support cc = checking "for C11 support" $ withTempDir $ \dir -> do + let test_o = dir </> "test.o" + compileC cc test_o $ unlines + [ "#include <stdio.h>" + , "#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L" + , "# error \"Compiler does not advertise C11 conformance\"" + , "#endif" + ] + return cc + checkCcSupportsExtraViaCFlags :: Cc -> M () checkCcSupportsExtraViaCFlags cc = checking "whether cc supports extra via-c flags" $ withTempDir $ \dir -> do let test_o = dir </> "test.o" ===================================== utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs ===================================== @@ -19,7 +19,7 @@ import GHC.Toolchain.Prelude import GHC.Toolchain.Program import GHC.Toolchain.Tools.Cc -import GHC.Toolchain.Utils (withTempDir, expectFileExists) +import GHC.Toolchain.Utils (withTempDir, oneOf, expectFileExists) newtype Cpp = Cpp { cppProgram :: Program } @@ -160,7 +160,13 @@ findJsCpp progOpt cc = checking "for JavaScript C preprocessor" $ do findCmmCpp :: ProgOpt -> Cc -> M CmmCpp findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do -- Use the specified CPP or try to use the c compiler - cpp <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) []) + foundCppProg <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) []) + -- Check whether the C preprocessor needs -std=gnu11 (only very old toolchains need this) + Cc cpp <- oneOf "cc doesn't support C11" $ map checkC11Support + [ Cc foundCppProg + , Cc (foundCppProg & _prgFlags %++ "-std=gnu11") + ] + cmmCppSupportsG0 <- withTempDir $ \dir -> do let conftest = dir </> "conftest.c" writeFile conftest "int main(void) {}" @@ -175,9 +181,14 @@ findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do findCpp :: ProgOpt -> Cc -> M Cpp findCpp progOpt cc = checking "for C preprocessor" $ do -- Use the specified CPP or try to use the c compiler - cpp <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) []) + foundCppProg <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) []) + -- Check whether the C preprocessor needs -std=gnu11 (only very old toolchains need this) + Cc cpp2 <- oneOf "cc doesn't support C11" $ map checkC11Support + [ Cc foundCppProg + , Cc (foundCppProg & _prgFlags %++ "-std=gnu11") + ] -- Always add the -E flag to the CPP, regardless of the user options - let cppProgram = addFlagIfNew "-E" cpp + let cppProgram = addFlagIfNew "-E" cpp2 return Cpp{cppProgram} -------------------------------------------------------------------------------- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4f42954afe40dc269881a19c0ef1c1f... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4f42954afe40dc269881a19c0ef1c1f... You're receiving this email because of your account on gitlab.haskell.org.