rbs 3.9.5 → 3.10.0.pre.1

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 (171) 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/README.md +38 -1
  11. data/Rakefile +152 -23
  12. data/config.yml +190 -62
  13. data/core/array.rbs +44 -43
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +3 -2
  16. data/core/enumerable.rbs +89 -2
  17. data/core/errno.rbs +8 -0
  18. data/core/errors.rbs +28 -1
  19. data/core/exception.rbs +2 -2
  20. data/core/fiber.rbs +3 -3
  21. data/core/file.rbs +26 -11
  22. data/core/float.rbs +1 -1
  23. data/core/gc.rbs +422 -281
  24. data/core/hash.rbs +1024 -727
  25. data/core/io/wait.rbs +11 -33
  26. data/core/io.rbs +6 -4
  27. data/core/kernel.rbs +49 -43
  28. data/core/marshal.rbs +1 -1
  29. data/core/match_data.rbs +1 -1
  30. data/core/math.rbs +42 -3
  31. data/core/method.rbs +14 -6
  32. data/core/module.rbs +71 -11
  33. data/core/nil_class.rbs +3 -3
  34. data/core/numeric.rbs +8 -8
  35. data/core/object.rbs +3 -3
  36. data/core/object_space.rbs +13 -0
  37. data/{stdlib/pathname/0 → core}/pathname.rbs +253 -352
  38. data/core/proc.rbs +15 -8
  39. data/core/process.rbs +2 -2
  40. data/core/ractor.rbs +278 -437
  41. data/core/range.rbs +6 -7
  42. data/core/rbs/unnamed/argf.rbs +1 -1
  43. data/core/rbs/unnamed/env_class.rbs +1 -1
  44. data/core/rbs/unnamed/random.rbs +4 -2
  45. data/core/regexp.rbs +22 -17
  46. data/core/ruby_vm.rbs +6 -4
  47. data/core/rubygems/errors.rbs +3 -70
  48. data/core/rubygems/rubygems.rbs +11 -79
  49. data/core/set.rbs +439 -332
  50. data/core/string.rbs +2897 -1117
  51. data/core/struct.rbs +1 -1
  52. data/core/symbol.rbs +4 -4
  53. data/core/thread.rbs +83 -20
  54. data/core/time.rbs +35 -9
  55. data/core/unbound_method.rbs +14 -6
  56. data/docs/aliases.md +79 -0
  57. data/docs/collection.md +2 -2
  58. data/docs/gem.md +0 -1
  59. data/docs/sigs.md +3 -3
  60. data/ext/rbs_extension/ast_translation.c +1016 -0
  61. data/ext/rbs_extension/ast_translation.h +37 -0
  62. data/ext/rbs_extension/class_constants.c +157 -0
  63. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  64. data/ext/rbs_extension/compat.h +10 -0
  65. data/ext/rbs_extension/extconf.rb +25 -1
  66. data/ext/rbs_extension/legacy_location.c +317 -0
  67. data/ext/rbs_extension/legacy_location.h +45 -0
  68. data/ext/rbs_extension/main.c +365 -14
  69. data/ext/rbs_extension/rbs_extension.h +6 -21
  70. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  71. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  72. data/include/rbs/ast.h +687 -0
  73. data/include/rbs/defines.h +86 -0
  74. data/include/rbs/lexer.h +199 -0
  75. data/include/rbs/location.h +59 -0
  76. data/include/rbs/parser.h +135 -0
  77. data/include/rbs/string.h +49 -0
  78. data/include/rbs/util/rbs_allocator.h +59 -0
  79. data/include/rbs/util/rbs_assert.h +20 -0
  80. data/include/rbs/util/rbs_buffer.h +83 -0
  81. data/include/rbs/util/rbs_constant_pool.h +6 -67
  82. data/include/rbs/util/rbs_encoding.h +282 -0
  83. data/include/rbs/util/rbs_unescape.h +23 -0
  84. data/include/rbs.h +1 -2
  85. data/lib/rbs/annotate/formatter.rb +3 -13
  86. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  87. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  88. data/lib/rbs/cli/validate.rb +2 -2
  89. data/lib/rbs/cli.rb +1 -1
  90. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  91. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  92. data/lib/rbs/environment.rb +64 -59
  93. data/lib/rbs/environment_loader.rb +1 -1
  94. data/lib/rbs/errors.rb +1 -1
  95. data/lib/rbs/parser_aux.rb +5 -0
  96. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  97. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  98. data/lib/rbs/test/type_check.rb +13 -0
  99. data/lib/rbs/types.rb +3 -1
  100. data/lib/rbs/version.rb +1 -1
  101. data/lib/rbs.rb +1 -1
  102. data/lib/rdoc/discover.rb +1 -1
  103. data/lib/rdoc_plugin/parser.rb +3 -3
  104. data/sig/annotate/formatter.rbs +2 -2
  105. data/sig/annotate/rdoc_annotater.rbs +1 -1
  106. data/sig/environment.rbs +57 -6
  107. data/sig/manifest.yaml +0 -1
  108. data/sig/parser.rbs +20 -0
  109. data/sig/resolver/type_name_resolver.rbs +38 -7
  110. data/sig/types.rbs +4 -1
  111. data/src/ast.c +1256 -0
  112. data/src/lexer.c +2956 -0
  113. data/src/lexer.re +147 -0
  114. data/src/lexstate.c +205 -0
  115. data/src/location.c +71 -0
  116. data/src/parser.c +3495 -0
  117. data/src/string.c +90 -0
  118. data/src/util/rbs_allocator.c +152 -0
  119. data/src/util/rbs_assert.c +21 -0
  120. data/src/util/rbs_buffer.c +54 -0
  121. data/src/util/rbs_constant_pool.c +16 -86
  122. data/src/util/rbs_encoding.c +21308 -0
  123. data/src/util/rbs_unescape.c +131 -0
  124. data/stdlib/cgi/0/core.rbs +2 -396
  125. data/stdlib/cgi/0/manifest.yaml +1 -0
  126. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  127. data/stdlib/coverage/0/coverage.rbs +3 -1
  128. data/stdlib/delegate/0/delegator.rbs +10 -7
  129. data/stdlib/erb/0/erb.rbs +737 -347
  130. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  131. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  132. data/stdlib/json/0/json.rbs +67 -48
  133. data/stdlib/net-http/0/net-http.rbs +3 -0
  134. data/stdlib/objspace/0/objspace.rbs +8 -3
  135. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  136. data/stdlib/openssl/0/openssl.rbs +182 -149
  137. data/stdlib/optparse/0/optparse.rbs +3 -3
  138. data/stdlib/rdoc/0/code_object.rbs +2 -2
  139. data/stdlib/rdoc/0/comment.rbs +2 -0
  140. data/stdlib/rdoc/0/options.rbs +76 -0
  141. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  142. data/stdlib/rdoc/0/store.rbs +1 -1
  143. data/stdlib/resolv/0/resolv.rbs +25 -68
  144. data/stdlib/ripper/0/ripper.rbs +5 -2
  145. data/stdlib/singleton/0/singleton.rbs +3 -0
  146. data/stdlib/socket/0/socket.rbs +13 -1
  147. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  148. data/stdlib/stringio/0/stringio.rbs +412 -80
  149. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  150. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  151. data/stdlib/tsort/0/cyclic.rbs +3 -0
  152. data/stdlib/uri/0/common.rbs +11 -2
  153. data/stdlib/uri/0/file.rbs +1 -1
  154. data/stdlib/uri/0/generic.rbs +16 -15
  155. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  156. data/stdlib/zlib/0/zstream.rbs +1 -0
  157. metadata +41 -18
  158. data/ext/rbs_extension/lexer.c +0 -2728
  159. data/ext/rbs_extension/lexer.h +0 -179
  160. data/ext/rbs_extension/lexer.re +0 -147
  161. data/ext/rbs_extension/lexstate.c +0 -175
  162. data/ext/rbs_extension/location.c +0 -325
  163. data/ext/rbs_extension/location.h +0 -85
  164. data/ext/rbs_extension/parser.c +0 -2982
  165. data/ext/rbs_extension/parser.h +0 -18
  166. data/ext/rbs_extension/parserstate.c +0 -411
  167. data/ext/rbs_extension/parserstate.h +0 -163
  168. data/ext/rbs_extension/unescape.c +0 -32
  169. data/include/rbs/ruby_objs.h +0 -72
  170. data/src/constants.c +0 -153
  171. 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,194 @@ 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 keword 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 `:heap_eden_pages` +
