Skip to content

Commit 9fdf29c

Browse files
authored
Merge branch 'master' into zjit-env
2 parents 1dcc744 + a04555c commit 9fdf29c

35 files changed

Lines changed: 436 additions & 633 deletions

depend

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14598,7 +14598,6 @@ ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_newline_list.h
1459814598
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
1459914599
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
1460014600
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
14601-
ruby.$(OBJEXT): $(top_srcdir)/version.h
1460214601
ruby.$(OBJEXT): {$(VPATH)}assert.h
1460314602
ruby.$(OBJEXT): {$(VPATH)}atomic.h
1460414603
ruby.$(OBJEXT): {$(VPATH)}backward/2/assume.h
@@ -14782,7 +14781,6 @@ ruby.$(OBJEXT): {$(VPATH)}prism/ast.h
1478214781
ruby.$(OBJEXT): {$(VPATH)}prism/diagnostic.h
1478314782
ruby.$(OBJEXT): {$(VPATH)}prism/version.h
1478414783
ruby.$(OBJEXT): {$(VPATH)}prism_compile.h
14785-
ruby.$(OBJEXT): {$(VPATH)}revision.h
1478614784
ruby.$(OBJEXT): {$(VPATH)}ruby.c
1478714785
ruby.$(OBJEXT): {$(VPATH)}ruby_assert.h
1478814786
ruby.$(OBJEXT): {$(VPATH)}ruby_atomic.h

doc/ruby/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ $ ruby -n -e 'p $_' desiderata.txt
302302
"be on good terms with all persons.\n"
303303
```
304304

305-
With option `-l' (chopped):
305+
With option `-l` (chopped):
306306

