Skip to content

Commit ea704c1

Browse files
committed
local functions to global functions
In preparation for replacing recursion with metaprogramming.
1 parent 9e78161 commit ea704c1

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

base/promotion.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,19 @@ const _promote_type_binary_detected_infinite_recursion_exception = let
335335
s = "`promote_type`: detected unbounded recursion caused by faulty `promote_rule` logic"
336336
ArgumentError(s)
337337
end
338+
function _promote_type_binary_err_giving_up()
339+
@noinline
340+
throw(_promote_type_binary_recursion_depth_limit_exception)
341+
end
342+
function _promote_type_binary_err_detected_infinite_recursion()
343+
@noinline
344+
throw(_promote_type_binary_detected_infinite_recursion_exception)
345+
end
346+
function _promote_type_binary_detect_loop(T::Type, S::Type, A::Type, B::Type)
347+
onesided(T::Type, S::Type, A::Type, B::Type) = _types_are_equal(T, A) && _types_are_equal(S, B)
348+
onesided(T, S, A, B) || onesided(T, S, B, A)
349+
end
338350
function _promote_type_binary(T::Type, S::Type, recursion_depth_limit::Tuple{Vararg{Nothing}})
339-
function err_giving_up()
340-
@noinline
341-
throw(_promote_type_binary_recursion_depth_limit_exception)
342-
end
343-
function err_detected_infinite_recursion()
344-
@noinline
345-
throw(_promote_type_binary_detected_infinite_recursion_exception)
346-
end
347-
detect_loop_onesided(T::Type, S::Type, A::Type, B::Type) = _types_are_equal(T, A) && _types_are_equal(S, B)
348-
detect_loop(T::Type, S::Type, A::Type, B::Type) = detect_loop_onesided(T, S, A, B) || detect_loop_onesided(T, S, B, A)
349351
# Try promote_rule in both orders.
350352
ts = promote_rule(T, S)
351353
st = promote_rule(S, T)
@@ -362,13 +364,13 @@ function _promote_type_binary(T::Type, S::Type, recursion_depth_limit::Tuple{Var
362364
if st_is_bottom || _types_are_equal(st, ts)
363365
return ts
364366
end
365-
if detect_loop(T, S, ts, st)
367+
if _promote_type_binary_detect_loop(T, S, ts, st)
366368
# This is not strictly necessary, as we already limit the recursion depth, but
367369
# makes for nicer UX.
368-
err_detected_infinite_recursion()
370+
_promote_type_binary_err_detected_infinite_recursion()
369371
end
370372
if recursion_depth_limit === ()
371-
err_giving_up()
373+
_promote_type_binary_err_giving_up()
372374
end
373375
l = tail(recursion_depth_limit)
374376
_promote_type_binary(ts, st, l)

0 commit comments

Comments
 (0)