Skip to content

Commit

Permalink
Merge pull request #22 from clash-lang/941-support
Browse files Browse the repository at this point in the history
Add support for GHC 9.4.1
  • Loading branch information
christiaanb authored Sep 2, 2022
2 parents 631facf + f4aea17 commit e489f7d
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 53 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.14.1
# version: 0.15.20220826
#
# REGENDATA ("0.14.1",["github","ghc-tcplugins-extra.cabal"])
# REGENDATA ("0.15.20220826",["github","ghc-tcplugins-extra.cabal"])
#
name: Haskell-CI
on:
Expand All @@ -19,7 +19,7 @@ on:
jobs:
linux:
name: Haskell-CI - Linux - ${{ matrix.compiler }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes:
60
container:
Expand All @@ -28,20 +28,25 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.2.1
- compiler: ghc-9.4.2
compilerKind: ghc
compilerVersion: 9.2.1
compilerVersion: 9.4.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.2.4
compilerKind: ghc
compilerVersion: 9.2.4
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.0.2
compilerKind: ghc
compilerVersion: 9.0.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-8.10.4
- compiler: ghc-8.10.7
compilerKind: ghc
compilerVersion: 8.10.4
setup-method: hvr-ppa
compilerVersion: 8.10.7
setup-method: ghcup
allow-failure: false
- compiler: ghc-8.8.4
compilerKind: ghc
Expand Down Expand Up @@ -81,18 +86,19 @@ jobs:
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
if [ "${{ matrix.setup-method }}" = ghcup ]; then
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER"
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml;
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
else
apt-add-repository -y 'ppa:hvr/ghc'
apt-get update
apt-get install -y "$HCNAME"
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
fi
env:
HCKIND: ${{ matrix.compilerKind }}
Expand Down Expand Up @@ -123,7 +129,7 @@ jobs:
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
if [ $((HCNUMVER > 90201)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
if [ $((HCNUMVER > 90402)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
env:
Expand Down Expand Up @@ -161,6 +167,7 @@ jobs:
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
key-threshold: 3
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override
EOF
fi
cat >> $CABAL_CONFIG <<EOF
Expand Down Expand Up @@ -246,7 +253,7 @@ jobs:
${CABAL} -vnormal check
- name: haddock
run: |
$CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
$CABAL v2-haddock --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
- name: unconstrained build
run: |
rm -f cabal.project.local
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.4.3 *September 2nd 2022*
* Support for GHC-9.4.2

## 0.4.2 *June 17th 2021*
* Support for GHC-9.2.0.20210422

Expand Down
2 changes: 1 addition & 1 deletion defaults.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
, license = "BSD2"
, license-file = "LICENSE"
, tested-with =
"GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.2, GHC == 9.2.1"
"GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.2, GHC == 9.2.1, GHC == 9.4.1"
, extra-source-files =
[ "README.md", "CHANGELOG.md", "defaults.dhall", "package.dhall" ]
, ghc-options = [ "-Wall" ]
Expand Down
22 changes: 18 additions & 4 deletions ghc-tcplugins-extra.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.0

-- This file has been generated from package.dhall by hpack version 0.34.6.
-- This file has been generated from package.dhall by hpack version 0.35.0.
--
-- see: https://github.com/sol/hpack

Expand All @@ -21,7 +21,8 @@ license: BSD2
license-file: LICENSE
build-type: Simple
tested-with:
GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.2, GHC == 9.2.1
GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5,
GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.4, GHC == 9.4.2
extra-source-files:
README.md
CHANGELOG.md
Expand All @@ -47,13 +48,27 @@ library
ghc-options: -Wall
build-depends:
base >=4.8 && <5
, ghc >=7.10 && <9.4
, ghc >=7.10 && <9.6
default-language: Haskell2010
if impl(ghc >= 8.0.0)
ghc-options: -Wcompat -Wincomplete-uni-patterns -Widentities -Wredundant-constraints
if impl(ghc >= 8.4.0)
ghc-options: -fhide-source-paths
if flag(deverror)
ghc-options: -Werror
if impl(ghc >= 9.4) && impl(ghc < 9.6)
other-modules:
GhcApi.Constraint
GhcApi.Predicate
GhcApi.GhcPlugins
Internal.Type
Internal.Constraint
Internal.Evidence
hs-source-dirs:
src-ghc-tree-9.4
src-ghc-9.4
build-depends:
ghc >=9.4 && <9.6
if impl(ghc >= 9.2) && impl(ghc < 9.4)
other-modules:
GhcApi.Constraint
Expand Down Expand Up @@ -183,4 +198,3 @@ library
src-ghc-cpp
build-depends:
ghc >=7.10 && <8.0
default-language: Haskell2010
53 changes: 27 additions & 26 deletions package.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ let version = ./version.dhall
in let ghc = { name = "ghc", mixin = [] : List Text }

in let gin =
ghc
{ mixin =
[ "hiding ()"
, "(TcRnTypes as Constraint)"
, "(Type as Predicate)"
]
}
ghc
// { mixin =
[ "hiding ()"
, "(TcRnTypes as Constraint)"
, "(Type as Predicate)"
]
}

in let mods =
[ "GhcApi.Constraint"
Expand All @@ -22,23 +22,24 @@ in let ghc = { name = "ghc", mixin = [] : List Text }
, "Internal.Evidence"
]

in defs
{ library =
{ source-dirs = "src"
, dependencies =
[ "base >=4.8 && <5", "ghc >=7.10 && <9.4" ]
, exposed-modules = "GHC.TcPluginM.Extra"
, other-modules = "Internal"
, when =
[ version "9.2" "9.4" [ "tree", "9.2" ] ghc mods
, version "9.0" "9.2" [ "tree", "9.0" ] ghc mods
, version "8.10" "9.0" [ "flat", "8.10" ] ghc mods
, version "8.8" "8.10" [ "flat", "8.8" ] gin mods
, version "8.6" "8.8" [ "flat", "8.6" ] gin mods
, version "8.4" "8.6" [ "flat", "8.4" ] gin mods
, version "8.2" "8.4" [ "flat", "8.2" ] gin mods
, version "8.0" "8.2" [ "flat", "8.0" ] gin mods
, version "7.10" "8.0" [ "cpp" ] ghc ([] : List Text)
]
in defs
// { library =
{ source-dirs = "src"
, dependencies =
[ "base >=4.8 && <5", "ghc >=7.10 && <9.6" ]
, exposed-modules = "GHC.TcPluginM.Extra"
, other-modules = "Internal"
, when =
[ version "9.4" "9.6" [ "tree-9.4", "9.4" ] ghc mods
, version "9.2" "9.4" [ "tree", "9.2" ] ghc mods
, version "9.0" "9.2" [ "tree", "9.0" ] ghc mods
, version "8.10" "9.0" [ "flat", "8.10" ] ghc mods
, version "8.8" "8.10" [ "flat", "8.8" ] gin mods
, version "8.6" "8.8" [ "flat", "8.6" ] gin mods
, version "8.4" "8.6" [ "flat", "8.4" ] gin mods
, version "8.2" "8.4" [ "flat", "8.2" ] gin mods
, version "8.0" "8.2" [ "flat", "8.0" ] gin mods
, version "7.10" "8.0" [ "cpp" ] ghc ([] : List Text)
]
}
}
}
13 changes: 13 additions & 0 deletions src-ghc-9.4/GhcApi/Constraint.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module GhcApi.Constraint
( Ct(..)
, CtEvidence(..)
, CtLoc
, CanEqLHS(..)
, ctLoc
, ctEvId
, mkNonCanonical
)
where

import GHC.Tc.Types.Constraint
(Ct (..), CtEvidence (..), CanEqLHS (..), CtLoc, ctLoc, ctEvId, mkNonCanonical)
5 changes: 5 additions & 0 deletions src-ghc-9.4/GhcApi/GhcPlugins.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module GhcApi.GhcPlugins (module GHC.Plugins, FindResult(..), findPluginModule) where

import GHC.Plugins hiding (TcPlugin, mkSubst)
import GHC.Unit.Finder (findPluginModule)
import GHC.Tc.Plugin (FindResult(..))
49 changes: 49 additions & 0 deletions src-ghc-9.4/Internal/Constraint.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{-# LANGUAGE RecordWildCards #-}

module Internal.Constraint (newGiven, flatToCt, mkSubst, overEvidencePredType) where

import GhcApi.GhcPlugins
import GhcApi.Constraint
(Ct(..), CtEvidence(..), CanEqLHS(..), CtLoc, ctLoc, ctEvId, mkNonCanonical)

import GHC.Tc.Utils.TcType (TcType)
import GHC.Tc.Types.Constraint (QCInst(..))
import GHC.Tc.Types.Evidence (EvTerm(..), EvBindsVar)
import GHC.Tc.Plugin (TcPluginM)
import qualified GHC.Tc.Plugin as TcPlugin (newGiven)

-- | Create a new [G]iven constraint, with the supplied evidence. This must not
-- be invoked from 'tcPluginInit' or 'tcPluginStop', or it will panic.
newGiven :: EvBindsVar -> CtLoc -> PredType -> EvTerm -> TcPluginM CtEvidence
newGiven tcEvbinds loc pty (EvExpr ev) = TcPlugin.newGiven tcEvbinds loc pty ev
newGiven _ _ _ ev = panicDoc "newGiven: not an EvExpr: " (ppr ev)

flatToCt :: [((TcTyVar,TcType),Ct)] -> Maybe Ct
flatToCt [((_,lhs),ct),((_,rhs),_)]
= Just
$ mkNonCanonical
$ CtGiven (mkPrimEqPred lhs rhs)
(ctEvId ct)
(ctLoc ct)

flatToCt _ = Nothing

-- | Create simple substitution from type equalities
mkSubst :: Ct -> Maybe ((TcTyVar, TcType),Ct)
mkSubst ct@(CEqCan {..})
| TyVarLHS tyvar <- cc_lhs
= Just ((tyvar,cc_rhs),ct)
mkSubst _ = Nothing

-- | Modify the predicate type of the evidence term of a constraint
overEvidencePredType :: (TcType -> TcType) -> Ct -> Ct
overEvidencePredType f (CQuantCan qci) =
let
ev :: CtEvidence
ev = qci_ev qci
in CQuantCan ( qci { qci_ev = ev { ctev_pred = f (ctev_pred ev) } } )
overEvidencePredType f ct =
let
ev :: CtEvidence
ev = cc_ev ct
in ct { cc_ev = ev { ctev_pred = f (ctev_pred ev) } }
14 changes: 14 additions & 0 deletions src-ghc-9.4/Internal/Evidence.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Internal.Evidence (evByFiat) where

import GHC.Tc.Types.Evidence (EvTerm(..))
import GHC.Core.TyCo.Rep (UnivCoProvenance (..))

import GhcApi.GhcPlugins

-- | The 'EvTerm' equivalent for 'Unsafe.unsafeCoerce'
evByFiat :: String -- ^ Name the coercion should have
-> Type -- ^ The LHS of the equivalence relation (~)
-> Type -- ^ The RHS of the equivalence relation (~)
-> EvTerm
evByFiat name t1 t2 =
EvExpr $ Coercion $ mkUnivCo (PluginProv name) Nominal t1 t2
30 changes: 30 additions & 0 deletions src-ghc-9.4/Internal/Type.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Internal.Type (substType) where

import Data.Maybe (fromMaybe)
import GHC.Tc.Utils.TcType (TcType)
import GHC.Core.TyCo.Rep (Type (..))
import GHC.Types.Var (TcTyVar)

-- | Apply substitutions in Types
--
-- __NB:__ Doesn't substitute under binders
substType
:: [(TcTyVar, TcType)]
-> TcType
-> TcType
substType subst tv@(TyVarTy v) =
fromMaybe tv (lookup v subst)
substType subst (AppTy t1 t2) =
AppTy (substType subst t1) (substType subst t2)
substType subst (TyConApp tc xs) =
TyConApp tc (map (substType subst) xs)
substType _subst t@(ForAllTy _tv _ty) =
-- TODO: Is it safe to do "dumb" substitution under binders?
-- ForAllTy tv (substType subst ty)
t
substType subst (FunTy k1 k2 t1 t2) =
FunTy k1 k2 (substType subst t1) (substType subst t2)
substType _ l@(LitTy _) = l
substType subst (CastTy ty co) =
CastTy (substType subst ty) co
substType _ co@(CoercionTy _) = co
3 changes: 3 additions & 0 deletions src-ghc-tree-9.4/GhcApi/Predicate.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module GhcApi.Predicate (mkPrimEqPred) where

import GHC.Core.Coercion (mkPrimEqPred)
Loading

0 comments on commit e489f7d

Please sign in to comment.