Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GHC 9.4 #56

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ common:ghc_9_0_2 --repo_env=GHC_VERSION=9.0.2

common:ghc_9_2_5 --repo_env=GHC_VERSION=9.2.5

common:ghc_9_4_5 --repo_env=GHC_VERSION=9.4.5

# Try to load a file that includes the remote cache authentication flag
try-import %workspace%/.bazelrc.auth

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ["ghc_8_10_7", "ghc_9_0_2", "ghc_9_2_5"]
ghc-version: ["ghc_8_10_7", "ghc_9_0_2", "ghc_9_2_5", "ghc_9_4_5"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
66 changes: 66 additions & 0 deletions himportscan/src/HImportScan/GHC/FakeSettings9_4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- Copyright (c) 2020, Shayne Fletcher. All rights reserved.
-- SPDX-License-Identifier: BSD-3-Clause.
{-#LANGUAGE CPP #-}

#if __GLASGOW_HASKELL__ >= 904

{-# OPTIONS_GHC -Wno-missing-fields #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}

-- This file is a single code path copied over from https://hackage.haskell.org/package/ghc-lib-parser-ex-8.10.0.24/docs/src/Language.Haskell.GhclibParserEx.GHC.Settings.Config.html
-- TODO[GL]: We can get rid of this file once we only support >=9.2, as ParserOpts are much smaller there.
module HImportScan.GHC.FakeSettings9_4(
fakeSettings
, fakeLlvmConfig
)
where

import GHC.Settings.Config
import GHC.Driver.Session
import GHC.Utils.Fingerprint
import GHC.Platform
import GHC.Settings

fakeSettings :: Settings
fakeSettings = Settings
{ sGhcNameVersion=ghcNameVersion
, sFileSettings=fileSettings
, sTargetPlatform=platform
, sPlatformMisc=platformMisc
, sToolSettings=toolSettings
, sRawSettings=[]
}
where
toolSettings = ToolSettings {
toolSettings_opt_P_fingerprint=fingerprint0
}
fileSettings = FileSettings {}
platformMisc = PlatformMisc {}
ghcNameVersion =
GhcNameVersion{ghcNameVersion_programName="ghc"
,ghcNameVersion_projectVersion=cProjectVersion
}
platform =
Platform{
platformWordSize=PW8
, platformArchOS=ArchOS {archOS_arch=ArchUnknown, archOS_OS=OSUnknown}
, platformByteOrder = LittleEndian
, platformUnregisterised=True
, platformHasGnuNonexecStack = False
, platformHasIdentDirective = False
, platformHasSubsectionsViaSymbols = False
, platformIsCrossCompiling = False
, platformLeadingUnderscore = False
, platformTablesNextToCode = False
, platform_constants = Nothing
, platformHasLibm = True
}

fakeLlvmConfig :: LlvmConfig
fakeLlvmConfig = LlvmConfig [] []

#else

module HImportScan.GHC.FakeSettings9_4 where

#endif
102 changes: 102 additions & 0 deletions himportscan/src/HImportScan/GHC9_4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{-#LANGUAGE CPP #-}

#if __GLASGOW_HASKELL__ >= 904
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this uses >= now and it might also work with later GHC versions, in case the API did not change.


-- | A module abstracting the provenance of GHC API names
module HImportScan.GHC9_4 (module X, imports, handleParseError, getOptions) where

import HImportScan.GHC.FakeSettings9_4 as X

import GHC.Driver.Session as X (DynFlags, defaultDynFlags, xopt_set, xopt_unset)
import GHC.Data.EnumSet as X (empty, fromList)
import GHC.Driver.Errors as X (printMessages)
import GHC.Data.FastString as X (FastString, mkFastString, unpackFS)
import GHC as X (runGhc, getSessionDynFlags)
import GHC.LanguageExtensions as X
(Extension
( ImportQualifiedPost
, PackageImports
, TemplateHaskell
, ImplicitPrelude
, PatternSynonyms
, ExplicitNamespaces
, MagicHash
)
)
import GHC.Parser.Header as X (getImports)
import GHC.Types.SourceError (mkSrcErr)
import GHC.Parser.Lexer as X
( ParseResult(..)
, ParserOpts
, Token(..)
, lexer
, loc
, unP
)
import GHC.Unit.Module as X (ModuleName, moduleNameString)
import GHC.Types.SrcLoc as X
( Located
, RealSrcLoc
, SrcLoc(RealSrcLoc)
, getLoc
, mkRealSrcLoc
, srcLocLine
, srcLocCol
, srcSpanStart
, unLoc
)
import GHC.Data.StringBuffer as X (StringBuffer(StringBuffer), stringToStringBuffer)
import GHC.Driver.Config.Parser
import GHC.Utils.Logger as X
import Control.Exception (throwIO)
import GHC.Parser.Errors.Types (PsMessage)
import GHC.Driver.Errors.Types (GhcMessage(GhcPsMessage))
import GHC.Driver.Config.Diagnostic (initDiagOpts)
import GHC.Types.Error (Messages)
import GHC.Types.PkgQual (RawPkgQual (RawPkgQual, NoRawPkgQual))
import qualified GHC.Types.SourceText as StringLiteral (sl_fs)
import qualified GHC.Parser.Header as PH (getOptions)

initOpts :: DynFlags -> ParserOpts
initOpts = initParserOpts

getOptions :: DynFlags -> StringBuffer -> FilePath -> [Located String]
getOptions dynFlags sb filePath =
snd $ PH.getOptions (initOpts dynFlags) sb filePath

imports ::
DynFlags ->
StringBuffer ->
FilePath ->
IO
( Either
-- (Bag PsError)
(Messages PsMessage)
( [(Maybe FastString, Located ModuleName)],
[(Maybe FastString, Located ModuleName)], Located ModuleName
)
)
imports dynFlagsWithExtensions sb filePath = do
-- [GG] We should never care about the Prelude import,
-- since it is always a module from an external library.
-- Hence the `False`.
imports' <- getImports (initOpts dynFlagsWithExtensions) False sb filePath filePath

return $ (\ (m1, m2, _, mname) -> (toFastMessage <$> m1, toFastMessage <$> m2, mname)) `fmap` imports'
where
toFastMessage (NoRawPkgQual, b) = (Nothing, b)
toFastMessage (RawPkgQual stringLit, b) = (Just $ StringLiteral.sl_fs stringLit, b)

handleParseError :: DynFlags -> Messages PsMessage -> IO a
handleParseError dynFlagsWithExtensions err = do
logger <- initLogger
let diagOpts = initDiagOpts dynFlagsWithExtensions
ghcErrors = GhcPsMessage <$> err
printMessages logger diagOpts err
throwIO (mkSrcErr ghcErrors)

#else

module HImportScan.GHC9_4 where

#endif
4 changes: 3 additions & 1 deletion himportscan/src/HImportScan/ImportScanner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import Data.Set (Set)
import qualified Data.Set as Set
import System.Directory (doesFileExist)

#if __GLASGOW_HASKELL__ >= 902
#if __GLASGOW_HASKELL__ >= 904
import HImportScan.GHC9_4 as GHC
#elif __GLASGOW_HASKELL__ >= 902
import HImportScan.GHC9_2 as GHC
#elif __GLASGOW_HASKELL__ == 900
import HImportScan.GHC9_0 as GHC
Expand Down
Loading