355
+ # `:heap_tomb_pages`.
356
+ # * `:heap_sorted_length`: The number of pages that can fit into the buffer
357
+ # that holds references to all pages.
358
+ # * `:heap_allocatable_pages`: The total number of pages the application could
359
+ # allocate without additional GC.
360
+ # * `:heap_available_slots`: The total number of slots in all
361
+ # `:heap_allocated_pages`.
362
+ # * `:heap_live_slots`: The total number of slots which contain live objects.
363
+ # * `:heap_free_slots`: The total number of slots which do not contain live
364
+ # objects.
365
+ # * `:heap_final_slots`: The total number of slots with pending finalizers to
366
+ # be run.
367
+ # * `:heap_marked_slots`: The total number of objects marked in the last GC.
368
+ # * `:heap_eden_pages`: The total number of pages which contain at least one
369
+ # live slot.
370
+ # * `:heap_tomb_pages`: The total number of pages which do not contain any
371
+ # live slots.
372
+ # * `:total_allocated_pages`: The cumulative number of pages allocated since
373
+ # application start.
374
+ # * `:total_freed_pages`: The cumulative number of pages freed since
375
+ # application start.
376
+ # * `:total_allocated_objects`: The cumulative number of objects allocated
377
+ # since application start.
378
+ # * `:total_freed_objects`: The cumulative number of objects freed since
379
+ # application start.
380
+ # * `:malloc_increase_bytes`: Amount of memory allocated on the heap for
381
+ # objects. Decreased by any GC.
382
+ # * `:malloc_increase_bytes_limit`: When `:malloc_increase_bytes` crosses this
383
+ # limit, GC is triggered.
384
+ # * `:minor_gc_count`: The total number of minor garbage collections run since
385
+ # process start.
386
+ # * `:major_gc_count`: The total number of major garbage collections run since
387
+ # process start.
388
+ # * `:compact_count`: The total number of compactions run since process start.
389
+ # * `:read_barrier_faults`: The total number of times the read barrier was
390
+ # triggered during compaction.
391
+ # * `:total_moved_objects`: The total number of objects compaction has moved.
392
+ # * `:remembered_wb_unprotected_objects`: The total number of objects without
393
+ # write barriers.
394
+ # * `:remembered_wb_unprotected_objects_limit`: When
395
+ # `:remembered_wb_unprotected_objects` crosses this limit, major GC is
396
+ # triggered.
397
+ # * `:old_objects`: Number of live, old objects which have survived at least 3
398
+ # garbage collections.
399
+ # * `:old_objects_limit`: When `:old_objects` crosses this limit, major GC is
400
+ # triggered.
401
+ # * `:oldmalloc_increase_bytes`: Amount of memory allocated on the heap for
402
+ # objects. Decreased by major GC.
403
+ # * `:oldmalloc_increase_bytes_limit`: When `:oldmalloc_increase_bytes`
404
+ # crosses this limit, major GC is triggered.
406
405
  #
