rbs 4.0.0.dev.4 → 4.0.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 (281) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +18 -11
  5. data/.github/workflows/comments.yml +5 -3
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +27 -34
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +2 -2
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/CHANGELOG.md +323 -0
  13. data/README.md +1 -1
  14. data/Rakefile +43 -33
  15. data/Steepfile +1 -0
  16. data/config.yml +426 -24
  17. data/core/array.rbs +307 -227
  18. data/core/basic_object.rbs +9 -8
  19. data/core/binding.rbs +0 -2
  20. data/core/builtin.rbs +2 -2
  21. data/core/class.rbs +6 -5
  22. data/core/comparable.rbs +55 -34
  23. data/core/complex.rbs +104 -78
  24. data/core/dir.rbs +61 -49
  25. data/core/encoding.rbs +12 -15
  26. data/core/enumerable.rbs +179 -87
  27. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  28. data/core/enumerator.rbs +65 -2
  29. data/core/errno.rbs +11 -2
  30. data/core/errors.rbs +58 -29
  31. data/core/exception.rbs +13 -13
  32. data/core/fiber.rbs +74 -54
  33. data/core/file.rbs +280 -177
  34. data/core/file_test.rbs +3 -3
  35. data/core/float.rbs +257 -92
  36. data/core/gc.rbs +425 -281
  37. data/core/hash.rbs +1045 -739
  38. data/core/integer.rbs +135 -137
  39. data/core/io/buffer.rbs +53 -42
  40. data/core/io/wait.rbs +13 -35
  41. data/core/io.rbs +192 -144
  42. data/core/kernel.rbs +216 -155
  43. data/core/marshal.rbs +4 -4
  44. data/core/match_data.rbs +15 -13
  45. data/core/math.rbs +107 -66
  46. data/core/method.rbs +69 -33
  47. data/core/module.rbs +244 -106
  48. data/core/nil_class.rbs +7 -6
  49. data/core/numeric.rbs +74 -63
  50. data/core/object.rbs +9 -11
  51. data/core/object_space.rbs +30 -23
  52. data/core/pathname.rbs +1322 -0
  53. data/core/proc.rbs +95 -58
  54. data/core/process.rbs +222 -202
  55. data/core/ractor.rbs +371 -515
  56. data/core/random.rbs +21 -3
  57. data/core/range.rbs +159 -57
  58. data/core/rational.rbs +60 -89
  59. data/core/rbs/unnamed/argf.rbs +60 -53
  60. data/core/rbs/unnamed/env_class.rbs +19 -14
  61. data/core/rbs/unnamed/main_class.rbs +123 -0
  62. data/core/rbs/unnamed/random.rbs +11 -118
  63. data/core/regexp.rbs +258 -214
  64. data/core/ruby.rbs +53 -0
  65. data/core/ruby_vm.rbs +38 -34
  66. data/core/rubygems/config_file.rbs +5 -5
  67. data/core/rubygems/errors.rbs +4 -71
  68. data/core/rubygems/requirement.rbs +5 -5
  69. data/core/rubygems/rubygems.rbs +16 -82
  70. data/core/rubygems/version.rbs +2 -3
  71. data/core/set.rbs +490 -360
  72. data/core/signal.rbs +26 -16
  73. data/core/string.rbs +3234 -1285
  74. data/core/struct.rbs +27 -26
  75. data/core/symbol.rbs +41 -34
  76. data/core/thread.rbs +135 -67
  77. data/core/time.rbs +81 -50
  78. data/core/trace_point.rbs +41 -35
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +24 -16
  81. data/core/warning.rbs +7 -7
  82. data/docs/aliases.md +79 -0
  83. data/docs/collection.md +3 -3
  84. data/docs/config.md +171 -0
  85. data/docs/encoding.md +56 -0
  86. data/docs/gem.md +0 -1
  87. data/docs/inline.md +576 -0
  88. data/docs/sigs.md +3 -3
  89. data/docs/syntax.md +46 -16
  90. data/docs/type_fingerprint.md +21 -0
  91. data/exe/rbs +1 -1
  92. data/ext/rbs_extension/ast_translation.c +544 -116
  93. data/ext/rbs_extension/ast_translation.h +3 -0
  94. data/ext/rbs_extension/class_constants.c +16 -2
  95. data/ext/rbs_extension/class_constants.h +8 -0
  96. data/ext/rbs_extension/extconf.rb +5 -1
  97. data/ext/rbs_extension/legacy_location.c +33 -56
  98. data/ext/rbs_extension/legacy_location.h +37 -0
  99. data/ext/rbs_extension/main.c +44 -35
  100. data/include/rbs/ast.h +448 -173
  101. data/include/rbs/defines.h +27 -0
  102. data/include/rbs/lexer.h +30 -11
  103. data/include/rbs/location.h +25 -44
  104. data/include/rbs/parser.h +6 -6
  105. data/include/rbs/string.h +0 -2
  106. data/include/rbs/util/rbs_allocator.h +34 -13
  107. data/include/rbs/util/rbs_assert.h +12 -1
  108. data/include/rbs/util/rbs_constant_pool.h +0 -3
  109. data/include/rbs/util/rbs_encoding.h +2 -0
  110. data/include/rbs/util/rbs_unescape.h +2 -1
  111. data/include/rbs.h +8 -0
  112. data/lib/rbs/ast/annotation.rb +1 -1
  113. data/lib/rbs/ast/comment.rb +1 -1
  114. data/lib/rbs/ast/declarations.rb +10 -10
  115. data/lib/rbs/ast/members.rb +14 -14
  116. data/lib/rbs/ast/ruby/annotations.rb +293 -3
  117. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  118. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  119. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  120. data/lib/rbs/ast/ruby/members.rb +532 -22
  121. data/lib/rbs/ast/type_param.rb +24 -4
  122. data/lib/rbs/buffer.rb +20 -15
  123. data/lib/rbs/cli/diff.rb +16 -15
  124. data/lib/rbs/cli/validate.rb +38 -106
  125. data/lib/rbs/cli.rb +52 -19
  126. data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
  127. data/lib/rbs/collection/sources/git.rb +1 -0
  128. data/lib/rbs/definition.rb +1 -1
  129. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  130. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  131. data/lib/rbs/definition_builder.rb +147 -25
  132. data/lib/rbs/diff.rb +7 -1
  133. data/lib/rbs/environment.rb +227 -74
  134. data/lib/rbs/environment_loader.rb +0 -6
  135. data/lib/rbs/errors.rb +27 -18
  136. data/lib/rbs/inline_parser.rb +342 -6
  137. data/lib/rbs/location_aux.rb +1 -1
  138. data/lib/rbs/locator.rb +5 -1
  139. data/lib/rbs/method_type.rb +5 -3
  140. data/lib/rbs/parser_aux.rb +20 -7
  141. data/lib/rbs/prototype/helpers.rb +57 -0
  142. data/lib/rbs/prototype/rb.rb +3 -28
  143. data/lib/rbs/prototype/rbi.rb +3 -20
  144. data/lib/rbs/prototype/runtime.rb +8 -0
  145. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  146. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  147. data/lib/rbs/subtractor.rb +3 -1
  148. data/lib/rbs/test/type_check.rb +19 -2
  149. data/lib/rbs/type_name.rb +1 -1
  150. data/lib/rbs/types.rb +88 -78
  151. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  152. data/lib/rbs/validator.rb +2 -2
  153. data/lib/rbs/version.rb +1 -1
  154. data/lib/rbs.rb +1 -2
  155. data/lib/rdoc/discover.rb +1 -1
  156. data/lib/rdoc_plugin/parser.rb +1 -1
  157. data/rbs.gemspec +4 -3
  158. data/rust/.gitignore +1 -0
  159. data/rust/Cargo.lock +378 -0
  160. data/rust/Cargo.toml +7 -0
  161. data/rust/ruby-rbs/Cargo.toml +22 -0
  162. data/rust/ruby-rbs/build.rs +764 -0
  163. data/rust/ruby-rbs/examples/locations.rs +60 -0
  164. data/rust/ruby-rbs/src/lib.rs +1 -0
  165. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  166. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  167. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  168. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  169. data/rust/ruby-rbs-sys/build.rs +204 -0
  170. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  171. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  172. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  173. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  174. data/schema/typeParam.json +17 -1
  175. data/sig/ast/ruby/annotations.rbs +315 -4
  176. data/sig/ast/ruby/comment_block.rbs +8 -0
  177. data/sig/ast/ruby/declarations.rbs +102 -4
  178. data/sig/ast/ruby/members.rbs +108 -2
  179. data/sig/cli/diff.rbs +5 -11
  180. data/sig/cli/validate.rbs +12 -8
  181. data/sig/cli.rbs +18 -18
  182. data/sig/definition.rbs +6 -1
  183. data/sig/definition_builder.rbs +2 -0
  184. data/sig/environment.rbs +70 -12
  185. data/sig/errors.rbs +13 -14
  186. data/sig/inline_parser.rbs +39 -2
  187. data/sig/locator.rbs +0 -2
  188. data/sig/manifest.yaml +0 -1
  189. data/sig/method_builder.rbs +3 -1
  190. data/sig/parser.rbs +31 -13
  191. data/sig/prototype/helpers.rbs +2 -0
  192. data/sig/resolver/type_name_resolver.rbs +35 -7
  193. data/sig/source.rbs +3 -3
  194. data/sig/type_param.rbs +13 -8
  195. data/sig/types.rbs +6 -7
  196. data/sig/unit_test/spy.rbs +0 -8
  197. data/sig/unit_test/type_assertions.rbs +11 -0
  198. data/src/ast.c +410 -153
  199. data/src/lexer.c +1392 -1313
  200. data/src/lexer.re +3 -0
  201. data/src/lexstate.c +58 -37
  202. data/src/location.c +8 -48
  203. data/src/parser.c +977 -516
  204. data/src/string.c +0 -48
  205. data/src/util/rbs_allocator.c +89 -71
  206. data/src/util/rbs_assert.c +1 -1
  207. data/src/util/rbs_buffer.c +2 -2
  208. data/src/util/rbs_constant_pool.c +10 -14
  209. data/src/util/rbs_encoding.c +4 -8
  210. data/src/util/rbs_unescape.c +56 -20
  211. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  212. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  213. data/stdlib/cgi/0/core.rbs +9 -393
  214. data/stdlib/cgi/0/manifest.yaml +1 -0
  215. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  216. data/stdlib/coverage/0/coverage.rbs +7 -4
  217. data/stdlib/date/0/date.rbs +92 -79
  218. data/stdlib/date/0/date_time.rbs +25 -24
  219. data/stdlib/delegate/0/delegator.rbs +10 -7
  220. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  221. data/stdlib/digest/0/digest.rbs +110 -0
  222. data/stdlib/erb/0/erb.rbs +748 -347
  223. data/stdlib/etc/0/etc.rbs +55 -50
  224. data/stdlib/fileutils/0/fileutils.rbs +158 -139
  225. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  226. data/stdlib/io-console/0/io-console.rbs +2 -2
  227. data/stdlib/json/0/json.rbs +217 -136
  228. data/stdlib/monitor/0/monitor.rbs +3 -3
  229. data/stdlib/net-http/0/net-http.rbs +162 -134
  230. data/stdlib/objspace/0/objspace.rbs +17 -34
  231. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  232. data/stdlib/open3/0/open3.rbs +469 -10
  233. data/stdlib/openssl/0/openssl.rbs +475 -357
  234. data/stdlib/optparse/0/optparse.rbs +26 -17
  235. data/stdlib/pathname/0/pathname.rbs +11 -1381
  236. data/stdlib/pp/0/pp.rbs +9 -8
  237. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  238. data/stdlib/pstore/0/pstore.rbs +35 -30
  239. data/stdlib/psych/0/psych.rbs +65 -12
  240. data/stdlib/psych/0/store.rbs +2 -4
  241. data/stdlib/pty/0/pty.rbs +9 -6
  242. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  243. data/stdlib/rdoc/0/code_object.rbs +2 -1
  244. data/stdlib/rdoc/0/parser.rbs +1 -1
  245. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  246. data/stdlib/rdoc/0/store.rbs +1 -1
  247. data/stdlib/resolv/0/resolv.rbs +25 -68
  248. data/stdlib/ripper/0/ripper.rbs +22 -19
  249. data/stdlib/securerandom/0/manifest.yaml +2 -0
  250. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  251. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  252. data/stdlib/singleton/0/singleton.rbs +3 -0
  253. data/stdlib/socket/0/addrinfo.rbs +7 -7
  254. data/stdlib/socket/0/basic_socket.rbs +3 -3
  255. data/stdlib/socket/0/ip_socket.rbs +10 -8
  256. data/stdlib/socket/0/socket.rbs +23 -10
  257. data/stdlib/socket/0/tcp_server.rbs +1 -1
  258. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  259. data/stdlib/socket/0/udp_socket.rbs +1 -1
  260. data/stdlib/socket/0/unix_server.rbs +1 -1
  261. data/stdlib/stringio/0/stringio.rbs +1177 -85
  262. data/stdlib/strscan/0/string_scanner.rbs +27 -25
  263. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  264. data/stdlib/time/0/time.rbs +8 -6
  265. data/stdlib/timeout/0/timeout.rbs +63 -7
  266. data/stdlib/tsort/0/cyclic.rbs +3 -0
  267. data/stdlib/tsort/0/tsort.rbs +7 -6
  268. data/stdlib/uri/0/common.rbs +42 -20
  269. data/stdlib/uri/0/file.rbs +3 -3
  270. data/stdlib/uri/0/generic.rbs +26 -18
  271. data/stdlib/uri/0/http.rbs +2 -2
  272. data/stdlib/uri/0/ldap.rbs +2 -2
  273. data/stdlib/uri/0/mailto.rbs +3 -3
  274. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  275. data/stdlib/zlib/0/deflate.rbs +4 -3
  276. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  277. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  278. data/stdlib/zlib/0/inflate.rbs +1 -1
  279. data/stdlib/zlib/0/need_dict.rbs +1 -1
  280. data/stdlib/zlib/0/zstream.rbs +1 -0
  281. metadata +50 -6
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
+ # <strong>All-Implementations Configuration</strong>
201
186
  #
