Skip to content
Snippets Groups Projects
  1. Jul 14, 2019
    • John Ericson's avatar
      Expunge #ifdef and #ifndef from the codebase · d7c6c471
      John Ericson authored and Marge Bot's avatar Marge Bot committed
      These are unexploded minds as far as the linter is concerned. I don't
      want to hit in my MRs by mistake!
      
      I did this with `sed`, and then rolled back some changes in the docs,
      config.guess, and the linter itself.
      d7c6c471
  2. Jun 27, 2019
  3. Jun 26, 2019
  4. Jun 23, 2019
    • Ryan Scott's avatar
      Refactor UnliftedNewtypes-relation kind signature validity checks · 9bbcc3be
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This fixes three infelicities related to the programs that are
      (and aren't) accepted with `UnliftedNewtypes`:
      
      * Enabling `UnliftedNewtypes` would permit newtypes to have return
        kind `Id Type`, which had disastrous results (i.e., GHC panics).
      * Data family declarations ending in kind `TYPE r` (for some `r`)
        weren't being accepted if `UnliftedNewtypes` wasn't enabled,
        despite the GHC proposal specifying otherwise.
      * GHC wasn't warning about programs that _would_ typecheck if
        `UnliftedNewtypes` were enabled in certain common cases.
      
      As part of fixing these issues, I factored out the logic for checking
      all of the various properties about data type/data family return
      kinds into a single `checkDataKindSig` function. I also cleaned up
      some of the formatting in the existing error message that gets
      thrown.
      
      Fixes #16821, fixes #16827, and fixes #16829.
      9bbcc3be
  5. Jun 21, 2019
    • Matthías Páll Gissurarson's avatar
      Add HoleFitPlugins and RawHoleFits · c311277b
      Matthías Páll Gissurarson authored
      This patch adds a new kind of plugin, Hole fit plugins. These plugins
      can change what candidates are considered when looking for valid hole
      fits, and add hole fits of their own. The type of a plugin is relatively
      simple,
      
      ```
      type FitPlugin = TypedHole -> [HoleFit] -> TcM [HoleFit]
      type CandPlugin = TypedHole -> [HoleFitCandidate] -> TcM [HoleFitCandidate]
      data HoleFitPlugin = HoleFitPlugin { candPlugin :: CandPlugin
                                         , fitPlugin :: FitPlugin }
      
      data TypedHole = TyH { tyHRelevantCts :: Cts
                             -- ^ Any relevant Cts to the hole
                           , tyHImplics :: [Implication]
                             -- ^ The nested implications of the hole with the
                             --   innermost implication first.
                           , tyHCt :: Maybe Ct
                             -- ^ The hole constraint itself, if available.
                           }
      
      This allows users and plugin writers to interact with the candidates and
      fits as they wish, even going as far as to allow them to reimplement the
      current functionality (since `TypedHole` contains all the relevant
      information).
      
      As an example, consider the following plugin:
      
      ```
      module HolePlugin where
      
      import GhcPlugins
      
      import TcHoleErrors
      
      import Data.List (intersect, stripPrefix)
      import RdrName (importSpecModule)
      
      import TcRnTypes
      
      import System.Process
      
      plugin :: Plugin
      plugin = defaultPlugin { holeFitPlugin = hfp, pluginRecompile = purePlugin }
      
      hfp :: [CommandLineOption] -> Maybe HoleFitPluginR
      hfp opts = Just (fromPureHFPlugin $ HoleFitPlugin (candP opts) (fp opts))
      
      toFilter :: Maybe String -> Maybe String
      toFilter = flip (>>=) (stripPrefix "_module_")
      
      replace :: Eq a => a -> a -> [a] -> [a]
      replace match repl str = replace' [] str
        where
          replace' sofar (x:xs) | x == match = replace' (repl:sofar) xs
          replace' sofar (x:xs) = replace' (x:sofar) xs
          replace' sofar [] = reverse sofar
      
      -- | This candidate plugin filters the candidates by module,
      --   using the name of the hole as module to search in
      candP :: [CommandLineOption] -> CandPlugin
      candP _ hole cands =
        do let he = case tyHCt hole of
                      Just (CHoleCan _ h) -> Just (occNameString $ holeOcc h)
                      _ -> Nothing
           case toFilter he of
              Just undscModName -> do let replaced = replace '_' '.' undscModName
                                      let res = filter (greNotInOpts [replaced]) cands
                                      return $ res
              _ -> return cands
        where greNotInOpts opts (GreHFCand gre)  = not $ null $ intersect (inScopeVia gre) opts
              greNotInOpts _ _ = True
              inScopeVia = map (moduleNameString . importSpecModule) . gre_imp
      
      -- Yes, it's pretty hacky, but it is just an example :)
      searchHoogle :: String -> IO [String]
      searchHoogle ty = lines <$> (readProcess "hoogle" [(show ty)] [])
      
      fp :: [CommandLineOption] -> FitPlugin
      fp ("hoogle":[]) hole hfs =
          do dflags <- getDynFlags
             let tyString = showSDoc dflags . ppr . ctPred <$> tyHCt hole
             res <- case tyString of
                      Just ty -> liftIO $ searchHoogle ty
                      _ -> return []
             return $ (take 2 $ map (RawHoleFit . text . ("Hoogle says: " ++)) res) ++ hfs
      fp _ _ hfs = return hfs
      
      ```
      
      with this plugin available, you can compile the following file
      
      ```
      {-# OPTIONS -fplugin=HolePlugin -fplugin-opt=HolePlugin:hoogle #-}
      module Main where
      
      import Prelude hiding (head, last)
      
      import Data.List (head, last)
      
      t :: [Int] -> Int
      t = _module_Prelude
      
      g :: [Int] -> Int
      g = _module_Data_List
      
      main :: IO ()
      main = print $ t [1,2,3]
      ```
      
      and get the following output:
      
      ```
      Main.hs:14:5: error:
          • Found hole: _module_Prelude :: [Int] -> Int
            Or perhaps ‘_module_Prelude’ is mis-spelled, or not in scope
          • In the expression: _module_Prelude
            In an equation for ‘t’: t = _module_Prelude
          • Relevant bindings include
              t :: [Int] -> Int (bound at Main.hs:14:1)
            Valid hole fits include
              Hoogle says: GHC.List length :: [a] -> Int
              Hoogle says: GHC.OldList length :: [a] -> Int
              t :: [Int] -> Int (bound at Main.hs:14:1)
              g :: [Int] -> Int (bound at Main.hs:17:1)
              length :: forall (t :: * -> *) a. Foldable t => t a -> Int
                with length @[] @Int
                (imported from ‘Prelude’ at Main.hs:5:1-34
                 (and originally defined in ‘Data.Foldable’))
              maximum :: forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
                with maximum @[] @Int
                (imported from ‘Prelude’ at Main.hs:5:1-34
                 (and originally defined in ‘Data.Foldable’))
              (Some hole fits suppressed; use -fmax-valid-hole-fits=N or -fno-max-valid-hole-fits)
         |
      14 | t = _module_Prelude
         |     ^^^^^^^^^^^^^^^
      
      Main.hs:17:5: error:
          • Found hole: _module_Data_List :: [Int] -> Int
            Or perhaps ‘_module_Data_List’ is mis-spelled, or not in scope
          • In the expression: _module_Data_List
            In an equation for ‘g’: g = _module_Data_List
          • Relevant bindings include
              g :: [Int] -> Int (bound at Main.hs:17:1)
            Valid hole fits include
              Hoogle says: GHC.List length :: [a] -> Int
              Hoogle says: GHC.OldList length :: [a] -> Int
              g :: [Int] -> Int (bound at Main.hs:17:1)
              head :: forall a. [a] -> a
                with head @Int
                (imported from ‘Data.List’ at Main.hs:7:19-22
                 (and originally defined in ‘GHC.List’))
              last :: forall a. [a] -> a
                with last @Int
                (imported from ‘Data.List’ at Main.hs:7:25-28
                 (and originally defined in ‘GHC.List’))
         |
      17 | g = _module_Data_List
      
      ```
      
      This relatively simple plugin has two functions, as an example of what
      is possible to do with hole fit plugins. The candidate plugin starts by
      filtering the candidates considered by module, indicated by the name of
      the hole (`_module_Data_List`). The second function is in the fit
      plugin, where the plugin invokes a local hoogle instance to search by
      the type of the hole.
      
      By adding the `RawHoleFit` type, we can also allow these completely free
      suggestions, used in the plugin above to display fits found by Hoogle.
      
      Additionally, the `HoleFitPluginR` wrapper can be used for plugins to
      maintain state between invocations, which can be used to speed up
      invocation of plugins that have expensive initialization.
      
      ```
      -- | HoleFitPluginR adds a TcRef to hole fit plugins so that plugins can
      -- track internal state. Note the existential quantification, ensuring that
      -- the state cannot be modified from outside the plugin.
      data HoleFitPluginR = forall s. HoleFitPluginR
        { hfPluginInit :: TcM (TcRef s)
          -- ^ Initializes the TcRef to be passed to the plugin
        , hfPluginRun :: TcRef s -> HoleFitPlugin
          -- ^ The function defining the plugin itself
        , hfPluginStop :: TcRef s -> TcM ()
          -- ^ Cleanup of state, guaranteed to be called even on error
        }
      ```
      
      Of course, the syntax here is up for debate, but hole fit plugins allow
      us to experiment relatively easily with ways to interact with
      typed-holes without having to dig deep into GHC.
      
      Reviewers: bgamari
      
      Subscribers: rwbarton, carter
      
      Differential Revision: https://phabricator.haskell.org/D5373
      c311277b
  6. Jun 20, 2019
  7. Jun 14, 2019
    • Andrew Martin's avatar
      Implement the -XUnliftedNewtypes extension. · effdd948
      Andrew Martin authored and Marge Bot's avatar Marge Bot committed
      GHC Proposal: 0013-unlifted-newtypes.rst
      Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/98
      
      
      Issues: #15219, #1311, #13595, #15883
      Implementation Details:
        Note [Implementation of UnliftedNewtypes]
        Note [Unifying data family kinds]
        Note [Compulsory newtype unfolding]
      
      This patch introduces the -XUnliftedNewtypes extension. When this
      extension is enabled, GHC drops the restriction that the field in
      a newtype must be of kind (TYPE 'LiftedRep). This allows types
      like Int# and ByteArray# to be used in a newtype. Additionally,
      coerce is made levity-polymorphic so that it can be used with
      newtypes over unlifted types.
      
      The bulk of the changes are in TcTyClsDecls.hs. With -XUnliftedNewtypes,
      getInitialKind is more liberal, introducing a unification variable to
      return the kind (TYPE r0) rather than just returning (TYPE 'LiftedRep).
      When kind-checking a data constructor with kcConDecl, we attempt to
      unify the kind of a newtype with the kind of its field's type. When
      typechecking a data declaration with tcTyClDecl, we again perform a
      unification. See the implementation note for more on this.
      
      Co-authored-by: Richard Eisenberg's avatarRichard Eisenberg <rae@richarde.dev>
      effdd948
  8. Jun 13, 2019
    • Ben Gamari's avatar
      users-guide: Fix a few markup issues · 70b5eefe
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Strangely these were only causing the build to fail in the aarch64-linux
      job, despite Sphinx throwing errors in all jobs I checked.
      
      Also changes some `#ifdef`s to `#if defined` to satisfy the linter.
      70b5eefe
  9. Jun 11, 2019
  10. Jun 09, 2019
    • Roland Senn's avatar
      Add disable/enable commands to ghci debugger #2215 · 10452959
      Roland Senn authored and Marge Bot's avatar Marge Bot committed
      This patch adds two new commands `:enable` and `:disable` to the GHCi debugger.
      Opposite to `:set stop <n> :continue` a breakpoint disabled with `:disable` will
      not loose its previously set stop command.
      A new field breakEnabled is added to the BreakLocation data structure to
      track the enable/disable state. When a breakpoint is disabled with a `:disable`
      command, the following happens:
      
      The corresponding BreakLocation data element is searched dictionary of the
      `breaks` field of the GHCiStateMonad. If the break point is found and not
      already in the disabled state, the breakpoint is removed from bytecode.
      The BreakLocation data structure is kept in the breaks list and the new
      breakEnabled field is set to false.
      
      The `:enable` command works similar.
      
      The breaks field in the GHCiStateMonad was changed from an association list
      to int `IntMap`.
      10452959
  11. Jun 07, 2019
  12. Jun 04, 2019
    • xldenis's avatar
      Add GHCi :instances command · 002594b7
      xldenis authored and Marge Bot's avatar Marge Bot committed
      This commit adds the `:instances` command to ghci following proosal
      number 41.
      
      This makes it possible to query which instances are available to a given
      type.
      
      The output of this command is all the possible instances with type
      variables and constraints instantiated.
      002594b7
  13. Jun 01, 2019
    • Ryan Scott's avatar
      Reject nested foralls in foreign imports (#16702) · 45f88494
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      This replaces a panic observed in #16702 with a simple error message
      stating that nested `forall`s simply aren't allowed in the type
      signature of a `foreign import` (at least, not at present).
      
      Fixes #16702.
      45f88494
  14. May 31, 2019
  15. May 29, 2019
  16. May 27, 2019
  17. May 22, 2019
    • Ryan Scott's avatar
      Use HsTyPats in associated type family defaults · 6efe04de
      Ryan Scott authored and Marge Bot's avatar Marge Bot committed
      Associated type family default declarations behave strangely in a
      couple of ways:
      
      1. If one tries to bind the type variables with an explicit `forall`,
         the `forall`'d part will simply be ignored. (#16110)
      2. One cannot use visible kind application syntax on the left-hand
         sides of associated default equations, unlike every other form
         of type family equation. (#16356)
      
      Both of these issues have a common solution. Instead of using
      `LHsQTyVars` to represent the left-hand side arguments of an
      associated default equation, we instead use `HsTyPats`, which is what
      other forms of type family equations use. In particular, here are
      some highlights of this patch:
      
      * `FamEqn` is no longer parameterized by a `pats` type variable, as
        the `feqn_pats` field is now always `HsTyPats`.
      * The new design for `FamEqn` in chronicled in
        `Note [Type family instance declarations in HsSyn]`.
      * `TyFamDefltEqn` now becomes the same thing as `TyFamInstEqn`. This
        means that many of `TyFamDefltEqn`'s code paths can now reuse the
        code paths for `TyFamInstEqn`, resulting in substantial
        simplifications to various parts of the code dealing with
        associated type family defaults.
      
      Fixes #16110 and #16356.
      6efe04de
    • Michael Sloan's avatar
      Have GHCi use object code for UnboxedTuples modules #15454 · 21272670
      Michael Sloan authored and Marge Bot's avatar Marge Bot committed
      The idea is to automatically enable -fobject-code for modules that use
      UnboxedTuples, along with all the modules they depend on. When looking
      into how to solve this, I was pleased to find that there was already
      highly similar logic for enabling code generation when -fno-code is
      specified but TemplateHaskell is used.
      
      The state before this patch was that if you used unboxed tuples then you
      had to enable `-fobject-code` globally rather than on a per module
      basis.
      21272670
    • Julian Leviston's avatar
      0dc79856
  18. May 21, 2019
  19. May 14, 2019
    • Vladislav Zavialov's avatar
      Guard CUSKs behind a language pragma · a5fdd185
      Vladislav Zavialov authored and Ben Gamari's avatar Ben Gamari committed
      GHC Proposal #36 describes a transition plan away from CUSKs and to
      top-level kind signatures:
      
      1. Introduce a new extension, -XCUSKs, on by default, that detects CUSKs
         as they currently exist.
      2. We turn off the -XCUSKs extension in a few releases and remove it
         sometime thereafter.
      
      This patch implements phase 1 of this plan, introducing a new language
      extension to control whether CUSKs are enabled. When top-level kind
      signatures are implemented, we can transition to phase 2.
      a5fdd185
  20. May 10, 2019
  21. May 08, 2019
  22. May 05, 2019
  23. May 04, 2019
  24. May 03, 2019
    • Ryan Scott's avatar
      Make equality constraints in kinds invisible · cc495d57
      Ryan Scott authored and Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan committed
      Issues #12102 and #15872 revealed something strange about the way GHC
      handles equality constraints in kinds: it treats them as _visible_
      arguments! This causes a litany of strange effects, from strange
      error messages
      (ghc/ghc#12102 (comment 169035))
      to bizarre `Eq#`-related things leaking through to GHCi output, even
      without any special flags enabled.
      
      This patch is an attempt to contain some of this strangeness.
      In particular:
      
      * In `TcHsType.etaExpandAlgTyCon`, we propagate through the
        `AnonArgFlag`s of any `Anon` binders. Previously, we were always
        hard-coding them to `VisArg`, which meant that invisible binders
        (like those whose kinds were equality constraint) would mistakenly
        get flagged as visible.
      * In `ToIface.toIfaceAppArgsX`, we previously assumed that the
        argument to a `FunTy` always corresponding to a `Required`
        argument. We now dispatch on the `FunTy`'s `AnonArgFlag` and map
        `VisArg` to `Required` and `InvisArg` to `Inferred`. As a
        consequence, the iface pretty-printer correctly recognizes that
        equality coercions are inferred arguments, and as a result,
        only displays them in `-fprint-explicit-kinds` is enabled.
      * Speaking of iface pretty-printing, `Anon InvisArg` binders were
        previously being pretty-printed like `T (a :: b ~ c)`, as if they
        were required. This seemed inconsistent with other invisible
        arguments (that are printed like `T @{d}`), so I decided to switch
        this to `T @{a :: b ~ c}`.
      
      Along the way, I also cleaned up a minor inaccuracy in the users'
      guide section for constraints in kinds that was spotted in
      ghc/ghc#12102 (comment 136220).
      
      Fixes #12102 and #15872.
      cc495d57
  25. Apr 21, 2019
  26. Apr 19, 2019
    • Alec Theriault's avatar
      TH: make `Lift` and `TExp` levity-polymorphic · 57cf1133
      Alec Theriault authored and Marge Bot's avatar Marge Bot committed
      Besides the obvious benefits of being able to manipulate `TExp`'s of
      unboxed types, this also simplified `-XDeriveLift` all while making
      it more capable.
      
        * `ghc-prim` is explicitly depended upon by `template-haskell`
      
        * The following TH things are parametrized over `RuntimeRep`:
      
            - `TExp(..)`
            - `unTypeQ`
            - `unsafeTExpCoerce`
            - `Lift(..)`
      
        * The following instances have been added to `Lift`:
      
            - `Int#`, `Word#`, `Float#`, `Double#`, `Char#`, `Addr#`
            - unboxed tuples of lifted types up to arity 7
            - unboxed sums of lifted types up to arity 7
      
          Ideally we would have levity-polymorphic _instances_ of unboxed
          tuples and sums.
      
        * The code generated by `-XDeriveLift` uses expression quotes
          instead of generating large amounts of TH code and having
          special hard-coded cases for some unboxed types.
      57cf1133
  27. Apr 15, 2019
Loading