407
406
  def self.stat: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
408
407
  | (Symbol key) -> Integer
409
408
 
410
409
  # <!--
411
410
  # rdoc-file=gc.rb
412
- # - GC.measure_total_time = true/false
411
+ # - GC.measure_total_time = setting -> setting
413
412
  # -->
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.
413
+ # Enables or disables GC total time measurement; returns `setting`. See
414
+ # GC.total_time.
415
+ #
416
+ # When argument `object` is `nil` or `false`, disables total time measurement;
417
+ # GC.measure_total_time then returns `false`:
418
+ #
419
+ # GC.measure_total_time = nil # => nil
420
+ # GC.measure_total_time # => false
421
+ # GC.measure_total_time = false # => false
422
+ # GC.measure_total_time # => false
423
+ #
424
+ # Otherwise, enables total time measurement; GC.measure_total_time then returns
425
+ # `true`:
426
+ #
427
+ # GC.measure_total_time = true # => true
428
+ # GC.measure_total_time # => true
429
+ # GC.measure_total_time = :foo # => :foo
430
+ # GC.measure_total_time # => true
431
+ #
432
+ # Note that when enabled, total time measurement affects performance.
416
433
  #
417
434
  def self.measure_total_time=: [T] (T enable) -> T
418
435
 
419
436
  # <!--
