1. 02 Oct, 2020 1 commit
  2. 01 Sep, 2020 1 commit
    • Sylvain Henry's avatar
      Remove "Ord FastString" instance · 4b4fbc58
      Sylvain Henry authored
      FastStrings can be compared in 2 ways: by Unique or lexically. We don't
      want to bless one particular way with an "Ord" instance because it leads
      to bugs (#18562) or to suboptimal code (e.g. using lexical comparison
      while a Unique comparison would suffice).
      
      UTF-8 encoding has the advantage that sorting strings by their encoded
      bytes also sorts them by their Unicode code points, without having to
      decode the actual code points. BUT GHC uses Modified UTF-8 which
      diverges from UTF-8 by encoding \0 as 0xC080 instead of 0x00 (to avoid
      null bytes in the middle of a String so that the string can still be
      null-terminated). This patch adds a new `utf8CompareShortByteString`
      function that performs sorting by bytes but that also takes Modified
      UTF-8 into account. It is much more performant than decoding the strings
      into [Char] to perform comparisons (which we did in the previous patch).
      
      Bump haddock submodule
      4b4fbc58
  3. 12 Aug, 2020 1 commit
    • Sylvain Henry's avatar
      DynFlags: disentangle Outputable · accbc242
      Sylvain Henry authored
      - put panic related functions into GHC.Utils.Panic
      - put trace related functions using DynFlags in GHC.Driver.Ppr
      
      One step closer making Outputable fully independent of DynFlags.
      
      Bump haddock submodule
      accbc242
  4. 18 Jul, 2020 1 commit
    • Simon Peyton Jones's avatar
      Allow multiple case branches to have a higher rank type · bcb177dd
      Simon Peyton Jones authored
      As #18412 points out, it should be OK for multiple case alternatives
      to have a higher rank type, provided they are all the same.
      
      This patch implements that change.  It sweeps away
      GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it
      with an enhanced version of fillInferResult.
      
      The basic change to fillInferResult is to permit the case in which
      another case alternative has already filled in the result; and in
      that case simply unify.  It's very simple actually.
      
      See the new Note [fillInferResult] in TcMType
      
      Other refactoring:
      
      - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType
        (previously some of it was in Unify)
      
      - Move tcInstType and friends from TcMType to Instantiate, where it
        more properly belongs.  (TCMType was getting very long.)
      bcb177dd
  5. 25 Jun, 2020 1 commit
    • Takenobu Tani's avatar
      Clean up haddock hyperlinks of GHC.* (part1) · c7dd6da7
      Takenobu Tani authored
      This updates haddock comments only.
      
      This patch focuses to update for hyperlinks in GHC API's haddock comments,
      because broken links especially discourage newcomers.
      
      This includes the following hierarchies:
        - GHC.Hs.*
        - GHC.Core.*
        - GHC.Stg.*
        - GHC.Cmm.*
        - GHC.Types.*
        - GHC.Data.*
        - GHC.Builtin.*
        - GHC.Parser.*
        - GHC.Driver.*
        - GHC top
      c7dd6da7
  6. 17 Jun, 2020 2 commits
    • Krzysztof Gogolewski's avatar
      Various performance improvements · 6cb84c46
      Krzysztof Gogolewski authored
      This implements several general performance improvements to GHC,
      to offset the effect of the linear types change.
      
      General optimisations:
      - Add a `coreFullView` function which iterates `coreView` on the
        head. This avoids making function recursive solely because the
        iterate `coreView` themselves. As a consequence, this functions can
        be inlined, and trigger case-of-known constructor (_e.g._
        `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`,
        `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`,
        `tyConAppTyCon_maybe`). The common pattern about all these functions
        is that they are almost always used as views, and immediately
        consumed by a case expression. This commit also mark them asx `INLINE`.
      - In `subst_ty` add a special case for nullary `TyConApp`, which avoid
        allocations altogether.
      - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This
        required quite a bit of module shuffling.
        case. `myTyConApp` enforces crucial sharing, whi...
      6cb84c46
    • Krzysztof Gogolewski's avatar
      Linear types (#15981) · 40fa237e
      Krzysztof Gogolewski authored
      This is the first step towards implementation of the linear types proposal
      (https://github.com/ghc-proposals/ghc-proposals/pull/111).
      
      It features
      
      * A language extension -XLinearTypes
      * Syntax for linear functions in the surface language
      * Linearity checking in Core Lint, enabled with -dlinear-core-lint
      * Core-to-core passes are mostly compatible with linearity
      * Fields in a data type can be linear or unrestricted; linear fields
        have multiplicity-polymorphic constructors.
        If -XLinearTypes is disabled, the GADT syntax defaults to linear fields
      
      The following items are not yet supported:
      
      * a # m -> b syntax (only prefix FUN is supported for now)
      * Full multiplicity inference (multiplicities are really only checked)
      * Decent linearity error messages
      * Linear let, where, and case expressions in the surface language
        (each of these currently introduce the unrestricted variant)
      * Multiplicity-parametric fields
      * Syntax for annotating lambda-bound or let-bound with a multiplicity
      * S...
      40fa237e
  7. 13 Jun, 2020 1 commit
    • Ryan Scott's avatar
      Use HsForAllTelescope to avoid inferred, visible foralls · a31218f7
      Ryan Scott authored
      Currently, `HsForAllTy` permits the combination of `ForallVis` and
      `Inferred`, but you can't actually typecheck code that uses it
      (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a
      new `HsForAllTelescope` data type that makes a type-level distinction
      between visible and invisible `forall`s such that visible `forall`s
      do not track `Specificity`. That part of the patch is actually quite
      small; the rest is simply changing consumers of `HsType` to
      accommodate this new type.
      
      Fixes #18235. Bumps the `haddock` submodule.
      a31218f7
  8. 10 Jun, 2020 1 commit
  9. 21 May, 2020 1 commit
    • Gert-Jan Bottu's avatar
      Explicit Specificity · a9311cd5
      Gert-Jan Bottu authored
      Implementation for Ticket #16393.
      Explicit specificity allows users to manually create inferred type variables,
      by marking them with braces.
      This way, the user determines which variables can be instantiated through
      visible type application.
      
      The additional syntax is included in the parser, allowing users to write
      braces in type variable binders (type signatures, data constructors etc).
      This information is passed along through the renamer and verified in the
      type checker.
      The AST for type variable binders, data constructors, pattern synonyms,
      partial signatures and Template Haskell has been updated to include the
      specificity of type variables.
      
      Minor notes:
      - Bumps haddock submodule
      - Disables pattern match checking in GHC.Iface.Type with GHC 8.8
      a9311cd5
  10. 14 May, 2020 1 commit
  11. 26 Apr, 2020 1 commit
  12. 18 Apr, 2020 1 commit
    • Sylvain Henry's avatar
      Modules (#13009) · 15312bbb
      Sylvain Henry authored
      * SysTools
      * Parser
      * GHC.Builtin
      * GHC.Iface.Recomp
      * Settings
      
      Update Haddock submodule
      
      Metric Decrease:
          Naperian
          parsing001
      15312bbb
  13. 07 Apr, 2020 1 commit
  14. 29 Mar, 2020 1 commit
  15. 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 r...
      73a7383e
  16. 17 Mar, 2020 1 commit
  17. 26 Feb, 2020 1 commit
  18. 21 Feb, 2020 1 commit
    • Simon Peyton Jones's avatar
      Re-implement unsafe coercions in terms of unsafe equality proofs · 74ad75e8
      Simon Peyton Jones authored
      (Commit message written by Omer, most of the code is written by Simon
      and Richard)
      
      See Note [Implementing unsafeCoerce] for how unsafe equality proofs and
      the new unsafeCoerce# are implemented.
      
      New notes added:
      
      - [Checking for levity polymorphism] in CoreLint.hs
      - [Implementing unsafeCoerce] in base/Unsafe/Coerce.hs
      - [Patching magic definitions] in Desugar.hs
      - [Wiring in unsafeCoerce#] in Desugar.hs
      
      Only breaking change in this patch is unsafeCoerce# is not exported from
      GHC.Exts, instead of GHC.Prim.
      
      Fixes #17443
      Fixes #16893
      
      NoFib
      -----
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs    Instrs     Reads    Writes
      --------------------------------------------------------------------------------
                   CS          -0.1%      0.0%     -0.0%     -0.0%     -0.0%
                  CSD          -0.1%      0.0%     -0.0%     -0.0%     -0.0%
                   FS          -...
      74ad75e8
  19. 12 Feb, 2020 1 commit
  20. 06 Feb, 2020 2 commits
    • Simon Peyton Jones's avatar
      Use foldTyCo for exactTyCoVarsOfType · 5541b87c
      Simon Peyton Jones authored
      This entailed
      
      * Adding a tcf_view field to TyCoFolder
      
      * Moving exactTyCoVarsOtType to TcType.  It properly belongs
        there, since only the typechecker calls this function. But
        it also means that we can "see" and inline tcView.
      
      Metric Decrease:
        T14683
      5541b87c
    • Simon Peyton Jones's avatar
      Reform the free variable finders for types · ed2f0e5c
      Simon Peyton Jones authored
      This patch delivers on (much of) #17509.
      
      * Introduces the shallow vs deep free variable distinction
      
      * Introduce TyCoRep.foldType,
          foldType :: Monoid a => TyCoFolder env a
                               -> env -> Type -> a
        and use it in the free variable finders.
      
      * Substitution in TyCoSubst
         * ASSERTs are on for checkValidSubst
         * checkValidSubst uses shallowTyCoVarsOfTypes etc
      
      Quite a few things still to do
      
      * We could use foldType in lots of other places
      
      * We could use mapType for substitution.  (Check that we get
        good code!)
      
      * Some (but not yet all) clients of substitution can now
        save time by using shallowTyCoVarsOfTypes
      
      * All calls to tyCoVarsOfTypes should be inspected; most of
        them should be shallow.  Maybe.
      
      * Currently shallowTyCoVarsOfTypes still returns
        unification variables, but not CoVarHoles.
        Reason: we need to return unification variables
        in some of the calls in TcSimplify, eg when promoting.
      
      * We should do the same thing for tyCoFVsOfTypes, which is
        currently unchanged.
      
      * tyCoFVsOfTypes returns CoVarHoles, because of the
        use in TcSimplify.mkResidualConstraints.  See
        Note [Emitting the residual implication in simplifyInfer]
      
      * #17509 talks about "relevant" variables too.
      ed2f0e5c
  21. 13 Jan, 2020 1 commit
  22. 06 Jan, 2020 1 commit
  23. 13 Nov, 2019 1 commit
    • Ben Gamari's avatar
      Ensure that coreView/tcView are able to inline · 2d4f9ad8
      Ben Gamari authored
      Previously an import cycle between Type and TyCoRep meant that several
      functions in TyCoRep ended up SOURCE import coreView. This is quite
      unfortunate as coreView is intended to be fused into a larger pattern
      match and not incur an extra call.
      
      Fix this with a bit of restructuring:
      
       * Move the functions in `TyCoRep` which depend upon things in `Type`
         into `Type`
       * Fold contents of `Kind` into `Type` and turn `Kind` into a simple
         wrapper re-exporting kind-ish things from `Type`
       * Clean up the redundant imports that popped up as a result
      
      Closes #17441.
      
      Metric Decrease:
          T4334
      2d4f9ad8
  24. 21 Sep, 2019 1 commit
    • Sebastian Graf's avatar
      PredType for type constraints in the pattern match checker instead of EvVar · 1ea8c451
      Sebastian Graf authored
      Using EvVars for capturing type constraints implied side-effects in DsM
      when we just wanted to *construct* type constraints.
      
      But giving names to type constraints is only necessary when passing
      Givens to the type checker, of which the majority of the pattern match
      checker should be unaware.
      
      Thus, we simply generate `newtype TyCt = TyCt PredType`, which are
      nicely stateless. But at the same time this means we have to allocate
      EvVars when we want to query the type oracle! So we keep the type oracle
      state as `newtype TyState = TySt (Bag EvVar)`, which nicely makes a
      distinction between new, unchecked `TyCt`s and the inert set in
      `TyState`.
      1ea8c451
  25. 31 Jul, 2019 1 commit
    • Ben Gamari's avatar
      Break up TyCoRep · 371dadfb
      Ben Gamari authored
      This breaks up the monstrous TyCoReps module into several new modules by
      topic:
      
       * TyCoRep: Contains the `Coercion`, `Type`, and related type
         definitions and a few simple predicates but nothing further
      
       * TyCoPpr: Contains the the pretty-printer logic
      
       * TyCoFVs: Contains the free variable computations (and
         `tyConAppNeedsKindSig`, although I suspect this should change)
      
       * TyCoSubst: Contains the substitution logic for types and coercions
      
       * TyCoTidy: Contains the tidying logic for types
      
      While we are able to eliminate a good number of `SOURCE` imports (and
      make a few others smaller) with this change, we must introduce one new
      `hs-boot` file for `TyCoPpr` so that `TyCoRep` can define `Outputable`
      instances for the types it defines.
      
      Metric Increase:
          haddock.Cabal
          haddock.compiler
      371dadfb
  26. 19 Jul, 2019 1 commit
  27. 29 May, 2019 1 commit
    • Krzysztof Gogolewski's avatar
      Fix missing unboxed tuple RuntimeReps (#16565) · 69b16331
      Krzysztof Gogolewski authored
      Unboxed tuples and sums take extra RuntimeRep arguments,
      which must be manually passed in a few places.
      This was not done in deSugar/Check.
      
      This error was hidden because zipping functions in TyCoRep
      ignored lists with mismatching length. This is now fixed;
      the lengths are now checked by calling zipEqual.
      
      As suggested in #16565, I moved checking for isTyVar and
      isCoVar to zipTyEnv and zipCoEnv.
      69b16331
  28. 25 Mar, 2019 1 commit
    • Takenobu Tani's avatar
      Update Wiki URLs to point to GitLab · 3769e3a8
      Takenobu Tani authored
      This moves all URL references to Trac Wiki to their corresponding
      GitLab counterparts.
      
      This substitution is classified as follows:
      
      1. Automated substitution using sed with Ben's mapping rule [1]
          Old: ghc.haskell.org/trac/ghc/wiki/XxxYyy...
          New: gitlab.haskell.org/ghc/ghc/wikis/xxx-yyy...
      
      2. Manual substitution for URLs containing `#` index
          Old: ghc.haskell.org/trac/ghc/wiki/XxxYyy...#Zzz
          New: gitlab.haskell.org/ghc/ghc/wikis/xxx-yyy...#zzz
      
      3. Manual substitution for strings starting with `Commentary`
          Old: Commentary/XxxYyy...
          New: commentary/xxx-yyy...
      
      See also !539
      
      [1]: https://gitlab.haskell.org/bgamari/gitlab-migration/blob/master/wiki-mapping.json
      3769e3a8
  29. 15 Mar, 2019 1 commit
  30. 11 Mar, 2019 1 commit
  31. 07 Mar, 2019 1 commit
    • Ryan Scott's avatar
      Fix #16391 by using occCheckExpand in TcValidity · 068b7e98
      Ryan Scott authored
      The type-variables-escaping-their-scope-via-kinds check in
      `TcValidity` was failing to properly expand type synonyms, which led
      to #16391. This is easily fixed by using `occCheckExpand` before
      performing the validity check.
      
      Along the way, I refactored this check out into its own function,
      and sprinkled references to Notes to better explain all of the moving
      parts. Many thanks to @simonpj for the suggestions.
      
      Bumps the haddock submodule.
      068b7e98
  32. 01 Mar, 2019 1 commit
    • Ryan Scott's avatar
      Visible dependent quantification · c26d299d
      Ryan Scott authored
      This implements GHC proposal 35
      (https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0035-forall-arrow.rst)
      by adding the ability to write kinds with
      visible dependent quantification (VDQ).
      
      Most of the work for supporting VDQ was actually done _before_ this
      patch. That is, GHC has been able to reason about kinds with VDQ for
      some time, but it lacked the ability to let programmers directly
      write these kinds in the source syntax. This patch is primarly about
      exposing this ability, by:
      
      * Changing `HsForAllTy` to add an additional field of type
        `ForallVisFlag` to distinguish between invisible `forall`s (i.e,
        with dots) and visible `forall`s (i.e., with arrows)
      * Changing `Parser.y` accordingly
      
      The rest of the patch mostly concerns adding validity checking to
      ensure that VDQ is never used in the type of a term (as permitting
      this would require full-spectrum dependent types). This is
      accomplished by:
      
      * Adding a `vdqAllowed` predicate to `TcValidity`.
      * Introducing `splitLHsSigmaTyInvis`, a variant of `splitLHsSigmaTy`
        that only splits invisible `forall`s. This function is used in
        certain places (e.g., in instance declarations) to ensure that GHC
        doesn't try to split visible `forall`s (e.g., if it tried splitting
        `instance forall a -> Show (Blah a)`, then GHC would mistakenly
        allow that declaration!)
      
      This also updates Template Haskell by introducing a new `ForallVisT`
      constructor to `Type`.
      
      Fixes #16326. Also fixes #15658 by documenting this feature in the
      users' guide.
      c26d299d
  33. 24 Feb, 2019 1 commit
    • Simon Peyton Jones's avatar
      Add AnonArgFlag to FunTy · 6cce36f8
      Simon Peyton Jones authored
      The big payload of this patch is:
      
        Add an AnonArgFlag to the FunTy constructor
        of Type, so that
          (FunTy VisArg   t1 t2) means (t1 -> t2)
          (FunTy InvisArg t1 t2) means (t1 => t2)
      
      The big payoff is that we have a simple, local test to make
      when decomposing a type, leading to many fewer calls to
      isPredTy. To me the code seems a lot tidier, and probably
      more efficient (isPredTy has to take the kind of the type).
      
      See Note [Function types] in TyCoRep.
      
      There are lots of consequences
      
      * I made FunTy into a record, so that it'll be easier
        when we add a linearity field, something that is coming
        down the road.
      
      * Lots of code gets touched in a routine way, simply because it
        pattern matches on FunTy.
      
      * I wanted to make a pattern synonym for (FunTy2 arg res), which
        picks out just the argument and result type from the record. But
        alas the pattern-match overlap checker has a heart attack, and
        either reports false positives, or takes too long.  In the end
        I gave up on pattern synonyms.
      
        There's some commented-out code in TyCoRep that shows what I
        wanted to do.
      
      * Much more clarity about predicate types, constraint types
        and (in particular) equality constraints in kinds.  See TyCoRep
        Note [Types for coercions, predicates, and evidence]
        and Note [Constraints in kinds].
      
        This made me realise that we need an AnonArgFlag on
        AnonTCB in a TyConBinder, something that was really plain
        wrong before. See TyCon Note [AnonTCB InivsArg]
      
      * When building function types we must know whether we
        need VisArg (mkVisFunTy) or InvisArg (mkInvisFunTy).
        This turned out to be pretty easy in practice.
      
      * Pretty-printing of types, esp in IfaceType, gets
        tidier, because we were already recording the (->)
        vs (=>) distinction in an ad-hoc way.  Death to
        IfaceFunTy.
      
      * mkLamType needs to keep track of whether it is building
        (t1 -> t2) or (t1 => t2).  See Type
        Note [mkLamType: dictionary arguments]
      
      Other minor stuff
      
      * Some tidy-up in validity checking involving constraints;
        Trac #16263
      6cce36f8
  34. 20 Feb, 2019 1 commit
  35. 14 Feb, 2019 1 commit
    • Simon Peyton Jones's avatar
      Make a smart mkAppTyM · 68278382
      Simon Peyton Jones authored
      This patch finally delivers on Trac #15952.  Specifically
      
      * Completely remove Note [The tcType invariant], along with
        its complicated consequences (IT1-IT6).
      
      * Replace Note [The well-kinded type invariant] with:
      
            Note [The Purely Kinded Type Invariant (PKTI)]
      
      * Instead, establish the (PKTI) in TcHsType.tcInferApps,
        by using a new function mkAppTyM when building a type
        application.  See Note [mkAppTyM].
      
      * As a result we can remove the delicate mkNakedXX functions
        entirely.  Specifically, mkNakedCastTy retained lots of
        extremly delicate Refl coercions which just cluttered
        everything up, and(worse) were very vulnerable to being
        silently eliminated by (say) substTy. This led to a
        succession of bug reports.
      
      The result is noticeably simpler to explain, simpler
      to code, and Richard and I are much more confident that
      it is correct.
      
      It does not actually fix any bugs, but it brings us closer.
      E.g. I hoped it'd fix #15918 and #15799, but it doesn't quite
      do so.  However, it makes it much easier to fix.
      
      I also did a raft of other minor refactorings:
      
      * Use tcTypeKind consistently in the type checker
      
      * Rename tcInstTyBinders to tcInvisibleTyBinders,
        and refactor it a bit
      
      * Refactor tcEqType, pickyEqType, tcEqTypeVis
        Simpler, probably more efficient.
      
      * Make zonkTcType zonk TcTyCons, at least if they have
        any free unification variables -- see zonk_tc_tycon
        in TcMType.zonkTcTypeMapper.
      
        Not zonking these TcTyCons was actually a bug before.
      
      * Simplify try_to_reduce_no_cache in TcFlatten (a lot)
      
      * Combine checkExpectedKind and checkExpectedKindX.
        And then combine the invisible-binder instantation code
        Much simpler now.
      
      * Fix a little bug in TcMType.skolemiseQuantifiedTyVar.
        I'm not sure how I came across this originally.
      
      * Fix a little bug in TyCoRep.isUnliftedRuntimeRep
        (the ASSERT was over-zealous).  Again I'm not certain
        how I encountered this.
      
      * Add a missing solveLocalEqualities in
        TcHsType.tcHsPartialSigType.
        I came across this when trying to get level numbers
        right.
      68278382
  36. 06 Feb, 2019 1 commit
  37. 28 Jan, 2019 1 commit