From 73033373b94b3d4be1896e89ef9a0575c5bf97c9 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Thu, 12 Dec 2024 13:26:45 +0000 Subject: [PATCH] Miscellaneous `Meta.partially_inline!` fixes I'm not a big fan of this pass, or the way it's written. At a minimum, I'd expect both better test coverage (when we write similar passes for the core Compiler, we get away with weak test coverage by relying on user code) and a re-factor to make this switch exhaustive (it should error if unexpected IR elements are encountered, instead of just performing an incorrect transformation) This doesn't make progress on those issues for now, but it at least fixes up a couple of conspicuous problems I noticed when reviewing #56787 --- base/meta.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/base/meta.jl b/base/meta.jl index 0078e15bcd98b..eaeefce211604 100644 --- a/base/meta.jl +++ b/base/meta.jl @@ -362,6 +362,19 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any}, x.edges .+= slot_offset return x end + if isa(x, Core.UpsilonNode) + if !isdefined(x, :val) + return x + end + return Core.UpsilonNode( + _partially_inline!(x.val, slot_replacements, type_signature, static_param_values, + slot_offset, statement_offset, boundscheck), + ) + end + if isa(x, Core.PhiCNode) + _partially_inline!(x.values, slot_replacements, type_signature, static_param_values, + slot_offset, statement_offset, boundscheck) + end if isa(x, Core.ReturnNode) # Unreachable doesn't have val defined if !isdefined(x, :val) @@ -381,6 +394,9 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any}, ) end if isa(x, Core.EnterNode) + if x.catch_dest == 0 + return x + end return Core.EnterNode(x, x.catch_dest + statement_offset) end if isa(x, Expr)