on 63aae12 help sign in
streamly/docs/Developer/Contributing.md
271 lines 11 kB history raw
1# Contributors' Guide
3## Bug Reports
5Please feel free to [open an
6issue](https://github.com/composewell/streamly/issues) for any questions,
7suggestions, issues or bugs in the library. In case you are reporting a bug
8we will appreciate if you provide as much detail as possible to reproduce or
9understand the problem, but nevertheless you are encouraged to open an issue
10for any problem that you may encounter.
12## Picking Issues to Work on
14Beginners are encouraged to pick up issues that are marked `help wanted`. It is
15a good idea to update the issue expressing your intent so that others do not
16duplicate the effort and people with a background on the issue can help.
18## Build and test
20Some common commands:
22```
23$ cabal repl
24$ cabal build
25$ cabal build --disable-optimization --flags -opt
26$ bin/test.sh --quick
27$ bin/bench.sh --quick # For nix use "--use-nix"
28$ bin/run-ci --targets help # Only supported with nix
29$ cabal haddock
30$ cabal-docspec --timeout 60 --check-properties --property-variables xs
31```
33The `bin/test.sh` and `bin/bench.sh` are custom scripts to perform test
34and benchmarking tasks conveniently. They support running a group of
35tests or benchmarks, coverage, using correct optimization flags for
36benchmarking, benchmark comparison reports etc. Use the `--help` option
37to see how to use these. See [benchmark/README.md](/docs/Developer/Benchmarks.md)
38and [test/README.md](/docs/Developer/Tests.md) for more details.
40You can also run tests or benchmarks directly for example:
42```
43$ cabal test --disable-optimization --flags -opt --test-show-details=streaming --test-option=--color streamly-tests
44```
46To view haddock docs open the link printed at the end of the haddock
47command, in your browser.
49Nix users: There is a `default.nix` available which can be used to start
50a nix-shell and then use the above commands as usual. nix-shell started
51by `default.nix` creates a `.cabal.nix` for cabal configuration and sets
52`CABAL_DIR` environment variable to point to that. Therefore, `~/.cabal`
53would not be used.
55## Contributing A Change
57If the feature makes significant changes to design, we encourage you to open an
58issue as early as possible so that you do not have to redo much work because of
59changes in design decisions. However, if you are confident, you can still go
60ahead and take that risk as the maintainers are supposed to be reasonable
61people.
63### Pull Requests (PR)
65Please feel free to [send a pull
66request (PR)](https://github.com/composewell/streamly/pulls) whether it is a
67single letter typo fix or a complex change. We will accept any PR that makes a
68net positive change to the package. We encourage you to provide a complete,
69consistent change with test, documentation and benchmarks. You can contact the
70[maintainers](https://gitter.im/composewell/streamly) for any help or
71collaboration needed in that regard. However, if due to lack of time you are
72not able to complete the PR, you are still welcome to submit it, maintainers
73will try their best to actively contribute and pick up your change as long as
74the change is approved.
76### Pull Request (PR) Checklist
78Here is a quick checklist for a PR, for details please see the next section:
80* PR contains one logical changeset
81* Each commit in the PR consists of a logical change
82* Commits are rebased/squashed/fixup/reordered as needed
83* Stylistic changes to irrelevant parts of the code are separated in
84 independent commits.
85* Code is formatted as per the style of the file or that of other files
86* Compiler warnings are fixed
87* Reasonable hlint suggestions are accepted
88* Tests are added to cover the changed parts
89* All [tests](/test) pass
90* [Performance benchmarks](/benchmark) are added, where applicable
91* No significant regressions are reported by [performance benchmarks](/docs/Developer/Benchmarks.md)
92* Haddock documentation is added to user visible APIs and data types
93* [Docs](/docs) are updated if necessary.
94* [Changelog](/docs/User/ProjectRelated/Changelog.md) is updated if needed
95* The code conforms to the license, it is not stolen, credit is given,
96 copyright notices are retained, original license is included if needed.
98### Structuring Pull Requests
100__Lean PR:__ Please keep the reviewer in mind when sending pull
101requests. Use one PR for each logical changeset. A lean and thin
102PR with one independent logical change is more likely to be reviewed and
103merged quickly than a big monolithic PR with several unrelated changes.
105__PR Dependencies:__ If your change depends on an earlier PR you can
106create a branch from the old PR's branch, and raise a new PR targeting
107to merge into the old PR branch. Do not push the commits to the same PR
108just because the commit depends on that PR.
110__Commits:__ You are encouraged to group a logically related set of
111changes into a single commit. When the overall changeset is largish you
112can divide it into multiple smaller commits, with each commit having
113a logically grouped changeset and the title summarizing the logical
114grouping. Always keep in mind a logical division helps reviewers
115understand and review your code quickly, easier history tracking and
116when required clean reversal changes.
118__Functional Changes:__ Keep the reviewer in mind when making
119changes. Please resist the temptation to make style related changes to
120surrounding code unless you are changing that code anyway . Whenever
121possible, try to separate unrelated refactoring changes which do not
122affect functionality in separate commits so that it is easier for the
123reviewer to verify functional changes.
125__Style Changes:__ Make sure that your IDE/Editor is not automatically
126making sweeping style changes to all the files you are editing. That
127makes separating the signal from the noise very difficult and makes
128everything harder. If you would like to make style related changes
129then please send a separate PR with just those changes and no other
130functionality changes.
132__Rebasing:__ If your commits reflect how you fixed intermediate
133problems during testing or made random changes at different times you
134may have to squash your changes (`git rebase -i`) into a single commit
135or logically related set of commits.
137### Resolving Conflicts
139If during the course of development or before you send the PR you find that
140your changes are conflicting with the master branch then use `git rebase
141master` to rebase your changes on top of master. DO NOT MERGE MASTER INTO YOUR
142BRANCH.
144### Testing
146It is a good idea to include tests for the changes where applicable. See
147the existing tests in the [test](/test) directory. Also see the
148[test/README.md](/docs/Developer/Tests.md) for more details on how to run the tests.
150### Documentation
152For user visible APIs, it is a good idea to provide haddock documentation that
153is easily understood by the end programmer and does not sound highfalutin,
154and preferably with examples. If your change affects the tutorial or needs to
155be mentioned in the tutorial then please update the tutorial. Check if the
156additional [guides](/docs) are affected or need to updated.
158### Performance Benchmarks
160It is a good idea to run performance benchmarks to see if your change affects
161any of the existing performance benchmarks. If you introduced something new
162then you may want to add benchmarks to check if it performs as well as expected
163by the programmers to deem it usable.
165See the [README](/docs/Developer/Benchmarks.md) file in the `benchmark` directory for more
166details on how to run the benchmarks.
168The first level of check is the regression in "allocations", this is
169the most stable measure of regression. "bytesCopied" is another stable
170measure, it gives an idea of the amount of long lived data being copied
171across generations of GC.
173The next measure to look at is "cpuTime" this may have some variance
174from run to run because of factors like cpu frequency scaling, load on
175the system or the number of context switches etc. However, the variance
176would usually be within 5-10%, anything more than that is likely to be a
177red flag.
179Quite often an increase in "cpuTime" would correspond to an increase
180in "allocations". Increase in "allocations" indicates an inefficiency
181in computing due to too much GC activity e.g. due to lack of
182fusion. However, it is also possible for the cpu time to go up without
183the allocations going up, this indicates an inefficiency in processing
184in general or more CPU being used for the same task. It could be because
185of inefficient code generation, branch mis-predictions or lack of cache
186locality etc.
188For concurrent benchmarks we can compare "cpuTime" and "time" to check
189the degree of concurrency and total efficiency.
191### Changelog
193Any new changes that affect the user of the library in some way must be
194documented under `Unreleased` section at the top of the `Changelog`. The
195changes in the changelog must be organized in the following categories, in that
196order:
198* Breaking Changes
199* Enhancements
200* Bug Fixes
201* Deprecations
203If there are very few changes then you can just prefix a bullet with these
204annotations. If there are many changes make sections to group them. A section
205can be absent if there is nothing to add in it.
207If you make changes that are incompatible with the released versions
208of the library please indicate that in the `Changelog` as `Breaking Changes`
209and also write short notes regarding what the programmers need to do to adapt
210their existing code to the new change.
212### Licensing
214If you have copied code from elsewhere you need to conform to the
215licensing terms of the original code. Usually you would need to add a
216copyright notice in the source header, and include the license of the
217original code as per the terms of the license. If the code you are
218copying does not have an associated license please do not use it.
220## Developer documentation
222* Use https://streamly.composewell.com/ for searching in reference docs
223* Build haddock docs for latest reference docs
224* See [the dev directory](/docs/Developer) for design guidelines and dev documents.
226## Coding Guidelines
228### Coding Style
230Please see [the Haskell coding style guide](https://github.com/composewell/haskell-dev/blob/master/coding-style.rst).
232### Type variable ordering
234Ordering of variables in `forall` may be important in type applications. In
235streams, we usually declare them in this order `t m a`.
237Use the same order in constraints as well
239Example,
241```
242func :: forall m a. (MonadIO m, Storable a) => ...
243```
245### StreamD coding style
247Some conventions that we follow in the StreamD code are illustrated by the
248following example:
250```
251mapM f (Stream step1 state1) = Stream step state
252 where
254 step gst st = do
255 r <- step1 (adaptState gst) st
256 case r of
257 Yield x s -> f x >>= \a -> return $ Yield a s
258 Skip s -> return $ Skip s
259 Stop -> return Stop
260```
262* For the input streams use numbering for `step` and `state` e.g.
263 step1/state1. For the output stream use `step` and `state`.
264* For state argument of `step`, use `st`.
265* For result of executing a `step` use `r` or `res`
266* For the yielded element use `x`
267* For the yielded state use `s`
269In general, the rule is - the shorter the scope of a variable the shorter its
270name can be. For example, `s` has the shortest scope in the above code, `st`
271has a bigger scope and `state` has the biggest scope.