307307
```console
308308
$ ruby -ln -e 'p $_' desiderata.txt

ext/win32/resolv/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'mkmf'
2-
if RUBY_ENGINE == "ruby" and have_library('iphlpapi', 'GetNetworkParams')
2+
if RUBY_ENGINE == "ruby" and have_library('iphlpapi', 'GetNetworkParams', ['windows.h', 'iphlpapi.h'])
33
create_makefile('win32/resolv')
44
else
55
File.write('Makefile', "all clean install:\n\t@echo Done: $(@)\n")

gc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ object_id(VALUE obj)
19211921
// in fields.
19221922
return class_object_id(obj);
19231923
case T_IMEMO:
1924-
rb_bug("T_IMEMO can't have an object_id");
1924+
RUBY_ASSERT(IMEMO_TYPE_P(obj, imemo_fields));
19251925
break;
19261926
default:
19271927
break;
@@ -1945,20 +1945,26 @@ build_id2ref_i(VALUE obj, void *data)
19451945
switch (BUILTIN_TYPE(obj)) {
19461946
case T_CLASS:
19471947
case T_MODULE:
1948+
RUBY_ASSERT(!rb_objspace_garbage_object_p(obj));
19481949
if (RCLASS(obj)->object_id) {
1949-
RUBY_ASSERT(!rb_objspace_garbage_object_p(obj));
19501950
st_insert(id2ref_tbl, RCLASS(obj)->object_id, obj);
19511951
}
19521952
break;
19531953
case T_IMEMO:
1954-
case T_NONE:
1954+
RUBY_ASSERT(!rb_objspace_garbage_object_p(obj));
1955+
if (IMEMO_TYPE_P(obj, imemo_fields) && rb_shape_obj_has_id(obj)) {
1956+
st_insert(id2ref_tbl, rb_obj_id(obj), rb_imemo_fields_owner(obj));
1957+
}
19551958
break;
1956-
default:
1959+
case T_OBJECT:
1960+
RUBY_ASSERT(!rb_objspace_garbage_object_p(obj));
19571961
if (rb_shape_obj_has_id(obj)) {
1958-
RUBY_ASSERT(!rb_objspace_garbage_object_p(obj));
19591962
st_insert(id2ref_tbl, rb_obj_id(obj), obj);
19601963
}
19611964
break;
1965+
default:
1966+
// For generic_fields, the T_IMEMO/fields is responsible for populating the entry.
1967+
break;
19621968
}
19631969
}
19641970

gc.rb

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,29 @@ def self.latest_gc_info hash_or_key = nil
383383
end
384384

385385
# call-seq:
386-
# GC.measure_total_time = true/false
386+
# GC.measure_total_time = setting -> setting
387387
#
388-
# Enables measuring \GC time.
389-
# You can get the result with <tt>GC.stat(:time)</tt>.
390-
# Note that \GC time measurement can cause some performance overhead.
388+
# Enables or disables \GC total time measurement;
389+
# returns +setting+.
390+
# See GC.total_time.
391+
#
392+
# When argument +object+ is +nil+ or +false+, disables total time measurement;
393+
# GC.measure_total_time then returns +false+:
394+
#
395+
# GC.measure_total_time = nil # => nil
396+
# GC.measure_total_time # => false
397+
# GC.measure_total_time = false # => false
398+
# GC.measure_total_time # => false
399+
#
400+
# Otherwise, enables total time measurement;
401+
# GC.measure_total_time then returns +true+:
402+
#
403+
# GC.measure_total_time = true # => true
404+
# GC.measure_total_time # => true
405+
# GC.measure_total_time = :foo # => :foo
406+
# GC.measure_total_time # => true
407+
#
408+
# Note that when enabled, total time measurement affects performance.
391409
def self.measure_total_time=(flag)
392410
Primitive.cstmt! %{
393411
rb_gc_impl_set_measure_total_time(rb_gc_get_objspace(), flag);
@@ -396,20 +414,47 @@ def self.measure_total_time=(flag)
396414
end
397415

398416
# call-seq:
399-
# GC.measure_total_time -> true/false
417+
# GC.measure_total_time -> true or false
400418
#
401-
# Returns the measure_total_time flag (default: +true+).
402-
# Note that measurement can affect the application's performance.
419+
# Returns the setting for \GC total time measurement;
420+
# the initial setting is +true+.
421+
# See GC.total_time.
403422
def self.measure_total_time
404423
Primitive.cexpr! %{
405424
RBOOL(rb_gc_impl_get_measure_total_time(rb_gc_get_objspace()))
406425
}
407426
end
408427

409428
# call-seq:
410-
# GC.total_time -> int
429+
# GC.total_time -> integer
430+
#
431+
# Returns the \GC total time in nanoseconds:
432+
#
433+
# GC.total_time # => 156250
434+
#
435+
# Note that total time accumulates
436+
# only when total time measurement is enabled
437+
# (that is, when GC.measure_total_time is +true+):
438+
#
439+
# GC.measure_total_time # => true
440+
# GC.total_time # => 625000
441+
# GC.start
442+
# GC.total_time # => 937500
443+
# GC.start
444+
# GC.total_time # => 1093750
445+
#
446+
# GC.measure_total_time = false
447+
# GC.total_time # => 1250000
448+
# GC.start
449+
# GC.total_time # => 1250000
450+
# GC.start
451+
# GC.total_time # => 1250000
452+
#
453+
# GC.measure_total_time = true
454+
# GC.total_time # => 1250000
455+
# GC.start
456+
# GC.total_time # => 1406250
411457
#
412-
# Returns the measured \GC total time in nanoseconds.
413458
def self.total_time
414459
Primitive.cexpr! %{
415460
ULL2NUM(rb_gc_impl_get_total_time(rb_gc_get_objspace()))

gems/bundled_gems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ostruct 0.6.3 https://github.com/ruby/ostruct
3939
pstore 0.2.0 https://github.com/ruby/pstore
4040
benchmark 0.4.1 https://github.com/ruby/benchmark
4141
logger 1.7.0 https://github.com/ruby/logger
42-
rdoc 6.14.2 https://github.com/ruby/rdoc f4a90c6010b2346cb5426d4496f5a37a136a82fb # for markdown
42+
rdoc 6.14.2 https://github.com/ruby/rdoc
4343
win32ole 1.9.2 https://github.com/ruby/win32ole
4444
irb 1.15.2 https://github.com/ruby/irb 331c4e851296b115db766c291e8cf54a2492fb36
4545
reline 0.6.2 https://github.com/ruby/reline

imemo.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,40 +109,40 @@ rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt)
109109
}
110110

111111
static VALUE
112-
imemo_fields_new(VALUE klass, size_t capa)
112+
imemo_fields_new(VALUE owner, size_t capa)
113113
{
114114
size_t embedded_size = offsetof(struct rb_fields, as.embed) + capa * sizeof(VALUE);
115115
if (rb_gc_size_allocatable_p(embedded_size)) {
116-
VALUE fields = rb_imemo_new(imemo_fields, klass, embedded_size);
116+
VALUE fields = rb_imemo_new(imemo_fields, owner, embedded_size);
117117
RUBY_ASSERT(IMEMO_TYPE_P(fields, imemo_fields));
118118
return fields;
119119
}
120120
else {
121-
VALUE fields = rb_imemo_new(imemo_fields, klass, sizeof(struct rb_fields));
121+
VALUE fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields));
122122
FL_SET_RAW(fields, OBJ_FIELD_EXTERNAL);
123123
IMEMO_OBJ_FIELDS(fields)->as.external.ptr = ALLOC_N(VALUE, capa);
124124
return fields;
125125
}
126126
}
127127

128128
VALUE
129-
rb_imemo_fields_new(VALUE klass, size_t capa)
129+
rb_imemo_fields_new(VALUE owner, size_t capa)
130130
{
131-
return imemo_fields_new(klass, capa);
131+
return imemo_fields_new(owner, capa);
132132
}
133133

134134
static VALUE
135-
imemo_fields_new_complex(VALUE klass, size_t capa)
135+
imemo_fields_new_complex(VALUE owner, size_t capa)
136136
{
137-
VALUE fields = imemo_fields_new(klass, sizeof(struct rb_fields));
137+
VALUE fields = imemo_fields_new(owner, sizeof(struct rb_fields));
138138
IMEMO_OBJ_FIELDS(fields)->as.complex.table = st_init_numtable_with_size(capa);
139139
return fields;
140140
}
141141

142142
VALUE
143-
rb_imemo_fields_new_complex(VALUE klass, size_t capa)
143+
rb_imemo_fields_new_complex(VALUE owner, size_t capa)
144144
{
145-
return imemo_fields_new_complex(klass, capa);
145+
return imemo_fields_new_complex(owner, capa);
146146
}
147147

148148
static int
@@ -161,9 +161,9 @@ imemo_fields_complex_wb_i(st_data_t key, st_data_t value, st_data_t arg)
161161
}
162162

163163
VALUE
164-
rb_imemo_fields_new_complex_tbl(VALUE klass, st_table *tbl)
164+
rb_imemo_fields_new_complex_tbl(VALUE owner, st_table *tbl)
165165
{
166-
VALUE fields = imemo_fields_new(klass, sizeof(struct rb_fields));
166+
VALUE fields = imemo_fields_new(owner, sizeof(struct rb_fields));
167167
IMEMO_OBJ_FIELDS(fields)->as.complex.table = tbl;
168168
st_foreach(tbl, imemo_fields_trigger_wb_i, (st_data_t)fields);
169169
return fields;
@@ -176,15 +176,15 @@ rb_imemo_fields_clone(VALUE fields_obj)
176176
VALUE clone;
177177

178178
if (rb_shape_too_complex_p(shape_id)) {
179-
clone = rb_imemo_fields_new_complex(CLASS_OF(fields_obj), 0);
179+
clone = rb_imemo_fields_new_complex(rb_imemo_fields_owner(fields_obj), 0);
180180
RBASIC_SET_SHAPE_ID(clone, shape_id);
181181
st_table *src_table = rb_imemo_fields_complex_tbl(fields_obj);
182182
st_table *dest_table = rb_imemo_fields_complex_tbl(clone);
183183
st_replace(dest_table, src_table);
184184
st_foreach(dest_table, imemo_fields_complex_wb_i, (st_data_t)clone);
185185
}
186186
else {
187-
clone = imemo_fields_new(CLASS_OF(fields_obj), RSHAPE_CAPACITY(shape_id));
187+
clone = imemo_fields_new(rb_imemo_fields_owner(fields_obj), RSHAPE_CAPACITY(shape_id));
188188
RBASIC_SET_SHAPE_ID(clone, shape_id);
189189
VALUE *fields = rb_imemo_fields_ptr(clone);
190190
attr_index_t fields_count = RSHAPE_LEN(shape_id);

internal/class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(VALUE obj)
546546
RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
547547
rb_classext_t *ext = RCLASS_EXT_WRITABLE(obj);
548548
if (!ext->fields_obj) {
549-
RB_OBJ_WRITE(obj, &ext->fields_obj, rb_imemo_fields_new(rb_singleton_class(obj), 1));
549+
RB_OBJ_WRITE(obj, &ext->fields_obj, rb_imemo_fields_new(obj, 1));
550550
}
551551
return ext->fields_obj;
552552
}

internal/imemo.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,18 @@ struct rb_fields {
273273
#define OBJ_FIELD_EXTERNAL IMEMO_FL_USER0
274274
#define IMEMO_OBJ_FIELDS(fields) ((struct rb_fields *)fields)
275275

276-
VALUE rb_imemo_fields_new(VALUE klass, size_t capa);
277-
VALUE rb_imemo_fields_new_complex(VALUE klass, size_t capa);
278-
VALUE rb_imemo_fields_new_complex_tbl(VALUE klass, st_table *tbl);
276+
VALUE rb_imemo_fields_new(VALUE owner, size_t capa);
277+
VALUE rb_imemo_fields_new_complex(VALUE owner, size_t capa);
278+
VALUE rb_imemo_fields_new_complex_tbl(VALUE owner, st_table *tbl);
279279
VALUE rb_imemo_fields_clone(VALUE fields_obj);
280280
void rb_imemo_fields_clear(VALUE fields_obj);
281281

282+
static inline VALUE
283+
rb_imemo_fields_owner(VALUE fields_obj)
284+
{
285+
return CLASS_OF(fields_obj);
286+
}
287+
282288
static inline VALUE *
283289
rb_imemo_fields_ptr(VALUE obj_fields)
284290
{

lib/prism/translation/parser/lexer.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,20 @@ def to_a
277277
when :tCOMMENT
278278
if token.type == :EMBDOC_BEGIN
279279

280-
while !((next_token = lexed[index][0]) && next_token.type == :EMBDOC_END) && (index < length - 1)
280+
while !((next_token = lexed[index]&.first) && next_token.type == :EMBDOC_END) && (index < length - 1)
281281
value += next_token.value
282282
index += 1
283283
end
284284

285285
value += next_token.value
286-
location = range(token.location.start_offset, lexed[index][0].location.end_offset)
286+
location = range(token.location.start_offset, next_token.location.end_offset)
287287
index += 1
288288
else
289289
is_at_eol = value.chomp!.nil?
290290
location = range(token.location.start_offset, token.location.end_offset + (is_at_eol ? 0 : -1))
291291

292-
prev_token = lexed[index - 2][0] if index - 2 >= 0
293-
next_token = lexed[index][0]
292+
prev_token, _ = lexed[index - 2] if index - 2 >= 0
293+
next_token, _ = lexed[index]
294294

295295
is_inline_comment = prev_token&.location&.start_line == token.location.start_line
296296
if is_inline_comment && !is_at_eol && !COMMENT_CONTINUATION_TYPES.include?(next_token&.type)
@@ -309,7 +309,7 @@ def to_a
309309
end
310310
end
311311
when :tNL
312-
next_token = next_token = lexed[index][0]
312+
next_token, _ = lexed[index]
313313
# Newlines after comments are emitted out of order.
314314
if next_token&.type == :COMMENT
315315
comment_newline_location = location
@@ -346,8 +346,8 @@ def to_a
346346
location = range(token.location.start_offset, token.location.start_offset + percent_array_leading_whitespace(value))
347347
value = nil
348348
when :tSTRING_BEG
349-
next_token = lexed[index][0]
350-
next_next_token = lexed[index + 1][0]
349+
next_token, _ = lexed[index]
350+
next_next_token, _ = lexed[index + 1]
351351
basic_quotes = value == '"' || value == "'"
352352

353353
if basic_quotes && next_token&.type == :STRING_END
@@ -415,7 +415,8 @@ def to_a
415415
while token.type == :STRING_CONTENT
416416
current_length += token.value.bytesize
417417
# Heredoc interpolation can have multiple STRING_CONTENT nodes on the same line.
418-
is_first_token_on_line = lexed[index - 1] && token.location.start_line != lexed[index - 2][0].location&.start_line
418+
prev_token, _ = lexed[index - 2] if index - 2 >= 0
419+
is_first_token_on_line = prev_token && token.location.start_line != prev_token.location.start_line
419420
# The parser gem only removes indentation when the heredoc is not nested
420421
not_nested = heredoc_stack.size == 1
421422
if is_percent_array
@@ -434,7 +435,7 @@ def to_a
434435
tokens << [:tSTRING_CONTENT, [current_string, range(start_offset, start_offset + current_length)]]
435436
break
436437
end
437-
token = lexed[index][0]
438+
token, _ = lexed[index]
438439
index += 1
439440
end
440441
else
@@ -489,7 +490,7 @@ def to_a
489490
end
490491

491492
if percent_array?(quote_stack.pop)
492-
prev_token = lexed[index - 2][0] if index - 2 >= 0
493+
prev_token, _ = lexed[index - 2] if index - 2 >= 0
493494
empty = %i[PERCENT_LOWER_I PERCENT_LOWER_W PERCENT_UPPER_I PERCENT_UPPER_W].include?(prev_token&.type)
494495
ends_with_whitespace = prev_token&.type == :WORDS_SEP
495496
# parser always emits a space token after content in a percent array, even if no actual whitespace is present.
@@ -498,7 +499,7 @@ def to_a
498499
end
499500
end
500501
when :tSYMBEG
501-
if (next_token = lexed[index][0]) && next_token.type != :STRING_CONTENT && next_token.type != :EMBEXPR_BEGIN && next_token.type != :EMBVAR && next_token.type != :STRING_END
502+
if (next_token = lexed[index]&.first) && next_token.type != :STRING_CONTENT && next_token.type != :EMBEXPR_BEGIN && next_token.type != :EMBVAR && next_token.type != :STRING_END
502503
next_location = token.location.join(next_token.location)
503504
type = :tSYMBOL
504505
value = next_token.value
@@ -513,13 +514,13 @@ def to_a
513514
type = :tIDENTIFIER
514515
end
515516
when :tXSTRING_BEG
516-
if (next_token = lexed[index][0]) && !%i[STRING_CONTENT STRING_END EMBEXPR_BEGIN].include?(next_token.type)
517+
if (next_token = lexed[index]&.first) && !%i[STRING_CONTENT STRING_END EMBEXPR_BEGIN].include?(next_token.type)
517518
# self.`()
518519
type = :tBACK_REF2
519520
end
520521
quote_stack.push(value)
521522
when :tSYMBOLS_BEG, :tQSYMBOLS_BEG, :tWORDS_BEG, :tQWORDS_BEG
522-
if (next_token = lexed[index][0]) && next_token.type == :WORDS_SEP
523+
if (next_token = lexed[index]&.first) && next_token.type == :WORDS_SEP
523524
index += 1
524525
end
525526

@@ -595,9 +596,9 @@ def calculate_heredoc_whitespace(heredoc_token_index)
595596
previous_line = -1
596597
result = Float::MAX
597598

598-
while (lexed[next_token_index] && next_token = lexed[next_token_index][0])
599+
while (next_token = lexed[next_token_index]&.first)
599600
next_token_index += 1
600-
next_next_token = lexed[next_token_index] && lexed[next_token_index][0]
601+
next_next_token, _ = lexed[next_token_index]
601602
first_token_on_line = next_token.location.start_column == 0
602603

603604
# String content inside nested heredocs and interpolation is ignored

0 commit comments

Comments
 (0)