rbs 3.10.0 → 4.0.0.dev.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
data/core/gc.rbs CHANGED
@@ -160,65 +160,81 @@ module GC
160
160
  # <!--
161
161
  # rdoc-file=gc.rb
162
162
  # - GC.config -> hash
163
- # - GC.config(hash_to_merge) -> hash
163
+ # - GC.config(hash) -> hash
164
164
  # -->
165
- # This method is implementation-specific to CRuby.
166
- #
167
- # Sets or gets information about the current GC configuration.
165
+ # Sets or gets information about the current GC config.
168
166
  #
169
167
  # Configuration parameters are GC implementation-specific and may change without
170
168
  # notice.
171
169
  #
172
- # With no argument given, returns a hash containing the configuration:
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.
173
188
  #
174
- # GC.config
175
- # # => {rgengc_allow_full_mark: true, implementation: "default"}
189
+ # ### GC Implementation independent values
176
190
  #
177
- # With argument `hash_to_merge` given, merges that hash into the stored
178
- # configuration hash; ignores unknown hash keys; returns the configuration hash:
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`.
179
194
  #
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"}
195
+ # There is currently only one global, read-only key:
184
196
  #
185
- # **All-Implementations Configuration**
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
186
201
  #
187
- # The single read-only entry for all implementations is:
188
202
  #
189
- # * `:implementation`: the string name of the implementation; for the Ruby
190
- # default implementation, `'default'`.
203
+ # ### GC Implementation specific values
191
204
  #
192
- # **Implementation-Specific Configuration**
205
+ # GC libraries are expected to document their own configuration. Valid keys for
206
+ # Ruby's default GC implementation are:
193
207
  #
194
- # A GC implementation maintains its own implementation-specific configuration.
208
+ # rgengc_allow_full_mark
209
+ # : Controls whether the GC is allowed to run a full mark (young & old
210
+ # objects).
195
211
  #
196
- # For Ruby's default implementation the single entry is:
212
+ # When `true`, GC interleaves major and minor collections. This is the
213
+ # default. GC will function as intended.
197
214
  #
198
- # * `:rgengc_allow_full_mark`: Controls whether the GC is allowed to run a
199
- # full mark (young & old objects):
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.
200
219
  #
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`.
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`.
209
229
  #
210
230
  def self.config: () -> Hash[Symbol, untyped]
211
231
  | (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
212
232
 
213
233
  # <!--
214
234
  # rdoc-file=gc.rb
215
- # - self.count -> integer
235
+ # - GC.count -> Integer
216
236
  # -->
217
- # Returns the total number of times garbage collection has occurred:
218
- #
219
- # GC.count # => 385
220
- # GC.start
221
- # GC.count # => 386
237
+ # Returns the number of times GC has occurred since the process started.
222
238
  #
223
239
  def self.count: () -> Integer
224
240
 
@@ -226,12 +242,11 @@ module GC
226
242
  # rdoc-file=gc.rb
227
243
  # - GC.disable -> true or false
228
244
  # -->
229
- # Disables garbage collection (but GC.start remains potent): returns whether
230
- # garbage collection was already disabled.
245
+ # Disables garbage collection, returning `true` if garbage collection was
246
+ # already disabled.
231
247
  #
232
- # GC.enable
233
- # GC.disable # => false
234
- # GC.disable # => true
248
+ # GC.disable #=> false
249
+ # GC.disable #=> true
235
250
  #
236
251
  def self.disable: () -> bool
237
252
 
@@ -239,11 +254,12 @@ module GC
239
254
  # rdoc-file=gc.rb
240
255
  # - GC.enable -> true or false
241
256
  # -->
242
- # Enables garbage collection; returns whether garbage collection was disabled:
257
+ # Enables garbage collection, returning `true` if garbage collection was
258
+ # previously disabled.
243
259
  #
244
- # GC.disable
245
- # GC.enable # => true
246
- # GC.enable # => false
260
+ # GC.disable #=> false
261
+ # GC.enable #=> true
262
+ # GC.enable #=> false
247
263
  #
248
264
  def self.enable: () -> bool
249
265
 
@@ -251,193 +267,161 @@ module GC
251
267
  # rdoc-file=gc.rb
252
268
  # - start(full_mark: true, immediate_mark: true, immediate_sweep: true)
253
269
  # -->
254
- # Initiates garbage collection, even if explicitly disabled by GC.disable.
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.
255
303
  #
256
- # Keyword arguments:
304
+ # The contents of the hash are implementation-specific and may change in the
305
+ # future without notice.
257
306
  #
258
- # * `full_mark`: its boolean value determines whether to perform a major
259
- # garbage collection cycle:
307
+ # The hash includes internal statistics about GC such as:
260
308
  #
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.
309
+ # count
310
+ # : The total number of garbage collections run since application start (count
311
+ # includes both minor and major garbage collections)
265
312
  #
266
- # * `immediate_mark`: its boolean value determines whether to perform
267
- # incremental marking:
313
+ # time
314
+ # : The total time spent in garbage collections (in milliseconds)
268
315
  #
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`.
316
+ # heap_allocated_pages
317
+ # : The total number of `:heap_eden_pages` + `:heap_tomb_pages`
275
318
  #
