Prevent `rewriteEvidence` from converting a W into a WD
Summary
(This is true in 8.6.5 and also right now at 6febc444.)
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/typecheck/TcCanonical.hs#L2226 declares rewriteEvidence with the comment that "rewriteEvidence old_ev new_pred co ... Returns a new_ev : new_pred, with same wanted/given/derived flag as old_ev".
However, the CtWanted case just immediately calls newWanted, which ignores the incoming ctev_nosh flag and always uses WDeriv.
rewriteEvidence ev@(CtWanted { ctev_dest = dest
, ctev_loc = loc }) new_pred co
= do { mb_new_ev <- newWanted loc new_pred
Thus I'm seeing a [W] become a [WD], which seems to contradict the comment's "same flag" claim.
Steps to reproduce
Unfortunately, my only repro involves a plugin I'm developing. The constraint solver is looping unproductively because my plugin keeps discarding the (re-)emitted [D] shadow as a tautology, then the [W] "unsplits" during canonicalization (even though my plugin didn't touch the [W]), this re-emits the same [D] (via a fundep), and so on.
(See the -ddump-tc-trace snippet in first comment below.)
Expected behavior
rewriteEvidence should create a [W] from a [W].
Environment
- GHC version used: GHC-8.6.5