Commit 83914908
83914908c1ffMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: unbox poly sources into scalar block params at yield and instance_exec binds
With block params no longer widened to poly, a poly source bound to a scalar block param is the reverse coercion of the boxing arms added earlier: a poly yield value into an int block param (emit_block_invoke), and a poly instance_exec arg -- a widened ivar or trampoline temp -- into an int block param. Unbox with emit_unbox_text down to the slot type when the source is poly and the slot is a concrete scalar. Unblocks the yield / block-forward family (yield, forward_args_block, block_forward_recv_typed/self_call, inlined_yield_self_locals, instance_exec_mixed_args).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 83914908c1ff
- Parent
- 9c94f5400377
src/codegen_call.cmodifiedView file
if (!pn) continue; LocalVar *plv = scope_local(comp_scope_of(c, id), pn); int ppoly = plv && plv->type == TY_POLY; /* widened slot needs a boxed rvalue */ /* a scalar slot (e.g. an int block param, which is NOT widened) fed a poly arg needs the reverse: unbox the poly down to the slot type. */ int pscalar = plv && plv->type != TY_POLY && plv->type != TY_UNKNOWN; emit_indent(g_pre, g_indent); buf_printf(g_pre, "lv_%s = ", rename_local(pn)); if (as_kind) { Buf eb; memset(&eb, 0, sizeof eb); if (an >= 0) { if (ppoly) emit_boxed(c, an, &eb); else emit_expr(c, an, &eb); } else buf_puts(&eb, "0"); buf_puts(g_pre, eb.p ? eb.p : "0"); free(eb.p); if (an >= 0 && pscalar && comp_ntype(c, an) == TY_POLY) emit_unbox_text(c, plv->type, eb.p ? eb.p : "", g_pre); else buf_puts(g_pre, eb.p ? eb.p : "0"); free(eb.p); } else if (is_exec) { if (p < iac) { if (ppoly) emit_boxed(c, iav[p], g_pre); else emit_expr(c, iav[p], g_pre); } if (p < iac) { if (ppoly) emit_boxed(c, iav[p], g_pre); else if (pscalar && comp_ntype(c, iav[p]) == TY_POLY) { Buf eb; memset(&eb, 0, sizeof eb); emit_expr(c, iav[p], &eb); emit_unbox_text(c, plv->type, eb.p ? eb.p : "", g_pre); free(eb.p); } else emit_expr(c, iav[p], g_pre); } else emit_ie_param_default(c, plv ? plv->type : TY_POLY, g_pre); } else buf_printf(g_pre, "_t%d", tr); /* instance_eval yields self */ TyKind at = comp_ntype(c, yargs[k]); if (bt == TY_POLY && at != TY_POLY && at != TY_UNKNOWN) emit_boxed(c, yargs[k], b); else if (at == TY_POLY && bt != TY_POLY && bt != TY_UNKNOWN) { /* a poly yield value into a scalar (e.g. int, non-widened) block param: unbox down to the slot type (the reverse of the box arm above). */ Buf yb; memset(&yb, 0, sizeof yb); emit_expr(c, yargs[k], &yb); emit_unbox_text(c, bt, yb.p ? yb.p : "", b); free(yb.p); } else emit_expr(c, yargs[k], b); }