Skip to content

Code not inferrable in reported min_world #58143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
topolarity opened this issue Apr 16, 2025 · 0 comments
Open

Code not inferrable in reported min_world #58143

topolarity opened this issue Apr 16, 2025 · 0 comments

Comments

@topolarity
Copy link
Member

topolarity commented Apr 16, 2025

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)

topolarity added a commit that referenced this issue Apr 16, 2025
topolarity added a commit that referenced this issue May 1, 2025
topolarity added a commit that referenced this issue May 5, 2025
charleskawczynski pushed a commit to charleskawczynski/julia that referenced this issue May 12, 2025
charleskawczynski pushed a commit to charleskawczynski/julia that referenced this issue May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant