Skip to content

Commit

Permalink
Parse Assert-based constraints in GHC 9.4+ (#51)
Browse files Browse the repository at this point in the history
So we can create new wanted constraints from them. Before, we
would only recognise `~`-based constraints. We need to parse
`Assert`-based constraints because it is used to implement `<=`.

Also, we no longer silently fails when it's unexpected constraint.
  • Loading branch information
christiaanb authored Apr 3, 2024
1 parent d5578a1 commit 1eed8d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog for the [`ghc-typelits-extra`](http://hackage.haskell.org/package/ghc-typelits-extra) package

# 0.4.7
* Fix Plugin silently fails when normalizing <= in GHC 9.4+ [#50](https://github.com/clash-lang/ghc-typelits-extra/issues/50)

# 0.4.6 *October 10th 2023*
* Support for GHC-9.8.1

Expand Down
2 changes: 1 addition & 1 deletion ghc-typelits-extra.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ghc-typelits-extra
version: 0.4.6
version: 0.4.7
synopsis: Additional type-level operations on GHC.TypeLits.Nat
description:
Additional type-level operations on @GHC.TypeLits.Nat@:
Expand Down
5 changes: 3 additions & 2 deletions src-ghc-9.4/GHC/TypeLits/Extra/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import GHC.TcPluginM.Extra
(evByFiat, lookupModule, lookupName, tracePlugin, newWanted)

-- GHC API
import GHC.Builtin.Names (eqPrimTyConKey, hasKey)
import GHC.Builtin.Names (eqPrimTyConKey, hasKey, getUnique)
import GHC.Builtin.Types (promotedTrueDataCon, promotedFalseDataCon)
import GHC.Builtin.Types (boolTy, naturalTy, cTupleDataCon, cTupleTyCon)
import GHC.Builtin.Types.Literals (typeNatTyCons)
Expand Down Expand Up @@ -289,7 +289,8 @@ createWantedFromNormalised defs sct = do
let (ct, t1, t2) = extractCtSides sct
newPredTy <- case splitTyConApp_maybe $ ctEvPred $ ctEvidence ct of
Just (tc, [a, b, _, _]) | tc `hasKey` eqPrimTyConKey -> pure (mkTyConApp tc [a, b, t1, t2])
_ -> fail "Nothing"
Just (tc, [_, b]) | tc `hasKey` getUnique (assertTC defs) -> pure (mkTyConApp tc [t1,b])
_ -> error "Impossible: neither (<=?) nor Assert"
ev <- newWanted (ctLoc ct) newPredTy
let ctN = case ct of
CQuantCan qc -> CQuantCan (qc { qci_ev = ev})
Expand Down
11 changes: 11 additions & 0 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ test57
-> Proxy True
test57 _ _ = id

test58a
:: 1 <= n
=> Proxy n
-> Proxy n
test58a = id

test58b
:: Proxy (Max (n+2) 1)
-> Proxy (Max (n+2) 1)
test58b = test58a

main :: IO ()
main = defaultMain tests

Expand Down

0 comments on commit 1eed8d3

Please sign in to comment.