1. 25 Jun, 2020 2 commits
    • Roland Senn's avatar
      In `:break ident` allow out of scope and nested identifiers (Fix #3000) · 7e6d3d09
      Roland Senn authored
      This patch fixes the bug and implements the feature request of #3000.
      
      1. If `Module` is a real module name and `identifier` a name of a
      top-level function in `Module` then `:break Module.identifer` works
      also for an `identifier` that is out of scope.
      
      2. Extend the syntax for `:break identifier` to:
      
          :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent]
      
      `ModQual` is optional and is either the effective name of a module or
      the local alias of a qualified import statement.
      
      `topLevelIdent` is the name of a top level function in the module
      referenced by `ModQual`.
      
      `nestedIdent` is optional and the name of a function nested in a let or
      where clause inside the previously mentioned function `nestedIdent` or
      `topLevelIdent`.
      
      If `ModQual` is a module name, then `topLevelIdent` can be any top level
      identifier in this module. If `ModQual` is missing or a local alias of a
      qualified import, then `topLevelIdent` must be in scope.
      
      Breakpoints can be set on arbitrarily deeply nested functions, but the
      whole chain of nested function names must be specified.
      
      3. To support the new functionality rewrite the code to tab complete `:break`.
      7e6d3d09
    • Andreas Klebinger's avatar
      Enable large address space optimization on windows. · 03a708ba
      Andreas Klebinger authored
      Starting with Win 8.1/Server 2012 windows no longer preallocates
      page tables for reserverd memory eagerly, which prevented us from
      using this approach in the past.
      
      We also try to allocate the heap high in the memory space.
      Hopefully this makes it easier to allocate things in the low
      4GB of memory that need to be there. Like jump islands for the
      linker.
      03a708ba
  2. 17 Jun, 2020 2 commits
    • Krzysztof Gogolewski's avatar
      Linear types (#15981) · 40fa237e
      Krzysztof Gogolewski authored
      This is the first step towards implementation of the linear types proposal
      (https://github.com/ghc-proposals/ghc-proposals/pull/111).
      
      It features
      
      * A language extension -XLinearTypes
      * Syntax for linear functions in the surface language
      * Linearity checking in Core Lint, enabled with -dlinear-core-lint
      * Core-to-core passes are mostly compatible with linearity
      * Fields in a data type can be linear or unrestricted; linear fields
        have multiplicity-polymorphic constructors.
        If -XLinearTypes is disabled, the GADT syntax defaults to linear fields
      
      The following items are not yet supported:
      
      * a # m -> b syntax (only prefix FUN is supported for now)
      * Full multiplicity inference (multiplicities are really only checked)
      * Decent linearity error messages
      * Linear let, where, and case expressions in the surface language
        (each of these currently introduce the unrestricted variant)
      * Multiplicity-parametric fields
      * Syntax for annotating lambda-bound or let-bound with a multiplicity
      * 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
    • Adam Sandberg Eriksson's avatar
      4cab6897
  3. 16 Jun, 2020 1 commit
  4. 14 Jun, 2020 1 commit
  5. 11 Jun, 2020 1 commit
  6. 09 Jun, 2020 1 commit
    • Ryan Scott's avatar
      Make GADT constructors adhere to the forall-or-nothing rule properly · 72c7fe9a
      Ryan Scott authored
      Issue #18191 revealed that the types of GADT constructors don't quite
      adhere to the `forall`-or-nothing rule. This patch serves to clean up
      this sad state of affairs somewhat. The main change is not in the
      code itself, but in the documentation, as this patch introduces two
      sections to the GHC User's Guide:
      
      * A "Formal syntax for GADTs" section that presents a BNF-style
        grammar for what is and isn't allowed in GADT constructor types.
        This mostly exists to codify GHC's existing behavior, but it also
        imposes a new restriction that addresses #18191: the outermost
        `forall` and/or context in a GADT constructor is not allowed to be
        surrounded by parentheses. Doing so would make these
        `forall`s/contexts nested, and GADTs do not support nested
        `forall`s/contexts at present.
      
      * A "`forall`-or-nothing rule" section that describes exactly what
        the `forall`-or-nothing rule is all about. Surprisingly, there was
        no mention of this anywhere in the User's Guide up until now!
      
      To adhere the new specification in the "Formal syntax for GADTs"
      section of the User's Guide, the following code changes were made:
      
      * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced.
        This is very much like `splitLHsSigmaTy`, except that it avoids
        splitting apart any parentheses, which can be syntactically
        significant for GADT types. See
        `Note [No nested foralls or contexts in GADT constructors]` in
        `GHC.Hs.Type`.
      
      * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was
        introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return
        it when given a prefix GADT constructor. Unlike `ConDeclGADT`,
        `ConDeclGADTPrefixPs` does not split the GADT type into its argument
        and result types, as this cannot be done until after the type is
        renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why
        this is the case).
      
      * `GHC.Renamer.Module.rnConDecl` now has an additional case for
        `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into
        its `forall`s, context, argument types, and result type, and
        (2) checks for nested `forall`s/contexts. Step (2) used to be
        performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather
        than the renamer, but now the relevant code from the typechecker
        can simply be deleted.
      
        One nice side effect of this change is that we are able to give a
        more accurate error message for GADT constructors that use visible
        dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`),
        which improves the stderr in the `T16326_Fail6` test case.
      
      Fixes #18191. Bumps the Haddock submodule.
      72c7fe9a
  7. 05 Jun, 2020 1 commit
    • 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
  8. 30 May, 2020 2 commits
  9. 23 May, 2020 2 commits
    • Andrew Martin's avatar
      Implement cstringLength# and FinalPtr · 49301ad6
      Andrew Martin authored
      This function and its accompanying rule resolve issue #5218.
      A future PR to the bytestring library will make the internal
      Data.ByteString.Internal.unsafePackAddress compute string length
      with cstringLength#. This will improve the status quo because it is
      eligible for constant folding.
      
      Additionally, introduce a new data constructor to ForeignPtrContents
      named FinalPtr. This additional data constructor, when used in the
      IsString instance for ByteString, leads to more Core-to-Core
      optimization opportunities, fewer runtime allocations, and smaller
      binaries.
      
      Also, this commit re-exports all the functions from GHC.CString
      (including cstringLength#) in GHC.Exts. It also adds a new test
      driver. This test driver is used to perform substring matches on Core
      that is dumped after all the simplifier passes. In this commit, it is
      used to check that constant folding of cstringLength# works.
      49301ad6
    • Adam Sandberg Eriksson's avatar
      docs: fix formatting and add some links · d830bbc9
      Adam Sandberg Eriksson authored
      [skip ci]
      d830bbc9
  10. 21 May, 2020 3 commits
    • Stefan Holdermans's avatar
      Update documentation for GHCi :script · cf566330
      Stefan Holdermans authored
      This patch adds the fixes that allow for file names containing spaces to
      be passed to GHCi's ':script' command to the release notes for 8.12 and
      expands the user-guide documentation for ':script' by mentioning how
      such file names can be passed.
      
      Related to #18027.
      cf566330
    • Andreas Klebinger's avatar
      Refactor linear reg alloc to remember past assignments. · 13f6c9d0
      Andreas Klebinger authored
      When assigning registers we now first try registers we
      assigned to in the past, instead of picking the "first"
      one.
      
      This is in extremely helpful when dealing with loops for
      which variables are dead for part of the loop.
      
      This is important for patterns like this:
      
              foo = arg1
          loop:
              use(foo)
              ...
              foo = getVal()
              goto loop;
      
      There we:
      * assign foo to the register of arg1.
      * use foo, it's dead after this use as it's overwritten after.
      * do other things.
      * look for a register to put foo in.
      
      If we pick an arbitrary one it might differ from the register the
      start of the loop expect's foo to be in.
      To fix this we simply look for past register assignments for
      the given variable. If we find one and the register is free we
      use that register.
      
      This reduces the need for fixup blocks which match the register
      assignment between blocks. In the example above between the end
      and the head of the loop.
      
      This patch also moves branch weight estimation ahead of register
      allocation and adds a flag to control it (cmm-static-pred).
      * It means the linear allocator is more likely to assign the hotter
        code paths first.
      * If it assign these first we are:
        + Less likely to spill on the hot path.
        + Less likely to introduce fixup blocks on the hot path.
      
      These two measure combined are surprisingly effective. Based on nofib
      we get in the mean:
      
      * -0.9% instructions executed
      * -0.1% reads/writes
      * -0.2% code size.
      * -0.1% compiler allocations.
      * -0.9% compile time.
      * -0.8% runtime.
      
      Most of the benefits are simply a result of removing redundant moves
      and spills.
      
      Reduced compiler allocations likely are the result of less code being
      generated. (The added lookup is mostly non-allocating).
      13f6c9d0
    • Gert-Jan Bottu's avatar
      Explicit Specificity · a9311cd5
      Gert-Jan Bottu authored
      Implementation for Ticket #16393.
      Explicit specificity allows users to manually create inferred type variables,
      by marking them with braces.
      This way, the user determines which variables can be instantiated through
      visible type application.
      
      The additional syntax is included in the parser, allowing users to write
      braces in type variable binders (type signatures, data constructors etc).
      This information is passed along through the renamer and verified in the
      type checker.
      The AST for type variable binders, data constructors, pattern synonyms,
      partial signatures and Template Haskell has been updated to include the
      specificity of type variables.
      
      Minor notes:
      - Bumps haddock submodule
      - Disables pattern match checking in GHC.Iface.Type with GHC 8.8
      a9311cd5
  11. 04 May, 2020 1 commit
  12. 30 Apr, 2020 1 commit
  13. 23 Apr, 2020 1 commit
    • Simon Peyton Jones's avatar
      Do eager instantation in terms · ffde2348
      Simon Peyton Jones authored
      This patch implements eager instantiation, a small but critical change
      to the type inference engine, #17173.  The main change is this:
      
        When inferring types, always return an instantiated type
        (for now, deeply instantiated; in future shallowly instantiated)
      
      There is more discussion in
      https://www.tweag.io/posts/2020-04-02-lazy-eager-instantiation.html
      
      There is quite a bit of refactoring in this patch:
      
      * The ir_inst field of GHC.Tc.Utils.TcType.InferResultk
        has entirely gone.  So tcInferInst and tcInferNoInst have collapsed
        into tcInfer.
      
      * Type inference of applications, via tcInferApp and
        tcInferAppHead, are substantially refactored, preparing
        the way for Quick Look impredicativity.
      
      * New pure function GHC.Tc.Gen.Expr.collectHsArgs and applyHsArgs
        are beatifully dual.  We can see the zipper!
      
      * GHC.Tc.Gen.Expr.tcArgs is now much nicer; no longer needs to return
        a wrapper
      
      * In HsExpr, HsTypeApp now contains the the actual type argument,
        and is used in desugaring, rather than putting it in a mysterious
        wrapper.
      
      * I struggled a bit with good error reporting in
        Unify.matchActualFunTysPart. It's a little bit simpler than before,
        but still not great.
      
      Some smaller things
      
      * Rename tcPolyExpr --> tcCheckExpr
               tcMonoExpr --> tcLExpr
      * tcPatSig moves from GHC.Tc.Gen.HsType to GHC.Tc.Gen.Pat
      
      Metric Decrease:
          T9961
      
      Reduction of 1.6% in comiler allocation on T9961, I think.
      ffde2348
  14. 12 Apr, 2020 1 commit
    • Ryan Scott's avatar
      Use conLikeUserTyVarBinders to quantify field selector types · 54ca66a7
      Ryan Scott authored
      This patch:
      
      1. Writes up a specification for how the types of top-level field
         selectors should be determined in a new section of the GHC User's
         Guide, and
      2. Makes GHC actually implement that specification by using
         `conLikeUserTyVarBinders` in `mkOneRecordSelector` to preserve the
         order and specificity of type variables written by the user.
      
      Fixes #18023.
      54ca66a7
  15. 18 Mar, 2020 1 commit
    • Richard Eisenberg's avatar
      Add release note about fix to #16502. · 4e8a71c1
      Richard Eisenberg authored
      We thought we needed to update the manual, but the fix for #16502
      actually brings the implementation in line with the manual. So we
      just alert users of how to update their code.
      4e8a71c1
  16. 21 Feb, 2020 1 commit
  17. 11 Feb, 2020 1 commit
  18. 25 Jan, 2020 1 commit
    • Ryan Scott's avatar
      Handle local fixity declarations in DsMeta properly · c3fde723
      Ryan Scott authored
      `DsMeta.rep_sig` used to skip over `FixSig` entirely, which had the
      effect of causing local fixity declarations to be dropped when quoted
      in Template Haskell. But there is no good reason for this state of
      affairs, as the code in `DsMeta.repFixD` (which handles top-level
      fixity declarations) handles local fixity declarations just fine.
      This patch factors out the necessary parts of `repFixD` so that they
      can be used in `rep_sig` as well.
      
      There was one minor complication: the fixity signatures for class
      methods in each `HsGroup` were stored both in `FixSig`s _and_ the
      list of `LFixitySig`s for top-level fixity signatures, so I needed
      to take action to prevent fixity signatures for class methods being
      converted to `Dec`s twice. I tweaked `RnSource.add` to avoid putting
      these fixity signatures in two places and added
      `Note [Top-level fixity signatures in an HsGroup]` in `GHC.Hs.Decls`
      to explain the new design.
      
      Fixes #17608. Bumps the Haddock submodule.
      c3fde723
  19. 13 Jan, 2020 2 commits
    • Richard Eisenberg's avatar
      Don't zap to Any; error instead · 350e2b78
      Richard Eisenberg authored
      This changes GHC's treatment of so-called Naughty Quantification
      Candidates to issue errors, instead of zapping to Any.
      
      Close #16775.
      
      No new test cases, because existing ones cover this well.
      350e2b78
    • Matthew Pickering's avatar
      Overloaded Quotation Brackets (#246) · 9129210f
      Matthew Pickering authored
      This patch implements overloaded quotation brackets which generalise the
      desugaring of all quotation forms in terms of a new minimal interface.
      
      The main change is that a quotation, for example, [e| 5 |], will now
      have type `Quote m => m Exp` rather than `Q Exp`. The `Quote` typeclass
      contains a single method for generating new names which is used when
      desugaring binding structures.
      
      The return type of functions from the `Lift` type class, `lift` and `liftTyped` have
      been restricted to `forall m . Quote m => m Exp` rather than returning a
      result in a Q monad.
      
      More details about the feature can be read in the GHC proposal.
      
      https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst
      9129210f
  20. 26 Dec, 2019 1 commit
  21. 04 Dec, 2019 2 commits