Skip to content

Commit 072a6a4

Browse files
committed
Rename putstring instruction as dupstring
As well as `putchilledstring` as `dupchilledstring`. This is more consistent with similar `duparray` and `duphash` instructions and better reflect it's behavior.
1 parent 3f75e99 commit 072a6a4

15 files changed

Lines changed: 60 additions & 60 deletions

File tree

bootstraptest/test_insns.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def m&b
8686
[ 'putobject', %q{ /(?<x>x)/ =~ "x"; x == "x" }, ],
8787

8888
[ 'putspecialobject', %q{ {//=>true}[//] }, ],
89-
[ 'putstring', %q{ "true" }, ],
89+
[ 'dupstring', %q{ "true" }, ],
9090
[ 'tostring / concatstrings', %q{ "#{true}" }, ],
9191
[ 'toregexp', %q{ /#{true}/ =~ "true" && $~ }, ],
9292
[ 'intern', %q{ :"#{true}" }, ],

compile.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,7 @@ iseq_pop_newarray(rb_iseq_t *iseq, INSN *iobj)
31953195
static int
31963196
is_frozen_putstring(INSN *insn, VALUE *op)
31973197
{
3198-
if (IS_INSN_ID(insn, putstring) || IS_INSN_ID(insn, putchilledstring)) {
3198+
if (IS_INSN_ID(insn, dupstring) || IS_INSN_ID(insn, dupchilledstring)) {
31993199
*op = OPERAND_AT(insn, 0);
32003200
return 1;
32013201
}
@@ -3255,8 +3255,8 @@ optimize_checktype(rb_iseq_t *iseq, INSN *iobj)
32553255
VALUE type;
32563256

32573257
switch (INSN_OF(iobj)) {
3258-
case BIN(putstring):
3259-
case BIN(putchilledstring):
3258+
case BIN(dupstring):
3259+
case BIN(dupchilledstring):
32603260
type = INT2FIX(T_STRING);
32613261
break;
32623262
case BIN(putnil):
@@ -3454,8 +3454,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
34543454
}
34553455

34563456
/*
3457-
* putstring "beg"
3458-
* putstring "end"
3457+
* dupstring "beg"
3458+
* dupstring "end"
34593459
* newrange excl
34603460
*
34613461
* ==>
@@ -3670,16 +3670,16 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
36703670
* =>
36713671
* jump L1
36723672
*
3673-
* putstring ".."
3673+
* dupstring ".."
36743674
* if L1
36753675
* =>
36763676
* jump L1
36773677
*
3678-
* putstring ".."
3678+
* dupstring ".."
36793679
* dup
36803680
* if L1
36813681
* =>
3682-
* putstring ".."
3682+
* dupstring ".."
36833683
* jump L1
36843684
*
36853685
*/
@@ -3694,7 +3694,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
36943694
OPERAND_AT(pobj, 0) == Qfalse :
36953695
FALSE);
36963696
}
3697-
else if (IS_INSN_ID(pobj, putstring) ||
3697+
else if (IS_INSN_ID(pobj, dupstring) ||
36983698
IS_INSN_ID(pobj, duparray) ||
36993699
IS_INSN_ID(pobj, newarray)) {
37003700
cond = IS_INSN_ID(iobj, branchif);
@@ -3732,7 +3732,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
37323732

37333733
if (IS_INSN_ID(iobj, pop)) {
37343734
/*
3735-
* putself / putnil / putobject obj / putstring "..."
3735+
* putself / putnil / putobject obj / dupstring "..."
37363736
* pop
37373737
* =>
37383738
* # do nothing
@@ -3741,8 +3741,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
37413741
if (IS_INSN(prev)) {
37423742
enum ruby_vminsn_type previ = ((INSN *)prev)->insn_id;
37433743
if (previ == BIN(putobject) || previ == BIN(putnil) ||
3744-
previ == BIN(putself) || previ == BIN(putstring) ||
3745-
previ == BIN(putchilledstring) ||
3744+
previ == BIN(putself) || previ == BIN(dupstring) ||
3745+
previ == BIN(dupchilledstring) ||
37463746
previ == BIN(dup) ||
37473747
previ == BIN(getlocal) ||
37483748
previ == BIN(getblockparam) ||
@@ -3884,10 +3884,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
38843884
}
38853885
}
38863886

3887-
if (IS_INSN_ID(iobj, putstring) || IS_INSN_ID(iobj, putchilledstring) ||
3887+
if (IS_INSN_ID(iobj, dupstring) || IS_INSN_ID(iobj, dupchilledstring) ||
38883888
(IS_INSN_ID(iobj, putobject) && RB_TYPE_P(OPERAND_AT(iobj, 0), T_STRING))) {
38893889
/*
3890-
* putstring ""
3890+
* dupstring ""
38913891
* concatstrings N
38923892
* =>
38933893
* concatstrings N-1
@@ -4222,7 +4222,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
42224222
}
42234223
}
42244224
}
4225-
else if ((IS_INSN_ID(niobj, putstring) || IS_INSN_ID(niobj, putchilledstring) ||
4225+
else if ((IS_INSN_ID(niobj, dupstring) || IS_INSN_ID(niobj, dupchilledstring) ||
42264226
(IS_INSN_ID(niobj, putobject) && RB_TYPE_P(OPERAND_AT(niobj, 0), T_STRING))) &&
42274227
IS_NEXT_INSN_ID(&niobj->link, send)) {
42284228
const struct rb_callinfo *ci = (struct rb_callinfo *)OPERAND_AT((INSN *)niobj->link.next, 0);
@@ -4235,9 +4235,9 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
42354235
return COMPILE_OK;
42364236
}
42374237
}
4238-
// newarray n, putchilledstring "E", getlocal b, send :pack with {buffer: b}
4239-
// -> putchilledstring "E", getlocal b, opt_newarray_send n+2, :pack, :buffer
4240-
else if ((IS_INSN_ID(niobj, putstring) || IS_INSN_ID(niobj, putchilledstring) ||
4238+
// newarray n, dupchilledstring "E", getlocal b, send :pack with {buffer: b}
4239+
// -> dupchilledstring "E", getlocal b, opt_newarray_send n+2, :pack, :buffer
4240+
else if ((IS_INSN_ID(niobj, dupstring) || IS_INSN_ID(niobj, dupchilledstring) ||
42414241
(IS_INSN_ID(niobj, putobject) && RB_TYPE_P(OPERAND_AT(niobj, 0), T_STRING))) &&
42424242
IS_NEXT_INSN_ID(&niobj->link, getlocal) &&
42434243
(niobj->link.next && IS_NEXT_INSN_ID(niobj->link.next, send))) {
@@ -4260,7 +4260,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
42604260
// Break the "else if" chain since some prior checks abort after sub-ifs.
42614261
// We already found "newarray". To match `[...].include?(arg)` we look for
42624262
// the instruction(s) representing the argument followed by a "send".
4263-
if ((IS_INSN_ID(niobj, putstring) || IS_INSN_ID(niobj, putchilledstring) ||
4263+
if ((IS_INSN_ID(niobj, dupstring) || IS_INSN_ID(niobj, dupchilledstring) ||
42644264
IS_INSN_ID(niobj, putobject) ||
42654265
IS_INSN_ID(niobj, putself) ||
42664266
IS_INSN_ID(niobj, getlocal) ||
@@ -4729,7 +4729,7 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node)
47294729
int cnt;
47304730
if (!RNODE_DSTR(node)->nd_next) {
47314731
VALUE lit = rb_node_dstr_string_val(node);
4732-
ADD_INSN1(ret, node, putstring, lit);
4732+
ADD_INSN1(ret, node, dupstring, lit);
47334733
RB_OBJ_SET_SHAREABLE(lit);
47344734
RB_OBJ_WRITTEN(iseq, Qundef, lit);
47354735
}
@@ -11250,10 +11250,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
1125011250
}
1125111251
switch (option->frozen_string_literal) {
1125211252
case ISEQ_FROZEN_STRING_LITERAL_UNSET:
11253-
ADD_INSN1(ret, node, putchilledstring, lit);
11253+
ADD_INSN1(ret, node, dupchilledstring, lit);
1125411254
break;
1125511255
case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
11256-
ADD_INSN1(ret, node, putstring, lit);
11256+
ADD_INSN1(ret, node, dupstring, lit);
1125711257
break;
1125811258
case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
1125911259
ADD_INSN1(ret, node, putobject, lit);

defs/opt_insn_unif.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
__END__
77

88
putobject putobject
9-
putobject putstring
9+
putobject dupstring
1010
putobject setlocal
1111

12-
putstring putstring
13-
putstring putobject
14-
putstring setlocal
12+
dupstring dupstring
13+
dupstring putobject
14+
dupstring setlocal
1515

1616
# putnil end
1717

doc/language/option_dump.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The supported dump items:
1818
$ ruby --dump=insns t.rb
1919
== disasm: #<ISeq:<main>@t.rb:1 (1,0)-(1,10)> (catch: FALSE)
2020
0000 putself ( 1)[Li]
21-
0001 putstring "Foo"
21+
0001 dupstring "Foo"
2222
0003 opt_send_without_block <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>
2323
0005 leave
2424
```

insns.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ putspecialobject
373373

374374
/* put string val. string will be copied. */
375375
DEFINE_INSN
376-
putstring
376+
dupstring
377377
(VALUE str)
378378
()
379379
(VALUE val)
@@ -383,7 +383,7 @@ putstring
383383

384384
/* put chilled string val. string will be copied but frozen in the future. */
385385
DEFINE_INSN
386-
putchilledstring
386+
dupchilledstring
387387
(VALUE str)
388388
()
389389
(VALUE val)

iseq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ iseqw_s_of(VALUE klass, VALUE body)
32663266
* 0000 trace 8 ( 1)
32673267
* 0002 trace 1 ( 2)
32683268
* 0004 putself
3269-
* 0005 putstring "hello, world"
3269+
* 0005 dupstring "hello, world"
32703270
* 0007 send :puts, 1, nil, 8, <ic:0>
32713271
* 0013 trace 16 ( 3)
32723272
* 0015 leave ( 2)

prism/prism.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5074,7 +5074,7 @@ pm_interpolated_regular_expression_node_closing_set(pm_parser_t *parser, pm_inte
50745074
* PM_NODE_FLAG_STATIC_LITERAL indicates that the node should be treated as a
50755075
* single static literal string that can be pushed onto the stack on its own.
50765076
* Note that this doesn't necessarily mean that the string will be frozen or
5077-
* not; the instructions in CRuby will be either putobject or putstring,
5077+
* not; the instructions in CRuby will be either putobject, dupstring or dupchilledstring,
50785078
* depending on the combination of `--enable-frozen-string-literal`,
50795079
* `# frozen_string_literal: true`, and whether or not there is interpolation.
50805080
*

prism_compile.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ pm_interpolated_node_compile(rb_iseq_t *iseq, const pm_node_list_t *parts, const
774774
if (frozen_result) {
775775
PUSH_INSN1(ret, current_location, putobject, current_string);
776776
} else if (mutable_result || interpolated) {
777-
PUSH_INSN1(ret, current_location, putstring, current_string);
777+
PUSH_INSN1(ret, current_location, dupstring, current_string);
778778
} else {
779-
PUSH_INSN1(ret, current_location, putchilledstring, current_string);
779+
PUSH_INSN1(ret, current_location, dupchilledstring, current_string);
780780
}
781781
} else {
782782
PUSH_INSN1(ret, current_location, putobject, current_string);
@@ -9677,10 +9677,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
96779677
PUSH_INSN1(ret, location, putobject, string);
96789678
}
96799679
else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9680-
PUSH_INSN1(ret, location, putstring, string);
9680+
PUSH_INSN1(ret, location, dupstring, string);
96819681
}
96829682
else {
9683-
PUSH_INSN1(ret, location, putchilledstring, string);
9683+
PUSH_INSN1(ret, location, dupchilledstring, string);
96849684
}
96859685
}
96869686
}
@@ -10395,10 +10395,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
1039510395
PUSH_INSN1(ret, location, putobject, string);
1039610396
}
1039710397
else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10398-
PUSH_INSN1(ret, location, putstring, string);
10398+
PUSH_INSN1(ret, location, dupstring, string);
1039910399
}
1040010400
else {
10401-
PUSH_INSN1(ret, location, putchilledstring, string);
10401+
PUSH_INSN1(ret, location, dupchilledstring, string);
1040210402
}
1040310403
}
1040410404
return;
@@ -10452,10 +10452,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
1045210452
PUSH_INSN1(ret, location, putobject, value);
1045310453
}
1045410454
else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10455-
PUSH_INSN1(ret, location, putstring, value);
10455+
PUSH_INSN1(ret, location, dupstring, value);
1045610456
}
1045710457
else {
10458-
PUSH_INSN1(ret, location, putchilledstring, value);
10458+
PUSH_INSN1(ret, location, dupchilledstring, value);
1045910459
}
1046010460
}
1046110461
return;

