You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/optanalysis.md
+54-1Lines changed: 54 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ JET implements such an analyzer that investigates the optimized representation o
27
27
anywhere the compiler failed in optimization. Especially, it can find where Julia creates captured variables, where
28
28
runtime dispatch will happen, and where Julia gives up the optimization work due to unresolvable recursive function call.
29
29
30
-
[SnoopCompile also detects inference failures](https://timholy.github.io/SnoopCompile.jl/stable/snoopi_deep_analysis/), but JET and SnoopCompile use different mechanisms: JET performs *static* analysis of a particular call, while SnoopCompile performs *dynamic* analysis of new inference. As a consequence, JET's detection of inference failures is reproducible (you can run the same analysis repeatedly and get the same result) but terminates at any non-inferable node of the call graph: you will miss runtime dispatch in any non-inferable callees. Conversely, SnoopCompile's detection of inference failures can explore the entire callgraph, but only for those portions that have not been previously inferred, and the analysis cannot be repeated in the same session.
30
+
[SnoopCompile also detects inference failures](https://timholy.github.io/SnoopCompile.jl/stable/tutorials/snoop_inference_analysis/), but JET and SnoopCompile use different mechanisms: JET performs *static* analysis of a particular call, while SnoopCompile performs *dynamic* analysis of new inference. As a consequence, JET's detection of inference failures is reproducible (you can run the same analysis repeatedly and get the same result) but terminates at any non-inferable node of the call graph: you will miss runtime dispatch in any non-inferable callees. Conversely, SnoopCompile's detection of inference failures can explore the entire callgraph, but only for those portions that have not been previously inferred, and the analysis cannot be repeated in the same session.
31
31
32
32
## [Quick Start](@id optanalysis-quick-start)
33
33
@@ -164,6 +164,59 @@ using Test
164
164
end
165
165
```
166
166
167
+
## [Integration with Cthulhu](@id cthulhu-integration)
168
+
169
+
If you identify inference problems, you may want to fix them. Cthulhu can be a useful tool for gaining more insight, and JET integrates nicely with Cthulhu.
170
+
171
+
To exploit Cthulhu, you first need to split the overall report into individual inference failures:
172
+
173
+
```@repl quickstart
174
+
report = @report_opt sumup(sin);
175
+
rpts = JET.get_reports(report)
176
+
```
177
+
178
+
!!! tip
179
+
If `rpts` is a long list, consider using `urpts = unique(reportkey, rpts)` to trim it.
180
+
See [`reportkey`](@ref).
181
+
182
+
Now you can `ascend` individual reports:
183
+
184
+
```
185
+
julia> using Cthulhu
186
+
187
+
julia> ascend(rpts[1])
188
+
Choose a call for analysis (q to quit):
189
+
runtime dispatch to make_vals(%1::Any)::Any
190
+
> sumup(::typeof(sin))
191
+
192
+
Open an editor at a possible caller of
193
+
Tuple{typeof(make_vals), Any}
194
+
or browse typed code:
195
+
> "REPL[7]", sumup: lines [4]
196
+
Browse typed code
197
+
```
198
+
199
+
`ascend` will show the full call-chain to reach a particular runtime dispatch; in this case, it was our entry point, but in other cases it may be deeper in the call graph. In this case, we've interactively moved the selector `>` down to the `sumup` call (you cannot descend into the `"runtime dispatch to..."` as there is no known code associated with it) and hit `<Enter>`, at which point Cthulhu showed us that the call to `make_vals(::Any)` occured only on line 4 of the definition of `sumup` (which we entered at the REPL). Cthulhu is now prompting us to either open the code in an editor (which will fail in this case, since there is no associated file!) or view the type-annoted code. If we select the "Browse typed code" option we see
200
+
201
+
```
202
+
sumup(f) @ Main REPL[7]:1
203
+
1 function sumup(f::Core.Const(sin))::Any
204
+
2 # this function uses the non-constant global variable `n` here
205
+
3 # and it makes every succeeding operations type-unstable
0 commit comments