rbs 3.9.5 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/ruby.yml +34 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/CHANGELOG.md +49 -0
  11. data/README.md +38 -1
  12. data/Rakefile +152 -23
  13. data/config.yml +190 -62
  14. data/core/array.rbs +100 -46
  15. data/core/complex.rbs +32 -21
  16. data/core/dir.rbs +2 -2
  17. data/core/encoding.rbs +6 -9
  18. data/core/enumerable.rbs +90 -3
  19. data/core/enumerator.rbs +18 -1
  20. data/core/errno.rbs +8 -0
  21. data/core/errors.rbs +28 -1
  22. data/core/exception.rbs +2 -2
  23. data/core/fiber.rbs +5 -4
  24. data/core/file.rbs +27 -12
  25. data/core/file_test.rbs +1 -1
  26. data/core/float.rbs +209 -22
  27. data/core/gc.rbs +417 -281
  28. data/core/hash.rbs +1024 -727
  29. data/core/integer.rbs +78 -38
  30. data/core/io/buffer.rbs +18 -7
  31. data/core/io/wait.rbs +11 -33
  32. data/core/io.rbs +14 -12
  33. data/core/kernel.rbs +57 -51
  34. data/core/marshal.rbs +1 -1
  35. data/core/match_data.rbs +1 -1
  36. data/core/math.rbs +42 -3
  37. data/core/method.rbs +14 -6
  38. data/core/module.rbs +88 -17
  39. data/core/nil_class.rbs +3 -3
  40. data/core/numeric.rbs +16 -16
  41. data/core/object.rbs +3 -3
  42. data/core/object_space.rbs +21 -15
  43. data/{stdlib/pathname/0 → core}/pathname.rbs +255 -355
  44. data/core/proc.rbs +15 -8
  45. data/core/process.rbs +2 -2
  46. data/core/ractor.rbs +278 -437
  47. data/core/range.rbs +7 -8
  48. data/core/rational.rbs +37 -24
  49. data/core/rbs/unnamed/argf.rbs +2 -2
  50. data/core/rbs/unnamed/env_class.rbs +1 -1
  51. data/core/rbs/unnamed/random.rbs +4 -2
  52. data/core/regexp.rbs +25 -20
  53. data/core/ruby.rbs +53 -0
  54. data/core/ruby_vm.rbs +6 -4
  55. data/core/rubygems/errors.rbs +3 -70
  56. data/core/rubygems/rubygems.rbs +11 -79
  57. data/core/rubygems/version.rbs +2 -3
  58. data/core/set.rbs +488 -359
  59. data/core/string.rbs +3145 -1231
  60. data/core/struct.rbs +1 -1
  61. data/core/symbol.rbs +4 -4
  62. data/core/thread.rbs +92 -29
  63. data/core/time.rbs +35 -9
  64. data/core/trace_point.rbs +7 -4
  65. data/core/unbound_method.rbs +14 -6
  66. data/docs/aliases.md +79 -0
  67. data/docs/collection.md +2 -2
  68. data/docs/encoding.md +56 -0
  69. data/docs/gem.md +0 -1
  70. data/docs/sigs.md +3 -3
  71. data/ext/rbs_extension/ast_translation.c +1016 -0
  72. data/ext/rbs_extension/ast_translation.h +37 -0
  73. data/ext/rbs_extension/class_constants.c +155 -0
  74. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  75. data/ext/rbs_extension/compat.h +10 -0
  76. data/ext/rbs_extension/extconf.rb +25 -1
  77. data/ext/rbs_extension/legacy_location.c +317 -0
  78. data/ext/rbs_extension/legacy_location.h +45 -0
  79. data/ext/rbs_extension/main.c +357 -14
  80. data/ext/rbs_extension/rbs_extension.h +6 -21
  81. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  82. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  83. data/include/rbs/ast.h +687 -0
  84. data/include/rbs/defines.h +86 -0
  85. data/include/rbs/lexer.h +199 -0
  86. data/include/rbs/location.h +59 -0
  87. data/include/rbs/parser.h +135 -0
  88. data/include/rbs/string.h +47 -0
  89. data/include/rbs/util/rbs_allocator.h +59 -0
  90. data/include/rbs/util/rbs_assert.h +20 -0
  91. data/include/rbs/util/rbs_buffer.h +83 -0
  92. data/include/rbs/util/rbs_constant_pool.h +6 -67
  93. data/include/rbs/util/rbs_encoding.h +282 -0
  94. data/include/rbs/util/rbs_unescape.h +24 -0
  95. data/include/rbs.h +1 -2
  96. data/lib/rbs/annotate/formatter.rb +3 -13
  97. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  98. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  99. data/lib/rbs/cli/validate.rb +2 -2
  100. data/lib/rbs/cli.rb +1 -1
  101. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  102. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  103. data/lib/rbs/environment.rb +64 -59
  104. data/lib/rbs/environment_loader.rb +1 -1
  105. data/lib/rbs/errors.rb +1 -1
  106. data/lib/rbs/parser_aux.rb +5 -0
  107. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  108. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  109. data/lib/rbs/test/type_check.rb +14 -0
  110. data/lib/rbs/types.rb +3 -1
  111. data/lib/rbs/version.rb +1 -1
  112. data/lib/rbs.rb +1 -1
  113. data/lib/rdoc/discover.rb +1 -1
  114. data/lib/rdoc_plugin/parser.rb +3 -3
  115. data/sig/annotate/formatter.rbs +2 -2
  116. data/sig/annotate/rdoc_annotater.rbs +1 -1
  117. data/sig/environment.rbs +57 -6
  118. data/sig/manifest.yaml +0 -1
  119. data/sig/parser.rbs +20 -0
  120. data/sig/resolver/type_name_resolver.rbs +38 -7
  121. data/sig/types.rbs +4 -1
  122. data/src/ast.c +1256 -0
  123. data/src/lexer.c +2956 -0
  124. data/src/lexer.re +147 -0
  125. data/src/lexstate.c +205 -0
  126. data/src/location.c +71 -0
  127. data/src/parser.c +3507 -0
  128. data/src/string.c +41 -0
  129. data/src/util/rbs_allocator.c +152 -0
  130. data/src/util/rbs_assert.c +19 -0
  131. data/src/util/rbs_buffer.c +54 -0
  132. data/src/util/rbs_constant_pool.c +18 -88
  133. data/src/util/rbs_encoding.c +21308 -0
  134. data/src/util/rbs_unescape.c +167 -0
  135. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  136. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  137. data/stdlib/cgi/0/core.rbs +2 -396
  138. data/stdlib/cgi/0/manifest.yaml +1 -0
  139. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  140. data/stdlib/coverage/0/coverage.rbs +3 -1
  141. data/stdlib/date/0/date.rbs +67 -59
  142. data/stdlib/date/0/date_time.rbs +1 -1
  143. data/stdlib/delegate/0/delegator.rbs +10 -7
  144. data/stdlib/erb/0/erb.rbs +737 -347
  145. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  146. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  147. data/stdlib/json/0/json.rbs +68 -48
  148. data/stdlib/net-http/0/net-http.rbs +3 -0
  149. data/stdlib/objspace/0/objspace.rbs +9 -4
  150. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  151. data/stdlib/openssl/0/openssl.rbs +331 -228
  152. data/stdlib/optparse/0/optparse.rbs +3 -3
  153. data/stdlib/psych/0/psych.rbs +3 -3
  154. data/stdlib/rdoc/0/code_object.rbs +2 -2
  155. data/stdlib/rdoc/0/comment.rbs +2 -0
  156. data/stdlib/rdoc/0/options.rbs +76 -0
  157. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  158. data/stdlib/rdoc/0/store.rbs +1 -1
  159. data/stdlib/resolv/0/resolv.rbs +25 -68
  160. data/stdlib/ripper/0/ripper.rbs +5 -2
  161. data/stdlib/singleton/0/singleton.rbs +3 -0
  162. data/stdlib/socket/0/socket.rbs +13 -1
  163. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  164. data/stdlib/stringio/0/stringio.rbs +1176 -85
  165. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  166. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  167. data/stdlib/time/0/time.rbs +1 -1
  168. data/stdlib/timeout/0/timeout.rbs +63 -7
  169. data/stdlib/tsort/0/cyclic.rbs +3 -0
  170. data/stdlib/uri/0/common.rbs +11 -2
  171. data/stdlib/uri/0/file.rbs +1 -1
  172. data/stdlib/uri/0/generic.rbs +17 -16
  173. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  174. data/stdlib/zlib/0/zstream.rbs +1 -0
  175. metadata +43 -18
  176. data/ext/rbs_extension/lexer.c +0 -2728
  177. data/ext/rbs_extension/lexer.h +0 -179
  178. data/ext/rbs_extension/lexer.re +0 -147
  179. data/ext/rbs_extension/lexstate.c +0 -175
  180. data/ext/rbs_extension/location.c +0 -325
  181. data/ext/rbs_extension/location.h +0 -85
  182. data/ext/rbs_extension/parser.c +0 -2982
  183. data/ext/rbs_extension/parser.h +0 -18
  184. data/ext/rbs_extension/parserstate.c +0 -411
  185. data/ext/rbs_extension/parserstate.h +0 -163
  186. data/ext/rbs_extension/unescape.c +0 -32
  187. data/include/rbs/ruby_objs.h +0 -72
  188. data/src/constants.c +0 -153
  189. data/src/ruby_objs.c +0 -799
