Skip to content

Commit 5aa2d96

Browse files
authored
Allow more general macro calls (#104)
Fixes #103
1 parent 8c02260 commit 5aa2d96

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ checkname(fname::QuoteNode, name) = checkname(fname.value, name)
2828

2929
function isfuncexpr(ex, name=nothing)
3030
# Strip any macros that wrap the method definition
31-
while ex isa Expr && ex.head === :macrocall && length(ex.args) == 3
32-
ex = ex.args[3]
31+
while ex isa Expr && ex.head === :macrocall && length(ex.args) >= 3
32+
ex = ex.args[end]
3333
end
3434
isa(ex, Expr) || return false
3535
if ex.head === :function || ex.head === :(=)

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
169169
@test occursin("x^3", src)
170170
@test line == 52
171171

172+
# Issue #103
173+
if isdefined(Base, Symbol("@assume_effects"))
174+
m = only(methods(pow103))
175+
src, line = definition(String, m)
176+
@test occursin("res *= x", src)
177+
@test line == 57
178+
end
179+
172180
# Invalidation-insulating methods used by Revise and perhaps others
173181
d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}()
174182
CodeTracking.invoked_setindex!(d, sin, "sin")

test/script.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ end
5050

5151
# Issue #80
5252
f80 = x -> 2 * x^3 + 1
53+
54+
# Issue #103
55+
if isdefined(Base, Symbol("@assume_effects"))
56+
@eval begin
57+
Base.@assume_effects :terminates_locally function pow103(x)
58+
# this :terminates_locally allows `pow` to be constant-folded
59+
res = 1
60+
1 < x < 20 || error("bad pow")
61+
while x > 1
62+
res *= x
63+
x -= 1
64+
end
65+
return res
66+
end
67+
end
68+
end

0 commit comments

Comments
 (0)