Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
5591 commits behind the upstream repository.
  • Apoorv Ingle's avatar
    5ff7cc26
    Expand `do` blocks right before typechecking using the `HsExpansion` philosophy. · 5ff7cc26
    Apoorv Ingle authored
    - 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.
    5ff7cc26
    History
    Expand `do` blocks right before typechecking using the `HsExpansion` philosophy.
    Apoorv Ingle authored
    - 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.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
T23147.hs 665 B