Skip to content

Commit 6532aa4

Browse files
committed
Update instructions for code inspection
1 parent cf586d7 commit 6532aa4

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

CONTRIBUTING.md

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,76 @@ cpp-options: -DBENCH_containers_Map -DBENCH_containers_IntMap -DBENCH_hashmap_Ma
6262

6363
## Inspecting the generated code
6464

65-
The library section in `unordered-containers.cabal` contains a commented-out set of `ghc-options` for
66-
dumping Core and other forms of generated code. To dump this code, uncomment these options and run
65+
The file `cabal.project.local.dump-code` contains `ghc-options` for dumping Core and
66+
other forms of generated code. To generate these dump files, run
6767

6868
```
69+
cp cabal.project.local.dump-code cabal.project.local
6970
cabal clean
70-
cabal build
71+
cabal build benches tests
72+
```
73+
74+
You can find the resulting `.dump-*` files in `dist-newstyle/build/*/*/unordered-containers-*/`, e.g.
75+
76+
```
77+
$ tree dist-newstyle/build/*/*/unordered-containers-*/
78+
dist-newstyle/build/x86_64-linux/ghc-9.12.2/unordered-containers-0.2.20.1/
79+
├── b
80+
│   ├── fine-grained
81+
│   │   ├── build
82+
│   │   │   └── fine-grained
83+
│   │   │   ├── autogen
84+
│   │   │   │   ├── cabal_macros.h
85+
│   │   │   │   ├── PackageInfo_unordered_containers.hs
86+
│   │   │   │   └── Paths_unordered_containers.hs
87+
│   │   │   ├── fine-grained
88+
│   │   │   └── fine-grained-tmp
89+
│   │   │   ├── benchmarks
90+
│   │   │   │   ├── FineGrained.dump-asm
91+
│   │   │   │   ├── FineGrained.dump-cmm
92+
│   │   │   │   ├── FineGrained.dump-prep
93+
│   │   │   │   ├── FineGrained.dump-simpl
94+
...
7195
```
7296

73-
You can find the resulting `.dump-*` files in `dist-newstyle/build/**/unordered-containers-*/build/`, e.g.
97+
To visually compare the generated code from two different states of the source tree,
98+
you can copy the `dist-newstyle/build/*/*/unordered-containers-*/` directory from
99+
each state to separate directories and then use a diff tool like
100+
[Meld](https://meldmerge.org/) to compare them:
74101

75102
```
76-
$ tree dist-newstyle/build/x86_64-linux/ghc-9.2.2/unordered-containers-0.2.16.0/build/
77-
dist-newstyle/build/x86_64-linux/ghc-9.2.2/unordered-containers-0.2.16.0/build/
78-
├── Data
79-
│   ├── HashMap
80-
│   │   ├── Internal
81-
│   │   │   ├── Array.dump-asm
82-
│   │   │   ├── Array.dump-cmm
83-
│   │   │   ├── Array.dump-simpl
84-
│   │   │   ├── Array.dump-stg-final
85-
...
103+
cabal clean
104+
cabal build benches tests
105+
mkdir dump-$(git rev-parse HEAD)
106+
cp -r dist-newstyle/build/*/*/unordered-containers-*/ dump-$(git rev-parse HEAD)
107+
# Repeat at different commit
108+
meld dump-*
109+
```
110+
111+
Because the files with the generated code are so large, it can be helpful to
112+
temporarily add a small "playground module" to the library:
113+
114+
In `unordered-containers`:
115+
116+
```diff
117+
library:
118+
exposed-modules:
119+
...
120+
Data.HashSet
121+
Data.HashSet.Internal
122+
+ Playground
86123
```
87124

88-
To visually compare the generated code from two different states of the source tree, you can copy
89-
the `dist-newstyle/build/**/unordered-containers-*/build/` directory from each state to two
90-
directories `a` and `b` and then use a diff tool like [Meld](https://meldmerge.org/) to compare
91-
them:
125+
`Playground.hs`:
92126

93127
```
94-
meld a/ b/
128+
{-# language TypeApplications #-}
129+
module Playground where
130+
131+
import qualified Data.HashMap.Internal as HMI
132+
import qualified Data.HashMap.Strict as HS
133+
134+
f = HS.union @String
95135
```
96136

97137
### References

cabal.project.local.dump-code

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package unordered-containers
2+
ghc-options: -ddump-simpl
3+
ghc-options: -ddump-prep
4+
ghc-options: -ddump-cmm
5+
ghc-options: -ddump-asm
6+
ghc-options: -dsuppress-coercions
7+
ghc-options: -dsuppress-unfoldings
8+
ghc-options: -dsuppress-module-prefixes
9+
ghc-options: -dsuppress-uniques
10+
ghc-options: -dsuppress-timestamps
11+
ghc-options: -ddump-to-file

unordered-containers.cabal

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ library
7373

7474
ghc-options: -Wall -O2 -fwarn-tabs -ferror-spans
7575

76-
-- For dumping the generated code:
77-
-- ghc-options: -ddump-simpl -ddump-stg-final -ddump-cmm -ddump-asm -ddump-to-file
78-
-- ghc-options: -dsuppress-coercions -dsuppress-unfoldings -dsuppress-module-prefixes
79-
-- ghc-options: -dsuppress-uniques -dsuppress-timestamps
80-
8176
if flag(debug)
8277
cpp-options: -DASSERTS
8378

0 commit comments

Comments
 (0)