Skip to content
Snippets Groups Projects
  1. May 24, 2024
    • Cheng Shao's avatar
      compiler: avoid saving foreign call target to local when there are no caller-save GlobalRegs · 8dd8a076
      Cheng Shao authored and Marge Bot's avatar Marge Bot committed
      This patch makes the STG->Cmm backend avoid saving foreign call target
      to local when there are no caller-save GlobalRegs.
      
      Since 321941a8, when we lower a
      foreign call, we unconditionally save the foreign call target to a
      temporary local first, then rely on cmmSink to clean it up later,
      which only happens with -fcmm-sink (implied by -O) and not in
      unoptimized code.
      
      And this is troublesome for the wasm backend NCG, which needs to infer
      a foreign call target symbol's type signature from the Cmm call site.
      Previously, the NCG has been emitting incorrect type signatures for
      unoptimized code, which happens to work with `wasm-ld` most of the
      time, but this is never future-proof against upstream toolchain
      updates, and it causes horrible breakages when LTO objects are
      included in linker input. Hence this patch.
      8dd8a076
  2. Apr 04, 2023
  3. Jan 31, 2023
    • sheaf's avatar
      Cmm: track the type of global registers · 5618fc21
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch tracks the type of Cmm global registers. This is needed
      in order to lint uses of polymorphic registers, such as SIMD vector
      registers that can be used both for floating-point and integer values.
      
      This changes allows us to refactor VanillaReg to not store VGcPtr,
      as that information is instead stored in the type of the usage of the
      register.
      
      Fixes #22297
      5618fc21
  4. Jan 18, 2023
    • Luite Stegeman's avatar
      Add PrimCallConv support to GHCi · b4c14c4b
      Luite Stegeman authored and Marge Bot's avatar Marge Bot committed
      This adds support for calling Cmm code from bytecode using the native
      calling convention, allowing modules that use `foreign import prim`
      to be loaded and debugged in GHCi.
      
      This patch introduces a new `PRIMCALL` bytecode instruction and
      a helper stack frame `stg_primcall`. The code is based on the
      existing functionality for dealing with unboxed tuples in bytecode,
      which has been generalised to handle arbitrary calls.
      
      Fixes #22051
      b4c14c4b
  5. Feb 08, 2022
  6. Feb 04, 2022
  7. Feb 01, 2022
  8. Jan 26, 2022
    • sheaf's avatar
      Levity-polymorphic arrays and mutable variables · e471a680
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch makes the following types levity-polymorphic in their
      last argument:
      
        - Array# a, SmallArray# a, Weak# b, StablePtr# a, StableName# a
      
        - MutableArray# s a, SmallMutableArray# s a,
          MutVar# s a, TVar# s a, MVar# s a, IOPort# s a
      
      The corresponding primops are also made levity-polymorphic, e.g.
      `newArray#`, `readArray#`, `writeMutVar#`, `writeIOPort#`, etc.
      
      Additionally, exception handling functions such as `catch#`, `raise#`,
      `maskAsyncExceptions#`,... are made levity/representation-polymorphic.
      
      Now that Array# and MutableArray# also work with unlifted types,
      we can simply re-define ArrayArray# and MutableArrayArray# in terms
      of them. This means that ArrayArray# and MutableArrayArray# are no
      longer primitive types, but simply unlifted newtypes around Array# and
      MutableArrayArray#.
      
      This completes the implementation of the Pointer Rep proposal
        https://github.com/ghc-proposals/ghc-proposals/pull/203
      
      Fixes #20911
      
      -------------------------
      Metric Increase:
          T12545
      -------------------------
      
      -------------------------
      Metric Decrease:
          T12545
      -------------------------
      e471a680
  9. Jun 05, 2021
    • Moritz Angermann's avatar
      Adds AArch64 Native Code Generator · 3b1aa7db
      Moritz Angermann authored and Marge Bot's avatar Marge Bot committed
      In which we add a new code generator to the Glasgow Haskell
      Compiler. This codegen supports ELF and Mach-O targets, thus covering
      Linux, macOS, and BSDs in principle.  It was tested only on macOS and
      Linux.  The NCG follows a similar structure as the other native code
      generators we already have, and should therfore be realtively easy to
      follow.
      
      It supports most of the features required for a proper native code
      generator, but does not claim to be perfect or fully optimised.  There
      are still opportunities for optimisations.
      
      Metric Decrease:
          ManyAlternatives
          ManyConstructors
          MultiLayerModules
          PmSeriesG
          PmSeriesS
          PmSeriesT
          PmSeriesV
          T10421
          T10421a
          T10858
          T11195
          T11276
          T11303b
          T11374
          T11822
          T12227
          T12545
          T12707
          T13035
          T13253
          T13253-spj
          T13379
          T13701
          T13719
          T14683
          T14697
          T15164
          T15630
          T16577
          T17096
          T17516
          T17836
          T17836b
          T17977
          T17977b
          T18140
          T18282
          T18304
          T18478
          T18698a
          T18698b
          T18923
          T1969
          T3064
          T5030
          T5321FD
          T5321Fun
          T5631
          T5642
          T5837
          T783
          T9198
          T9233
          T9630
          T9872d
          T9961
          WWRec
      Metric Increase:
          T4801
      3b1aa7db
  10. May 29, 2021
  11. Mar 27, 2021
    • Sebastian Graf's avatar
      Rubbish literals for all representations (#18983) · 57d21e6a
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      This patch cleans up the complexity around WW's `mk_absent_let` by
      broadening the scope of `LitRubbish`. Rubbish literals now store the
      `PrimRep` they represent and are ultimately lowered in Cmm.
      This in turn allows absent literals of `VecRep` or `VoidRep`. The latter
      allows absent literals for unlifted coercions, as requested in #18983.
      
      I took the liberty to rewrite and clean up `Note [Absent fillers]` and
      `Note [Rubbish values]` to account for the new implementation and to
      make them more orthogonal in their description.
      
      I didn't add a new regression test, as `T18982` already contains the
      test in the ticket and its test output changes as expected.
      
      Fixes #18983.
      57d21e6a
  12. Feb 06, 2021
  13. Oct 09, 2020
    • Sylvain Henry's avatar
      Use UnitId in the backend instead of Unit · 386c2d7f
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      In Cmm we can only have real units identified with an UnitId.  Other
      units (on-the-fly instantiated units and holes) are only used in
      type-checking backpack sessions that don't produce Cmm.
      386c2d7f
  14. Aug 12, 2020
    • Sylvain Henry's avatar
      DynFlags: disentangle Outputable · accbc242
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      - put panic related functions into GHC.Utils.Panic
      - put trace related functions using DynFlags in GHC.Driver.Ppr
      
      One step closer making Outputable fully independent of DynFlags.
      
      Bump haddock submodule
      accbc242
  15. Aug 07, 2020
  16. Jul 25, 2020
    • Sylvain Henry's avatar
      Remove platform constant wrappers · 9dfeca6c
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      Platform constant wrappers took a DynFlags parameter, hence implicitly
      used the target platform constants. We removed them to allow support
      for several platforms at once (#14335) and to avoid having to pass
      the full DynFlags to every function (#17957).
      
      Metric Decrease:
         T4801
      9dfeca6c
  17. Jul 03, 2020
    • Sylvain Henry's avatar
      Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function · f08d6316
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      SCC profiling was enabled in a convoluted way: if WayProf was enabled,
      Opt_SccProfilingOn general flag was set (in
      `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in
      various places.
      
      There is no need to go via general flags, so this patch defines a
      `sccProfilingEnabled :: DynFlags -> Bool` helper function that just
      checks whether WayProf is enabled.
      f08d6316
  18. Jun 24, 2020
    • Sylvain Henry's avatar
      Cmm: introduce SAVE_REGS/RESTORE_REGS · 7750bd45
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      We don't want to save both Fn and Dn register sets on x86-64 as they are
      aliased to the same arch register (XMMn).
      
      Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]`
      which makes a set of Cmm registers alive so that they cover all arch
      registers used to pass parameter, we could have Fn, Dn and XMMn alive at
      the same time. It made the LLVM code generator choke (see #17920).
      
      Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of
      registers.
      7750bd45
  19. Jun 14, 2020
    • Peter Trommler's avatar
      FFI: Fix pass small ints in foreign call wrappers · 01f7052c
      Peter Trommler authored and Marge Bot's avatar Marge Bot committed
      The Haskell calling convention requires integer parameters smaller
      than wordsize to be promoted to wordsize (where the upper bits are
      don't care). To access such small integer parameter read a word from
      the parameter array and then cast that word to the small integer
      target type.
      
      Fixes #15933
      01f7052c
  20. Apr 26, 2020
  21. Apr 18, 2020
    • 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
  22. Mar 29, 2020
  23. Mar 19, 2020
  24. Mar 17, 2020
  25. Feb 22, 2020
  26. Feb 12, 2020
  27. Jan 25, 2020
  28. Dec 31, 2019
  29. Sep 09, 2019
    • Sylvain Henry's avatar
      Module hierarchy: StgToCmm (#13009) · 447864a9
      Sylvain Henry authored
      Add StgToCmm module hierarchy. Platform modules that are used in several
      other places (NCG, LLVM codegen, Cmm transformations) are put into
      GHC.Platform.
      447864a9
  30. Jun 14, 2019
    • Andrew Martin's avatar
      Implement the -XUnliftedNewtypes extension. · effdd948
      Andrew Martin authored and Marge Bot's avatar Marge Bot committed
      GHC Proposal: 0013-unlifted-newtypes.rst
      Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/98
      
      
      Issues: #15219, #1311, #13595, #15883
      Implementation Details:
        Note [Implementation of UnliftedNewtypes]
        Note [Unifying data family kinds]
        Note [Compulsory newtype unfolding]
      
      This patch introduces the -XUnliftedNewtypes extension. When this
      extension is enabled, GHC drops the restriction that the field in
      a newtype must be of kind (TYPE 'LiftedRep). This allows types
      like Int# and ByteArray# to be used in a newtype. Additionally,
      coerce is made levity-polymorphic so that it can be used with
      newtypes over unlifted types.
      
      The bulk of the changes are in TcTyClsDecls.hs. With -XUnliftedNewtypes,
      getInitialKind is more liberal, introducing a unification variable to
      return the kind (TYPE r0) rather than just returning (TYPE 'LiftedRep).
      When kind-checking a data constructor with kcConDecl, we attempt to
      unify the kind of a newtype with the kind of its field's type. When
      typechecking a data declaration with tcTyClDecl, we again perform a
      unification. See the implementation note for more on this.
      
      Co-authored-by: Richard Eisenberg's avatarRichard Eisenberg <rae@richarde.dev>
      effdd948
  31. Jun 08, 2019
  32. Jun 04, 2019
    • Andrew Martin's avatar
      Use a better strategy for determining the offset applied to foreign function... · db78ac6f
      Andrew Martin authored and Marge Bot's avatar Marge Bot committed
      Use a better strategy for determining the offset applied to foreign function arguments that have an unlifted boxed type. We used to use the type of the argument. We now use the type of the foreign function. Add a test to confirm that the roundtrip conversion between an unlifted boxed type and Any is sound in the presence of a foreign function call.
      db78ac6f
  33. Mar 19, 2018
    • Ben Gamari's avatar
      Improve accuracy of get/setAllocationCounter · 20cbb016
      Ben Gamari authored and Ben Gamari's avatar Ben Gamari committed
      Summary:
      get/setAllocationCounter didn't take into account allocations in the
      current block. This was known at the time, but it turns out to be
      important to have more accuracy when using these in a fine-grained
      way.
      
      Test Plan:
      New unit test to test incrementally larger allocaitons.  Before I got
      results like this:
      
      ```
      +0
      +0
      +0
      +0
      +0
      +4096
      +0
      +0
      +0
      +0
      +0
      +4064
      +0
      +0
      +4088
      +4056
      +0
      +0
      +0
      +4088
      +4096
      +4056
      +4096
      ```
      
      Notice how the results aren't always monotonically increasing.  After
      this patch:
      
      ```
      +344
      +416
      +488
      +560
      +632
      +704
      +776
      +848
      +920
      +992
      +1064
      +1136
      +1208
      +1280
      +1352
      +1424
      +1496
      +1568
      +1640
      +1712
      +1784
      +1856
      +1928
      +2000
      +2072
      +2144
      ```
      
      Reviewers: hvr, erikd, simonmar, jrtc27, trommler
      
      Reviewed By: simonmar
      
      Subscribers: trommler, jrtc27, rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4363
      20cbb016
    • Michal Terepeta's avatar
      Get rid of more CPP in cmm/ and codeGen/ · 0db0e46c
      Michal Terepeta authored and Ben Gamari's avatar Ben Gamari committed
      
      This removes a bunch of unnecessary includes of `HsVersions.h` along
      with unnecessary CPP (e.g., due to checking for DEBUG which can be
      achieved by looking at `debugIsOn`)
      
      Signed-off-by: default avatarMichal Terepeta <michal.terepeta@gmail.com>
      
      Test Plan: ./validate
      
      Reviewers: bgamari, simonmar
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4462
      0db0e46c
  34. Feb 18, 2018
  35. Jan 18, 2018
  36. Jan 08, 2018
    • Simon Marlow's avatar
      Improve accuracy of get/setAllocationCounter · a1a689dd
      Simon Marlow authored
      Summary:
      get/setAllocationCounter didn't take into account allocations in the
      current block. This was known at the time, but it turns out to be
      important to have more accuracy when using these in a fine-grained
      way.
      
      Test Plan:
      New unit test to test incrementally larger allocaitons.  Before I got
      results like this:
      
      ```
      +0
      +0
      +0
      +0
      +0
      +4096
      +0
      +0
      +0
      +0
      +0
      +4064
      +0
      +0
      +4088
      +4056
      +0
      +0
      +0
      +4088
      +4096
      +4056
      +4096
      ```
      
      Notice how the results aren't always monotonically increasing.  After
      this patch:
      
      ```
      +344
      +416
      +488
      +560
      +632
      +704
      +776
      +848
      +920
      +992
      +1064
      +1136
      +1208
      +1280
      +1352
      +1424
      +1496
      +1568
      +1640
      +1712
      +1784
      +1856
      +1928
      +2000
      +2072
      +2144
      ```
      
      Reviewers: niteria, bgamari, hvr, erikd
      
      Subscribers: rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4288
      a1a689dd
  37. Sep 19, 2017
    • Herbert Valerio Riedel's avatar
      compiler: introduce custom "GhcPrelude" Prelude · f63bc730
      Herbert Valerio Riedel authored and Ben Gamari's avatar Ben Gamari committed
      This switches the compiler/ component to get compiled with
      -XNoImplicitPrelude and a `import GhcPrelude` is inserted in all
      modules.
      
      This is motivated by the upcoming "Prelude" re-export of
      `Semigroup((<>))` which would cause lots of name clashes in every
      modulewhich imports also `Outputable`
      
      Reviewers: austin, goldfire, bgamari, alanz, simonmar
      
      Reviewed By: bgamari
      
      Subscribers: goldfire, rwbarton, thomie, mpickering, bgamari
      
      Differential Revision: https://phabricator.haskell.org/D3989
      f63bc730
  38. Jan 19, 2017
    • Richard Eisenberg's avatar
      Update levity polymorphism · e7985ed2
      Richard Eisenberg authored
      This commit implements the proposal in
      https://github.com/ghc-proposals/ghc-proposals/pull/29 and
      https://github.com/ghc-proposals/ghc-proposals/pull/35.
      
      Here are some of the pieces of that proposal:
      
      * Some of RuntimeRep's constructors have been shortened.
      
      * TupleRep and SumRep are now parameterized over a list of RuntimeReps.
      * This
      means that two types with the same kind surely have the same
      representation.
      Previously, all unboxed tuples had the same kind, and thus the fact
      above was
      false.
      
      * RepType.typePrimRep and friends now return a *list* of PrimReps. These
      functions can now work successfully on unboxed tuples. This change is
      necessary because we allow abstraction over unboxed tuple types and so
      cannot
      always handle unboxed tuples specially as we did before.
      
      * We sometimes have to create an Id from a PrimRep. I thus split PtrRep
      * into
      LiftedRep and UnliftedRep, so that the created Ids have the right
      strictness.
      
      * The RepType.RepType type was removed, as it didn't seem to help with
      * much.
      
      * The RepType.repType function is also removed, in favor of typePrimRep.
      
      * I have waffled a good deal on whether or not to keep VoidRep in
      TyCon.PrimRep. In the end, I decided to keep it there. PrimRep is *not*
      represented in RuntimeRep, and typePrimRep will never return a list
      including
      VoidRep. But it's handy to have in, e.g., ByteCodeGen and friends. I can
      imagine another design choice where we have a PrimRepV type that is
      PrimRep
      with an extra constructor. That seemed to be a heavier design, though,
      and I'm
      not sure what the benefit would be.
      
      * The last, unused vestiges of # (unliftedTypeKind) have been removed.
      
      * There were several pretty-printing bugs that this change exposed;
      * these are fixed.
      
      * We previously checked for levity polymorphism in the types of binders.
      * But we
      also must exclude levity polymorphism in function arguments. This is
      hard to check
      for, requiring a good deal of care in the desugarer. See Note [Levity
      polymorphism
      checking] in DsMonad.
      
      * In order to efficiently check for levity polymorphism in functions, it
      * was necessary
      to add a new bit of IdInfo. See Note [Levity info] in IdInfo.
      
      * It is now safe for unlifted types to be unsaturated in Core. Core Lint
      * is updated
      accordingly.
      
      * We can only know strictness after zonking, so several checks around
      * strictness
      in the type-checker (checkStrictBinds, the check for unlifted variables
      under a ~
      pattern) have been moved to the desugarer.
      
      * Along the way, I improved the treatment of unlifted vs. banged
      * bindings. See
      Note [Strict binds checks] in DsBinds and #13075.
      
      * Now that we print type-checked source, we must be careful to print
      * ConLikes correctly.
      This is facilitated by a new HsConLikeOut constructor to HsExpr.
      Particularly troublesome
      are unlifted pattern synonyms that get an extra void# argument.
      
      * Includes a submodule update for haddock, getting rid of #.
      
      * New testcases:
        typecheck/should_fail/StrictBinds
        typecheck/should_fail/T12973
        typecheck/should_run/StrictPats
        typecheck/should_run/T12809
        typecheck/should_fail/T13105
        patsyn/should_fail/UnliftedPSBind
        typecheck/should_fail/LevPolyBounded
        typecheck/should_compile/T12987
        typecheck/should_compile/T11736
      
      * Fixed tickets:
        #12809
        #12973
        #11736
        #13075
        #12987
      
      * This also adds a test case for #13105. This test case is
      * "compile_fail" and
      succeeds, because I want the testsuite to monitor the error message.
      When #13105 is fixed, the test case will compile cleanly.
      e7985ed2
Loading