Skip to content

Fix partially_inline for unreachable #56787

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

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,15 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
return x
end
if isa(x, Core.ReturnNode)
# Unreachable doesn't have val defined
if !isdefined(x, :val)
return x
else
return Core.ReturnNode(
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
slot_offset, statement_offset, boundscheck),
)
end
end
if isa(x, Core.GotoIfNot)
return Core.GotoIfNot(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but it looks like the code a few lines down also does not handle EnterNodes with catch_dest == 0 correctly.

Also it looks like it's missing handling for PhiCNode and UpsilonNode in general. The doc-comment suggests that's because this is for pre-type-inference IR, but I thought we didn't have PhiNodes in that either so I'm not really sure what IR this code is trying to support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reasonable, though unfortunately knowing how to handle that is a bit out of my depth =/. I found this while working on EnzymeAD/Reactant.jl#364 (which if you have availability, I'd love comment/review on ... especially since apparently I segfault julia). Where...we do use a variant of this function for post inference IR (and I'm not sure what else to use).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down
5 changes: 5 additions & 0 deletions test/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ ci = code_lowered(g, Tuple{Val{true}})[1]
@test Meta.partially_inline!(copy(ci.code), Any[isdefined_globalref, 1], Tuple{typeof(isdefined_globalref), Int},
[], 0, 0, :propagate)[1] == Expr(:isdefined, GlobalRef(Base, :foo))

withunreachable(s::String) = sin(s)
ci = code_lowered(withunreachable, Tuple{String})[1]
ci.code[end] = Core.ReturnNode()
@test Meta.partially_inline!(copy(ci.code), Any[withunreachable, "foo"], Tuple{typeof(withunreachable), String},
[], 0, 0, :propagate)[end] == Core.ReturnNode()
end

@testset "Base.Meta docstrings" begin
Expand Down
Loading