[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: DmdAnal: Improve handling of precise exceptions

Marge Bot gitlab at gitlab.haskell.org
Fri May 15 15:15:10 UTC 2020



 Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00
DmdAnal: Improve handling of precise exceptions

This patch does two things: Fix possible unsoundness in what was called
the "IO hack" and implement part 2.1 of the "fixing precise exceptions"
plan in
https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions,
which, in combination with !2956, supersedes !3014 and !2525.

**IO hack**

The "IO hack" (which is a fallback to preserve precise exceptions
semantics and thus soundness, rather than some smart thing that
increases precision) is called `exprMayThrowPreciseException` now.
I came up with two testcases exemplifying possible unsoundness (if
twisted enough) in the old approach:

- `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting
             to manual state token threading and direct use of primops.
             More details below.
- `T13380e`: Demonstrating unsoundness of the "IO hack" when we have
             Nested CPR. Not currently relevant, as we don't have Nested
             CPR yet.
- `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI
             calls.

Basically, the IO hack assumed 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, see
`T13380e`. Hence, we now have a more careful test in `forcesRealWorld`
that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR).

**Precise exceptions**

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 was terribly unprincipled.

That unprincipledness resulted 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 (and the existing IO hack doesn't
             detect that)

Fixing both issues in !3014 turned out to be too complicated and had
the potential to regress in the future. Hence we decided to only fix
`T13380b` and augment the `Divergence` lattice with a new middle-layer
element, `ExnOrDiv`, which means either `Diverges` (, throws an
imprecise exception) or throws a *precise* exception.

See the wiki page on Step 2.1 for more implementational details:
https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21

- - - - -
568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00
GHC.Cmm.Opt: Handle MO_XX_Conv

This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3
but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't
handled. Ideally we would eliminate the match but this appears to be a
larger task.

Fixes #18141.

- - - - -
0570ce99 by Ben Gamari at 2020-05-15T11:14:59-04:00
nonmoving: Optimise the write barrier

- - - - -
65c81c36 by Richard Eisenberg at 2020-05-15T11:14:59-04:00
MR template should ask for key part
- - - - -
c36e4f15 by Galen Huntington at 2020-05-15T11:15:02-04:00
Clarify pitfalls of NegativeLiterals; see #18022.
- - - - -
5dd21f0d by Alexey Kuleshevich at 2020-05-15T11:15:05-04:00
Fix wording in primops documentation to reflect the correct reasoning:

* Besides resizing functions, shrinking ones also mutate the
  size of a mutable array and because of those two `sizeofMutabeByteArray`
  and `sizeofSmallMutableArray` are now deprecated
* Change reference in documentation to the newer functions `getSizeof*`
  instead of `sizeof*` for shrinking functions
* Fix incorrect mention of "byte" instead of "small"

- - - - -


30 changed files:

- .gitlab/merge_request_templates/merge-request.md
- compiler/GHC.hs
- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/Cmm/Opt.hs
- compiler/GHC/Core/Arity.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/CallArity.hs
- compiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/FloatIn.hs
- compiler/GHC/Core/Opt/FloatOut.hs
- compiler/GHC/Core/Opt/LiberateCase.hs
- compiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.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/ForeignCall.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Types/Id/Make.hs
- docs/users_guide/exts/negative_literals.rst
- rts/Updates.h
- + testsuite/tests/cmm/opt/T18141.hs
- testsuite/tests/cmm/opt/all.T
- testsuite/tests/stranal/should_compile/T10482a.stderr
- testsuite/tests/stranal/should_compile/T10694.stderr


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ecc2e67a2296986049580d785f5f78d450a83901...5dd21f0d87aa00f21dba0401ddb7989c8af486cd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ecc2e67a2296986049580d785f5f78d450a83901...5dd21f0d87aa00f21dba0401ddb7989c8af486cd
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/20200515/d900187a/attachment.html>


More information about the ghc-commits mailing list