1. 23 Aug, 2021 1 commit
    • sheaf's avatar
      TcPlugins: solve and report contras simultaneously · f1708665
      sheaf authored
      This changes the TcPlugin datatype to allow type-checking plugins
      to report insoluble constraints while at the same time solve
      some other constraints. This allows better error messages, as
      the plugin can still simplify constraints, even when it wishes
      to report a contradiction.
      Pattern synonyms TcPluginContradiction and TcPluginOk are provided
      for backwards compatibility: existing type-checking plugins should
      continue to work without modification.
  2. 19 Aug, 2021 4 commits
  3. 18 Aug, 2021 4 commits
    • sheaf's avatar
      Don't look for TypeError in type family arguments · 4a10f0ff
      sheaf authored
      Changes checkUserTypeError to no longer look for custom type errors
      inside type family arguments.
      This means that a program such as
      foo :: F xyz (TypeError (Text "blah")) -> bar
      does not throw a type error at definition site.
      This means that more programs can be accepted, as the custom type error
      might disappear upon reducing the above type family F.
      This applies only to user-written type signatures, which are checked
      within checkValidType. Custom type errors in type family arguments
      continue to be reported when they occur in unsolved Wanted constraints.
      Fixes #20241
    • Matthew Pickering's avatar
      recomp: Check backend type rather than -fwrite-interface to decide whether we need any objects · d9cf2ec8
      Matthew Pickering authored
      This was a small oversight in the original patch which leads to spurious
      recompilation when using `-fno-code` but not `-fwrite-interface`, which
      you plausibly might do when using ghci.
      Fixes #20216
    • Matthew Pickering's avatar
      Driver rework pt3: the upsweep · 5f0d2dab
      Matthew Pickering authored
      This patch specifies and simplifies the module cycle compilation
      in upsweep. How things work are described in the Note [Upsweep]
      Note [Upsweep]
      Upsweep takes a 'ModuleGraph' as input, computes a build plan and then executes
      the plan in order to compile the project.
      The first step is computing the build plan from a 'ModuleGraph'.
      The output of this step is a `[BuildPlan]`, which is a topologically sorted plan for
      how to build all the modules.
      data BuildPlan = SingleModule ModuleGraphNode  -- A simple, single module all alone but *might* have an hs-boot file which isn't part of a cycle
                     | ResolvedCycle [ModuleGraphNode]   -- A resolved cycle, linearised by hs-boot files
                     | UnresolvedCycle [ModuleGraphNode] -- An actual cycle, which wasn't resolved by hs-boot files
      The plan is computed in two steps:
      Step 1: Topologically sort the module graph without hs-boot files. This returns a [SCC ModuleGraphNode] which contains
      Step 2: For each cycle, topologically sort the modules in the cycle *with* the relevant hs-boot files. This should
              result in an acyclic build plan if the hs-boot files are sufficient to resolve the cycle.
      The `[BuildPlan]` is then interpreted by the `interpretBuildPlan` function.
      * `SingleModule nodes` are compiled normally by either the upsweep_inst or upsweep_mod functions.
      * `ResolvedCycles` need to compiled "together" so that the information which ends up in
        the interface files at the end is accurate (and doesn't contain temporary information from
        the hs-boot files.)
        - During the initial compilation, a `KnotVars` is created which stores an IORef TypeEnv for
          each module of the loop. These IORefs are gradually updated as the loop completes and provide
          the required laziness to typecheck the module loop.
        - At the end of typechecking, all the interface files are typechecked again in
          the retypecheck loop. This time, the knot-tying is done by the normal laziness
          based tying, so the environment is run without the KnotVars.
      * UnresolvedCycles are indicative of a proper cycle, unresolved by hs-boot files
        and are reported as an error to the user.
      The main trickiness of `interpretBuildPlan` is deciding which version of a dependency
      is visible from each module. For modules which are not in a cycle, there is just
      one version of a module, so that is always used. For modules in a cycle, there are two versions of
      1. Internal to loop: The version created whilst compiling the loop by upsweep_mod.
      2. External to loop: The knot-tied version created by typecheckLoop.
      Whilst compiling a module inside the loop, we need to use the (1). For a module which
      is outside of the loop which depends on something from in the loop, the (2) version
      is used.
      As the plan is interpreted, which version of a HomeModInfo is visible is updated
      by updating a map held in a state monad. So after a loop has finished being compiled,
      the visible module is the one created by typecheckLoop and the internal version is not
      used again.
      This plan also ensures the most important invariant to do with module loops:
      > If you depend on anything within a module loop, before you can use the dependency,
        the whole loop has to finish compiling.
      The end result of `interpretBuildPlan` is a `[MakeAction]`, which are pairs
      of `IO a` actions and a `MVar (Maybe a)`, somewhere to put the result of running
      the action. This list is topologically sorted, so can be run in order to compute
      the whole graph.
      As well as this `interpretBuildPlan` also outputs an `IO [Maybe (Maybe HomeModInfo)]` which
      can be queried at the end to get the result of all modules at the end, with their proper
      visibility. For example, if any module in a loop fails then all modules in that loop will
      report as failed because the visible node at the end will be the result of retypechecking
      those modules together.
      Along the way we also fix a number of other bugs in the driver:
      * Unify upsweep and parUpsweep.
      * Fix #19937 (static points, ghci and -j)
      * Adds lots of module loop tests due to Divam.
      Also related to #20030
      Co-authored-by: Divam Narula's avatarDivam Narula <dfordivam@gmail.com>
      Metric Decrease:
    • Matthew Pickering's avatar
      Fix parsing of rpaths which include spaces in runInjectRPaths · 0ba21dbe
      Matthew Pickering authored
      The logic didn't account for the fact that the paths could contain
      spaces before which led to errors such as the following from
      Stderr ( T14304 ):
      Warning: -rtsopts and -with-rtsopts have no effect with -shared.
          Call hs_init_ghc() from your main() function to set these options.
      error: /nix/store/a6j5761iy238pbckxq2xrhqr2d5kra4m-cctools-binutils-darwin-949.0.1/bin/install_name_tool: for: dist/build/libHSp-0.1-ghc8.10.6.dylib (for architecture arm64) option "-add_rpath /Users/matt/ghc/bindisttest/install   dir/lib/ghc-8.10.6/ghc-prim-0.6.1" would duplicate path, file already has LC_RPATH for: /Users/matt/ghc/bindisttest/install   dir/lib/ghc-8.10.6/ghc-prim-0.6.1
      `install_name_tool' failed in phase `Install Name Tool'. (Exit code: 1)
      Fixes #20212
      This apparently also fixes #20026, which is a nice surprise.
  4. 17 Aug, 2021 3 commits
    • Sylvain Henry's avatar
      StgToCmm: use correct bounds for switches on sized values · 5798357d
      Sylvain Henry authored
      StgToCmm was only using literals signedness to determine whether using
      Int and Word range in Cmm switches. Now that we have sized literals
      (Int8#, Int16#, etc.), it needs to take their ranges into account.
    • John Ericson's avatar
      Test non-native switch C-- with twos compliment · b784a51e
      John Ericson authored
      We don't want regressions like e8f7734d
      to regress.
      Co-Authored-By: default avatarSylvain Henry <hsyl20@gmail.com>
    • Matthew Pickering's avatar
      ghci: Fix rec statements in interactive prompt · acb188e0
      Matthew Pickering authored
      We desugar a recursive Stmt to somethign like
        (a,_,c) <- mfix (\(a,b,_) -> do { ... ; return (a,b,c) })
        ...stuff after the rec...
      The knot-tied tuple must contain
      * All the variables that are used before they are bound in the `rec` block
      * All the variables that are used after the entire `rec` block
      In the case of GHCi, however, we don't know what variables will be used
      after the `rec` (#20206).  For example, we might have
          ghci>  rec { x <- e1; y <- e2 }
          ghci>  print x
          ghci>  print y
      So we have to assume that *all* the variables bound in the `rec` are used
      afterwards.  We use `Nothing` in the argument to segmentRecStmts to signal
      that all the variables are used.
      Fixes #20206
  5. 15 Aug, 2021 6 commits
    • Greg Steuck's avatar
      Fix iconv detection in configure on OpenBSD · 31dc013f
      Greg Steuck authored
      This regressed in 544414ba causing
      configure: error: iconv is required on non-Windows platforms
      More details:
    • Simon Peyton Jones's avatar
      Use the right InScopeSet for findBest · 7f217429
      Simon Peyton Jones authored
      This is the right thing to do, easy to do, and fixes
      a second not-in-scope crash in #20200 (see !6302)
      The problem occurs in the findBest test, which compares
      two RULES.
      Repro case in simplCore/should_compile/T20200a
    • Krzysztof Gogolewski's avatar
      Fix lookupIdSubst call during RULE matching · 149bce42
      Krzysztof Gogolewski authored
      As #20200 showed, there was a call to lookupIdSubst during RULE
      matching, where the variable being looked up wasn't in the InScopeSet.
      This patch fixes the problem at source, by dealing separately with
      nested and non-nested binders.
      As a result we can change the trace call in lookupIdSubst to a
      proper panic -- if it happens, we really want to know.
    • Simon Peyton Jones's avatar
      TypeError is OK on the RHS of a type synonym · 0f6fb7d3
      Simon Peyton Jones authored
      We should not complain about TypeError in
        type T = TypeError blah
      This fixes #20181
      The error message for T13271 changes, because that test did
      indeed have a type synonym with TypeError on the RHS
    • sheaf's avatar
      Update TcPlugin_RewritePerf performance test · 71130bf8
      sheaf authored
      This test exhibited inconsistent behaviour, with different CI runs
      having a 98% decrease in allocations.
      This commit addresses this problem by ensuring that we measure
      allocations of the whole collection of modules used in the test.
      Metric Increase:
    • sheaf's avatar
      Detect TypeError when checking for insolubility · 1e896b47
      sheaf authored
      We detect insoluble Givens by making getInertInsols
      take into account TypeError constraints, on top of insoluble equalities
      such as Int ~ Bool (which it already took into account).
      This allows pattern matches with insoluble contexts to be reported
      as redundant (tyOracle calls tcCheckGivens which calls getInertInsols).
      As a bonus, we get to remove a workaround in Data.Typeable.Internal:
      we can directly use a NotApplication type family, as opposed to
      needing to cook up an insoluble equality constraint.
      Fixes #11503 #14141 #16377 #20180
  6. 14 Aug, 2021 3 commits
    • Matthew Pickering's avatar
      hadrian: Also produce versioned wrapper scripts · a975583c
      Matthew Pickering authored
      Since !6133 we are more consistent about producing versioned
      executables but we still didn't produce versioned wrappers. This patch
      adds the corresponding versioned wrappers to match the versioned
      executables in the relocatable bindist.
      I also fixed the ghci wrapper so that it wasn't overwritten during
      The final bindir looks like:
      lrwxrwxrwx 1 matt users   16 Aug 12 11:56 ghc -> ghc-9.3.20210809
      -rwxr-xr-x 1 matt users  674 Aug 12 11:56 ghc-9.3.20210809
      lrwxrwxrwx 1 matt users   17 Aug 12 11:56 ghci -> ghci-9.3.20210809
      -rwxr-xr-x 1 matt users  708 Aug 12 11:56 ghci-9.3.20210809
      lrwxrwxrwx 1 matt users   20 Aug 12 11:56 ghc-pkg -> ghc-pkg-9.3.20210809
      -rwxr-xr-x 1 matt users  734 Aug 12 11:56 ghc-pkg-9.3.20210809
      lrwxrwxrwx 1 matt users   14 Aug 12 11:56 haddock -> haddock-2.24.0
      -rwxr-xr-x 1 matt users  682 Aug 12 11:56 haddock-2.24.0
      lrwxrwxrwx 1 matt users    9 Aug 12 11:56 hp2ps -> hp2ps-0.1
      -rwxr-xr-x 1 matt users  648 Aug 12 11:56 hp2ps-0.1
      lrwxrwxrwx 1 matt users    8 Aug 12 11:56 hpc -> hpc-0.68
      -rwxr-xr-x 1 matt users  646 Aug 12 11:56 hpc-0.68
      lrwxrwxrwx 1 matt users   13 Aug 12 11:56 hsc2hs -> hsc2hs-0.68.8
      -rwxr-xr-x 1 matt users 1.4K Aug 12 11:56 hsc2hs-0.68.8
      lrwxrwxrwx 1 matt users   19 Aug 12 11:56 runghc -> runghc-9.3.20210809
      -rwxr-xr-x 1 matt users  685 Aug 12 11:56 runghc-9.3.20210809
      Fixes #20225
    • Matthew Pickering's avatar
      Create absolute symlink for test executables · 9700b9a8
      Matthew Pickering authored
      This is necessary because the symlink needs to be created between two
      arbritary filepaths in the build tree, it's hard to compute how to get
      between them relatively. As this symlink doesn't end up in a bindist
      then it's fine for it to be absolute.
    • Matthew Pickering's avatar
      Revert "hadrian: Make copyFileLinked a bit more robust" · 0bf8e73a
      Matthew Pickering authored
      This reverts commit d45e3cda.
  7. 13 Aug, 2021 3 commits
    • sheaf's avatar
      Add rewriting to typechecking plugins · 9d4ba36f
      sheaf authored
      Type-checking plugins can now directly rewrite type-families.
      The TcPlugin record is given a new field, tcPluginRewrite.
      The plugin specifies how to rewrite certain type-families with a value
      of type `UniqFM TyCon TcPluginRewriter`, where:
      type TcPluginRewriter
        =  RewriteEnv -- Rewriter environment
        -> [Ct]       -- Givens
        -> [TcType]   -- type family arguments
        -> TcPluginM TcPluginRewriteResult
      data TcPluginRewriteResult
        = TcPluginNoRewrite
        | TcPluginRewriteTo
            { tcPluginRewriteTo    :: Reduction
            , tcRewriterNewWanteds :: [Ct]
      When rewriting an exactly-saturated type-family application,
      GHC will first query type-checking plugins for possible rewritings
      before proceeding.
      Includes some changes to the TcPlugin API, e.g. removal
      of the EvBindsVar parameter to the TcPluginM monad.
    • Sylvain Henry's avatar
      Refactoring module dependencies · c367b39e
      Sylvain Henry authored
      * 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:
    • Gergő Érdi's avatar
      Move `ol_witness` to `OverLitTc` · 7ad813a4
      Gergő Érdi authored
      We also add a new `ol_from_fun` field to renamed (but not yet
      typechecked) OverLits. This has the nice knock-on effect of making
      total some typechecker functions that used to be partial.
      Fixes #20151
  8. 11 Aug, 2021 3 commits
    • Alina Banerjee's avatar
      Modify InlineSpec data constructor (helps fix #18138) · 100ffe75
      Alina Banerjee authored
      The inl_inline field of the InlinePragma record is modified to store pragma
      source text by adding a data constructor of type SourceText. This can help in
      tracking the actual text of pragma names.
      Add/modify functions, modify type instance for InlineSpec type
      Modify parser, lexer to handle InlineSpec constructors containing SourceText
      Modify functions with InlineSpec type
      Extract pragma source from InlineSpec for SpecSig, InlineSig types
      Modify cvtInline function to add SourceText to InlineSpec type
      Extract name for InlineSig, SpecSig from pragma, SpectInstSig from source (fixes #18138)
      Extract pragma name for SpecPrag pragma, SpecSig signature
      Add Haddock annotation for inlinePragmaName function
      Add Haddock annotations for using helper functions in hsSigDoc
      Remove redundant ppr in pragma name for SpecSig, InlineSig; update comment
      Rename test to T18138 for misplaced SPECIALIZE pragma testcase
    • Sven Tennie's avatar
      Optimize Info Table Provenance Entries (IPEs) Map creation and lookup · f5fdace5
      Sven Tennie authored
      Using a hash map reduces the complexity of lookupIPE(), making it non linear.
      On registration each IPE list is added to a temporary IPE lists buffer, reducing
      registration time. The hash map is built lazily on first lookup.
      IPE event output to stderr is added with tests.
      For details, please see
      Note [The Info Table Provenance Entry (IPE) Map].
      A performance test for IPE registration and lookup can be found here:
      !5724 (comment 370806)
    • Moritz Angermann's avatar
      Update HACKING.md · c65a7ffa
      Moritz Angermann authored
  9. 10 Aug, 2021 4 commits
  10. 09 Aug, 2021 8 commits
    • Sylvain Henry's avatar
      Hadrian: fix .cabal file · 8b9acc4d
      Sylvain Henry authored
      `stack sdist` in the hadrian directory reported:
        Package check reported the following errors:
        To use the 'extra-doc-files' field the package needs to specify at
        least 'cabal-version: >= 1.18'.
    • John Ericson's avatar
      Move `/includes` to `/rts/include`, sort per package better · d5de970d
      John Ericson authored
      In order to make the packages in this repo "reinstallable", we need to
      associate source code with a specific packages. Having a top level
      `/includes` dir that mixes concerns (which packages' includes?) gets in
      the way of this.
      To start, I have moved everything to `rts/`, which is mostly correct.
      There are a few things however that really don't belong in the rts (like
      the generated constants haskell type, `CodeGen.Platform.h`). Those
      needed to be manually adjusted.
      Things of note:
       - No symlinking for sake of windows, so we hard-link at configure time.
       - `CodeGen.Platform.h` no longer as `.hs` extension (in addition to
         being moved to `compiler/`) so as not to confuse anyone, since it is
         next to Haskell files.
       - Blanket `-Iincludes` is gone in both build systems, include paths now
         more strictly respect per-package dependencies.
       - `deriveConstants` has been taught to not require a `--target-os` flag
         when generating the platform-agnostic Haskell type. Make takes
         advantage of this, but Hadrian has yet to.
    • John Ericson's avatar
      Make `PosixSource.h` installed and under `rts/` · fc350dba
      John Ericson authored
      is used outside of the rts so we do this rather than just fish it out of
      the repo in ad-hoc way, in order to make packages in this repo more
    • John Ericson's avatar
      Clean up whitespace in /includes · db7098fe
      John Ericson authored
      I need to do this now or when I move these files the linter will be mad.
    • Sylvain Henry's avatar
      Remove ad-hoc fromIntegral rules · 74863638
      Sylvain Henry authored
      fromIntegral is defined as:
        {-# NOINLINE [1] fromIntegral #-}
        fromIntegral :: (Integral a, Num b) => a -> b
        fromIntegral = fromInteger . toInteger
      Before this patch, we had a lot of rewrite rules for fromIntegral, to
      avoid passing through Integer when there is a faster way, e.g.:
        "fromIntegral/Int->Word"  fromIntegral = \(I# x#) -> W# (int2Word# x#)
        "fromIntegral/Word->Int"  fromIntegral = \(W# x#) -> I# (word2Int# x#)
        "fromIntegral/Word->Word" fromIntegral = id :: Word -> Word
      Since we have added sized types and primops (Word8#, Int16#, etc.) and
      Natural, this approach didn't really scale as there is a combinatorial
      explosion of types. In addition, we really want these conversions to be
      optimized for all these types and in every case (not only when
      fromIntegral is explicitly used).
      This patch removes all those ad-hoc fromIntegral rules. Instead we rely
      on inlining and built-in constant-folding rules. There are not too many
      native conversions between Integer/Natural and fixed size types, so we
      can handle them all explicitly.
      Foreign.C.Types was using rules to ensure that fromIntegral rules "sees"
      through the newtype wrappers,e.g.:
        {-# RULES
        "fromIntegral/a->CSize"      fromIntegral = \x -> CSize      (fromIntegral x)
        "fromIntegral/CSize->a"      fromIntegral = \(CSize      x) -> fromIntegral x
      But they aren't necessary because coercions due to newtype deriving are
      pushed out of the way. So this patch removes these rules (as
      fromIntegral is now inlined, they won't match anymore anyway).
      * INLINE `fromIntegral`
      * Add some missing constant-folding rules
      * Remove every fromIntegral ad-hoc rules (fix #19907)
      Fix #20062 (missing fromIntegral rules for sized primitives)
        - T12545 wiggles (tracked by #19414)
      Metric Decrease:
      Metric Increase:
    • Sylvain Henry's avatar
    • Ben Gamari's avatar
      rts: Fix use of sized array in Heap.h · 080ffd4b
      Ben Gamari authored
      Sized arrays cannot be used in headers that might be imported from C++.
      Fixes #20199.
    • Ben Gamari's avatar
      testsuite: Add test for #20199 · cf7e6c8d
      Ben Gamari authored
      Ensures that Rts.h can be parsed as C++.
  11. 08 Aug, 2021 1 commit