Note [Generated code and pattern-match checking]
Some parts of the compiler generate code that is then typechecked. For example: - the XXExprGhcRn mechanism described in Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr, - the deriving mechanism. It is usually the case that we want to avoid generating error messages that refer to generated code. The way this is handled is that we mark certain parts of the AST as being generated (using the Origin datatype); this is then used to set the tcl_in_gen_code flag in TcLclEnv, as explained in Note [Error contexts in generated code] in GHC.Tc.Utils.Monad. Being in generated code is usually taken to mean we should also skip doing pattern-match checking, but not always. For example, when desugaring a record update (as described in Note [Record Updates] in GHC.Tc.Gen.Expr), we still want to do pattern-match checking, in order to report incomplete record updates (failing to do so lead to #23250). So, for a 'Generated' 'Origin', we keep track of whether we should do pattern-match checks; see the calls of the requiresPMC function (e.g. isMatchContextPmChecked and needToRunPmCheck in GHC.HsToCore.Pmc.Utils).
References 3
- Rebindable syntax and XXExprGhcRn GHC.Hs.Expr
- Record Updates GHC.Tc.Gen.Expr
- Error contexts in generated code GHC.Tc.Utils.Monad
Referenced by 6
- GHC.Types.Basic call site ×3
- GHC.Hs.Expr call site
- Expanding HsDo with XXExprGhcRn GHC.Tc.Gen.Do
- Error contexts in generated code GHC.Tc.Utils.Monad