Skip to content

Commit c1e2760

Browse files
authored
Identify used SSAValues from within :struct_type Exprs (#30936)
1 parent baeebbc commit c1e2760

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

base/compiler/ssair/ir.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,26 @@ iterate(it::UseRefIterator) = (it.use[1].op = 0; iterate(it, nothing))
394394
end
395395
end
396396

397+
function scan_ssa_use_recursive!(push!, used, @nospecialize(a))
398+
if isa(a, SSAValue)
399+
push!(used, a.id)
400+
elseif isa(a, Expr)
401+
for aa in a.args
402+
scan_ssa_use_recursive!(push!, used, aa)
403+
end
404+
end
405+
return used
406+
end
407+
397408
# This function is used from the show code, which may have a different
398409
# `push!`/`used` type since it's in Base.
399410
function scan_ssa_use!(push!, used, @nospecialize(stmt))
400411
if isa(stmt, SSAValue)
401412
push!(used, stmt.id)
413+
elseif isexpr(stmt, :struct_type)
414+
for a in stmt.args
415+
scan_ssa_use_recursive!(push!, used, a)
416+
end
402417
end
403418
for useref in userefs(stmt)
404419
val = useref[]

test/compiler/ssair.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ let
8181
# XXX: missing @test
8282
end
8383

84+
let
85+
ex = quote
86+
function fouter(x)
87+
finner(::Float16) = 2x
88+
return finner(Float16(1))
89+
end
90+
end
91+
thunk1 = Meta.lower(Main, ex)
92+
thunk2 = thunk1.args[1].code[2]
93+
code = thunk2.args[1]
94+
used = BitSet()
95+
for stmt in code.code
96+
Compiler.scan_ssa_use!(push!, used, stmt)
97+
end
98+
@test !isempty(used)
99+
end
100+
84101
for compile in ("min", "yes")
85102
cmd = `$(Base.julia_cmd()) --compile=$compile interpreter_exec.jl`
86103
if !success(pipeline(Cmd(cmd, dir=@__DIR__); stdout=stdout, stderr=stderr))

0 commit comments

Comments
 (0)