FluxML / FluxML/IRTools.jl

UndefVarError when referring to struct in closure dynamo

Open
#51 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
113
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Basically I can write:
```
module ClosureScratch

using IRTools
using IRTools: IR, @dynamo

mutable struct Counter
count::Int
end

@dynamo function (c::Counter)(m...)
ir = IR(m...)
for (v, st) in ir
c.count += 1
end
return ir
end

function foo(x::Int)
y = x + 5
return y
end

c = Counter(1)

c() do
foo(5)
end

println(@code_ir c foo(5))
println(c)

end #module
```
and this will work, you can refer to c inside @dynamo.

But if I define the dynamo elsewhere in the library, I run into issues...
```
ERROR: LoadError: Error compiling @dynamo Main.TraceTransform.Jaynes.Trace on (Main.TraceTransform.var"#1#2",):
UndefVarError: tr not defined
```
where I've defined a dynamo inside my library as
```
@dynamo function (tr::Trace)(m...)
ir = IR(m...)
println(tr)
ir == nothing && return
recurse!(ir)
return ir
end
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.