Skip to content

Commit

Permalink
Fix partially_inline for unreachable (#56787)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Dec 12, 2024
1 parent 48be7ca commit 9118ea7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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(
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

0 comments on commit 9118ea7

Please sign in to comment.