Skip to content

WIP: Preserve precise exceptions in strictness analysis

Sebastian Graf requested to merge wip/T17676 into master

Superseded by !2956 (closed) and !3014 (closed), as per https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions.

The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) always was quite hard to understand. That led to a misguided effort to simplify it (!1829 (closed)), because the Note wasn't particularly clear about what kinds of side-effects it cares about.

The implementation seemed to care about preserving precise exception semantics, but failed to deliver for the central case of raiseIO# (#17676 (closed)), which is in stark contrast to one of the motivating examples in the Note (the one about exitWith ExitSuccess).

This patch rewords the Note to apply to IO actions throwing precise exceptions, rather than all side-effecting IO actions (such as write effects) in general. Also it makes this clear in the implementation by extracting the rather opaque io_hack_reqd into CoreUtils.exprMightThrowPreciseException.

In fact, that alone wasn't enough to fix #17676 (closed) (see #17676 (comment 248676)). It actually turned out to be a duplicate of #13380 (closed), for which we had a fix in 7b087aeb, making catchIO# have topDiv from botDiv. But that was reverted on the grounds of regressing dead code elimination too much. In this patch we introduce exnDiv for raiseIO#, the defaultDmd of which acts like topDivs (which was the key point which fixed #13380 (closed)), but otherwise acts like botDiv in terms of dead code elimination.

Fixes #13380 (closed) and #17676 (closed).

Edited by Sebastian Graf

Merge request reports