1. 25 May, 2022 1 commit
  2. 21 May, 2022 1 commit
    • Norman Ramsey's avatar
      Change `Backend` type and remove direct dependencies · 4aa3c5bd
      Norman Ramsey authored and Cheng Shao's avatar Cheng Shao committed
      With this change, `Backend` becomes an abstract type
      (there are no more exposed value constructors).
      Decisions that were formerly made by asking "is the
      current back end equal to (or different from) this named value
      constructor?" are now made by interrogating the back end about
      its properties, which are functions exported by `GHC.Driver.Backend`.
      There is a description of how to migrate code using `Backend` in the
      user guide.
      Clients using the GHC API can find a backdoor to access the Backend
      datatype in GHC.Driver.Backend.Internal.
      Bumps haddock submodule.
      Fixes #20927
  3. 23 Mar, 2022 1 commit
    • Zubin's avatar
      hi haddock: Lex and store haddock docs in interface files · b91798be
      Zubin authored and  Marge Bot's avatar Marge Bot committed
      Names appearing in Haddock docstrings are lexed and renamed like any other names
      appearing in the AST. We currently rename names irrespective of the namespace,
      so both type and constructor names corresponding to an identifier will appear in
      the docstring. Haddock will select a given name as the link destination based on
      its own heuristics.
      This patch also restricts the limitation of `-haddock` being incompatible with
      The export and documenation structure is now computed in GHC and serialised in
      .hi files. This can be used by haddock to directly generate doc pages without
      reparsing or renaming the source. At the moment the operation of haddock
      is not modified, that's left to a future patch.
      Updates the haddock submodule with the minimum changes needed.
  4. 20 Feb, 2022 1 commit
    • Zubin's avatar
      Track object file dependencies for TH accurately (#20604) · 4b04f7e1
      Zubin authored and  Marge Bot's avatar Marge Bot committed
      `hscCompileCoreExprHook` is changed to return a list of `Module`s required
      by a splice. These modules are accumulated in the TcGblEnv (tcg_th_needed_mods).
      Dependencies on the object files of these modules are recording in the
      The data structures in `LoaderState` are replaced with more efficient versions
      to keep track of all the information required. The
      MultiLayerModulesTH_Make allocations increase slightly but runtime is
      Fixes #20604
      Metric Increase:
  5. 12 Feb, 2022 1 commit
    • Andreas Klebinger's avatar
      Tag inference work. · 0e93023e
      Andreas Klebinger authored and Matthew Pickering's avatar Matthew Pickering committed
      This does three major things:
      * Enforce the invariant that all strict fields must contain tagged
      * Try to predict the tag on bindings in order to omit tag checks.
      * Allows functions to pass arguments unlifted (call-by-value).
      The former is "simply" achieved by wrapping any constructor allocations with
      a case which will evaluate the respective strict bindings.
      The prediction is done by a new data flow analysis based on the STG
      representation of a program. This also helps us to avoid generating
      redudant cases for the above invariant.
      StrictWorkers are created by W/W directly and SpecConstr indirectly.
      See the Note [Strict Worker Ids]
      Other minor changes:
      * Add StgUtil module containing a few functions needed by, but
        not specific to the tag analysis.
      Metric Decrease:
      Metric Increase:
  6. 07 Feb, 2022 2 commits
  7. 21 Dec, 2021 1 commit
    • Sylvain Henry's avatar
      Give plugins a better interface (#17957) · 9728d6c2
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      Plugins were directly fetched from HscEnv (hsc_static_plugins and
      hsc_plugins). The tight coupling of plugins and of HscEnv is undesirable
      and it's better to store them in a new Plugins datatype and to use it in
      the plugins' API (e.g. withPlugins, mapPlugins...).
      In the process, the interactive context (used by GHCi) got proper
      support for different static plugins than those used for loaded modules.
      Bump haddock submodule
  8. 17 Nov, 2021 1 commit
    • Ben Gamari's avatar
      Increase type sharing · 083a7583
      Ben Gamari authored and  Marge Bot's avatar Marge Bot committed
      Fixes #20541 by making mkTyConApp do more sharing of types.
      In particular, replace
      * BoxedRep Lifted    ==>  LiftedRep
      * BoxedRep Unlifted  ==>  UnliftedRep
      * TupleRep '[]       ==>  ZeroBitRep
      * TYPE ZeroBitRep    ==>  ZeroBitType
      In each case, the thing on the right is a type synonym
      for the thing on the left, declared in ghc-prim:GHC.Types.
      See Note [Using synonyms to compress types] in GHC.Core.Type.
      The synonyms for ZeroBitRep and ZeroBitType are new, but absolutely
      in the same spirit as the other ones.   (These synonyms are mainly
      for internal use, though the programmer can use them too.)
      I also renamed GHC.Core.Ty.Rep.isVoidTy to isZeroBitTy, to be
      compatible with the "zero-bit" nomenclature above.  See discussion
      on !6806.
      There is a tricky wrinkle: see GHC.Core.Types
        Note [Care using synonyms to compress types]
      Compiler allocation decreases by up to 0.8%.
  9. 17 Oct, 2021 1 commit
    • sheaf's avatar
      Introduce Concrete# for representation polymorphism checks · 81740ce8
      sheaf authored and  Marge Bot's avatar Marge Bot committed
      PHASE 1: we never rewrite Concrete# evidence.
      This patch migrates all the representation polymorphism checks to
      the typechecker, using a new constraint form
        Concrete# :: forall k. k -> TupleRep '[]
      Whenever a type `ty` must be representation-polymorphic
      (e.g. it is the type of an argument to a function), we emit a new
      `Concrete# ty` Wanted constraint. If this constraint goes
      unsolved, we report a representation-polymorphism error to the user.
      The 'FRROrigin' datatype keeps track of the context of the
      representation-polymorphism check, for more informative error messages.
      This paves the way for further improvements, such as
      allowing type families in RuntimeReps and improving the soundness
      of typed Template Haskell. This is left as future work (PHASE 2).
      fixes #17907 #20277 #20330 #20423 #20426
      updates haddock submodule
      Metric Decrease:
  10. 17 Sep, 2021 1 commit
  11. 13 Aug, 2021 1 commit
    • Sylvain Henry's avatar
      Refactoring module dependencies · c367b39e
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      * Make mkDependencies pure
      * Use Sets instead of sorted lists
      Notable perf changes:
            MultiLayerModules(normal) ghc/alloc  4130851520.0  2981473072.0 -27.8%
                       T13719(normal) ghc/alloc  4313296052.0  4151647512.0  -3.7%
      Metric Decrease:
  12. 17 Jun, 2021 1 commit
    • Matthew Pickering's avatar
      profiling: Look in RHS of rules for cost centre ticks · 01fd2617
      Matthew Pickering authored and  Marge Bot's avatar Marge Bot committed
      There are some obscure situations where the RHS of a rule can contain a
      tick which is not mentioned anywhere else in the program. If this
      happens you end up with an obscure linker error. The solution is quite
      simple, traverse the RHS of rules to also look for ticks. It turned out
      to be easier to implement if the traversal was moved into CoreTidy
      rather than at the start of code generation because there we still had
      easy access to the rules.
      ./StreamD.o(.text+0x1b9f2): error: undefined reference to 'StreamK_mkStreamFromStream_HPC_cc'
      ./MArray.o(.text+0xbe83): error: undefined reference to 'StreamK_mkStreamFromStream_HPC_cc'
      Main.o(.text+0x6fdb): error: undefined reference to 'StreamK_mkStreamFromStream_HPC_cc'
  13. 10 Jun, 2021 1 commit
  14. 07 Jun, 2021 1 commit
    • Sylvain Henry's avatar
      Make Logger independent of DynFlags · 4dc681c7
      Sylvain Henry authored
      Introduce LogFlags as a independent subset of DynFlags used for logging.
      As a consequence in many places we don't have to pass both Logger and
      DynFlags anymore.
      The main reason for this refactoring is that I want to refactor the
      systools interfaces: for now many systools functions use DynFlags both
      to use the Logger and to fetch their parameters (e.g. ldInputs for the
      linker). I'm interested in refactoring the way they fetch their
      parameters (i.e. use dedicated XxxOpts data types instead of DynFlags)
      for #19877. But if I did this refactoring before refactoring the Logger,
      we would have duplicate parameters (e.g. ldInputs from DynFlags and
      linkerInputs from LinkerOpts). Hence this patch first.
      Some flags don't really belong to LogFlags because they are subsystem
      specific (e.g. most DumpFlags). For example -ddump-asm should better be
      passed in NCGConfig somehow. This patch doesn't fix this tight coupling:
      the dump flags are part of the UI but they are passed all the way down
      for example to infer the file name for the dumps.
      Because LogFlags are a subset of the DynFlags, we must update the former
      when the latter changes (not so often). As a consequence we now use
      accessors to read/write DynFlags in HscEnv instead of using `hsc_dflags`
      In the process I've also made some subsystems less dependent on DynFlags:
      - CmmToAsm: by passing some missing flags via NCGConfig (see new fields
        in GHC.CmmToAsm.Config)
      - Core.Opt.*:
          - by passing -dinline-check value into UnfoldingOpts
          - by fixing some Core passes interfaces (e.g. CallArity, FloatIn)
            that took DynFlags argument for no good reason.
          - as a side-effect GHC.Core.Opt.Pipeline.doCorePass is much less
  15. 03 Jun, 2021 2 commits
    • 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.
    • Matthew Pickering's avatar
      Driver Rework Patch · 25977ab5
      Matthew Pickering authored
      This patch comprises of four different but closely related ideas. The
      net result is fixing a large number of open issues with the driver
      whilst making it simpler to understand.
      1. Use the hash of the source file to determine whether the source file
      has changed or not. This makes the recompilation checking more robust to
      modern build systems which are liable to copy files around changing
      their modification times.
      2. Remove the concept of a "stable module", a stable module was one
      where the object file was older than the source file, and all transitive
      dependencies were also stable. Now we don't rely on the modification
      time of the source file, the notion of stability is moot.
      3. Fix TH/plugin recompilation after the removal of stable modules. The
      TH recompilation check used to rely on stable modules. Now there is a
      uniform and simple way, we directly track the linkables which were
      loaded into the interpreter whilst compiling a module. This is an
      over-approximation but more robust wrt package dependencies changing.
      4. Fix recompilation checking for dynamic object files. Now we actually
      check if the dynamic object file exists when compiling with -dynamic-too
      Fixes #19774 #19771 #19758 #17434 #11556 #9121 #8211 #16495 #7277 #16093
  16. 13 May, 2021 3 commits
    • Sylvain Henry's avatar
      Remove useless {-# LANGUAGE CPP #-} pragmas · 67a5a91e
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
    • Sylvain Henry's avatar
      Fully remove HsVersions.h · 0ef11907
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      Replace uses of WARN macro with calls to:
        warnPprTrace :: Bool -> SDoc -> a -> a
      Remove the now unused HsVersions.h
      Bump haddock submodule
    • Sylvain Henry's avatar
      Replace CPP assertions with Haskell functions · bfabf94f
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      There is no reason to use CPP. __LINE__ and __FILE__ macros are now
      better replaced with GHC's CallStack. As a bonus, assert error messages
      now contain more information (function name, column).
      Here is the mapping table (HasCallStack omitted):
        * ASSERT:   assert     :: Bool -> a -> a
        * MASSERT:  massert    :: Bool -> m ()
        * ASSERTM:  assertM    :: m Bool -> m ()
        * ASSERT2:  assertPpr  :: Bool -> SDoc -> a -> a
        * MASSERT2: massertPpr :: Bool -> SDoc -> m ()
        * ASSERTM2: assertPprM :: m Bool -> SDoc -> m ()
  17. 29 Apr, 2021 1 commit
    • Alfredo Di Napoli's avatar
      Add GhcMessage and ancillary types · 7d18e1ba
      Alfredo Di Napoli authored and  Marge Bot's avatar Marge Bot committed
      This commit adds GhcMessage and ancillary (PsMessage, TcRnMessage, ..)
      These types will be expanded to represent more errors generated
      by different subsystems within GHC. Right now, they are underused,
      but more will come in the glorious future.
      for a design overview.
      Along the way, lots of other things had to happen:
      * Adds Semigroup and Monoid instance for Bag
      * Fixes #19746 by parsing OPTIONS_GHC pragmas into Located Strings.
        See GHC.Parser.Header.toArgs (moved from GHC.Utils.Misc, where it
        didn't belong anyway).
      * Addresses (but does not completely fix) #19709, now reporting
        desugarer warnings and errors appropriately for TH splices.
        Not done: reporting type-checker warnings for TH splices.
      * Some small refactoring around Safe Haskell inference, in order
        to keep separate classes of messages separate.
      * Some small refactoring around initDsTc, in order to keep separate
        classes of messages separate.
      * Separate out the generation of messages (that is, the construction
        of the text block) from the wrapping of messages (that is, assigning
        a SrcSpan). This is more modular than the previous design, which
        mixed the two.
      Close #19746.
      This was a collaborative effort by Alfredo di Napoli and
      Richard Eisenberg, with a key assist on #19746 by Iavor
      Metric Increase:
  18. 06 Apr, 2021 1 commit
    • Alfredo Di Napoli's avatar
      Introduce SevIgnore Severity to suppress warnings · 49528121
      Alfredo Di Napoli authored and  Marge Bot's avatar Marge Bot committed
      This commit introduces a new `Severity` type constructor called
      `SevIgnore`, which can be used to classify diagnostic messages which are
      not meant to be displayed to the user, for example suppressed warnings.
      This extra constructor allows us to get rid of a bunch of redundant
      checks when emitting diagnostics, typically in the form of the pattern:
      when (optM Opt_XXX) $
        addDiagnosticTc (WarningWithFlag Opt_XXX) ...
      Fair warning! Not all checks should be omitted/skipped, as evaluating some data
      structures used to produce a diagnostic might still be expensive (e.g.
      zonking, etc). Therefore, a case-by-case analysis must be conducted when
      deciding if a check can be removed or not.
      Last but not least, we remove the unnecessary `CmdLine.WarnReason` type, which is now
      redundant with `DiagnosticReason`.
  19. 29 Mar, 2021 1 commit
    • Alfredo Di Napoli's avatar
      Add `MessageClass`, rework `Severity` and add `DiagnosticReason`. · c30af951
      Alfredo Di Napoli authored
      Other than that:
      * Fix T16167,json,json2,T7478,T10637 tests to reflect the introduction of
        the `MessageClass` type
      * Remove `makeIntoWarning`
      * Remove `warningsToMessages`
      * Refactor GHC.Tc.Errors
        1. Refactors GHC.Tc.Errors so that we use `DiagnosticReason` for "choices"
           (defer types errors, holes, etc);
        2. We get rid of `reportWarning` and `reportError` in favour of a general
      * Introduce `DiagnosticReason`, `Severity` is an enum: This big commit makes
        `Severity` a simple enumeration, and introduces the concept of `DiagnosticReason`,
        which classifies the /reason/ why we are emitting a particular diagnostic.
        It also adds a monomorphic `DiagnosticMessage` type which is used for
        generic messages.
      * The `Severity` is computed (for now) from the reason, statically.
        Later improvement will add a `diagReasonSeverity` function to compute
        the `Severity` taking `DynFlags` into account.
      * Rename ...
  20. 20 Mar, 2021 1 commit
  21. 10 Mar, 2021 1 commit
    • Luke Lau's avatar
      template-haskell: Add putDoc, getDoc, withDecDoc and friends · 8a59f49a
      Luke Lau authored and Ben Gamari's avatar Ben Gamari committed
      This adds two new methods to the Quasi class, putDoc and getDoc. They
      allow Haddock documentation to be added to declarations, module headers,
      function arguments and class/type family instances, as well as looked
      It works by building up a map of names to attach pieces of
      documentation to, which are then added in the extractDocs function in
      GHC.HsToCore.Docs. However because these template haskell names need to
      be resolved to GHC names at the time they are added, putDoc cannot
      directly add documentation to declarations that are currently being
      spliced. To remedy this, withDecDoc/withDecsDoc wraps the operation with
      addModFinalizer, and provides a more ergonomic interface for doing so.
      Similarly, the funD_doc, dataD_doc etc. combinators provide a more
      ergonomic interface for documenting functions and their arguments
      This also changes ArgDocMap to use an IntMap rather than an Map Int, for
      Part of the work towards #5467
  22. 03 Mar, 2021 1 commit
  23. 14 Feb, 2021 1 commit
    • Sylvain Henry's avatar
      Refactor Logger · 8e2f85f6
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      Before this patch, the only way to override GHC's default logging
      behavior was to set `log_action`, `dump_action` and `trace_action`
      fields in DynFlags. This patch introduces a new Logger abstraction and
      stores it in HscEnv instead.
      This is part of #17957 (avoid storing state in DynFlags). DynFlags are
      duplicated and updated per-module (because of OPTIONS_GHC pragma), so
      we shouldn't store global state in them.
      This patch also fixes a race in parallel "--make" mode which updated
      the `generatedDumps` IORef concurrently.
      Bump haddock submodule
      The increase in MultilayerModules is tracked in #19293.
      Metric Increase:
  24. 01 Feb, 2021 2 commits
    • Alfredo Di Napoli's avatar
      Introduce the DecoratedSDoc type · c0709c1d
      Alfredo Di Napoli authored and  Marge Bot's avatar Marge Bot committed
      This commit introduces a DecoratedSDoc type which replaces the old
      ErrDoc, and hopefully better reflects the intent.
    • Alfredo Di Napoli's avatar
      Remove ErrDoc and MsgDoc · ddc2a759
      Alfredo Di Napoli authored and  Marge Bot's avatar Marge Bot committed
      This commit boldly removes the ErrDoc and the MsgDoc from the codebase.
      The former was introduced with the only purpose of classifying errors
      according to their importance, but a similar result can be obtained just
      by having a simple [SDoc], and placing bullets after each of them.
      On top of that I have taken the perhaps controversial decision to also
      banish MsgDoc, as it was merely a type alias over an SDoc and as such it wasn't
      offering any extra type safety. Granted, it was perhaps making type
      signatures slightly more "focused", but at the expense of cognitive
      burden: if it's really just an SDoc, let's call it with its proper name.
  25. 29 Jan, 2021 1 commit
  26. 22 Jan, 2021 1 commit
    • Alfredo Di Napoli's avatar
      Parameterise Messages over e · a64f21e9
      Alfredo Di Napoli authored and  Marge Bot's avatar Marge Bot committed
      This commit paves the way to a richer and more structured representation
      of GHC error messages, as per GHC proposal #306. More specifically
      'Messages' from 'GHC.Types.Error' now gains an extra type parameter,
      that we instantiate to 'ErrDoc' for now. Later, this will allow us to
      replace ErrDoc with something more structure (for example messages
      coming from the parser, the typechecker etc).
  27. 14 Dec, 2020 1 commit
    • Sylvain Henry's avatar
      Move Unit related fields from DynFlags to HscEnv · d0e8c10d
      Sylvain Henry authored
      The unit database cache, the home unit and the unit state were stored in
      DynFlags while they ought to be stored in the compiler session state
      (HscEnv). This patch fixes this.
      It introduces a new UnitEnv type that should be used in the future to
      handle separate unit environments (especially host vs target units).
      Related to #17957
      Bump haddock submodule
  28. 21 Nov, 2020 1 commit
    • Sylvain Henry's avatar
      Move Plugins into HscEnv (#17957) · ecfd0278
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      Loaded plugins have nothing to do in DynFlags so this patch moves them
      into HscEnv (session state).
      "DynFlags plugins" become "Driver plugins" to still be able to register
      static plugins.
      Bump haddock submodule
  29. 01 Nov, 2020 1 commit
  30. 29 Oct, 2020 1 commit
    • Sylvain Henry's avatar
      Split GHC.Driver.Types · 0e9f6def
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      I was working on making DynFlags stateless (#17957), especially by
      storing loaded plugins into HscEnv instead of DynFlags. It turned out to
      be complicated because HscEnv is in GHC.Driver.Types but LoadedPlugin
      isn't: it is in GHC.Driver.Plugins which depends on GHC.Driver.Types. I
      didn't feel like introducing yet another hs-boot file to break the loop.
      Additionally I remember that while we introduced the module hierarchy
      (#13009) we talked about splitting GHC.Driver.Types because it contained
      various unrelated types and functions, but we never executed. I didn't
      feel like making GHC.Driver.Types bigger with more unrelated Plugins
      related types, so finally I bit the bullet and split GHC.Driver.Types.
      As a consequence this patch moves a lot of things. I've tried to put
      them into appropriate modules but nothing is set in stone.
      Several other things moved to avoid loops.
      * Removed Binary instances from GHC.Utils.Binary for random compiler
      * Moved Typeable Binary instances into GHC.Utils.Binary.Typeable: they
        import a lot of things that users of GHC.Utils.Binary don't want to
        depend on.
      * put everything related to Units/Modules under GHC.Unit:
        GHC.Unit.Finder, GHC.Unit.Module.{ModGuts,ModIface,Deps,etc.}
      * Created several modules under GHC.Types: GHC.Types.Fixity, SourceText,
      * Split GHC.Utils.Error (into GHC.Types.Error)
      * Finally removed GHC.Driver.Types
      Note that this patch doesn't put loaded plugins into HscEnv. It's left
      for another patch.
      Bump haddock submodule
  31. 10 Oct, 2020 1 commit
  32. 09 Oct, 2020 1 commit
  33. 12 Sep, 2020 1 commit
    • Sebastian Graf's avatar
      PmCheck: Disattach COMPLETE pragma lookup from TyCons · 2a942285
      Sebastian Graf authored and  Marge Bot's avatar Marge Bot committed
      By not attaching COMPLETE pragmas with a particular TyCon and instead
      assume that every COMPLETE pragma is applicable everywhere, we can
      drastically simplify the logic that tries to initialise available
      COMPLETE sets of a variable during the pattern-match checking process,
      as well as fixing a few bugs.
      Of course, we have to make sure not to report any of the
      ill-typed/unrelated COMPLETE sets, which came up in a few regression
      In doing so, we fix #17207, #18277 and #14422.
      There was a metric decrease in #18478 by ~20%.
      Metric Decrease:
  34. 09 Sep, 2020 2 commits