Skip to content

Commit

Permalink
also optimize getproperty where first argument is a constant module
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Nov 14, 2022
1 parent b25deb4 commit b174be3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ function lookup_global_refs!(ex::Expr)
return nothing
end

function lookup_getproperties(a::Expr)
if a.head === :call && length(a.args) == 3 &&
a.args[1] isa QuoteNode && a.args[1].value === Base.getproperty &&
a.args[2] isa QuoteNode && a.args[2].value isa Module &&
a.args[3] isa QuoteNode && a.args[3].value isa Symbol
return lookup_global_ref(Core.GlobalRef(a.args[2].value, a.args[3].value))
end
return a
end

"""
optimize!(code::CodeInfo, mod::Module)
Expand Down Expand Up @@ -161,6 +171,7 @@ function optimize!(code::CodeInfo, scope)
continue
else
lookup_global_refs!(stmt)
code.code[i] = lookup_getproperties(stmt)
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,17 @@ end
@interpret FunctionWrapper{Int,Tuple{}}(()->42)
end

@testset "issue #550" begin
using FunctionWrappers:FunctionWrapper
f = (obs) -> (obs[1] = obs[3] * obs[4]; obs)
Tout = Vector{Int}
Tin = Tuple{Vector{Int}}
fw = FunctionWrapper{Tout, Tin}(f)

obs = [0,2,3,4]
@test @interpret(fw(obs)) == fw(obs)
end

@testset "TypedSlots" begin
function foo(x, y)
z = x + y
Expand Down

0 comments on commit b174be3

Please sign in to comment.