EnzymeAD / Reactant.jl

MIT License
26 stars 2 forks source link

Track closures' captured variables #32

Closed mofeing closed 4 days ago

mofeing commented 1 week ago

From Julia documentation,

A closure is simply a callable object with field names corresponding to captured variables. For example, the following code:

function adder(x)
    return y->x+y
end

is lowered to (roughly):

struct ##1{T}
    x::T
end

(_::##1)(y) = _.x + y

function adder(x)
    return ##1(x)
end

It shouldn't be hard to add support for closures. We just need to correctly track the captured variables in Reactant.make_mlir_fn, right?

wsmoses commented 1 week ago

So we already handle it in make mlir fn, we just need to update the code which uses make mlir fn

On Wed, Jun 26, 2024, 6:06 AM Sergio Sánchez Ramírez < @.***> wrote:

From Julia documentation,

A closure is simply a callable object with field names corresponding to captured variables. For example, the following code:

function adder(x) return y->x+yend

is lowered to (roughly):

struct ##1{T} x::Tend

(::##1)(y) = .x + y function adder(x) return ##1(x)end

It shouldn't be hard to add support for closures. We just need to correctly track the captured variables in Reactant.make_mlir_fn, right?

— Reply to this email directly, view it on GitHub https://github.com/EnzymeAD/Reactant.jl/issues/32, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTUXBAV3YQPWEYEJ3565DZJI46HAVCNFSM6AAAAABJ5BJP7CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3TIMJVGYZTQMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>