187
+ # The single read-only entry for all implementations is:
202
188
  #
203
- # ### GC Implementation specific values
189
+ # * <code>:implementation</code>: the string name of the implementation; for
190
+ # the Ruby default implementation, <code>'default'</code>.
204
191
  #
205
- # GC libraries are expected to document their own configuration. Valid keys for
206
- # Ruby's default GC implementation are:
192
+ # <strong>Implementation-Specific Configuration</strong>
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
+ # * <code>:rgengc_allow_full_mark</code>: Controls whether the GC is allowed
199
+ # to run a 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,200 @@ 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
+ # * <code>:count</code>: The total number of garbage collections run since
352
+ # application start (count includes both minor and major garbage
353
+ # collections).
354
+ # * <code>:time</code>: The total time spent in garbage collections (in
355
+ # milliseconds).
356
+ # * <code>:heap_allocated_pages</code>: The total number of allocated pages.
357
+ # * <code>:heap_empty_pages</code>: The number of pages with no live objects,
358
+ # and that could be released to the system.
359
+ # * <code>:heap_sorted_length</code>: The number of pages that can fit into
360
+ # the buffer that holds references to all pages.
361
+ # * <code>:heap_allocatable_pages</code>: The total number of pages the
362
+ # application could allocate without additional GC.
363
+ # * <code>:heap_available_slots</code>: The total number of slots in all
364
+ # <code>:heap_allocated_pages</code>.
365
+ # * <code>:heap_live_slots</code>: The total number of slots which contain
366
+ # live objects.
367
+ # * <code>:heap_free_slots</code>: The total number of slots which do not
368
+ # contain live objects.
369
+ # * <code>:heap_final_slots</code>: The total number of slots with pending
370
+ # finalizers to be run.
371
+ # * <code>:heap_marked_slots</code>: The total number of objects marked in the
372
+ # last GC.
373
+ # * <code>:heap_eden_pages</code>: The total number of pages which contain at
374
+ # least one live slot.
375
+ # * <code>:total_allocated_pages</code>: The cumulative number of pages
376
+ # allocated since application start.
377
+ # * <code>:total_freed_pages</code>: The cumulative number of pages freed
378
+ # since application start.
379
+ # * <code>:total_allocated_objects</code>: The cumulative number of objects
380
+ # allocated since application start.
381
+ # * <code>:total_freed_objects</code>: The cumulative number of objects freed
382
+ # since application start.
383
+ # * <code>:malloc_increase_bytes</code>: Amount of memory allocated on the
384
+ # heap for objects. Decreased by any GC.
385
+ # * <code>:malloc_increase_bytes_limit</code>: When
386
+ # <code>:malloc_increase_bytes</code> crosses this limit, GC is triggered.
387
+ # * <code>:minor_gc_count</code>: The total number of minor garbage
388
+ # collections run since process start.
389
+ # * <code>:major_gc_count</code>: The total number of major garbage
390
+ # collections run since process start.
391
+ # * <code>:compact_count</code>: The total number of compactions run since
392
+ # process start.
393
+ # * <code>:read_barrier_faults</code>: The total number of times the read
394
+ # barrier was triggered during compaction.
395
+ # * <code>:total_moved_objects</code>: The total number of objects compaction
396
+ # has moved.
397
+ # * <code>:remembered_wb_unprotected_objects</code>: The total number of
398
+ # objects without write barriers.
399
+ # * <code>:remembered_wb_unprotected_objects_limit</code>: When
400
+ # <code>:remembered_wb_unprotected_objects</code> crosses this limit, major
401
+ # GC is triggered.
402
+ # * <code>:old_objects</code>: Number of live, old objects which have survived
403
+ # at least 3 garbage collections.
404
+ # * <code>:old_objects_limit</code>: When <code>:old_objects</code> crosses
405
+ # this limit, major GC is triggered.
406
+ # * <code>:oldmalloc_increase_bytes</code>: Amount of memory allocated on the
407
+ # heap for objects. Decreased by major GC.
408
+ # * <code>:oldmalloc_increase_bytes_limit</code>: When
409
+ # <code>:oldmalloc_increase_bytes</code> crosses this limit, major GC is
410
+ # triggered.
406
411
  #
407
412
  def self.stat: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
408
413
  | (Symbol key) -> Integer
409
414
 
410
415
  # <!--
411
416
  # rdoc-file=gc.rb
412
- # - GC.measure_total_time = true/false
417
+ # - GC.measure_total_time = setting -> setting
413
418
  # -->
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.
419
+ # Enables or disables GC total time measurement; returns `setting`. See
420
+ # GC.total_time.
421
+ #
422
+ # When argument `object` is `nil` or `false`, disables total time measurement;
423
+ # GC.measure_total_time then returns `false`:
424
+ #
425
+ # GC.measure_total_time = nil # => nil
426
+ # GC.measure_total_time # => false
427
+ # GC.measure_total_time = false # => false
428
+ # GC.measure_total_time # => false
429
+ #
430
+ # Otherwise, enables total time measurement; GC.measure_total_time then returns
431
+ # `true`:
432
+ #
433
+ # GC.measure_total_time = true # => true
434
+ # GC.measure_total_time # => true
435
+ # GC.measure_total_time = :foo # => :foo
436
+ # GC.measure_total_time # => true
437
+ #
438
+ # Note that when enabled, total time measurement affects performance.
416
439
  #
417
440
  def self.measure_total_time=: [T] (T enable) -> T
418
441
 
419
442
  # <!--
