Skip to content

--trace-compile incorrectly reports only-inferred methods as being re-compiled #56155

@topolarity

Description

@topolarity

There are times (such as when inlining) when Julia will create a CodeInstance that has no code associated with it.

For example:

using Base.Filesystem: contractuser
mi = methods(contractuser, (String,))[1].specializations::Base.MethodInstance

println("world range: ", (mi.cache.min_world, mi.cache.max_world))
println("invoke, specptr: ", (mi.cache.invoke, mi.cache.specptr))
println("next?: ", (isdefined(mi.cache, :next)))

println(contractuser("")) # trigger compilation

println("world range: ", (mi.cache.min_world, mi.cache.max_world))
println("invoke, specptr: ", (mi.cache.invoke, mi.cache.specptr))
println("next?: ", (isdefined(mi.cache, :next)))

This outputs:

world range: (0x0000000000003f84, 0xffffffffffffffff)
invoke, specptr: (Ptr{Nothing}(0x0000000000000000), Ptr{Nothing}(0x0000000000000000))
next?: false

world range: (0x0000000000003f84, 0xffffffffffffffff)
invoke, specptr: (Ptr{Nothing}(0x00007f6f10b09680), Ptr{Nothing}(0x00007f6f10b09590))
next?: false

which shows that contractuser(::String) was never invalidated (and in fact only has one CodeInstance). It just never had any code associated with it because it was only inferred and then inlined.

However if you run with --trace-compile=compile.log you'll see:

...
precompile(Tuple{typeof(Base.Filesystem.contractuser), String}) # recompile
...

You can see we reported precompile(Tuple{typeof(Base.Filesystem.contractuser), String}) # recompile

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorobservabilitymetrics, timing, understandability, reflection, logging, ...

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions