1. 06 Apr, 2016 1 commit
    • Joachim Breitner's avatar
      Demand Analyzer: Do not set OneShot information (second try) · 0f58d348
      Joachim Breitner authored
      as suggested in ticket:11770#comment:1. This code was buggy
      (#11770), and the occurrence analyzer does the same job anyways.
      
      This also elaborates the notes in the occurrence analyzer accordingly.
      
      Previously, the worker/wrapper code would go through lengths to transfer
      the oneShot annotations from the original function to both the worker
      and the wrapper. We now simply transfer the demand on the worker, and
      let the subsequent occurrence analyzer push this onto the lambda
      binders.
      
      This also requires the occurrence analyzer to do this more reliably.
      Previously, it would not hand out OneShot annotatoins to things that
      would not `certainly_inline` (and it might not have mattered, as the
      Demand Analysis might have handed out the annotations). Now we hand out
      one-shot annotations unconditionally.
      
      Differential Revision: https://phabricator.haskell.org/D2085
      0f58d348
  2. 30 Mar, 2016 1 commit
  3. 29 Mar, 2016 1 commit
  4. 18 Jan, 2016 1 commit
    • Jan Stolarek's avatar
      Replace calls to `ptext . sLit` with `text` · b8abd852
      Jan Stolarek authored
      Summary:
      In the past the canonical way for constructing an SDoc string literal was the
      composition `ptext . sLit`.  But for some time now we have function `text` that
      does the same.  Plus it has some rules that optimize its runtime behaviour.
      This patch takes all uses of `ptext . sLit` in the compiler and replaces them
      with calls to `text`.  The main benefits of this patch are clener (shorter) code
      and less dependencies between module, because many modules now do not need to
      import `FastString`.  I don't expect any performance benefits - we mostly use
      SDocs to report errors and it seems there is little to be gained here.
      
      Test Plan: ./validate
      
      Reviewers: bgamari, austin, goldfire, hvr, alanz
      
      Subscribers: goldfire, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D1784
      b8abd852
  5. 17 Dec, 2015 1 commit
    • Simon Marlow's avatar
      Remote GHCi, -fexternal-interpreter · 4905b83a
      Simon Marlow authored
      Summary:
      (Apologies for the size of this patch, I couldn't make a smaller one
      that was validate-clean and also made sense independently)
      
      (Some of this code is derived from GHCJS.)
      
      This commit adds support for running interpreted code (for GHCi and
      TemplateHaskell) in a separate process.  The functionality is
      experimental, so for now it is off by default and enabled by the flag
      -fexternal-interpreter.
      
      Reaosns we want this:
      
      * compiling Template Haskell code with -prof does not require
        building the code without -prof first
      
      * when GHC itself is profiled, it can interpret unprofiled code, and
        the same applies to dynamic linking.  We would no longer need to
        force -dynamic-too with TemplateHaskell, and we can load ordinary
        objects into a dynamically-linked GHCi (and vice versa).
      
      * An unprofiled GHCi can load and run profiled code, which means it
        can use the stack-trace functionality provided by profiling without
        taking the performance hit on the compiler that profiling would
        entail.
      
      Amongst other things; see
      https://ghc.haskell.org/trac/ghc/wiki/RemoteGHCi for more details.
      
      Notes on the implementation are in Note [Remote GHCi] in the new
      module compiler/ghci/GHCi.hs.  It probably needs more documenting,
      feel free to suggest things I could elaborate on.
      
      Things that are not currently implemented for -fexternal-interpreter:
      
      * The GHCi debugger
      * :set prog, :set args in GHCi
      * `recover` in Template Haskell
      * Redirecting stdin/stdout for the external process
      
      These are all doable, I just wanted to get to a working validate-clean
      patch first.
      
      I also haven't done any benchmarking yet.  I expect there to be slight hit
      to link times for byte code and some penalty due to having to
      serialize/deserialize TH syntax, but I don't expect it to be a serious
      problem.  There's also lots of low-hanging fruit in the byte code
      generator/linker that we could exploit to speed things up.
      
      Test Plan:
      * validate
      * I've run parts of the test suite with
      EXTRA_HC_OPTS=-fexternal-interpreter, notably tests/ghci and tests/th.
      There are a few failures due to the things not currently implemented
      (see above).
      
      Reviewers: simonpj, goldfire, ezyang, austin, alanz, hvr, niteria, bgamari, gibiansky, luite
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1562
      4905b83a
  6. 11 Dec, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Add kind equalities to GHC. · 67465497
      eir@cis.upenn.edu authored
      This implements the ideas originally put forward in
      "System FC with Explicit Kind Equality" (ICFP'13).
      
      There are several noteworthy changes with this patch:
       * We now have casts in types. These change the kind
         of a type. See new constructor `CastTy`.
      
       * All types and all constructors can be promoted.
         This includes GADT constructors. GADT pattern matches
         take place in type family equations. In Core,
         types can now be applied to coercions via the
         `CoercionTy` constructor.
      
       * Coercions can now be heterogeneous, relating types
         of different kinds. A coercion proving `t1 :: k1 ~ t2 :: k2`
         proves both that `t1` and `t2` are the same and also that
         `k1` and `k2` are the same.
      
       * The `Coercion` type has been significantly enhanced.
         The documentation in `docs/core-spec/core-spec.pdf` reflects
         the new reality.
      
       * The type of `*` is now `*`. No more `BOX`.
      
       * Users can write explicit kind variables in their code,
         anywhere they can write type variables. For backward compatibility,
         automatic inference of kind-variable binding is still permitted.
      
       * The new extension `TypeInType` turns on the new user-facing
         features.
      
       * Type families and synonyms are now promoted to kinds. This causes
         trouble with parsing `*`, leading to the somewhat awkward new
         `HsAppsTy` constructor for `HsType`. This is dispatched with in
         the renamer, where the kind `*` can be told apart from a
         type-level multiplication operator. Without `-XTypeInType` the
         old behavior persists. With `-XTypeInType`, you need to import
         `Data.Kind` to get `*`, also known as `Type`.
      
       * The kind-checking algorithms in TcHsType have been significantly
         rewritten to allow for enhanced kinds.
      
       * The new features are still quite experimental and may be in flux.
      
       * TODO: Several open tickets: #11195, #11196, #11197, #11198, #11203.
      
       * TODO: Update user manual.
      
      Tickets addressed: #9017, #9173, #7961, #10524, #8566, #11142.
      Updates Haddock submodule.
      67465497
  7. 04 Dec, 2015 1 commit
    • Bartosz Nitka's avatar
      Make callToPats deterministic in SpecConstr · 5b2b7e33
      Bartosz Nitka authored
      This fixes a non-determinism bug where where depending on the
      order of uniques allocated, the specialized workers would have different
      order of arguments.
      
      Compare:
      
      ```
        $s$wgo_s1CN :: Int# -> Int -> Int#
        [LclId, Arity=2, Str=DmdType <L,U><L,U>]
        $s$wgo_s1CN =
          \ (sc_s1CI :: Int#) (sc_s1CJ :: Int) ->
            case tagToEnum# @ Bool (<=# sc_s1CI 0#) of _ [Occ=Dead] {
              False ->
                $wgo_s1BU (Just @ Int (I# (-# sc_s1CI 1#))) (Just @ Int sc_s1CJ);
              True -> 0#
            }
      ```
      
      vs
      
      ```
        $s$wgo_s18mTj :: Int -> Int# -> Int#
        [LclId, Arity=2, Str=DmdType <L,U><L,U>]
        $s$wgo_s18mTj =
          \ (sc_s18mTn :: Int) (sc_s18mTo :: Int#) ->
            case tagToEnum# @ Bool (<=# sc_s18mTo 0#) of _ [Occ=Dead] {
              False ->
                $wgo_s18mUc
                  (Just @ Int (I# (-# sc_s18mTo 1#))) (Just @ Int sc_s18mTn);
              True -> 0#
            }
      ```
      
      Test Plan:
      I've added a new testcase
      ./validate
      
      Reviewers: simonmar, simonpj, austin, goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1508
      
      GHC Trac Issues: #4012
      5b2b7e33
  8. 11 Nov, 2015 1 commit
    • niteria's avatar
      Put kind variables before type variables when specializing · 0f495083
      niteria authored
      When you reverse the order of uniques you get the core lint
      error from the testcase. The testcase is copied from
      tests/simplCore/should_compile/T10689a.hs.
      
      The problem is that we would put type and kind variables ordered by
      unique order, which happened to be the right order for this testcase to
      pass under normal conditions.
      
      I think it's enough to sort them with `sortQuantVars`, but I'm not
      really sure if some more sophisticated dependency analysis isn't needed.
      
      Test Plan: added a new testcase
      
      Reviewers: simonpj, goldfire, simonmar, austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1457
      0f495083
  9. 10 Oct, 2015 1 commit
  10. 13 Jul, 2015 2 commits
  11. 20 Jun, 2015 1 commit
    • Edward Z. Yang's avatar
      Filter orphan rules based on imports, fixes #10294 and #10420. · 0cb1f5cf
      Edward Z. Yang authored
      Summary:
      If we have an orphan rule in our database, don't apply it
      unless the defining module is transitively imported by the
      module we are processing.  We do this by defining a new RuleEnv
      data type which includes both the RuleBase as well as the set
      of visible orphan modules, and threading this through the
      relevant environments (CoreReader, RuleCheckEnv and ScEnv).
      
      This is analogous to the instances fix we applied in #2182
      4c834fdd, but done for RULES.
      An important knock-on effect is that we can remove some buggy
      code in LoadInterface which tried to avoid loading interfaces
      that were loaded by plugins (which sometimes caused instances
      and rules to NEVER become visible).
      
      One note about tests: I renamed the old plugins07 test to T10420
      and replaced plugins07 with a test to ensure that a plugin
      import did not cause new rules to be loaded in.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: simonpj, austin, goldfire
      
      Subscribers: bgamari, thomie
      
      Differential Revision: https://phabricator.haskell.org/D950
      
      GHC Trac Issues: #10420
      0cb1f5cf
  12. 01 May, 2015 1 commit
  13. 29 Apr, 2015 1 commit
    • Simon Peyton Jones's avatar
      Seed SpecConstr from local calls · b61562fe
      Simon Peyton Jones authored
      Seed SpecConstr based on *local* calls as well as *RHS* calls.
      See Note [Seeding top-level recursive groups].  The change here
      is mentioned here:
      
         NB: before Apr 15 we used (a) only, but Dimitrios had an example
             where (b) was  crucial, so I added that.
      
      This is a pretty small change, requested by Dimitrios, that adds
      SpecConstr call patterns from the rest of the module, as well as ones
      from the RHS.
      
      Still to come: #10346.
      b61562fe
  14. 10 Apr, 2015 1 commit
  15. 10 Feb, 2015 1 commit
  16. 16 Dec, 2014 1 commit
    • Peter Wortmann's avatar
      Source notes (Core support) · 993975d3
      Peter Wortmann authored
      This patch introduces "SourceNote" tickishs that link Core to the
      source code that generated it. The idea is to retain these source code
      links throughout code transformations so we can eventually relate
      object code all the way back to the original source (which we can,
      say, encode as DWARF information to allow debugging).  We generate
      these SourceNotes like other tickshs in the desugaring phase. The
      activating command line flag is "-g", consistent with the flag other
      compilers use to decide DWARF generation.
      
      Keeping ticks from getting into the way of Core transformations is
      tricky, but doable. The changes in this patch produce identical Core
      in all cases I tested -- which at this point is GHC, all libraries and
      nofib. Also note that this pass creates *lots* of tick nodes, which we
      reduce somewhat by removing duplicated and overlapping source
      ticks. This will still cause significant Tick "clumps" - a possible
      future optimization could be to make Tick carry a list of Tickishs
      instead of one at a time.
      
      (From Phabricator D169)
      993975d3
  17. 03 Dec, 2014 1 commit
  18. 27 Sep, 2014 1 commit
    • thomie's avatar
      Stop exporting, and stop using, functions marked as deprecated · 51aa2fa3
      thomie authored
      Don't export `getUs` and `getUniqueUs`. `UniqSM` has a `MonadUnique` instance:
      
          instance MonadUnique UniqSM where
              getUniqueSupplyM = getUs
              getUniqueM  = getUniqueUs
              getUniquesM = getUniquesUs
      
      Commandline-fu used:
      
          git grep -l 'getUs\>' |
              grep -v compiler/basicTypes/UniqSupply.lhs |
              xargs sed -i 's/getUs/getUniqueSupplyM/g
      
          git grep -l 'getUniqueUs\>' |
              grep -v combiler/basicTypes/UniqSupply.lhs |
              xargs sed -i 's/getUniqueUs/getUniqueM/g'
      
      Follow up on b522d3a3
      
      Reviewed By: austin, hvr
      
      Differential Revision: https://phabricator.haskell.org/D220
      51aa2fa3
  19. 25 Aug, 2014 3 commits
    • Simon Peyton Jones's avatar
      More refactoring in SpecConstr · 5c4df288
      Simon Peyton Jones authored
      This patch should make no change in behaviour.
      
       * Make RhsInfo into a record
      
       * Include ri_rhs_usg, which previously travelled around separately
      
       * Introduce specRec, specNonRec, and
         make them return [OneSpec] rather than SpecInfo
      5c4df288
    • Simon Peyton Jones's avatar
      Do not duplicate call information in SpecConstr (Trac #8852) · af4bc31c
      Simon Peyton Jones authored
      This long-standing and egregious bug meant that call information was
      being gratuitously copied, leading to an exponential blowup in the
      number of calls to be examined when function definitions are deeply
      nested.  That is what has been causing the blowup in SpecConstr's
      running time, not (as I had previously supposed) generating very large code.
      
      See Note [spec_usg includes rhs_usg]
      af4bc31c
    • Simon Peyton Jones's avatar
      Introduce the Call data types · c0fe1d9e
      Simon Peyton Jones authored
      This is just a small refactoring that makes the code a bit clearer,
      using a data type instead of a triple.  We get better pretty-printing too.
      c0fe1d9e
  20. 15 May, 2014 1 commit
    • Herbert Valerio Riedel's avatar
      Add LANGUAGE pragmas to compiler/ source files · 23892440
      Herbert Valerio Riedel authored
      In some cases, the layout of the LANGUAGE/OPTIONS_GHC lines has been
      reorganized, while following the convention, to
      
      - place `{-# LANGUAGE #-}` pragmas at the top of the source file, before
        any `{-# OPTIONS_GHC #-}`-lines.
      
      - Moreover, if the list of language extensions fit into a single
        `{-# LANGUAGE ... -#}`-line (shorter than 80 characters), keep it on one
        line. Otherwise split into `{-# LANGUAGE ... -#}`-lines for each
        individual language extension. In both cases, try to keep the
        enumeration alphabetically ordered.
        (The latter layout is preferable as it's more diff-friendly)
      
      While at it, this also replaces obsolete `{-# OPTIONS ... #-}` pragma
      occurences by `{-# OPTIONS_GHC ... #-}` pragmas.
      23892440
  21. 05 May, 2014 1 commit
  22. 13 Feb, 2014 1 commit
  23. 14 Jan, 2014 2 commits
  24. 12 Dec, 2013 1 commit
    • Simon Peyton Jones's avatar
      Improve the handling of used-once stuff · 80989de9
      Simon Peyton Jones authored
      Joachim and I are committing this onto a branch so that we can share it,
      but we expect to do a bit more work before merging it onto head.
      
      Nofib staus:
        - Most programs, no change
        - A few improve
        - A couple get worse (cacheprof, tak, rfib)
      Investigating the "get worse" set is what's holding up putting this
      on head.
      
      The major issue is this.  Consider
      
          map (f g) ys
      
      where f's demand signature looks like
      
         f :: <L,C1(C1(U))> -> <L,U> -> .
      
      So 'f' is not saturated.  What demand do we place on g?
      Answer
              C(C1(U))
      That is, the inner C1 should stay, even though f is not saturated.
      
      I found that this made a significant difference in the demand signatures
      inferred in GHC.IO, which uses lots of higher-order exception handlers.
      
      I also had to add used-once demand signatures for some of the
      'catch' primops, so that we know their handlers are only called once.
      80989de9
  25. 09 Dec, 2013 1 commit
  26. 25 Oct, 2013 2 commits
    • Austin Seipp's avatar
      Update documentation regarding SpecConstr. · 32df4290
      Austin Seipp authored
       * Note new SPEC type in release notes.
       * Document SPEC in the users guide under the documentation for
         -fspec-constr.
       * Clean up comments in SpecConstr regarding the forcing of
         specialisation (see Note [Forcing specialisation].)
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      32df4290
    • Austin Seipp's avatar
      Make SpecConstr also check for GHC.Types.SPEC · cee3adbc
      Austin Seipp authored
      SpecConstr has for a while now looked for types with the built
      in ForceSpecConstr annotation, in order to know where to be particularly
      aggressive.
      
      Unfortunately using an annotation has a number of downsides, the most
      prominent two being:
      
        A) ForceSpecConstr is vital for efficiency (even if it's
           a hack), but it means users of it must have GHCI - even though
           stage2 features are not required for anything but the annotation.
      
        B) Any user who might need it (read: vector) has to duplicate the same
           piece of code. In general there are few people actually doing this,
           but it's unclear why they should have to.
      
      This patch makes SpecConstr look for functions applied to the new
      GHC.Types.SPEC type - a copy of the already-extant 'SPEC' type - as well
      as look for annotations, in the stage2 compiler.
      
      In particular, this means `vector` can now be built with a stage1
      compiler, since it no longer depends on stage2 for anything else. This
      is particularly important for e.g. iOS cross-compilers.
      
      This also means we should be able to build `vector` earlier in the build
      process too, but this patch doesn't address that.
      
      This requires an accompanying bump in ghc-prim.
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      cee3adbc
  27. 30 Aug, 2013 1 commit
  28. 02 Aug, 2013 1 commit
  29. 15 May, 2013 1 commit
    • amosrobinson's avatar
      SpecConstr: seed specialisation of top-level bindings, as with letrecs. · 8a588511
      amosrobinson authored
      When specialising a top-level recursive group, if none of the binders
      are exported then we can start specialising based on the later calls to
      the functions.
      This is instead of creating specialisations based on the RHS of the
      bindings.
      The main benefit of this is that only specialisations that will actually
      be used are created. This saves quite a bit of memory when compiling
      stream-fusion and ForceSpecConstr sort of code.
      
      Nofib has an average allocation and runtime of -0.7%, maximum 2%.
      There are a few with significant decreases in allocation (10 - 20%)
      but, interestingly, those ones seem to have similar runtimes.
      One of these does have a significantly reduced total elapsed time
      though: -38%.
      
      On average the nofib compilation times are the same, but they do vary
      with s.d. of -4 to 4%.
      I think this is acceptable because of the fairly major code blowup fixes
      this has for fusion-style code.
      (In one example, a SpecConstr was previously producing 122,000 term size,
      now only produces 28,000 with the same object code)
      8a588511
  30. 03 May, 2013 1 commit
  31. 11 Apr, 2013 1 commit
    • nfrisby's avatar
      ignore RealWorld in size_expr; flag to keep w/w from creating sharing · af12cf66
      nfrisby authored
      size_expr now ignores RealWorld lambdas, arguments, and applications.
      
      Worker-wrapper previously removed all lambdas from a function, if they
      were all unused. Removing *all* value lambdas is no longer
      allowed. Instead (\_ -> E) will become (\_void -> E), where it used to
      become E. The previous behavior can be recovered via the new
      -ffun-to-thunk flag.
      
      Nofib notables:
      
      ----------------------------------------------------------------
              Program               O2          O2 newly ignoring RealWorld
                                                and not turning function
                                                closures into thunks
      ----------------------------------------------------------------
      
       Allocations
      
        comp_lab_zift            333090392%           -5.0%
      reverse-complem            155188304%           -3.2%
      
              rewrite             15380888%           +4.0%
               boyer2              3901064%           +7.5%
      
      rewrite previously benefited from fortunate LoopBreaker choice that is
      now disrupted.
      
      A function in boyer2 goes from $wonewayunify1 size 700 to size 650,
      thus gets inlined into rewritelemmas, thus exposing a parameter
      scrutinisation, thus allowing SpecConstr, which unfortunately involves
      reboxing.
      
      Run Time
      
       fannkuch-redux                 7.89%          -15.9%
      
                  hpg                 0.25%           +5.6%
                 wang                 0.21%           +5.8%
      
      /shrug
      af12cf66
  32. 28 Mar, 2013 1 commit
  33. 02 Feb, 2013 1 commit
  34. 30 Jan, 2013 1 commit
  35. 24 Jan, 2013 1 commit
    • Simon Peyton Jones's avatar
      Introduce CPR for sum types (Trac #5075) · d3b8991b
      Simon Peyton Jones authored
      The main payload of this patch is to extend CPR so that it
      detects when a function always returns a result constructed
      with the *same* constructor, even if the constructor comes from
      a sum type.  This doesn't matter very often, but it does improve
      some things (results below).
      
      Binary sizes increase a little bit, I think because there are more
      wrappers.  This with -split-objs.  Without split-ojbs binary sizes
      increased by 6% even for HelloWorld.hs.  It's hard to see exactly why,
      but I think it was because System.Posix.Types.o got included in the
      linked binary, whereas it didn't before.
      
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
                fluid          +1.8%     -0.3%      0.01      0.01     +0.0%
                  tak          +2.2%     -0.2%      0.02      0.02     +0.0%
                 ansi          +1.7%     -0.3%      0.00      0.00     +0.0%
            cacheprof          +1.6%     -0.3%     +0.6%     +0.5%     +1.4%
              parstof          +1.4%     -4.4%      0.00      0.00     +0.0%
              reptile          +2.0%     +0.3%      0.02      0.02     +0.0%
      ----------------------------------------------------------------------
                  Min          +1.1%     -4.4%     -4.7%     -4.7%    -15.0%
                  Max          +2.3%     +0.3%     +8.3%     +9.4%    +50.0%
       Geometric Mean          +1.9%     -0.1%     +0.6%     +0.7%     +0.3%
      
      Other things in this commit
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
      * Got rid of the Lattice class in Demand
      
      * Refactored the way that products and newtypes are
        decomposed (no change in functionality)
      d3b8991b