Skip to content

Commit

Permalink
Try and outright solve substituted constraint
Browse files Browse the repository at this point in the history
Partially Fixes [#65](#65)
  • Loading branch information
rowanG077 committed Nov 11, 2022
1 parent e0af5b3 commit c2a6a6c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 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-natnormalise`](http://hackage.haskell.org/package/ghc-typelits-natnormalise) package

## Unreleased
* Try and outright solve substituted constraints, the same as is done with the unsubstituted constraint. Partially Fixes [#65](https://github.com/clash-lang/ghc-typelits-natnormalise/issues/65).

## 0.7.7 *October 10th 2022*
* Solve unflattened wanteds instead of the wanteds passed to the plugin. Fixes [#1901]https://github.com/clash-lang/clash-compiler/issues/1901.
* Add support for GHC 9.4
Expand Down
1 change: 1 addition & 0 deletions src-ghc-9.4/GHC/TypeLits/Normalise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ simplifyNats opts@Opts {..} leqT eqsG eqsW = do
-- `1 <= x^y`
-- OR
(instantSolveIneq depth u:
instantSolveIneq depth uS:
-- This inequality is either a given constraint, or it is a wanted
-- constraint, which in normal form is equal to another given
-- constraint, hence it can be solved.
Expand Down
1 change: 1 addition & 0 deletions src-pre-ghc-9.4/GHC/TypeLits/Normalise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ simplifyNats opts@Opts {..} ordCond eqsG eqsW = do
-- `1 <= x^y`
-- OR
(instantSolveIneq depth u:
instantSolveIneq depth uS:
-- This inequality is either a given constraint, or it is a wanted
-- constraint, which in normal form is equal to another given
-- constraint, hence it can be solved.
Expand Down
9 changes: 9 additions & 0 deletions tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ tyFamMonotonicityFun _ = ()
tyFamMonotonicity :: (2 <= F2 dom) => Proxy (dom :: Symbol) -> ()
tyFamMonotonicity dom = tyFamMonotonicityFun dom

oneLtPowSubst :: forall a b. (b ~ (2^a)) => Proxy a -> Proxy a
oneLtPowSubst = go
where
go :: 1 <= b => Proxy a -> Proxy a
go = id

main :: IO ()
main = defaultMain tests

Expand Down Expand Up @@ -598,6 +604,9 @@ tests = testGroup "ghc-typelits-natnormalise"
, testCase "2 <= P (G2 dom) implies 1 <= P (G2 dom)" $
show (tyFamMonotonicity (Proxy :: Proxy Dom)) @?=
"()"
, testCase "b ~ (2^a) => 1 <= b" $
show (oneLtPowSubst (Proxy :: Proxy 0)) @?=
"Proxy"
]
, testGroup "errors"
[ testCase "x + 2 ~ 3 + x" $ testProxy1 `throws` testProxy1Errors
Expand Down

0 comments on commit c2a6a6c

Please sign in to comment.