-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{-#LANGUAGE CPP #-} | ||
|
||
#if __GLASGOW_HASKELL__ >= 904 | ||
|
||
-- | 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.