Skip to content
Snippets Groups Projects
  1. Jun 21, 2023
    • Bartłomiej Cieślar's avatar
      Add support for deprecating exported items (proposal #134) · 711b1d24
      Bartłomiej Cieślar authored and Ben Gamari's avatar Ben Gamari committed
      
      This is an implementation of the deprecated exports proposal #134.
      The proposal introduces an ability to introduce warnings to exports.
      This allows for deprecating a name only when it is exported from a specific
      module, rather than always depreacting its usage. In this example:
      
          module A ({-# DEPRECATED "do not use" #-} x) where
          x = undefined
          ---
          module B where
          import A(x)
      
      `x` will emit a warning when it is explicitly imported.
      
      Like the declaration warnings, export warnings are first accumulated within
      the `Warnings` struct, then passed into the ModIface, from which they are
      then looked up and warned about in the importing module in the `lookup_ie`
      helpers of the `filterImports` function (for the explicitly imported names)
      and in the `addUsedGRE(s)` functions where they warn about regular usages
      of the imported name.
      
      In terms of the AST information, the custom warning is stored in the
      extension field of the variants of the `IE` type (see Trees that Grow for
      more information).
      
      The commit includes a bump to the haddock submodule added in MR #28
      
      Signed-off-by: default avatarBartłomiej Cieślar <bcieslar2001@gmail.com>
      711b1d24
    • Sylvain Henry's avatar
      JS: implement TH support · 4d356ea3
      Sylvain Henry authored
      
      - Add ghc-interp.js bootstrap script for the JS interpreter
      - Interactively link and execute iserv code from the ghci package
      - Incrementally load and run JS code for splices into the running iserv
      
      Co-authored-by: default avatarLuite Stegeman <stegeman@gmail.com>
      4d356ea3
  2. May 25, 2023
  3. Jan 11, 2023
    • Vladislav Zavialov's avatar
      Introduce the TypeAbstractions language flag · bc125775
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      GHC Proposals #448 "Modern scoped type variables"
      and #425 "Invisible binders in type declarations"
      introduce a new language extension flag: TypeAbstractions.
      
      Part of the functionality guarded by this flag has already been
      implemented, namely type abstractions in constructor patterns, but it
      was guarded by a combination of TypeApplications and ScopedTypeVariables
      instead of a dedicated language extension flag.
      
      This patch does the following:
      
      * introduces a new language extension flag TypeAbstractions
      * requires TypeAbstractions for @a-syntax in constructor patterns
        instead of TypeApplications and ScopedTypeVariables
      * creates a User's Guide page for TypeAbstractions and
        moves the "Type Applications in Patterns" section there
      
      To avoid a breaking change, the new flag is implied by
      ScopedTypeVariables and is retroactively added to GHC2021.
      
      Metric Decrease:
          MultiLayerModulesTH_OneShot
      bc125775
  4. Nov 29, 2022
  5. Oct 26, 2022
  6. Oct 24, 2022
  7. Jul 25, 2022
    • Simon Peyton Jones's avatar
      Implement DeepSubsumption · dc27e15a
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      This MR adds the language extension -XDeepSubsumption, implementing
      GHC proposal #511.  This change mitigates the impact of GHC proposal
      
      The changes are highly localised, by design.  See Note [Deep subsumption]
      in GHC.Tc.Utils.Unify.
      
      The main changes are:
      
      * Add -XDeepSubsumption, which is on by default in Haskell98 and Haskell2010,
        but off in Haskell2021.
      
        -XDeepSubsumption largely restores the behaviour before the "simple subsumption" change.
        -XDeepSubsumpition has a similar flavour as -XNoMonoLocalBinds:
        it makes type inference more complicated and less predictable, but it
        may be convenient in practice.
      
      * The main changes are in:
        * GHC.Tc.Utils.Unify.tcSubType, which does deep susumption and eta-expanansion
        * GHC.Tc.Utils.Unify.tcSkolemiseET, which does deep skolemisation
        * In GHC.Tc.Gen.App.tcApp we call tcSubTypeNC to match the result
          type. Without deep subsumption, unifyExpectedType would be sufficent.
      
        See Note [Deep subsumption] in GHC.Tc.Utils.Unify.
      
      * There are no changes to Quick Look at all.
      
      * The type of `withDict` becomes ambiguous; so add -XAllowAmbiguousTypes to
        GHC.Magic.Dict
      
      * I fixed a small but egregious bug in GHC.Core.FVs.varTypeTyCoFVs, where
        we'd forgotten to take the free vars of the multiplicity of an Id.
      
      * I also had to fix tcSplitNestedSigmaTys
      
        When I did the shallow-subsumption patch
          commit 2b792fac
          Date:   Sun Feb 2 18:23:11 2020 +0000
          Simple subsumption
      
        I changed tcSplitNestedSigmaTys to not look through function arrows
        any more.  But that was actually an un-forced change.  This function
        is used only in
      
        * Improving error messages in GHC.Tc.Gen.Head.addFunResCtxt
        * Validity checking for default methods: GHC.Tc.TyCl.checkValidClass
        * A couple of calls in the GHCi debugger: GHC.Runtime.Heap.Inspect
      
        All to do with validity checking and error messages. Acutally its
        fine to look under function arrows here, and quite useful a test
        DeepSubsumption05 (a test motivated by a build failure in the
        `lens` package) shows.
      
        The fix is easy.  I added Note [tcSplitNestedSigmaTys].
      dc27e15a
  8. May 29, 2022
  9. Apr 07, 2022
    • Vladislav Zavialov's avatar
      Rename [] to List (#21294) · 02279a9c
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      This patch implements a small part of GHC Proposal #475.
      The key change is in GHC.Types:
      
      	- data [] a = [] | a : [a]
      	+ data List a = [] | a : List a
      
      And the rest of the patch makes sure that List is pretty-printed as []
      in various contexts.
      
      Updates the haddock submodule.
      02279a9c
  10. Mar 23, 2022
    • Zubin's avatar
      hi haddock: Lex and store haddock docs in interface files · b91798be
      Zubin authored and Marge Bot's avatar Marge Bot committed
      Names appearing in Haddock docstrings are lexed and renamed like any other names
      appearing in the AST. We currently rename names irrespective of the namespace,
      so both type and constructor names corresponding to an identifier will appear in
      the docstring. Haddock will select a given name as the link destination based on
      its own heuristics.
      
      This patch also restricts the limitation of `-haddock` being incompatible with
      `Opt_KeepRawTokenStream`.
      
      The export and documenation structure is now computed in GHC and serialised in
      .hi files. This can be used by haddock to directly generate doc pages without
      reparsing or renaming the source. At the moment the operation of haddock
      is not modified, that's left to a future patch.
      
      Updates the haddock submodule with the minimum changes needed.
      b91798be
  11. Mar 10, 2021
    • Luke Lau's avatar
      template-haskell: Add putDoc, getDoc, withDecDoc and friends · 8a59f49a
      Luke Lau authored and Ben Gamari's avatar Ben Gamari committed
      This adds two new methods to the Quasi class, putDoc and getDoc. They
      allow Haddock documentation to be added to declarations, module headers,
      function arguments and class/type family instances, as well as looked
      up.
      
      It works by building up a map of names to attach pieces of
      documentation to, which are then added in the extractDocs function in
      GHC.HsToCore.Docs. However because these template haskell names need to
      be resolved to GHC names at the time they are added, putDoc cannot
      directly add documentation to declarations that are currently being
      spliced. To remedy this, withDecDoc/withDecsDoc wraps the operation with
      addModFinalizer, and provides a more ergonomic interface for doing so.
      Similarly, the funD_doc, dataD_doc etc. combinators provide a more
      ergonomic interface for documenting functions and their arguments
      simultaneously.
      
      This also changes ArgDocMap to use an IntMap rather than an Map Int, for
      efficiency.
      
      Part of the work towards #5467
      8a59f49a
  12. Jun 04, 2020
    • Luke Lau's avatar
      Fix documentation on type families not being extracted · 2bd3929a
      Luke Lau authored and Marge Bot's avatar Marge Bot committed
      It looks like the location of the Names used for CoAxioms on type
      families are now located at their type constructors. Previously, Docs.hs
      thought the Names were located in the RHS, so the RealSrcSpan in the
      instanceMap and getInstLoc didn't match up. Fixes #18241
      2bd3929a
  13. Apr 12, 2020
  14. Mar 12, 2020
    • Simon Peyton Jones's avatar
      Expose compulsory unfoldings always · 3a259092
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      The unsafeCoerce# patch requires that unsafeCoerce# has
      a compulsory unfolding that is always available.  So we have
      to be careful to expose compulsory unfoldings unconditionally
      and consistently.
      
      We didn't get this quite right: #17871.  This patch fixes
      it.  No real surprises here.
      
      See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy
      3a259092
  15. Jan 08, 2020
    • Ryan Scott's avatar
      Print Core type applications with no whitespace after @ (#17643) · 923a1272
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This brings the pretty-printer for Core in line with how visible
      type applications are normally printed: namely, with no whitespace
      after the `@` character (i.e., `f @a` instead of `f @ a`). While I'm
      in town, I also give the same treatment to type abstractions (i.e.,
      `\(@a)` instead of `\(@ a)`) and coercion applications (i.e.,
      `f @~x` instead of `f @~ x`).
      
      Fixes #17643.
      923a1272
  16. Jan 30, 2019
  17. Nov 29, 2018
    • Simon Peyton Jones's avatar
      Taming the Kind Inference Monster · 2257a86d
      Simon Peyton Jones authored
      My original goal was (Trac #15809) to move towards using level numbers
      as the basis for deciding which type variables to generalise, rather
      than searching for the free varaibles of the environment.  However
      it has turned into a truly major refactoring of the kind inference
      engine.
      
      Let's deal with the level-numbers part first:
      
      * Augment quantifyTyVars to calculate the type variables to
        quantify using level numbers, and compare the result with
        the existing approach.  That is; no change in behaviour,
        just a WARNing if the two approaches give different answers.
      
      * To do this I had to get the level number right when calling
        quantifyTyVars, and this entailed a bit of care, especially
        in the code for kind-checking type declarations.
      
      * However, on the way I was able to eliminate or simplify
        a number of calls to solveEqualities.
      
      This work is incomplete: I'm not /using/ level numbers yet.
      When I subsequently get rid of any remaining WARNings in
      quantifyTyVars, that the level-number answers differ from
      the current answers, then I can rip out the current
      "free vars of the environment" stuff.
      
      Anyway, this led me into deep dive into kind inference for type and
      class declarations, which is an increasingly soggy part of GHC.
      Richard already did some good work recently in
      
         commit 5e45ad10
         Date:   Thu Sep 13 09:56:02 2018 +0200
      
          Finish fix for #14880.
      
          The real change that fixes the ticket is described in
          Note [Naughty quantification candidates] in TcMType.
      
      but I kept turning over stones. So this patch has ended up
      with a pretty significant refactoring of that code too.
      
      Kind inference for types and classes
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      * Major refactoring in the way we generalise the inferred kind of
        a TyCon, in kcTyClGroup.  Indeed, I made it into a new top-level
        function, generaliseTcTyCon.  Plus a new Note to explain it
        Note [Inferring kinds for type declarations].
      
      * We decided (Trac #15592) not to treat class type variables specially
        when dealing with Inferred/Specified/Required for associated types.
        That simplifies things quite a bit. I also rewrote
        Note [Required, Specified, and Inferred for types]
      
      * Major refactoring of the crucial function kcLHsQTyVars:
        I split it into
             kcLHsQTyVars_Cusk  and  kcLHsQTyVars_NonCusk
        because the two are really quite different. The CUSK case is
        almost entirely rewritten, and is much easier because of our new
        decision not to treat the class variables specially
      
      * I moved all the error checks from tcTyClTyVars (which was a bizarre
        place for it) into generaliseTcTyCon and/or the CUSK case of
        kcLHsQTyVars.  Now tcTyClTyVars is extremely simple.
      
      * I got rid of all the all the subtleties in tcImplicitTKBndrs. Indeed
        now there is no difference between tcImplicitTKBndrs and
        kcImplicitTKBndrs; there is now a single bindImplicitTKBndrs.
        Same for kc/tcExplicitTKBndrs.  None of them monkey with level
        numbers, nor build implication constraints.  scopeTyVars is gone
        entirely, as is kcLHsQTyVarBndrs. It's vastly simpler.
      
        I found I could get rid of kcLHsQTyVarBndrs entirely, in favour of
        the bnew bindExplicitTKBndrs.
      
      Quantification
      ~~~~~~~~~~~~~~
      * I now deal with the "naughty quantification candidates"
        of the previous patch in candidateQTyVars, rather than in
        quantifyTyVars; see Note [Naughty quantification candidates]
        in TcMType.
      
        I also killed off closeOverKindsCQTvs in favour of the same
        strategy that we use for tyCoVarsOfType: namely, close over kinds
        at the occurrences.
      
        And candidateQTyVars no longer needs a gbl_tvs argument.
      
      * Passing the ContextKind, rather than the expected kind itself,
        to tc_hs_sig_type_and_gen makes it easy to allocate the expected
        result kind (when we are in inference mode) at the right level.
      
      Type families
      ~~~~~~~~~~~~~~
      * I did a major rewrite of the impenetrable tcFamTyPats. The result
        is vastly more comprehensible.
      
      * I got rid of kcDataDefn entirely, quite a big function.
      
      * I re-did the way that checkConsistentFamInst works, so
        that it allows alpha-renaming of invisible arguments.
      
      * The interaction of kind signatures and family instances is tricky.
          Type families: see Note [Apparently-nullary families]
          Data families: see Note [Result kind signature for a data family instance]
                         and Note [Eta-reduction for data families]
      
      * The consistent instantation of an associated type family is tricky.
        See Note [Checking consistent instantiation] and
            Note [Matching in the consistent-instantation check]
        in TcTyClsDecls.  It's now checked in TcTyClsDecls because that is
        when we have the relevant info to hand.
      
      * I got tired of the compromises in etaExpandFamInst, so I did the
        job properly by adding a field cab_eta_tvs to CoAxBranch.
        See Coercion.etaExpandCoAxBranch.
      
      tcInferApps and friends
      ~~~~~~~~~~~~~~~~~~~~~~~
      * I got rid of the mysterious and horrible ClsInstInfo argument
        to tcInferApps, checkExpectedKindX, and various checkValid
        functions.  It was horrible!
      
      * I got rid of [Type] result of tcInferApps.  This list was used
        only in tcFamTyPats, when checking the LHS of a type instance;
        and if there is a cast in the middle, the list is meaningless.
        So I made tcInferApps simpler, and moved the complexity
        (not much) to tcInferApps.
      
        Result: tcInferApps is now pretty comprehensible again.
      
      * I refactored the many function in TcMType that instantiate skolems.
      
      Smaller things
      
      * I rejigged the error message in checkValidTelescope; I think it's
        quite a bit better now.
      
      * checkValidType was not rejecting constraints in a kind signature
           forall (a :: Eq b => blah). blah2
        That led to further errors when we then do an ambiguity check.
        So I make checkValidType reject it more aggressively.
      
      * I killed off quantifyConDecl, instead calling kindGeneralize
        directly.
      
      * I fixed an outright bug in tyCoVarsOfImplic, where we were not
        colleting the tyvar of the kind of the skolems
      
      * Renamed ClsInstInfo to AssocInstInfo, and made it into its
        own data type
      
      * Some fiddling around with pretty-printing of family
        instances which was trickier than I thought.  I wanted
        wildcards to print as plain "_" in user messages, although
        they each need a unique identity in the CoAxBranch.
      
      Some other oddments
      
      * Refactoring around the trace messages from reportUnsolved.
      * A bit of extra tc-tracing in TcHsSyn.commitFlexi
      
      This patch fixes a raft of bugs, and includes tests for them.
      
       * #14887
       * #15740
       * #15764
       * #15789
       * #15804
       * #15817
       * #15870
       * #15874
       * #15881
      2257a86d
  18. Aug 12, 2018
  19. Jun 14, 2018
    • Simon Jakobi's avatar
      Fix deserialization of docs (#15240) · 69b50efe
      Simon Jakobi authored and Ben Gamari's avatar Ben Gamari committed
      We were using Map.fromDistinctAscList to deserialize a
      (Map Name HsDocString). As the Names' Uniques had changed, we
      ended up with an invalid map in which we couldn't lookup certain keys.
      
      Switching to Map.fromList fixed the issue.
      
      Added comments in several places.
      
      Reviewers: alexbiehl, hvr, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie, carter
      
      GHC Trac Issues: #15240
      
      Differential Revision: https://phabricator.haskell.org/D4816
      69b50efe
  20. Jun 04, 2018
    • Simon Jakobi's avatar
      Serialize docstrings to ifaces, display them with new GHCi :doc command · 85309a3c
      Simon Jakobi authored and Ben Gamari's avatar Ben Gamari committed
      If `-haddock` is set, we now extract docstrings from the renamed ast
      and serialize them in the .hi-files.
      
      This includes some of the changes from D4749 with the notable
      exceptions of the docstring lexing and renaming.
      
      A currently limited and experimental GHCi :doc command can be used
      to display docstrings for declarations.
      
      The formatting of pretty-printed docstrings is changed slightly,
      causing some changes in testsuite/tests/haddock.
      
      Test Plan: ./validate
      
      Reviewers: alexbiehl, hvr, gershomb, harpocrates, bgamari
      
      Reviewed By: alexbiehl
      
      Subscribers: rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4758
      85309a3c
  21. Feb 12, 2017
Loading