1. 21 Mar, 2020 2 commits
    • Richard Eisenberg's avatar
      Update core spec to reflect changes to Core. · 9a96ff6b
      Richard Eisenberg authored
      Key changes:
       * Adds a new rule for forall-coercions over coercion variables, which
      was implemented but conspicuously missing from the spec.
       * Adds treatment for FunCo.
       * Adds treatment for ForAllTy over coercion variables.
       * Improves commentary (including restoring a Note lost in
      03d48526) in the source.
      
      No changes to running code.
      9a96ff6b
    • Richard Eisenberg's avatar
      Simplify treatment of heterogeneous equality · 73a7383e
      Richard Eisenberg authored
      Previously, if we had a [W] (a :: k1) ~ (rhs :: k2), we would
      spit out a [D] k1 ~ k2 and part the W as irreducible, hoping for
      a unification. But we needn't do this. Instead, we now spit out
      a [W] co :: k2 ~ k1 and then use co to cast the rhs of the original
      Wanted. This means that we retain the connection between the
      spat-out constraint and the original.
      
      The problem with this new approach is that we cannot use the
      casted equality for substitution; it's too like wanteds-rewriting-
      wanteds. So, we forbid CTyEqCans that mention coercion holes.
      
      All the details are in Note [Equalities with incompatible kinds]
      in TcCanonical.
      
      There are a few knock-on effects, documented where they occur.
      
      While debugging an error in this patch, Simon and I ran into
      infelicities in how patterns and matches are printed; we made
      small improvements.
      
      This patch includes mitigations for #17828, which causes spurious
      pattern-match warnings. When #17828 is fixed, these lines should
      be removed.
      73a7383e
  2. 19 Mar, 2020 2 commits
  3. 18 Mar, 2020 1 commit
  4. 17 Mar, 2020 4 commits
    • Richard Eisenberg's avatar
      Fix #17021 by checking more return kinds · 53ff2cd0
      Richard Eisenberg authored
      All the details are in new Note [Datatype return kinds] in
      TcTyClsDecls.
      
      Test case: typecheck/should_fail/T17021{,b}
                 typecheck/should_compile/T17021a
      
      Updates haddock submodule
      53ff2cd0
    • Ömer Sinan Ağacan's avatar
      Don't update ModDetails with CafInfos when opts are disabled · 5800ebfe
      Ömer Sinan Ağacan authored
      This is consistent with the interface file behavior where we omit
      HsNoCafRefs annotations with -fomit-interface-pragmas (implied by -O0).
      
      ModDetails and ModIface are just different representations of the same
      thing, so they really need to be in sync. This patch does the right
      thing and does not need too much explanation, but here's an example of a
      problem not doing this causes in !2842:
      
          -- MyInteger.hs
          module MyInteger
            ( MyInteger (MyInteger)
            , ToMyInteger (toMyInteger)
            ) where
      
          newtype MyInteger = MyInteger Integer
      
          class ToMyInteger a where
            toMyInteger :: a -> MyInteger
      
          instance ToMyInteger Integer where
            toMyInteger = MyInteger {- . succ -}
      
          -- Main.hs
          module Main
            ( main
            ) where
      
          import MyInteger (MyInteger (MyInteger), toMyInteger)
      
          main :: IO ()
          main = do
            let (MyInteger i) = (id . toMyInteger) (41 :: Integer)
            print i
      
      If I build this with -O0, without this fix, we generate a ModDetails with
      accurate LFInfo for toMyInteger (MyInteger.$fToMyIntegerInteger) which says that
      it's a LFReEntrant with arity 1. This means in the use site (Main) we tag the
      value:
      
          R3 = MyInteger.$fToMyIntegerInteger_closure + 1;
          R2 = GHC.Base.id_closure;
          R1 = GHC.Base.._closure;
          Sp = Sp - 16;
          call stg_ap_ppp_fast(R4, R3, R2, R1) args: 24, res: 0, upd: 24;
      
      Now we change the definition by uncommenting the `succ` part and it becomes a thunk:
      
          MyInteger.$fToMyIntegerInteger [InlPrag=INLINE (sat-args=0)]
            :: MyInteger.ToMyInteger GHC.Integer.Type.Integer
          [GblId[DFunId(nt)]] =
              {} \u [] $ctoMyInteger_rEA;
      
      and its LFInfo is now LFThunk. This change in LFInfo makes a difference in the
      use site: we can no longer tag it.
      
      But becuase the interface fingerprint does not change (because ModIface does not
      change) we don't rebuild Main and tag the thunk.
      
      (1.2% increase in allocations when building T12545 on armv7 because we
      generate more code without CafInfos)
      
      Metric Increase:
          T12545
      5800ebfe
    • Simon Peyton Jones's avatar
      Implement mapTyCo like foldTyCo · beffa147
      Simon Peyton Jones authored
      This patch makes mapType use the successful idiom described
      in TyCoRep
         Note [Specialising foldType]
      
      I have not yet changed any functions to use mapType, though there
      may be some suitable candidates.
      
      This patch should be a no-op in terms of functionality but,
      because it inlines the mapper itself, I'm hoping that there may
      be some modest perf improvements.
      
      Metric Decrease:
          T5631
          T5642
          T3064
          T9020
          T14683
          hie002
          haddock.Cabal
          haddock.base
          haddock.compiler
      beffa147
    • Sylvain Henry's avatar
      Modules: Core (#13009) · 18a346a4
      Sylvain Henry authored
      Update submodule: haddock
      18a346a4
  5. 15 Mar, 2020 3 commits
    • Judah Jacobson's avatar
      Add a -no-haddock flag. · c35c545d
      Judah Jacobson authored
      This flag undoes the effect of a previous "-haddock" flag.  Having both flags makes it easier
      for build systems to enable Haddock parsing in a set of global flags, but then disable it locally for
      specific targets (e.g., third-party packages whose comments don't pass the validation in the latest GHC).
      
      I added the flag to expected-undocumented-flags.txt since `-haddock` was alreadyin that list.
      c35c545d
    • Sylvain Henry's avatar
      Refactor CmmToAsm (disentangle DynFlags) · 2e82465f
      Sylvain Henry authored
      This patch disentangles a bit more DynFlags from the native code
      generator (CmmToAsm).
      
      In more details:
      
      - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the
        configuration of a native code generation session
      - explicitly pass NCGConfig/Platform arguments when necessary
      - as a consequence `sdocWithPlatform` is gone and there are only a few
        `sdocWithDynFlags` left
      - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG
      - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig)
      
      There are still some places where DynFlags is used, especially because
      of pretty-printing (CLabel), because of Cmm helpers (such as
      `cmmExprType`) and because of `Outputable` instance for the
      instructions. These are left for future refactoring as this patch is
      already big.
      2e82465f
    • Brian Foley's avatar
      Remove some dead code · b4774598
      Brian Foley authored
      From the notes.ghc.drop list found using weeder in #17713
      b4774598
  6. 14 Mar, 2020 4 commits
    • Krzysztof Gogolewski's avatar
      1de3ab4a
    • Simon Peyton Jones's avatar
      Improve CSE.combineAlts · 88f7a762
      Simon Peyton Jones authored
      This patch improves the way that CSE combines identical
      alternatives.  See #17901.
      
      I'm still not happy about the duplication between CSE.combineAlts
      and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those
      functions.  But this patch is a step forward.
      
      Metric Decrease:
          T12425
          T5642
      88f7a762
    • Simon Peyton Jones's avatar
      Simple refactor of cheapEqExpr · 2f8c7767
      Simon Peyton Jones authored
      No change in functionality.  Just seems tidier (and signficantly more
      efficient) to deal with ticks directly than to call stripTicksTopE.
      2f8c7767
    • Simon Peyton Jones's avatar
      Fix Lint · c12a2ec5
      Simon Peyton Jones authored
      Ticket #17590 pointed out a bug in the way the linter dealt with
      type lets, exposed by the new uniqAway story.
      
      The fix is described in Note [Linting type lets]. I ended up
      putting the in-scope Ids in a different env field, le_ids,
      rather than (as before) sneaking them into the TCvSubst.
      
      Surprisingly tiresome, but done.
      
      Metric Decrease:
          hie002
      c12a2ec5
  7. 13 Mar, 2020 1 commit
    • Sylvain Henry's avatar
      Rename isDllName · 44fad4a9
      Sylvain Henry authored
      I wanted to fix the dangling comment in `isDllName` ("This is the cause
      of #", #8696 is already mentioned earlier). I took the opportunity to
      change the function name to better reflect what it does.
      44fad4a9
  8. 12 Mar, 2020 6 commits
    • Simon Peyton Jones's avatar
      Expose compulsory unfoldings always · 3a259092
      Simon Peyton Jones authored
      The unsafeCoerce# patch requires that unsafeCoerce# has
      a compulsory unfolding that is always available.  So we have
      to be careful to expose compulsory unfoldings unconditionally
      and consistently.
      
      We didn't get this quite right: #17871.  This patch fixes
      it.  No real surprises here.
      
      See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy
      3a259092
    • Kirill Elagin's avatar
      pretty-printer: Do not print ApplicativeDo join · 5cb93af7
      Kirill Elagin authored
      * Do not print `join` in ApplictiveStmt, unless ppr-debug
      * Print parens around multiple parallel binds
      
      When ApplicativeDo is enabled, the renamer analyses the statements of a
      `do` block and in certain cases marks them as needing to be rewritten
      using `join`.
      
      For example, if you have:
      
      ```
      foo = do
        a <- e1
        b <- e2
        doSomething a b
      ```
      
      it will be desugared into:
      
      ```
      foo = join (doSomething <$> e1 <*> e2)
      ```
      
      After renaming but before desugaring the expression is stored
      essentially as:
      
      ```
      foo = do
        [will need join] (a <- e1 | b <- e2)
        [no return] doSomething a b
      ```
      
      Before this change, the pretty printer would print a call to `join`,
      even though it is not needed at this stage at all. The expression will be
      actually rewritten into one using join only at desugaring, at which
      point a literal call to join will be inserted.
      5cb93af7
    • Kirill Elagin's avatar
      pretty-printer: Properly parenthesise LastStmt · 1f9db3e7
      Kirill Elagin authored
      After ApplicatveDo strips the last `return` during renaming, the pretty
      printer has to restore it. However, if the return was followed by `$`,
      the dollar was stripped too and not restored.
      
      For example, the last stamement in:
      
      ```
        foo = do
          x <- ...
          ...
          return $ f x
      ```
      
      would be printed as:
      
      ```
          return f x
      ```
      
      This commit preserved the dolar, so it becomes:
      
      ```
          return $ f x
      ```
      1f9db3e7
    • Sylvain Henry's avatar
      Use a Set to represent Ways · a6989971
      Sylvain Henry authored
      Should make `member` queries faster and avoid messing up with missing
      `nubSort`.
      
      Metric Increase:
          hie002
      a6989971
    • Sylvain Henry's avatar
      Refactor interpreterDynamic and interpreterProfiled · bc41e471
      Sylvain Henry authored
      * `interpreterDynamic` and `interpreterProfiled` now take `Interp`
        parameters instead of DynFlags
      
      * slight refactoring of `ExternalInterp` so that we can read the iserv
        configuration (which is pure) without reading an MVar.
      bc41e471
    • Sylvain Henry's avatar
      Refactor GHC.Driver.Session (Ways and Flags) · 8e6febce
      Sylvain Henry authored
      * extract flags and ways into their own modules (with some renaming)
      
      * remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases
      
      * when GHC uses dynamic linking (WayDyn), `interpWays` was only
        reporting WayDyn even if the host was profiled (WayProf).  Now it
        returns both as expected (might fix #16803).
      
      * `mkBuildTag :: [Way] -> String` wasn't reporting a canonical tag for
        differently ordered lists. Now we sort and nub the list to fix this.
      8e6febce
  9. 11 Mar, 2020 1 commit
    • Sylvain Henry's avatar
      Split GHC.Iface.Utils module · 20800b9a
      Sylvain Henry authored
      * GHC.Iface.Recomp: recompilation avoidance stuff
      * GHC.Iface.Make: mkIface*
      
      Moved `writeIfaceFile` into GHC.Iface.Load alongside `readIface` and
      renamed it `writeIface` for consistency.
      20800b9a
  10. 10 Mar, 2020 3 commits
    • Krzysztof Gogolewski's avatar
      Typos in comments [skip ci] · abf5736b
      Krzysztof Gogolewski authored
      abf5736b
    • Krzysztof Gogolewski's avatar
      Misc cleanup · 3300eeac
      Krzysztof Gogolewski authored
      - Remove Note [Existentials in shift_con_pat].
        The function shift_con_pat has been removed 15 years ago in 23f40f0e.
      - Remove kcLookupTcTyCon - it's the same as tcLookupTcTyCon
      - Remove ASSERT in tyConAppArgN. It's already done by getNth,
        and it's the only reason getNth exists.
      - Remove unused function nextRole
      3300eeac
    • Ben Price's avatar
      Clarify a Lint message · 5ba01d83
      Ben Price authored
      When developing a plugin I had a shadowing problem, where I generated
      code
        app = \f{v r7B} x{v r7B} -> f{v r7B} x{v r7B}
      This is obviously wrong, since the occurrence of `f` to the right of the
      arrow refers to the `x` binder (they share a Unique). However, it is
      rather confusing when Lint reports
        Mismatch in type between binder and occurrence
        Var: x{v rB7}
      since it is printing the binder, rather than the occurrence.
      It is rather easy to read this as claiming there is something wrong with
      the `x` occurrence!
      
      We change the report to explicitly print both the binder and the
      occurrence variables.
      5ba01d83
  11. 09 Mar, 2020 1 commit
  12. 02 Mar, 2020 2 commits
    • Roland Senn's avatar
      Set `ImpredicativeTypes` during :print command. (#14828) · 7c0c76fb
      Roland Senn authored
      If ImpredicativeTypes is not enabled, then `:print <term>` will fail if the
      type of <term> has nested `forall`s or `=>`s.
      This is because the GHCi debugger's internals will attempt to unify a
      metavariable with the type of <term> and then display the result, but if the
      type has nested `forall`s or `=>`s, then unification will fail.
      As a result, `:print` will bail out and the unhelpful result will be
      `<term> = (_t1::t1)` (where `t1` is a metavariable).
      
      Beware: <term> can have nested `forall`s even if its definition doesn't use
      RankNTypes! Here is an example from #14828:
      
        class Functor f where
          fmap :: (a -> b) -> f a -> f b
      
      Somewhat surprisingly, `:print fmap` considers the type of fmap to have
      nested foralls. This is because the GHCi debugger sees the type
      `fmap :: forall f. Functor f => forall a b. (a -> b) -> f a -> f b`.
      We could envision deeply instantiating this type to get the type
      `forall f a b. Functor f => (a -> b) -> f a -> f b`,
      but this trick wouldn't work for higher-rank types.
      
      Instead, we adopt a simpler fix: enable `ImpredicativeTypes` when using
      `:print` and friends in the GHCi debugger. This is allows metavariables
      to unify with types that have nested (or higher-rank) `forall`s/`=>`s,
      which makes `:print fmap` display as
      `fmap = (_t1::forall a b. Functor f => (a -> b) -> f a -> f b)`, as expected.
      
      Although ImpredicativeTypes is a somewhat unpredictable from a type inference
      perspective, there is no danger in using it in the GHCi debugger, since all
      of the terms that the GHCi debugger deals with have already been typechecked.
      7c0c76fb
    • Krzysztof Gogolewski's avatar
      Remove dead code · 3cf7303b
      Krzysztof Gogolewski authored
      * The names in PrelName and THNames are no longer used
        since TH merged types and kinds, Typeable is kind-polymorphic,
        .net support was removed
      * unqualQuasiQuote no longer used since 6f8ff0bb
      3cf7303b
  13. 29 Feb, 2020 6 commits
    • Roland Senn's avatar
      Show breakpoint locations of breakpoints which were ignored during :force (#2950) · 3979485b
      Roland Senn authored
      GHCi is split up into 2 major parts: The user-interface (UI)
      and the byte-code interpreter. With `-fexternal-interpreter`
      they even run in different processes. Communication between
      the UI and the Interpreter (called `iserv`) is done using
      messages over a pipe. This is called `Remote GHCI` and
      explained in the Note [Remote GHCi] in `compiler/ghci/GHCi.hs`.
      
      To process a `:force` command the UI sends a `Seq` message
      to the `iserv` process. Then `iserv` does the effective
      evaluation of the value. When during this process a breakpoint
      is hit, the `iserv` process has no additional information to
      enhance the `Ignoring breakpoint` output with the breakpoint
      location.
      
      To be able to print additional breakpoint information,
      there are 2 possible implementation choices:
      1. Store the needed information in the `iserv` process.
      2. Print the `Ignoring breakpoint` from the UI process.
      
      For option 1 we need to store the breakpoint info redundantely
      in 2 places and this is bad. Therfore option 2 was implemented
      in this MR:
      - The user enters a `force` command
      - The UI sends  a `Seq` message to the `iserv` process.
      - If processing of the `Seq` message hits a breakpoint,
        the `iserv` process returns control to the UI process.
      - The UI looks up the source location of the breakpoint,
        and prints the enhanced `Ignoring breakpoint` output.
      - The UI sends a `ResumeSeq` message to the `iserv` process,
        to continue forcing.
      3979485b
    • Ömer Sinan Ağacan's avatar
      Simplify IfaceIdInfo type · 04d30137
      Ömer Sinan Ağacan authored
      IfaceIdInfo type is confusing: there's practically no difference between
      `NoInfo` and `HasInfo []`. The comments say NoInfo is used when
      -fomit-interface-pragmas is enabled, but we don't need to distinguish
      `NoInfo` from `HasInfo []` in when reading the interface so the
      distinction is not important.
      
      This patch simplifies the type by removing NoInfo. When we have no info
      we use an empty list.
      
      With this change we no longer read the info list lazily when reading an
      IfaceInfoItem, but when reading an IfaceId the ifIdInfo field is
      read lazily, so I doubt this is going to be a problem.
      04d30137
    • Sylvain Henry's avatar
      Refactor runtime interpreter code · 18757cab
      Sylvain Henry authored
      In #14335 we want to be able to use both the internal interpreter (for
      the plugins) and the external interpreter (for TH and GHCi) at the same
      time.
      
      This patch performs some preliminary refactoring: the `hsc_interp` field
      of HscEnv replaces `hsc_iserv` and is now used to indicate which
      interpreter (internal, external) to use to execute TH and GHCi.
      
      Opt_ExternalInterpreter flag and iserv options in DynFlags are now
      queried only when we set the session DynFlags. It should help making GHC
      multi-target in the future by selecting an interpreter according to the
      selected target.
      18757cab
    • Ömer Sinan Ağacan's avatar
      Document and refactor a few things around bitmap scavenging · b5fb58fd
      Ömer Sinan Ağacan authored
      - Added a few comments in StgPAP
      - Added a few comments and assertions in scavenge_small_bitmap and
        walk_large_bitmap
      - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted
        dead code, used PlatformWordSize type.
      b5fb58fd
    • Ben Gamari's avatar
      plugins: Ensure that loadInterface plugins can see annotations · 99d2de86
      Ben Gamari authored
      loadInterface replaces the `mi_decls`, `mi_insts`, `mi_fam_insts`,
      `mi_rules`, `mi_anns` fields of ModIface with `undefined` before
      inserting the interface into the EPS. However, we still want to give
      loadInterface plugins access to these fields. Consequently, we want to
      pass the unmodified `ModIface` the plugin.
      99d2de86
    • Vladislav Zavialov's avatar
      Monotonic locations (#17632) · 327b29e1
      Vladislav Zavialov authored
      When GHC is parsing a file generated by a tool, e.g. by the C preprocessor, the
      tool may insert #line pragmas to adjust the locations reported to the user.
      
      As the result, the locations recorded in RealSrcLoc are not monotonic. Elements
      that appear later in the StringBuffer are not guaranteed to have a higher
      line/column number.
      
      In fact, there are no guarantees whatsoever, as #line pragmas can arbitrarily
      modify locations. This lack of guarantees makes ideas such as #17544
      infeasible.
      
      This patch adds an additional bit of information to every SrcLoc:
      
      	newtype BufPos = BufPos { bufPos :: Int }
      
      A BufPos represents the location in the StringBuffer, unaffected by any
      pragmas.
      
      Updates haddock submodule.
      
      Metric Increase:
          haddock.Cabal
          haddock.base
          haddock.compiler
          MultiLayerModules
          Naperian
          parsing001
          T12150
      327b29e1
  14. 27 Feb, 2020 1 commit
    • Sebastian Graf's avatar
      PmCheck: Implement Long-distance information with Covered sets · 74311e10
      Sebastian Graf authored
      Consider
      
      ```hs
      data T = A | B | C
      
      f :: T -> Int
      f A = 1
      f x = case x of
        A -> 2
        B -> 3
        C -> 4
      ```
      
      Clearly, the RHS returning 2 is redundant. But we don't currently see
      that, because our approximation to the covered set of the inner case
      expression just picks up the positive information from surrounding
      pattern matches. It lacks the context sensivity that `x` can't be `A`
      anymore!
      
      Therefore, we adopt the conceptually and practically superior approach
      of reusing the covered set of a particular GRHS from an outer pattern
      match. In this case, we begin checking the `case` expression with the
      covered set of `f`s second clause, which encodes the information that
      `x` can't be `A` anymore. After this MR, we will successfully warn about
      the RHS returning 2 being redundant.
      
      Perhaps surprisingly, this was a great simplification to the code of
      both the coverage checker and the desugarer.
      
      Found a redundant case alternative in `unix` submodule, so we have to
      bump it with a fix.
      
      Metric Decrease:
          T12227
      74311e10
  15. 26 Feb, 2020 3 commits