diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2020-11-30 17:08:40 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-12-23 10:21:56 -0500 |
commit | f0ec06c76ccd6797d42736fd423adbbb238723b4 (patch) | |
tree | c6eade36b2649f83df8172ac319f716c5f30ebe0 /compiler/GHC/CoreToIface.hs | |
parent | 56841432ae4e38dabdada1a280ef0e0878e895f1 (diff) | |
download | haskell-f0ec06c76ccd6797d42736fd423adbbb238723b4.tar.gz |
WorkWrap: Unbox constructors with existentials (#18982)
Consider
```hs
data Ex where
Ex :: e -> Int -> Ex
f :: Ex -> Int
f (Ex e n) = e `seq` n + 1
```
Worker/wrapper should build the following worker for `f`:
```hs
$wf :: forall e. e -> Int# -> Int#
$wf e n = e `seq` n +# 1#
```
But previously it didn't, because `Ex` binds an existential.
This patch lifts that condition. That entailed having to instantiate
existential binders in `GHC.Core.Opt.WorkWrap.Utils.mkWWstr` via
`GHC.Core.Utils.dataConRepFSInstPat`, requiring a bit of a refactoring
around what is now `DataConPatContext`.
CPR W/W still won't unbox DataCons with existentials.
See `Note [Which types are unboxed?]` for details.
I also refactored the various `tyCon*DataCon(s)_maybe` functions in
`GHC.Core.TyCon`, deleting some of them which are no longer needed
(`isDataProductType_maybe` and `isDataSumType_maybe`).
I cleaned up a couple of call sites, some of which weren't very explicit
about whether they cared for existentials or not.
The test output of `T18013` changed, because we now unbox the `Rule`
data type. Its constructor carries existential state and will be
w/w'd now. In the particular example, the worker functions inlines right
back into the wrapper, which then unnecessarily has a (quite big) stable
unfolding. I think this kind of fallout is inevitable;
see also Note [Don't w/w inline small non-loop-breaker things].
There's a new regression test case `T18982`.
Fixes #18982.
Diffstat (limited to 'compiler/GHC/CoreToIface.hs')
-rw-r--r-- | compiler/GHC/CoreToIface.hs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/GHC/CoreToIface.hs b/compiler/GHC/CoreToIface.hs index a65e89853c..076c2812d9 100644 --- a/compiler/GHC/CoreToIface.hs +++ b/compiler/GHC/CoreToIface.hs @@ -245,7 +245,7 @@ toIfaceTyCon tc , Just tsort <- tupleSort tc' = tsort | isUnboxedSumTyCon tc - , Just cons <- isDataSumTyCon_maybe tc = IfaceSumTyCon (length cons) + , Just cons <- tyConDataCons_maybe tc = IfaceSumTyCon (length cons) | otherwise = IfaceNormalTyCon |