Skip to content

Commit 3bc9f4d

Browse files
committed
Hack attempt #2
1 parent 689bb50 commit 3bc9f4d

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src-ghc-9.4/GHC/TypeLits/Normalise.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ simplifyNats opts@Opts {..} leqT eqsG eqsW = do
507507
x' = substsSOP subst x
508508
y' = substsSOP subst y
509509
uS = (x',y',b)
510-
leqsG' | isGiven (ctEvidence ct) = (x',y',b):leqsG
511-
| otherwise = leqsG
510+
isG = isGiven (ctEvidence ct)
511+
leqsG' | isG = (x',y',b):leqsG
512+
| otherwise = leqsG
512513
ineqs = concat [ leqsG
513514
, map (substLeq subst) leqsG
514515
, map snd (rights (map fst eqsG))
@@ -519,7 +520,7 @@ simplifyNats opts@Opts {..} leqT eqsG eqsW = do
519520
evs' <- maybe evs (:evs) <$> evMagic ct knW (subToPred opts leqT k)
520521
simples subst evs' leqsG' xs eqs'
521522

522-
Just (False,_) | null k -> return (Impossible (fst eq))
523+
Just (False,_) | null k && not isG -> return (Impossible (fst eq))
523524
_ -> do
524525
let solvedIneq = mapMaybe runWriterT
525526
-- it is an inequality that can be instantly solved, such as

src-pre-ghc-9.4/GHC/TypeLits/Normalise.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,9 @@ simplifyNats opts@Opts {..} ordCond eqsG eqsW = do
640640
x' = substsSOP subst x
641641
y' = substsSOP subst y
642642
uS = (x',y',b)
643-
leqsG' | isGiven (ctEvidence ct) = (x',y',b):leqsG
644-
| otherwise = leqsG
643+
isG = isGiven (ctEvidence ct)
644+
leqsG' | isG = (x',y',b):leqsG
645+
| otherwise = leqsG
645646
ineqs = concat [ leqsG
646647
, map (substLeq subst) leqsG
647648
, map snd (rights (map fst eqsG))
@@ -652,7 +653,7 @@ simplifyNats opts@Opts {..} ordCond eqsG eqsW = do
652653
evs' <- maybe evs (:evs) <$> evMagic ct knW (subToPred opts ordCond k)
653654
simples subst evs' leqsG' xs eqs'
654655

655-
Just (False,_) | null k -> return (Impossible (fst eq))
656+
Just (False,_) | null k && not isG -> return (Impossible (fst eq))
656657
_ -> do
657658
let solvedIneq = mapMaybe runWriterT
658659
-- it is an inequality that can be instantly solved, such as

src/GHC/TypeLits/Normalise/Unify.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ unifiers' ct (S ((P [I i]):ps1)) (S ((P [I j]):ps2))
568568
unifiers' ct s1@(S ps1) s2@(S ps2) = case sopToIneq k1 of
569569
Just (s1',s2',_)
570570
| s1' /= s1 || s2' /= s1
571-
, maybe False (uncurry (&&) . second Set.null) (runWriterT (isNatural s1'))
572-
, maybe False (uncurry (&&) . second Set.null) (runWriterT (isNatural s2'))
571+
, maybe True (uncurry (&&) . second Set.null) (runWriterT (isNatural s1'))
572+
, maybe True (uncurry (&&) . second Set.null) (runWriterT (isNatural s2'))
573573
-> unifiers' ct s1' s2'
574574
_ | null psx
575575
, length ps1 == length ps2
@@ -655,7 +655,7 @@ isNatural (S []) = return True
655655
isNatural (S [P []]) = return True
656656
isNatural (S [P (I i:ps)])
657657
| i >= 0 = isNatural (S [P ps])
658-
| otherwise = WriterT Nothing
658+
| otherwise = return False
659659
-- If i is not a natural number then their sum *might* be natural,
660660
-- but we simply can't be sure since ps might be zero
661661
isNatural (S [P (V _:ps)]) = isNatural (S [P ps])

tests/Tests.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,8 @@ oneLtPowSubst = go
508508
go :: 1 <= b => Proxy a -> Proxy a
509509
go = id
510510

511-
givenLEZeroNotImpossible :: forall (a :: Nat) . Proxy a -> a <= 0 => ()
512-
givenLEZeroNotImpossible _ = go (Proxy @(a + a - a))
513-
where
514-
go :: Proxy b -> b <= 0 => ()
515-
go _ = ()
511+
givenLEZeroNotImpossible :: forall (a :: Nat) . Proxy (a <= 0) -> Proxy 'True
512+
givenLEZeroNotImpossible p = id (Proxy @(a + 0 <=? 0))
516513

517514
main :: IO ()
518515
main = defaultMain tests
@@ -618,7 +615,7 @@ tests = testGroup "ghc-typelits-natnormalise"
618615
show (oneLtPowSubst (Proxy :: Proxy 0)) @?=
619616
"Proxy"
620617
, testCase "given a <= 0 is not impossible" $
621-
givenLEZeroNotImpossible (Proxy @0) @?= ()
618+
givenLEZeroNotImpossible (Proxy @(0 <=? 0)) @?= Proxy
622619
]
623620
, testGroup "errors"
624621
[ testCase "x + 2 ~ 3 + x" $ testProxy1 `throws` testProxy1Errors

0 commit comments

Comments
 (0)