420
443
  # rdoc-file=gc.rb
421
- # - GC.measure_total_time -> true/false
444
+ # - GC.measure_total_time -> true or false
422
445
  # -->
423
- # Returns the measure_total_time flag (default: `true`). Note that measurement
424
- # can affect the application's performance.
446
+ # Returns the setting for GC total time measurement; the initial setting is
447
+ # `true`. See GC.total_time.
425
448
  #
426
449
  def self.measure_total_time: () -> bool
427
450
 
@@ -447,71 +470,134 @@ module GC
447
470
 
448
471
  # <!--
449
472
  # 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
473
+ # - GC.stat_heap -> new_hash
474
+ # - GC.stat_heap(heap_id) -> new_hash
475
+ # - GC.stat_heap(heap_id, key) -> value
476
+ # - GC.stat_heap(nil, hash) -> hash
477
+ # - GC.stat_heap(heap_id, hash) -> hash
455
478
  # -->
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.
479
+ # This method is implementation-specific to CRuby.
480
+ #
481
+ # Returns statistics for GC heaps. The particular statistics are
482
+ # implementation-specific and may change in the future without notice.
483
+ #
484
+ # With no argument given, returns statistics for all heaps:
485
+ #
486
+ # GC.stat_heap
487
+ # # =>
488
+ # {0 =>
489
+ # {slot_size: 40,
490
+ # heap_eden_pages: 246,
491
+ # heap_eden_slots: 402802,
492
+ # total_allocated_pages: 246,
493
+ # force_major_gc_count: 2,
494
+ # force_incremental_marking_finish_count: 1,
495
+ # total_allocated_objects: 33867152,
496
+ # total_freed_objects: 33520523},
497
+ # 1 =>
498
+ # {slot_size: 80,
499
+ # heap_eden_pages: 84,
500
+ # heap_eden_slots: 68746,
501
+ # total_allocated_pages: 84,
502
+ # force_major_gc_count: 1,
503
+ # force_incremental_marking_finish_count: 4,
504
+ # total_allocated_objects: 147491,
505
+ # total_freed_objects: 90699},
506
+ # 2 =>
507
+ # {slot_size: 160,
508
+ # heap_eden_pages: 157,
509
+ # heap_eden_slots: 64182,
510
+ # total_allocated_pages: 157,
511
+ # force_major_gc_count: 0,
512
+ # force_incremental_marking_finish_count: 0,
513
+ # total_allocated_objects: 211460,
514
+ # total_freed_objects: 190075},
515
+ # 3 =>
516
+ # {slot_size: 320,
517
+ # heap_eden_pages: 8,
518
+ # heap_eden_slots: 1631,
519
+ # total_allocated_pages: 8,
520
+ # force_major_gc_count: 0,
521
+ # force_incremental_marking_finish_count: 0,
522
+ # total_allocated_objects: 1422,
523
+ # total_freed_objects: 700},
524
+ # 4 =>
525
+ # {slot_size: 640,
526
+ # heap_eden_pages: 16,
527
+ # heap_eden_slots: 1628,
528
+ # total_allocated_pages: 16,
529
+ # force_major_gc_count: 0,
530
+ # force_incremental_marking_finish_count: 0,
531
+ # total_allocated_objects: 1230,
532
+ # total_freed_objects: 309}}
533
+ #
534
+ # In the example above, the keys in the outer hash are the heap identifiers:
535
+ #
536
+ # GC.stat_heap.keys # => [0, 1, 2, 3, 4]
537
+ #
538
+ # On CRuby, each heap identifier is an integer; on other implementations, a heap
539
+ # identifier may be a string.
540
+ #
541
+ # With only argument `heap_id` given, returns statistics for the given heap
542
+ # identifier:
543
+ #
544
+ # GC.stat_heap(2)
545
+ # # =>
546
+ # {slot_size: 160,
547
+ # heap_eden_pages: 157,
548
+ # heap_eden_slots: 64182,
549
+ # total_allocated_pages: 157,
550
+ # force_major_gc_count: 0,
551
+ # force_incremental_marking_finish_count: 0,
552
+ # total_allocated_objects: 225018,
553
+ # total_freed_objects: 206647}
554
+ #
555
+ # With arguments `heap_id` and `key` given, returns the value for the given key
556
+ # in the given heap:
557
+ #
558
+ # GC.stat_heap(2, :slot_size) # => 160
559
+ #
560
+ # With arguments `nil` and `hash` given, merges the statistics for all heaps
561
+ # into the given hash:
562
+ #
563
+ # h = {foo: 0, bar: 1}
564
+ # GC.stat_heap(nil, h).keys # => [:foo, :bar, 0, 1, 2, 3, 4]
565
+ #
566
+ # With arguments `heap_id` and `hash` given, merges the statistics for the given
567
+ # heap into the given hash:
568
+ #
569
+ # h = {foo: 0, bar: 1}
570
+ # GC.stat_heap(2, h).keys
571
+ # # =>
572
+ # [:foo,
573
+ # :bar,
574
+ # :slot_size,
575
+ # :heap_eden_pages,
576
+ # :heap_eden_slots,
577
+ # :total_allocated_pages,
578
+ # :force_major_gc_count,
579
+ # :force_incremental_marking_finish_count,
580
+ # :total_allocated_objects,
581
+ # :total_freed_objects]
582
+ #
583
+ # The statistics for a heap may include:
584
+ #
585
+ # * <code>:slot_size</code>: The slot size of the heap in bytes.
586
+ # * <code>:heap_allocatable_pages</code>: The number of pages that can be
587
+ # allocated without triggering a new garbage collection cycle.
588
+ # * <code>:heap_eden_pages</code>: The number of pages in the eden heap.
589
+ # * <code>:heap_eden_slots</code>: The total number of slots in all of the
590
+ # pages in the eden heap.
591
+ # * <code>:total_allocated_pages</code>: The total number of pages that have
592
+ # been allocated in the heap.
593
+ # * <code>:total_freed_pages</code>: The total number of pages that have been
594
+ # freed and released back to the system in the heap.
595
+ # * <code>:force_major_gc_count</code>: The number of times this heap has
596
+ # forced major garbage collection cycles to start due to running out of free
597
+ # slots.
598
+ # * <code>:force_incremental_marking_finish_count</code>: The number of times
599
+ # this heap has forced incremental marking to complete due to running out of
600
+ # pooled slots.
515
601
  #
