1. 29 Aug, 2013 1 commit
  2. 05 Aug, 2013 1 commit
  3. 02 Aug, 2013 1 commit
  4. 24 Jun, 2013 1 commit
  5. 21 Jun, 2013 1 commit
    • eir@cis.upenn.edu's avatar
      Revise implementation of overlapping type family instances. · 569b2652
      eir@cis.upenn.edu authored
      This commit changes the syntax and story around overlapping type
      family instances. Before, we had "unbranched" instances and
      "branched" instances. Now, we have closed type families and
      open ones.
      The behavior of open families is completely unchanged. In particular,
      coincident overlap of open type family instances still works, despite
      emails to the contrary.
      A closed type family is declared like this:
      > type family F a where
      >   F Int = Bool
      >   F a   = Char
      The equations are tried in order, from top to bottom, subject to
      certain constraints, as described in the user manual. It is not
      allowed to declare an instance of a closed family.
  6. 30 May, 2013 2 commits
    • Simon Peyton Jones's avatar
      Fix a trailing case in making FamInstTyCon, · d0ecba6d
      Simon Peyton Jones authored
      where the invariant didn't hold, leading to
      subsequent chaos. Happily an ASSERT caught it.
    • Simon Peyton Jones's avatar
      Make 'SPECIALISE instance' work again · 1ed04090
      Simon Peyton Jones authored
      This is a long-standing regression (Trac #7797), which meant that in
      particular the Eq [Char] instance does not get specialised.
      (The *methods* do, but the dictionary itself doesn't.)  So when you
      call a function
           f :: Eq a => blah
      on a string type (ie a=[Char]), 7.6 passes a dictionary of un-specialised
      This only matters when calling an overloaded function from a
      specialised context, but that does matter in some programs.  I
      remember (though I cannot find the details) that Nick Frisby discovered
      this to be the source of some pretty solid performanc regresisons.
      Anyway it works now. The key change is that a DFunUnfolding now takes
      a form that is both simpler than before (the DFunArg type is eliminated)
      and more general:
      data Unfolding
        = ...
        | DFunUnfolding {     -- The Unfolding of a DFunId
          			-- See Note [DFun unfoldings]
            		  	--     df = /\a1..am. \d1..dn. MkD t1 .. tk
                              --                                 (op1 a1..am d1..dn)
           		      	--     	    	      	       	   (op2 a1..am d1..dn)
              df_bndrs :: [Var],      -- The bound variables [a1..m],[d1..dn]
              df_con   :: DataCon,    -- The dictionary data constructor (never a newtype datacon)
              df_args  :: [CoreExpr]  -- Args of the data con: types, superclasses and methods,
          }                           -- in positional order
      That in turn allowed me to re-enable the DFunUnfolding specialisation in
      DsBinds.  Lots of details here in TcInstDcls:
      	  Note [SPECIALISE instance pragmas]
      I also did some refactoring, in particular to pass the InScopeSet to
      exprIsConApp_maybe (which in turn means it has to go to a RuleFun).
      NB: Interface file format has changed!
  7. 25 Apr, 2013 1 commit
  8. 15 Feb, 2013 1 commit
  9. 13 Feb, 2013 1 commit
  10. 28 Jan, 2013 1 commit
    • Simon Peyton Jones's avatar
      More refactoring of FamInst/FamInstEnv; finally fixes Trac #7524 · a98e51ec
      Simon Peyton Jones authored
      Quite a bit of tidying up here; the fix to #7524 is actually
      only a small part.
      * Be fully clear that the cab_tvs in a CoAxBranch are not
        fresh.  See Note [CoAxBranch type variables] in CoAxiom.
      * Use CoAxBranch to replace the ATDfeault type in Class.
        CoAxBranch is perfect here.  This change allowed me to
        delete quite a bit of boilerplate code, including the
        corresponding IfaceSynType.
      * Tidy up the construction of CoAxBranches, and when FamIntBranch is
        freshened.  The latter onw happens only in FamInst.newFamInst.
      * Tidy the tyvars of a CoAxBranch when we build them, done in
        FamInst.mkCoAxBranch.  See Note [Tidy axioms when we build them]
        in that module.  This is what fixes #7524.
      Much niceer now.
  11. 25 Jan, 2013 1 commit
    • Simon Peyton Jones's avatar
      Refactor and improve the promotion inference · 09ff0e0d
      Simon Peyton Jones authored
      It should be the case that either an entire mutually recursive
      group of data type declarations can be promoted, or none of them.
      It's really odd to promote some data constructors of a type but
      not others. Eg
        data T a = T1 a | T2 Int
      Here T1 is sort-of-promotable but T2 isn't (becuase Int isn't
      This patch makes it all-or-nothing. At the same time I've made
      the TyCon point to its promoted cousin (via the tcPromoted field
      of an AlgTyCon), as well as vice versa (via the ty_con field of
      The inference for the group is done in TcTyDecls, the same place
      that infers which data types are recursive, another global question.
  12. 17 Jan, 2013 1 commit
    • Simon Peyton Jones's avatar
      Major patch to implement the new Demand Analyser · 0831a12e
      Simon Peyton Jones authored
      This patch is the result of Ilya Sergey's internship at MSR.  It
      constitutes a thorough overhaul and simplification of the demand
      analyser.  It makes a solid foundation on which we can now build.
      Main changes are
      * Instead of having one combined type for Demand, a Demand is
         now a pair (JointDmd) of
            - a StrDmd and
            - an AbsDmd.
         This allows strictness and absence to be though about quite
         orthogonally, and greatly reduces brain melt-down.
      * Similarly in the DmdResult type, it's a pair of
           - a PureResult (indicating only divergence/non-divergence)
           - a CPRResult (which deals only with the CPR property
      * In IdInfo, the
          strictnessInfo field contains a StrictSig, not a Maybe StrictSig
          demandInfo     field contains a Demand, not a Maybe Demand
        We don't need Nothing (to indicate no strictness/demand info)
        any more; topSig/topDmd will do.
      * Remove "boxity" analysis entirely.  This was an attempt to
        avoid "reboxing", but it added complexity, is extremely
        ad-hoc, and makes very little difference in practice.
      * Remove the "unboxing strategy" computation. This was an an
        attempt to ensure that a worker didn't get zillions of
        arguments by unboxing big tuples.  But in fact removing it
        DRAMATICALLY reduces allocation in an inner loop of the
        I/O library (where the threshold argument-count had been
        set just too low).  It's exceptional to have a zillion arguments
        and I don't think it's worth the complexity, especially since
        it turned out to have a serious performance hit.
      * Remove quite a bit of ad-hoc cruft
      * Move worthSplittingFun, worthSplittingThunk from WorkWrap to
        Demand. This allows JointDmd to be fully abstract, examined
        only inside Demand.
      Everything else really follows from these changes.
      All of this is really just refactoring, so we don't expect
      big performance changes, but acutally the numbers look quite
      good.  Here is a full nofib run with some highlights identified:
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
               expert          -2.6%    -15.5%      0.00      0.00     +0.0%
                fluid          -2.4%     -7.1%      0.01      0.01     +0.0%
                   gg          -2.5%    -28.9%      0.02      0.02    -33.3%
            integrate          -2.6%     +3.2%     +2.6%     +2.6%     +0.0%
              mandel2          -2.6%     +4.2%      0.01      0.01     +0.0%
             nucleic2          -2.0%    -16.3%      0.11      0.11     +0.0%
                 para          -2.6%    -20.0%    -11.8%    -11.7%     +0.0%
               parser          -2.5%    -17.9%      0.05      0.05     +0.0%
               prolog          -2.6%    -13.0%      0.00      0.00     +0.0%
               puzzle          -2.6%     +2.2%     +0.8%     +0.8%     +0.0%
              sorting          -2.6%    -35.9%      0.00      0.00     +0.0%
             treejoin          -2.6%    -52.2%     -9.8%     -9.9%     +0.0%
                  Min          -2.7%    -52.2%    -11.8%    -11.7%    -33.3%
                  Max          -1.8%     +4.2%    +10.5%    +10.5%     +7.7%
       Geometric Mean          -2.5%     -2.8%     -0.4%     -0.5%     -0.4%
      Things to note
      * Binary sizes are smaller. I don't know why, but it's good.
      * Allocation is sometiemes a *lot* smaller. I believe that all the big numbers
        (I checked treejoin, gg, sorting) arise from one place, namely a function
        GHC.IO.Encoding.UTF8.utf8_decode, which is strict in two Buffers both of
        which have several arugments.  Not w/w'ing both arguments (which is what
        we did before) has a big effect.  So the big win in actually somewhat
        accidental, gained by removing the "unboxing strategy" code.
      * A couple of benchmarks allocate slightly more.  This turns out
        to be due to reboxing (integrate).  But the biggest increase is
        mandel2, and *that* turned out also to be a somewhat accidental
        loss of CSE, and pointed the way to doing better CSE: see Trac
      * Runtimes are never very reliable, but seem to improve very slightly.
      All in all, a good piece of work.  Thank you Ilya!
  13. 05 Jan, 2013 1 commit
    • eir@cis.upenn.edu's avatar
      Refactor invariants for FamInsts. · 5765248b
      eir@cis.upenn.edu authored
      This commit mirrors work done in the commit for ClsInsts, 5efe9b...
      - All FamInsts have *fresh* type variables. So, no more freshness work
      in addLocalFamInst
      - Some pretty-printing code around FamInsts was cleaned up a bit
      This caused location information to be added to CoAxioms and index
      information to be added to FamInstBranches.
  14. 01 Jan, 2013 1 commit
  15. 23 Dec, 2012 1 commit
    • Simon Peyton Jones's avatar
      Make {-# UNPACK #-} work for type/data family invocations · 1ee1cd41
      Simon Peyton Jones authored
      This fixes most of Trac #3990.  Consider
        data family D a
        data instance D Double = CD Int Int
        data T = T {-# UNPACK #-} !(D Double)
      Then we want the (D Double unpacked).
      To do this we need to construct a suitable coercion, and it's much
      safer to record that coercion in the interface file, lest the in-scope
      instances differ somehow.  That in turn means elaborating the HsBang
      type to include a coercion.
      To do that I moved HsBang from BasicTypes to DataCon, which caused
      quite a few minor knock-on changes.
      Interface-file format has changed!
      Still to do: need to do knot-tying to allow instances to take effect
      within the same module.
  16. 22 Dec, 2012 1 commit
    • eir@cis.upenn.edu's avatar
      Implement overlapping type family instances. · 8366792e
      eir@cis.upenn.edu authored
      An ordered, overlapping type family instance is introduced by 'type
      where', followed by equations. See the new section in the user manual
      ( for details. The canonical example is Boolean equality at the
      type family Equals (a :: k) (b :: k) :: Bool
      type instance where
        Equals a a = True
        Equals a b = False
      A branched family instance, such as this one, checks its equations in
      and applies only the first the matches. As explained in the note
      checking within groups] in FamInstEnv.lhs, we must be careful not to
      say, (Equals Int b) to False, because b might later unify with Int.
      This commit includes all of the commits on the overlapping-tyfams
      branch. SPJ
      requested that I combine all my commits over the past several months
      into one
      monolithic commit. The following GHC repos are affected: ghc, testsuite,
      utils/haddock, libraries/template-haskell, and libraries/dph.
      Here are some details for the interested:
      - The definition of CoAxiom has been moved from TyCon.lhs to a
        new file CoAxiom.lhs. I made this decision because of the
        number of definitions necessary to support BranchList.
      - BranchList is a GADT whose type tracks whether it is a
        singleton list or not-necessarily-a-singleton-list. The reason
        I introduced this type is to increase static checking of places
        where GHC code assumes that a FamInst or CoAxiom is indeed a
        singleton. This assumption takes place roughly 10 times
        throughout the code. I was worried that a future change to GHC
        would invalidate the assumption, and GHC might subtly fail to
        do the right thing. By explicitly labeling CoAxioms and
        FamInsts as being Unbranched (singleton) or
        Branched (not-necessarily-singleton), we make this assumption
        explicit and checkable. Furthermore, to enforce the accuracy of
        this label, the list of branches of a CoAxiom or FamInst is
        stored using a BranchList, whose constructors constrain its
        type index appropriately.
      I think that the decision to use BranchList is probably the most
      controversial decision I made from a code design point of view.
      Although I provide conversions to/from ordinary lists, it is more
      efficient to use the brList... functions provided in CoAxiom than
      always to convert. The use of these functions does not wander far
      from the core CoAxiom/FamInst logic.
      BranchLists are motivated and explained in the note [Branched axioms] in
      - The CoAxiom type has changed significantly. You can see the new
        type in CoAxiom.lhs. It uses a CoAxBranch type to track
        branches of the CoAxiom. Correspondingly various functions
        producing and consuming CoAxioms had to change, including the
        binary layout of interface files.
      - To get branched axioms to work correctly, it is important to have a
        of type "apartness": two types are apart if they cannot unify, and no
        substitution of variables can ever get them to unify, even after type
        simplification. (This is different than the normal failure to unify
        of the type family bit.) This notion in encoded in tcApartTys, in
        Because apartness is finer-grained than unification, the tcUnifyTys
        calls tcApartTys.
      - CoreLinting axioms has been updated, both to reflect the new
        form of CoAxiom and to enforce the apartness rules of branch
        application. The formalization of the new rules is in
      - The FamInst type (in types/FamInstEnv.lhs) has changed
        significantly, paralleling the changes to CoAxiom. Of course,
        this forced minor changes in many files.
      - There are several new Notes in FamInstEnv.lhs, including one
        discussing confluent overlap and why we're not doing it.
      - lookupFamInstEnv, lookupFamInstEnvConflicts, and
        lookup_fam_inst_env' (the function that actually does the work)
        have all been more-or-less completely rewritten. There is a
        Note [lookup_fam_inst_env' implementation] describing the
        implementation. One of the changes that affects other files is
        to change the type of matches from a pair of (FamInst, [Type])
        to a new datatype (which now includes the index of the matching
        branch). This seemed a better design.
      - The TySynInstD constructor in Template Haskell was updated to
        use the new datatype TySynEqn. I also bumped the TH version
        number, requiring changes to DPH cabal files. (That's why the
        DPH repo has an overlapping-tyfams branch.)
      - As SPJ requested, I refactored some of the code in HsDecls:
       * splitting up TyDecl into SynDecl and DataDecl, correspondingly
         changing HsTyDefn to HsDataDefn (with only one constructor)
       * splitting FamInstD into TyFamInstD and DataFamInstD and
         splitting FamInstDecl into DataFamInstDecl and TyFamInstDecl
       * making the ClsInstD take a ClsInstDecl, for parallelism with
         InstDecl's other constructors
       * changing constructor TyFamily into FamDecl
       * creating a FamilyDecl type that stores the details for a family
         declaration; this is useful because FamilyDecls can appear in classes
         other decls cannot
       * restricting the associated types and associated type defaults for a
       * class
         to be the new, more restrictive types
       * splitting cid_fam_insts into cid_tyfam_insts and cid_datafam_insts,
         according to the new types
       * perhaps one or two more that I'm overlooking
      None of these changes has far-reaching implications.
      - The user manual, section, is updated to describe the new type
  17. 05 Dec, 2012 1 commit
  18. 19 Oct, 2012 1 commit
    • Simon Peyton Jones's avatar
      Only promote *non-existential* data constructors · 8019bc2c
      Simon Peyton Jones authored
      I don't konw how this was left out before; Trac #7347.
      In fixing this I did the usual round of refactoring.  In particular, I
      cached the fact that a DataCon can be promoted in the DataCon
      itself (the dcPromoted field).
  19. 16 Oct, 2012 1 commit
    • ian@well-typed.com's avatar
      Some alpha renaming · cd33eefd
      ian@well-typed.com authored
      Mostly d -> g (matching DynFlag -> GeneralFlag).
      Also renamed if* to when*, matching the Haskell if/when names
  20. 12 Oct, 2012 1 commit
    • Simon Peyton Jones's avatar
      Be lazier when typechecking data type contexts (Trac #7321) · beb2f743
      Simon Peyton Jones authored
      We should be lazy when type-checking the equality-contraint
      part of a data constructor's type, to make the knot-tying
      work out right.  The fact that it's always worked before
      is a fluke: no one else wrote a GADT whose type index mentions
        data T a wher
          MkT :: T (T Int)
  21. 09 Oct, 2012 1 commit
    • ian@well-typed.com's avatar
      Make the opt_UF_* static flags dynamic · 0a768bcb
      ian@well-typed.com authored
      I also removed the default values from the "Discounts and thresholds"
      note: most of them were no longer up-to-date.
      Along the way I added FloatSuffix to the argument parser, analogous to
  22. 18 Sep, 2012 1 commit
    • Simon Peyton Jones's avatar
      Make a start towards eta-rules and injective families · 58470fb7
      Simon Peyton Jones authored
      * Make Any into a type family (which it should always have been)
        This is to support the future introduction of eta rules for
        product types (see email on ghc-users title "PolyKind issue"
        early Sept 2012)
      * Add the *internal* data type support for
          (a) closed type families [so that you can't give
              type instance for 'Any']
          (b) injective type families [because Any is really
        This amounts to two boolean flags on the SynFamilyTyCon
        constructor of TyCon.SynTyConRhs.
      There is some knock-on effect, but all of a routine nature.
      It remains to offer source syntax for either closed or
      injective families.
  23. 17 Sep, 2012 1 commit
    • Simon Peyton Jones's avatar
      Implement 'left' and 'right' coercions · af7cc995
      Simon Peyton Jones authored
      This patch finally adds 'left' and 'right' coercions back into
      GHC.  Trac #7205 gives the details.
      The main change is to add a new constructor to Coercion:
        data Coercion
          = ...
          | NthCo  Int         Coercion     -- OLD, still there
          | LRCo   LeftOrRight Coercion     -- NEW
        data LeftOrRight = CLeft | CRight
        * Similar change to TcCoercion
        * Use LRCo when decomposing AppTys
        * Coercion optimisation needs to handle left/right
      The rest is just knock-on effects.
  24. 27 Jun, 2012 1 commit
    • Simon Peyton Jones's avatar
      Add silent superclass parameters (again) · aa1e0976
      Simon Peyton Jones authored
      Silent superclass parameters solve the problem that
      the superclasses of a dicionary construction can easily
      turn out to be (wrongly) bottom.  The problem and solution
      are described in
         Note [Silent superclass arguments] in TcInstDcls
      I first implemented this fix (with Dimitrios) in Dec 2010, but removed
      it again in Jun 2011 becuase we thought it wasn't necessary any
      more. (The reason we thought it wasn't necessary is that we'd stopped
      generating derived superclass constraints for *wanteds*.  But we were
      wrong; that didn't solve the superclass-loop problem.)
      So we have to re-implement it.  It's not hard.  Main features:
        * The IdDetails for a DFunId says how many silent arguments it has
        * A DFunUnfolding describes which dictionary args are
          just parameters (DFunLamArg) and which are a function to apply
          to the parameters (DFunPolyArg).  This adds the DFunArg type
          to CoreSyn
        * Consequential changes to IfaceSyn.  (Binary hi file format changes
        * TcInstDcls changes to generate the right dfuns
        * CoreSubst.exprIsConApp_maybe handles the new DFunUnfolding
      The thing taht is *not* done yet is to alter the vectoriser to
      pass the relevant extra argument when building a PA dictionary.
  25. 13 Jun, 2012 1 commit
    • Simon Peyton Jones's avatar
      Simplify the implementation of Implicit Parameters · 5a8ac0f8
      Simon Peyton Jones authored
      This patch re-implements implicit parameters via a class
      with a functional dependency:
          class IP (n::Symbol) a | n -> a where
            ip :: a
      This definition is in the library module GHC.IP. Notice
      how it use a type-literal, so we can have constraints like
         IP "x" Int
      Now all the functional dependency machinery works right to make
      implicit parameters behave as they should.
      Much special-case processing for implicit parameters can be removed
      entirely. One particularly nice thing is not having a dedicated
      "original-name cache" for implicit parameters (the nsNames field of
      NameCache).  But many other cases disappear:
        * BasicTypes.IPName
        * IPTyCon constructor in Tycon.TyCon
        * CIPCan constructor  in TcRnTypes.Ct
        * IPPred constructor  in Types.PredTree
      Implicit parameters remain special in a few ways:
       * Special syntax.  Eg the constraint (IP "x" Int) is parsed
         and printed as (?x::Int).  And we still have local bindings
         for implicit parameters, and occurrences thereof.
       * A implicit-parameter binding  (let ?x = True in e) amounts
         to a local instance declaration, which we have not had before.
         It just generates an implication contraint (easy), but when
         going under it we must purge any existing bindings for
         ?x in the inert set.  See Note [Shadowing of Implicit Parameters]
         in TcSimplify
       * TcMType.sizePred classifies implicit parameter constraints as size-0,
         as before the change
      There are accompanying patches to libraries 'base' and 'haddock'
      All the work was done by Iavor Diatchki
  26. 12 Jun, 2012 2 commits
  27. 06 Jun, 2012 1 commit
  28. 02 May, 2012 1 commit
    • Simon Peyton Jones's avatar
      Allow cases with empty alterantives · ac230c5e
      Simon Peyton Jones authored
      This patch allows, for the first time, case expressions with an empty
      list of alternatives. Max suggested the idea, and Trac #6067 showed
      that it is really quite important.
      So I've implemented the idea, fixing #6067. Main changes
       * See Note [Empty case alternatives] in CoreSyn
       * Various foldr1's become foldrs
       * IfaceCase does not record the type of the alternatives.
         I added IfaceECase for empty-alternative cases.
       * Core Lint does not complain about empty cases
       * MkCore.castBottomExpr constructs an empty-alternative case
         expression   (case e of ty {})
       * CoreToStg converts '(case e of {})' to just 'e'
  29. 30 Apr, 2012 1 commit
    • Simon Peyton Jones's avatar
      Make the interface-file deserialisation work right for promoted types (Trac #6054) · e57c8667
      Simon Peyton Jones authored
      GHC currently uses the slightly-dodgy plan that when we proote
      a TyCon to be a Kind constructor we leave it with the same Name.
      That means that to make sense of a IfaceType we need to know wheter
      it is really an IfaceType or an IfaceKind, because in the latter an
      occurrence of (say) Maybe will be the *promoted* Maybe.
      See Note [Checking IfaceTypes vs IfaceKinds] in TcIface
  30. 28 Mar, 2012 1 commit
  31. 05 Mar, 2012 1 commit
  32. 22 Feb, 2012 2 commits
    • batterseapower's avatar
      Simplified serialization of IfaceTyCon, again · 0a882747
      batterseapower authored
      Jose's patch implementing kind-polymorphic core (09015be8) reverted many of the simplifying changes to interface file TyCon serialization I had made in a previous patch (5d7173f9). Based on the diff I think this was an unintended consequence of how Jose did the merge rather than a real change he intended to make.
      In fact, as a result of kind-polymorphic core we don't need to treat the Any TyCon specially any longer so my old simplifying changes can be made even simpler: IfaceTyCon is now just a newtype on IfaceExtName.
    • Ian Lynagh's avatar
      Remove support for CTYPE pragmas on type synonyms · 544926d7
      Ian Lynagh authored
      It's not clear whether it's desirable or not, and it turns out that
      the way we use coercions in GHC means we tend to lose information
      about type synonyms.
  33. 16 Feb, 2012 2 commits
  34. 25 Jan, 2012 1 commit
    • Iavor S. Diatchki's avatar
      Add support for type-level "strings". · 5851f847
      Iavor S. Diatchki authored
      These are types that look like "this" and "that".
      They are of kind `Symbol`, defined in module `GHC.TypeLits`.
      For each type-level symbol `X`, we have a singleton type, `TSymbol X`.
      The value of the singleton type can be named with the overloaded
      constant `tSymbol`.  Here is an example:
      tSymbol :: TSymbol "Hello"
  35. 15 Jan, 2012 1 commit
    • chak@cse.unsw.edu.au.'s avatar
      Fix vectorisation of classes · b68bbd86
      chak@cse.unsw.edu.au. authored
      - Make sure that we have no implicit names in ifaces
      - Any vectorisation info makes a module an orphan module
      - Allow 'Show' in vectorised code without vectorising it for the moment
  36. 13 Jan, 2012 1 commit