Skip to content
Snippets Groups Projects
  1. Mar 07, 2024
    • Vladislav Zavialov's avatar
      Rephrase error message to say "visible arguments" (#24318) · 9cd9efb4
      Vladislav Zavialov authored
      * Main change: make the error message generated by mkFunTysMsg more
        accurate by changing "value arguments" to "visible arguments".
      
      * Refactor: define a new type synonym VisArity and use it instead of
        Arity in a few places.
      
      It might be the case that there other places in the compiler that should
      talk about visible arguments rather than value arguments, but I haven't
      tried to find them all, focusing only on the error message reported in
      the ticket.
      9cd9efb4
  2. Mar 01, 2024
    • Torsten Schmits's avatar
      Introduce ListTuplePuns extension · d91d00fc
      Torsten Schmits authored and Marge Bot's avatar Marge Bot committed
      This implements Proposal 0475, introducing the `ListTuplePuns` extension
      which is enabled by default.
      
      Disabling this extension makes it invalid to refer to list, tuple and
      sum type constructors by using built-in syntax like `[Int]`,
      `(Int, Int)`, `(# Int#, Int# #)` or `(# Int | Int #)`.
      Instead, this syntax exclusively denotes data constructors for use with
      `DataKinds`.
      The conventional way of referring to these data constructors by
      prefixing them with a single quote (`'(Int, Int)`) is now a parser
      error.
      
      Tuple declarations have been moved to `GHC.Tuple.Prim` and the `Solo`
      data constructor has been renamed to `MkSolo` (in a previous commit).
      Unboxed tuples and sums now have real source declarations in `GHC.Types`.
      Unit and solo types for tuples are now called `Unit`, `Unit#`, `Solo`
      and `Solo#`.
      Constraint tuples now have the unambiguous type constructors `CTuple<n>`
      as well as `CUnit` and `CSolo`, defined in `GHC.Classes` like before.
      
      A new parser construct has been added for the unboxed sum data
      constructor declarations.
      
      The type families `Tuple`, `Sum#` etc. that were intended to provide
      nicer syntax have been omitted from this change set due to inference
      problems, to be implemented at a later time.
      See the MR discussion for more info.
      
      Updates the submodule utils/haddock.
      Updates the cabal submodule due to new language extension.
      
          Metric Increase:
              haddock.base
      
          Metric Decrease:
              MultiLayerModulesTH_OneShot
              size_hello_artifact
      
      Proposal document: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0475-tuple-syntax.rst
      
      Merge request: !8820
      
      Tracking ticket: #21294
      d91d00fc
  3. Feb 25, 2024
  4. Feb 21, 2024
    • Andrei Borzenkov's avatar
      Namespacing for fixity signatures (#14032) · 77629e76
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      Namespace specifiers were added to syntax of fixity signatures:
        - sigdecl ::= infix prec ops | ...
        + sigdecl ::= infix prec namespace_spec ops | ...
      
      To preserve namespace during renaming MiniFixityEnv type
      now has separate FastStringEnv fields for names that should be
      on the term level and for name that should be on the type level.
      
      makeMiniFixityEnv function was changed to fill MiniFixityEnv in the right way:
       - signatures without namespace specifiers fill both fields
       - signatures with 'data' specifier fill data field only
       - signatures with 'type' specifier fill type field only
      
      Was added helper function lookupMiniFixityEnv that takes care about
      looking for a name in an appropriate namespace.
      
      Updates haddock submodule.
      
      Metric Decrease:
          MultiLayerModulesTH_OneShot
      77629e76
  5. Feb 19, 2024
    • Andrei Borzenkov's avatar
      Parser, renamer, type checker for @a-binders (#17594) · 0dbd729e
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      GHC Proposal 448 introduces binders for invisible type arguments
      (@a-binders) in various contexts. This patch implements @-binders
      in lambda patterns and function equations:
      
        {-# LANGUAGE TypeAbstractions #-}
      
        id1 :: a -> a
        id1 @t x = x :: t      -- @t-binder on the LHS of a function equation
      
        higherRank :: (forall a. (Num a, Bounded a) => a -> a) -> (Int8, Int16)
        higherRank f = (f 42, f 42)
      
        ex :: (Int8, Int16)
        ex = higherRank (\ @a x -> maxBound @a - x )
                               -- @a-binder in a lambda pattern in an argument
                               -- to a higher-order function
      
      Syntax
      ------
      
      To represent those @-binders in the AST, the list of patterns in Match
      now uses ArgPat instead of Pat:
      
        data Match p body
           = Match {
               ...
      -        m_pats  :: [LPat p],
      +        m_pats  :: [LArgPat p],
               ...
         }
      
      + data ArgPat pass
      +   = VisPat (XVisPat pass) (LPat pass)
      +   | InvisPat (XInvisPat pass) (HsTyPat (NoGhcTc pass))
      +   | XArgPat !(XXArgPat pass)
      
      The VisPat constructor represents patterns for visible arguments,
      which include ordinary value-level arguments and required type arguments
      (neither is prefixed with a @), while InvisPat represents invisible type
      arguments (prefixed with a @).
      
      Parser
      ------
      
      In the grammar (Parser.y), the lambda and lambda-cases productions of
      aexp non-terminal were updated to accept argpats instead of apats:
      
        aexp : ...
      -        | '\\' apats '->' exp
      +        | '\\' argpats '->' exp
               ...
      -        | '\\' 'lcases' altslist(apats)
      +        | '\\' 'lcases' altslist(argpats)
               ...
      
      + argpat : apat
      +        | PREFIX_AT atype
      
      Function left-hand sides did not require any changes to the grammar, as
      they were already parsed with productions capable of parsing @-binders.
      Those binders were being rejected in post-processing (isFunLhs), and now
      we accept them.
      
      In Parser.PostProcess, patterns are constructed with the help of
      PatBuilder, which is used as an intermediate data structure when
      disambiguating between FunBind and PatBind. In this patch we define
      ArgPatBuilder to accompany PatBuilder. ArgPatBuilder is a short-lived
      data structure produced in isFunLhs and consumed in checkFunBind.
      
      Renamer
      -------
      
      Renaming of @-binders builds upon prior work on type patterns,
      implemented in 2afbddb0, which guarantees proper scoping and
      shadowing behavior of bound type variables.
      
      This patch merely defines rnLArgPatsAndThen to process a mix of visible
      and invisible patterns:
      
      + rnLArgPatsAndThen :: NameMaker -> [LArgPat GhcPs] -> CpsRn [LArgPat GhcRn]
      + rnLArgPatsAndThen mk = mapM (wrapSrcSpanCps rnArgPatAndThen) where
      +   rnArgPatAndThen (VisPat x p)    = ... rnLPatAndThen ...
      +   rnArgPatAndThen (InvisPat _ tp) = ... rnHsTyPat ...
      
      Common logic between rnArgPats and rnPats is factored out into the
      rn_pats_general helper.
      
      Type checker
      ------------
      
      Type-checking of @-binders builds upon prior work on lazy skolemisation,
      implemented in f5d3e03c.
      
      This patch extends tcMatchPats to handle @-binders. Now it takes and
      returns a list of LArgPat rather than LPat:
      
        tcMatchPats ::
                    ...
      -             -> [LPat GhcRn]
      +             -> [LArgPat GhcRn]
                    ...
      -             -> TcM ([LPat GhcTc], a)
      +             -> TcM ([LArgPat GhcTc], a)
      
      Invisible binders in the Match are matched up with invisible (Specified)
      foralls in the type. This is done with a new clause in the `loop` worker
      of tcMatchPats:
      
        loop :: [LArgPat GhcRn] -> [ExpPatType] -> TcM ([LArgPat GhcTc], a)
        loop (L l apat : pats) (ExpForAllPatTy (Bndr tv vis) : pat_tys)
          ...
          -- NEW CLAUSE:
          | InvisPat _ tp <- apat, isSpecifiedForAllTyFlag vis
          = ...
      
      In addition to that, tcMatchPats no longer discards type patterns. This
      is done by filterOutErasedPats in the desugarer instead.
      
      x86_64-linux-deb10-validate+debug_info
      Metric Increase:
          MultiLayerModulesTH_OneShot
      0dbd729e
  6. Feb 08, 2024
    • Ben Gamari's avatar
      Move `base` to `ghc-internal` · 44f6557a
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Here we move a good deal of the implementation of `base` into a new
      package, `ghc-internal` such that it can be evolved independently
      from the user-visible interfaces of `base`.
      
      While we want to isolate implementation from interfaces, naturally, we
      would like to avoid turning `base` into a mere set of module re-exports.
      However, this is a non-trivial undertaking for a variety of reasons:
      
       * `base` contains numerous known-key and wired-in things, requiring
         corresponding changes in the compiler
      
       * `base` contains a significant amount of C code and corresponding
         autoconf logic, which is very fragile and difficult to break apart
      
       * `base` has numerous import cycles, which are currently dealt with via
         carefully balanced `hs-boot` files
      
       * We must not break existing users
      
      To accomplish this migration, I tried the following approaches:
      
      * [Split-GHC.Base]: Break apart the GHC.Base knot to allow incremental
        migration of modules into ghc-internal: this knot is simply too
        intertwined to be easily pulled apart, especially given the rather
        tricky import cycles that it contains)
      
      * [Move-Core]: Moving the "core" connected component of base (roughly
        150 modules) into ghc-internal. While the Haskell side of this seems
        tractable, the C dependencies are very subtle to break apart.
      
      * [Move-Incrementally]:
      
        1. Move all of base into ghc-internal
        2. Examine the module structure and begin moving obvious modules (e.g.
           leaves of the import graph) back into base
        3. Examine the modules remaining in ghc-internal, refactor as necessary
           to facilitate further moves
        4. Go to (2) iterate until the cost/benefit of further moves is
           insufficient to justify continuing
        5. Rename the modules moved into ghc-internal to ensure that they don't
           overlap with those in base
        6. For each module moved into ghc-internal, add a shim module to base
           with the declarations which should be exposed and any requisite
           Haddocks (thus guaranteeing that base will be insulated from changes
           in the export lists of modules in ghc-internal
      
      Here I am using the [Move-Incrementally] approach, which is empirically
      the least painful of the unpleasant options above
      
      Bumps haddock submodule.
      
      Metric Decrease:
          haddock.Cabal
          haddock.base
      Metric Increase:
          MultiComponentModulesRecomp
          T16875
          size_hello_artifact
      44f6557a
  7. Feb 06, 2024
    • Andrei Borzenkov's avatar
      Lazy skolemisation for @a-binders (#17594) · f5d3e03c
      Andrei Borzenkov authored and Marge Bot's avatar Marge Bot committed
      This patch is a preparation for @a-binders implementation.  The main changes are:
      
      * Skolemisation is now prepared to deal with @binders.
        See Note [Skolemisation overview] in GHC.Tc.Utils.Unify.
        Most of the action is in
          - Utils.Unify.matchExpectedFunTys
          - Gen.Pat.tcMatchPats
          - Gen.Expr.tcPolyExprCheck
          - Gen.Binds.tcPolyCheck
      
      Some accompanying refactoring:
      
      * I found that funTyConAppTy_maybe was doing a lot of allocation, and
        rejigged userTypeError_maybe to avoid calling it.
      f5d3e03c
  8. Jan 26, 2024
    • Matt Walker's avatar
      Fix #24308 · b2d8cd85
      Matt Walker authored
      Add tests for semicolon separated where clauses
      b2d8cd85
  9. Jan 10, 2024
  10. Dec 12, 2023
  11. Dec 11, 2023
    • Vladislav Zavialov's avatar
      Make forall a keyword (#23719) · d9e4c597
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      Before this change, GHC used to accept `forall` as a term-level
      identifier:
      
      	-- from constraints-0.13
      	forall :: forall p. (forall a. Dict (p a)) -> Dict (Forall p)
      	forall d = ...
      
      Now it is a parse error.
      
      The -Wforall-identifier warning has served its purpose and is now
      a deprecated no-op.
      d9e4c597
  12. Dec 06, 2023
    • Vladislav Zavialov's avatar
      T2T in Patterns (#23739) · 0f0c53a5
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      This patch implements the T2T (term-to-type) transformation in patterns.
      Patterns that are checked against a visible forall can now be written
      without the `type` keyword:
      
      	  \(type t) (x :: t) -> ...   -- old
      	  \t (x :: t) -> ...          -- new
      
      The `t` binder is parsed and renamed as a term pattern (Pat), but
      then undergoes a conversion to a type pattern (HsTyPat).
      See the new function pat_to_type_pat in compiler/GHC/Tc/Gen/Pat.hs
      0f0c53a5
  13. Oct 28, 2023
  14. Oct 12, 2023
  15. Oct 10, 2023
  16. Oct 05, 2023
  17. Sep 27, 2023
  18. Sep 15, 2023
  19. Sep 12, 2023
    • Matthew Pickering's avatar
      Add -Winconsistent-flags warning · 21a906c2
      Matthew Pickering authored and Krzysztof Gogolewski's avatar Krzysztof Gogolewski committed
      The warning fires when inconsistent command line flags are passed.
      
      For example:
      
      * -dynamic-too and -dynamic
      * -dynamic-too on windows
      * -O and --interactive
      * etc
      
      This is on by default and allows users to control whether the warning is
      displayed and whether it should be an error or not.
      
      Fixes #22572
      21a906c2
    • Mario's avatar
      Fix TH pretty-printing of nested GADTs, issue #23937 · f418f919
      Mario authored and Marge Bot's avatar Marge Bot committed
      This commit fixes `Language.Haskell.TH.Ppr.pprint` so that it correctly
      pretty-prints GADTs declarations contained within data family instances.
      
      Fixes #23937
      f418f919
  20. Sep 08, 2023
    • Oleg Grenrus's avatar
      Add warning for badly staged types. · 88b942c4
      Oleg Grenrus authored and Marge Bot's avatar Marge Bot committed
      Resolves #23829.
      
      The stage violation results in out-of-bound names in splices.
      Technically this is an error, but someone might rely on this!?
      
      Internal changes:
      - we now track stages for TyVars.
      - thLevel (RunSplice _) = 0, instead of panic, as reifyInstances does
        in fact rename its argument type, and it can contain variables.
      88b942c4
  21. Aug 28, 2023
  22. Aug 08, 2023
    • Ryan Scott's avatar
      tcExpr: Push expected types for untyped TH splices inwards · 3b373838
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      In !10911, I deleted a `tcExpr` case for `HsUntypedSplice` in favor of a much
      simpler case that simply delegates to `tcApp`. Although this passed the test
      suite at the time, this was actually an error, as the previous `tcExpr` case
      was critically pushing the expected type inwards. This actually matters for
      programs like the one in #23796, which GHC would not accept with type inference
      alone—we need full-blown type _checking_ to accept these.
      
      I have added back the previous `tcExpr` case for `HsUntypedSplice` and now
      explain why we have two different `HsUntypedSplice` cases (one in `tcExpr` and
      another in `splitHsApps`) in `Note [Looking through Template Haskell splices in
      splitHsApps]` in `GHC.Tc.Gen.Head`.
      
      Fixes #23796.
      3b373838
  23. Aug 04, 2023
    • Vladislav Zavialov's avatar
      Fix (~) and (@) infix operators in TH splices (#23748) · 46fd8ced
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      8168b42a "Whitespace-sensitive bang patterns" allows GHC to accept
      the following infix operators:
      
      	a ~ b = ()
      	a @ b = ()
      
      But not if TH is used to generate those declarations:
      
      	$([d| a ~ b = ()
      	      a @ b = ()
      	    |])
      
      	-- Test.hs:5:2: error: [GHC-55017]
      	--    Illegal variable name: ‘~’
      	--    When splicing a TH declaration: (~_0) a_1 b_2 = GHC.Tuple.Prim.()
      
      This is easily fixed by modifying `reservedOps` in GHC.Utils.Lexeme
      46fd8ced
    • Ryan Scott's avatar
      Look through TH splices in splitHsApps · fdef003a
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This modifies `splitHsApps` (a key function used in typechecking function
      applications) to look through untyped TH splices and quasiquotes. Not doing so
      was the cause of #21077. This builds on !7821 by making `splitHsApps` match on
      `HsUntypedSpliceTop`, which contains the `ThModFinalizers` that must be run as
      part of invoking the TH splice. See the new `Note [Looking through Template
      Haskell splices in splitHsApps]` in `GHC.Tc.Gen.Head`.
      
      Along the way, I needed to make the type of `splitHsApps.set` slightly more
      general to accommodate the fact that the location attached to a quasiquote is
      a `SrcAnn NoEpAnns` rather than a `SrcSpanAnnA`.
      
      Fixes #21077.
      fdef003a
  24. 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
  25. Jul 06, 2023
  26. Jul 05, 2023
  27. Jun 27, 2023
  28. Jun 21, 2023
  29. Jun 18, 2023
  30. Jun 13, 2023
  31. 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
  32. 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
  33. May 29, 2023
  34. May 25, 2023
Loading