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

Sebastian Graf gitlab at gitlab.haskell.org
Wed Apr 1 18:09:09 UTC 2020



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


Commits:
f5344aa5 by Sebastian Graf at 2020-04-01T20:07:42+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, which is tracked
by these new test cases:

- `T13380b`: Regression in dead code elimination, because !2956 was too
             syntactic about `raiseIO#`
- `T13380c`: No need to apply the "IO hack" when the IO action may not
             throw a precise exception
- `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting
             to manual state token threading and direct use of primops.
             More details below.

The "IO hack" (which is a fallback to preserve precise exceptions
semantics and thus soundness, rather than some smart thing that
increases precision) is quite a misnomer and is called
`mayThrowPreciseException` now.

Also there is a slight chance that the IO hack was unsound before,
because it assumes that precise exceptions can only be thrown from a
case scrutinee of type `(# State# RealWorld, _ #)`.
I couldn't come up with a program using the `IO` abstraction that
violates this assumption. But it's easy to do so via manual state token
threading and direct use of primops, see `T13380d`. Also similar code
might be generated by Nested CPR in the (hopefully not too) distant
future.

Hence, we now have a more careful test in `forcesRealWorld` that passes
`T13380d`.

- - - - -


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/f5344aa5534a33125ddf6a18499701c948745898

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f5344aa5534a33125ddf6a18499701c948745898
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/cdea21c6/attachment.html>


More information about the ghc-commits mailing list