GithubHelp home page GithubHelp logo

Comments (3)

JeffBezanson avatar JeffBezanson commented on September 18, 2024

A workaround for now is to add extra methods to cause specialization, e.g.

f(args...) = # actual code

f(a) = invoke(f, Tuple{Vararg{Any}}, a,)
f(a, b) = invoke(f, Tuple{Vararg{Any}}, a, b)
f(a, b, c) = invoke(f, Tuple{Vararg{Any}}, a, b, c)
...

from cassette.jl.

jrevels avatar jrevels commented on September 18, 2024

Thanks, trying this out now. Two questions:

  1. How does this workaround interact with inlining? Can things get inlined through invoke or is invoke a de facto inline barrier? From some cursory exploration, it looks like invoke is not an inline barrier. Cassette forcibly inlines a lot of stuff, with the hopes that eventual no-op transformations are elided in generated code (in many use cases, "most" of Cassette's transformations end up being no-ops/pass-throughs).

  2. It seems that I'm running into a cycle when implementing this workaround for one of Cassette's callable structs. Here's a MWE:

julia> struct Foo{X,F}
           x::X
           f::F
       end

julia> (foo::Foo{Int})(args...) = foo.f(args...)

julia> (foo::Foo{Int})(x) = invoke(foo, Tuple{Vararg{Any}}, x)

julia> Foo(1, sin)(1)
ERROR: StackOverflowError:
Stacktrace:
 [1] (::Foo{Int64,typeof(sin)})(::Int64) at ./REPL[3]:0
 [2] (::Foo{Int64,typeof(sin)})(::Int64) at ./REPL[3]:1 (repeats 26666 times)

EDIT: Furthermore:

julia> struct Foo{F}
           x
           f::F
       end

julia> (foo::Foo)(args...) = foo.f(args...)

julia> (foo::Foo)(a) = invoke(foo, Tuple{Vararg{Any}}, a)

julia> @code_typed Foo(1, sin)(1)^C

julia> Foo(1, sin)(1)
[1]    52977 segmentation fault  julia7

Weirdly, the bug goes away if we get rid of the x field, but that field is actually necessary in the real code. What should I be doing here instead?

from cassette.jl.

jrevels avatar jrevels commented on September 18, 2024

closed by #41

from cassette.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.