[Git][ghc/ghc][wip/dmdanal-precise-exn] DmdAnal: Reflect precise exceptions in demand types

Sebastian Graf gitlab at gitlab.haskell.org
Wed Apr 1 17:17:14 UTC 2020



Sebastian Graf pushed to branch wip/dmdanal-precise-exn at Glasgow Haskell Compiler / GHC


Commits:
db0d66bd by Sebastian Graf at 2020-04-01T17:29:28+02:00
DmdAnal: Reflect precise exceptions in demand types

In #13380 and #17676 we saw that we didn't preserve precise exception
semantics in demand analysis. We fixed that with minimal changes in
!2956, but that is terribly unprincipled.

That unprincipledness results in a loss of precision, for example in
the following program (a play on #13380, `T13380b`):

```hs
m :: IO ()
m = error "pattern error or whatever imprecise exception"
{-# NOINLINE m #-}

f :: Int -> Int -> IO Int
-- à la #13380
f x y | x>0       = m >> return 0
      | y>0       = return 1
      | otherwise = return 2
{-# NOINLINE f #-}
```

Currently, we fail to infer that `m` always diverges without throwing a
precise exception and hence that `f` is strict in `y`.

Quite
The "IO hack" (which is a fallback to preserve precise exceptions
semantics and thus soundness, rather than some smart thing that
increases precision)

Apart from being possibly unsound, because it assumes that precise
exceptions can only be thrown from a case scrutinee of type
`(# State# RealWorld, _ #)`, it is also imprecise, for example for the
following program (`T13380b`):

- - - - -


30 changed files:

- compiler/GHC.hs
- compiler/GHC/Core/Arity.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Op/CallArity.hs
- compiler/GHC/Core/Op/DmdAnal.hs
- compiler/GHC/Core/Op/FloatIn.hs
- compiler/GHC/Core/Op/FloatOut.hs
- compiler/GHC/Core/Op/LiberateCase.hs
- compiler/GHC/Core/Op/SetLevels.hs
- compiler/GHC/Core/Op/Simplify.hs
- compiler/GHC/Core/Op/Simplify/Utils.hs
- compiler/GHC/Core/Op/SpecConstr.hs
- compiler/GHC/Core/Op/WorkWrap/Lib.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/Unfold.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Iface/Tidy.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Types/Demand.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Types/Id/Make.hs
- compiler/prelude/primops.txt.pp
- testsuite/tests/deSugar/should_compile/T2431.stderr
- testsuite/tests/numeric/should_compile/T14170.stdout
- testsuite/tests/numeric/should_compile/T14465.stdout
- testsuite/tests/numeric/should_compile/T7116.stdout
- testsuite/tests/simplCore/should_compile/T13143.stderr
- testsuite/tests/simplCore/should_compile/T13543.stderr
- testsuite/tests/simplCore/should_compile/T3717.stderr


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db0d66bd4522ac04a24e5754faaedf43e1b1c540

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db0d66bd4522ac04a24e5754faaedf43e1b1c540
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200401/2dff3b59/attachment.html>


More information about the ghc-commits mailing list