Skip to content
Snippets Groups Projects
  1. Feb 03, 2024
    • Apoorv Ingle's avatar
      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
  2. Jan 20, 2024
  3. Dec 06, 2023
  4. Aug 09, 2023
  5. Aug 02, 2023
  6. May 19, 2023
  7. May 05, 2023
  8. Apr 26, 2023
    • Sebastian Graf's avatar
      DmdAnal: Unleash demand signatures of free RULE and unfolding binders (#23208) · c30ac25f
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      In #23208 we observed that the demand signature of a binder occuring in a RULE
      wasn't unleashed, leading to a transitively used binder being discarded as
      absent. The solution was to use the same code path that we already use for
      handling exported bindings.
      
      See the changes to `Note [Absence analysis for stable unfoldings and RULES]`
      for more details.
      
      I took the chance to factor out the old notion of a `PlusDmdArg` (a pair of a
      `VarEnv Demand` and a `Divergence`) into `DmdEnv`, which fits nicely into our
      existing framework. As a result, I had to touch quite a few places in the code.
      
      This refactoring exposed a few small bugs around correct handling of bottoming
      demand environments. As a result, some strictness signatures now mention uniques
      that weren't there before which caused test output changes to T13143, T19969 and
      T22112. But these tests compared whole -ddump-simpl listings which is a very
      fragile thing to begin with. I changed what exactly they test for based on the
      symptoms in the corresponding issues.
      
      There is a single regression in T18894 because we are more conservative around
      stable unfoldings now. Unfortunately it is not easily fixed; let's wait until
      there is a concrete motivation before invest more time.
      
      Fixes #23208.
      c30ac25f
  9. Mar 30, 2023
  10. Jan 17, 2023
  11. Dec 14, 2022
  12. Nov 29, 2022
  13. Nov 09, 2022
    • Giles Anderson's avatar
      Use TcRnDiagnostic in GHC.Tc.TyCl.Instance (#20117) · 92ccb8de
      Giles Anderson authored and Marge Bot's avatar Marge Bot committed
      The following `TcRnDiagnostic` messages have been introduced:
      
      TcRnWarnUnsatisfiedMinimalDefinition
      TcRnMisplacedInstSig
      TcRnBadBootFamInstDeclErr
      TcRnIllegalFamilyInstance
      TcRnAssocInClassErr
      TcRnBadFamInstDecl
      TcRnNotOpenFamily
      92ccb8de
  14. Oct 11, 2022
    • Matthew Pickering's avatar
      Tidy implicit binds · fbb88740
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      We want to put implicit binds into fat interface files, so the easiest
      thing to do seems to be to treat them uniformly with other binders.
      fbb88740
  15. Sep 28, 2022
    • Simon Peyton Jones's avatar
      Refactor UnfoldingSource and IfaceUnfolding · addeefc0
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      I finally got tired of the way that IfaceUnfolding reflected
      a previous structure of unfoldings, not the current one. This
      MR refactors UnfoldingSource and IfaceUnfolding to be simpler
      and more consistent.
      
      It's largely just a refactor, but in UnfoldingSource (which moves
      to GHC.Types.Basic, since it is now used in IfaceSyn too), I
      distinguish between /user-specified/ and /system-generated/ stable
      unfoldings.
      
          data UnfoldingSource
            = VanillaSrc
            | StableUserSrc   -- From a user-specified pragma
            | StableSystemSrc -- From a system-generated unfolding
            | CompulsorySrc
      
      This has a minor effect in CSE (see the use of isisStableUserUnfolding
      in GHC.Core.Opt.CSE), which I tripped over when working on
      specialisation, but it seems like a Good Thing to know anyway.
      addeefc0
  16. Sep 13, 2022
    • sheaf's avatar
      Diagnostic codes: acccept test changes · 362cca13
      sheaf authored and Marge Bot's avatar Marge Bot committed
      The testsuite output now contains diagnostic codes, so many tests need
      to be updated at once.
      We decided it was best to keep the diagnostic codes in the testsuite
      output, so that contributors don't inadvertently make changes to the
      diagnostic codes.
      362cca13
  17. Jul 01, 2022
  18. Jun 20, 2022
    • Sebastian Graf's avatar
      Simplify: Take care with eta reduction in recursive RHSs (#21652) · 49fb2f9b
      Sebastian Graf authored
      Similar to the fix to #20836 in CorePrep, we now track the set of enclosing
      recursive binders in the SimplEnv and SimpleOptEnv.
      See Note [Eta reduction in recursive RHSs] for details.
      
      I also updated Note [Arity robustness] with the insights Simon and I had in a
      call discussing the issue.
      
      Fixes #21652.
      
      Unfortunately, we get a 5% ghc/alloc regression in T16577. That is due to
      additional eta reduction in GHC.Read.choose1 and the resulting ANF-isation
      of a large list literal at the top-level that didn't happen before (presumably
      because it was too interesting to float to the top-level). There's not much we
      can do about that.
      
      Metric Increase:
          T16577
      49fb2f9b
  19. Oct 24, 2021
    • Joachim Breitner's avatar
      undefined: Neater CallStack in error message · 3417a81a
      Joachim Breitner authored and Marge Bot's avatar Marge Bot committed
      Users of `undefined` don’t want to see
      ```
      files.hs: Prelude.undefined:
      CallStack (from HasCallStack):
        error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
        undefined, called at file.hs:151:19 in main:Main
      ```
      but want to see
      ```
      files.hs: Prelude.undefined:
      CallStack (from HasCallStack):
        undefined, called at file.hs:151:19 in main:Main
      ```
      so let’s make that so.
      
      The function for that is `withFrozenCallStack`, but that is not usable
      here (module dependencies, and also not representation-polymorphic). And
      even if it were, it could confuse GHC’s strictness analyzer, leading to
      big regressions in some perf tests (T10421 in particular).
      
      So after shuffling modules and definitions around, I eventually noticed
      that the easiest way is to just not call `error` here.
      
      Fixes #19886
      3417a81a
  20. Sep 30, 2021
    • Sebastian Graf's avatar
      Nested CPR light unleashed (#18174) · c261f220
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      This patch enables worker/wrapper for nested constructed products, as described
      in `Note [Nested CPR]`. The machinery for expressing Nested CPR was already
      there, since !5054. Worker/wrapper is equipped to exploit Nested CPR annotations
      since !5338. CPR analysis already handles applications in batches since !5753.
      This patch just needs to flip a few more switches:
      
      1. In `cprTransformDataConWork`, we need to look at the field expressions
         and their `CprType`s to see whether the evaluation of the expressions
         terminates quickly (= is in HNF) or if they are put in strict fields.
         If that is the case, then we retain their CPR info and may unbox nestedly
         later on. More details in `Note [Nested CPR]`.
      2. Enable nested `ConCPR` signatures in `GHC.Types.Cpr`.
      3. In the `asConCpr` call in `GHC.Core.Opt.WorkWrap.Utils`, pass CPR info of
         fields to the `Unbox`.
      4. Instead of giving CPR signatures to DataCon workers and wrappers, we now have
         `cprTransformDataConWork` for workers and treat wrappers by analysing their
         unfolding. As a result, the code from GHC.Types.Id.Make went away completely.
      5. I deactivated worker/wrappering for recursive DataCons and wrote a function
         `isRecDataCon` to detect them. We really don't want to give `repeat` or
         `replicate` the Nested CPR property.
         See Note [CPR for recursive data structures] for which kind of recursive
         DataCons we target.
      6. Fix a couple of tests and their outputs.
      
      I also documented that CPR can destroy sharing and lead to asymptotic increase
      in allocations (which is tracked by #13331/#19326) in
      `Note [CPR for data structures can destroy sharing]`.
      
      Nofib results:
      ```
      --------------------------------------------------------------------------------
              Program         Allocs    Instrs
      --------------------------------------------------------------------------------
         ben-raytrace          -3.1%     -0.4%
         binary-trees          +0.8%     -2.9%
         digits-of-e2          +5.8%     +1.2%
                event          +0.8%     -2.1%
       fannkuch-redux          +0.0%     -1.4%
                 fish           0.0%     -1.5%
               gamteb          -1.4%     -0.3%
              mkhprog          +1.4%     +0.8%
           multiplier          +0.0%     -1.9%
                  pic          -0.6%     -0.1%
              reptile         -20.9%    -17.8%
            wave4main          +4.8%     +0.4%
                 x2n1        -100.0%     -7.6%
      --------------------------------------------------------------------------------
                  Min         -95.0%    -17.8%
                  Max          +5.8%     +1.2%
       Geometric Mean          -2.9%     -0.4%
      ```
      The huge wins in x2n1 (loopy list) and reptile (see #19970) are due to
      refraining from unboxing (:). Other benchmarks like digits-of-e2 or wave4main
      regress because of that. Ultimately there are no great improvements due to
      Nested CPR alone, but at least it's a win.
      Binary sizes decrease by 0.6%.
      
      There are a significant number of metric decreases. The most notable ones (>1%):
      ```
             ManyAlternatives(normal) ghc/alloc   771656002.7   762187472.0  -1.2%
             ManyConstructors(normal) ghc/alloc  4191073418.7  4114369216.0  -1.8%
            MultiLayerModules(normal) ghc/alloc  3095678333.3  3128720704.0  +1.1%
                    PmSeriesG(normal) ghc/alloc    50096429.3    51495664.0  +2.8%
                    PmSeriesS(normal) ghc/alloc    63512989.3    64681600.0  +1.8%
                    PmSeriesV(normal) ghc/alloc    62575424.0    63767208.0  +1.9%
                       T10547(normal) ghc/alloc    29347469.3    29944240.0  +2.0%
                      T11303b(normal) ghc/alloc    46018752.0    47367576.0  +2.9%
                       T12150(optasm) ghc/alloc    81660890.7    82547696.0  +1.1%
                       T12234(optasm) ghc/alloc    59451253.3    60357952.0  +1.5%
                       T12545(normal) ghc/alloc  1705216250.7  1751278952.0  +2.7%
                       T12707(normal) ghc/alloc   981000472.0   968489800.0  -1.3% GOOD
                       T13056(optasm) ghc/alloc   389322664.0   372495160.0  -4.3% GOOD
                       T13253(normal) ghc/alloc   337174229.3   341954576.0  +1.4%
                       T13701(normal) ghc/alloc  2381455173.3  2439790328.0  +2.4%  BAD
                         T14052(ghci) ghc/alloc  2162530642.7  2139108784.0  -1.1%
                       T14683(normal) ghc/alloc  3049744728.0  2977535064.0  -2.4% GOOD
                       T14697(normal) ghc/alloc   362980213.3   369304512.0  +1.7%
                       T15164(normal) ghc/alloc  1323102752.0  1307480600.0  -1.2%
                       T15304(normal) ghc/alloc  1304607429.3  1291024568.0  -1.0%
                       T16190(normal) ghc/alloc   281450410.7   284878048.0  +1.2%
                       T16577(normal) ghc/alloc  7984960789.3  7811668768.0  -2.2% GOOD
                       T17516(normal) ghc/alloc  1171051192.0  1153649664.0  -1.5%
                       T17836(normal) ghc/alloc  1115569746.7  1098197592.0  -1.6%
                      T17836b(normal) ghc/alloc    54322597.3    55518216.0  +2.2%
                       T17977(normal) ghc/alloc    47071754.7    48403408.0  +2.8%
                      T17977b(normal) ghc/alloc    42579133.3    43977392.0  +3.3%
                       T18923(normal) ghc/alloc    71764237.3    72566240.0  +1.1%
                        T1969(normal) ghc/alloc   784821002.7   773971776.0  -1.4% GOOD
                        T3294(normal) ghc/alloc  1634913973.3  1614323584.0  -1.3% GOOD
                        T4801(normal) ghc/alloc   295619648.0   292776440.0  -1.0%
                      T5321FD(normal) ghc/alloc   278827858.7   276067280.0  -1.0%
                        T5631(normal) ghc/alloc   586618202.7   577579960.0  -1.5%
                        T5642(normal) ghc/alloc   494923048.0   487927208.0  -1.4%
                        T5837(normal) ghc/alloc    37758061.3    39261608.0  +4.0%
                        T9020(optasm) ghc/alloc   257362077.3   254672416.0  -1.0%
                        T9198(normal) ghc/alloc    49313365.3    50603936.0  +2.6%  BAD
                        T9233(normal) ghc/alloc   704944258.7   685692712.0  -2.7% GOOD
                        T9630(normal) ghc/alloc  1476621560.0  1455192784.0  -1.5%
                        T9675(optasm) ghc/alloc   443183173.3   433859696.0  -2.1% GOOD
                       T9872a(normal) ghc/alloc  1720926653.3  1693190072.0  -1.6% GOOD
                       T9872b(normal) ghc/alloc  2185618061.3  2162277568.0  -1.1% GOOD
                       T9872c(normal) ghc/alloc  1765842405.3  1733618088.0  -1.8% GOOD
         TcPlugin_RewritePerf(normal) ghc/alloc  2388882730.7  2365504696.0  -1.0%
                        WWRec(normal) ghc/alloc   607073186.7   597512216.0  -1.6%
      
                        T9203(normal) run/alloc   107284064.0   102881832.0  -4.1%
                haddock.Cabal(normal) run/alloc 24025329589.3 23768382560.0  -1.1%
                 haddock.base(normal) run/alloc 25660521653.3 25370321824.0  -1.1%
             haddock.compiler(normal) run/alloc 74064171706.7 73358712280.0  -1.0%
      ```
      The biggest exception to the rule is T13701 which seems to fluctuate as usual
      (not unlike T12545). T14697 has a similar quality, being a generated
      multi-module test. T5837 is small enough that it similarly doesn't measure
      anything significant besides module loading overhead.
      T13253 simply does one additional round of Simplification due to Nested CPR.
      
      There are also some apparent regressions in T9198, T12234 and PmSeriesG that we
      (@mpickering and I) were simply unable to reproduce locally. @mpickering tried
      to run the CI script in a local Docker container and actually found that T9198
      and PmSeriesG *improved*. In MRs that were rebased on top this one, like !4229,
      I did not experience such increases. Let's not get hung up on these regression
      tests, they were meant to test for asymptotic regressions.
      
      The build-cabal test improves by 1.2% in -O0.
      
      Metric Increase:
          T10421
          T12234
          T12545
          T13035
          T13056
          T13701
          T14697
          T18923
          T5837
          T9198
      Metric Decrease:
          ManyConstructors
          T12545
          T12707
          T13056
          T14683
          T16577
          T18223
          T1969
          T3294
          T9203
          T9233
          T9675
          T9872a
          T9872b
          T9872c
          T9961
          TcPlugin_RewritePerf
      c261f220
  21. Sep 28, 2021
  22. Sep 08, 2021
  23. Jun 25, 2021
    • Krzysztof Gogolewski's avatar
      Fixes around incomplete guards (#20023, #20024) · 4d5967b5
      Krzysztof Gogolewski authored and Marge Bot's avatar Marge Bot committed
      - Fix linearity error with incomplete MultiWayIf (#20023)
      - Fix partial pattern binding error message (#20024)
      - Remove obsolete test LinearPolyTest
        It tested the special typing rule for ($), which was removed
        during the implementation of Quick Look 97cff919.
      - Fix ticket numbers in linear/*/all.T, they referred to linear types
        issue tracker
      4d5967b5
  24. Jun 24, 2021
  25. Jun 10, 2021
    • Simon Peyton Jones's avatar
      Fix INLINE pragmas in desugarer · 3d5cb335
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      In #19969 we discovered that GHC has has a bug *forever* that means it
      sometimes essentially discarded INLINE pragams.  This happened when you have
      * Two more more mutually recursive functions
      * Some of which (presumably not all!) have an INLINE pragma
      * Completely monomorphic.
      
      This hits a particular case in GHC.HsToCore.Binds.dsAbsBinds, which was
      simply wrong -- it put the INLINE pragma on the wrong binder.
      
      This patch fixes the bug, rather easily, by adjusting the
      no-tyvar, no-dict case of GHC.HsToCore.Binds.dsAbsBinds.
      
      I also discovered that the GHC.Core.Opt.Pipeline.shortOutIndirections
      was not doing a good job for
      
          {-# INLINE lcl_id #-}
          lcl_id = BIG
      
          gbl_id = lcl_id
      
      Here we want to transfer the stable unfolding to gbl_id (we do), but
      we also want to remove it from lcl_id (we were not doing that).
      Otherwise both Ids have large stable unfoldings.  Easily fixed.
      Note [Transferring IdInfo] explains.
      3d5cb335
  26. Jun 03, 2021
    • Alfredo Di Napoli's avatar
      Port HsToCore messages to new infrastructure · d5b89ed4
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      This commit converts a bunch of HsToCore (Ds) messages to use the new
      GHC's diagnostic message infrastructure. In particular the DsMessage
      type has been expanded with a lot of type constructors, each
      encapsulating a particular error and warning emitted during desugaring.
      
      Due to the fact that levity polymorphism checking can happen both at the
      Ds and at the TcRn level, a new `TcLevityCheckDsMessage` constructor has
      been added to the `TcRnMessage` type.
      d5b89ed4
  27. Apr 14, 2021
  28. Apr 06, 2021
    • Alfredo Di Napoli's avatar
      Correct warning for deprecated and unrecognised flags · 3483c3de
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      Fixes #19616.
      
      This commit changes the `GHC.Driver.Errors.handleFlagWarnings` function
      to rely on the newly introduced `DiagnosticReason`. This allows us to
      correctly pretty-print the flags which triggered some warnings and in
      turn remove the cruft around this function (like the extra filtering
      and the `shouldPrintWarning` function.
      3483c3de
  29. Mar 20, 2021
    • Sebastian Graf's avatar
      Nested CPR light (#19398) · 044e5be3
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      While fixing #19232, it became increasingly clear that the vestigial
      hack described in `Note [Optimistic field binder CPR]` is complicated
      and causes reboxing. Rather than make the hack worse, this patch
      gets rid of it completely in favor of giving deeply unboxed parameters
      the Nested CPR property. Example:
      ```hs
      f :: (Int, Int) -> Int
      f p = case p of
       (x, y) | x == y    = x
              | otherwise = y
      ```
      Based on `p`'s `idDemandInfo` `1P(1P(L),1P(L))`, we can see that both
      fields of `p` will be available unboxed. As a result, we give `p` the
      nested CPR property `1(1,1)`. When analysing the `case`, the field
      CPRs are transferred to the binders `x` and `y`, respectively, so that
      we ultimately give `f` the CPR property.
      
      I took the liberty to do a bit of refactoring:
      
      - I renamed `CprResult` ("Constructed product result result") to plain
        `Cpr`.
      - I Introduced `FlatConCpr` in addition to (now nested) `ConCpr` and
        and according pattern synonym that rewrites flat `ConCpr` to
        `FlatConCpr`s, purely for compiler perf reasons.
      - Similarly for performance reasons, we now store binders with a
        Top signature in a separate `IntSet`,
        see `Note [Efficient Top sigs in SigEnv]`.
      - I moved a bit of stuff around in `GHC.Core.Opt.WorkWrap.Utils` and
        introduced `UnboxingDecision` to replace the `Maybe DataConPatContext`
        type we used to return from `wantToUnbox`.
      - Since the `Outputable Cpr` instance changed anyway, I removed the
        leading `m` which we used to emit for `ConCpr`. It's just noise,
        especially now that we may output nested CPRs.
      
      Fixes #19398.
      044e5be3
  30. Mar 10, 2021
  31. Mar 03, 2021
  32. Feb 06, 2021
  33. Jan 17, 2021
  34. Dec 19, 2020
  35. Dec 14, 2020
    • Ben Gamari's avatar
      Optimise nullary type constructor usage · dad87210
      Ben Gamari authored
      During the compilation of programs GHC very frequently deals with
      the `Type` type, which is a synonym of `TYPE 'LiftedRep`. This patch
      teaches GHC to avoid expanding the `Type` synonym (and other nullary
      type synonyms) during type comparisons, saving a good amount of work.
      This optimisation is described in `Note [Comparing nullary type
      synonyms]`.
      
      To maximize the impact of this optimisation, we introduce a few
      special-cases to reduce `TYPE 'LiftedRep` to `Type`. See
      `Note [Prefer Type over TYPE 'LiftedPtrRep]`.
      
      Closes #17958.
      
      Metric Decrease:
         T18698b
         T1969
         T12227
         T12545
         T12707
         T14683
         T3064
         T5631
         T5642
         T9020
         T9630
         T9872a
         T13035
         haddock.Cabal
         haddock.base
      dad87210
    • Ben Gamari's avatar
      Revert "Optimise nullary type constructor usage" · 92377c27
      Ben Gamari authored
      This was inadvertently merged.
      
      This reverts commit 7e9debd4.
      92377c27
    • Ben Gamari's avatar
      Optimise nullary type constructor usage · 7e9debd4
      Ben Gamari authored
      During the compilation of programs GHC very frequently deals with
      the `Type` type, which is a synonym of `TYPE 'LiftedRep`. This patch
      teaches GHC to avoid expanding the `Type` synonym (and other nullary
      type synonyms) during type comparisons, saving a good amount of work.
      This optimisation is described in `Note [Comparing nullary type
      synonyms]`.
      
      To maximize the impact of this optimisation, we introduce a few
      special-cases to reduce `TYPE 'LiftedRep` to `Type`. See
      `Note [Prefer Type over TYPE 'LiftedPtrRep]`.
      
      Closes #17958.
      
      Metric Decrease:
         T18698b
         T1969
         T12227
         T12545
         T12707
         T14683
         T3064
         T5631
         T5642
         T9020
         T9630
         T9872a
         T13035
         haddock.Cabal
         haddock.base
      7e9debd4
  36. Nov 20, 2020
    • Sebastian Graf's avatar
      Demand: Interleave usage and strictness demands (#18903) · 0aec78b6
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      As outlined in #18903, interleaving usage and strictness demands not
      only means a more compact demand representation, but also allows us to
      express demands that we weren't easily able to express before.
      
      Call demands are *relative* in the sense that a call demand `Cn(cd)`
      on `g` says "`g` is called `n` times. *Whenever `g` is called*, the
      result is used according to `cd`". Example from #18903:
      
      ```hs
      h :: Int -> Int
      h m =
        let g :: Int -> (Int,Int)
            g 1 = (m, 0)
            g n = (2 * n, 2 `div` n)
            {-# NOINLINE g #-}
        in case m of
          1 -> 0
          2 -> snd (g m)
          _ -> uncurry (+) (g m)
      ```
      
      Without the interleaved representation, we would just get `L` for the
      strictness demand on `g`. Now we are able to express that whenever
      `g` is called, its second component is used strictly in denoting `g`
      by `1C1(P(1P(U),SP(U)))`. This would allow Nested CPR to unbox the
      division, for example.
      
      Fixes #18903.
      While fixing regressions, I also discovered and fixed #18957.
      
      Metric Decrease:
          T13253-spj
      0aec78b6
  37. Nov 19, 2020
    • Sebastian Graf's avatar
      PmCheck: Print types of uncovered patterns (#18932) · 8150f654
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      In order to avoid confusion as in #18932, we display the type of the
      match variables in the non-exhaustiveness warning, e.g.
      
      ```
      T18932.hs:14:1: warning: [-Wincomplete-patterns]
          Pattern match(es) are non-exhaustive
          In an equation for ‘g’:
              Patterns of type  ‘T a’, ‘T a’, ‘T a’ not matched:
                  (MkT2 _) (MkT1 _) (MkT1 _)
                  (MkT2 _) (MkT1 _) (MkT2 _)
                  (MkT2 _) (MkT2 _) (MkT1 _)
                  (MkT2 _) (MkT2 _) (MkT2 _)
                  ...
         |
      14 | g (MkT1 x) (MkT1 _) (MkT1 _) = x
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ```
      
      It also allows us to omit the type signature on wildcard matches which
      we previously showed in only some situations, particularly
      `-XEmptyCase`.
      
      Fixes #18932.
      8150f654
Loading