Skip to content
Snippets Groups Projects
  1. Jul 13, 2023
    • Rodrigo Mesquita's avatar
      configure: Drop DllWrap command · 5e951395
      Rodrigo Mesquita authored and Marge Bot's avatar Marge Bot committed
      We used to configure into settings a DllWrap command for windows
      builds and distributions, however, we no longer do, and dllwrap is
      effectively unused.
      
      This simplification is motivated in part by the larger
      toolchain-selection project (#19877, !9263)
      5e951395
  2. Jun 21, 2023
  3. Jun 18, 2023
  4. Jun 15, 2023
  5. Jun 13, 2023
  6. May 26, 2023
    • Matthew Pickering's avatar
      error messages: Don't display ghci specific hints for missing packages · 34b44f7d
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      Tickets like #22884 suggest that it is confusing that GHC used on the
      command line can suggest options which only work in GHCi.
      
      This ticket uses the error message infrastructure to override certain
      error messages which displayed GHCi specific information so that this
      information is only showed when using GHCi.
      
      The main annoyance is that we mostly want to display errors in the same
      way as before, but with some additional information. This means that the
      error rendering code has to be exported from the Iface/Errors/Ppr.hs
      module.
      
      I am unsure about whether the approach taken here is the best or most
      maintainable solution.
      
      Fixes #22884
      34b44f7d
  7. May 25, 2023
  8. May 19, 2023
  9. May 18, 2023
  10. Apr 30, 2023
  11. Apr 27, 2023
    • Cheng Shao's avatar
      testsuite: add the req_host_target_ghc predicate · cb933665
      Cheng Shao authored and Marge Bot's avatar Marge Bot committed
      This patch adds the req_host_target_ghc predicate to the testsuite to
      assert the ghc compiler being tested can compile both host/target
      code. When testing cross GHCs this is not supported yet, but it may
      change in the future.
      cb933665
  12. Apr 18, 2023
    • Matthew Pickering's avatar
      Convert interface file loading errors into proper diagnostics · 5e1d33d7
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      This patch converts all the errors to do with loading interface files
      into proper structured diagnostics.
      
      * DriverMessage: Sometimes in the driver we attempt to load an interface
        file so we embed the IfaceMessage into the DriverMessage.
      * TcRnMessage: Most the time we are loading interface files during
        typechecking, so we embed the IfaceMessage
      
      This patch also removes the TcRnInterfaceLookupError constructor which
      is superceded by the IfaceMessage, which is now structured compared to
      just storing an SDoc before.
      5e1d33d7
  13. Feb 09, 2023
  14. Jan 12, 2023
  15. Nov 29, 2022
  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. Aug 19, 2022
  18. May 21, 2022
    • 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
      4aa3c5bd
  19. Apr 27, 2022
    • sheaf's avatar
      Mark GHC.Prim.PtrEq as Unsafe · 81cf52bb
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This module exports unsafe pointer equality operations,
      so we accordingly mark it as Unsafe.
      
      Fixes #21433
      81cf52bb
  20. Apr 13, 2022
  21. Jan 17, 2022
  22. Dec 28, 2021
    • Matthew Pickering's avatar
      Multiple Home Units · fd42ab5f
      Matthew Pickering authored
      
      Multiple home units allows you to load different packages which may depend on
      each other into one GHC session. This will allow both GHCi and HLS to support
      multi component projects more naturally.
      
      Public Interface
      ~~~~~~~~~~~~~~~~
      
      In order to specify multiple units, the -unit @⟨filename⟩ flag
      is given multiple times with a response file containing the arguments for each unit.
      The response file contains a newline separated list of arguments.
      
      ```
      ghc -unit @unitLibCore -unit @unitLib
      ```
      
      where the `unitLibCore` response file contains the normal arguments that cabal would pass to `--make` mode.
      
      ```
      -this-unit-id lib-core-0.1.0.0
      -i
      -isrc
      LibCore.Utils
      LibCore.Types
      ```
      
      The response file for lib, can specify a dependency on lib-core, so then modules in lib can use modules from lib-core.
      
      ```
      -this-unit-id lib-0.1.0.0
      -package-id lib-core-0.1.0.0
      -i
      -isrc
      Lib.Parse
      Lib.Render
      ```
      
      Then when the compiler starts in --make mode it will compile both units lib and lib-core.
      
      There is also very basic support for multiple home units in GHCi, at the
      moment you can start a GHCi session with multiple units but only the
      :reload is supported. Most commands in GHCi assume a single home unit,
      and so it is additional work to work out how to modify the interface to
      support multiple loaded home units.
      
      Options used when working with Multiple Home Units
      
      There are a few extra flags which have been introduced specifically for
      working with multiple home units. The flags allow a home unit to pretend
      it’s more like an installed package, for example, specifying the package
      name, module visibility and reexported modules.
      
      -working-dir ⟨dir⟩
      
          It is common to assume that a package is compiled in the directory
          where its cabal file resides. Thus, all paths used in the compiler
          are assumed to be relative to this directory. When there are
          multiple home units the compiler is often not operating in the
          standard directory and instead where the cabal.project file is
          located. In this case the -working-dir option can be passed which
          specifies the path from the current directory to the directory the
          unit assumes to be it’s root, normally the directory which contains
          the cabal file.
      
          When the flag is passed, any relative paths used by the compiler are
          offset by the working directory. Notably this includes -i and
          -I⟨dir⟩ flags.
      
      -this-package-name ⟨name⟩
      
          This flag papers over the awkward interaction of the PackageImports
          and multiple home units. When using PackageImports you can specify
          the name of the package in an import to disambiguate between modules
          which appear in multiple packages with the same name.
      
          This flag allows a home unit to be given a package name so that you
          can also disambiguate between multiple home units which provide
          modules with the same name.
      
      -hidden-module ⟨module name⟩
      
          This flag can be supplied multiple times in order to specify which
          modules in a home unit should not be visible outside of the unit it
          belongs to.
      
          The main use of this flag is to be able to recreate the difference
          between an exposed and hidden module for installed packages.
      
      -reexported-module ⟨module name⟩
      
          This flag can be supplied multiple times in order to specify which
          modules are not defined in a unit but should be reexported. The
          effect is that other units will see this module as if it was defined
          in this unit.
      
          The use of this flag is to be able to replicate the reexported
          modules feature of packages with multiple home units.
      
      Offsetting Paths in Template Haskell splices
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      When using Template Haskell to embed files into your program,
      traditionally the paths have been interpreted relative to the directory
      where the .cabal file resides. This causes problems for multiple home
      units as we are compiling many different libraries at once which have
      .cabal files in different directories.
      
      For this purpose we have introduced a way to query the value of the
      -working-dir flag to the Template Haskell API. By using this function we
      can implement a makeRelativeToProject function which offsets a path
      which is relative to the original project root by the value of
      -working-dir.
      
      ```
      import Language.Haskell.TH.Syntax ( makeRelativeToProject )
      
      foo = $(makeRelativeToProject "./relative/path" >>= embedFile)
      ```
      
      > If you write a relative path in a Template Haskell splice you should use the makeRelativeToProject function so that your library works correctly with multiple home units.
      
      A similar function already exists in the file-embed library. The
      function in template-haskell implements this function in a more robust
      manner by honouring the -working-dir flag rather than searching the file
      system.
      
      Closure Property for Home Units
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      For tools or libraries using the API there is one very important closure
      property which must be adhered to:
      
      > Any dependency which is not a home unit must not (transitively) depend
        on a home unit.
      
      For example, if you have three packages p, q and r, then if p depends on
      q which depends on r then it is illegal to load both p and r as home
      units but not q, because q is a dependency of the home unit p which
      depends on another home unit r.
      
      If you are using GHC by the command line then this property is checked,
      but if you are using the API then you need to check this property
      yourself. If you get it wrong you will probably get some very confusing
      errors about overlapping instances.
      
      Limitations of Multiple Home Units
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      There are a few limitations of the initial implementation which will be smoothed out on user demand.
      
          * Package thinning/renaming syntax is not supported
          * More complicated reexports/renaming are not yet supported.
          * It’s more common to run into existing linker bugs when loading a
            large number of packages in a session (for example #20674, #20689)
          * Backpack is not yet supported when using multiple home units.
          * Dependency chasing can be quite slow with a large number of
            modules and packages.
          * Loading wired-in packages as home units is currently not supported
            (this only really affects GHC developers attempting to load
            template-haskell).
          * Barely any normal GHCi features are supported, it would be good to
            support enough for ghcid to work correctly.
      
      Despite these limitations, the implementation works already for nearly
      all packages. It has been testing on large dependency closures,
      including the whole of head.hackage which is a total of 4784 modules
      from 452 packages.
      
      Internal Changes
      ~~~~~~~~~~~~~~~~
      
      * The biggest change is that the HomePackageTable is replaced with the
        HomeUnitGraph. The HomeUnitGraph is a map from UnitId to HomeUnitEnv,
        which contains information specific to each home unit.
      * The HomeUnitEnv contains:
          - A unit state, each home unit can have different package db flags
          - A set of dynflags, each home unit can have different flags
          - A HomePackageTable
      * LinkNode: A new node type is added to the ModuleGraph, this is used to
        place the linking step into the build plan so linking can proceed in
        parralel with other packages being built.
      * New invariant: Dependencies of a ModuleGraphNode can be completely
        determined by looking at the value of the node. In order to achieve
        this, downsweep now performs a more complete job of downsweeping and
        then the dependenices are recorded forever in the node rather than
        being computed again from the ModSummary.
      * Some transitive module calculations are rewritten to use the
        ModuleGraph which is more efficient.
      * There is always an active home unit, which simplifies modifying a lot
        of the existing API code which is unit agnostic (for example, in the
        driver).
      
      The road may be bumpy for a little while after this change but the
      basics are well-tested.
      
      One small metric increase, which we accept and also submodule update to
      haddock which removes ExtendedModSummary.
      
      Closes #10827
      
      -------------------------
      Metric Increase:
          MultiLayerModules
      -------------------------
      
      Co-authored-by: default avatarFendor <power.walross@gmail.com>
      fd42ab5f
  23. Dec 10, 2021
  24. Oct 12, 2021
    • Ben Gamari's avatar
      testsuite: Clean up dynlib support predicates · 05303f68
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Previously it was unclear whether req_shared_libs should require:
      
       * that the platform supports dynamic library loading,
       * that GHC supports dynamic linking of Haskell code, or
       * that the dyn way libraries were built
      
      Clarify by splitting the predicate into two:
      
       * `req_dynamic_lib_support` demands that the platform support dynamic
         linking
       * `req_dynamic_hs` demands that the GHC support dynamic linking of
         Haskell code on the target platform
      
      Naturally `req_dynamic_hs` cannot be true unless
      `req_dynamic_lib_support` is also true.
      05303f68
    • Ben Gamari's avatar
      testsuite: Compile safeInfered tests with -v0 · 2687f65e
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      This eliminates some spurious platform-dependence due to static linking
      (namely in UnsafeInfered02 due to dynamic-too).
      2687f65e
  25. Oct 05, 2021
    • Alfredo Di Napoli's avatar
      Eradicate TcRnUnknownMessage from GHC.Tc.Deriv · ac275f42
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      This (big) commit finishes porting the GHC.Tc.Deriv module to support
      the new diagnostic infrastructure (#18516) by getting rid of the legacy
      calls to `TcRnUnknownMessage`. This work ended up being quite pervasive
      and touched not only the Tc.Deriv module but also the Tc.Deriv.Utils and
      Tc.Deriv.Generics module, which needed to be adapted to use the new
      infrastructure. This also required generalising `Validity`.
      
      More specifically, this is a breakdown of the work done:
      
      * Add and use the TcRnUselessTypeable data constructor
      * Add and use TcRnDerivingDefaults data constructor
      * Add and use the TcRnNonUnaryTypeclassConstraint data constructor
      * Add and use TcRnPartialTypeSignatures
      * Add T13324_compile2 test to test another part of the
        TcRnPartialTypeSignatures diagnostic
      * Add and use TcRnCannotDeriveInstance data constructor, which introduces a
        new data constructor to TcRnMessage called TcRnCannotDeriveInstance, which
        is further sub-divided to carry a `DeriveInstanceErrReason` which explains
        the reason why we couldn't derive a typeclass instance.
      * Add DerivErrSafeHaskellGenericInst data constructor to DeriveInstanceErrReason
      * Add DerivErrDerivingViaWrongKind and DerivErrNoEtaReduce
      * Introduce the SuggestExtensionInOrderTo Hint, which adds (and use) a new
        constructor to the hint type `LanguageExtensionHint` called `SuggestExtensionInOrderTo`,
        which can be used to give a bit more "firm" recommendations when it's
        obvious what the required extension is, like in the case for the
        `DerivingStrategies`, which automatically follows from having enabled
        both `DeriveAnyClass` and `GeneralizedNewtypeDeriving`.
      * Wildcard-free pattern matching in mk_eqn_stock, which removes `_` in
        favour of pattern matching explicitly on `CanDeriveAnyClass` and
        `NonDerivableClass`, because that determine whether or not we can
        suggest to the user `DeriveAnyClass` or not.
      ac275f42
  26. Aug 10, 2021
  27. Jul 28, 2021
    • Alfredo Di Napoli's avatar
      Port more DriverUnknownMessage into richer DriverMessage constructors · 4a2ef3dd
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      In order:
      
      * Introduce the `PsErrUnknownOptionsPragma` diagnostic message
      
        This commit changes the diagnostic emitted inside
        `GHC.Parser.Header.checkProcessArgsResult` from an (erroneous) and
        unstructured `DriverUnknownMessage` to a `PsErrUnknownOPtionsPragma`,
        i.e. a new data constructor of a `PsHeaderMessage`.
      
      * Add the `DriverUserDefinedRuleIgnored` diagnostic message
      
      * Add `DriverUserDefinedRuleIgnored` data constructor
      
        This commit adds (and use) a new data constructor to the `DriverMessage`
        type, replacing a `DriverUnknownMessage` with it.
      
      * Add and use `DriverCannotLoadInterfaceFile` constructor
      
        This commit introduces the DriverCannotLoadInterfaceFile constructor for
        the `DriverMessage` type and it uses it to replace and occurrence of
        `DriverUnknownMessage`.
      
      * Add and use the `DriverInferredSafeImport` constructor
      
        This commit adds a new `DriverInferredSafeImport` constructor to the
        `DriverMessage` type, and uses it in `GHC.Driver.Main` to replace one
        occurrence of `DriverUnknownMessage`.
      
      * Add and use `DriverCannotImportUnsafeModule` constructor
      
        This commit adds the `DriverCannotImportUnsafeModule` constructor
        to the `DriverMessage` type, and later using it to replace one usage of
        `DriverUnknownMessage` in the `GHC.Driver.Main` module.
      
      * Add and use `DriverMissingSafeHaskellMode` constructor
      
      * Add and use `DriverPackageNotTrusted` constructor
      
      * Introduce and use `DriverInferredSafeModule` constructor
      
      * Add and use `DriverMarkedTrustworthyButInferredSafe` constructor
      
      * Add and use `DriverCannotImportFromUntrustedPackage`
      4a2ef3dd
  28. Jul 09, 2021
    • Sylvain Henry's avatar
      Avoid unsafePerformIO for getProgName · 2d4cdfda
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      getProgName was used to append the name of the program (e.g. "ghc") to
      printed error messages in the Show instance of GhcException. It doesn't
      belong here as GHCi and GHC API users may want to override this behavior
      by setting a different error handler. So we now call it in the
      defaultErrorHandler instead.
      2d4cdfda
  29. May 20, 2021
    • Matthew Pickering's avatar
      Remove transitive information about modules and packages from interface files · 38faeea1
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      This commit modifies interface files so that *only* direct information
      about modules and packages is stored in the interface file.
      
      * Only direct module and direct package dependencies are stored in the
      interface files.
      * Trusted packages are now stored separately as they need to be checked
        transitively.
      * hs-boot files below the compiled module in the home module are stored
        so that eps_is_boot can be calculated in one-shot mode without loading
        all interface files in the home package.
      * The transitive closure of signatures is stored separately
      
      This is important for two reasons
      
      * Less recompilation is needed, as motivated by #16885, a lot of
      redundant compilation was triggered when adding new imports deep in the
      module tree as all the parent interface files had to be redundantly
      updated.
      * Checking an interface file is cheaper because you don't have to
      perform a transitive traversal to check the dependencies are up-to-date.
      
      In the code, places where we would have used the transitive closure, we
      instead compute the necessary transitive closure. The closure is not
      computed very often, was already happening in checkDependencies, and
      was already happening in getLinkDeps.
      
      Fixes #16885
      
      -------------------------
      Metric Decrease:
          MultiLayerModules
          T13701
          T13719
      -------------------------
      38faeea1
  30. May 06, 2021
  31. Apr 29, 2021
    • 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, ..)
      types.
      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.
      
      See
      https://gitlab.haskell.org/ghc/ghc/-/wikis/Errors-as-(structured)-values
      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
      Diatchki.
      
      Metric Increase:
          MultiLayerModules
      7d18e1ba
  32. Apr 07, 2021
    • Sylvain Henry's avatar
      Remove dynamic-by-default (#16782) · d014ab0d
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      Dynamic-by-default was a mechanism to automatically select the -dynamic
      way for some targets.
      
      It was implemented in a convoluted way: it was defined as a flavour
      option, hence it couldn't be passed as a global settings (which are
      produced by `configure` before considering flavours), so a build system
      rule was used to pass -DDYNAMIC_BY_DEFAULT to the C compiler so that
      deriveConstants could infer it.
      
      * Make build system has it disabled for 8 years (951e28c0)
      * It has never been implemented in Hadrian
      * Last time someone tried to enable it 1 year ago it didn't work (!2436)
      * Having this as a global constant impedes making GHC multi-target (see !5427)
      
      This commit fully removes support for dynamic-by-default. If someone
      wants to reimplement something like this, it would probably need to move
      the logic in the compiler.
      
      (Doing this would probably need some refactoring of the way the compiler
      handles DynFlags: DynFlags are used to store and to pass enabled ways to
      many parts of the compiler. It can be set by command-line flags, GHC
      API, global settings. In multi-target GHC, we will use DynFlags to load
      the target platform and its constants: but at this point with the
      current DynFlags implementation we can't easily update the existing
      DynFlags with target-specific options such as dynamic-by-default without
      overriding ways previously set by the user.)
      d014ab0d
  33. Apr 06, 2021
  34. Apr 01, 2021
    • Alfredo Di Napoli's avatar
      Compute Severity of diagnostics at birth · 15b6c9f9
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      This commit further expand on the design for #18516 by getting rid of
      the `defaultReasonSeverity` in favour of a function called
      `diagReasonSeverity` which correctly takes the `DynFlags` as input. The
      idea is to compute the `Severity` and the `DiagnosticReason` of each
      message "at birth", without doing any later re-classifications, which
      are potentially error prone, as the `DynFlags` might evolve during the
      course of the program.
      
      In preparation for a proper refactoring, now `pprWarning` from the
      Parser.Ppr module has been renamed to `mkParserWarn`, which now takes a
      `DynFlags` as input.
      
      We also get rid of the reclassification we were performing inside `printOrThrowWarnings`.
      
      Last but not least, this commit removes the need for reclassify inside GHC.Tc.Errors,
      and also simplifies the implementation of `maybeReportError`.
      
      Update Haddock submodule
      15b6c9f9
  35. Mar 12, 2021
  36. Mar 10, 2021
  37. Feb 14, 2021
    • Joachim Breitner's avatar
      Always set `safeInferred`, not only when it turns `False` · f1362008
      Joachim Breitner authored and Marge Bot's avatar Marge Bot committed
      previously, `safeFlagCheck` would be happy to switch the `safeFlag` to
      `False`, but not the other way around. This meant that after
      
          :set -XGeneralizedNewtypeDeriving
          :set -XNoGeneralizedNewtypeDeriving
      
      in GHCi all loaded files would be still be infered as unsafe.
      
      This fixes #19243.
      
      This is a corner case, but somewhat relevant once ghci by default starts
      with `GeneralizedNewtypeDeriving` on (due to GHC2021).
      f1362008
  38. Jul 15, 2020
Loading