1. 07 Apr, 2020 1 commit
  2. 04 Apr, 2020 1 commit
  3. 02 Apr, 2020 1 commit
    • Ryan Scott's avatar
      Fix two ASSERT buglets in reifyDataCon · 30a63e79
      Ryan Scott authored
      Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but
      `arg_tys` is not meaningful for GADT constructors. In fact, it's
      worse than non-meaningful, since using `arg_tys` when reifying a
      GADT constructor can lead to failed `ASSERT`ions, as #17305
      demonstrates.
      
      This patch applies the simplest possible fix to the immediate
      problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as
      the former makes sure to give something meaningful for GADT
      constructors. This makes the panic go away at the very least. There
      is still an underlying issue with the way the internals of
      `reifyDataCon` work, as described in
      #17305 (comment 227023), but we
      leave that as future work, since fixing the underlying issue is
      much trickier (see
      #17305 (comment 227087)).
      30a63e79
  4. 01 Apr, 2020 1 commit
    • Ryan Scott's avatar
      Clean up "Eta reduction for data families" Notes · 9b39f2e6
      Ryan Scott authored
      Before, there were two distinct Notes named
      "Eta reduction for data families". This renames one of them to
      "Implementing eta reduction for data families" to disambiguate the
      two and fixes references in other parts of the codebase to ensure
      that they are pointing to the right place.
      
      Fixes #17313.
      
      [ci skip]
      9b39f2e6
  5. 31 Mar, 2020 1 commit
    • Ryan Scott's avatar
      Require GHC 8.8 as the minimum compiler for bootstrapping · 57b888c0
      Ryan Scott authored
      This allows us to remove several bits of CPP that are either always
      true or no longer reachable. As an added bonus, we no longer need to
      worry about importing `Control.Monad.Fail.fail` qualified to avoid
      clashing with `Control.Monad.fail`, since the latter is now the same
      as the former.
      57b888c0
  6. 29 Mar, 2020 4 commits
    • Krzysztof Gogolewski's avatar
      Minor cleanup · 45eb9d8c
      Krzysztof Gogolewski authored
      - Simplify mkBuildExpr, the function newTyVars was called
        only on a one-element list.
      - TTG: use noExtCon in more places. This is more future-proof.
      - In zonkExpr, panic instead of printing a warning.
      45eb9d8c
    • Ryan Scott's avatar
      Run checkNewDataCon before constraint-solving newtype constructors · a0d8e92e
      Ryan Scott authored
      Within `checkValidDataCon`, we used to run `checkValidType` on the
      argument types of a newtype constructor before running
      `checkNewDataCon`, which ensures that the user does not attempt
      non-sensical things such as newtypes with multiple arguments or
      constraints. This works out in most situations, but this falls over
      on a corner case revealed in #17955:
      
      ```hs
      newtype T = Coercible () T => T ()
      ```
      
      `checkValidType`, among other things, peforms an ambiguity check on
      the context of a data constructor, and that it turn invokes the
      constraint solver. It turns out that there is a special case in the
      constraint solver for representational equalities (read: `Coercible`
      constraints) that causes newtypes to be unwrapped (see
      `Note [Unwrap newtypes first]` in `TcCanonical`). This special case
      does not know how to cope with an ill formed newtype like `T`, so
      it ends up panicking.
      
      The solution is surprisingly simple: just invoke `checkNewDataCon`
      before `checkValidType` to ensure that the illicit newtype
      constructor context is detected before the constraint solver can
      run amok with it.
      
      Fixes #17955.
      a0d8e92e
    • Sylvain Henry's avatar
      Store ComponentId details · e54500c1
      Sylvain Henry authored
      As far as GHC is concerned, installed package components ("units") are
      identified by an opaque ComponentId string provided by Cabal. But we
      don't want to display it to users (as it contains a hash) so GHC queries
      the database to retrieve some infos about the original source package
      (name, version, component name).
      
      This patch caches these infos in the ComponentId itself so that we don't
      need to provide DynFlags (which contains installed package informations)
      to print a ComponentId.
      
      In the future we want GHC to support several independent package states
      (e.g. for plugins and for target code), hence we need to avoid
      implicitly querying a single global package state.
      e54500c1
    • Sylvain Henry's avatar
      Modules: Types (#13009) · 1941ef4f
      Sylvain Henry authored
      Update Haddock submodule
      
      Metric Increase:
         haddock.compiler
      1941ef4f
  7. 26 Mar, 2020 1 commit
    • Sylvain Henry's avatar
      DynFlags refactoring III · 0de03cd7
      Sylvain Henry authored
      Use Platform instead of DynFlags when possible:
      * `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al.
      * no more DynFlags in PreRules: added a new `RuleOpts` datatype
      * don't use `wORD_SIZE` in the compiler
      * make `wordAlignment` use `Platform`
      * make `dOUBLE_SIZE` a constant
      
      Metric Decrease:
          T13035
          T1969
      0de03cd7
  8. 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
  9. 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
  10. 18 Mar, 2020 1 commit
  11. 17 Mar, 2020 3 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
    • 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
  12. 15 Mar, 2020 1 commit
  13. 14 Mar, 2020 4 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
  14. 12 Mar, 2020 2 commits
    • 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
      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
  15. 11 Mar, 2020 2 commits
    • 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
  16. 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
    • 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
  17. 09 Mar, 2020 1 commit
  18. 29 Feb, 2020 3 commits
    • 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
    • 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
  19. 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
  20. 26 Feb, 2020 2 commits
  21. 25 Feb, 2020 1 commit
    • Krzysztof Gogolewski's avatar
      Comments, small refactor · 354e2787
      Krzysztof Gogolewski authored
      * Remove outdated Note [HsForAllTy tyvar binders] and [Context quantification].
        Since the wildcard refactor 1e041b73, HsForAllTy no longer has an flag
        controlling explicity. The field `hsq_implicit` is gone too.
        The current situation is covered by Note [HsType binders] which is already
        linked from LHsQTyVars.
      * Small refactor in CoreLint, extracting common code to a function
      * Remove "not so sure about WpFun" in TcEvidence, per Richard's comment
        !852 (comment 223226)
      * Use mkIfThenElse in Foreign/Call, as it does exactly what we need.
      354e2787
  22. 24 Feb, 2020 1 commit
    • Vladislav Zavialov's avatar
      Remove Ord SrcLoc, Ord SrcSpan · 26e8fff3
      Vladislav Zavialov authored
      Before this patch, GHC relied on Ord SrcSpan to identify source elements, by
      using SrcSpan as Map keys:
      
      	blackList :: Map SrcSpan ()      -- compiler/GHC/HsToCore/Coverage.hs
      	instanceMap :: Map SrcSpan Name  -- compiler/GHC/HsToCore/Docs.hs
      
      Firstly, this design is not valid in presence of UnhelpfulSpan, as it
      distinguishes between  UnhelpfulSpan "X"  and  UnhelpfulSpan "Y", but those
      strings are messages for the user, unfit to serve as identifiers for source
      elements.
      
      Secondly, this design made it hard to extend SrcSpan with additional data.
      Recall that the definition of SrcSpan is:
      
      	data SrcSpan =
      	    RealSrcSpan !RealSrcSpan
      	  | UnhelpfulSpan !FastString
      
      Say we want to extend the RealSrcSpan constructor with additional information:
      
      	data SrcSpan =
      	    RealSrcSpan !RealSrcSpan !AdditionalInformation
      	  | UnhelpfulSpan !FastString
      
      	getAdditionalInformation :: SrcSpan -> AdditionalInformation
      	getAdditionalInformation (RealSrcSpan _ a) = a
      
      Now, in order for  Map SrcSpan  to keep working correctly, we must *ignore* additional
      information when comparing SrcSpan values:
      
      	instance Ord SrcSpan where
      	  compare (RealSrcSpan r1 _) (RealSrcSpan r2 _) = compare r1 r2
      	  ...
      
      However, this would violate an important law:
      
      	a == b  therefore  f a == f b
      
      Ignoring  AdditionalInformation  in comparisons would mean that with
      f=getAdditionalInformation, the law above does not hold.
      
      A more robust design is to avoid  Ord SrcSpan  altogether, which is what this patch implements.
      The mappings are changed to use RealSrcSpan instead:
      
      	blackList :: Set RealSrcSpan         -- compiler/GHC/HsToCore/Coverage.hs
      	instanceMap :: Map RealSrcSpan Name  -- compiler/GHC/HsToCore/Docs.hs
      
      All SrcSpan comparisons are now done with explicit comparison strategies:
      
      	SrcLoc.leftmost_smallest
      	SrcLoc.leftmost_largest
      	SrcLoc.rightmost_smallest
      
      These strategies are not subject to the law mentioned above and can easily
      discard both the string stored in  UnhelpfulSpan  and  AdditionalInformation.
      
      Updates haddock submodule.
      26e8fff3
  23. 22 Feb, 2020 1 commit
  24. 21 Feb, 2020 2 commits