Skip to content

Overloading all functions #60

Open
@MilesCranmer

Description

@MilesCranmer

@aviatesk

I'm trying to move BorrowChecker.jl to use this over Cassette.jl but am having some difficulties figuring out how to do generic overlay passes where I overlay behavior on all functions that get hit.

Here's my current attempt, from studying the code:

using CassetteOverlay
using CassetteOverlay: CassetteOverlayGenerator
using Test

@MethodTable AllMethods

pass = @overlaypass AllMethods
# ^Just to initialize the object

_sin(x) = sin(x)

# Now, we attempt to do a generic override of it:
@eval function (p::typeof(pass))(f, args...)
    $(Expr(:meta, :generated, CassetteOverlayGenerator(:pass, :fargs)))
    println("Hello from ", f, " with args: ", args)
    return f(args...)
end

pass(() -> _sin(0.5));

This prints:

Hello from #2 with args: ()

So it seems this captures the first function (the closure), but the f(args...) does not hit the same overlay pass again.

Another thing I tried was

@overlay AllMethods (f::Function)(args...) = ...

but faced similar issues.

How can I do this? I basically want to overload all functions matching a specific signature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions