Skip to content

Commit 8fdfd47

Browse files
committed
JuliaStaging/GeneralizedGenerated.jl#21 : support some macrocalls' expanded forms
1 parent 1cd7220 commit 8fdfd47

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/JuliaVariables.jl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ end
101101

102102
rmlines(a) = a
103103

104+
function no_ana(ex)
105+
@match ex begin
106+
# inline
107+
Expr(:meta, _...) ||
108+
# @label, @goto
109+
Expr(:symboliclabel, _...) ||
110+
Expr(:symbolicgoto, _...) ||
111+
# @inbounds
112+
Expr(:inbounds, _...) ||
113+
# @generated
114+
Expr(:generated, _...) ||
115+
# @ boundscheck
116+
Expr(:boundscheck, _...) ||
117+
# @locals
118+
Expr(:locals) => true
119+
_ => false
120+
end
121+
end
122+
104123
function quick_lambda(ex)
105124
@when Expr(:call, args...) && if any(==(:_), args) end = ex begin
106125
quick_arg = gensym("quick_arg")
@@ -189,7 +208,8 @@ function solve(ana, sym :: Symbol, ctx_flag::CtxFlag)
189208
ScopedVar(ana.solved, sym)
190209
end
191210

192-
function solve(ana, ex, ctx_flag::CtxFlag = CtxFlag())
211+
function solve(ana, ex::Expr, ctx_flag::CtxFlag)
212+
no_ana(ex) && return ex
193213
@match ex begin
194214
# give up analysing macrocall expressions.
195215
Expr(:macrocall, _...) => ex
@@ -341,10 +361,17 @@ function solve(ana, ex, ctx_flag::CtxFlag = CtxFlag())
341361
args = map(solve(ana, _, ctx_flag), args)
342362
Expr(hd, args...)
343363
end
344-
a => a
345364
end
346365
end
347366

367+
function solve(ana, ex, ctx_flag::CtxFlag)
368+
ex
369+
end
370+
371+
function solve(ana, ex)
372+
solve(ana, ex, CtxFlag())
373+
end
374+
348375
function solve(ex)
349376
ana = top_analyzer()
350377
ex = solve(ana, ex)

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,16 @@ JuliaVariables.@quick_lambda begin
9494
@test haskey(func.scope.bounds, :z)
9595
@test func.scope.bounds[:z].is_mutable.x
9696

97+
98+
func = solve(macroexpand(@__MODULE__, :(@inline function (x)
99+
z = x + 1
100+
@inline function (y)
101+
z += 1
102+
z
103+
end
104+
end)))
105+
println(func |> rmlines)
106+
107+
97108
end
98109
end

0 commit comments

Comments
 (0)