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 3 commits
    • Ömer Sinan Ağacan's avatar
      FastString: fix eager reading of string ptr in hashStr · cb1785d9
      Ömer Sinan Ağacan authored
      This read causes NULL dereferencing when len is 0.
      
      Fixes #17909
      
      In the reproducer in #17909 this bug is triggered as follows:
      
      - SimplOpt.dealWithStringLiteral is called with a single-char string
        ("=" in #17909)
      
      - tailFS gets called on the FastString of the single-char string.
      
      - tailFS checks the length of the string, which is 1, and calls
        mkFastStringByteString on the tail of the ByteString, which is an
        empty ByteString as the original ByteString has only one char.
      
      - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty
        ByteString, which is passed to mkFastStringWith.
      
      - mkFastStringWith gets hash of the NULL pointer via hashStr, which
        fails on empty strings because of this bug.
      cb1785d9
    • Sylvain Henry's avatar
      Refactoring: use Platform instead of DynFlags when possible · 64f20756
      Sylvain Henry authored
      Metric Decrease:
          ManyConstructors
          T12707
          T13035
          T1969
      64f20756
    • Sebastian Graf's avatar
      PmCheck: Use ConLikeSet to model negative info · b03fd3bc
      Sebastian Graf authored
      In #17911, Simon recognised many warnings stemming from over-long list
      unions while coverage checking Cabal's `LicenseId` module.
      
      This patch introduces a new `PmAltConSet` type which uses a `UniqDSet`
      instead of an association list for `ConLike`s. For `PmLit`s, it will
      still use an assocation list, though, because a similar map data
      structure would entail a lot of busy work.
      
      Fixes #17911.
      b03fd3bc
  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 7 commits
    • Krzysztof Gogolewski's avatar
      1de3ab4a
    • Vladislav Zavialov's avatar
      Remove second tcLookupTcTyCon in tcDataDefn · bee4cdad
      Vladislav Zavialov authored
      Before this patch, tcDataDefn used to call tcLookupTcTyCon twice in a row:
      	1. in bindTyClTyVars itself
      	2. in the continuation passed to it
      
      Now bindTyClTyVars passes the TcTyCon to the continuation, making
      the second lookup unnecessary.
      bee4cdad
    • Simon Peyton Jones's avatar
      Refactoring in TcSMonad · 73133a3b
      Simon Peyton Jones authored
      This patch is just refactoring: no change in
      behaviour.
      
      I removed the rather complicated
          checkConstraintsTcS
          checkTvConstraintsTcS
      
      in favour of simpler functions
          emitImplicationTcS
          emitTvImplicationTcS
          pushLevelNoWorkList
      
      The last of these is a little strange, but overall
      it's much better I think.
      73133a3b
    • Simon Peyton Jones's avatar
      Wrap an implication around class-sig kind errors · e3c374cc
      Simon Peyton Jones authored
      Ticket #17841 showed that we can get a kind error
      in a class signature, but lack an enclosing implication
      that binds its skolems.
      
      This patch
      
      * Adds the wrapping implication: the new call to
        checkTvConstraints in tcClassDecl1
      
      * Simplifies the API to checkTvConstraints, which
        was not otherwise called at all.
      
      * Simplifies TcErrors.report_unsolved by *not*
        initialising the TidyEnv from the typechecker lexical
        envt.  It's enough to do so from the free vars of the
        unsolved constraints; and we get silly renamings if
        we add variables twice: once from the lexical scope
        and once from the implication constraint.
      e3c374cc
    • 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 7 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
    • Ryan Scott's avatar
      Make DeriveFunctor-generated code require fewer beta reductions · cb93a1a4
      Ryan Scott authored
      Issue #17880 demonstrates that `DeriveFunctor`-generated code is
      surprisingly fragile when rank-_n_ types are involved. The culprit is
      that `$fmap` (the algorithm used to generate `fmap` implementations)
      was too keen on applying arguments with rank-_n_ types to lambdas,
      which fail to typecheck more often than not.
      
      In this patch, I change `$fmap` (both the specification and the
      implementation) to produce code that avoids creating as many lambdas,
      avoiding problems when rank-_n_ field types arise.
      See the comments titled "Functor instances" in `TcGenFunctor` for a
      more detailed description. Not only does this fix #17880, but it also
      ensures that the code that `DeriveFunctor` generates will continue
      to work after simplified subsumption is implemented (see #17775).
      
      What is truly amazing is that #17880 is actually a regression
      (introduced in GHC 7.6.3) caused by commit
      49ca2a37, the fix #7436. Prior to
      that commit, the version of `$fmap` that was used was almost
      identical to the one used in this patch! Why did that commit change
      `$fmap` then? It was to avoid severe performance issues that would
      arise for recursive `fmap` implementations, such as in the example
      below:
      
      ```hs
      data List a = Nil | Cons a (List a) deriving Functor
      
      -- ===>
      
      instance Functor List where
        fmap f Nil = Nil
        fmap f (Cons x xs) = Cons (f x) (fmap (\y -> f y) xs)
      ```
      
      The fact that `\y -> f y` was eta expanded caused significant
      performance overheads. Commit
      49ca2a37 fixed this performance
      issue, but it went too far. As a result, this patch partially
      reverts 49ca2a37.
      
      To ensure that the performance issues pre-#7436 do not resurface,
      I have taken some precautionary measures:
      
      * I have added a special case to `$fmap` for situations where the
        last type variable in an application of some type occurs directly.
        If this special case fires, we avoid creating a lambda expression.
        This ensures that we generate
        `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived
        `Functor List` instance above. For more details, see
        `Note [Avoid unnecessary eta expansion in derived fmap implementations]`
        in `TcGenFunctor`.
      * I have added a `T7436b` test case to ensure that the performance
        of this derived `Functor List`-style code does not regress.
      
      When implementing this, I discovered that `$replace`, the algorithm
      which generates implementations of `(<$)`, has a special case that is
      very similar to the `$fmap` special case described above. `$replace`
      marked this special case with a custom `Replacer` data type, which
      was a bit overkill. In order to use the same machinery for both
      `Functor` methods, I ripped out `Replacer` and instead implemented
      a simple way to detect the special case. See the updated commentary
      in `Note [Deriving <$]` for more details.
      cb93a1a4
    • 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 3 commits
    • Simon Peyton Jones's avatar
      Deepen call stack for isIn · c61b9b02
      Simon Peyton Jones authored
      I see quite a few warnings like:
      
        WARNING: file compiler/utils/Util.hs, line 593
          Over-long elem in unionLists
      
      But the call stack is uninformative.   Better to add HasDebugCallStack
      to isIn.  Ditto isn'tIn.
      c61b9b02
    • Ryan Scott's avatar
      Re-quantify when generalising over rewrite rule types · 0bc23338
      Ryan Scott authored
      Previously, `tcRules` would check for naughty quantification
      candidates (see `Note [Naughty quantification candidates]` in
      `TcMType`) when generalising over the type of a rewrite rule. This
      caused sensible-looking rewrite rules (like those in #17710) to be
      rejected. A more permissing (and easier-to-implement) approach is to
      do what is described in `Note [Generalising in tcTyFamInstEqnGuts]`
      in `TcTyClsDecls`: just re-quantify all the type variable binders,
      regardless of the order in which the user specified them. After all,
      the notion of type variable specificity has no real meaning in
      rewrite rules, since one cannot "visibly apply" a rewrite rule.
      I have written up this wisdom in
      `Note [Re-quantify type variables in rules]` in `TcRules`.
      
      As a result of this patch, compiling the `ExplicitForAllRules1` test
      case now generates one fewer warning than it used to. As far as I can
      tell, this is benign, since the thing that the disappearing warning
      talked about was also mentioned in an entirely separate warning.
      
      Fixes #17710.
      0bc23338
    • 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 6 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
    • Simon Peyton Jones's avatar
      Comments only · 7b2c827b
      Simon Peyton Jones authored
      Clarify code added in #17852 and MR !2724
      7b2c827b
    • 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
    • Richard Eisenberg's avatar
      anyRewritableTyVar now looks in RuntimeReps · 5fa9cb82
      Richard Eisenberg authored
      Previously, anyRewritableTyVar looked only at the arg and res
      of `arg -> res`, but their RuntimeReps are also subject to
      rewriting. Easy to fix.
      
      Test case: typecheck/should_compile/T17024
      
      Fixes #17024.
      5fa9cb82
    • Ben Gamari's avatar
      SysTools: Ensure that error parser can handle absolute paths on Windows · 70b50778
      Ben Gamari authored
      This fixes #17786, where the error parser fails to correctly handle the
      drive name in absolute Windows paths.
      
      Unfortunately I couldn't find a satisfactory way to test this.
      70b50778
  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