516
602
  def self.stat_heap: (?Integer? heap_name, ?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
517
603
  | (Integer heap_name, Symbol key) -> Integer
@@ -532,37 +618,67 @@ module GC
532
618
 
533
619
  # <!--
534
620
  # rdoc-file=gc.rb
535
- # - GC.stress -> integer, true, or false
621
+ # - GC.stress -> setting
536
622
  # -->
537
- # Returns the current status of GC stress mode.
623
+ # Returns the current GC stress-mode setting, which initially is `false`.
624
+ #
625
+ # The stress mode may be set by method GC.stress=.
538
626
  #
539
627
  def self.stress: () -> (Integer | bool)
540
628
 
541
629
  # <!--
542
630
  # rdoc-file=gc.rb
543
- # - GC.stress = flag -> flag
631
+ # - GC.stress = value -> value
544
632
  # -->
545
- # Updates the GC stress mode.
633
+ # Enables or disables stress mode; enabling stress mode will degrade
634
+ # performance; it is only for debugging.
635
+ #
636
+ # Sets the current GC stress mode to the given value:
546
637
  #
547
- # When stress mode is enabled, the GC is invoked at every GC opportunity: all
548
- # memory and object allocations.
638
+ # * If the value is `nil` or `false`, disables stress mode.
639
+ # * If the value is an integer, enables stress mode with certain flags; see
640
+ # below.
641
+ # * Otherwise, enables stress mode; GC is invoked at every GC opportunity: all
642
+ # memory and object allocations.
549
643
  #
550
- # Enabling stress mode will degrade performance; it is only for debugging.
644
+ # The flags are bits in the given integer:
551
645
  #
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
646
+ # * `0x01`: No major GC.
647
+ # * `0x02`: No immediate sweep.
648
+ # * `0x04`: Full mark after malloc/calloc/realloc.
557
649
  #
558
650
  def self.stress=: (Integer flag) -> Integer
559
651
  | (bool flag) -> bool
560
652
 
561
653
  # <!--
562
654
  # rdoc-file=gc.rb
563
- # - GC.total_time -> int
655
+ # - GC.total_time -> integer
564
656
  # -->
565
- # Returns the measured GC total time in nanoseconds.
657
+ # Returns the GC total time in nanoseconds:
658
+ #
659
+ # GC.total_time # => 156250
660
+ #
661
+ # Note that total time accumulates only when total time measurement is enabled
662
+ # (that is, when GC.measure_total_time is `true`):
663
+ #
664
+ # GC.measure_total_time # => true
665
+ # GC.total_time # => 625000
666
+ # GC.start
667
+ # GC.total_time # => 937500
668
+ # GC.start
669
+ # GC.total_time # => 1093750
670
+ #
671
+ # GC.measure_total_time = false
672
+ # GC.total_time # => 1250000
673
+ # GC.start
674
+ # GC.total_time # => 1250000
675
+ # GC.start
676
+ # GC.total_time # => 1250000
677
+ #
678
+ # GC.measure_total_time = true
679
+ # GC.total_time # => 1250000
680
+ # GC.start
681
+ # GC.total_time # => 1406250
566
682
  #
567
683
  def self.total_time: () -> Integer
568
684
 
@@ -619,17 +735,45 @@ module GC
619
735
 
620
736
  # <!--
621
737
  # rdoc-file=gc.rb
622
- # - GC.latest_gc_info -> hash
623
- # - GC.latest_gc_info(hash) -> hash
738
+ # - GC.latest_gc_info -> new_hash
624
739
  # - GC.latest_gc_info(key) -> value
740
+ # - GC.latest_gc_info(hash) -> hash
625
741
  # -->
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]`.
742
+ # With no argument given, returns information about the most recent garbage
743
+ # collection:
744
+ #
745
+ # GC.latest_gc_info
746
+ # # =>
747
+ # {major_by: :force,
748
+ # need_major_by: nil,
749
+ # gc_by: :method,
750
+ # have_finalizer: false,
751
+ # immediate_sweep: true,
752
+ # state: :none,
753
+ # weak_references_count: 0,
754
+ # retained_weak_references_count: 0}
755
+ #
756
+ # With symbol argument `key` given, returns the value for that key:
757
+ #
758
+ # GC.latest_gc_info(:gc_by) # => :newobj
759
+ #
760
+ # With hash argument `hash` given, returns that hash with GC information merged
761
+ # into its content; this form may be useful in minimizing [probe
762
+ # effects](https://en.wikipedia.org/wiki/Probe_effect):
763
+ #
764
+ # h = {foo: 0, bar: 1}
765
+ # GC.latest_gc_info(h)
766
+ # # =>
767
+ # {foo: 0,
768
+ # bar: 1,
769
+ # major_by: nil,
770
+ # need_major_by: nil,
771
+ # gc_by: :newobj,
772
+ # have_finalizer: false,
773
+ # immediate_sweep: false,
774
+ # state: :sweeping,
775
+ # weak_references_count: 0,
776
+ # retained_weak_references_count: 0}
633
777
  #
634
778
  def self.latest_gc_info: (?Hash[Symbol, untyped]? hash) -> Hash[Symbol, untyped]
635
779
  | (Symbol key) -> untyped