GHC.Check

ghc-check-0.5.0.8: detect mismatches between compile-time and run-time versions of the ghc api

Safe Haskell | None
Language | Haskell2010

GHC.Check

Contents

- GHC version check
  - Interpreting the results
  - Exports for TH

Synopsis

- makeGhcVersionChecker :: IO FilePath -> SpliceQ GhcVersionChecker
- type GhcVersionChecker = String -> IO InstallationCheck
- data InstallationCheck
  - = InstallationChecked {
    - compileTime :: !Version
    - packageCheck :: Ghc PackageCheckResult
    }
  - | InstallationMismatch {
    - libdir :: !String
    - compileTime :: !Version
    - runTime :: !Version
    }
  - | InstallationNotFound {
    - libdir :: !String
    }
- data PackageCheckResult
  - = PackageCheckSuccess !(NonEmpty (String, PackageCheck))
  - | PackageCheckFailure !(NonEmpty (String, PackageCheck))
  - | PackageCheckInconclusive ![String]
  - | PackageCheckError !SomeException
- data PackageCheck
  - = VersionMismatch {
    - compileTime :: !Version
    - runTime :: !Version
    }
  - | AbiMismatch {
    - compileTimeAbi :: !String
    - runTimeAbi :: !String
    - compileTime :: !Version
    }
  - | VersionMatch {
    - packageVersion :: !PackageVersion
    }
- guessCompatibility :: PackageCheckResult -> CompatibilityGuess
- data CompatibilityGuess
  - = ProbablyCompatible {
    - warning :: Maybe String
    }
  - | NotCompatible {
    - reason :: !NotCompatibleReason
    }
- data NotCompatibleReason
  - = PackageVersionMismatch {
    - compileTime :: !Version
    - runTime :: !Version
    - packageName :: !String
    }
  - | BasePackageAbiMismatch {
    - compileTimeAbi :: !String
    - runTimeAbi :: !String
    - compileTime :: !Version
    }
- checkGhcVersion :: HasCallStack => [(String, PackageVersion)] -> GhcVersionChecker

# GHC version check

makeGhcVersionChecker :: IO FilePath -> SpliceQ GhcVersionChecker #

`makeGhcVersionChecker libdir` returns a function to check the run-time version of GHC against the compile-time version. It performs two checks:

1. It checks the version of the GHC installation given the run-time libdir In some platforms, like Nix, the libdir is not fixed at compile-time
2. It compares the version of the `ghc` package, if found at run-time. If not, it compares the abi of the `base` package.

    ghcChecker :: IO(Ghc (String -> PackageCheck))
    ghcChecker = $$(makeGhcVersionChecker (pure $ Just GHC.Paths.libdir))

    checkGhcVersion :: IO ()
    checkGhcVersion = do
        InstallationChecked packageCheck <- ghcChecker runTimeLibdir
        res <- runGhc (Just runTimeLibdir) $ do
                 setupGhcApi
                 result <- packageCheck
                 case guessCompatibility result of ...

type GhcVersionChecker = String -> IO InstallationCheck #

Given a run-time libdir, checks the ghc installation and returns a `Ghc` action to check the package database

data InstallationCheck #

Constructors

InstallationChecked | The GHC installation looks fine. Further checks are needed for the package libraries.
Fields compileTime :: !Version The compile time version of GHC packageCheck :: Ghc PackageCheckResult The second stage of the GHC version check
InstallationMismatch | The libdir points to a different GHC version
Fields libdir :: !String compileTime :: !Version The compile time version of GHC runTime :: !Version
InstallationNotFound | The libdir does not exist
Fields libdir :: !String

data PackageCheckResult #

Constructors

PackageCheckSuccess !(NonEmpty (String, PackageCheck)) | All the compile time packages tested match
PackageCheckFailure !(NonEmpty (String, PackageCheck)) | Found package mismatches
PackageCheckInconclusive ![String] | None of the compile time packages could be found
PackageCheckError !SomeException | An exception arised during the package check

data PackageCheck #

Constructors

VersionMismatch | Different versions
Fields compileTime :: !Version runTime :: !Version
AbiMismatch | Same version but different abi
Fields compileTimeAbi :: !String runTimeAbi :: !String compileTime :: !Version
VersionMatch | Same version and abi
Fields packageVersion :: !PackageVersion

#### Instances

Instances details

Show PackageCheck # |
Instance details Defined in GHC.Check Methods showsPrec :: Int -> PackageCheck -> ShowS # show :: PackageCheck -> String # showList :: [PackageCheck] -> ShowS #
Eq PackageCheck # |
Instance details Defined in GHC.Check Methods (==) :: PackageCheck -> PackageCheck -> Bool # (/=) :: PackageCheck -> PackageCheck -> Bool #

## Interpreting the results

guessCompatibility :: PackageCheckResult -> CompatibilityGuess #

Interpret a `PackageCheckResult` into a yes/no GHC compatibility answer

data CompatibilityGuess #

The result of interpreting a `PackageCheckResult`

Constructors

ProbablyCompatible |
Fields warning :: Maybe String
NotCompatible |
Fields reason :: !NotCompatibleReason

#### Instances

Instances details

Show CompatibilityGuess # |
Instance details Defined in GHC.Check Methods showsPrec :: Int -> CompatibilityGuess -> ShowS # show :: CompatibilityGuess -> String # showList :: [CompatibilityGuess] -> ShowS #
Eq CompatibilityGuess # |
Instance details Defined in GHC.Check Methods (==) :: CompatibilityGuess -> CompatibilityGuess -> Bool # (/=) :: CompatibilityGuess -> CompatibilityGuess -> Bool #

data NotCompatibleReason #

Constructors

PackageVersionMismatch |
Fields compileTime :: !Version runTime :: !Version packageName :: !String
BasePackageAbiMismatch |
Fields compileTimeAbi :: !String runTimeAbi :: !String compileTime :: !Version

#### Instances

Instances details

Show NotCompatibleReason # |
Instance details Defined in GHC.Check Methods showsPrec :: Int -> NotCompatibleReason -> ShowS # show :: NotCompatibleReason -> String # showList :: [NotCompatibleReason] -> ShowS #
Eq NotCompatibleReason # |
Instance details Defined in GHC.Check Methods (==) :: NotCompatibleReason -> NotCompatibleReason -> Bool # (/=) :: NotCompatibleReason -> NotCompatibleReason -> Bool #

## Exports for TH

checkGhcVersion :: HasCallStack => [(String, PackageVersion)] -> GhcVersionChecker #

Checks if the run-time version of the `ghc` package matches the given version.

If the package database contains an unstable ghc library version, we omit the package version check. This leads to a more convenient usage for working on GHC. When developing for or on GHC, you can compile GHC HEAD with a bootstrap compiler and use the freshly compiled ghc library to load programs that use the latest GHC API. We consider the ghc version to be unstable according to the GHC User Guide