Running `reload` twice, or simply replacing `reload` with `include`, gives
the expected behavior.
If you look at `@code_typed m2.f(d)` before and after the second `reload`,
you will see that after the second `reload`, `m2.f(d)` is actually closing
over `d`:
start:
julia @code_lowered m2.f(d)
1-element Array{Any,1}:
:($(Expr(:lambda, {:d}, {{},{{:d,Dict{Symbol,T},1}},{}}, :(begin #
/home/juser/test.jl, line 19:
$(Expr(:method, :((top(getfield))(Base,:getindex)),
:((top(tuple))((top(tuple))(Symbol,(top(apply_type))(Vararg,Any)),(top(tuple))())),
AST(:($(Expr(:lambda, {:s,:(args::(top(apply_type))(Vararg,Any))},
{{},{{:s,Any,0},{:args,Any,0}},{{:d,Dict{Symbol,T},1}}}, :(begin #
/home/juser/test.jl, line 19:
return (top(getfield))(getindex(d,s),:i)
end))) # line 20:
return println(getindex(:s))
end
after second reload:
1-element Array{Any,1}:
:($(Expr(:lambda, {:d},
{{:_var0,:_var1},{{:d,Dict{Symbol,T},1},{:_var0,(Int64,),0},{:_var1,Int64,18}},{}},
:(begin # /home/juser/test.jl, line 19:
$(Expr(:method, :((top(getfield))(Base,:getindex)),
:((top(tuple))((top(tuple))(Symbol,(top(apply_type))(Vararg,Any)),(top(tuple))())),
AST(:($(Expr(:lambda, {:s,:(args::(top(apply_type))(Vararg,Any))},
{{},{{:s,Any,0},{:args,Any,0}},{{:d,Dict{Symbol,T},1}}}, :(begin #
/home/juser/test.jl, line 19:
return (top(getfield))(getindex(d,s),:i)
end))) # line 20:
_var1 = getindex(:s)::Int64
return println(GetfieldNode(Base,:STDOUT,Any),_var1::Int64)
end
I'm not entirely sure why this is the case, but I never use reload as I've
found it to be too quirky.
You may be interested in https://github.com/malmaud/Autoreload.jl (note
that it does not in fact use the built-in `reload` at all, probably for
this reason! rather it uses `include`).
ps: this seems like a sort of odd thing to do, but I'll just trust you know
what you are doing :)