data/core/gc.rbs CHANGED
@@ -160,81 +160,65 @@ module GC
160
160
  # <!--
161
161
  # rdoc-file=gc.rb
162
162
  # - GC.config -> hash
163
- # - GC.config(hash) -> hash
163
+ # - GC.config(hash_to_merge) -> hash
164
164
  # -->
165
- # Sets or gets information about the current GC config.
165
+ # This method is implementation-specific to CRuby.
166
+ #
167
+ # Sets or gets information about the current GC configuration.
166
168
  #
167
169
  # Configuration parameters are GC implementation-specific and may change without
168
170
  # notice.
169
171
  #
170
- # This method can be called without parameters to retrieve the current config as
171
- # a `Hash` with `Symbol` keys.
172
- #
173
- # This method can also be called with a `Hash` argument to assign values to
174
- # valid config keys. Config keys missing from the passed `Hash` will be left
175
- # unmodified.
176
- #
177
- # If a key/value pair is passed to this function that does not correspond to a
178
- # valid config key for the GC implementation being used, no config will be
179
- # updated, the key will be present in the returned Hash, and its value will be
180
- # `nil`. This is to facilitate easy migration between GC implementations.
181
- #
182
- # In both call-seqs, the return value of `GC.config` will be a `Hash` containing
183
- # the most recent full configuration, i.e., all keys and values defined by the
184
- # specific GC implementation being used. In the case of a config update, the
185
- # return value will include the new values being updated.
186
- #
187
- # This method is only expected to work on CRuby.
172
+ # With no argument given, returns a hash containing the configuration:
188
173
  #
189
- # ### GC Implementation independent values
174
+ # GC.config
175
+ # # => {rgengc_allow_full_mark: true, implementation: "default"}
190
176
  #
