FRR phase 2 for newtype constructor patterns
Ticket: #20363 (closed).
This MR implements PHASE 2 of the FixedRuntimeRep plan described in Note [The Concrete mechanism] in GHC.Tc.Utils.Concrete for newtype constructor patterns.
In short, GHC now accepts programs of the form
f (MkN x) = ...in which the argument x of the newtype constructor pattern MkN x has a representation that is not syntactically concrete, e.g. it can be
Id IntRep reducing to IntRep. See T20363{,b,c} for examples.
There are two main parts to the implementation:
-
Typechecking, in GHC.Tc.Gen.Pat.tcDataConPat. See Note [Typechecking newtype constructor patterns] in GHC.Tc.Gen.Pat.
-
Desugaring. We restructure the code for desugaring pattern matches by allowing the scrutinised match variable to be casted. This allows us to accumulate coercions and avoids creating binders at intermediate types tha don't have a fixed RuntimeRep. See the revamped Note [Match Ids] in GHC.HsToCore.Monad.