Expand `do` blocks right before typechecking using the `HsExpansion` philosophy.
- Fixes #18324 #20020 #23147 #22788 #15598 #22086 #21206 - The change is detailed in - Note [Expanding HsDo with HsExpansion] in `GHC.Tc.Gen.Do` - Note [Doing HsExpansion in the Renamer vs Typechecker] in `GHC.Rename.Expr` expains the rational of doing expansions in type checker as opposed to in the renamer - Adds new datatypes: - `GHC.Hs.Expr.XXExprGhcRn`: new datatype makes this expansion work easier 1. Expansion bits for Expressions, Statements and Patterns in (`ExpandedThingRn`) 2. `PopErrCtxt` a special GhcRn Phase only artifcat to pop the previous error message in the error context stack - `GHC.Basic.Origin` now tracks the reason for expansion in case of Generated This is useful for type checking cf. `GHC.Tc.Gen.Expr.tcExpr` case for `HsLam` - Kills `HsExpansion` and `HsExpanded` as we have inlined them in `XXExprGhcRn` and `XXExprGhcTc` - Ensures warnings such as 1. Pattern match checks 2. Failable patterns 3. non-() return in body statements are preserved - Kill `HsMatchCtxt` in favor of `TcMatchAltChecker` - Testcases: * T18324 T20020 T23147 T22788 T15598 T22086 * T23147b (error message check), * DoubleMatch (match inside a match for pmc check) * pattern-fails (check pattern match with non-refutable pattern, eg. newtype) * Simple-rec (rec statements inside do statment) * T22788 (code snippet from #22788) * DoExpanion1 (Error messages for body statments) * DoExpansion2 (Error messages for bind statements) * DoExpansion3 (Error messages for let statements) Also repoint haddock to the right submodule so that the test (haddockHypsrcTest) pass Metric Increase 'compile_time/bytes allocated': T9020 The testcase is a pathalogical example of a `do`-block with many statements that do nothing. Given that we are expanding the statements into function binds, we will have to bear a (small) 2% cost upfront in the compiler to unroll the statements.
Showing
- compiler/GHC/Hs/Expr.hs 165 additions, 45 deletionscompiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Instances.hs 2 additions, 2 deletionscompiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Pat.hs 73 additions, 39 deletionscompiler/GHC/Hs/Pat.hs
- compiler/GHC/Hs/Syn/Type.hs 1 addition, 1 deletioncompiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/Hs/Utils.hs 6 additions, 5 deletionscompiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Arrows.hs 1 addition, 1 deletioncompiler/GHC/HsToCore/Arrows.hs
- compiler/GHC/HsToCore/Expr.hs 28 additions, 2 deletionscompiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs 31 additions, 6 deletionscompiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Pmc.hs 10 additions, 7 deletionscompiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Quote.hs 9 additions, 4 deletionscompiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs 68 additions, 37 deletionscompiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs 7 additions, 5 deletionscompiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Rename/Expr.hs 117 additions, 56 deletionscompiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Pat.hs 2 additions, 2 deletionscompiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Utils.hs 53 additions, 10 deletionscompiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Deriv/Generate.hs 3 additions, 3 deletionscompiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Errors/Ppr.hs 1 addition, 1 deletioncompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Gen/App.hs 62 additions, 25 deletionscompiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Arrow.hs 3 additions, 5 deletionscompiler/GHC/Tc/Gen/Arrow.hs
- compiler/GHC/Tc/Gen/Do.hs 475 additions, 0 deletionscompiler/GHC/Tc/Gen/Do.hs
Loading
Please register or sign in to comment