191
- # The `GC.config` hash can also contain keys that are global and read-only.
192
- # These keys are not specific to any one GC library implementation and
193
- # attempting to write to them will raise `ArgumentError`.
177
+ # With argument `hash_to_merge` given, merges that hash into the stored
178
+ # configuration hash; ignores unknown hash keys; returns the configuration hash:
194
179
  #
195
- # There is currently only one global, read-only key:
180
+ # GC.config(rgengc_allow_full_mark: false)
181
+ # # => {rgengc_allow_full_mark: false, implementation: "default"}
182
+ # GC.config(foo: 'bar')
183
+ # # => {rgengc_allow_full_mark: false, implementation: "default"}
196
184
  #
197
- # implementation
198
- # : Returns a `String` containing the name of the currently loaded GC library,
199
- # if one has been loaded using `RUBY_GC_LIBRARY`, and "default" in all other
200
- # cases
185
+ # **All-Implementations Configuration**
201
186
  #
187
+ # The single read-only entry for all implementations is:
202
188
  #
203
- # ### GC Implementation specific values
189
+ # * `:implementation`: the string name of the implementation; for the Ruby
190
+ # default implementation, `'default'`.
204
191
  #
205
- # GC libraries are expected to document their own configuration. Valid keys for
206
- # Ruby's default GC implementation are:
192
+ # **Implementation-Specific Configuration**
207
193
  #
208
- # rgengc_allow_full_mark
209
- # : Controls whether the GC is allowed to run a full mark (young & old
210
- # objects).
194
+ # A GC implementation maintains its own implementation-specific configuration.
211
195
  #
212
- # When `true`, GC interleaves major and minor collections. This is the
213
- # default. GC will function as intended.
196
+ # For Ruby's default implementation the single entry is:
214
197
  #
215
- # When `false`, the GC will never trigger a full marking cycle unless
216
- # explicitly requested by user code. Instead, only a minor mark will
217
- # run—only young objects will be marked. When the heap space is exhausted,
218
- # new pages will be allocated immediately instead of running a full mark.
198
+ # * `:rgengc_allow_full_mark`: Controls whether the GC is allowed to run a
199
+ # full mark (young & old objects):
219
200
  #
220
- # A flag will be set to notify that a full mark has been requested. This
221
- # flag is accessible using `GC.latest_gc_info(:needs_major_by)`
222
- #
223
- # The user can trigger a major collection at any time using
224
- # `GC.start(full_mark: true)`
225
- #
226
- # When `false`, Young to Old object promotion is disabled. For performance
227
- # reasons, it is recommended to warm up an application using
228
- # `Process.warmup` before setting this parameter to `false`.
201
+ # * `true` (default): GC interleaves major and minor collections. A flag
202
+ # is set to notify GC that a full mark has been requested. This flag is
203
+ # accessible via GC.latest_gc_info(:need_major_by).
204
+ # * `false`: GC does not initiate a full marking cycle unless explicitly
205
+ # directed by user code; see GC.start. Setting this parameter to `false`
206
+ # disables young-to-old promotion. For performance reasons, we
207
+ # recommended warming up the application using Process.warmup before
208
+ # setting this parameter to `false`.
229
209
  #
230
210
  def self.config: () -> Hash[Symbol, untyped]
