Giter VIP home page Giter VIP logo

Comments (3)

timholy avatar timholy commented on July 17, 2024

xref #92

I generally suspect the @code_typed is more reliable, but I'm not sure even that's always true.

from cthulhu.jl.

cafaxo avatar cafaxo commented on July 17, 2024

Thanks. I have another (unrelated?) question:

After running

julia> @noinline function f(x...)
       return x
       end;

julia> g(x) = f(x, 1);

julia> g(1)
(1, 1)

I get

julia> methods(f).ms[1].specializations
svec(MethodInstance for f(::Int64, ::Int64), #undef, #undef, #undef, #undef, #undef, #undef, MethodInstance for f(::Int64, ::Vararg{Int64}))

Why is the specialization f(::Int64, ::Int64) created?

from cthulhu.jl.

timholy avatar timholy commented on July 17, 2024

Great question, I've been (and sometimes still am) confused about the same thing. The short answer is that specialization of inference is distinct from specialization of codegen.

julia> @noinline function f(x...)
       return x
       end;

julia> g(x) = f(x, 1);

julia> g(1)
(1, 1)

julia> using MethodAnalysis

julia> mis = methodinstances(f)
2-element Vector{Core.MethodInstance}:
 MethodInstance for f(::Int64, ::Int64)
 MethodInstance for f(::Int64, ::Vararg{Int64, N} where N)

julia> mis[1].cache.specptr
Ptr{Nothing} @0x0000000000000000

julia> mis[2].cache.specptr
Ptr{Nothing} @0x00007f007fe42e10

It's the second one which actually runs. But it's been decided (and I generally agree) that it's useful for callers who know more about their argument types to be able to infer the return type. It also can help link, e.g., the callee of a do block to the method in which it's defined (why that might be important: https://julialang.org/blog/2021/01/precompile_tutorial/). You can generally use Base.inferencebarrier(arg) in the caller when you want to prevent even inference-specialization of the callee.

from cthulhu.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.