1. 28 Mar, 2021 1 commit
    • Sebastian Graf's avatar
      Rename StrictSig to DmdSig (#19597) · b02c8ef7
      Sebastian Graf authored
      In #19597, we also settled on the following renamings:
      
        * `idStrictness` -> `idDmdSig`,
          `strictnessInfo` -> `dmdSigInfo`,
          `HsStrictness` -> `HsDmdSig`
        * `idCprInfo` -> `idCprSig`,
          `cprInfo` -> `cprSigInfo`,
          `HsCpr` -> `HsCprSig`
      
      Fixes #19597.
      b02c8ef7
  2. 22 Mar, 2021 1 commit
  3. 03 Mar, 2021 2 commits
    • Matthew Pickering's avatar
      Add whereFrom and whereFrom# primop · 9087899e
      Matthew Pickering authored
      The `whereFrom` function provides a Haskell interface for using the
      information created by `-finfo-table-map`. Given a Haskell value, the
      info table address will be passed to the `lookupIPE` function in order
      to attempt to find the source location information for that particular closure.
      
      At the moment it's not possible to distinguish the absense of the map
      and a failed lookup.
      9087899e
    • Sylvain Henry's avatar
      Fix array and cleanup conversion primops (#19026) · d8dc0f96
      Sylvain Henry authored
      The first change makes the array ones use the proper fixed-size types,
      which also means that just like before, they can be used without
      explicit conversions with the boxed sized types. (Before, it was Int# /
      Word# on both sides, now it is fixed sized on both sides).
      
      For the second change, don't use "extend" or "narrow" in some of the
      user-facing primops names for conversions.
      
        - Names like `narrowInt32#` are misleading when `Int` is 32-bits.
      
        - Names like `extendInt64#` are flat-out wrong when `Int is
          32-bits.
      
        - `narrow{Int,Word}<N>#` however map a type to itself, and so don't
          suffer from this problem. They are left as-is.
      
      These changes are batched together because Alex happend to use the array
      ops. We can only use released versions of Alex at this time, sadly, and
      I don't want to have to have a release thatwon't work for the final GHC
      9.2. So by combining these we get all the changes for Alex done at once.
      
      Bump hackage state in a few places, and also make that workflow slightly
      easier for the future.
      
      Bump minimum Alex version
      
      Bump Cabal, array, bytestring, containers, text, and binary submodules
      d8dc0f96
  4. 14 Feb, 2021 3 commits
  5. 22 Jan, 2021 1 commit
    • John Ericson's avatar
      Add missing fixed-sized primops and constant folding · 0eaf63b6
      John Ericson authored
      - `inversePrimOp` is renamed to `semiInversePrimOp` to indicate the
        given primop is only a right inverse, not left inverse (and
        contra-wise for the primop which we are giving rules for). This
        explains why are new usage is not incorrect.
      
      - The removed `subsumedByPrimOp` calls were actually dead as the match
        on ill-typed code. @hsyl20 pointed this out in
        !4390 (comment 311912),
      
      Metric Decrease:
          T13701
      0eaf63b6
  6. 10 Jan, 2021 1 commit
    • John Ericson's avatar
      Fix `not32Word#` -> `notWord32#` · 4bb957de
      John Ericson authored
      This is is correcting a mistake I unfortunately missed in !4698. But
      that is a recent PR so this fix is not a compatibility hazard with
      released versions of GHC.
      4bb957de
  7. 07 Jan, 2021 1 commit
  8. 03 Jan, 2021 1 commit
  9. 18 Dec, 2020 1 commit
  10. 28 Nov, 2020 1 commit
    • John Ericson's avatar
      Cleanup some primop constructor names · c82bc8e9
      John Ericson authored
      Harmonize the internal (big sum type) names of the native vs fixed-sized
      number primops a bit. (Mainly by renaming the former.)
      
      No user-facing names are changed.
      c82bc8e9
  11. 26 Nov, 2020 1 commit
    • Moritz Angermann's avatar
      [Sized Cmm] properly retain sizes. · be5d74ca
      Moritz Angermann authored
      This replaces all Word<N> = W<N># Word# and Int<N> = I<N># Int#  with
      Word<N> = W<N># Word<N># and Int<N> = I<N># Int<N>#, thus providing us
      with properly sized primitives in the codegenerator instead of pretending
      they are all full machine words.
      
      This came up when implementing darwinpcs for arm64.  The darwinpcs reqires
      us to pack function argugments in excess of registers on the stack.  While
      most procedure call standards (pcs) assume arguments are just passed in
      8 byte slots; and thus the caller does not know the exact signature to make
      the call, darwinpcs requires us to adhere to the prototype, and thus have
      the correct sizes.  If we specify CInt in the FFI call, it should correspond
      to the C int, and not just be Word sized, when it's only half the size.
      
      This does change the expected output of T16402 but the new result is no
      less correct as it eliminates the narrowing (instead of the `and` as was
      previously done).
      
      Bumps the array, bytestring, text, and binary submodules.
      Co-Authored-By: Ben Gamari's avatarBen Gamari <ben@well-typed.com>
      
      Metric Increase:
          T13701
          T14697
      be5d74ca
  12. 20 Nov, 2020 2 commits
    • Sebastian Graf's avatar
      Demand: Interleave usage and strictness demands (#18903) · 0aec78b6
      Sebastian Graf authored
      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
    • Sebastian Graf's avatar
      Fix strictness signatures of `prefetchValue*#` primops · 321d1bd8
      Sebastian Graf authored
      Their strictness signatures said the primops are strict in their first
      argument, which is wrong: Handing it a thunk will prefetch the pointer
      to the thunk, but not evaluate it. Hence not strict.
      
      The regression test `T8256` actually tests for laziness in the first
      argument, so GHC apparently never exploited the strictness signature.
      
      See also #8256 (comment 310867),
      where this came up.
      321d1bd8
  13. 16 Nov, 2020 1 commit
  14. 05 Nov, 2020 1 commit
    • vdukhovni's avatar
      Naming, value types and tests for Addr# atomics · 17d5c518
      vdukhovni authored
      The atomic Exchange and CAS operations on integral types are updated to
      take and return more natural `Word#` rather than `Int#` values.  These
      are bit-block not arithmetic operations, and the sign bit plays no
      special role.
      
      Standardises the names to `atomic<OpType><ValType>Addr#`, where `OpType` is one
      of `Cas` or `Exchange` and `ValType` is presently either `Word` or `Addr`.
      Eventually, variants for `Word32` and `Word64` can and should be added,
      once #11953 and related issues (e.g. #13825) are resolved.
      
      Adds tests for `Addr#` CAS that mirror existing tests for
      `MutableByteArray#`.
      17d5c518
  15. 31 Oct, 2020 1 commit
  16. 07 Oct, 2020 1 commit
    • Andreas Klebinger's avatar
      WinIO: Small changes related to atomic request swaps. · b41f7c38
      Andreas Klebinger authored
      Move the atomix exchange over the Ptr type to an internal module.
      
      Fix a bug caused by us passing ptr-to-ptr instead of ptr to
      atomic exchange.
      
      Renamed interlockedExchange to exchangePtr.
      
      I've also added an cas primitive. It turned out we don't need it
      for WinIO but I'm leaving it in as it's useful for other things.
      b41f7c38
  17. 02 Oct, 2020 1 commit
  18. 09 Sep, 2020 1 commit
    • John Ericson's avatar
      Use "to" instead of "2" in internal names of conversion ops · e5a2899c
      John Ericson authored
      Change the constructors for the primop union, and also names of the
      literal conversion functions.
      
      "2" runs into trouble when we need to do conversions from fixed-width
      types, and end up with thing like "Int642Word".
      
      Only the names internal to GHC are changed, as I don't want to worry
      about breaking changes ATM.
      e5a2899c
  19. 28 Aug, 2020 1 commit
    • Krzysztof Gogolewski's avatar
      Add missing primop documentation (#18454) · c6f50cea
      Krzysztof Gogolewski authored
      - Add three pseudoops to primops.txt.pp, so that Haddock renders
        the documentation
      - Update comments
      - Remove special case for "->" - it's no longer exported from GHC.Prim
      - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no
        longer there after updates to levity polymorphism.
      - Document GHC.Prim
      - Remove the comment that lazy is levity-polymorphic.
        As far as I can tell, it never was: in 80e39963,
        only the unfolding was given an open type variable.
      - Remove haddock hack in GHC.Magic - no longer neccessary after
        adding realWorld# to primops.txt.pp.
      c6f50cea
  20. 26 Aug, 2020 1 commit
    • Krzysztof Gogolewski's avatar
      primops: Remove Monadic and Dyadic categories · 770100e0
      Krzysztof Gogolewski authored
      There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp.
      
      The compiler does not treat Monadic and Dyadic in any special way,
      we can just replace them with GenPrimOp.
      
      Compare is still used in isComparisonPrimOp.
      770100e0
  21. 23 Jul, 2020 1 commit
  22. 15 Jul, 2020 1 commit
  23. 28 Jun, 2020 1 commit
  24. 27 Jun, 2020 1 commit
    • Sylvain Henry's avatar
      Fix ghc-bignum exceptions · 1b3d13b6
      Sylvain Henry authored
      We must ensure that exceptions are not simplified. Previously we used:
      
         case raiseDivZero of
            _ -> 0## -- dummyValue
      
      But it was wrong because the evaluation of `raiseDivZero` was removed and
      the dummy value was directly returned. See new Note [ghc-bignum exceptions].
      
      I've also removed the exception triggering primops which were fragile.
      We don't need them to be primops, we can have them exported by ghc-prim.
      
      I've also added a test for #18359 which triggered this patch.
      1b3d13b6
  25. 17 Jun, 2020 1 commit
    • Krzysztof Gogolewski's avatar
      Linear types (#15981) · 40fa237e
      Krzysztof Gogolewski authored
      This is the first step towards implementation of the linear types proposal
      (https://github.com/ghc-proposals/ghc-proposals/pull/111).
      
      It features
      
      * A language extension -XLinearTypes
      * Syntax for linear functions in the surface language
      * Linearity checking in Core Lint, enabled with -dlinear-core-lint
      * Core-to-core passes are mostly compatible with linearity
      * Fields in a data type can be linear or unrestricted; linear fields
        have multiplicity-polymorphic constructors.
        If -XLinearTypes is disabled, the GADT syntax defaults to linear fields
      
      The following items are not yet supported:
      
      * a # m -> b syntax (only prefix FUN is supported for now)
      * Full multiplicity inference (multiplicities are really only checked)
      * Decent linearity error messages
      * Linear let, where, and case expressions in the surface language
        (each of these currently introduce the unrestricted variant)
      * Multiplicity-parametric fields
      * Syntax for annotating lambda-bound or let-bound with a multiplicity
      * Syntax for non-linear/multiple-field-multiplicity records
      * Linear projections for records with a single linear field
      * Linear pattern synonyms
      * Multiplicity coercions (test LinearPolyType)
      
      A high-level description can be found at
      https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation
      Following the link above you will find a description of the changes made to Core.
      This commit has been authored by
      
      * Richard Eisenberg
      * Krzysztof Gogolewski
      * Matthew Pickering
      * Arnaud Spiwack
      
      With contributions from:
      
      * Mark Barbone
      * Alexander Vershilov
      
      Updates haddock submodule.
      40fa237e
  26. 14 Jun, 2020 1 commit
  27. 10 Jun, 2020 1 commit
  28. 21 May, 2020 1 commit
    • Alexey Kuleshevich's avatar
      Fix wording in primops documentation to reflect the correct reasoning: · 1b508a9e
      Alexey Kuleshevich authored
      * Besides resizing functions, shrinking ones also mutate the
        size of a mutable array and because of those two `sizeofMutabeByteArray`
        and `sizeofSmallMutableArray` are now deprecated
      * Change reference in documentation to the newer functions `getSizeof*`
        instead of `sizeof*` for shrinking functions
      * Fix incorrect mention of "byte" instead of "small"
      1b508a9e
  29. 15 May, 2020 1 commit
    • Sebastian Graf's avatar
      DmdAnal: Improve handling of precise exceptions · 9bd20e83
      Sebastian Graf authored
      This patch does two things: Fix possible unsoundness in what was called
      the "IO hack" and implement part 2.1 of the "fixing precise exceptions"
      plan in
      https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions,
      which, in combination with !2956, supersedes !3014 and !2525.
      
      **IO hack**
      
      The "IO hack" (which is a fallback to preserve precise exceptions
      semantics and thus soundness, rather than some smart thing that
      increases precision) is called `exprMayThrowPreciseException` now.
      I came up with two testcases exemplifying possible unsoundness (if
      twisted enough) in the old approach:
      
      - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting
                   to manual state token threading and direct use of primops.
                   More details below.
      - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have
                   Nested CPR. Not currently relevant, as we don't have Nested
                   CPR yet.
      - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI
                   calls.
      
      Basically, the IO hack assumed that precise exceptions can only be
      thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I
      couldn't come up with a program using the `IO` abstraction that violates
      this assumption. But it's easy to do so via manual state token threading
      and direct use of primops, see `T13380d`. Also similar code might be
      generated by Nested CPR in the (hopefully not too) distant future, see
      `T13380e`. Hence, we now have a more careful test in `forcesRealWorld`
      that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR).
      
      **Precise exceptions**
      
      In #13380 and #17676 we saw that we didn't preserve precise exception
      semantics in demand analysis. We fixed that with minimal changes in
      !2956, but that was terribly unprincipled.
      
      That unprincipledness resulted in a loss of precision, which is tracked
      by these new test cases:
      
      - `T13380b`: Regression in dead code elimination, because !2956 was too
                   syntactic about `raiseIO#`
      - `T13380c`: No need to apply the "IO hack" when the IO action may not
                   throw a precise exception (and the existing IO hack doesn't
                   detect that)
      
      Fixing both issues in !3014 turned out to be too complicated and had
      the potential to regress in the future. Hence we decided to only fix
      `T13380b` and augment the `Divergence` lattice with a new middle-layer
      element, `ExnOrDiv`, which means either `Diverges` (, throws an
      imprecise exception) or throws a *precise* exception.
      
      See the wiki page on Step 2.1 for more implementational details:
      https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21
      9bd20e83
  30. 18 Apr, 2020 1 commit
    • Sylvain Henry's avatar
      Modules (#13009) · 15312bbb
      Sylvain Henry authored
      * SysTools
      * Parser
      * GHC.Builtin
      * GHC.Iface.Recomp
      * Settings
      
      Update Haddock submodule
      
      Metric Decrease:
          Naperian
          parsing001
      15312bbb
  31. 02 Apr, 2020 1 commit
  32. 18 Mar, 2020 1 commit
  33. 12 Feb, 2020 1 commit
    • Sebastian Graf's avatar
      Separate CPR analysis from the Demand analyser · 059c3c9d
      Sebastian Graf authored
      The reasons for that can be found in the wiki:
      https://gitlab.haskell.org/ghc/ghc/wikis/nested-cpr/split-off-cpr
      
      We now run CPR after demand analysis (except for after the final demand
      analysis run just before code gen). CPR got its own dump flags
      (`-ddump-cpr-anal`, `-ddump-cpr-signatures`), but not its own flag to
      activate/deactivate. It will run with `-fstrictness`/`-fworker-wrapper`.
      
      As explained on the wiki page, this step is necessary for a sane Nested
      CPR analysis. And it has quite positive impact on compiler performance:
      
      Metric Decrease:
          T9233
          T9675
          T9961
          T15263
      059c3c9d
  34. 11 Feb, 2020 1 commit
  35. 06 Jan, 2020 1 commit
  36. 11 Dec, 2019 1 commit