231
211
  | (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
232
212
 
233
213
  # <!--
234
214
  # rdoc-file=gc.rb
235
- # - GC.count -> Integer
215
+ # - self.count -> integer
236
216
  # -->
237
- # Returns the number of times GC has occurred since the process started.
217
+ # Returns the total number of times garbage collection has occurred:
218
+ #
219
+ # GC.count # => 385
220
+ # GC.start
221
+ # GC.count # => 386
238
222
  #
239
223
  def self.count: () -> Integer
240
224
 
@@ -242,11 +226,12 @@ module GC
242
226
  # rdoc-file=gc.rb
243
227
  # - GC.disable -> true or false
244
228
  # -->
245
- # Disables garbage collection, returning `true` if garbage collection was
246
- # already disabled.
229
+ # Disables garbage collection (but GC.start remains potent): returns whether
230
+ # garbage collection was already disabled.
247
231
  #
248
- # GC.disable #=> false
249
- # GC.disable #=> true
232
+ # GC.enable
233
+ # GC.disable # => false
234
+ # GC.disable # => true
250
235
  #
251
236
  def self.disable: () -> bool
252
237
 
@@ -254,12 +239,11 @@ module GC
254
239
  # rdoc-file=gc.rb
255
240
  # - GC.enable -> true or false
256
241
  # -->
257
- # Enables garbage collection, returning `true` if garbage collection was
258
- # previously disabled.
242
+ # Enables garbage collection; returns whether garbage collection was disabled:
259
243
  #
260
- # GC.disable #=> false
261
- # GC.enable #=> true
262
- # GC.enable #=> false
244
+ # GC.disable
245
+ # GC.enable # => true
246
+ # GC.enable # => false
263
247
  #
264
248
  def self.enable: () -> bool
265
249
 
@@ -267,161 +251,193 @@ module GC
267
251
  # rdoc-file=gc.rb
268
252
  # - start(full_mark: true, immediate_mark: true, immediate_sweep: true)
269
253
  # -->
270
- # Initiates garbage collection, even if manually disabled.
271
- #
272
- # The `full_mark` keyword argument determines whether or not to perform a major
273
- # garbage collection cycle. When set to `true`, a major garbage collection cycle
274
- # is run, meaning all objects are marked. When set to `false`, a minor garbage
275
- # collection cycle is run, meaning only young objects are marked.
276
- #
277
- # The `immediate_mark` keyword argument determines whether or not to perform
278
- # incremental marking. When set to `true`, marking is completed during the call
279
- # to this method. When set to `false`, marking is performed in steps that are
280
- # interleaved with future Ruby code execution, so marking might not be completed
281
- # during this method call. Note that if `full_mark` is `false`, then marking
282
- # will always be immediate, regardless of the value of `immediate_mark`.
283
- #
284
- # The `immediate_sweep` keyword argument determines whether or not to defer
285
- # sweeping (using lazy sweep). When set to `false`, sweeping is performed in
286
- # steps that are interleaved with future Ruby code execution, so sweeping might
287
- # not be completed during this method call. When set to `true`, sweeping is
288
- # completed during the call to this method.
289
- #
290
- # Note: These keyword arguments are implementation and version-dependent. They
291
- # are not guaranteed to be future-compatible and may be ignored if the
292
- # underlying implementation does not support them.
293
- #
294
- def self.start: (?immediate_sweep: boolish, ?immediate_mark: boolish, ?full_mark: boolish) -> nil
295
-
296
- # <!--
297
- # rdoc-file=gc.rb
298
- # - GC.stat -> Hash
299
- # - GC.stat(hash) -> Hash
300
- # - GC.stat(:key) -> Numeric
301
- # -->
302
- # Returns a Hash containing information about the GC.
303
- #
304
- # The contents of the hash are implementation-specific and may change in the
305
- # future without notice.
306
- #
307
- # The hash includes internal statistics about GC such as:
308
- #
309
- # count
310
- # : The total number of garbage collections run since application start (count
311
- # includes both minor and major garbage collections)
312
- #
313
- # time
314
- # : The total time spent in garbage collections (in milliseconds)
315
- #
316
- # heap_allocated_pages
317
- # : The total number of `:heap_eden_pages` + `:heap_tomb_pages`
318
- #
319
- # heap_sorted_length
320
- # : The number of pages that can fit into the buffer that holds references to
321
- # all pages
322
- #
323
- # heap_allocatable_pages
324
- # : The total number of pages the application could allocate without
325
- # additional GC
326
- #
327
- # heap_available_slots
328
- # : The total number of slots in all `:heap_allocated_pages`
329
- #
330
- # heap_live_slots
331
- # : The total number of slots which contain live objects
332
- #
333
- # heap_free_slots
334
- # : The total number of slots which do not contain live objects
335
- #
336
- # heap_final_slots
337
- # : The total number of slots with pending finalizers to be run
338
- #
339
- # heap_marked_slots
340
- # : The total number of objects marked in the last GC
341
- #
342
- # heap_eden_pages
343
- # : The total number of pages which contain at least one live slot
344
- #
345
- # heap_tomb_pages
346
- # : The total number of pages which do not contain any live slots
347
- #
348
- # total_allocated_pages
349
- # : The cumulative number of pages allocated since application start
350
- #
351
- # total_freed_pages
352
- # : The cumulative number of pages freed since application start
353
- #
354
- # total_allocated_objects
355
- # : The cumulative number of objects allocated since application start
356
- #
357
- # total_freed_objects
358
- # : The cumulative number of objects freed since application start
359
- #
360
- # malloc_increase_bytes
361
- # : Amount of memory allocated on the heap for objects. Decreased by any GC
362
- #
363
- # malloc_increase_bytes_limit
364
- # : When `:malloc_increase_bytes` crosses this limit, GC is triggered
365
- #
366
- # minor_gc_count
367
- # : The total number of minor garbage collections run since process start
368
- #
369
- # major_gc_count
370
- # : The total number of major garbage collections run since process start
371
- #
372
- # compact_count
373
- # : The total number of compactions run since process start
374
- #
375
- # read_barrier_faults
376
- # : The total number of times the read barrier was triggered during compaction
377
- #
378
- # total_moved_objects
379
- # : The total number of objects compaction has moved
254
+ # Initiates garbage collection, even if explicitly disabled by GC.disable.
380
255
  #
381
- # remembered_wb_unprotected_objects
382
- # : The total number of objects without write barriers
256
+ # Keyword arguments:
383
257
  #
384
- # remembered_wb_unprotected_objects_limit
385
- # : When `:remembered_wb_unprotected_objects` crosses this limit, major GC is
386
- # triggered
258
+ # * `full_mark`: its boolean value determines whether to perform a major
259
+ # garbage collection cycle:
387
260
  #
388
- # old_objects
389
- # : Number of live, old objects which have survived at least 3 garbage
390
- # collections
261
+ # * `true`: initiates a major garbage collection cycle, meaning all
262
+ # objects (old and new) are marked.
263
+ # * `false`: initiates a minor garbage collection cycle, meaning only
264
+ # young objects are marked.
391
265
  #
392
- # old_objects_limit
393
- # : When `:old_objects` crosses this limit, major GC is triggered
266
+ # * `immediate_mark`: its boolean value determines whether to perform
267
+ # incremental marking:
394
268
  #
395
- # oldmalloc_increase_bytes
396
- # : Amount of memory allocated on the heap for objects. Decreased by major GC
269
+ # * `true`: marking is completed before the method returns.
270
+ # * `false`: marking is performed by parts, interleaved with program
271
+ # execution both before the method returns and afterward; therefore
272
+ # marking may not be completed before the return. Note that if
273
+ # `full_mark` is `false`, marking will always be immediate, regardless
274
+ # of the value of `immediate_mark`.
397
275
  #
398
- # oldmalloc_increase_bytes_limit
399
- # : When `:oldmalloc_increase_bytes` crosses this limit, major GC is triggered
276
+ # * `immediate_sweep`: its boolean value determines whether to defer sweeping
277
+ # (using lazy sweep):
400
278
  #
279
+ # * `true`: sweeping is completed before the method returns.
280
+ # * `false`: sweeping is performed by parts, interleaved with program
281
+ # execution both before the method returns and afterward; therefore
282
+ # sweeping may not be completed before the return.
401
283
  #
402
- # If the optional argument, hash, is given, it is overwritten and returned. This
403
- # is intended to avoid the probe effect.
284
+ # Note that these keyword arguments are implementation- and version-dependent,
285
+ # are not guaranteed to be future-compatible, and may be ignored in some
286
+ # implementations.
404
287
  #
405
- # This method is only expected to work on CRuby.
288
+ def self.start: (?immediate_sweep: boolish, ?immediate_mark: boolish, ?full_mark: boolish) -> nil
289
+
290
+ # <!--
291
+ # rdoc-file=gc.rb
292
+ # - GC.stat -> new_hash
293
+ # - GC.stat(key) -> value
294
+ # - GC.stat(hash) -> hash
295
+ # -->
296
+ # This method is implementation-specific to CRuby.
297
+ #
298
+ # Returns GC statistics. The particular statistics are implementation-specific
299
+ # and may change in the future without notice.
300
+ #
301
+ # With no argument given, returns information about the most recent garbage
302
+ # collection:
303
+ #
304
+ # GC.stat
305
+ # # =>
306
+ # {count: 28,
307
+ # time: 1,
308
+ # marking_time: 1,
309
+ # sweeping_time: 0,
310
+ # heap_allocated_pages: 521,
311
+ # heap_empty_pages: 0,
312
+ # heap_allocatable_slots: 0,
313
+ # heap_available_slots: 539590,
314
+ # heap_live_slots: 422243,
315
+ # heap_free_slots: 117347,
316
+ # heap_final_slots: 0,
317
+ # heap_marked_slots: 264877,
318
+ # heap_eden_pages: 521,
319
+ # total_allocated_pages: 521,
320
+ # total_freed_pages: 0,
321
+ # total_allocated_objects: 2246376,
322
+ # total_freed_objects: 1824133,
323
+ # malloc_increase_bytes: 50982,
324
+ # malloc_increase_bytes_limit: 18535172,
325
+ # minor_gc_count: 18,
326
+ # major_gc_count: 10,
327
+ # compact_count: 0,
328
+ # read_barrier_faults: 0,
329
+ # total_moved_objects: 0,
330
+ # remembered_wb_unprotected_objects: 0,
331
+ # remembered_wb_unprotected_objects_limit: 2162,
332
+ # old_objects: 216365,
333
+ # old_objects_limit: 432540,
334
+ # oldmalloc_increase_bytes: 1654232,
335
+ # oldmalloc_increase_bytes_limit: 16846103}
336
+ #
337
+ # With symbol argument `key` given, returns the value for that key:
338
+ #
339
+ # GC.stat(:count) # => 30
340
+ #
341
+ # With hash argument `hash` given, returns that hash with GC statistics merged
342
+ # into its content; this form may be useful in minimizing [probe
343
+ # effects](https://en.wikipedia.org/wiki/Probe_effect):
344
+ #
345
+ # h = {foo: 0, bar: 1}
346
+ # GC.stat(h)
347
+ # h.keys.take(5) # => [:foo, :bar, :count, :time, :marking_time]
348
+ #
349
+ # The hash includes entries such as:
350
+ #
351
+ # * `:count`: The total number of garbage collections run since application
352
+ # start (count includes both minor and major garbage collections).
353
+ # * `:time`: The total time spent in garbage collections (in milliseconds).
354
+ # * `:heap_allocated_pages`: The total number of allocated pages.
355
+ # * `:heap_empty_pages`: The number of pages with no live objects, and that
356
+ # could be released to the system.
357
+ # * `:heap_sorted_length`: The number of pages that can fit into the buffer
358
+ # that holds references to all pages.
359
+ # * `:heap_allocatable_pages`: The total number of pages the application could
360
+ # allocate without additional GC.
361
+ # * `:heap_available_slots`: The total number of slots in all
362
+ # `:heap_allocated_pages`.
363
+ # * `:heap_live_slots`: The total number of slots which contain live objects.
364
+ # * `:heap_free_slots`: The total number of slots which do not contain live
365
+ # objects.
366
+ # * `:heap_final_slots`: The total number of slots with pending finalizers to
367
+ # be run.
368
+ # * `:heap_marked_slots`: The total number of objects marked in the last GC.
369
+ # * `:heap_eden_pages`: The total number of pages which contain at least one
370
+ # live slot.
371
+ # * `:total_allocated_pages`: The cumulative number of pages allocated since
372
+ # application start.
373
+ # * `:total_freed_pages`: The cumulative number of pages freed since
374
+ # application start.
375
+ # * `:total_allocated_objects`: The cumulative number of objects allocated
376
+ # since application start.
377
+ # * `:total_freed_objects`: The cumulative number of objects freed since
378
+ # application start.
379
+ # * `:malloc_increase_bytes`: Amount of memory allocated on the heap for
380
+ # objects. Decreased by any GC.
381
+ # * `:malloc_increase_bytes_limit`: When `:malloc_increase_bytes` crosses this
382
+ # limit, GC is triggered.
383
+ # * `:minor_gc_count`: The total number of minor garbage collections run since
384
+ # process start.
385
+ # * `:major_gc_count`: The total number of major garbage collections run since
386
+ # process start.
387
+ # * `:compact_count`: The total number of compactions run since process start.
388
+ # * `:read_barrier_faults`: The total number of times the read barrier was
389
+ # triggered during compaction.
390
+ # * `:total_moved_objects`: The total number of objects compaction has moved.
391
+ # * `:remembered_wb_unprotected_objects`: The total number of objects without
392
+ # write barriers.
393
+ # * `:remembered_wb_unprotected_objects_limit`: When
394
+ # `:remembered_wb_unprotected_objects` crosses this limit, major GC is
395
+ # triggered.
396
+ # * `:old_objects`: Number of live, old objects which have survived at least 3
397
+ # garbage collections.
398
+ # * `:old_objects_limit`: When `:old_objects` crosses this limit, major GC is
399
+ # triggered.
400
+ # * `:oldmalloc_increase_bytes`: Amount of memory allocated on the heap for
401
+ # objects. Decreased by major GC.
402
+ # * `:oldmalloc_increase_bytes_limit`: When `:oldmalloc_increase_bytes`
403
+ # crosses this limit, major GC is triggered.
406
404
  #
407
405
  def self.stat: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
408
406
  | (Symbol key) -> Integer
409
407
 
410
408
  # <!--
411
409
  # rdoc-file=gc.rb
412
- # - GC.measure_total_time = true/false
410
+ # - GC.measure_total_time = setting -> setting
413
411
  # -->
414
- # Enables measuring GC time. You can get the result with `GC.stat(:time)`. Note
415
- # that GC time measurement can cause some performance overhead.
412
+ # Enables or disables GC total time measurement; returns `setting`. See
413
+ # GC.total_time.
414
+ #
415
+ # When argument `object` is `nil` or `false`, disables total time measurement;
416
+ # GC.measure_total_time then returns `false`:
417
+ #
418
+ # GC.measure_total_time = nil # => nil
419
+ # GC.measure_total_time # => false
420
+ # GC.measure_total_time = false # => false
421
+ # GC.measure_total_time # => false
422
+ #
423
+ # Otherwise, enables total time measurement; GC.measure_total_time then returns
424
+ # `true`:
425
+ #
426
+ # GC.measure_total_time = true # => true
427
+ # GC.measure_total_time # => true
428
+ # GC.measure_total_time = :foo # => :foo
429
+ # GC.measure_total_time # => true
430
+ #
431
+ # Note that when enabled, total time measurement affects performance.
416
432
  #
417
433
  def self.measure_total_time=: [T] (T enable) -> T
418
434
 
419
435
  # <!--
420
436
  # rdoc-file=gc.rb
421
- # - GC.measure_total_time -> true/false
437
+ # - GC.measure_total_time -> true or false
422
438
  # -->
423
- # Returns the measure_total_time flag (default: `true`). Note that measurement
424
- # can affect the application's performance.
439
+ # Returns the setting for GC total time measurement; the initial setting is
440
+ # `true`. See GC.total_time.
425
441
  #
426
442
  def self.measure_total_time: () -> bool
427
443
 
@@ -447,71 +463,133 @@ module GC
447
463
 
448
464
  # <!--
449
465
  # rdoc-file=gc.rb
450
- # - GC.stat_heap -> Hash
451
- # - GC.stat_heap(nil, hash) -> Hash
452
- # - GC.stat_heap(heap_name) -> Hash
453
- # - GC.stat_heap(heap_name, hash) -> Hash
454
- # - GC.stat_heap(heap_name, :key) -> Numeric
466
+ # - GC.stat_heap -> new_hash
467
+ # - GC.stat_heap(heap_id) -> new_hash
468
+ # - GC.stat_heap(heap_id, key) -> value
469
+ # - GC.stat_heap(nil, hash) -> hash
470
+ # - GC.stat_heap(heap_id, hash) -> hash
455
471
  # -->
456
- # Returns information for heaps in the GC.
457
- #
458
- # If the first optional argument, `heap_name`, is passed in and not `nil`, it
459
- # returns a `Hash` containing information about the particular heap. Otherwise,
460
- # it will return a `Hash` with heap names as keys and a `Hash` containing
461
- # information about the heap as values.
462
- #
463
- # If the second optional argument, `hash_or_key`, is given as a `Hash`, it will
464
- # be overwritten and returned. This is intended to avoid the probe effect.
465
- #
466
- # If both optional arguments are passed in and the second optional argument is a
467
- # symbol, it will return a `Numeric` value for the particular heap.
468
- #
469
- # On CRuby, `heap_name` is of the type `Integer` but may be of type `String` on
470
- # other implementations.
471
- #
472
- # The contents of the hash are implementation-specific and may change in the
473
- # future without notice.
474
- #
475
- # If the optional argument, hash, is given, it is overwritten and returned.
476
- #
477
- # This method is only expected to work on CRuby.
478
- #
479
- # The hash includes the following keys about the internal information in the GC:
480
- #
481
- # slot_size
482
- # : The slot size of the heap in bytes.
483
- #
484
- # heap_allocatable_pages
485
- # : The number of pages that can be allocated without triggering a new garbage
486
- # collection cycle.
487
- #
488
- # heap_eden_pages
489
- # : The number of pages in the eden heap.
490
- #
491
- # heap_eden_slots
492
- # : The total number of slots in all of the pages in the eden heap.
493
- #
494
- # heap_tomb_pages
495
- # : The number of pages in the tomb heap. The tomb heap only contains pages
496
- # that do not have any live objects.
497
- #
498
- # heap_tomb_slots
499
- # : The total number of slots in all of the pages in the tomb heap.
500
- #
501
- # total_allocated_pages
502
- # : The total number of pages that have been allocated in the heap.
503
- #
504
- # total_freed_pages
505
- # : The total number of pages that have been freed and released back to the
506
- # system in the heap.
507
- #
508
- # force_major_gc_count
509
- # : The number of times this heap has forced major garbage collection cycles
510
- # to start due to running out of free slots.
511
- #
512
- # force_incremental_marking_finish_count
513
- # : The number of times this heap has forced incremental marking to complete
514
- # due to running out of pooled slots.
472
+ # This method is implementation-specific to CRuby.
473
+ #
474
+ # Returns statistics for GC heaps. The particular statistics are
475
+ # implementation-specific and may change in the future without notice.
476
+ #
477
+ # With no argument given, returns statistics for all heaps:
478
+ #
479
+ # GC.stat_heap
480
+ # # =>
481
+ # {0 =>
482
+ # {slot_size: 40,
483
+ # heap_eden_pages: 246,
484
+ # heap_eden_slots: 402802,
485
+ # total_allocated_pages: 246,
486
+ # force_major_gc_count: 2,
487
+ # force_incremental_marking_finish_count: 1,
488
+ # total_allocated_objects: 33867152,
489
+ # total_freed_objects: 33520523},
490
+ # 1 =>
491
+ # {slot_size: 80,
492
+ # heap_eden_pages: 84,
493
+ # heap_eden_slots: 68746,
494
+ # total_allocated_pages: 84,
495
+ # force_major_gc_count: 1,
496
+ # force_incremental_marking_finish_count: 4,
497
+ # total_allocated_objects: 147491,
498
+ # total_freed_objects: 90699},
499
+ # 2 =>
500
+ # {slot_size: 160,
501
+ # heap_eden_pages: 157,
502
+ # heap_eden_slots: 64182,
503
+ # total_allocated_pages: 157,
504
+ # force_major_gc_count: 0,
505
+ # force_incremental_marking_finish_count: 0,
506
+ # total_allocated_objects: 211460,
507
+ # total_freed_objects: 190075},
508
+ # 3 =>
509
+ # {slot_size: 320,
510
+ # heap_eden_pages: 8,
511
+ # heap_eden_slots: 1631,
512
+ # total_allocated_pages: 8,
513
+ # force_major_gc_count: 0,
514
+ # force_incremental_marking_finish_count: 0,
515
+ # total_allocated_objects: 1422,
516
+ # total_freed_objects: 700},
517
+ # 4 =>
518
+ # {slot_size: 640,
519
+ # heap_eden_pages: 16,
520
+ # heap_eden_slots: 1628,
521
+ # total_allocated_pages: 16,
522
+ # force_major_gc_count: 0,
523
+ # force_incremental_marking_finish_count: 0,
524
+ # total_allocated_objects: 1230,
525
+ # total_freed_objects: 309}}
526
+ #
527
+ # In the example above, the keys in the outer hash are the heap identifiers:
528
+ #
529
+ # GC.stat_heap.keys # => [0, 1, 2, 3, 4]
530
+ #
531
+ # On CRuby, each heap identifier is an integer; on other implementations, a heap
532
+ # identifier may be a string.
533
+ #
534
+ # With only argument `heap_id` given, returns statistics for the given heap
535
+ # identifier:
536
+ #
537
+ # GC.stat_heap(2)
538
+ # # =>
539
+ # {slot_size: 160,
540
+ # heap_eden_pages: 157,
541
+ # heap_eden_slots: 64182,
542
+ # total_allocated_pages: 157,
543
+ # force_major_gc_count: 0,
544
+ # force_incremental_marking_finish_count: 0,
545
+ # total_allocated_objects: 225018,
546
+ # total_freed_objects: 206647}
547
+ #
548
+ # With arguments `heap_id` and `key` given, returns the value for the given key
549
+ # in the given heap:
550
+ #
551
+ # GC.stat_heap(2, :slot_size) # => 160
552
+ #
553
+ # With arguments `nil` and `hash` given, merges the statistics for all heaps
554
+ # into the given hash:
555
+ #
556
+ # h = {foo: 0, bar: 1}
557
+ # GC.stat_heap(nil, h).keys # => [:foo, :bar, 0, 1, 2, 3, 4]
558
+ #
559
+ # With arguments `heap_id` and `hash` given, merges the statistics for the given
560
+ # heap into the given hash:
561
+ #
562
+ # h = {foo: 0, bar: 1}
563
+ # GC.stat_heap(2, h).keys
564
+ # # =>
565
+ # [:foo,
566
+ # :bar,
567
+ # :slot_size,
568
+ # :heap_eden_pages,
569
+ # :heap_eden_slots,
570
+ # :total_allocated_pages,
571
+ # :force_major_gc_count,
572
+ # :force_incremental_marking_finish_count,
573
+ # :total_allocated_objects,
574
+ # :total_freed_objects]
575
+ #
576
+ # The statistics for a heap may include:
577
+ #
578
+ # * `:slot_size`: The slot size of the heap in bytes.
579
+ # * `:heap_allocatable_pages`: The number of pages that can be allocated
580
+ # without triggering a new garbage collection cycle.
581
+ # * `:heap_eden_pages`: The number of pages in the eden heap.
582
+ # * `:heap_eden_slots`: The total number of slots in all of the pages in the
583
+ # eden heap.
584
+ # * `:total_allocated_pages`: The total number of pages that have been
585
+ # allocated in the heap.
586
+ # * `:total_freed_pages`: The total number of pages that have been freed and
587
+ # released back to the system in the heap.
588
+ # * `:force_major_gc_count`: The number of times this heap has forced major
589
+ # garbage collection cycles to start due to running out of free slots.
590
+ # * `:force_incremental_marking_finish_count`: The number of times this heap
591
+ # has forced incremental marking to complete due to running out of pooled
592
+ # slots.
515
593
  #
516
594
  def self.stat_heap: (?Integer? heap_name, ?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
517
595
  | (Integer heap_name, Symbol key) -> Integer
@@ -532,37 +610,67 @@ module GC
532
610
 
533
611
  # <!--
534
612
  # rdoc-file=gc.rb
535
- # - GC.stress -> integer, true, or false
613
+ # - GC.stress -> setting
536
614
  # -->
537
- # Returns the current status of GC stress mode.
615
+ # Returns the current GC stress-mode setting, which initially is `false`.
616
+ #
617
+ # The stress mode may be set by method GC.stress=.
538
618
  #
539
619
  def self.stress: () -> (Integer | bool)
540
620
 
541
621
  # <!--
542
622
  # rdoc-file=gc.rb
543
- # - GC.stress = flag -> flag
623
+ # - GC.stress = value -> value
544
624
  # -->
545
- # Updates the GC stress mode.
625
+ # Enables or disables stress mode; enabling stress mode will degrade
626
+ # performance; it is only for debugging.
627
+ #
628
+ # Sets the current GC stress mode to the given value:
546
629
  #
547
- # When stress mode is enabled, the GC is invoked at every GC opportunity: all
548
- # memory and object allocations.
630
+ # * If the value is `nil` or `false`, disables stress mode.
631
+ # * If the value is an integer, enables stress mode with certain flags; see
632
+ # below.
633
+ # * Otherwise, enables stress mode; GC is invoked at every GC opportunity: all
634
+ # memory and object allocations.
549
635
  #
550
- # Enabling stress mode will degrade performance; it is only for debugging.
636
+ # The flags are bits in the given integer:
551
637
  #
552
- # The flag can be true, false, or an integer bitwise-ORed with the following
553
- # flags:
554
- # 0x01:: no major GC
555
- # 0x02:: no immediate sweep
556
- # 0x04:: full mark after malloc/calloc/realloc
638
+ # * `0x01`: No major GC.
639
+ # * `0x02`: No immediate sweep.
640
+ # * `0x04`: Full mark after malloc/calloc/realloc.
557
641
  #
558
642
  def self.stress=: (Integer flag) -> Integer
559
643
  | (bool flag) -> bool
560
644
 
561
645
  # <!--
562
646
  # rdoc-file=gc.rb
563
- # - GC.total_time -> int
647
+ # - GC.total_time -> integer
564
648
  # -->
565
- # Returns the measured GC total time in nanoseconds.
649
+ # Returns the GC total time in nanoseconds:
650
+ #
651
+ # GC.total_time # => 156250
652
+ #
653
+ # Note that total time accumulates only when total time measurement is enabled
654
+ # (that is, when GC.measure_total_time is `true`):
655
+ #
656
+ # GC.measure_total_time # => true
657
+ # GC.total_time # => 625000
658
+ # GC.start
659
+ # GC.total_time # => 937500
660
+ # GC.start
661
+ # GC.total_time # => 1093750
662
+ #
663
+ # GC.measure_total_time = false
664
+ # GC.total_time # => 1250000
665
+ # GC.start
666
+ # GC.total_time # => 1250000
667
+ # GC.start
668
+ # GC.total_time # => 1250000
669
+ #
670
+ # GC.measure_total_time = true
671
+ # GC.total_time # => 1250000
672
+ # GC.start
673
+ # GC.total_time # => 1406250
566
674
  #
567
675
  def self.total_time: () -> Integer
568
676
 
@@ -619,17 +727,45 @@ module GC
619
727
 
620
728
  # <!--
621
729
  # rdoc-file=gc.rb
622
- # - GC.latest_gc_info -> hash
623
- # - GC.latest_gc_info(hash) -> hash
730
+ # - GC.latest_gc_info -> new_hash
624
731
  # - GC.latest_gc_info(key) -> value
732
+ # - GC.latest_gc_info(hash) -> hash
625
733
  # -->
626
- # Returns information about the most recent garbage collection.
627
- #
628
- # If the argument `hash` is given and is a Hash object, it is overwritten and
629
- # returned. This is intended to avoid the probe effect.
630
- #
631
- # If the argument `key` is given and is a Symbol object, it returns the value
632
- # associated with the key. This is equivalent to `GC.latest_gc_info[key]`.
734
+ # With no argument given, returns information about the most recent garbage
735
+ # collection:
736
+ #
737
+ # GC.latest_gc_info
738
+ # # =>
739
+ # {major_by: :force,
740
+ # need_major_by: nil,
741
+ # gc_by: :method,
742
+ # have_finalizer: false,
743
+ # immediate_sweep: true,
744
+ # state: :none,
745
+ # weak_references_count: 0,
746
+ # retained_weak_references_count: 0}
747
+ #
748
+ # With symbol argument `key` given, returns the value for that key:
749
+ #
750
+ # GC.latest_gc_info(:gc_by) # => :newobj
751
+ #
752
+ # With hash argument `hash` given, returns that hash with GC information merged
753
+ # into its content; this form may be useful in minimizing [probe
754
+ # effects](https://en.wikipedia.org/wiki/Probe_effect):
755
+ #
756
+ # h = {foo: 0, bar: 1}
757
+ # GC.latest_gc_info(h)
758
+ # # =>
759
+ # {foo: 0,
760
+ # bar: 1,
761
+ # major_by: nil,
762
+ # need_major_by: nil,
763
+ # gc_by: :newobj,
764
+ # have_finalizer: false,
765
+ # immediate_sweep: false,
766
+ # state: :sweeping,
767
+ # weak_references_count: 0,
768
+ # retained_weak_references_count: 0}
633
769
  #
634
770
  def self.latest_gc_info: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
635
771
  | (Symbol key) -> untyped