test/ruby/test_optimization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def test_peephole_string_literal_range
728728
insn = iseq.disasm
729729
assert_match %r{putobject\s+#{Regexp.quote('"1.8.0"..."1.8.8"')}}, insn
730730
assert_match %r{putobject\s+#{Regexp.quote('"2.0.0".."2.3.2"')}}, insn
731-
assert_no_match(/putstring/, insn)
731+
assert_no_match(/dupstring/, insn)
732732
assert_no_match(/newrange/, insn)
733733
end
734734
end

yjit/src/codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ fn gen_newhash(
27642764
Some(KeepCompiling)
27652765
}
27662766

2767-
fn gen_putstring(
2767+
fn gen_dupstring(
27682768
jit: &mut JITState,
27692769
asm: &mut Assembler,
27702770
) -> Option<CodegenStatus> {
@@ -2784,7 +2784,7 @@ fn gen_putstring(
27842784
Some(KeepCompiling)
27852785
}
27862786

2787-
fn gen_putchilledstring(
2787+
fn gen_dupchilledstring(
27882788
jit: &mut JITState,
27892789
asm: &mut Assembler,
27902790
) -> Option<CodegenStatus> {
@@ -10814,8 +10814,8 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
1081410814
YARVINSN_concattoarray => Some(gen_concattoarray),
1081510815
YARVINSN_pushtoarray => Some(gen_pushtoarray),
1081610816
YARVINSN_newrange => Some(gen_newrange),
10817-
YARVINSN_putstring => Some(gen_putstring),
10818-
YARVINSN_putchilledstring => Some(gen_putchilledstring),
10817+
YARVINSN_dupstring => Some(gen_dupstring),
10818+
YARVINSN_dupchilledstring => Some(gen_dupchilledstring),
1081910819
YARVINSN_expandarray => Some(gen_expandarray),
1082010820
YARVINSN_defined => Some(gen_defined),
1082110821
YARVINSN_definedivar => Some(gen_definedivar),

0 commit comments

Comments
 (0)