diff --git a/.ci/docker/build-and-publish-docker-image.sh b/.ci/docker/build-and-publish-docker-image.sh index 73306be82d..16d1d741c3 100755 --- a/.ci/docker/build-and-publish-docker-image.sh +++ b/.ci/docker/build-and-publish-docker-image.sh @@ -14,8 +14,8 @@ elif [[ "$1" != "" ]]; then exit 1 fi UBUNTU_VERSION=jammy-20250126 -GHC_VERSIONS=("9.10.1" "9.8.4" "9.6.7" "9.4.8" "9.2.8" "9.0.2" "8.10.7") -CABAL_VERSIONS=("3.14.1.1" "3.14.1.1" "3.14.1.1" "3.14.1.1" "3.14.1.1" "3.14.1.1" "3.12.1.0") +GHC_VERSIONS=("9.12.2" "9.10.1" "9.8.4" "9.6.7" "9.4.8" "9.2.8" "9.0.2" "8.10.7") +CABAL_VERSIONS=("3.14.2.0" "3.14.2.0" "3.14.2.0" "3.14.2.0" "3.14.2.0" "3.14.2.0" "3.14.2.0" "3.12.1.0") # We want to use docker buildkit so that our layers are built in parallel. This # is ignored completely on versions of docker which don't support buildkit. diff --git a/.ci/gitlab/common.yml b/.ci/gitlab/common.yml index ba29f26052..ab37527be8 100644 --- a/.ci/gitlab/common.yml +++ b/.ci/gitlab/common.yml @@ -12,8 +12,8 @@ default: timeout: 10 minutes stage: build variables: - CLASH_DOCKER_TAG: 20250402 - CACHE_BUST_TOKEN: 3 + CLASH_DOCKER_TAG: 20250419 + CACHE_BUST_TOKEN: 4 # Note that we copy+paste the image name into CACHE_FALLBACK_KEY. If we don't, # $GHC_VERSION gets inserted at verbatim, instead of resolving to some ghc version. CACHE_FALLBACK_KEY: $CI_JOB_NAME-master-ghcr.io/clash-lang/clash-ci:$GHC_VERSION-$CLASH_DOCKER_TAG-$CACHE_BUST_TOKEN-3-non_protected diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fb6d47da54..92707c5b03 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,12 +34,18 @@ tests: CI_PARENT_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE parallel: matrix: - - GHC_VERSION: 9.10.1 + - GHC_VERSION: 9.12.2 RUN_TESTS: "always" + # TODO: remove this when https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12264#note_602406 + # has landed in stable release + SKIP_CLASH_FFI_EXAMPLE: "yes" + + - GHC_VERSION: 9.10.1 + RUN_TESTS: "nightly" - GHC_VERSION: 9.8.4 # TODO: remove this when https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12264#note_602406 - # is fixed + # has landed in stable release SKIP_CLASH_FFI_EXAMPLE: "yes" RUN_TESTS: "always" diff --git a/README.md b/README.md index 8553482fe3..b978819745 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ Note that release branches might contain non-released patches. | 9.6 | ✔️3 | ✔️3,4 | ✔️3 | 1.8 | ✔️ | 9.8 | ✔️ | ✔️4 | ✔️ | 1.8 | ️✔️ | 9.10 | ✔️ | ✔️4 | ✔️ | 1.8 | ️✔️ +| 9.12 | ✔️ | ✔️4,5 | ✔️5 | 1.8.3 | ️✔️ 1 GHC 9.2 contains a regression, rendering Clash error messages indecipherable. This change was reverted in 9.4. @@ -85,7 +86,9 @@ Note that release branches might contain non-released patches. 3 Clash starts extremely slowly when compiled with 9.4.8 up to and including 9.6.2. Consider downgrading to 9.4.7 or upgrading to 9.6.3 and up. -4 Clash starts extremely slowly on Windows with GHC 9.6 through 9.10, consider downgrading to 9.4.7 +4 Clash starts extremely slowly on Windows with GHC 9.6 through 9.12, consider downgrading to 9.4.7 + +5 We're waiting for Stackage to publish a nightly based on GHC 9.12 in order to get CI working on Windows and macOS. ## Cabal To use Cabal you need both Cabal and GHC installed on your system. We recommend using [ghcup](https://www.haskell.org/ghcup/). For more information, see [https://www.haskell.org/downloads/](https://www.haskell.org/downloads/). diff --git a/cabal.project b/cabal.project index 67281bb607..e06d7bf79d 100644 --- a/cabal.project +++ b/cabal.project @@ -15,7 +15,7 @@ write-ghc-environment-files: always -- index state, to go along with the cabal.project.freeze file. update the index -- state by running `cabal update` twice and looking at the index state it -- displays to you (as the second update will be a no-op) -index-state: 2025-02-10T14:25:49Z +index-state: 2025-04-19T07:34:07Z -- For some reason the `clash-testsuite` executable fails to run without -- this, as it cannot find the related library... diff --git a/changelog/2025-04-20T23_25_06+02_00_add_ghc912_support b/changelog/2025-04-20T23_25_06+02_00_add_ghc912_support new file mode 100644 index 0000000000..3c80f45774 --- /dev/null +++ b/changelog/2025-04-20T23_25_06+02_00_add_ghc912_support @@ -0,0 +1 @@ +ADD: Added GHC 9.12 support diff --git a/clash-cosim/src/Clash/CoSim/Types.hs b/clash-cosim/src/Clash/CoSim/Types.hs index e88a6c1551..b59c9bbe53 100644 --- a/clash-cosim/src/Clash/CoSim/Types.hs +++ b/clash-cosim/src/Clash/CoSim/Types.hs @@ -1,5 +1,7 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-| @@ -11,7 +13,10 @@ be housed in Simulator.hs, but FFI code crashes Template Haskell. -} module Clash.CoSim.Types where -import Data.Data (Data, Typeable) +import Data.Data (Data) +#if __GLASGOW_HASKELL__ <= 910 +import Data.Data (Typeable) +#endif import Clash.Prelude (BitPack, BitSize, KnownNat) import Clash.XException (NFDataX) @@ -28,7 +33,10 @@ data CoSimSettings = CoSimSettings -- ^ Include files while running simulator , enableStdout :: Bool -- ^ Print verbose output to stdout - } deriving (Show, Typeable, Data) + } deriving (Show, Data) +#if __GLASGOW_HASKELL__ <= 910 + deriving Typeable +#endif -- | Default simulator settings use Icarus, have a period of 20 and all other -- options disabled. @@ -53,4 +61,7 @@ data CoSimulator = Icarus -- ^ https://github.com/steveicarus/iverilog | ModelSim -- ^ https://www.mentor.com/products/fv/modelsim/ - deriving (Show, Eq, Typeable, Data) + deriving (Show, Eq, Data) +#if __GLASGOW_HASKELL__ <= 910 + deriving Typeable +#endif diff --git a/clash-ghc/clash-ghc.cabal b/clash-ghc/clash-ghc.cabal index 915f93b770..3b894be8de 100644 --- a/clash-ghc/clash-ghc.cabal +++ b/clash-ghc/clash-ghc.cabal @@ -121,7 +121,9 @@ common common-options library import: common-options HS-Source-Dirs: src-ghc, src-bin-common - if impl(ghc >= 9.10.0) + if impl(ghc >= 9.12.0) + HS-Source-Dirs: src-bin-9.12 + elif impl(ghc >= 9.10.0) HS-Source-Dirs: src-bin-9.10 elif impl(ghc >= 9.8.0) HS-Source-Dirs: src-bin-9.8 @@ -151,7 +153,7 @@ library base >= 4.11 && < 5, bytestring >= 0.9 && < 0.13, Cabal, - containers >= 0.5.4.0 && < 0.8, + containers >= 0.5.4.0 && < 0.9, data-binary-ieee754 >= 0.4.4 && < 0.6, directory >= 1.2 && < 1.4, extra >= 1.6 && < 1.9, @@ -173,23 +175,23 @@ library ghc-typelits-natnormalise >= 0.6 && < 0.8, deepseq >= 1.3.0.2 && < 1.6, time >= 1.4.0.1 && < 1.15, - ghc-boot >= 8.10.0 && < 9.11, - ghc-prim >= 0.3.1.0 && < 0.12, - ghci >= 8.10.0 && < 9.11, + ghc-boot >= 8.10.0 && < 9.13, + ghc-prim >= 0.3.1.0 && < 0.14, + ghci >= 8.10.0 && < 9.13, uniplate >= 1.6.12 && < 1.8, reflection >= 2.1.2 && < 3.0, primitive >= 0.5.0.1 && < 1.0, string-interpolate ^>= 0.3, - template-haskell >= 2.8.0.0 && < 2.23, + template-haskell >= 2.8.0.0 && < 2.24, utf8-string >= 1.0.0.0 && < 1.1.0.0, vector >= 0.11 && < 1.0 if os(darwin) -- 8.10 is broken on macOS - it exits tests with status code -11 - Build-Depends: ghc >= 9.0.0 && < 9.11 + Build-Depends: ghc >= 9.0.0 && < 9.13 else -- Unix - Build-Depends: ghc >= 8.10.0 && < 9.11 + Build-Depends: ghc >= 8.10.0 && < 9.13 if impl(ghc >= 8.10.0) Build-Depends: exceptions >= 0.10.4 && < 0.11, diff --git a/clash-ghc/src-bin-9.12/Clash/GHCi/Leak.hs b/clash-ghc/src-bin-9.12/Clash/GHCi/Leak.hs new file mode 100644 index 0000000000..0598540af1 --- /dev/null +++ b/clash-ghc/src-bin-9.12/Clash/GHCi/Leak.hs @@ -0,0 +1,85 @@ +{-# LANGUAGE RecordWildCards, LambdaCase #-} +module Clash.GHCi.Leak + ( LeakIndicators + , getLeakIndicators + , checkLeakIndicators + ) where + +import Clash.GHCi.Util +import Control.Monad +import Data.Bits +import Foreign.Ptr (ptrToIntPtr, intPtrToPtr) +import GHC +import GHC.Ptr (Ptr (..)) +import GHC.Driver.Env +import GHC.Driver.Ppr +import GHC.Utils.Outputable +import GHC.Unit.Module.ModDetails +import GHC.Unit.Home.ModInfo +import GHC.Platform (target32Bit) +import GHC.Linker.Types +import Prelude +import System.Mem +import System.Mem.Weak +import GHC.Types.Unique.DFM +import Control.Exception + +-- Checking for space leaks in GHCi. See #15111, and the +-- -fghci-leak-check flag. + +data LeakIndicators = LeakIndicators [LeakModIndicators] + +data LeakModIndicators = LeakModIndicators + { leakMod :: Weak HomeModInfo + , leakIface :: Weak ModIface + , leakDetails :: Weak ModDetails + , leakLinkable :: [Maybe (Weak Linkable)] + } + +-- | Grab weak references to some of the data structures representing +-- the currently loaded modules. +getLeakIndicators :: HscEnv -> IO LeakIndicators +getLeakIndicators hsc_env = + fmap LeakIndicators $ + forM (eltsUDFM (hsc_HPT hsc_env)) $ \hmi@HomeModInfo{..} -> do + leakMod <- mkWeakPtr hmi Nothing + leakIface <- mkWeakPtr hm_iface Nothing + leakDetails <- mkWeakPtr hm_details Nothing + leakLinkable <- mkWeakLinkables hm_linkable + return $ LeakModIndicators{..} + where + mkWeakLinkables :: HomeModLinkable -> IO [Maybe (Weak Linkable)] + mkWeakLinkables (HomeModLinkable mbc mo) = + mapM (\ln -> traverse (flip mkWeakPtr Nothing <=< evaluate) ln) [mbc, mo] + +-- | Look at the LeakIndicators collected by an earlier call to +-- `getLeakIndicators`, and print messasges if any of them are still +-- alive. +checkLeakIndicators :: DynFlags -> LeakIndicators -> IO () +checkLeakIndicators dflags (LeakIndicators leakmods) = do + performGC + forM_ leakmods $ \LeakModIndicators{..} -> do + deRefWeak leakMod >>= \case + Nothing -> return () + Just hmi -> + report ("HomeModInfo for " ++ + showSDoc dflags (ppr (mi_module (hm_iface hmi)))) (Just hmi) + deRefWeak leakIface >>= \case + Nothing -> return () + Just miface -> report ("ModIface:" ++ moduleNameString (moduleName (mi_module miface))) (Just miface) + deRefWeak leakDetails >>= report "ModDetails" + forM_ leakLinkable $ \l -> forM_ l $ \l' -> deRefWeak l' >>= report "Linkable" + where + report :: String -> Maybe a -> IO () + report _ Nothing = return () + report msg (Just a) = do + addr <- anyToPtr a + putStrLn ("-fghci-leak-check: " ++ msg ++ " is still alive at " ++ + show (maskTagBits addr)) + + tagBits + | target32Bit (targetPlatform dflags) = 2 + | otherwise = 3 + + maskTagBits :: Ptr a -> Ptr a + maskTagBits p = intPtrToPtr (ptrToIntPtr p .&. complement (shiftL 1 tagBits - 1)) diff --git a/clash-ghc/src-bin-9.12/Clash/GHCi/UI.hs b/clash-ghc/src-bin-9.12/Clash/GHCi/UI.hs new file mode 100644 index 0000000000..32f6c1bcfe --- /dev/null +++ b/clash-ghc/src-bin-9.12/Clash/GHCi/UI.hs @@ -0,0 +1,4882 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE NondecreasingIndentation #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE TypeFamilies #-} + +{-# OPTIONS -fno-warn-name-shadowing #-} +-- This module does a lot of it + +----------------------------------------------------------------------------- +-- +-- GHC Interactive User Interface +-- +-- (c) The GHC Team 2005-2006 +-- +----------------------------------------------------------------------------- + +module Clash.GHCi.UI ( + interactiveUI, + GhciSettings(..), + defaultGhciSettings, + ghciCommands, + ghciWelcomeMsg, + makeHDL + ) where + +-- GHCi +import qualified Clash.GHCi.UI.Monad as GhciMonad ( args, runStmt, runDecls' ) +import Clash.GHCi.UI.Monad hiding ( args, runStmt ) +import Clash.GHCi.UI.Info +import Clash.GHCi.UI.Exception +import GHC.Runtime.Debugger +import GHC.Runtime.Eval (mkTopLevEnv) + +-- The GHC interface +import GHC.Runtime.Interpreter +import GHCi.RemoteTypes +import GHCi.BreakArray( breakOn, breakOff ) +import GHC.ByteCode.Types +import GHC.Core.DataCon +import GHC.Core.ConLike +import GHC.Core.PatSyn +import GHC.Driver.Flags +import GHC.Driver.Errors +import GHC.Driver.Errors.Types +import GHC.Driver.Phases +import GHC.Driver.Session as DynFlags +import GHC.Driver.Ppr hiding (printForUser) +import GHC.Utils.Error hiding (traceCmd) +import GHC.Driver.Monad ( modifySession ) +import GHC.Driver.Make ( newIfaceCache, ModIfaceCache(..) ) +import GHC.Driver.Config.Parser (initParserOpts) +import GHC.Driver.Config.Diagnostic +import qualified GHC +import GHC ( LoadHowMuch(..), Target(..), TargetId(..), + Resume, SingleStep, Ghc, + GetDocsFailure(..), pushLogHookM, + getModuleGraph, handleSourceError, ms_mod ) +import GHC.Driver.Main (hscParseModuleWithLocation, hscParseStmtWithLocation) +import GHC.Hs.ImpExp +import GHC.Hs +import GHC.Driver.Env +import GHC.Runtime.Context +import GHC.Types.TyThing +import GHC.Types.TyThing.Ppr +import GHC.Core.TyCo.Ppr +import GHC.Types.SafeHaskell ( getSafeMode ) +import GHC.Types.SourceError ( SourceError ) +import GHC.Types.Name +import GHC.Types.Breakpoint +import GHC.Types.Var ( varType ) +import GHC.Iface.Syntax ( showToHeader ) +import GHC.Builtin.Names +import GHC.Builtin.Types( stringTyCon_RDR ) +import GHC.Types.Name.Reader as RdrName ( getGRE_NameQualifier_maybes, getRdrName, greName, globalRdrEnvElts) +import GHC.Types.SrcLoc as SrcLoc +import qualified GHC.Parser.Lexer as Lexer +import GHC.Parser.Header ( toArgs ) +import qualified GHC.Parser.Header as Header +import GHC.Types.PkgQual + +import GHC.Unit +import GHC.Unit.Finder as Finder +import GHC.Unit.Module.Graph (filterToposortToModules) +import GHC.Unit.Module.ModSummary + +import GHC.Data.StringBuffer +import GHC.Utils.Outputable +import GHC.Utils.Logger + +-- Other random utilities +import GHC.Types.Basic hiding ( isTopLevel ) +import GHC.Data.Graph.Directed +import GHC.Utils.Encoding +import GHC.Data.FastString +import qualified GHC.Linker.Loader as Loader +import GHC.Data.Maybe ( expectJust ) +import GHC.Types.Name.Set +import GHC.Utils.Panic hiding ( showException, try ) +import GHC.Utils.Misc +import qualified GHC.LanguageExtensions as LangExt +import qualified GHC.Data.Strict as Strict +import GHC.Types.Error + +-- Haskell Libraries +import System.Console.Haskeline as Haskeline + +import Control.Applicative hiding (empty) +import Control.DeepSeq (deepseq) +import Control.Monad as Monad +import Control.Monad.Catch as MC +import Control.Monad.IO.Class +import Control.Monad.Trans.Class +import Control.Monad.Trans.Except + +import Data.Array +import qualified Data.ByteString.Char8 as BS +import Data.Char +import Data.Function +import Data.IORef ( IORef, modifyIORef, newIORef, readIORef, writeIORef ) +import Data.List ( elemIndices, find, intercalate, intersperse, minimumBy, + isPrefixOf, isSuffixOf, nub, partition, sort, sortBy, (\\) ) +import qualified Data.List.NonEmpty as NE +import qualified Data.Set as S +import Data.Maybe +import qualified Data.Map as M +import Data.IntMap.Strict (IntMap) +import qualified Data.IntMap.Strict as IntMap +import Data.Time.LocalTime ( getZonedTime ) +import Data.Time.Format ( formatTime, defaultTimeLocale ) +import Data.Version ( showVersion ) +import qualified Data.Semigroup as S +import Prelude hiding ((<>)) + +import GHC.Utils.Exception as Exception hiding (catch, mask, handle) +import Foreign hiding (void) +import GHC.Stack hiding (SrcLoc(..)) +import GHC.Unit.Env +import GHC.Unit.Home.ModInfo + +import System.Directory +import System.Environment +import System.Exit ( exitWith, ExitCode(..) ) +import System.FilePath +import System.Info +import System.IO +import System.IO.Error +import System.IO.Unsafe ( unsafePerformIO ) +import System.Process +import Text.Printf +import Text.Read ( readMaybe ) +import Text.Read.Lex (isSymbolChar) + +import Unsafe.Coerce + +#if !defined(mingw32_HOST_OS) +import System.Posix hiding ( getEnv ) +#else +import qualified System.Win32 +#endif + +import GHC.IO.Exception ( IOErrorType(InvalidArgument) ) +import GHC.IO.Handle ( hFlushAll ) +import GHC.TopHandler ( topHandler ) + +import Clash.GHCi.Leak +import qualified GHC.Unit.Module.Graph as GHC + +-- clash additions +import Clash.Backend (Backend(initBackend, hdlKind, primDirs)) +import Clash.Backend.SystemVerilog (SystemVerilogState) +import Clash.Backend.VHDL (VHDLState) +import Clash.Backend.Verilog (VerilogState) +import qualified Clash.Driver +import Clash.Driver.Bool (fromGhcOverridingBool) +import Clash.Driver.Types (ClashOpts(..), ClashEnv(..), ClashDesign(..)) +import Clash.GHC.Evaluator +import Clash.GHC.GenerateBindings +import Clash.GHC.NetlistTypes +import Clash.GHC.PartialEval +import Clash.GHCi.Common +import Clash.Util (clashLibVersion, reportTimeDiff) +import Data.Proxy +import qualified Data.Time.Clock as Clock +import qualified Paths_clash_ghc + +----------------------------------------------------------------------------- + +data GhciSettings = GhciSettings { + availableCommands :: [Command], + shortHelpText :: String, + fullHelpText :: String, + defPrompt :: PromptFunction, + defPromptCont :: PromptFunction + } + +defaultGhciSettings :: IORef ClashOpts -> GhciSettings +defaultGhciSettings opts = + GhciSettings { + availableCommands = ghciCommands opts, + shortHelpText = defShortHelpText, + defPrompt = default_prompt, + defPromptCont = default_prompt_cont, + fullHelpText = defFullHelpText + } + +ghciWelcomeMsg :: String +ghciWelcomeMsg = "Clashi, version " ++ Data.Version.showVersion Paths_clash_ghc.version ++ + " (using clash-lib, version " ++ Data.Version.showVersion clashLibVersion ++ + "):\nhttps://clash-lang.org/ :? for help" + +ghciCommands :: IORef ClashOpts -> [Command] +ghciCommands opts = map mkCmd [ + -- Hugs users are accustomed to :e, so make sure it doesn't overlap + ("?", keepGoing help, noCompletion), + ("add", keepGoingPaths addModule, completeFilename), + ("abandon", keepGoing abandonCmd, noCompletion), + ("break", keepGoing breakCmd, completeBreakpoint), + ("back", keepGoing backCmd, noCompletion), + ("browse", keepGoing' (browseCmd False), completeModule), + ("browse!", keepGoing' (browseCmd True), completeModule), + ("cd", keepGoingMulti' changeDirectory, completeFilename), + ("continue", keepGoing continueCmd, noCompletion), + ("cmd", keepGoing cmdCmd, completeExpression), + ("def", keepGoing (defineMacro False), completeExpression), + ("def!", keepGoing (defineMacro True), completeExpression), + ("delete", keepGoing deleteCmd, noCompletion), + ("disable", keepGoing disableCmd, noCompletion), + ("doc", keepGoing' docCmd, completeIdentifier), + ("edit", keepGoingMulti' editFile, completeFilename), + ("enable", keepGoing enableCmd, noCompletion), + ("force", keepGoing forceCmd, completeExpression), + ("forward", keepGoing forwardCmd, noCompletion), + ("help", keepGoingMulti help, noCompletion), + ("history", keepGoingMulti historyCmd, noCompletion), + ("info", keepGoingMulti' (info False), completeIdentifier), + ("info!", keepGoingMulti' (info True), completeIdentifier), + ("issafe", keepGoing' isSafeCmd, completeModule), + ("ignore", keepGoing ignoreCmd, noCompletion), + ("kind", keepGoingMulti' (kindOfType False), completeIdentifier), + ("kind!", keepGoingMulti' (kindOfType True), completeIdentifier), + ("load", keepGoingPaths loadModule_, completeHomeModuleOrFile), + ("load!", keepGoingPaths loadModuleDefer, completeHomeModuleOrFile), + ("list", keepGoing' listCmd, noCompletion), + ("module", keepGoing moduleCmd, completeSetModule), + ("main", keepGoing runMain, completeFilename), + ("print", keepGoing printCmd, completeExpression), + ("quit", quit, noCompletion), + ("reload", keepGoingMulti' reloadModule, noCompletion), + ("reload!", keepGoingMulti' reloadModuleDefer, noCompletion), + ("run", keepGoing runRun, completeFilename), + ("script", keepGoing' scriptCmd, completeFilename), + ("set", keepGoingMulti setCmd, completeSetOptions), + ("seti", keepGoingMulti setiCmd, completeSeti), + ("show", keepGoingMulti' showCmd, completeShowOptions), + ("showi", keepGoing showiCmd, completeShowiOptions), + ("sprint", keepGoing sprintCmd, completeExpression), + ("step", keepGoing stepCmd, completeIdentifier), + ("steplocal", keepGoing stepLocalCmd, completeIdentifier), + ("stepmodule",keepGoing stepModuleCmd, completeIdentifier), + ("type", keepGoingMulti' typeOfExpr, completeExpression), + ("trace", keepGoing traceCmd, completeExpression), + ("unadd", keepGoingPaths unAddModule, completeFilename), + ("undef", keepGoing undefineMacro, completeMacro), + ("unset", keepGoing unsetOptions, completeSetOptions), + ("where", keepGoing whereCmd, noCompletion), + ("vhdl", keepGoingPaths (makeVHDL opts), completeHomeModuleOrFile), + ("verilog", keepGoingPaths (makeVerilog opts), completeHomeModuleOrFile), + ("systemverilog",keepGoingPaths (makeSystemVerilog opts), completeHomeModuleOrFile), + ("instances", keepGoing' instancesCmd, completeExpression) + ] ++ map mkCmdHidden [ -- hidden commands + ("all-types", keepGoing' allTypesCmd), + ("complete", keepGoing completeCmd), + ("loc-at", keepGoing' locAtCmd), + ("type-at", keepGoing' typeAtCmd), + ("uses", keepGoing' usesCmd) + ] + where + mkCmd (n,a,c) = Command { cmdName = n + , cmdAction = a + , cmdHidden = False + , cmdCompletionFunc = c + } + + mkCmdHidden (n,a) = Command { cmdName = n + , cmdAction = a + , cmdHidden = True + , cmdCompletionFunc = noCompletion + } + +-- We initialize readline (in the interactiveUI function) to use +-- word_break_chars as the default set of completion word break characters. +-- This can be overridden for a particular command (for example, filename +-- expansion shouldn't consider '/' to be a word break) by setting the third +-- entry in the Command tuple above. +-- +-- NOTE: in order for us to override the default correctly, any custom entry +-- must be a SUBSET of word_break_chars. +word_break_chars :: String +word_break_chars = spaces ++ specials ++ symbols + +word_break_chars_pred :: Char -> Bool +word_break_chars_pred '.' = False +word_break_chars_pred c = c `elem` (spaces ++ specials) || isSymbolChar c + +symbols, specials, spaces :: String +symbols = "!#$%&*+/<=>?@\\^|-~" +specials = "(),;[]`{}" +spaces = " \t\n" + +flagWordBreakChars :: String +flagWordBreakChars = " \t\n" + + +showSDocForUser' :: GHC.GhcMonad m => SDoc -> m String +showSDocForUser' doc = do + dflags <- getDynFlags + unit_state <- hsc_units <$> GHC.getSession + name_ppr_ctx <- GHC.getNamePprCtx + pure $ showSDocForUser dflags unit_state name_ppr_ctx doc + +showSDocForUserQualify :: GHC.GhcMonad m => SDoc -> m String +showSDocForUserQualify doc = do + dflags <- getDynFlags + unit_state <- hsc_units <$> GHC.getSession + pure $ showSDocForUser dflags unit_state alwaysQualify doc + + +keepGoing :: (String -> GHCi ()) -> (String -> InputT GHCi CmdExecOutcome) +keepGoing a str = keepGoing' (lift . a) str + +keepGoingMulti :: (String -> GHCi ()) -> (String -> InputT GHCi CmdExecOutcome) +keepGoingMulti a str = keepGoingMulti' (lift . a) str + +keepGoing' :: GhciMonad m => (a -> m ()) -> a -> m CmdExecOutcome +keepGoing' a str = do + in_multi <- inMultiMode + if in_multi + then + liftIO $ hPutStrLn stderr "Command is not supported (yet) in multi-mode" + else + a str + return CmdSuccess + +-- For commands which are actually support in multi-mode, initially just :reload +keepGoingMulti' :: GhciMonad m => (String -> m ()) -> String -> m CmdExecOutcome +keepGoingMulti' a str = a str >> return CmdSuccess + +inMultiMode :: GhciMonad m => m Bool +inMultiMode = multiMode <$> getGHCiState + +keepGoingPaths :: ([FilePath] -> InputT GHCi ()) -> (String -> InputT GHCi CmdExecOutcome) +keepGoingPaths a str + = do case toArgsNoLoc str of + Left err -> liftIO $ hPutStrLn stderr err >> return CmdSuccess + Right args -> keepGoing' a args + +defShortHelpText :: String +defShortHelpText = "use :? for help.\n" + +defFullHelpText :: String +defFullHelpText = + " Commands available from the prompt:\n" ++ + "\n" ++ + " evaluate/run \n" ++ + " : repeat last command\n" ++ + " :{\\n ..lines.. \\n:}\\n multiline command\n" ++ + " :add [*] ... add module(s) to the current target set\n" ++ + " :browse[!] [[*]] display the names defined by module \n" ++ + " (!: more details; *: all top-level names)\n" ++ + " :cd change directory to \n" ++ + " :cmd run the commands returned by ::IO String\n" ++ + " :complete [] list completions for partial input string\n" ++ + " :def[!] define command : (later defined command has\n" ++ + " precedence, :: is always a builtin command)\n" ++ + " (!: redefine an existing command name)\n" ++ + " :doc display docs for the given name (experimental)\n" ++ + " :edit edit file\n" ++ + " :edit edit last module\n" ++ + " :help, :? display this list of commands\n" ++ + " :info[!] [ ...] display information about the given names\n" ++ + " (!: do not filter instances)\n" ++ + " :instances display the class instances available for \n" ++ + " :issafe [] display safe haskell information of module \n" ++ + " :kind[!] show the kind of \n" ++ + " (!: also print the normalised type)\n" ++ + " :load[!] [*] ... load module(s) and their dependents\n" ++ + " (!: defer type errors)\n" ++ + " :main [ ...] run the main function with the given arguments\n" ++ + " :module [+/-] [*] ... set the context for expression evaluation\n" ++ + " :quit exit GHCi\n" ++ + " :reload[!] reload the current module set\n" ++ + " (!: defer type errors)\n" ++ + " :run function [ ...] run the function with the given arguments\n" ++ + " :script run the script \n" ++ + " :type show the type of \n" ++ + " :type +d show the type of , defaulting type variables\n" ++ + " :unadd ... remove module(s) from the current target set\n" ++ + " :undef undefine user-defined command :\n" ++ + " :: run the builtin command\n" ++ + " :! run the shell command \n" ++ + " :vhdl synthesize currently loaded module to vhdl\n" ++ + " :vhdl [] synthesize specified modules/files to vhdl\n" ++ + " :verilog synthesize currently loaded module to verilog\n" ++ + " :verilog [] synthesize specified modules/files to verilog\n" ++ + " :systemverilog synthesize currently loaded module to systemverilog\n" ++ + " :systemverilog [] synthesize specified modules/files to systemverilog\n" ++ + "\n" ++ + " -- Commands for debugging:\n" ++ + "\n" ++ + " :abandon at a breakpoint, abandon current computation\n" ++ + " :back [] go back in the history N steps (after :trace)\n" ++ + " :break [] [] set a breakpoint at the specified location\n" ++ + " :break set a breakpoint on the specified function\n" ++ + " :continue [] resume after a breakpoint [and set break ignore count]\n" ++ + " :delete ... delete the specified breakpoints\n" ++ + " :delete * delete all breakpoints\n" ++ + " :disable ... disable the specified breakpoints\n" ++ + " :disable * disable all breakpoints\n" ++ + " :enable ... enable the specified breakpoints\n" ++ + " :enable * enable all breakpoints\n" ++ + " :force print , forcing unevaluated parts\n" ++ + " :forward [] go forward in the history N step s(after :back)\n" ++ + " :history [] after :trace, show the execution history\n" ++ + " :ignore for break set break ignore \n" ++ + " :list show the source code around current breakpoint\n" ++ + " :list show the source code for \n" ++ + " :list [] show the source code around line number \n" ++ + " :print [ ...] show a value without forcing its computation\n" ++ + " :sprint [ ...] simplified version of :print\n" ++ + " :step single-step after stopping at a breakpoint\n"++ + " :step single-step into \n"++ + " :steplocal single-step within the current top-level binding\n"++ + " :stepmodule single-step restricted to the current module\n"++ + " :trace trace after stopping at a breakpoint\n"++ + " :trace evaluate with tracing on (see :history)\n"++ + + "\n" ++ + " -- Commands for changing settings:\n" ++ + "\n" ++ + " :set