Skip to content

Commit f52c853

Browse files
committed
test that handling %new right in forwarddiff_no_inf
1 parent a36d852 commit f52c853

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/stage2_fwd.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,23 @@ module stage2_fwd
4343
g(x) = Diffractor.∂☆{1}()(Diffractor.ZeroBundle{1}(f), Diffractor.TaylorBundle{1}(x, (1.0,)))
4444
Diffractor.∂☆{1}()(Diffractor.ZeroBundle{1}(g), Diffractor.TaylorBundle{1}(10f0, (1.0,)))
4545
end
46+
47+
@testset "Constructors in forward_diff_no_inf!" begin
48+
struct Bar148
49+
v
50+
end
51+
foo_148(x) = Bar148(x)
52+
53+
# this is needed as transform! is *always* called on Arguments regardless of what visit_custom says
54+
identity_transform!(ir, ssa::Core.SSAValue, order) = ir[ssa]
55+
function identity_transform!(ir, arg::Core.Argument, order)
56+
return Core.Compiler.insert_node!(ir, Core.SSAValue(1), Core.Compiler.NewInstruction(Expr(:call, Diffractor.ZeroBundle{1}, arg), Any))
57+
end
58+
59+
ir = first(only(Base.code_ircode(foo_148, Tuple{Float64})))
60+
Diffractor.forward_diff_no_inf!(ir, [Core.SSAValue(1) => 1]; transform! = identity_transform!)
61+
ir2 = Core.Compiler.compact!(ir)
62+
f = Core.OpaqueClosure(ir2; do_compile=false)
63+
@test f(1.0) == Bar148(1.0) # This would error if we were not handling constructors (%new) right
64+
end
4665
end

0 commit comments

Comments
 (0)