Open mniip opened 1 year ago
So here's what's going on.
a - b
, we must emit a b <= a
constraint when we solve a constraint.m ~ (n - 1)
, and them as substitution ([m := n - 1]
when we follow the example), as we continue solving: https://github.com/clash-lang/ghc-typelits-natnormalise/blob/3289e1a25df3d7752d6734aa83ba04782d6e43cd/src-ghc-9.4/GHC/TypeLits/Normalise.hs#L491-L500b <= a
constraints we collected in step 1. https://github.com/clash-lang/ghc-typelits-natnormalise/blob/3289e1a25df3d7752d6734aa83ba04782d6e43cd/src-ghc-9.4/GHC/TypeLits/Normalise.hs#L484-L485 It's the subToPred opts leqT k
part.b <= a
constraints from step 2 to step 4. We only emit the b <= a
constraints belonging to the constraint from before substitution we do in step 3.So the solution is that whenever we create the substitution in step 2, we remember if we need to tag any b <= a
constraints with them. And then in step 3, whenever a substitution carrying one of these constraints with them succeeds, we need to also emit those b <= a
constraints in step 4.
Note that the additional (redundant!)
m
type variable is necessary, without it the constraint is correctly rejected.