1. 05 Oct, 2020 1 commit
    • Sebastian Graf's avatar
      Inline `integerDecodeDouble#` and constant-fold `decodeDouble_Int64#` instead · bc5de347
      Sebastian Graf authored
      Currently, `integerDecodeDouble#` is known-key so that it can be
      recognised in constant folding. But that is very brittle and doesn't
      survive worker/wrapper, which we even do for
      `NOINLINE` things since #13143.
      Also it is a trade-off: The implementation of `integerDecodeDouble#`
      allocates an `Integer` box that never cancels aways if we don't inline
      it.
      
      Hence we recognise the `decodeDouble_Int64#` primop instead in constant
      folding, so that we can inline `integerDecodeDouble#`. As a result,
      `integerDecodeDouble#` no longer needs to be known-key.
      
      While doing so, I realised that we don't constant-fold
      `decodeFloat_Int#` either, so I also added a RULE for it.
      
      `integerDecodeDouble` is dead, so I deleted it.
      
      Part of #18092. This improves the 32-bit `realToFrac`/`toRational`:
      
      Metric Decrease:
          T10359
      bc5de347
  2. 02 Oct, 2020 1 commit
  3. 01 Oct, 2020 1 commit
  4. 02 Sep, 2020 1 commit
  5. 22 Aug, 2020 1 commit
    • Aditya Gupta's avatar
      mkUnique refactoring (#18362) · e67ae884
      Aditya Gupta authored
      Move uniqFromMask from Unique.Supply to Unique.
      Move the the functions that call mkUnique from Unique to Builtin.Uniques
      e67ae884
  6. 23 Jul, 2020 1 commit
  7. 15 Jul, 2020 1 commit
  8. 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
  9. 17 Jun, 2020 2 commits
    • Sylvain Henry's avatar
      Update compiler · 96aa5787
      Sylvain Henry authored
      Thanks to ghc-bignum, the compiler can be simplified:
      
      * Types and constructors of Integer and Natural can be wired-in. It
        means that we don't have to query them from interfaces. It also means
        that numeric literals don't have to carry their type with them.
      
      * The same code is used whatever ghc-bignum backend is enabled. In
        particular, conversion of bignum literals into final Core expressions
        is now much more straightforward. Bignum closure inspection too.
      
      * GHC itself doesn't depend on any integer-* package anymore
      
      * The `integerLibrary` setting is gone.
      96aa5787
    • 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
      * S...
      40fa237e
  10. 13 Jun, 2020 2 commits
    • Sylvain Henry's avatar
      Rename Package into Unit (2) · 653d17bd
      Sylvain Henry authored
      * rename PackageState into UnitState
      * rename findWiredInPackages into findWiredInUnits
      * rename lookupModuleInAll[Packages,Units]
      * etc.
      653d17bd
    • Sylvain Henry's avatar
      Enhance UnitId use · e7272d53
      Sylvain Henry authored
      * use UnitId instead of String to identify wired-in units
      * use UnitId instead of Unit in the backend (Unit are only use by
        Backpack to produce type-checked interfaces, not real code)
      * rename lookup functions for consistency
      * documentation
      e7272d53
  11. 10 Jun, 2020 1 commit
    • Simon Peyton Jones's avatar
      Implement cast worker/wrapper properly · 6d49d5be
      Simon Peyton Jones authored
      The cast worker/wrapper transformation transforms
         x = e |> co
      into
         y = e
         x = y |> co
      
      This is done by the simplifier, but we were being
      careless about transferring IdInfo from x to y,
      and about what to do if x is a NOINLNE function.
      This resulted in a series of bugs:
           #17673, #18093, #18078.
      
      This patch fixes all that:
      
      * Main change is in GHC.Core.Opt.Simplify, and
        the new prepareBinding function, which does this
        cast worker/wrapper transform.
        See Note [Cast worker/wrappers].
      
      * There is quite a bit of refactoring around
        prepareRhs, makeTrivial etc.  It's nicer now.
      
      * Some wrappers from strictness and cast w/w, notably those for
        a function with a NOINLINE, should inline very late. There
        wasn't really a mechanism for that, which was an existing bug
        really; so I invented a new finalPhase = Phase (-1).  It's used
        for all simplifier runs after the user-visible phase 2,1,0 have
        run.  (No new runs of the simplifier are introduced thereby.)
      
        See new Note [Compiler phases] in GHC.Types.Basic;
        the main changes are in GHC.Core.Opt.Driver
      
      * Doing this made me trip over two places where the AnonArgFlag on a
        FunTy was being lost so we could end up with (Num a -> ty)
        rather than (Num a => ty)
          - In coercionLKind/coercionRKind
          - In contHoleType in the Simplifier
      
        I fixed the former by defining mkFunctionType and using it in
        coercionLKind/RKind.
      
        I could have done the same for the latter, but the information
        is almost to hand.  So I fixed the latter by
          - adding sc_hole_ty to ApplyToVal (like ApplyToTy),
          - adding as_hole_ty to ValArg (like TyArg)
          - adding sc_fun_ty to StrictArg
        Turned out I could then remove ai_type from ArgInfo.  This is
        just moving the deck chairs around, but it worked out nicely.
      
        See the new Note [AnonArgFlag] in GHC.Types.Var
      
      * When looking at the 'arity decrease' thing (#18093) I discovered
        that stable unfoldings had a much lower arity than the actual
        optimised function.  That's what led to the arity-decrease
        message.  Simple solution: eta-expand.
      
        It's described in Note [Eta-expand stable unfoldings]
        in GHC.Core.Opt.Simplify
      
      * I also discovered that unsafeCoerce wasn't being inlined if
        the context was boring.  So (\x. f (unsafeCoerce x)) would
        create a thunk -- yikes!  I fixed that by making inlineBoringOK
        a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold.
      
        I also found that unsafeCoerceName was unused, so I removed it.
      
      I made a test case for #18078, and a very similar one for #17673.
      
      The net effect of all this on nofib is very modest, but positive:
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
      --------------------------------------------------------------------------------
                 anna          -0.4%     -0.1%     -3.1%     -3.1%      0.0%
       fannkuch-redux          -0.4%     -0.3%     -0.1%     -0.1%      0.0%
             maillist          -0.4%     -0.1%     -7.8%     -1.0%    -14.3%
            primetest          -0.4%    -15.6%     -7.1%     -6.6%      0.0%
      --------------------------------------------------------------------------------
                  Min          -0.9%    -15.6%    -13.3%    -14.2%    -14.3%
                  Max          -0.3%      0.0%    +12.1%    +12.4%      0.0%
       Geometric Mean          -0.4%     -0.2%     -2.3%     -2.2%     -0.1%
      
      All following metric decreases are compile-time allocation decreases
      between -1% and -3%:
      
      Metric Decrease:
        T5631
        T13701
        T14697
        T15164
      6d49d5be
  12. 05 Jun, 2020 1 commit
    • Simon Peyton Jones's avatar
      Simple subsumption · 2b792fac
      Simon Peyton Jones authored
      This patch simplifies GHC to use simple subsumption.
        Ticket #17775
      
      Implements GHC proposal #287
         https://github.com/ghc-proposals/ghc-proposals/blob/master/
         proposals/0287-simplify-subsumption.rst
      
      All the motivation is described there; I will not repeat it here.
      The implementation payload:
       * tcSubType and friends become noticably simpler, because it no
         longer uses eta-expansion when checking subsumption.
       * No deeplyInstantiate or deeplySkolemise
      
      That in turn means that some tests fail, by design; they can all
      be fixed by eta expansion.  There is a list of such changes below.
      
      Implementing the patch led me into a variety of sticky corners, so
      the patch includes several othe changes, some quite significant:
      
      * I made String wired-in, so that
          "foo" :: String   rather than
          "foo" :: [Char]
        This improves error messages, and fixes #15679
      
      * The pattern match checker relies on knowing about in-scope equality
        constraints, andd adds them to the desugarer's environment u...
      2b792fac
  13. 29 May, 2020 1 commit
    • Andreas Klebinger's avatar
      Fix "build/elem" RULE. · f10d11fa
      Andreas Klebinger authored
      An redundant constraint prevented the rule from matching.
      
      Fixing this allows a call to elem on a known list to be translated
      into a series of equality checks, and eventually a simple case
      expression.
      
      Surprisingly this seems to regress elem for strings. To avoid
      this we now also allow foldrCString to inline and add an UTF8
      variant. This results in elem being compiled to a tight
      non-allocating loop over the primitive string literal which
      performs a linear search.
      
      In the process this commit adds UTF8 variants for some of the
      functions in GHC.CString. This is required to make this work for
      both ASCII and UTF8 strings.
      
      There are also small tweaks to the CString related rules.
      We now allow ourselfes the luxury to compare the folding function
      via eqExpr, which helps to ensure the rule fires before we inline
      foldrCString*. Together with a few changes to allow matching on both
      the UTF8 and ASCII variants of the CString functions.
      f10d11fa
  14. 24 May, 2020 1 commit
    • Ryan Scott's avatar
      Add orderingTyCon to wiredInTyCons (#18185) · 66bd24d1
      Ryan Scott authored
      `Ordering` needs to be wired in for use in the built-in `CmpNat` and
      `CmpSymbol` type families, but somehow it was never added to the list
      of `wiredInTyCons`, leading to the various oddities observed
      in #18185. Easily fixed by moving `orderingTyCon` from
      `basicKnownKeyNames` to `wiredInTyCons`.
      
      Fixes #18185.
      66bd24d1
  15. 23 May, 2020 1 commit
    • Andrew Martin's avatar
      Implement cstringLength# and FinalPtr · 49301ad6
      Andrew Martin authored
      This function and its accompanying rule resolve issue #5218.
      A future PR to the bytestring library will make the internal
      Data.ByteString.Internal.unsafePackAddress compute string length
      with cstringLength#. This will improve the status quo because it is
      eligible for constant folding.
      
      Additionally, introduce a new data constructor to ForeignPtrContents
      named FinalPtr. This additional data constructor, when used in the
      IsString instance for ByteString, leads to more Core-to-Core
      optimization opportunities, fewer runtime allocations, and smaller
      binaries.
      
      Also, this commit re-exports all the functions from GHC.CString
      (including cstringLength#) in GHC.Exts. It also adds a new test
      driver. This test driver is used to perform substring matches on Core
      that is dumped after all the simplifier passes. In this commit, it is
      used to check that constant folding of cstringLength# works.
      49301ad6
  16. 10 May, 2020 1 commit
  17. 30 Apr, 2020 1 commit
  18. 28 Apr, 2020 1 commit
    • Ryan Scott's avatar
      Make boxed 1-tuples have known keys · 518a63d4
      Ryan Scott authored
      Unlike other tuples, which use special syntax and are "known" by way
      of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not
      use special syntax. Therefore, in order to make sure that the
      internals of GHC are aware of the `data Unit a = Unit a` definition
      in `GHC.Tuple`, we give `Unit` known keys. For the full details, see
      `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)`
      in `GHC.Builtin.Types`.
      
      Fixes #18097.
      518a63d4
  19. 26 Apr, 2020 1 commit
  20. 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
  21. 07 Apr, 2020 1 commit
  22. 29 Mar, 2020 1 commit
  23. 02 Mar, 2020 1 commit
    • Krzysztof Gogolewski's avatar
      Remove dead code · 3cf7303b
      Krzysztof Gogolewski authored
      * The names in PrelName and THNames are no longer used
        since TH merged types and kinds, Typeable is kind-polymorphic,
        .net support was removed
      * unqualQuasiQuote no longer used since 6f8ff0bb
      3cf7303b
  24. 22 Feb, 2020 1 commit
  25. 21 Feb, 2020 1 commit
    • Simon Peyton Jones's avatar
      Re-implement unsafe coercions in terms of unsafe equality proofs · 74ad75e8
      Simon Peyton Jones authored
      (Commit message written by Omer, most of the code is written by Simon
      and Richard)
      
      See Note [Implementing unsafeCoerce] for how unsafe equality proofs and
      the new unsafeCoerce# are implemented.
      
      New notes added:
      
      - [Checking for levity polymorphism] in CoreLint.hs
      - [Implementing unsafeCoerce] in base/Unsafe/Coerce.hs
      - [Patching magic definitions] in Desugar.hs
      - [Wiring in unsafeCoerce#] in Desugar.hs
      
      Only breaking change in this patch is unsafeCoerce# is not exported from
      GHC.Exts, instead of GHC.Prim.
      
      Fixes #17443
      Fixes #16893
      
      NoFib
      -----
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs    Instrs     Reads    Writes
      --------------------------------------------------------------------------------
                   CS          -0.1%      0.0%     -0.0%     -0.0%     -0.0%
                  CSD          -0.1%      0.0%     -0.0%     -0.0%     -0.0%
                   FS          -...
      74ad75e8
  26. 08 Feb, 2020 1 commit
  27. 27 Jan, 2020 1 commit
  28. 06 Jan, 2020 1 commit
  29. 04 Dec, 2019 1 commit
    • Ben Gamari's avatar
      Simplify uniqAway · 78b67ad0
      Ben Gamari authored
      This does two things:
      
       * Eliminate all uses of Unique.deriveUnique, which was quite easy to
         mis-use and extremely subtle.
      
       * Rename the previous "derived unique" notion to "local unique". This
         is possible because the only places where `uniqAway` can be safely
         used are those where local uniqueness (with respect to some
         InScopeSet) is sufficient.
      
       * Rework the implementation of VarEnv.uniqAway, as discussed in #17462.
         This should make the operation significantly more efficient than its
         previous iterative implementation..
      
      Metric Decrease:
          T9872c
          T12227
          T9233
          T14683
          T5030
          T12545
          hie002
      
      Metric Increase:
          T9961
      78b67ad0
  30. 25 Sep, 2019 1 commit
  31. 17 Jul, 2019 1 commit
    • John Ericson's avatar
      Create {Int,Word}32Rep · 0a9b77b8
      John Ericson authored
      This prepares the way for making Int32# and Word32# the actual size they
      claim to be.
      
      Updates binary submodule for (de)serializing the new runtime reps.
      0a9b77b8
  32. 26 Jun, 2019 1 commit
    • Ben Gamari's avatar
      Don't eta-expand unsaturated primops · cac8dc9f
      Ben Gamari authored
      Previously, as described in Note [Primop wrappers], `hasNoBinding` would
      return False in the case of `PrimOpId`s. This would result in eta
      expansion of unsaturated primop applications during CorePrep. Not only
      did this expansion result in unnecessary allocations, but it also meant
      lead to rather nasty inconsistencies between the CAFfy-ness
      determinations made by TidyPgm and CorePrep.
      
      This fixes #16846.
      cac8dc9f
  33. 22 Jun, 2019 1 commit
    • Ben Gamari's avatar
      ghci: Don't rely on resolution of System.IO to base module · 655c6e26
      Ben Gamari authored
      Previously we would hackily evaluate a textual code snippet to compute
      actions to disable I/O buffering and flush the stdout/stderr handles.
      This broke in a number of ways (#15336, #16563).
      
      Instead we now ship a module (`GHC.GHCi.Helpers`) with `base` containing
      the needed actions. We can then easily refer to these via `Orig` names.
      655c6e26
  34. 22 Mar, 2019 1 commit
  35. 15 Feb, 2019 1 commit
  36. 08 Feb, 2019 1 commit
    • Ömer Sinan Ağacan's avatar
      Remove a few undefined prel names · 0a4bbb52
      Ömer Sinan Ağacan authored
      - breakpointAuto
      - breakpointJump
      - breakpointCondJump
      - breakpointAutoJump
      
      These Ids are never defined, but there were definitions about those in
      PrelNames. Those are now removed.
      0a4bbb52
  37. 17 Nov, 2018 1 commit
  38. 02 Nov, 2018 1 commit
    • Michal Terepeta's avatar
      Add Int8# and Word8# · 2c959a18
      Michal Terepeta authored
      This is the first step of implementing:
      https://github.com/ghc-proposals/ghc-proposals/pull/74
      
      
      
      The main highlights/changes:
      
          primops.txt.pp gets two new sections for two new primitive types for
          signed and unsigned 8-bit integers (Int8# and Word8 respectively) along
          with basic arithmetic and comparison operations. PrimRep/RuntimeRep get
          two new constructors for them. All of the primops translate into the
          existing MachOPs.
      
          For CmmCalls the codegen will now zero-extend the values at call
          site (so that they can be moved to the right register) and then truncate
          them back their original width.
      
          x86 native codegen needed some updates, since it wasn't able to deal
          with the new widths, but all the changes are quite localized. LLVM
          backend seems to just work.
      
      This is the second attempt at merging this, after the first attempt in
      D4475 had to be backed out due to regressions on i386.
      
      Bumps binary submodule.
      Signed-off-by: Michal Terepeta's avatarMichal Terepeta <michal.terepeta@gmail.com>
      
      Test Plan: ./validate (on both x86-{32,64})
      
      Reviewers: bgamari, hvr, goldfire, simonmar
      
      Subscribers: rwbarton, carter
      
      Differential Revision: https://phabricator.haskell.org/D5258
      2c959a18