276
- # * `immediate_sweep`: its boolean value determines whether to defer sweeping
277
- # (using lazy sweep):
319
+ # heap_sorted_length
320
+ # : The number of pages that can fit into the buffer that holds references to
321
+ # all pages
278
322
  #
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.
323
+ # heap_allocatable_pages
324
+ # : The total number of pages the application could allocate without
325
+ # additional GC
283
326
  #
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.
327
+ # heap_available_slots
328
+ # : The total number of slots in all `:heap_allocated_pages`
287
329
  #
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.
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
380
+ #
381
+ # remembered_wb_unprotected_objects
382
+ # : The total number of objects without write barriers
383
+ #
384
+ # remembered_wb_unprotected_objects_limit
385
+ # : When `:remembered_wb_unprotected_objects` crosses this limit, major GC is
386
+ # triggered
387
+ #
388
+ # old_objects
389
+ # : Number of live, old objects which have survived at least 3 garbage
390
+ # collections
391
+ #
392
+ # old_objects_limit
393
+ # : When `:old_objects` crosses this limit, major GC is triggered
394
+ #
395
+ # oldmalloc_increase_bytes
396
+ # : Amount of memory allocated on the heap for objects. Decreased by major GC
397
+ #
398
+ # oldmalloc_increase_bytes_limit
399
+ # : When `:oldmalloc_increase_bytes` crosses this limit, major GC is triggered
400
+ #
401
+ #
402
+ # If the optional argument, hash, is given, it is overwritten and returned. This
403
+ # is intended to avoid the probe effect.
404
+ #
405
+ # This method is only expected to work on CRuby.
404
406
  #
405
407
  def self.stat: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
406
408
  | (Symbol key) -> Integer
407
409
 
408
410
  # <!--
409
411
  # rdoc-file=gc.rb
410
- # - GC.measure_total_time = setting -> setting
412
+ # - GC.measure_total_time = true/false
411
413
  # -->
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.
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.
432
416
  #
433
417
  def self.measure_total_time=: [T] (T enable) -> T
434
418
 
435
419
  # <!--
436
420
  # rdoc-file=gc.rb
437
- # - GC.measure_total_time -> true or false
421
+ # - GC.measure_total_time -> true/false
438
422
  # -->
439
- # Returns the setting for GC total time measurement; the initial setting is
440
- # `true`. See GC.total_time.
423
+ # Returns the measure_total_time flag (default: `true`). Note that measurement
424
+ # can affect the application's performance.
441
425
  #
442
426
  def self.measure_total_time: () -> bool
443
427
 
@@ -463,133 +447,71 @@ module GC
463
447
 
464
448
  # <!--
465
449
  # rdoc-file=gc.rb
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
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
471
455
  # -->
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.
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.
593
515
  #
594
516
  def self.stat_heap: (?Integer? heap_name, ?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
595
517
  | (Integer heap_name, Symbol key) -> Integer
@@ -610,67 +532,37 @@ module GC
610
532
 
611
533
  # <!--
612
534
  # rdoc-file=gc.rb
613
- # - GC.stress -> setting
535
+ # - GC.stress -> integer, true, or false
614
536
  # -->
615
- # Returns the current GC stress-mode setting, which initially is `false`.
616
- #
617
- # The stress mode may be set by method GC.stress=.
537
+ # Returns the current status of GC stress mode.
618
538
  #
619
539
  def self.stress: () -> (Integer | bool)
620
540
 
621
541
  # <!--
622
542
  # rdoc-file=gc.rb
623
- # - GC.stress = value -> value
543
+ # - GC.stress = flag -> flag
624
544
  # -->
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:
545
+ # Updates the GC stress mode.
629
546
  #
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.
547
+ # When stress mode is enabled, the GC is invoked at every GC opportunity: all
548
+ # memory and object allocations.
635
549
  #
636
- # The flags are bits in the given integer:
550
+ # Enabling stress mode will degrade performance; it is only for debugging.
637
551
  #
638
- # * `0x01`: No major GC.
639
- # * `0x02`: No immediate sweep.
640
- # * `0x04`: Full mark after malloc/calloc/realloc.
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
641
557
  #
642
558
  def self.stress=: (Integer flag) -> Integer
643
559
  | (bool flag) -> bool
644
560
 
645
561
  # <!--
646
562
  # rdoc-file=gc.rb
647
- # - GC.total_time -> integer
563
+ # - GC.total_time -> int
648
564
  # -->
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
565
+ # Returns the measured GC total time in nanoseconds.
674
566
  #
675
567
  def self.total_time: () -> Integer
676
568
 
@@ -727,45 +619,17 @@ module GC
727
619
 
728
620
  # <!--
729
621
  # rdoc-file=gc.rb
730
- # - GC.latest_gc_info -> new_hash
731
- # - GC.latest_gc_info(key) -> value
622
+ # - GC.latest_gc_info -> hash
732
623
  # - GC.latest_gc_info(hash) -> hash
624
+ # - GC.latest_gc_info(key) -> value
733
625
  # -->
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}
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]`.
769
633
  #
770
634
  def self.latest_gc_info: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
771
635
  | (Symbol key) -> untyped