420
437
  # rdoc-file=gc.rb
421
- # - GC.measure_total_time -> true/false
438
+ # - GC.measure_total_time -> true or false
422
439
  # -->
423
- # Returns the measure_total_time flag (default: `true`). Note that measurement
424
- # can affect the application's performance.
440
+ # Returns the setting for GC total time measurement; the initial setting is
441
+ # `true`. See GC.total_time.
425
442
  #
426
443
  def self.measure_total_time: () -> bool
427
444
 
@@ -447,71 +464,137 @@ module GC
447
464
 
448
465
  # <!--
449
466
  # 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
467
+ # - GC.stat_heap -> new_hash
468
+ # - GC.stat_heap(heap_id) -> new_hash
469
+ # - GC.stat_heap(heap_id, key) -> value
470
+ # - GC.stat_heap(nil, hash) -> hash
471
+ # - GC.stat_heap(heap_id, hash) -> hash
455
472
  # -->
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.
473
+ # This method is implementation-specific to CRuby.
474
+ #
475
+ # Returns statistics for GC heaps. The particular statistics are
476
+ # implementation-specific and may change in the future without notice.
477
+ #
478
+ # With no argument given, returns statistics for all heaps:
479
+ #
480
+ # GC.stat_heap
481
+ # # =>
482
+ # {0 =>
483
+ # {slot_size: 40,
484
+ # heap_eden_pages: 246,
485
+ # heap_eden_slots: 402802,
486
+ # total_allocated_pages: 246,
487
+ # force_major_gc_count: 2,
488
+ # force_incremental_marking_finish_count: 1,
489
+ # total_allocated_objects: 33867152,
490
+ # total_freed_objects: 33520523},
491
+ # 1 =>
492
+ # {slot_size: 80,
493
+ # heap_eden_pages: 84,
494
+ # heap_eden_slots: 68746,
495
+ # total_allocated_pages: 84,
496
+ # force_major_gc_count: 1,
497
+ # force_incremental_marking_finish_count: 4,
498
+ # total_allocated_objects: 147491,
499
+ # total_freed_objects: 90699},
500
+ # 2 =>
501
+ # {slot_size: 160,
502
+ # heap_eden_pages: 157,
503
+ # heap_eden_slots: 64182,
504
+ # total_allocated_pages: 157,
505
+ # force_major_gc_count: 0,
506
+ # force_incremental_marking_finish_count: 0,
507
+ # total_allocated_objects: 211460,
508
+ # total_freed_objects: 190075},
509
+ # 3 =>
510
+ # {slot_size: 320,
511
+ # heap_eden_pages: 8,
512
+ # heap_eden_slots: 1631,
513
+ # total_allocated_pages: 8,
514
+ # force_major_gc_count: 0,
515
+ # force_incremental_marking_finish_count: 0,
516
+ # total_allocated_objects: 1422,
517
+ # total_freed_objects: 700},
518
+ # 4 =>
519
+ # {slot_size: 640,
520
+ # heap_eden_pages: 16,
521
+ # heap_eden_slots: 1628,
522
+ # total_allocated_pages: 16,
523
+ # force_major_gc_count: 0,
524
+ # force_incremental_marking_finish_count: 0,
525
+ # total_allocated_objects: 1230,
526
+ # total_freed_objects: 309}}
527
+ #
528
+ # In the example above, the keys in the outer hash are the heap identifiers:
529
+ #
530
+ # GC.stat_heap.keys # => [0, 1, 2, 3, 4]
531
+ #
532
+ # On CRuby, each heap identifier is an integer; on other implementations, a heap
533
+ # identifier may be a string.
534
+ #
535
+ # With only argument `heap_id` given, returns statistics for the given heap
536
+ # identifier:
537
+ #
538
+ # GC.stat_heap(2)
539
+ # # =>
540
+ # {slot_size: 160,
541
+ # heap_eden_pages: 157,
542
+ # heap_eden_slots: 64182,
543
+ # total_allocated_pages: 157,
544
+ # force_major_gc_count: 0,
545
+ # force_incremental_marking_finish_count: 0,
546
+ # total_allocated_objects: 225018,
547
+ # total_freed_objects: 206647}
548
+ #
549
+ # With arguments `heap_id` and `key` given, returns the value for the given key
550
+ # in the given heap:
551
+ #
552
+ # GC.stat_heap(2, :slot_size) # => 160
553
+ #
554
+ # With arguments `nil` and `hash` given, merges the statistics for all heaps
555
+ # into the given hash:
556
+ #
557
+ # h = {foo: 0, bar: 1}
558
+ # GC.stat_heap(nil, h).keys # => [:foo, :bar, 0, 1, 2, 3, 4]
559
+ #
560
+ # With arguments `heap_id` and `hash` given, merges the statistics for the given
561
+ # heap into the given hash:
562
+ #
563
+ # h = {foo: 0, bar: 1}
564
+ # GC.stat_heap(2, h).keys
565
+ # # =>
566
+ # [:foo,
567
+ # :bar,
568
+ # :slot_size,
569
+ # :heap_eden_pages,
570
+ # :heap_eden_slots,
571
+ # :total_allocated_pages,
572
+ # :force_major_gc_count,
573
+ # :force_incremental_marking_finish_count,
574
+ # :total_allocated_objects,
575
+ # :total_freed_objects]
576
+ #
577
+ # The statistics for a heap may include:
578
+ #
579
+ # * `:slot_size`: The slot size of the heap in bytes.
580
+ # * `:heap_allocatable_pages`: The number of pages that can be allocated
581
+ # without triggering a new garbage collection cycle.
582
+ # * `:heap_eden_pages`: The number of pages in the eden heap.
583
+ # * `:heap_eden_slots`: The total number of slots in all of the pages in the
584
+ # eden heap.
585
+ # * `:heap_tomb_pages`: The number of pages in the tomb heap. The tomb heap
586
+ # only contains pages that do not have any live objects.
587
+ # * `:heap_tomb_slots`: The total number of slots in all of the pages in the
588
+ # tomb heap.
589
+ # * `:total_allocated_pages`: The total number of pages that have been
590
+ # allocated in the heap.
591
+ # * `:total_freed_pages`: The total number of pages that have been freed and
592
+ # released back to the system in the heap.
593
+ # * `:force_major_gc_count`: The number of times this heap has forced major
594
+ # garbage collection cycles to start due to running out of free slots.
595
+ # * `:force_incremental_marking_finish_count`: The number of times this heap
596
+ # has forced incremental marking to complete due to running out of pooled
597
+ # slots.
515
598
  #
