Skip to content

Commit

Permalink
Preserve slottypes during opaque closure IR compression
Browse files Browse the repository at this point in the history
They currently affect codegen, so they need to be preserved
until we decide to store the environment type somewhere else.
  • Loading branch information
Keno committed Apr 28, 2022
1 parent 000a6cd commit 4206af5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function Core.OpaqueClosure(ir::IRCode, env...;
src = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
src.slotflags = UInt8[]
src.slotnames = fill(:none, nargs+1)
src.slottypes = copy(ir.argtypes)
Core.Compiler.replace_code_newstyle!(src, ir, nargs+1)
Core.Compiler.widen_all_consts!(src)
src.inferred = true
Expand Down
7 changes: 7 additions & 0 deletions src/ircode.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ JL_DLLEXPORT jl_array_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code)
jl_encode_value_(&s, jl_get_nth_field((jl_value_t*)code, i), copy);
}

// For opaque closure, also save the slottypes. We technically only need the first slot type,
// but this is simpler for now. We may want to refactor where this gets stored in the future.
if (m->is_for_opaque_closure)
jl_encode_value_(&s, code->slottypes, 1);

if (m->generator)
// can't optimize generated functions
jl_encode_value_(&s, (jl_value_t*)jl_compress_argnames(code->slotnames), 1);
Expand Down Expand Up @@ -834,6 +839,8 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t
jl_value_t **fld = (jl_value_t**)((char*)jl_data_ptr(code) + jl_field_offset(jl_code_info_type, i));
*fld = jl_decode_value(&s);
}
if (m->is_for_opaque_closure)
code->slottypes = jl_decode_value(&s);

jl_value_t *slotnames = jl_decode_value(&s);
if (!jl_is_string(slotnames))
Expand Down

0 comments on commit 4206af5

Please sign in to comment.