Draft: Don't inline newtype DFuns (#21229)
Our work on #21229 (closed) uncovered a way in which Specialise could produce unsound specialisations, ultimately caused by reboxing of newtype dictionaries.
In the case of datatypes, we carefully avoid this through the mechanism in
Note [ClassOp/DFun selection]
that refrains from inlining a DFun.
This patch uses the same mechanism for newtype dictionaries, thus upholding the
new Note [Do not inline dictionary selectors]
.
I also had to adapt GHC.Tc.Instance.Class.makeLitDict
to produce a call to
a DFun, GHC.TypeNats.natDict @0 (SNat (NS 0##))
instead of producing the
necessary evidence of the form MkKnownNat (SNat (NS 0##))
directly. That is
because the latter will no longer rewrite with Note [ClassOp/DFun selection]
(it is not a DFun, after all), regressing T14170.
The new natDict
(resp. symbolDict
, charDict
) bindings are implemented via
Note [Patching magic definitions]
and thus need to add a few known-key things.
- Fixes #21229 (closed).
- See also #21328 (closed)