@@ -2,6 +2,20 @@ module Internals
2
2
3
3
import StableTasks: @spawn , @spawnat , @fetch , @fetchfrom , StableTask, AtomicRef
4
4
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
+
5
19
Base. getindex (r:: AtomicRef ) = @atomic r. x
6
20
Base. setindex! (r:: AtomicRef{T} , x) where {T} = @atomic r. x = convert (T, x)
7
21
@@ -96,7 +110,7 @@ macro spawn(args...)
96
110
quote
97
111
let $ (letargs... )
98
112
f = $ thunk
99
- T = Core . Compiler . return_type (f, Tuple{} )
113
+ T = infer_return_type (f )
100
114
ref = AtomicRef {T} ()
101
115
f_wrap = () -> (ref[] = f (); nothing )
102
116
task = Task (f_wrap)
@@ -136,7 +150,7 @@ macro spawnat(thrdid, ex)
136
150
end
137
151
let $ (letargs... )
138
152
thunk = $ thunk
139
- RT = Core . Compiler . return_type (thunk, Tuple{} )
153
+ RT = infer_return_type (thunk)
140
154
ret = AtomicRef {RT} ()
141
155
thunk_wrap = () -> (ret[] = thunk (); nothing )
142
156
local task = Task (thunk_wrap)
0 commit comments