From 6a8e46141cec083758adecffc218fca420b59ffc Mon Sep 17 00:00:00 2001 From: William Moses Date: Wed, 27 Nov 2024 12:12:22 -0500 Subject: [PATCH] simplify deferred failures (#2126) Co-authored-by: William Moses --- src/Enzyme.jl | 9 ++++++--- src/compiler.jl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Enzyme.jl b/src/Enzyme.jl index 5305beff8d..8c94911368 100644 --- a/src/Enzyme.jl +++ b/src/Enzyme.jl @@ -690,13 +690,13 @@ code, as well as high-order differentiation. rt = Compiler.primal_return_type(mode, FTy, tt) A2 = A{rt} if rt == Union{} - throw(ErrorException("Return type inferred to be Union{}. Giving up.")) + rt = Nothing end else @assert A isa DataType rt = A if rt == Union{} - throw(ErrorException("Return type inferred to be Union{}. Giving up.")) + throw(ErrorException("Return type inferred to be Union{}. Giving up.")) end end @@ -841,7 +841,10 @@ code, as well as high-order differentiation. if RT isa UnionAll rt = Compiler.primal_return_type(mode, FT, tt) - rt = RT{rt} + if rt == Union{} + rt = Nothing + end + rt = RT{rt} else @assert RT isa DataType rt = RT diff --git a/src/compiler.jl b/src/compiler.jl index e836f4bb8c..f266fd5f34 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -3262,7 +3262,7 @@ function primal_return_type_generator(world::UInt, source, self, @nospecialize(m return new_ci end -@eval @inline function primal_return_type(mode::Mode, ft::Type, tt::Type) +@eval Base.@assume_effects :removable :foldable :nothrow @inline function primal_return_type(mode::Mode, ft::Type, tt::Type) $(Expr(:meta, :generated_only)) $(Expr(:meta, :generated, primal_return_type_generator)) end