Skip to content
Snippets Groups Projects
  1. Jul 22, 2023
    • sheaf's avatar
      Finish migration of diagnostics in GHC.Tc.Validity · 7e05f6df
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch finishes migrating the error messages in GHC.Tc.Validity
      to use the new diagnostic infrastructure.
      
      It also refactors the error message datatypes for class and family
      instances, to common them up under a single datatype as much as possible.
      7e05f6df
  2. Jul 03, 2023
  3. Jun 13, 2023
  4. May 24, 2023
    • Hai Nguyen Quang's avatar
      Migrate errors in GHC.Tc.Validity · 838aaf4b
      Hai Nguyen Quang authored and Marge Bot's avatar Marge Bot committed
      This patch migrates the error messages in GHC.Tc.Validity to use
      the new diagnostic infrastructure.
      
      It adds the constructors:
      
        - TcRnSimplifiableConstraint
        - TcRnArityMismatch
        - TcRnIllegalInstanceDecl, with sub-datatypes for HasField errors
          and fundep coverage condition errors.
      838aaf4b
  5. May 19, 2023
  6. May 05, 2023
  7. May 04, 2023
    • Ryan Scott's avatar
      Fix type variable substitution in gen_Newtype_fam_insts · e8b72ff6
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Previously, `gen_Newtype_fam_insts` was substituting the type variable binders
      of a type family instance using `substTyVars`, which failed to take type
      variable dependencies into account. There is similar code in
      `GHC.Tc.TyCl.Class.tcATDefault` that _does_ perform this substitution properly,
      so this patch:
      
      1. Factors out this code into a top-level `substATBndrs` function, and
      2. Uses `substATBndrs` in `gen_Newtype_fam_insts`.
      
      Fixes #23329.
      e8b72ff6
  8. Apr 30, 2023
  9. Apr 17, 2023
    • Ryan Scott's avatar
      validDerivPred: Reject exotic constraints in IrredPreds · 0158c5f1
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This brings the `IrredPred` case in sync with the treatment of `ClassPred`s as
      described in `Note [Valid 'deriving' predicate]` in `GHC.Tc.Validity`. Namely,
      we should reject `IrredPred`s that are inferred from `deriving` clauses whose
      arguments contain other type constructors, as described in `(VD2) Reject exotic
      constraints` of that Note.  This has the nice property that `deriving` clauses
      whose inferred instance context mention `TypeError` will now emit the type
      error in the resulting error message, which better matches existing intuitions
      about how `TypeError` should work.
      
      While I was in town, I noticed that much of `Note [Valid 'deriving' predicate]`
      was duplicated in a separate `Note [Exotic derived instance contexts]` in
      `GHC.Tc.Deriv.Infer`. I decided to fold the latter Note into the former so that
      there is a single authority on describing the conditions under which an
      inferred `deriving` constraint can be considered valid.
      
      This changes the behavior of `deriving` in a way that existing code might
      break, so I have made a mention of this in the GHC User's Guide. It seems very,
      very unlikely that much code is relying on this strange behavior, however, and
      even if there is, there is a clear, backwards-compatible migration path using
      `StandaloneDeriving`.
      
      Fixes #22696.
      0158c5f1
  10. Mar 29, 2023
    • sheaf's avatar
      Handle records in the renamer · 3f374399
      sheaf authored
      This patch moves the field-based logic for disambiguating record updates
      to the renamer. The type-directed logic, scheduled for removal, remains
      in the typechecker.
      
      To do this properly (and fix the myriad of bugs surrounding the treatment
      of duplicate record fields), we took the following main steps:
      
        1. Create GREInfo, a renamer-level equivalent to TyThing which stores
           information pertinent to the renamer.
           This allows us to uniformly treat imported and local Names in the
           renamer, as described in Note [GREInfo].
      
        2. Remove GreName. Instead of a GlobalRdrElt storing GreNames, which
           distinguished between normal names and field names, we now store
           simple Names in GlobalRdrElt, along with the new GREInfo information
           which allows us to recover the FieldLabel for record fields.
      
        3. Add namespacing for record fields, within the OccNames themselves.
           This allows us to remove the mangling of duplicate field selectors.
      
           This change ensures we don't print mangled names to the user in
           error messages, and allows us to handle duplicate record fields
           in Template Haskell.
      
        4. Move record disambiguation to the renamer, and operate on the
           level of data constructors instead, to handle #21443.
      
           The error message text for ambiguous record updates has also been
           changed to reflect that type-directed disambiguation is on the way
           out.
      
      (3) means that OccEnv is now a bit more complex: we first key on the
      textual name, which gives an inner map keyed on NameSpace:
      
        OccEnv a ~ FastStringEnv (UniqFM NameSpace a)
      
      Note that this change, along with (2), both increase the memory residency
      of GlobalRdrEnv = OccEnv [GlobalRdrElt], which causes a few tests to
      regress somewhat in compile-time allocation.
      
      Even though (3) simplified a lot of code (in particular the treatment of
      field selectors within Template Haskell and in error messages), it came
      with one important wrinkle: in the situation of
      
        -- M.hs-boot
        module M where { data A; foo :: A -> Int }
        -- M.hs
        module M where { data A = MkA { foo :: Int } }
      
      we have that M.hs-boot exports a variable foo, which is supposed to match
      with the record field foo that M exports. To solve this issue, we add a
      new impedance-matching binding to M
      
        foo{var} = foo{fld}
      
      This mimics the logic that existed already for impedance-binding DFunIds,
      but getting it right was a bit tricky.
      See Note [Record field impedance matching] in GHC.Tc.Module.
      
      We also needed to be careful to avoid introducing space leaks in GHCi.
      So we dehydrate the GlobalRdrEnv before storing it anywhere, e.g. in
      ModIface. This means stubbing out all the GREInfo fields, with the
      function forceGlobalRdrEnv.
      When we read it back in, we rehydrate with rehydrateGlobalRdrEnv.
      This robustly avoids any space leaks caused by retaining old type
      environments.
      
      Fixes #13352 #14848 #17381 #17551 #19664 #21443 #21444 #21720 #21898 #21946 #21959 #22125 #22160 #23010 #23062 #23063
      
      Updates haddock submodule
      
      -------------------------
      Metric Increase:
          MultiComponentModules
          MultiLayerModules
          MultiLayerModulesDefsGhci
          MultiLayerModulesNoCode
          T13701
          T14697
          hard_hole_fits
      -------------------------
      3f374399
  11. Mar 06, 2023
    • Andrei Borzenkov's avatar
      Convert diagnostics in GHC.Rename.Module to proper TcRnMessage (#20115) · cad5c576
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      I've turned almost all occurrences of TcRnUnknownMessage in GHC.Rename.Module
      module into a proper TcRnMessage.
      Instead, these TcRnMessage messages were introduced:
        TcRnIllegalInstanceHeadDecl
        TcRnUnexpectedStandaloneDerivingDecl
        TcRnUnusedVariableInRuleDecl
        TcRnUnexpectedStandaloneKindSig
        TcRnIllegalRuleLhs
        TcRnBadAssocRhs
        TcRnDuplicateRoleAnnot
        TcRnDuplicateKindSig
        TcRnIllegalDerivStrategy
        TcRnIllegalMultipleDerivClauses
        TcRnNoDerivStratSpecified
        TcRnStupidThetaInGadt
        TcRnBadImplicitSplice
        TcRnShadowedTyVarNameInFamResult
        TcRnIncorrectTyVarOnLhsOfInjCond
        TcRnUnknownTyVarsOnRhsOfInjCond
      
      Was introduced one helper type:
        RuleLhsErrReason
      cad5c576
  12. Jan 11, 2023
    • Richard Eisenberg's avatar
      Refactor the treatment of loopy superclass dicts · aed1974e
      Richard Eisenberg authored and Simon Peyton Jones's avatar Simon Peyton Jones committed
      This patch completely re-engineers how we deal with loopy superclass
      dictionaries in instance declarations. It fixes #20666 and #19690
      
      The highlights are
      
      * Recognise that the loopy-superclass business should use precisely
        the Paterson conditions.  This is much much nicer.  See
        Note [Recursive superclasses] in GHC.Tc.TyCl.Instance
      
      * With that in mind, define "Paterson-smaller" in
        Note [Paterson conditions] in GHC.Tc.Validity, and the new
        data type `PatersonSize` in GHC.Tc.Utils.TcType, along with
        functions to compute and compare PatsonSizes
      
      * Use the new PatersonSize stuff when solving superclass constraints
        See Note [Solving superclass constraints] in GHC.Tc.TyCl.Instance
      
      * In GHC.Tc.Solver.Monad.lookupInInerts, add a missing call to
        prohibitedSuperClassSolve.  This was the original cause of #20666.
      
      * Treat (TypeError "stuff") as having PatersonSize zero. See
        Note [Paterson size for type family applications] in GHC.Tc.Utils.TcType.
      
      * Treat the head of a Wanted quantified constraint in the same way
        as the superclass of an instance decl; this is what fixes #19690.
        See GHC.Tc.Solver.Canonical Note [Solving a Wanted forall-constraint]
        (Thanks to Matthew Craven for this insight.)
      
        This entailed refactoring the GivenSc constructor of CtOrigin a bit,
        to say whether it comes from an instance decl or quantified constraint.
      
      * Some refactoring way in which redundant constraints are reported; we
        don't want to complain about the extra, apparently-redundant
        constraints that we must add to an instance decl because of the
        loopy-superclass thing.  I moved some work from GHC.Tc.Errors to
        GHC.Tc.Solver.
      
      * Add a new section to the user manual to describe the loopy
        superclass issue and what rules it follows.
      aed1974e
  13. Dec 09, 2022
  14. Nov 30, 2022
  15. Nov 09, 2022
    • Giles Anderson's avatar
      Use TcRnDiagnostic in GHC.Tc.TyCl.Instance (#20117) · 92ccb8de
      Giles Anderson authored and Marge Bot's avatar Marge Bot committed
      The following `TcRnDiagnostic` messages have been introduced:
      
      TcRnWarnUnsatisfiedMinimalDefinition
      TcRnMisplacedInstSig
      TcRnBadBootFamInstDeclErr
      TcRnIllegalFamilyInstance
      TcRnAssocInClassErr
      TcRnBadFamInstDecl
      TcRnNotOpenFamily
      92ccb8de
  16. Nov 01, 2022
    • Simon Peyton Jones's avatar
      Add accurate skolem info when quantifying · 0560821f
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      Ticket #22379 revealed that skolemiseQuantifiedTyVar was
      dropping the passed-in skol_info on the floor when it encountered
      a SkolemTv.  Bad!  Several TyCons thereby share a single SkolemInfo
      on their binders, which lead to bogus error reports.
      0560821f
  17. Oct 26, 2022
  18. Sep 18, 2022
    • Ryan Scott's avatar
      DeriveFunctor: Check for last type variables using dataConUnivTyVars · 8a666ad2
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Previously, derived instances of `Functor` (as well as the related classes
      `Foldable`, `Traversable`, and `Generic1`) would determine which constraints to
      infer by checking for fields that contain the last type variable. The problem
      was that this last type variable was taken from `tyConTyVars`. For GADTs, the
      type variables in each data constructor are _not_ the same type variables as
      in `tyConTyVars`, leading to #22167.
      
      This fixes the issue by instead checking for the last type variable using
      `dataConUnivTyVars`. (This is very similar in spirit to the fix for #21185,
      which also replaced an errant use of `tyConTyVars` with type variables from
      each data constructor.)
      
      Fixes #22167.
      8a666ad2
  19. Sep 13, 2022
    • sheaf's avatar
      Diagnostic codes: acccept test changes · 362cca13
      sheaf authored and Marge Bot's avatar Marge Bot committed
      The testsuite output now contains diagnostic codes, so many tests need
      to be updated at once.
      We decided it was best to keep the diagnostic codes in the testsuite
      output, so that contributors don't inadvertently make changes to the
      diagnostic codes.
      362cca13
  20. Aug 19, 2022
  21. Jul 22, 2022
  22. Jun 06, 2022
  23. Jun 01, 2022
    • Rodrigo Mesquita's avatar
      TTG: Rework and improve splices · 7975202b
      Rodrigo Mesquita authored and Marge Bot's avatar Marge Bot committed
      This commit redefines the structure of Splices in the AST.
      
      We get rid of `HsSplice` which used to represent typed and untyped
      splices, quasi quotes, and the result of splicing either an expression,
      a type or a pattern.
      
      Instead we have `HsUntypedSplice` which models an untyped splice or a
      quasi quoter, which works in practice just like untyped splices.
      
      The `HsExpr` constructor `HsSpliceE` which used to be constructed with
      an `HsSplice` is split into `HsTypedSplice` and `HsUntypedSplice`. The
      former is directly constructed with an `HsExpr` and the latter now takes
      an `HsUntypedSplice`.
      
      Both `HsType` and `Pat` constructors `HsSpliceTy` and `SplicePat` now
      take an `HsUntypedSplice` instead of a `HsSplice` (remember only
      /untyped splices/ can be spliced as types or patterns).
      
      The result of splicing an expression, type, or pattern is now
      comfortably stored in the extension fields `XSpliceTy`, `XSplicePat`,
      `XUntypedSplice` as, respectively, `HsUntypedSpliceResult (HsType
      GhcRn)`, `HsUntypedSpliceResult (Pat GhcRn)`, and `HsUntypedSpliceResult
      (HsExpr GhcRn)`
      
      Overall the TTG extension points are now better used to
      make invalid states unrepresentable and model the progression between
      stages better.
      
      See Note [Lifecycle of an untyped splice, and PendingRnSplice]
      and Note [Lifecycle of an typed splice, and PendingTcSplice] for more
      details.
      
      Updates haddock submodule
      
      Fixes #21263
      
      -------------------------
      Metric Decrease:
          hard_hole_fits
      -------------------------
      7975202b
  24. Apr 07, 2022
  25. Apr 01, 2022
  26. Mar 24, 2022
    • Ryan Scott's avatar
      Fix and simplify DeriveAnyClass's context inference using SubTypePredSpec · c58d008c
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      As explained in `Note [Gathering and simplifying constraints for DeriveAnyClass]`
      in `GHC.Tc.Deriv.Infer`, `DeriveAnyClass` infers instance contexts by emitting
      implication constraints. Previously, these implication constraints were
      constructed by hand. This is a terribly trick thing to get right, as it
      involves a delicate interplay of skolemisation, metavariable instantiation, and
      `TcLevel` bumping. Despite much effort, we discovered in #20719 that the
      implementation was subtly incorrect, leading to valid programs being rejected.
      
      While we could scrutinize the code that manually constructs implication
      constraints and repair it, there is a better, less error-prone way to do
      things. After all, the heart of `DeriveAnyClass` is generating code which
      fills in each class method with defaults, e.g., `foo = $gdm_foo`. Typechecking
      this sort of code is tantamount to calling `tcSubTypeSigma`, as we much ensure
      that the type of `$gdm_foo` is a subtype of (i.e., more polymorphic than) the
      type of `foo`. As an added bonus, `tcSubTypeSigma` is a battle-tested function
      that handles skolemisation, metvariable instantiation, `TcLevel` bumping, and
      all other means of tricky bookkeeping correctly.
      
      With this insight, the solution to the problems uncovered in #20719 is simple:
      use `tcSubTypeSigma` to check if `$gdm_foo`'s type is a subtype of `foo`'s
      type. As a side effect, `tcSubTypeSigma` will emit exactly the implication
      constraint that we were attempting to construct by hand previously. Moreover,
      it does so correctly, fixing #20719 as a consequence.
      
      This patch implements the solution thusly:
      
      * The `PredSpec` data type (previously named `PredOrigin`) is now split into
        `SimplePredSpec`, which directly stores a `PredType`, and `SubTypePredSpec`,
        which stores the actual and expected types in a subtype check.
        `SubTypePredSpec` is only used for `DeriveAnyClass`; all other deriving
        strategies use `SimplePredSpec`.
      * Because `tcSubTypeSigma` manages the finer details of type variable
        instantiation and constraint solving under the hood, there is no longer any
        need to delicately split apart the method type signatures in
        `inferConstraintsAnyclass`. This greatly simplifies the implementation of
        `inferConstraintsAnyclass` and obviates the need to store skolems,
        metavariables, or given constraints in a `ThetaSpec` (previously named
        `ThetaOrigin`). As a bonus, this means that `ThetaSpec` now simply becomes a
        synonym for a list of `PredSpec`s, which is conceptually much simpler than it
        was before.
      * In `simplifyDeriv`, each `SubTypePredSpec` results in a call to
        `tcSubTypeSigma`. This is only performed for its side effect of emitting
        an implication constraint, which is fed to the rest of the constraint solving
        machinery in `simplifyDeriv`. I have updated
        `Note [Gathering and simplifying constraints for DeriveAnyClass]` to explain
        this in more detail.
      
      To make the changes in `simplifyDeriv` more manageable, I also performed some
      auxiliary refactoring:
      
      * Previously, every iteration of `simplifyDeriv` was skolemising the type
        variables at the start, simplifying, and then performing a reverse
        substitution at the end to un-skolemise the type variables. This is not
        necessary, however, since we can just as well skolemise once at the
        beginning of the `deriving` pipeline and zonk the `TcTyVar`s after
        `simplifyDeriv` is finished. This patch does just that, having been made
        possible by prior work in !7613. I have updated `Note [Overlap and deriving]`
        in `GHC.Tc.Deriv.Infer` to explain this, and I have also left comments on
        the relevant data structures (e.g., `DerivEnv` and `DerivSpec`) to explain
        when things might be `TcTyVar`s or `TyVar`s.
      * All of the aforementioned cleanup allowed me to remove an ad hoc
        deriving-related in `checkImplicationInvariants`, as all of the skolems in
        a `tcSubTypeSigma`–produced implication constraint should now be `TcTyVar`
        at the time the implication is created.
      * Since `simplifyDeriv` now needs a `SkolemInfo` and `UserTypeCtxt`, I have
        added `ds_skol_info` and `ds_user_ctxt` fields to `DerivSpec` to store these.
        Similarly, I have also added a `denv_skol_info` field to `DerivEnv`, which
        ultimately gets used to initialize the `ds_skol_info` in a `DerivSpec`.
      
      Fixes #20719.
      c58d008c
  27. Mar 21, 2022
    • Alex D's avatar
      Revamp derived Eq instance code generation (#17240) · c842611f
      Alex D authored and Marge Bot's avatar Marge Bot committed
      This patch improves code generation for derived Eq instances.
      The idea is to use 'dataToTag' to evaluate both arguments.
      This allows to 'short-circuit' when tags do not match.
      Unfortunately, inner evals are still present when we branch
      on tags. This is due to the way 'dataToTag#' primop
      evaluates its argument in the code generator. #21207 was
      created to explore further optimizations.
      
      Metric Decrease:
          LargeRecord
      c842611f
  28. Mar 15, 2022
    • Vladislav Zavialov's avatar
      Export (~) from Data.Type.Equality (#18862) · ab618309
      Vladislav Zavialov authored
      * Users can define their own (~) type operator
      * Haddock can display documentation for the built-in (~)
      * New transitional warnings implemented:
          -Wtype-equality-out-of-scope
          -Wtype-equality-requires-operators
      
      Updates the haddock submodule.
      ab618309
  29. Mar 01, 2022
    • Matthew Pickering's avatar
      driver: Properly add an edge between a .hs and its hs-boot file · c84dc506
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      As noted in #21071 we were missing adding this edge so there were
      situations where the .hs file would get compiled before the .hs-boot
      file which leads to issues with -j.
      
      I fixed this properly by adding the edge in downsweep so the definition
      of nodeDependencies can be simplified to avoid adding this dummy edge
      in.
      
      There are plenty of tests which seem to have these redundant boot files
      anyway so no new test. #21094 tracks the more general issue of
      identifying redundant hs-boot and SOURCE imports.
      c84dc506
  30. Feb 23, 2022
    • Richard Eisenberg's avatar
      Kill derived constraints · a599abba
      Richard Eisenberg authored and Marge Bot's avatar Marge Bot committed
      Co-authored by: Sam Derbyshire
      
      Previously, GHC had three flavours of constraint:
      Wanted, Given, and Derived. This removes Derived constraints.
      
      Though serving a number of purposes, the most important role
      of Derived constraints was to enable better error messages.
      This job has been taken over by the new RewriterSets, as explained
      in Note [Wanteds rewrite wanteds] in GHC.Tc.Types.Constraint.
      
      Other knock-on effects:
       - Various new Notes as I learned about under-described bits of GHC
      
       - A reshuffling around the AST for implicit-parameter bindings,
         with better integration with TTG.
      
       - Various improvements around fundeps. These were caused by the
         fact that, previously, fundep constraints were all Derived,
         and Derived constraints would get dropped. Thus, an unsolved
         Derived didn't stop compilation. Without Derived, this is no
         longer possible, and so we have to be considerably more careful
         around fundeps.
      
       - A nice little refactoring in GHC.Tc.Errors to center the work
         on a new datatype called ErrorItem. Constraints are converted
         into ErrorItems at the start of processing, and this allows for
         a little preprocessing before the main classification.
      
       - This commit also cleans up the behavior in generalisation around
         functional dependencies. Now, if a variable is determined by
         functional dependencies, it will not be quantified. This change
         is user facing, but it should trim down GHC's strange behavior
         around fundeps.
      
       - Previously, reportWanteds did quite a bit of work, even on an empty
         WantedConstraints. This commit adds a fast path.
      
       - Now, GHC will unconditionally re-simplify constraints during
         quantification. See Note [Unconditionally resimplify constraints when
         quantifying], in GHC.Tc.Solver.
      
      Close #18398.
      Close #18406.
      Solve the fundep-related non-confluence in #18851.
      Close #19131.
      Close #19137.
      Close #20922.
      Close #20668.
      Close #19665.
      
      -------------------------
      Metric Decrease:
          LargeRecord
          T9872b
          T9872b_defer
          T9872d
          TcPlugin_RewritePerf
      -------------------------
      a599abba
  31. Feb 22, 2022
    • sheaf's avatar
      Forbid standalone instances for built-in classes · 0b36801f
      sheaf authored and Marge Bot's avatar Marge Bot committed
        `check_special_inst_head` includes logic that disallows hand-written
        instances for built-in classes such as Typeable, KnownNat
        and KnownSymbol.
        However, it also allowed standalone deriving declarations. This was
        because we do want to allow standalone deriving instances with
        Typeable as they are harmless, but we certainly don't want to allow
        instances for e.g. KnownNat.
      
        This patch ensures that we don't allow derived instances for
        KnownNat, KnownSymbol (and also KnownChar, which was previously
        omitted entirely).
      
        Fixes #21087
      0b36801f
  32. Feb 06, 2022
  33. Jan 29, 2022
    • Matthew Pickering's avatar
      Rework the handling of SkolemInfo · 268efcc9
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      
      The main purpose of this patch is to attach a SkolemInfo directly to
      each SkolemTv. This fixes the large number of bugs which have
      accumulated over the years where we failed to report errors due to
      having "no skolem info" for particular type variables. Now the origin of
      each type varible is stored on the type variable we can always report
      accurately where it cames from.
      
      Fixes #20969 #20732 #20680 #19482 #20232 #19752 #10946
        #19760 #20063 #13499 #14040
      
      The main changes of this patch are:
      
      * SkolemTv now contains a SkolemInfo field which tells us how the
        SkolemTv was created. Used when reporting errors.
      
      * Enforce invariants relating the SkolemInfoAnon and level of an implication (ic_info, ic_tclvl)
        to the SkolemInfo and level of the type variables in ic_skols.
          * All ic_skols are TcTyVars -- Check is currently disabled
          * All ic_skols are SkolemTv
          * The tv_lvl of the ic_skols agrees with the ic_tclvl
          * The ic_info agrees with the SkolInfo of the implication.
      
        These invariants are checked by a debug compiler by
        checkImplicationInvariants.
      
      * Completely refactor kcCheckDeclHeader_sig which kept
        doing my head in. Plus, it wasn't right because it wasn't skolemising
        the binders as it decomposed the kind signature.
      
        The new story is described in Note [kcCheckDeclHeader_sig].  The code
        is considerably shorter than before (roughly 240 lines turns into 150
        lines).
      
        It still has the same awkward complexity around computing arity as
        before, but that is a language design issue.
        See Note [Arity inference in kcCheckDeclHeader_sig]
      
      * I added new type synonyms MonoTcTyCon and PolyTcTyCon, and used
        them to be clear which TcTyCons have "finished" kinds etc, and
        which are monomorphic. See Note [TcTyCon, MonoTcTyCon, and PolyTcTyCon]
      
      * I renamed etaExpandAlgTyCon to splitTyConKind, becuase that's a
        better name, and it is very useful in kcCheckDeclHeader_sig, where
        eta-expansion isn't an issue.
      
      * Kill off the nasty `ClassScopedTvEnv` entirely.
      
      Co-authored-by: default avatarSimon Peyton Jones <simon.peytonjones@gmail.com>
      268efcc9
  34. Jan 25, 2022
    • Ryan Scott's avatar
      DeriveGeneric: look up datacon fixities using getDataConFixityFun · 9d478d51
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Previously, `DeriveGeneric` would look up the fixity of a data constructor
      using `getFixityEnv`, but this is subtly incorrect for data constructors
      defined in external modules. This sort of situation can happen with
      `StandaloneDeriving`, as noticed in #20994. In fact, the same bug has occurred
      in the past in #9830, and while that bug was fixed for `deriving Read` and
      `deriving Show`, the fix was never extended to `DeriveGeneric` due to an
      oversight. This patch corrects that oversight.
      
      Fixes #20994.
      9d478d51
  35. Dec 28, 2021
    • Matthew Pickering's avatar
      Multiple Home Units · fd42ab5f
      Matthew Pickering authored
      
      Multiple home units allows you to load different packages which may depend on
      each other into one GHC session. This will allow both GHCi and HLS to support
      multi component projects more naturally.
      
      Public Interface
      ~~~~~~~~~~~~~~~~
      
      In order to specify multiple units, the -unit @⟨filename⟩ flag
      is given multiple times with a response file containing the arguments for each unit.
      The response file contains a newline separated list of arguments.
      
      ```
      ghc -unit @unitLibCore -unit @unitLib
      ```
      
      where the `unitLibCore` response file contains the normal arguments that cabal would pass to `--make` mode.
      
      ```
      -this-unit-id lib-core-0.1.0.0
      -i
      -isrc
      LibCore.Utils
      LibCore.Types
      ```
      
      The response file for lib, can specify a dependency on lib-core, so then modules in lib can use modules from lib-core.
      
      ```
      -this-unit-id lib-0.1.0.0
      -package-id lib-core-0.1.0.0
      -i
      -isrc
      Lib.Parse
      Lib.Render
      ```
      
      Then when the compiler starts in --make mode it will compile both units lib and lib-core.
      
      There is also very basic support for multiple home units in GHCi, at the
      moment you can start a GHCi session with multiple units but only the
      :reload is supported. Most commands in GHCi assume a single home unit,
      and so it is additional work to work out how to modify the interface to
      support multiple loaded home units.
      
      Options used when working with Multiple Home Units
      
      There are a few extra flags which have been introduced specifically for
      working with multiple home units. The flags allow a home unit to pretend
      it’s more like an installed package, for example, specifying the package
      name, module visibility and reexported modules.
      
      -working-dir ⟨dir⟩
      
          It is common to assume that a package is compiled in the directory
          where its cabal file resides. Thus, all paths used in the compiler
          are assumed to be relative to this directory. When there are
          multiple home units the compiler is often not operating in the
          standard directory and instead where the cabal.project file is
          located. In this case the -working-dir option can be passed which
          specifies the path from the current directory to the directory the
          unit assumes to be it’s root, normally the directory which contains
          the cabal file.
      
          When the flag is passed, any relative paths used by the compiler are
          offset by the working directory. Notably this includes -i and
          -I⟨dir⟩ flags.
      
      -this-package-name ⟨name⟩
      
          This flag papers over the awkward interaction of the PackageImports
          and multiple home units. When using PackageImports you can specify
          the name of the package in an import to disambiguate between modules
          which appear in multiple packages with the same name.
      
          This flag allows a home unit to be given a package name so that you
          can also disambiguate between multiple home units which provide
          modules with the same name.
      
      -hidden-module ⟨module name⟩
      
          This flag can be supplied multiple times in order to specify which
          modules in a home unit should not be visible outside of the unit it
          belongs to.
      
          The main use of this flag is to be able to recreate the difference
          between an exposed and hidden module for installed packages.
      
      -reexported-module ⟨module name⟩
      
          This flag can be supplied multiple times in order to specify which
          modules are not defined in a unit but should be reexported. The
          effect is that other units will see this module as if it was defined
          in this unit.
      
          The use of this flag is to be able to replicate the reexported
          modules feature of packages with multiple home units.
      
      Offsetting Paths in Template Haskell splices
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      When using Template Haskell to embed files into your program,
      traditionally the paths have been interpreted relative to the directory
      where the .cabal file resides. This causes problems for multiple home
      units as we are compiling many different libraries at once which have
      .cabal files in different directories.
      
      For this purpose we have introduced a way to query the value of the
      -working-dir flag to the Template Haskell API. By using this function we
      can implement a makeRelativeToProject function which offsets a path
      which is relative to the original project root by the value of
      -working-dir.
      
      ```
      import Language.Haskell.TH.Syntax ( makeRelativeToProject )
      
      foo = $(makeRelativeToProject "./relative/path" >>= embedFile)
      ```
      
      > If you write a relative path in a Template Haskell splice you should use the makeRelativeToProject function so that your library works correctly with multiple home units.
      
      A similar function already exists in the file-embed library. The
      function in template-haskell implements this function in a more robust
      manner by honouring the -working-dir flag rather than searching the file
      system.
      
      Closure Property for Home Units
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      For tools or libraries using the API there is one very important closure
      property which must be adhered to:
      
      > Any dependency which is not a home unit must not (transitively) depend
        on a home unit.
      
      For example, if you have three packages p, q and r, then if p depends on
      q which depends on r then it is illegal to load both p and r as home
      units but not q, because q is a dependency of the home unit p which
      depends on another home unit r.
      
      If you are using GHC by the command line then this property is checked,
      but if you are using the API then you need to check this property
      yourself. If you get it wrong you will probably get some very confusing
      errors about overlapping instances.
      
      Limitations of Multiple Home Units
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      There are a few limitations of the initial implementation which will be smoothed out on user demand.
      
          * Package thinning/renaming syntax is not supported
          * More complicated reexports/renaming are not yet supported.
          * It’s more common to run into existing linker bugs when loading a
            large number of packages in a session (for example #20674, #20689)
          * Backpack is not yet supported when using multiple home units.
          * Dependency chasing can be quite slow with a large number of
            modules and packages.
          * Loading wired-in packages as home units is currently not supported
            (this only really affects GHC developers attempting to load
            template-haskell).
          * Barely any normal GHCi features are supported, it would be good to
            support enough for ghcid to work correctly.
      
      Despite these limitations, the implementation works already for nearly
      all packages. It has been testing on large dependency closures,
      including the whole of head.hackage which is a total of 4784 modules
      from 452 packages.
      
      Internal Changes
      ~~~~~~~~~~~~~~~~
      
      * The biggest change is that the HomePackageTable is replaced with the
        HomeUnitGraph. The HomeUnitGraph is a map from UnitId to HomeUnitEnv,
        which contains information specific to each home unit.
      * The HomeUnitEnv contains:
          - A unit state, each home unit can have different package db flags
          - A set of dynflags, each home unit can have different flags
          - A HomePackageTable
      * LinkNode: A new node type is added to the ModuleGraph, this is used to
        place the linking step into the build plan so linking can proceed in
        parralel with other packages being built.
      * New invariant: Dependencies of a ModuleGraphNode can be completely
        determined by looking at the value of the node. In order to achieve
        this, downsweep now performs a more complete job of downsweeping and
        then the dependenices are recorded forever in the node rather than
        being computed again from the ModSummary.
      * Some transitive module calculations are rewritten to use the
        ModuleGraph which is more efficient.
      * There is always an active home unit, which simplifies modifying a lot
        of the existing API code which is unit agnostic (for example, in the
        driver).
      
      The road may be bumpy for a little while after this change but the
      basics are well-tested.
      
      One small metric increase, which we accept and also submodule update to
      haddock which removes ExtendedModSummary.
      
      Closes #10827
      
      -------------------------
      Metric Increase:
          MultiLayerModules
      -------------------------
      
      Co-authored-by: default avatarFendor <power.walross@gmail.com>
      fd42ab5f
  36. Dec 22, 2021
    • Matthew Pickering's avatar
      testsuite: Remove reqlib modifier · 3ed90911
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      The reqlib modifer was supposed to indicate that a test needed a certain
      library in order to work. If the library happened to be installed then
      the test would run as normal.
      
      However, CI has never run these tests as the packages have not been
      installed and we don't want out tests to depend on things which might
      get externally broken by updating the compiler.
      
      The new strategy is to run these tests in head.hackage, where the tests
      have been cabalised as well as possible. Some tests couldn't be
      transferred into the normal style testsuite but it's better than never
      running any of the reqlib tests. head.hackage!169
      
      A few submodules also had reqlib tests and have been updated to remove
      it.
      
      Closes #16264 #20032 #17764 #16561
      3ed90911
  37. Nov 25, 2021
    • Matthew Pickering's avatar
      Don't use implicit lifting when deriving Lift · 4d34bf15
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      It isn't much more complicated to be more precise when deriving Lift so
      we now generate
      
      ```
      data Foo = Foo Int Bool
      
      instance Lift Foo where
        lift (Foo a b) = [| Foo $(lift a) $(lift b) |]
        liftTyped (Foo a b) = [|| Foo $$(lift a) $$(lift b) |]
      ```
      
      This fixes #20688 which complained about using implicit lifting in the
      derived code.
      4d34bf15
Loading