diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2018-10-03 15:41:43 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2018-10-04 15:37:58 +0100 |
commit | 02b303eed0170983921877801e57f55d012db301 (patch) | |
tree | 7d1ba044c4d69b7aa81779b282f7efed4f05c109 /compiler | |
parent | e7ff9344a18c58c7b321566545fd37c10c609fb1 (diff) | |
download | haskell-02b303eed0170983921877801e57f55d012db301.tar.gz |
Do not mark CoVars as dead in the occur-anal
For years we have been marking CoVars as dead, becuase we
don't gather occurrence info from types. This is obviously
wrong and caused Trac #15695.
See Note [Do not mark CoVars as dead] in OccurAnal.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/simplCore/OccurAnal.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/simplCore/OccurAnal.hs b/compiler/simplCore/OccurAnal.hs index 236bb81066..2cc38a27e0 100644 --- a/compiler/simplCore/OccurAnal.hs +++ b/compiler/simplCore/OccurAnal.hs @@ -2501,6 +2501,10 @@ zapDetails = markAllMany . markAllNonTailCalled -- effectively sets to noOccInfo lookupDetails :: UsageDetails -> Id -> OccInfo lookupDetails ud id + | isCoVar id -- We do not currenly gather occurrence info (from types) + = noOccInfo -- for CoVars, so we must conservatively mark them as used + -- See Note [DoO not mark CoVars as dead] + | otherwise = case lookupVarEnv (ud_env ud) id of Just occ -> doZapping ud id occ Nothing -> IAmDead @@ -2512,6 +2516,25 @@ udFreeVars :: VarSet -> UsageDetails -> VarSet -- Find the subset of bndrs that are mentioned in uds udFreeVars bndrs ud = restrictUniqSetToUFM bndrs (ud_env ud) +{- Note [Do not mark CoVars as dead] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +It's obviously wrong to mark CoVars as dead if they are used. +Currently we don't traverse types to gather usase info for CoVars, +so we had better treat them as having noOccInfo. + +This showed up in Trac #15696 we had something like + case eq_sel d of co -> ...(typeError @(...co...) "urk")... + +Then 'd' was substitued by a dictionary, so the expression +simpified to + case (Coercion <blah>) of co -> ...(typeError @(...co...) "urk")... + +But then the "drop the case altogether" equation of rebuildCase +thought that 'co' was dead, and discarded the entire case. Urk! + +I have no idea how we managed to avoid this pitfall for so long! +-} + ------------------- -- Auxiliary functions for UsageDetails implementation |