Skip to content
Snippets Groups Projects
  1. Jul 13, 2023
    • sheaf's avatar
      Fix deprecation of record fields · 6143838a
      sheaf authored and Marge Bot's avatar Marge Bot committed
      Commit 3f374399 inadvertently broke the deprecation/warning mechanism
      for record fields due to its introduction of record field namespaces.
      
      This patch ensures that, when a top-level deprecation is applied to
      an identifier, it applies to all the record fields as well.
      This is achieved by refactoring GHC.Rename.Env.lookupLocalTcNames, and
      GHC.Rename.Env.lookupBindGroupOcc, to not look up a fixed number of
      NameSpaces but to look up all NameSpaces and filter out the irrelevant
      ones.
      6143838a
  2. Jul 06, 2023
  3. Jul 05, 2023
  4. Jun 27, 2023
  5. Jun 21, 2023
  6. Jun 18, 2023
  7. Jun 13, 2023
  8. Jun 09, 2023
    • Ryan Scott's avatar
      Consistently use validity checks for TH conversion of data constructors · 3ab0155b
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      We were checking that TH-spliced data declarations do not look like this:
      
      ```hs
      data D :: Type = MkD Int
      ```
      
      But we were only doing so for `data` declarations' data constructors, not for
      `newtype`s, `data instance`s, or `newtype instance`s. This patch factors out
      the necessary validity checks into its own `cvtDataDefnCons` function and uses
      it in all of the places where it needs to be.
      
      Fixes #22559.
      3ab0155b
  9. Jun 07, 2023
    • Vladislav Zavialov's avatar
      Invisible binders in type declarations (#22560) · 4aea0a72
      Vladislav Zavialov authored
      
      This patch implements @k-binders introduced in GHC Proposal #425
      and guarded behind the TypeAbstractions extension:
      
      	type D :: forall k j. k -> j -> Type
      	data D @k @j a b = ...
      	       ^^ ^^
      
      To represent the new syntax, we modify LHsQTyVars as follows:
      
      	-  hsq_explicit :: [LHsTyVarBndr () pass]
      	+  hsq_explicit :: [LHsTyVarBndr (HsBndrVis pass) pass]
      
      HsBndrVis is a new data type that records the distinction between
      type variable binders written with and without the @ sign:
      
      	data HsBndrVis pass
      	  = HsBndrRequired
      	  | HsBndrInvisible (LHsToken "@" pass)
      
      The rest of the patch updates GHC, template-haskell, and haddock
      to handle the new syntax.
      
      Parser:
        The PsErrUnexpectedTypeAppInDecl error message is removed.
        The syntax it used to reject is now permitted.
      
      Renamer:
        The @ sign does not affect the scope of a binder, so the changes to
        the renamer are minimal.  See rnLHsTyVarBndrVisFlag.
      
      Type checker:
        There are three code paths that were updated to deal with the newly
        introduced invisible type variable binders:
      
          1. checking SAKS: see kcCheckDeclHeader_sig, matchUpSigWithDecl
          2. checking CUSK: see kcCheckDeclHeader_cusk
          3. inference: see kcInferDeclHeader, rejectInvisibleBinders
      
        Helper functions bindExplicitTKBndrs_Q_Skol and bindExplicitTKBndrs_Q_Tv
        are generalized to work with HsBndrVis.
      
      Updates the haddock submodule.
      
      Metric Increase:
          MultiLayerModulesTH_OneShot
      
      Co-authored-by: default avatarSimon Peyton Jones <simon.peytonjones@gmail.com>
      4aea0a72
  10. May 29, 2023
  11. May 25, 2023
  12. May 19, 2023
  13. May 18, 2023
  14. May 09, 2023
  15. May 05, 2023
  16. Apr 30, 2023
  17. Apr 25, 2023
  18. Apr 18, 2023
    • Matthew Pickering's avatar
      Convert interface file loading errors into proper diagnostics · 5e1d33d7
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      This patch converts all the errors to do with loading interface files
      into proper structured diagnostics.
      
      * DriverMessage: Sometimes in the driver we attempt to load an interface
        file so we embed the IfaceMessage into the DriverMessage.
      * TcRnMessage: Most the time we are loading interface files during
        typechecking, so we embed the IfaceMessage
      
      This patch also removes the TcRnInterfaceLookupError constructor which
      is superceded by the IfaceMessage, which is now structured compared to
      just storing an SDoc before.
      5e1d33d7
  19. Apr 12, 2023
    • Oleg Grenrus's avatar
      Allow generation of TTH syntax with TH · ebd8918b
      Oleg Grenrus authored and Marge Bot's avatar Marge Bot committed
      In other words allow generation of typed splices and brackets with
      Untyped Template Haskell.
      
      That is useful in cases where a library is build with TTH in mind,
      but we still want to generate some auxiliary declarations,
      where TTH cannot help us, but untyped TH can.
      Such example is e.g. `staged-sop` which works with TTH,
      but we would like to derive `Generic` declarations with TH.
      
      An alternative approach is to use `unsafeCodeCoerce`, but then the
      derived `Generic` instances would be type-checked only at use sites,
      i.e. much later. Also `-ddump-splices` output is quite ugly:
      user-written instances would use TTH brackets, not `unsafeCodeCoerce`.
      
      This commit doesn't allow generating of untyped template splices
      and brackets with untyped TH, as I don't know why one would want to do
      that (instead of merging the splices, e.g.)
      ebd8918b
  20. Apr 04, 2023
    • Ryan Scott's avatar
      Make INLINE pragmas for pattern synonyms work with TH · 071139c3
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Previously, the code for converting `INLINE <name>` pragmas from TH splices
      used `vNameN`, which assumed that `<name>` must live in the variable namespace.
      Pattern synonyms, on the other hand, live in the constructor namespace. I've
      fixed the issue by switching to `vcNameN` instead, which works for both the
      variable and constructor namespaces.
      
      Fixes #23203.
      071139c3
  21. Apr 03, 2023
    • Haskell-mouse's avatar
      Convert diagnostics in GHC.Rename.HsType to proper TcRnMessage · 8b092910
      Haskell-mouse authored and Marge Bot's avatar Marge Bot committed
      I've turned all occurrences of TcRnUnknownMessage in GHC.Rename.HsType
      module into a proper TcRnMessage.
      Instead, these TcRnMessage messages were introduced:
      
      TcRnDataKindsError
      TcRnUnusedQuantifiedTypeVar
      TcRnIllegalKindSignature
      TcRnUnexpectedPatSigType
      TcRnSectionPrecedenceError
      TcRnPrecedenceParsingError
      TcRnIllegalKind
      TcRnNegativeNumTypeLiteral
      TcRnUnexpectedKindVar
      TcRnBindMultipleVariables
      TcRnBindVarAlreadyInScope
      8b092910
  22. Apr 01, 2023
  23. Mar 30, 2023
  24. 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
  25. Mar 21, 2023
  26. Mar 01, 2023
  27. Jan 31, 2023
    • Ryan Scott's avatar
      Fix two bugs in TypeData TH reification · 2f145052
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This patch fixes two issues in the way that `type data` declarations were
      reified with Template Haskell:
      
      * `type data` data constructors are now properly reified using `DataConI`.
        This is accomplished with a special case in `reifyTyCon`. Fixes #22818.
      
      * `type data` type constructors are now reified in `reifyTyCon` using
        `TypeDataD` instead of `DataD`. Fixes #22819.
      2f145052
  28. Jan 27, 2023
    • Andrei Borzenkov's avatar
      Replace errors from badOrigBinding with new one (#22839) · 2648c09c
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      Problem: in 02279a9c the type-level [] syntax was changed from a built-in name
      to an alias for the GHC.Types.List constructor. badOrigBinding assumes that if
      a name is not built-in then it must have come from TH quotation, but this is
      not necessarily the case with [].
      
      The outdated assumption in badOrigBinding leads to incorrect error messages.
      This code:
        data []
      Fails with "Cannot redefine a Name retrieved by a Template Haskell quote: []"
      
      Unfortunately, there is not enough information in RdrName to directly determine
      if the name was constructed via TH or by the parser, so this patch changes the
      error message instead.
      
      It unifies TcRnIllegalBindingOfBuiltIn and TcRnNameByTemplateHaskellQuote
      into a new error TcRnBindingOfExistingName and changes its wording to avoid
      guessing the origin of the name.
      2648c09c
  29. Jan 19, 2023
    • Andrei Borzenkov's avatar
      Fix printing of promoted MkSolo datacon (#22785) · 14b5982a
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      Problem: In 2463df2f, the Solo data constructor was renamed to MkSolo,
      and Solo was turned into a pattern synonym for backwards compatibility.
      Since pattern synonyms can not be promoted, the old code that pretty-printed
      promoted single-element tuples started producing ill-typed code:
         t :: Proxy ('Solo Int)
      This fails with "Pattern synonym ‘Solo’ used as a type"
      
      The solution is to track the distinction between type constructors and data
      constructors more carefully when printing single-element tuples.
      14b5982a
  30. Jan 18, 2023
    • Ryan Scott's avatar
      Add missing parenthesizeHsType in cvtSigTypeKind · 4efee43d
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      We need to ensure that the output of `cvtSigTypeKind` is parenthesized (at
      precedence `sigPrec`) so that any type signatures with an outermost, explicit
      kind signature can parse correctly.
      
      Fixes #22784.
      4efee43d
  31. Dec 09, 2022
    • Krzysztof Gogolewski's avatar
      Fixes around primitive literals · b0cc2fcf
      Krzysztof Gogolewski authored and Marge Bot's avatar Marge Bot committed
      * The SourceText of primitive characters 'a'# did not include
        the #, unlike for other primitive literals 1#, 1##, 1.0#, 1.0##, "a"#.
        We can now remove the function pp_st_suffix, which was a hack
        to add the # back.
      * Negative primitive literals shouldn't use parentheses, as described in
        Note [Printing of literals in Core]. Added a testcase to T14681.
      b0cc2fcf
  32. Nov 29, 2022
  33. Nov 24, 2022
    • Andrei Borzenkov's avatar
      Convert diagnostics in GHC.Rename.Expr to proper TcRnMessage (#20115) · 86ff1523
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      
      Problem: avoid usage of TcRnMessageUnknown
      
      Solution:
      The following `TcRnMessage` messages has been introduced:
        TcRnNoRebindableSyntaxRecordDot
        TcRnNoFieldPunsRecordDot
        TcRnIllegalStaticExpression
        TcRnIllegalStaticFormInSplice
        TcRnListComprehensionDuplicateBinding
        TcRnEmptyStmtsGroup
        TcRnLastStmtNotExpr
        TcRnUnexpectedStatementInContext
        TcRnIllegalTupleSection
        TcRnIllegalImplicitParameterBindings
        TcRnSectionWithoutParentheses
      
      Co-authored-by: sheaf's avatarsheaf <sam.derbyshire@gmail.com>
      86ff1523
  34. Nov 11, 2022
    • Simon Peyton Jones's avatar
      Type vs Constraint: finally nailed · 778c6adc
      Simon Peyton Jones authored and Simon Peyton Jones's avatar Simon Peyton Jones committed
      This big patch addresses the rats-nest of issues that have plagued
      us for years, about the relationship between Type and Constraint.
      See #11715/#21623.
      
      The main payload of the patch is:
      * To introduce CONSTRAINT :: RuntimeRep -> Type
      * To make TYPE and CONSTRAINT distinct throughout the compiler
      
      Two overview Notes in GHC.Builtin.Types.Prim
      
      * Note [TYPE and CONSTRAINT]
      
      * Note [Type and Constraint are not apart]
        This is the main complication.
      
      The specifics
      
      * New primitive types (GHC.Builtin.Types.Prim)
        - CONSTRAINT
        - ctArrowTyCon (=>)
        - tcArrowTyCon (-=>)
        - ccArrowTyCon (==>)
        - funTyCon     FUN     -- Not new
        See Note [Function type constructors and FunTy]
        and Note [TYPE and CONSTRAINT]
      
      * GHC.Builtin.Types:
        - New type Constraint = CONSTRAINT LiftedRep
        - I also stopped nonEmptyTyCon being built-in; it only needs to be wired-in
      
      * Exploit the fact that Type and Constraint are distinct throughout GHC
        - Get rid of tcView in favour of coreView.
        - Many tcXX functions become XX functions.
          e.g. tcGetCastedTyVar --> getCastedTyVar
      
      * Kill off Note [ForAllTy and typechecker equality], in (old)
        GHC.Tc.Solver.Canonical.  It said that typechecker-equality should ignore
        the specified/inferred distinction when comparein two ForAllTys.  But
        that wsa only weakly supported and (worse) implies that we need a separate
        typechecker equality, different from core equality. No no no.
      
      * GHC.Core.TyCon: kill off FunTyCon in data TyCon.  There was no need for it,
        and anyway now we have four of them!
      
      * GHC.Core.TyCo.Rep: add two FunTyFlags to FunCo
        See Note [FunCo] in that module.
      
      * GHC.Core.Type.  Lots and lots of changes driven by adding CONSTRAINT.
        The key new function is sORTKind_maybe; most other changes are built
        on top of that.
      
        See also `funTyConAppTy_maybe` and `tyConAppFun_maybe`.
      
      * Fix a longstanding bug in GHC.Core.Type.typeKind, and Core Lint, in
        kinding ForAllTys.  See new tules (FORALL1) and (FORALL2) in GHC.Core.Type.
        (The bug was that before (forall (cv::t1 ~# t2). blah), where
        blah::TYPE IntRep, would get kind (TYPE IntRep), but it should be
        (TYPE LiftedRep).  See Note [Kinding rules for types] in GHC.Core.Type.
      
      * GHC.Core.TyCo.Compare is a new module in which we do eqType and cmpType.
        Of course, no tcEqType any more.
      
      * GHC.Core.TyCo.FVs. I moved some free-var-like function into this module:
        tyConsOfType, visVarsOfType, and occCheckExpand.  Refactoring only.
      
      * GHC.Builtin.Types.  Compiletely re-engineer boxingDataCon_maybe to
        have one for each /RuntimeRep/, rather than one for each /Type/.
        This dramatically widens the range of types we can auto-box.
        See Note [Boxing constructors] in GHC.Builtin.Types
        The boxing types themselves are declared in library ghc-prim:GHC.Types.
      
        GHC.Core.Make.  Re-engineer the treatment of "big" tuples (mkBigCoreVarTup
        etc) GHC.Core.Make, so that it auto-boxes unboxed values and (crucially)
        types of kind Constraint. That allows the desugaring for arrows to work;
        it gathers up free variables (including dictionaries) into tuples.
        See  Note [Big tuples] in GHC.Core.Make.
      
        There is still work to do here: #22336. But things are better than
        before.
      
      * GHC.Core.Make.  We need two absent-error Ids, aBSENT_ERROR_ID for types of
        kind Type, and aBSENT_CONSTRAINT_ERROR_ID for vaues of kind Constraint.
        Ditto noInlineId vs noInlieConstraintId in GHC.Types.Id.Make;
        see Note [inlineId magic].
      
      * GHC.Core.TyCo.Rep. Completely refactor the NthCo coercion.  It is now called
        SelCo, and its fields are much more descriptive than the single Int we used to
        have.  A great improvement.  See Note [SelCo] in GHC.Core.TyCo.Rep.
      
      * GHC.Core.RoughMap.roughMatchTyConName.  Collapse TYPE and CONSTRAINT to
        a single TyCon, so that the rough-map does not distinguish them.
      
      * GHC.Core.DataCon
        - Mainly just improve documentation
      
      * Some significant renamings:
        GHC.Core.Multiplicity: Many -->  ManyTy (easier to grep for)
                               One  -->  OneTy
        GHC.Core.TyCo.Rep TyCoBinder      -->   GHC.Core.Var.PiTyBinder
        GHC.Core.Var      TyCoVarBinder   -->   ForAllTyBinder
                          AnonArgFlag     -->   FunTyFlag
                          ArgFlag         -->   ForAllTyFlag
        GHC.Core.TyCon    TyConTyCoBinder --> TyConPiTyBinder
        Many functions are renamed in consequence
        e.g. isinvisibleArgFlag becomes isInvisibleForAllTyFlag, etc
      
      * I refactored FunTyFlag (was AnonArgFlag) into a simple, flat data type
          data FunTyFlag
            = FTF_T_T           -- (->)  Type -> Type
            | FTF_T_C           -- (-=>) Type -> Constraint
            | FTF_C_T           -- (=>)  Constraint -> Type
            | FTF_C_C           -- (==>) Constraint -> Constraint
      
      * GHC.Tc.Errors.Ppr.  Some significant refactoring in the TypeEqMisMatch case
        of pprMismatchMsg.
      
      * I made the tyConUnique field of TyCon strict, because I
        saw code with lots of silly eval's.  That revealed that
        GHC.Settings.Constants.mAX_SUM_SIZE can only be 63, because
        we pack the sum tag into a 6-bit field.  (Lurking bug squashed.)
      
      Fixes
      * #21530
      
      Updates haddock submodule slightly.
      
      Performance changes
      ~~~~~~~~~~~~~~~~~~~
      I was worried that compile times would get worse, but after
      some careful profiling we are down to a geometric mean 0.1%
      increase in allocation (in perf/compiler).  That seems fine.
      
      There is a big runtime improvement in T10359
      
      Metric Decrease:
          LargeRecord
          MultiLayerModulesTH_OneShot
          T13386
          T13719
      Metric Increase:
          T8095
      778c6adc
  35. Nov 01, 2022
    • Vladislav Zavialov's avatar
      ThToHs: fix overzealous parenthesization · 30e625e6
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      Before this patch, when converting from TH.Exp to LHsExpr GhcPs,
      the compiler inserted more parentheses than required:
      
      	((f a) (b + c)) d
      
      This was happening because the LHS of the function application was
      parenthesized as if it was the RHS.
      
      Now we use funPrec and appPrec appropriately and produce sensibly
      parenthesized expressions:
      
      	f a (b + c) d
      
      I also took the opportunity to remove the special case for LamE,
      which was not special at all and simply duplicated code.
      30e625e6
Loading