Skip to content

Commit 8d59773

Browse files
committed
make code_lowered type stable
1 parent 4e72944 commit 8d59773

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

base/reflection.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,21 +1126,23 @@ function code_lowered(@nospecialize(f), @nospecialize(t=Tuple); generated::Bool=
11261126
throw(ArgumentError("'debuginfo' must be either :source or :none"))
11271127
end
11281128
world = get_world_counter()
1129-
world == typemax(UInt) && error("code reflection cannot be used from generated functions")
1130-
return map(method_instances(f, t, world)) do m
1129+
ret = CodeInfo[]
1130+
for m in method_instances(f, t, world)
11311131
if generated && hasgenerator(m)
11321132
if may_invoke_generator(m)
1133-
return ccall(:jl_code_for_staged, Any, (Any, UInt), m, world)::CodeInfo
1133+
push!(ret, ccall(:jl_code_for_staged, Any, (Any, UInt), m, world)::CodeInfo)
11341134
else
1135-
error("Could not expand generator for `@generated` method ", m, ". ",
1136-
"This can happen if the provided argument types (", t, ") are ",
1137-
"not leaf types, but the `generated` argument is `true`.")
1135+
error(
1136+
"Could not expand generator for `@generated` method ", m, ". ",
1137+
"This can happen if the provided argument types (", lt, ") are ",
1138+
"not leaf types, but the `generated` argument is `true`.")
11381139
end
11391140
end
11401141
code = uncompressed_ir(m.def::Method)
11411142
debuginfo === :none && remove_linenums!(code)
1142-
return code
1143+
push!(ret, code)
11431144
end
1145+
return ret
11441146
end
11451147

11461148
hasgenerator(m::Method) = isdefined(m, :generator)

test/reflection.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,3 +1193,6 @@ end
11931193
@test Base.isexported(Mod52812, :b)
11941194
@test Base.ispublic(Mod52812, :a)
11951195
@test Base.ispublic(Mod52812, :b)
1196+
1197+
@test Base.infer_return_type(code_lowered, (Any,)) == Vector{Core.CodeInfo}
1198+
@test Base.infer_return_type(code_lowered, (Any,Any)) == Vector{Core.CodeInfo}

0 commit comments

Comments
 (0)