Skip to content

Commit fc2db3f

Browse files
authored
Merge pull request #38519 from JuliaLang/sds/partially_inline_return_node
fix Meta.partially_inline! for ReturnNode and GotoIfNot
2 parents 5f55740 + 5482caf commit fc2db3f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

base/meta.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
344344
x.edges .+= slot_offset
345345
return x
346346
end
347+
if isa(x, Core.ReturnNode)
348+
return Core.ReturnNode(
349+
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
350+
slot_offset, statement_offset, boundscheck),
351+
)
352+
end
353+
if isa(x, Core.GotoIfNot)
354+
return Core.GotoIfNot(
355+
_partially_inline!(x.cond, slot_replacements, type_signature, static_param_values,
356+
slot_offset, statement_offset, boundscheck),
357+
x.dest,
358+
)
359+
end
347360
if isa(x, Expr)
348361
head = x.head
349362
if head === :static_parameter

test/meta.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,13 @@ macro m() 2 end
233233
end
234234

235235
@test _lower(TestExpandInWorldModule, :(@m), TestExpandInWorldModule.wa) == 1
236+
237+
f(::T) where {T} = T
238+
ci = code_lowered(f, Tuple{Int})[1]
239+
@test Meta.partially_inline!(ci.code, [], Tuple{typeof(f),Int}, Any[Int], 0, 0, :propagate) ==
240+
Any[Core.ReturnNode(QuoteNode(Int))]
241+
242+
g(::Val{x}) where {x} = x ? 1 : 0
243+
ci = code_lowered(g, Tuple{Val{true}})[1]
244+
@test Meta.partially_inline!(ci.code, [], Tuple{typeof(g),Val{true}}, Any[Val{true}], 0, 0, :propagate)[1] ==
245+
Core.GotoIfNot(QuoteNode(Val{true}), 3)

0 commit comments

Comments
 (0)