Note [Do not strictify a DFun's parameter dictionaries]
The typechecker can tie recursive knots involving (non-recursive) DFuns, so we must not strictify a DFun's parameter dictionaries (#22549). T22549 has an example involving undecidable instances that <<loop>>s when we strictify the DFun of, e.g., `$fEqSeqT`: Main.$fEqSeqT = \@m @a ($dEq :: Eq (m (ViewT m a))) ($dMonad :: Monad m) -> GHC.Classes.C:Eq @(SeqT m a) ($c== @m @a $dEq $dMonad) ($c/= @m @a $dEq $dMonad) Rec { $dEq_a = Main.$fEqSeqT @Identity @Int $dEq_b Main.$fMonadIdentity $dEq_b = ... $dEq_a ... <another strict context due to DFun> } If we make `$fEqSeqT` strict in `$dEq`, we'll collapse the Rec group into a giant, <<loop>>ing thunk. To prevent that, we never strictify dictionary params when inside a DFun. That is implemented by unsetting 'dmd_strict_dicts' when entering a DFun. See also Note [Speculative evaluation] in GHC.CoreToStg.Prep which has a rather similar example in #20836. We may never speculate *arguments* of (recursive) DFun calls, likewise we should not mark *formal parameters* of recursive DFuns as strict.
References 1
- Speculative evaluation GHC.CoreToStg.Prep
Referenced by 4
- GHC.Core.Opt.DmdAnal call site ×2
- Making dictionary parameters strict GHC.Core.Opt.DmdAnal
- Speculative evaluation GHC.CoreToStg.Prep