516
599
  def self.stat_heap: (?Integer? heap_name, ?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
517
600
  | (Integer heap_name, Symbol key) -> Integer
@@ -532,37 +615,67 @@ module GC
532
615
 
533
616
  # <!--
534
617
  # rdoc-file=gc.rb
535
- # - GC.stress -> integer, true, or false
618
+ # - GC.stress -> setting
536
619
  # -->
537
- # Returns the current status of GC stress mode.
620
+ # Returns the current GC stress-mode setting, which initially is `false`.
621
+ #
622
+ # The stress mode may be set by method GC.stress=.
538
623
  #
539
624
  def self.stress: () -> (Integer | bool)
540
625
 
541
626
  # <!--
542
627
  # rdoc-file=gc.rb
543
- # - GC.stress = flag -> flag
628
+ # - GC.stress = value -> value
544
629
  # -->
545
- # Updates the GC stress mode.
630
+ # Enables or disables stress mode; enabling stress mode will degrade
631
+ # performance; it is only for debugging.
632
+ #
633
+ # Sets the current GC stress mode to the given value:
546
634
  #
547
- # When stress mode is enabled, the GC is invoked at every GC opportunity: all
548
- # memory and object allocations.
635
+ # * If the value is `nil` or `false`, disables stress mode.
636
+ # * If the value is an integer, enables stress mode with certain flags; see
637
+ # below.
638
+ # * Otherwise, enables stress mode; GC is invoked at every GC opportunity: all
639
+ # memory and object allocations.
549
640
  #
550
- # Enabling stress mode will degrade performance; it is only for debugging.
641
+ # The flags are bits in the given integer:
551
642
  #
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
643
+ # * `0x01`: No major GC.
644
+ # * `0x02`: No immediate sweep.
645
+ # * `0x04`: Full mark after malloc/calloc/realloc.
557
646
  #
558
647
  def self.stress=: (Integer flag) -> Integer
559
648
  | (bool flag) -> bool
560
649
 
561
650
  # <!--
562
651
  # rdoc-file=gc.rb
563
- # - GC.total_time -> int
652
+ # - GC.total_time -> integer
564
653
  # -->
565
- # Returns the measured GC total time in nanoseconds.
654
+ # Returns the GC total time in nanoseconds:
655
+ #
656
+ # GC.total_time # => 156250
657
+ #
658
+ # Note that total time accumulates only when total time measurement is enabled
659
+ # (that is, when GC.measure_total_time is `true`):
660
+ #
661
+ # GC.measure_total_time # => true
662
+ # GC.total_time # => 625000
663
+ # GC.start
664
+ # GC.total_time # => 937500
665
+ # GC.start
666
+ # GC.total_time # => 1093750
667
+ #
668
+ # GC.measure_total_time = false
669
+ # GC.total_time # => 1250000
670
+ # GC.start
671
+ # GC.total_time # => 1250000
672
+ # GC.start
673
+ # GC.total_time # => 1250000
674
+ #
675
+ # GC.measure_total_time = true
676
+ # GC.total_time # => 1250000
677
+ # GC.start
678
+ # GC.total_time # => 1406250
566
679
  #
567
680
  def self.total_time: () -> Integer
568
681
 
@@ -619,17 +732,45 @@ module GC
619
732
 
620
733
  # <!--
621
734
  # rdoc-file=gc.rb
622
- # - GC.latest_gc_info -> hash
623
- # - GC.latest_gc_info(hash) -> hash
735
+ # - GC.latest_gc_info -> new_hash
624
736
  # - GC.latest_gc_info(key) -> value
737
+ # - GC.latest_gc_info(hash) -> hash
625
738
  # -->
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]`.
739
+ # With no argument given, returns information about the most recent garbage
740
+ # collection:
741
+ #
742
+ # GC.latest_gc_info
743
+ # # =>
744
+ # {major_by: :force,
745
+ # need_major_by: nil,
746
+ # gc_by: :method,
747
+ # have_finalizer: false,
748
+ # immediate_sweep: true,
749
+ # state: :none,
750
+ # weak_references_count: 0,
751
+ # retained_weak_references_count: 0}
752
+ #
753
+ # With symbol argument `key` given, returns the value for that key:
754
+ #
755
+ # GC.latest_gc_info(:gc_by) # => :newobj
756
+ #
757
+ # With hash argument `hash` given, returns that hash with GC information merged
758
+ # into its content; this form may be useful in minimizing [probe
759
+ # effects](https://en.wikipedia.org/wiki/Probe_effect):
760
+ #
761
+ # h = {foo: 0, bar: 1}
762
+ # GC.latest_gc_info(h)
763
+ # # =>
764
+ # {foo: 0,
765
+ # bar: 1,
766
+ # major_by: nil,
767
+ # need_major_by: nil,
768
+ # gc_by: :newobj,
769
+ # have_finalizer: false,
770
+ # immediate_sweep: false,
771
+ # state: :sweeping,
772
+ # weak_references_count: 0,
773
+ # retained_weak_references_count: 0}
633
774
  #
634
775
  def self.latest_gc_info: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
635
776
  | (Symbol key) -> untyped