summaryrefslogtreecommitdiff
path: root/compiler/stranal/DmdAnal.hs
Commit message (Collapse)AuthorAgeFilesLines
* Improve demand analysis for join pointsSimon Peyton Jones2017-04-121-20/+62
| | | | | | | | | I realised (Trac #13543) that we can improve demand analysis for join point quite straightforwardly. The idea is explained in Note [Demand analysis for join points] in DmdAnal
* Add comments on DmdAnal space leak fixSimon Peyton Jones2017-04-061-0/+3
|
* Stamp out space leaks from demand analysisReid Barton2017-04-011-1/+21
| | | | | | | | | | | | | | | | This reduces peak memory usage by ~30% on my test case (DynFlags), and (probably as a result of reduced GC work) decreases compilation time by a few percent as well. Also fix a bug in seqStrDmd so that demeand info is fully evaluated. Reviewers: simonpj, austin, bgamari Reviewed By: bgamari Subscribers: dfeuer, thomie Differential Revision: https://phabricator.haskell.org/D3400
* Broaden demand analysis IO hack notesDavid Feuer2017-03-131-4/+8
| | | | | | | | | | | | | | | The I/O hack for demand analysis has broader and arguably more important implications than the note expressed. Broaden it. [skip ci] Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: carter, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3307
* Upgrade UniqSet to a newtypeDavid Feuer2017-03-011-1/+2
| | | | | | | | | | | | | | | | | | | | | The fundamental problem with `type UniqSet = UniqFM` is that `UniqSet` has a key invariant `UniqFM` does not. For example, `fmap` over `UniqSet` will generally produce nonsense. * Upgrade `UniqSet` from a type synonym to a newtype. * Remove unused and shady `extendVarSet_C` and `addOneToUniqSet_C`. * Use cached unique in `tyConsOfType` by replacing `unitNameEnv (tyConName tc) tc` with `unitUniqSet tc`. Reviewers: austin, hvr, goldfire, simonmar, niteria, bgamari Reviewed By: niteria Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3146
* DmdAnal: Clarify reference to Cardinality Analysis paperBen Gamari2017-02-281-1/+1
|
* Tweaks and typos in manual, note refs, commentsGabor Greif2017-02-091-1/+1
|
* Join pointsLuke Maurer2017-02-011-7/+9
| | | | | | | | | | | | | | | | | | | This major patch implements Join Points, as described in https://ghc.haskell.org/trac/ghc/wiki/SequentCore. You have to read that page, and especially the paper it links to, to understand what's going on; but it is very cool. It's Luke Maurer's work, but done in close collaboration with Simon PJ. This Phab is a squash-merge of wip/join-points branch of http://github.com/lukemaurer/ghc. There are many, many interdependent changes. Reviewers: goldfire, mpickering, bgamari, simonmar, dfeuer, austin Subscribers: simonpj, dfeuer, mpickering, Mikolaj, thomie Differential Revision: https://phabricator.haskell.org/D2853
* Typos and grammar in manual/commentsGabor Greif2017-01-231-1/+1
|
* Typos in comments only [ci skip]Gabor Greif2017-01-181-1/+1
|
* DmdAnal: Add a final, safe iterationJoachim Breitner2016-08-251-78/+110
| | | | | | | | | | | | | | | | | | | this fixes #12368. It also refactors dmdFix a bit, removes some redundancies (such as passing around an strictness signature right next to an id, when that id is guaranteed to have been annotated with that strictness signature). Note that when fixed-point iteration does not terminate, we conservatively delete their strictness signatures (set them to nopSig). But this loses the information on how its strict free variables are used! Lazily used variables already escape via lazy_fvs. We ensure that in the case of an aborted fixed-point iteration, also the strict variables are put there (with a conservative demand of topDmd). Differential Revision: https://phabricator.haskell.org/D2392
* Comments only: Refer to actually existing NotesJoachim Breitner2016-08-251-2/+3
|
* Demand analyser: Implement LetUp rule (#12370)Joachim Breitner2016-07-121-21/+79
| | | | | | | | | | | | | This makes the implementation match the description in the paper more closely: There, a let binding that is not a function has first its body analised, and then the binding’s RHS. This way, the demand on the bound variable by the body can be fed into the RHS, yielding more precise results. Performance measurements do unfortunately not show significant improvements or regessions. Differential Revision: https://phabricator.haskell.org/D2395
* Typos in DmdAnalÖmer Sinan Ağacan2016-05-011-2/+2
|
* Comments onlySimon Peyton Jones2016-04-151-14/+16
|
* Add a final demand analyzer run right before TidyCoreJoachim Breitner2016-04-141-0/+28
| | | | | | | | | | | | | | | | | | in order to have precise used-once information in the exported strictness signatures, as well as precise used-once information on thunks. This avoids the bad effects of #11731. The subsequent worker-wrapper pass is responsible for removing the demand environment part of the strictness signature. It does not run after the final demand analyzer pass, so remove this also in CoreTidy. The subsequent worker-wrapper pass is also responsible for removing used-once-information from the demands and strictness signatures, as these might not be preserved by the simplifier. This is _not_ done by CoreTidy, because we _do_ want this information, as produced by the last round of the demand analyzer, to be available to the code generator. Differential Revision: https://phabricator.haskell.org/D2073
* Demand Analyzer: Do not set OneShot information (second try)Joachim Breitner2016-04-061-50/+5
| | | | | | | | | | | | | | | | | | | | | 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
* Revert "Demand Analyzer: Do not set OneShot information"Joachim Breitner2016-03-311-5/+50
| | | | | | | This reverts commit 28fe0eea4d161b707f67aae26fddaa2e60d8a901 due to various regressions. I’m not sure why my local ./validate --slow run did not catch this, though.
* Demand Analyzer: Do not set OneShot informationJoachim Breitner2016-03-311-50/+5
| | | | | | | | | 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. Differential Revision: https://phabricator.haskell.org/D2070
* Make warning names more consistentManav Rathi2016-02-251-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Replace "Sigs" with "Signatures" in WarningFlag data constructors. - Replace "PatSyn" with "PatternSynonym" in WarningFlag data constructors. - Deprecate "missing-local-sigs" in favor of "missing-local-signatures". - Deprecate "missing-exported-sigs" in favor of "missing-exported-signatures". - Deprecate "missing-pat-syn-signatures" in favor of "missing-pattern-synonym-signatures". - Replace "ddump-strsigs" with "ddump-str-signatures" These complete the tasks that were explicitly mentioned in #11583 Test Plan: Executed `ghc --show-options` and verified that the flags were changed as expected. Reviewers: svenpanne, austin, bgamari Reviewed By: austin, bgamari Subscribers: mpickering, thomie Differential Revision: https://phabricator.haskell.org/D1939 GHC Trac Issues: #11583
* Another batch of typo fixes in non-codeGabor Greif2016-02-111-1/+1
|
* Replace calls to `ptext . sLit` with `text`Jan Stolarek2016-01-181-4/+3
| | | | | | | | | | | | | | | | | | | | 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
* Make demand analysis understand catchSimon Peyton Jones2016-01-071-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As Trac #11222, and #10712 note, the strictness analyser needs to be rather careful about exceptions. Previously it treated them as identical to divergence, but that won't quite do. See Note [Exceptions and strictness] in Demand, which explains the deal. Getting more strictness in 'catch' and friends is a very good thing. Here is the nofib summary, keeping only the big ones. -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fasta -0.1% -6.9% -3.0% -3.0% +0.0% hpg -0.1% -2.0% -6.2% -6.2% +0.0% maillist -0.1% -0.3% 0.08 0.09 +1.2% reverse-complem -0.1% -10.9% -6.0% -5.9% +0.0% sphere -0.1% -4.3% 0.08 0.08 +0.0% x2n1 -0.1% -0.0% 0.00 0.00 +0.0% -------------------------------------------------------------------------------- Min -0.2% -10.9% -17.4% -17.3% +0.0% Max -0.0% +0.0% +4.3% +4.4% +1.2% Geometric Mean -0.1% -0.3% -2.9% -3.0% +0.0% On the way I did quite a bit of refactoring in Demand.hs
* Add kind equalities to GHC.Richard Eisenberg2015-12-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Typos in commentsSimon Peyton Jones2015-08-031-3/+3
|
* Fix Trac #10694: CPR analysisSimon Peyton Jones2015-07-301-21/+18
| | | | | | | | | | | In this commit commit 0696fc6d4de28cb589f6c751b8491911a5baf774 Author: Simon Peyton Jones <simonpj@microsoft.com> Date: Fri Jun 26 11:40:01 2015 +0100 I made an error in the is_var_scrut tests in extendEnvForProdAlt. This patch fixes it, thereby fixing Trac #10694.
* Improve strictness analysis for exceptionsSimon Peyton Jones2015-07-211-26/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two things here: * For exceptions-catching primops like catch#, we know that the main argument function will be called, so we can use strictApply1Dmd, rather than lazy Changes in primops.txt.pp * When a 'case' scrutinises a I/O-performing primop, the Note [IO hack in the demand analyser] was throwing away all strictness from the code that followed. I found that this was causing quite a bit of unnecessary reboxing in the (heavily used) function GHC.IO.Handle.Internals.wantReadableHandle So this patch prevents the hack applying when the case scrutinises a primop. See the revised Note [IO hack in the demand analyser] Thse two things buy us quite a lot in programs that do a lot of IO. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- hpg -0.4% -2.9% -0.9% -1.0% +0.0% reverse-complem -0.4% -10.9% +10.7% +10.9% +0.0% simple -0.3% -0.0% +26.2% +26.2% +3.7% sphere -0.3% -6.3% 0.09 0.09 +0.0% -------------------------------------------------------------------------------- Min -0.7% -10.9% -4.6% -4.7% -1.7% Max -0.2% +0.0% +26.2% +26.2% +6.5% Geometric Mean -0.4% -0.3% +2.1% +2.1% +0.1% I think the increase in runtime for 'simple' is measurement error.
* Improve CPR behavior for strict constructorsSimon Peyton Jones2015-06-261-76/+208
| | | | | | | | | | | | | | | | When working on Trac #10482 I noticed that we could give constructor arguments the CPR property if they are use strictly. This is documented carefully in Note [CPR in a product case alternative] and also Note [Initial CPR for strict binders] There are a bunch of intersting examples in Note [CPR examples] which I have added to the test suite as T10482a. I also added a test for #10482 itself.
* Fix addDataConStrictnessSimon Peyton Jones2015-06-261-11/+14
| | | | | | | | | | | | See Note [Add demands for strict constructors]. The new bit is the test for isAbsDmd in addDataConStrictness. There was a cryptic note that said that this function should add a seqDmd even for Absent arguments, but that is definitely a bad thing (as the Note now says), causing unused arguments to be passed to the worker. Easy fix!
* Wibble to DmdAnalSimon Peyton Jones2015-04-211-4/+4
| | | | | | | | This fixes a typo in d5773a4939b1feea51ec0db6624c9462751e948a Teach DmdAnal that coercions are value arguments! (Trac #10288) Sorry about that; I'm not sure how it slipped through.
* Support unboxing for GADT product typesSimon Peyton Jones2015-04-211-1/+4
| | | | | | | | | | | | Beofre this commit we never unboxed GADT, even if they are perfectly civilised products. This patch liberalises unboxing slightly. See Note [Product types] in TyCon. Still to come - for strictness, we could maybe deal with existentials too - todo: unboxing constructor arguments
* Teach DmdAnal about free coercion variablesSimon Peyton Jones2015-04-211-6/+11
| | | | | | | | | | | Coercion variables are used in casts and coercions, so the demand analyser should jolly well not regard them as absent! In fact this bug never makes a difference because even absent unboxed-coercion arguments are passed anyway; see WwLib.mk_abesnt_let, which returns Nothing for coercion Ids. But it was simply wrong before and that is never cool.
* Teach DmdAnal that coercions are value arguments!Simon Peyton Jones2015-04-201-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The demand analyser was treating coercion args like type args, which meant that the arguments in a strictness signature got out of step with the arguments of a call. Result chaos and disaster. Trac #10288 showed it up. It's hard to get this bug to show up in practice because - functions abstracted over coercions are usually abstracted over *boxed* coercions - we don't currently unbox a boxed-coercion arg because it's GADT (I see how to fix this too) But after floating, optimisation, and so on, Trac #10288 did get a function abstracted over an unboxed coercion, and then the -flate-dmd-anal pass went wrong. I don't think I can come up with a test case, but I don't think it matters too much. Still to come - Fix a second bug, namely that coercion variables are wrongly marked as absent because DmdAnal doesn't check the the free variables of casts. I think this never bites in practice (see the follow-up commit) - Make GADT products work with strictness analysis
* Zap usage info in CSE (Trac #10218)Simon Peyton Jones2015-04-141-2/+2
| | | | | | | | | | | | | | | | | Trac #10218 reports a subtle bug that turned out to be: - CSE invalidated the usage information computed by earlier demand analysis, by increasing sharing - that made a single-entry thunk into a multi-entry thunk - and with -feager-blackholing, that led to <<loop>> The patch fixes it by making the CSE pass zap usage information for let-bound identifiers. It can be restored by -flate-dmd-anal. (But making -flate-dmd-anal the default needs some careful work; see Trac #7782.)
* Typos in error messages and in commentsGabor Greif2015-04-101-1/+1
|
* Fix a long-standing bug in the demand analyserSimon Peyton Jones2015-04-071-84/+110
| | | | | | | | | | | | | | | | | | This patch fixes Trac #10148, an outright and egregious bug in the demand analyser. It is explained in Note [Demand on case-alternative binders] in Demand.hs. I did some other minor refactoring. To my astonishment I got some big compiler perf changes * perf/compiler/T5837: bytes allocated -76% * perf/compiler/T5030: bytes allocated -10% * perf/compiler/T3294: max bytes used -25% Happy days
* Replace .lhs with .hs in compiler commentsYuri de Wit2015-02-091-1/+1
| | | | | | | | | | | | | | Summary: It looks like during .lhs -> .hs switch the comments were not updated. So doing exactly that. Reviewers: austin, jstolarek, hvr, goldfire Reviewed By: austin, jstolarek Subscribers: thomie, goldfire Differential Revision: https://phabricator.haskell.org/D621 GHC Trac Issues: #9986
* unlit compiler/stranal/ modulesHerbert Valerio Riedel2014-12-011-0/+1186
Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D541