Skip to content

Code not inferrable in reported min_world #58143

@topolarity

Description

@topolarity

This CodeInstance claims it was valid in 0xa7:

julia> tt = Tuple{Base.var"#String##0#String##1"{LazyString}, IOBuffer}
julia> latest_world = Base.get_world_counter()
julia> m = only(Base._methods_by_ftype(tt , -1, latest_world)).method
julia> ci = m.specializations.cache
julia> ci.min_world
0x0000000000000af7

However, something goes wrong if we try to re-generate the code / inference:

julia> Base.code_typed_by_type(Tuple{Base.var"#String##0#String##1"{LazyString}, IOBuffer}; world=ci.min_world)
Any[]

This seems to be related to a bug I hit on #58014 where if we do type-inference on old worlds first (i.e. delete the reverse! on this line) then we get very incorrect inference results for this function in the sysimage:

julia> ccall(:jl_uncompress_ir, Any, (Any, Any, Any), m, ci, ci.inferred)
CodeInfo(
    @ strings/lazy.jl:84 within `#String##0`
1%1  =   builtin Core.getfield(#self#, :l)::LazyString
│  ┌ @ Base_compiler.jl:54 within `getproperty`
│  │ %2  =   builtin Base.getfield(%1, :parts)::Tuple
│  └
│  ┌ @ tuple.jl:74 within `iterate` @ tuple.jl:74
│  │┌ @ tuple.jl:28 within `length`
│  ││ %3  =   builtin Base.nfields(%2)::Int64
│  │└
│  │┌ @ int.jl:520 within `<=`
│  ││ %4  = intrinsic Base.sle_int(1, %3)::Bool
└──││       goto #2
   │└
2 ─│       goto #4 if not %4
   │┌ @ tuple.jl:33 within `getindex`
3 ─││ %7  = $(Expr(:boundscheck, true))::Bool
│  ││ %8  =   builtin Base.getfield(%2, 1, %7)::Any
│  │└
└──│       goto #5
4 ─│       goto #5
   │ @ tuple.jl:74 within `iterate`
5 ┄│ %11 = φ (#3 => false, #4 => true)::Bool
│  │ %12 = φ (#3 => %8)::Any
└──│       goto #66%14 = intrinsic Base.not_int(%11)::Bool
└──       goto #8 if not %14
    @ strings/lazy.jl:85 within `#String##0`
7 ─         dynamic Base.print(io, %12)::Union{}
└──       unreachable
8return nothing
)

In particular:

7 ─         dynamic Base.print(io, %12)::Union{}
└──       unreachable

this should be quickly invalidated (if it's even correct at all), but this CodeInstance is left valid indefinitely (and will SIGILL when executed in a new enough world)

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