Skip to content

Commit 86af1ed

Browse files
authored
Merge pull request #145 from JuliaDiff/ox/builtin
Give better error message when hitting a builtin
2 parents af9c43a + 9858d80 commit 86af1ed

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/stage1/recurse_fwd.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ struct ∂☆new{N}; end
2727
function ∂☆nomethd(@nospecialize(args))
2828
throw(MethodError(primal(args[1]), map(primal, Base.tail(args))))
2929
end
30+
function ∂☆builtin((f_bundle, args...))
31+
f = primal(f_bundle)
32+
argtypes = Any[Core.Typeof(primal(arg)) for arg in args]
33+
tt = Base.signature_type(f, argtypes)
34+
sig = Base.sprint(Base.show_tuple_as_call, Symbol(""), tt)
35+
throw(DomainError(f, "No `ChainRulesCore.frule` found for the built-in function `$sig`"))
36+
end
3037

3138
function perform_fwd_transform(world::UInt, source::LineNumberNode,
3239
@nospecialize(ff::Type{∂☆recurse{N}}), @nospecialize(args)) where {N}
@@ -36,6 +43,11 @@ function perform_fwd_transform(world::UInt, source::LineNumberNode,
3643
end
3744

3845
sig = Tuple{map(π, args)...}
46+
if sig.parameters[1] <: Core.Builtin
47+
return generate_lambda_ex(world, source,
48+
Core.svec(:ff, :args), Core.svec(), :(∂☆builtin(args)))
49+
end
50+
3951
mthds = Base._methods_by_ftype(sig, -1, world)
4052
if mthds === nothing || length(mthds) != 1
4153
# Core.println("[perform_fwd_transform] ", sig, " => ", mthds)

0 commit comments

Comments
 (0)