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
This PR makes `lines_required!`'s `norequire` logic more configurable.
That means the `exclude_named_typedefs` option is now got abstracted,
and each consumer can implement its own strategy to escape from the
required statement completion by control flow traversal.
The motivation for this change is we usually want to respect a control
flow in general context, but some consumer may not want that.
Especially, JET doesn't want to interpret all the statements within a
`try/catch` block, but just select those involved with a method
definition.
(issue: <aviatesk/JET.jl#150>)
For example, `lines_required!` selects statements in the snippet below
as JET expects:
```julia
for fname in (:foo, :bar, :baz)
@eval begin
@inline ($(Symbol("is", fname)))(a) = a === $(QuoteNode(fname))
end
end
```
, but in the example below, `lines_required` selects "too much"
statements and we need a customized `norequire`:
```julia
try
foo(a) = sum(a) # should be selected (selected initially)
foo("julia") # shouldn't be selected, but `lines_required` will
select this
catch err
err # shouldn't be selected, but `lines_required` will select this
end
```
Here is an example usage of this customizable `norequire` logic:
<aviatesk/JET.jl#152>
---
One downside of this change is that now we need to performa the basic
block traversal twice when using `norequire =
exclude_named_typedefs(src, edges)`.
As far as I confirmed, this computation would never be a performance
bottleneck, and thus this change hopefully won't hurt the performance.
I tried to profile the time with the following snippet:
```julia
function select_statements(n, src)
for _ in 1:n
stmts = src.code
isrq = rand(Bool, length(stmts))
edges = CodeEdges(src)
norequire = LoweredCodeUtils.exclude_named_typedefs(src, edges)
lines_required!(isrq, src, edges, norequire)
end
end
src = code_lowered(...)
@profiler select_statements(100, src)
```
isrequired =minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; exclude_named_typedefs=true) # initially mark only the constructor
265
+
isrequired =minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt),false), src, edges,exclude_named_typedefs(src, edges)) # initially mark only the constructor
0 commit comments