Commit 22a0c773

22a0c773783cMerged

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

Description

Fix retry, SourceEncodingNode, DCE parameter defaults and op-assign

analyze.c:

  • SourceEncodingNode returns TY_POLY (encoding object, not plain string)
  • encoding.name / .to_s / .inspect return TY_STRING
  • cr_collect_calls: scan DefNode parameters for default arg calls

codegen.c:

  • SourceEncodingNode emits sp_box_encoding(sp_encoding_utf8())
  • encoding.name dispatches to sp_poly_to_s
  • is_a?(Encoding) checks SP_TAG_ENCODING
  • retry: emit goto to _retry_N label before begin's setjmp when rescue contains RetryNode; subtree_has_retry helper detects RetryNode

Fixes: rescue (retry), source_encoding, default_args (parameter defaults in DCE), op_assign_user_operator (OperatorWriteNode operator names in DCE)

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

Details

Commit
22a0c773783c
Parent
f85018fcb066

src/analyze.cmodifiedView file

@@ -364,6 +364,17 @@
364364 nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "class"))
365365 return TY_STRING;
366366
367+ /* __ENCODING__.name / .to_s / .inspect -> the encoding name string */
368+ if (recv >= 0 && argc == 0 &&
369+ (!strcmp(name, "name") || !strcmp(name, "to_s") || !strcmp(name, "inspect")) &&
370+ nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "SourceEncodingNode"))
371+ return TY_STRING;
372+ /* <enc>.encoding.name -> the encoding name string */
373+ if (recv >= 0 && argc == 0 && !strcmp(name, "name") && rt == TY_POLY &&
374+ nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") &&
375+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "encoding"))
376+ return TY_STRING;
377+
367378 /* Module.singleton_writer= / Module.singleton_reader */
368379 if (recv >= 0 && nt_type(nt, recv) &&
369380 (!strcmp(nt_type(nt, recv), "ConstantReadNode") ||
@@ -1711,7 +1722,7 @@
17111722 if (!strcmp(ty, "StringNode")) return TY_STRING;
17121723 if (!strcmp(ty, "SourceFileNode")) return TY_STRING;
17131724 if (!strcmp(ty, "SourceLineNode")) return TY_INT;
1714- if (!strcmp(ty, "SourceEncodingNode")) return TY_STRING;
1725+ if (!strcmp(ty, "SourceEncodingNode")) return TY_POLY;
17151726 if (!strcmp(ty, "RegularExpressionNode") ||
17161727 !strcmp(ty, "InterpolatedRegularExpressionNode")) return TY_REGEX;
17171728 if (!strcmp(ty, "InterpolatedStringNode")) return TY_STRING;