@@ -2,6 +2,20 @@ module Internals
22
33import 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{})
12+ )
13+ infer_return_type (@nospecialize f:: Any ) = Core. Compiler. return_type (f, Tuple{})
14+ else
15+ # safe conservative fallback to `Any`, which is subtyped by each type
16+ infer_return_type (@nospecialize f:: Any ) = Any
17+ end
18+
519Base. getindex (r:: AtomicRef ) = @atomic r. x
620Base. setindex! (r:: AtomicRef{T} , x) where {T} = @atomic r. x = convert (T, x)
721
@@ -96,7 +110,7 @@ macro spawn(args...)
96110 quote
97111 let $ (letargs... )
98112 f = $ thunk
99- T = Core . Compiler . return_type (f, Tuple{} )
113+ T = infer_return_type (f )
100114 ref = AtomicRef {T} ()
101115 f_wrap = () -> (ref[] = f (); nothing )
102116 task = Task (f_wrap)
@@ -136,7 +150,7 @@ macro spawnat(thrdid, ex)
136150 end
137151 let $ (letargs... )
138152 thunk = $ thunk
139- RT = Core . Compiler . return_type (thunk, Tuple{} )
153+ RT = infer_return_type (thunk)
140154 ret = AtomicRef {RT} ()
141155 thunk_wrap = () -> (ret[] = thunk (); nothing )
142156 local task = Task (thunk_wrap)
0 commit comments