Skip to content

Commit

Permalink
Fix a missing widenconst in SROA (#31336)
Browse files Browse the repository at this point in the history
We can now infer Expr(:new) as returning a `PartialStruct` if
one of the arguments is constant. However, SROA was missing a
corresponding widenconst and thus refusing to process such Expr(:new).
This didn't show up very much in julia code, because inlining generally
dropped the PartialStruct annotation on the Expr(:new), but it does
show up with more aggressive inlining schemes that I'm playing with.
Fix it and add a test.
  • Loading branch information
Keno authored Mar 14, 2019
1 parent 97719d7 commit 2d6e183
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
lifted_leaves[leaf_key] = RefValue{Any}(lifted)
continue
elseif isexpr(def, :new)
typ = types(compact)[leaf]
typ = widenconst(types(compact)[leaf])
if isa(typ, UnionAll)
typ = unwrap_unionall(typ)
end
Expand Down
12 changes: 12 additions & 0 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test
using Base.Meta

# Tests for domsort

Expand Down Expand Up @@ -98,3 +99,14 @@ let nt = (a=1, b=2)
# Should throw
@test_throws ArgumentError blah31139(nt)
end

# Expr(:new) annoted as PartialStruct
struct FooPartial
x
y
global f_partial
f_partial(x) = new(x, 2).x
end
let ci = code_typed(f_partial, Tuple{Float64})[1].first
@test length(ci.code) == 1 && isexpr(ci.code[1], :return)
end

0 comments on commit 2d6e183

Please sign in to comment.