1. 26 Mar, 2020 1 commit
  2. 25 Mar, 2020 1 commit
    • Roland Senn's avatar
      Use export list of Main module in function TcRnDriver.hs:check_main (Fix #16453) · 703221f4
      Roland Senn authored
      - Provide the export list of the `Main` module as parameter to the
        `compiler/typecheck/TcRnDriver.hs:check_main` function.
      - Instead of `lookupOccRn_maybe` call the function `lookupInfoOccRn`.
        It returns the list `mains_all` of all the main functions in scope.
      - Select from this list `mains_all` all `main` functions that are in
        the export list of the `Main` module.
      - If this new list contains exactly one single `main` function, then
        typechecking continues.
      - Otherwise issue an appropriate error message.
      703221f4
  3. 23 Mar, 2020 5 commits
  4. 21 Mar, 2020 1 commit
    • 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
  5. 18 Mar, 2020 1 commit
  6. 17 Mar, 2020 2 commits
  7. 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
    • Krzysztof Gogolewski's avatar
      Document restriction on SCC pragma syntax · d30aeb4b
      Krzysztof Gogolewski authored
      Currently, the names of cost centres must be quoted or
      be lowercase identifiers.
      
      Fixes #17916.
      d30aeb4b
  8. 14 Mar, 2020 4 commits
    • Krzysztof Gogolewski's avatar
      1de3ab4a
    • 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
      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
  9. 12 Mar, 2020 4 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
  10. 11 Mar, 2020 2 commits
    • Ben Gamari's avatar
      testsuite: Mark ghci056 and ghcilink004 as fragile in unreg · 336eac7e
      Ben Gamari authored
      As noted in #17018.
      
      Also fix fragile declaration of T13786, which only runs in the normal
      way.
      336eac7e
    • 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
  11. 10 Mar, 2020 4 commits
  12. 09 Mar, 2020 1 commit
  13. 02 Mar, 2020 1 commit
    • 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
  14. 29 Feb, 2020 4 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
    • 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
    • Simon Peyton Jones's avatar
      Improve error handling for VTA + deferred type errors · 66f5d6d6
      Simon Peyton Jones authored
      This fixes #17792
      
      See Note [VTA for out-of-scope functions] in TcExpr
      66f5d6d6
  15. 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
  16. 26 Feb, 2020 5 commits