diff --git a/base/compiler/typelattice.jl b/base/compiler/typelattice.jl index 0029e96ab7e62..73b95d54a6ff7 100644 --- a/base/compiler/typelattice.jl +++ b/base/compiler/typelattice.jl @@ -255,7 +255,7 @@ end widenconst(m::MaybeUndef) = widenconst(m.typ) widenconst(c::PartialTypeVar) = TypeVar widenconst(t::PartialStruct) = t.typ -widenconst(t::PartialOpaque) = t.t +widenconst(t::PartialOpaque) = t.typ widenconst(t::Type) = t widenconst(t::TypeVar) = t widenconst(t::Core.TypeofVararg) = t diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index de819a3eba2e8..f97c30f68abb1 100644 --- a/base/compiler/utilities.jl +++ b/base/compiler/utilities.jl @@ -104,16 +104,6 @@ function invoke_api(li::CodeInstance) return ccall(:jl_invoke_api, Cint, (Any,), li) end -function get_staged(li::MethodInstance) - may_invoke_generator(li) || return nothing - try - # user code might throw errors – ignore them - return ccall(:jl_code_for_staged, Any, (Any,), li)::CodeInfo - catch - return nothing - end -end - function has_opaque_closure(c::CodeInfo) for i = 1:length(c.code) stmt = c.code[i] @@ -122,21 +112,31 @@ function has_opaque_closure(c::CodeInfo) return false end +function get_staged(mi::MethodInstance) + may_invoke_generator(mi) || return nothing + if isdefined(mi, :uninferred) + return copy(mi.uninferred::CodeInfo) + end + try + # user code might throw errors – ignore them + ci = ccall(:jl_code_for_staged, Any, (Any,), mi)::CodeInfo + if has_opaque_closure(mi) + # For opaque closures, cache the generated code info to make sure + # that OpaqueClosure method identity is stable + mi.uninferred = copy(ci) + end + return ci + catch + return nothing + end +end + function retrieve_code_info(linfo::MethodInstance) m = linfo.def::Method c = nothing if isdefined(m, :generator) - if isdefined(linfo, :uninferred) - c = copy(linfo.uninferred::CodeInfo) - else - # user code might throw errors – ignore them - c = get_staged(linfo) - # For opaque closures, cache the generated code info to make sure - # that Opaque Closure method identity remains stable. - if c !== nothing && has_opaque_closure(c) - linfo.uninferred = copy(c) - end - end + # user code might throw errors – ignore them + c = get_staged(linfo) end if c === nothing && isdefined(m, :source) src = m.source diff --git a/src/dump.c b/src/dump.c index d3c4f3ff4d648..362401037ee8d 100644 --- a/src/dump.c +++ b/src/dump.c @@ -380,7 +380,7 @@ static void jl_serialize_module(jl_serializer_state *s, jl_module_t *m) write_uint8(s->s, m->infer); } -static inline int jl_serialize_generic(jl_serializer_state *s, jl_value_t *v) JL_GC_DISABLED +static int jl_serialize_generic(jl_serializer_state *s, jl_value_t *v) JL_GC_DISABLED { if (v == NULL) { write_uint8(s->s, TAG_NULL);