Skip to content
Snippets Groups Projects
Commit 9a759195 authored by Sebastian Graf's avatar Sebastian Graf
Browse files

Make DataCon workers strict in strict fields (#20749)

This patch tweaks `exprIsConApp_maybe`, `exprIsHNF` and friends, and Demand
Analysis so that they exploit and maintain strictness of DataCon workers. See
`Note [Strict fields in Core]` for details.

Very little needed to change, and it puts field seq insertion done by Tag
Inference into a new perspective: That of *implementing* strict field semantics.
Before Tag Inference, DataCon workers are strict. Afterwards they are
effectively lazy and field seqs happen around use sites. History has shown
that there is no other way to guarantee taggedness and thus the STG Strict Field
Invariant.

There's also a functional change to `exprIsHNF`, which previously used
`exprOkForSpeculation` on unlifted arguments instead of recursing into
`exprIsHNF`. That regressed the termination analysis in CPR analysis
(which simply calls out to `exprIsHNF`), so I made it call
`exprOkForSpeculation`, too.

There's a small regression in Demand Analysis, visible in the changed test
output of T16859: Previously, a field seq on a variable would give that
variable a "used exactly once" demand, now it's "used at least once", because
`dmdTransformDataConSig` accounts for future uses of the field that actually all
go through the case binder (and hence won't re-enter the potential thunk). The
difference should hardly be observable.

Unfortunately, T21392 does no longer reproduce after this patch, so I marked it
as "not broken" in order to track whether we regress again in the future.

Fixes #20749, the satisfying conclusion of an annoying saga (cf. the ideas
in #21497 and #22475).
parent 93f0e3c4
No related branches found
No related tags found
No related merge requests found
Pipeline #63920 failed
Showing
with 488 additions and 316 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment