[Git][ghc/ghc][wip/dmdanal-precise-exn] DmdAnal: Reflect precise exceptions in demand types
Sebastian Graf
gitlab at gitlab.haskell.org
Fri Apr 3 14:44:05 UTC 2020
Sebastian Graf pushed to branch wip/dmdanal-precise-exn at Glasgow Haskell Compiler / GHC
Commits:
7a034c54 by Sebastian Graf at 2020-04-03T16:43:33+02:00
DmdAnal: Reflect precise exceptions in demand types
This is part two of the "fixing precise exception" plan in
https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions
and, in combination with !2956, supercedes !2525.
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`.
As for *how* we fixed these wrinkles: We augmented the `Divergence`
lattice to a diamond with two new elements forming the middle layer:
- `ExnOrDiv`: Means either `Diverges` (, throws an imprecise exception)
or throws a *precise* exception.
- `ConOrDiv`: Means either `Diverges` (, throws an imprecise exception)
or converges.
See the wiki page for more implementational details:
https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#replacing-hacks-by-principled-program-analyses
- - - - -
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/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
- testsuite/tests/simplCore/should_compile/T3772.stdout
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7a034c54d6b261ae15438276f5d9843c4dac6ac8
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7a034c54d6b261ae15438276f5d9843c4dac6ac8
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/20200403/333d037c/attachment-0001.html>
More information about the ghc-commits
mailing list