Skip to content
Snippets Groups Projects
  1. Mar 10, 2021
  2. Mar 07, 2021
    • Ben Gamari's avatar
      Implement BoxedRep proposal · 3e082f8f
      Ben Gamari authored
      This implements the BoxedRep proposal, refactoring the `RuntimeRep`
      hierarchy from:
      
      ```haskell
      data RuntimeRep = LiftedPtrRep | UnliftedPtrRep | ...
      ```
      
      to
      
      ```haskell
      data RuntimeRep = BoxedRep Levity | ...
      data Levity = Lifted | Unlifted
      ```
      
      Updates binary, haddock submodules.
      
      Closes #17526.
      
      Metric Increase:
          T12545
      3e082f8f
  3. Jan 27, 2021
    • Richard Eisenberg's avatar
      Remove some redundant validity checks. · 189efc39
      Richard Eisenberg authored and Marge Bot's avatar Marge Bot committed
      This commit also consolidates documentation in the user
      manual around UndecidableSuperClasses, UndecidableInstances,
      and FlexibleContexts.
      
      Close #19186.
      Close #19187.
      
      Test case: typecheck/should_compile/T19186,
      typecheck/should_fail/T19187{,a}
      189efc39
  4. Jan 22, 2021
  5. Dec 18, 2020
    • Ryan Scott's avatar
      Use HsOuterExplicit in instance sigs in deriving-generated code · 7a93435b
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Issue #18914 revealed that `GeneralizedNewtypeDeriving` would generate code
      that mentions unbound type variables, which is dangerously fragile. The
      problem (and fix) is described in the new `Wrinkle: Use HsOuterExplicit`
      in `Note [GND and QuantifiedConstraints]`. The gist of it: make sure to
      put the top-level `forall`s in `deriving`-generated instance signatures in an
      `HsOuterExplicit` to ensure that they scope over the bodies of methods
      correctly. A side effect of this process is that it will expand any type
      synonyms in the instance signature, which will surface any `forall`s that
      are hidden underneath type synonyms (such as in the test case for #18914).
      
      While I was in town, I also performed some maintenance on `NewHsTypeX`, which
      powers `GeneralizedNewtypeDeriving`:
      
      * I renamed `NewHsTypeX` to `HsCoreTy`, which more accurately describes its
        intended purpose (#15706). I also made `HsCoreTy` a type synonym instead of
        a newtype, as making it a distinct data type wasn't buying us much.
      * To make sure that mistakes similar to #18914 do not occur later, I added an
        additional validity check when renaming `HsCoreTy`s that complains if an
        `HsCoreTy`s contains an out-of-scope type variable. See the new
        `Note [Renaming HsCoreTys]` in `GHC.Rename.HsType` for the details.
      
      Fixes #15706. Fixes #18914. Bumps the `haddock` submodule.
      7a93435b
  6. Dec 15, 2020
  7. Dec 14, 2020
    • Andrew Martin's avatar
      Implement BoxedRep proposal · 6c2eb223
      Andrew Martin authored and Ben Gamari's avatar Ben Gamari committed
      This implements the BoxedRep proposal, refacoring the `RuntimeRep`
      hierarchy from:
      
      ```haskell
      data RuntimeRep = LiftedPtrRep | UnliftedPtrRep | ...
      ```
      
      to
      
      ```haskell
      data RuntimeRep = BoxedRep Levity | ...
      data Levity = Lifted | Unlifted
      ```
      
      Closes #17526.
      6c2eb223
    • Ben Gamari's avatar
      Optimise nullary type constructor usage · dad87210
      Ben Gamari authored
      During the compilation of programs GHC very frequently deals with
      the `Type` type, which is a synonym of `TYPE 'LiftedRep`. This patch
      teaches GHC to avoid expanding the `Type` synonym (and other nullary
      type synonyms) during type comparisons, saving a good amount of work.
      This optimisation is described in `Note [Comparing nullary type
      synonyms]`.
      
      To maximize the impact of this optimisation, we introduce a few
      special-cases to reduce `TYPE 'LiftedRep` to `Type`. See
      `Note [Prefer Type over TYPE 'LiftedPtrRep]`.
      
      Closes #17958.
      
      Metric Decrease:
         T18698b
         T1969
         T12227
         T12545
         T12707
         T14683
         T3064
         T5631
         T5642
         T9020
         T9630
         T9872a
         T13035
         haddock.Cabal
         haddock.base
      dad87210
    • Ben Gamari's avatar
      Revert "Optimise nullary type constructor usage" · 92377c27
      Ben Gamari authored
      This was inadvertently merged.
      
      This reverts commit 7e9debd4.
      92377c27
    • Ben Gamari's avatar
      Optimise nullary type constructor usage · 7e9debd4
      Ben Gamari authored
      During the compilation of programs GHC very frequently deals with
      the `Type` type, which is a synonym of `TYPE 'LiftedRep`. This patch
      teaches GHC to avoid expanding the `Type` synonym (and other nullary
      type synonyms) during type comparisons, saving a good amount of work.
      This optimisation is described in `Note [Comparing nullary type
      synonyms]`.
      
      To maximize the impact of this optimisation, we introduce a few
      special-cases to reduce `TYPE 'LiftedRep` to `Type`. See
      `Note [Prefer Type over TYPE 'LiftedPtrRep]`.
      
      Closes #17958.
      
      Metric Decrease:
         T18698b
         T1969
         T12227
         T12545
         T12707
         T14683
         T3064
         T5631
         T5642
         T9020
         T9630
         T9872a
         T13035
         haddock.Cabal
         haddock.base
      7e9debd4
  8. Dec 08, 2020
    • Simon Peyton Jones's avatar
      Fix kind inference for data types. Again. · 62ed6957
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      This patch fixes several aspects of kind inference for data type
      declarations, especially data /instance/ declarations
      
      Specifically
      
      1. In kcConDecls/kcConDecl make it clear that the tc_res_kind argument
         is only used in the H98 case; and in that case there is no result
         kind signature; and hence no need for the disgusting splitPiTys in
         kcConDecls (now thankfully gone).
      
         The GADT case is a bit different to before, and much nicer.
         This is what fixes #18891.
      
         See Note [kcConDecls: kind-checking data type decls]
      
      2. Do not look at the constructor decls of a data/newtype instance
         in tcDataFamInstanceHeader. See GHC.Tc.TyCl.Instance
         Note [Kind inference for data family instances].  This was a
         new realisation that arose when doing (1)
      
         This causes a few knock-on effects in the tests suite, because
         we require more information than before in the instance /header/.
      
         New user-manual material about this in "Kind inference in data type
         declarations" and "Kind inference for data/newtype instance
         declarations".
      
      3. Minor improvement in kcTyClDecl, combining GADT and H98 cases
      
      4. Fix #14111 and #8707 by allowing the header of a data instance
         to affect kind inferece for the the data constructor signatures;
         as described at length in Note [GADT return types] in GHC.Tc.TyCl
      
         This led to a modest refactoring of the arguments (and argument
         order) of tcConDecl/tcConDecls.
      
      5. Fix #19000 by inverting the sense of the test in new_locs
         in GHC.Tc.Solver.Canonical.canDecomposableTyConAppOK.
      62ed6957
  9. Oct 15, 2020
  10. Oct 14, 2020
  11. Jul 29, 2020
  12. Jul 21, 2020
    • Matthew Pickering's avatar
      Use a newtype `Code` for the return type of typed quotations (Proposal #195) · a6257192
      Matthew Pickering authored and Ben Gamari's avatar Ben Gamari committed
      There are three problems with the current API:
      
      1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition
         of two type constructors. Doing so in your program involves making your own newtype and
         doing a lot of wrapping/unwrapping.
      
         For example, if I want to create a language which I can either run immediately or
         generate code from I could write the following with the new API. ::
      
            class Lang r where
              _int :: Int -> r Int
              _if  :: r Bool -> r a -> r a -> r a
      
            instance Lang Identity where
              _int = Identity
              _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f)
      
            instance Quote m => Lang (Code m) where
              _int = liftTyped
              _if cb ct cf = [|| if $$cb then $$ct else $$cf ||]
      
      2. When doing code generation it is common to want to store code fragments in
         a map. When doing typed code generation, these code fragments contain a
         type index so it is desirable to store them in one of the parameterised
         map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from
         ``parameterized-utils``.
      
         ::
      
            compiler :: Env -> AST a -> Code Q a
      
            data AST a where ...
            data Ident a = ...
      
            type Env = MapF Ident (Code Q)
      
            newtype Code m a = Code (m (TExp a))
      
         In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``.
         Using one of these map types currently requires creating your own newtype and constantly
         wrapping every quotation and unwrapping it when using a splice. Achievable, but
         it creates even more syntactic noise than normal metaprogramming.
      
      3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is
         easier. This is a weak reason but one everyone
         can surely agree with.
      
      Updates text submodule.
      a6257192
  13. Jun 30, 2020
    • Ryan Scott's avatar
      Reject nested foralls/contexts in instance types more consistently · 71006532
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      GHC is very wishy-washy about rejecting instance declarations with
      nested `forall`s or contexts that are surrounded by outermost
      parentheses. This can even lead to some strange interactions with
      `ScopedTypeVariables`, as demonstrated in #18240. This patch makes
      GHC more consistently reject instance types with nested
      `forall`s/contexts so as to prevent these strange interactions.
      
      On the implementation side, this patch tweaks `splitLHsInstDeclTy`
      and `getLHsInstDeclHead` to not look through parentheses, which can
      be semantically significant. I've added a
      `Note [No nested foralls or contexts in instance types]` in
      `GHC.Hs.Type` to explain why. This also introduces a
      `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to
      catch nested `forall`s/contexts in instance types. This function is
      now used in `rnClsInstDecl` (for ordinary instance declarations) and
      `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter
      of which fixes #18271.
      
      On the documentation side, this adds a new
      "Formal syntax for instance declaration types" section to the GHC
      User's Guide that presents a BNF-style grammar for what is and isn't
      allowed in instance types.
      
      Fixes #18240. Fixes #18271.
      71006532
  14. Jun 28, 2020
    • Ryan Scott's avatar
      Use NHsCoreTy to embed types into GND-generated code · 42f797b0
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      `GeneralizedNewtypeDeriving` is in the unique situation where it must
      produce an `LHsType GhcPs` from a Core `Type`. Historically, this was
      done with the `typeToLHsType` function, which walked over the entire
      `Type` and attempted to construct an `LHsType` with the same overall
      structure. `typeToLHsType` is quite complicated, however, and has
      been the subject of numerous bugs over the years (e.g., #14579).
      
      Luckily, there is an easier way to accomplish the same thing: the
      `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`,
      which allows embedding a Core `Type` directly into an `HsType`,
      avoiding the need to laboriously convert from one to another (as
      `typeToLHsType` did). Moreover, renaming and typechecking an
      `XHsType` is simple, since one doesn't need to do anything to a
      Core `Type`...
      
      ...well, almost. For the reasons described in
      `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must
      apply a substitution that we build from the local `tcl_env` type
      environment. But that's a relatively modest price to pay.
      
      Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the
      `typeToLHsType` function no longer has any uses in GHC, so this patch
      rips it out. Some additional tweaks to `hsTypeNeedsParens` were
      necessary to make the new `-ddump-deriv` output correctly
      parenthesized, but other than that, this patch is quite
      straightforward.
      
      This is a mostly internal refactoring, although it is likely that
      `GeneralizedNewtypeDeriving`-generated code will now need fewer
      language extensions in certain situations than it did before.
      42f797b0
  15. Jun 27, 2020
    • Ryan Scott's avatar
      Revamp the treatment of auxiliary bindings for derived instances · ce987865
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This started as a simple fix for #18321 that organically grew into a
      much more sweeping refactor of how auxiliary bindings for derived
      instances are handled. I have rewritten `Note [Auxiliary binders]`
      in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but
      the highlights are:
      
      * Previously, the OccName of each auxiliary binding would be given
        a suffix containing a hash of its package name, module name, and
        parent data type to avoid name clashes. This was needlessly
        complicated, so we take the more direct approach of generating
        `Exact` `RdrName`s for each auxiliary binding with the same
        `OccName`, but using an underlying `System` `Name` with a fresh
        `Unique` for each binding. Unlike hashes, allocating new `Unique`s
        does not require any cleverness and avoid name clashes all the
        same...
      * ...speaking of which, in order to convince the renamer that multiple
        auxiliary bindings with the same `OccName` (but different
        `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of
        `rnTopBindsLHS` to rename auxiliary bindings. Again, see
        `Note [Auxiliary binders]` for the full story.
      * I have removed the `DerivHsBind` constructor for
        `DerivStuff`—which was only used for `Data.Data`-related
        auxiliary bindings—and refactored `gen_Data_binds` to use
        `DerivAuxBind` instead. This brings the treatment of
        `Data.Data`-related auxiliary bindings in line with every other
        form of auxiliary binding.
      
      Fixes #18321.
      ce987865
  16. Jun 17, 2020
    • Krzysztof Gogolewski's avatar
      Linear types (#15981) · 40fa237e
      Krzysztof Gogolewski authored and Ben Gamari's avatar Ben Gamari committed
      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
      * Syntax for non-linear/multiple-field-multiplicity records
      * Linear projections for records with a single linear field
      * Linear pattern synonyms
      * Multiplicity coercions (test LinearPolyType)
      
      A high-level description can be found at
      https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation
      Following the link above you will find a description of the changes made to Core.
      This commit has been authored by
      
      * Richard Eisenberg
      * Krzysztof Gogolewski
      * Matthew Pickering
      * Arnaud Spiwack
      
      With contributions from:
      
      * Mark Barbone
      * Alexander Vershilov
      
      Updates haddock submodule.
      40fa237e
  17. Jun 05, 2020
    • Simon Peyton Jones's avatar
      Simple subsumption · 2b792fac
      Simon Peyton Jones authored
      This patch simplifies GHC to use simple subsumption.
        Ticket #17775
      
      Implements GHC proposal #287
         https://github.com/ghc-proposals/ghc-proposals/blob/master/
         proposals/0287-simplify-subsumption.rst
      
      All the motivation is described there; I will not repeat it here.
      The implementation payload:
       * tcSubType and friends become noticably simpler, because it no
         longer uses eta-expansion when checking subsumption.
       * No deeplyInstantiate or deeplySkolemise
      
      That in turn means that some tests fail, by design; they can all
      be fixed by eta expansion.  There is a list of such changes below.
      
      Implementing the patch led me into a variety of sticky corners, so
      the patch includes several othe changes, some quite significant:
      
      * I made String wired-in, so that
          "foo" :: String   rather than
          "foo" :: [Char]
        This improves error messages, and fixes #15679
      
      * The pattern match checker relies on knowing about in-scope equality
        constraints, andd adds them to the desugarer's environment using
        addTyCsDs.  But the co_fn in a FunBind was missed, and for some reason
        simple-subsumption ends up with dictionaries there. So I added a
        call to addTyCsDs.  This is really part of #18049.
      
      * I moved the ic_telescope field out of Implication and into
        ForAllSkol instead.  This is a nice win; just expresses the code
        much better.
      
      * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader.
        We called checkDataKindSig inside tc_kind_sig, /before/
        solveEqualities and zonking.  Obviously wrong, easily fixed.
      
      * solveLocalEqualitiesX: there was a whole mess in here, around
        failing fast enough.  I discovered a bad latent bug where we
        could successfully kind-check a type signature, and use it,
        but have unsolved constraints that could fill in coercion
        holes in that signature --  aargh.
      
        It's all explained in Note [Failure in local type signatures]
        in GHC.Tc.Solver. Much better now.
      
      * I fixed a serious bug in anonymous type holes. IN
          f :: Int -> (forall a. a -> _) -> Int
        that "_" should be a unification variable at the /outer/
        level; it cannot be instantiated to 'a'.  This was plain
        wrong.  New fields mode_lvl and mode_holes in TcTyMode,
        and auxiliary data type GHC.Tc.Gen.HsType.HoleMode.
      
        This fixes #16292, but makes no progress towards the more
        ambitious #16082
      
      * I got sucked into an enormous refactoring of the reporting of
        equality errors in GHC.Tc.Errors, especially in
            mkEqErr1
            mkTyVarEqErr
            misMatchMsg
            misMatchMsgOrCND
        In particular, the very tricky mkExpectedActualMsg function
        is gone.
      
        It took me a full day.  But the result is far easier to understand.
        (Still not easy!)  This led to various minor improvements in error
        output, and an enormous number of test-case error wibbles.
      
        One particular point: for occurs-check errors I now just say
           Can't match 'a' against '[a]'
        rather than using the intimidating language of "occurs check".
      
      * Pretty-printing AbsBinds
      
      Tests review
      
      * Eta expansions
         T11305: one eta expansion
         T12082: one eta expansion (undefined)
         T13585a: one eta expansion
         T3102:  one eta expansion
         T3692:  two eta expansions (tricky)
         T2239:  two eta expansions
         T16473: one eta
         determ004: two eta expansions (undefined)
         annfail06: two eta (undefined)
         T17923: four eta expansions (a strange program indeed!)
         tcrun035: one eta expansion
      
      * Ambiguity check at higher rank.  Now that we have simple
        subsumption, a type like
           f :: (forall a. Eq a => Int) -> Int
        is no longer ambiguous, because we could write
           g :: (forall a. Eq a => Int) -> Int
           g = f
        and it'd typecheck just fine.  But f's type is a bit
        suspicious, and we might want to consider making the
        ambiguity check do a check on each sub-term.  Meanwhile,
        these tests are accepted, whereas they were previously
        rejected as ambiguous:
           T7220a
           T15438
           T10503
           T9222
      
      * Some more interesting error message wibbles
         T13381: Fine: one error (Int ~ Exp Int)
                 rather than two (Int ~ Exp Int, Exp Int ~ Int)
         T9834:  Small change in error (improvement)
         T10619: Improved
         T2414:  Small change, due to order of unification, fine
         T2534:  A very simple case in which a change of unification order
                 means we get tow unsolved constraints instead of one
         tc211: bizarre impredicative tests; just accept this for now
      
      Updates Cabal and haddock submodules.
      
      Metric Increase:
        T12150
        T12234
        T5837
        haddock.base
      Metric Decrease:
        haddock.compiler
        haddock.Cabal
        haddock.base
      
      Merge note: This appears to break the
      `UnliftedNewtypesDifficultUnification` test. It has been marked as
      broken in the interest of merging.
      
      (cherry picked from commit 66b7b195)
      2b792fac
  18. Jun 01, 2020
  19. May 25, 2020
  20. May 08, 2020
  21. May 06, 2020
    • Ryan Scott's avatar
      Make isTauTy detect higher-rank contexts · edec6a6c
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Previously, `isTauTy` would only detect higher-rank `forall`s, not
      higher-rank contexts, which led to some minor bugs observed
      in #18127. Easily fixed by adding a case for
      `(FunTy InvisArg _ _)`.
      
      Fixes #18127.
      edec6a6c
  22. Apr 23, 2020
  23. Apr 08, 2020
  24. Apr 07, 2020
  25. Mar 12, 2020
    • Ryan Scott's avatar
      Make DeriveFunctor-generated code require fewer beta reductions · cb93a1a4
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      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
  26. Mar 09, 2020
  27. Jan 08, 2020
    • Ryan Scott's avatar
      Print Core type applications with no whitespace after @ (#17643) · 923a1272
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This brings the pretty-printer for Core in line with how visible
      type applications are normally printed: namely, with no whitespace
      after the `@` character (i.e., `f @a` instead of `f @ a`). While I'm
      in town, I also give the same treatment to type abstractions (i.e.,
      `\(@a)` instead of `\(@ a)`) and coercion applications (i.e.,
      `f @~x` instead of `f @~ x`).
      
      Fixes #17643.
      923a1272
  28. Jan 04, 2020
  29. Nov 28, 2019
  30. Nov 20, 2019
  31. Nov 10, 2019
    • Richard Eisenberg's avatar
      Fix #17405 by not checking imported equations · 55ca1085
      Richard Eisenberg authored and Marge Bot's avatar Marge Bot committed
      Previously, we checked all imported type family equations
      for injectivity. This is very silly. Now, we check only
      for conflicts.
      
      Before I could even imagine doing the fix, I needed to untangle
      several functions that were (in my opinion) overly complicated.
      It's still not quite as perfect as I'd like, but it's good enough
      for now.
      
      Test case: typecheck/should_compile/T17405
      55ca1085
  32. Oct 28, 2019
    • Ryan Scott's avatar
      Refactor TcDeriv to validity-check less in anyclass/via deriving (#13154) · cd9b9459
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Due to the way `DerivEnv` is currently structured, there is an
      invariant that every derived instance must consist of a class applied
      to a non-empty list of argument types, where the last argument *must*
      be an application of a type constructor to some arguments. This works
      for many cases, but there are also some design patterns in standalone
      `anyclass`/`via` deriving that are made impossible due to enforcing
      this invariant, as documented in #13154.
      
      This fixes #13154 by refactoring `TcDeriv` and friends to perform
      fewer validity checks when using the `anyclass` or `via` strategies.
      The highlights are as followed:
      
      * Five fields of `DerivEnv` have been factored out into a new
        `DerivInstTys` data type. These fields only make sense for
        instances that satisfy the invariant mentioned above, so
        `DerivInstTys` is now only used in `stock` and `newtype` deriving,
        but not in other deriving strategies.
      * There is now a `Note [DerivEnv and DerivSpecMechanism]` describing
        the bullet point above in more detail, as well as explaining the
        exact requirements that each deriving strategy imposes.
      * I've refactored `mkEqnHelp`'s call graph to be slightly less
        complicated. Instead of the previous `mkDataTypeEqn`/`mkNewTypeEqn`
        dichotomy, there is now a single entrypoint `mk_eqn`.
      * Various bits of code were tweaked so as not to use fields that are
        specific to `DerivInstTys` so that they may be used by all deriving
        strategies, since not all deriving strategies use `DerivInstTys`.
      cd9b9459
  33. Oct 12, 2019
    • Ryan Scott's avatar
      Use newDFunName for both manual and derived instances (#17339) · 0a338264
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Issue #17339 was caused by using a slightly different version of
      `newDFunName` for derived instances that, confusingly enough, did not
      take all arguments to the class into account when generating the
      `DFun` name. I cannot think of any good reason for doing this, so
      this patch uses `newDFunName` uniformly for both derived instances
      and manually written instances alike.
      
      Fixes #17339.
      0a338264
  34. Oct 09, 2019
    • Ryan Scott's avatar
      Use addUsedDataCons more judiciously in TcDeriv (#17324) · d584e3f0
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      If you derive an instance like this:
      
      ```hs
      deriving <...> instance Foo C
      ```
      
      And the data constructors for `C` aren't in scope, then
      `doDerivInstErrorChecks1` throws an error. Moreover, it will
      _only_ throw an error if `<...>` is either `stock` or `newtype`.
      This is because the code that the `anyclass` or `via` strategies
      would generate would not require the use of the data constructors
      for `C`.
      
      However, `doDerivInstErrorChecks1` has another purpose. If you
      write this:
      
      ```hs
      import M (C(MkC1, ..., MkCn))
      
      deriving <...> instance Foo C
      ```
      
      Then `doDerivInstErrorChecks1` will call `addUsedDataCons` on
      `MkC1` through `MkCn` to ensure that `-Wunused-imports` does not
      complain about them. However, `doDerivInstErrorChecks1` was doing
      this for _every_ deriving strategy, which mean that if `<...>` were
      `anyclass` or `via`, then the warning about `MkC1` through `MkCn`
      being unused would be suppressed!
      
      The fix is simple enough: only call `addUsedDataCons` when the
      strategy is `stock` or `newtype`, just like the other code paths
      in `doDerivInstErrorChecks1`.
      
      Fixes #17324.
      d584e3f0
  35. Sep 25, 2019
Loading