Commit 9be33518

9be3351880ccMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Add InstanceVariableTargetNode and CallTargetNode to multi-write codegen

The ArrayNode-literal multi-write path (a, b = [x, y]) only handled LocalVariableTargetNode, ConstantTargetNode, and MultiTargetNode in its lefts/rights loops. Two missing arms:

  • InstanceVariableTargetNode: @a, @b = [1, 2] now emits self->iv_a = _t0; self->iv_b = _t1; with boxing when the ivar slot is poly but the element is not.

  • CallTargetNode: obj.setter = t (e.g. @c.v = 33) now resolves through comp_writer_in_chain and emits a direct ivar store: (recv)->iv = _t;

Both paths added symmetrically to analyze.c's multi-write loop so that ivar types are inferred from the literal element types.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
9be3351880cc
Parent
6bb066577fcc

src/analyze.cmodifiedView file

@@ -2107,6 +2107,20 @@
21072107 TyKind mg = ty_unify(cv->type, et);
21082108 if (mg != cv->type) { cv->type = mg; changed = 1; }
21092109 }
2110+ else if (!strcmp(lty, "InstanceVariableTargetNode")) {
2111+ Scope *iv_sc = comp_scope_of(c, id);
2112+ int iv_cid = iv_sc ? iv_sc->class_id : -1;
2113+ if (iv_cid < 0) continue;
2114+ const char *ivnm = nt_str(nt, lefts[i], "name");
2115+ int iv_idx = ivnm ? comp_ivar_index(&c->classes[iv_cid], ivnm) : -1;
2116+ if (iv_idx < 0) continue;
2117+ TyKind et = infer_type(c, els[i]);
2118+ if (et == TY_NIL) continue;
2119+ TyKind mg = ty_unify(c->classes[iv_cid].ivar_types[iv_idx], et);
2120+ if (mg != c->classes[iv_cid].ivar_types[iv_idx]) {
2121+ c->classes[iv_cid].ivar_types[iv_idx] = mg; changed = 1;
2122+ }
2123+ }
21102124 else if (!strcmp(lty, "MultiTargetNode")) {
21112125 /* (b, c) nested target: inner RHS must be an ArrayNode literal */
21122126 const char *ety = nt_type(nt, els[i]);
@@ -2150,6 +2164,18 @@
21502164 TyKind mg3 = ty_unify(cv2->type, et);
21512165 if (mg3 != cv2->type) { cv2->type = mg3; changed = 1; }
21522166 }
2167+ else if (!strcmp(rty3, "InstanceVariableTargetNode")) {
2168+ Scope *iv_sc3 = comp_scope_of(c, id);
2169+ int iv_cid3 = iv_sc3 ? iv_sc3->class_id : -1;
2170+ if (iv_cid3 < 0) continue;
2171+ const char *ivnm3 = nt_str(nt, rights[j], "name");
2172+ int iv_idx3 = ivnm3 ? comp_ivar_index(&c->classes[iv_cid3], ivnm3) : -1;
2173+ if (iv_idx3 < 0) continue;
2174+ TyKind mg4 = ty_unify(c->classes[iv_cid3].ivar_types[iv_idx3], et);
2175+ if (mg4 != c->classes[iv_cid3].ivar_types[iv_idx3]) {
2176+ c->classes[iv_cid3].ivar_types[iv_idx3] = mg4; changed = 1;
2177+ }
2178+ }
21532179 }
21542180 /* rest (splat) target: elements [ln, en-rn) become a typed array */
21552181 int rest_nid = nt_ref(nt, id, "rest");