Skip to content

Commit 08bde0f

Browse files
committed
infer_return_type: simplify definition, use less-private interface
The `Base.promote_op` function seems to be less private of an interface than `Compiler.return_type`. While the single method defined in `Base` basically just forwards to `Compiler.return_type` (for the purposes of StableTasks), the semantics are a bit different because a handful of packages actually add other methods to this function. That seems like a good thing, though. While at it, also avoid defining a new function, instead just assign the callable to a constant binding. Should help code coverage.
1 parent edd5e9d commit 08bde0f

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/internals.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ module Internals
22

33
import StableTasks: @spawn, @spawnat, @fetch, @fetchfrom, StableTask, AtomicRef
44

5-
if (
6-
(@isdefined Core) &&
7-
(Core isa Module) &&
8-
isdefined(Core, :Compiler) &&
9-
(Core.Compiler isa Module) &&
10-
isdefined(Core.Compiler, :return_type) &&
11-
applicable(Core.Compiler.return_type, identity, Tuple{})
5+
const infer_return_type = if (
6+
isdefined(Base, :promote_op) &&
7+
applicable(Base.promote_op, rand)
128
)
13-
infer_return_type(@nospecialize f::Any) = Core.Compiler.return_type(f, Tuple{})
9+
Base.promote_op
1410
else
1511
# safe conservative fallback to `Any`, which is subtyped by each type
16-
infer_return_type(@nospecialize f::Any) = Any
12+
Returns(Any)
1713
end
1814

1915
Base.getindex(r::AtomicRef) = @atomic r.x

0 commit comments

Comments
 (0)