rbs 3.3.2 → 3.4.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -5
  3. data/.github/workflows/ruby.yml +7 -8
  4. data/.github/workflows/typecheck.yml +37 -0
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +11 -11
  8. data/Steepfile +2 -2
  9. data/core/array.rbs +19 -49
  10. data/core/basic_object.rbs +2 -2
  11. data/core/comparable.rbs +17 -8
  12. data/core/complex.rbs +82 -43
  13. data/core/data.rbs +2 -4
  14. data/core/dir.rbs +635 -295
  15. data/core/enumerable.rbs +11 -18
  16. data/core/enumerator.rbs +37 -31
  17. data/core/errors.rbs +4 -0
  18. data/core/false_class.rbs +34 -15
  19. data/core/fiber.rbs +23 -0
  20. data/core/file.rbs +329 -120
  21. data/core/float.rbs +17 -32
  22. data/core/gc.rbs +17 -11
  23. data/core/hash.rbs +22 -44
  24. data/core/integer.rbs +82 -113
  25. data/core/io/buffer.rbs +90 -47
  26. data/core/io.rbs +39 -116
  27. data/core/kernel.rbs +442 -489
  28. data/core/match_data.rbs +55 -56
  29. data/core/module.rbs +45 -1
  30. data/core/nil_class.rbs +98 -35
  31. data/core/numeric.rbs +22 -32
  32. data/core/object_space/weak_key_map.rbs +102 -0
  33. data/core/process.rbs +1242 -655
  34. data/core/ractor.rbs +139 -120
  35. data/core/range.rbs +100 -4
  36. data/core/rational.rbs +0 -4
  37. data/core/rbs/unnamed/argf.rbs +16 -8
  38. data/core/rbs/unnamed/env_class.rbs +0 -24
  39. data/core/refinement.rbs +8 -0
  40. data/core/regexp.rbs +1149 -598
  41. data/core/ruby_vm.rbs +126 -12
  42. data/core/rubygems/platform.rbs +9 -0
  43. data/core/rubygems/rubygems.rbs +1 -1
  44. data/core/rubygems/version.rbs +5 -1
  45. data/core/set.rbs +20 -22
  46. data/core/signal.rbs +4 -4
  47. data/core/string.rbs +283 -230
  48. data/core/string_io.rbs +2 -14
  49. data/core/struct.rbs +404 -24
  50. data/core/symbol.rbs +1 -19
  51. data/core/thread.rbs +29 -12
  52. data/core/time.rbs +227 -104
  53. data/core/trace_point.rbs +2 -5
  54. data/core/true_class.rbs +54 -21
  55. data/core/warning.rbs +14 -11
  56. data/docs/data_and_struct.md +29 -0
  57. data/docs/syntax.md +3 -5
  58. data/docs/tools.md +1 -0
  59. data/ext/rbs_extension/lexer.c +643 -559
  60. data/ext/rbs_extension/lexer.re +5 -1
  61. data/ext/rbs_extension/parser.c +12 -3
  62. data/ext/rbs_extension/unescape.c +7 -47
  63. data/lib/rbs/cli/diff.rb +4 -1
  64. data/lib/rbs/cli/validate.rb +280 -0
  65. data/lib/rbs/cli.rb +2 -194
  66. data/lib/rbs/collection/config.rb +5 -6
  67. data/lib/rbs/collection/sources/git.rb +1 -1
  68. data/lib/rbs/collection.rb +1 -0
  69. data/lib/rbs/diff.rb +7 -4
  70. data/lib/rbs/errors.rb +11 -0
  71. data/lib/rbs/test/errors.rb +4 -1
  72. data/lib/rbs/test/guaranteed.rb +2 -3
  73. data/lib/rbs/test/type_check.rb +15 -10
  74. data/lib/rbs/test.rb +3 -3
  75. data/lib/rbs/types.rb +29 -0
  76. data/lib/rbs/unit_test/convertibles.rb +176 -0
  77. data/lib/rbs/unit_test/spy.rb +136 -0
  78. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  79. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  80. data/lib/rbs/unit_test.rb +6 -0
  81. data/lib/rbs/version.rb +1 -1
  82. data/sig/cli/validate.rbs +43 -0
  83. data/sig/diff.rbs +3 -1
  84. data/sig/errors.rbs +8 -0
  85. data/sig/rbs.rbs +1 -1
  86. data/sig/test/errors.rbs +52 -0
  87. data/sig/test/guranteed.rbs +9 -0
  88. data/sig/test/type_check.rbs +19 -0
  89. data/sig/test.rbs +82 -0
  90. data/sig/types.rbs +6 -1
  91. data/sig/unit_test/convertibles.rbs +154 -0
  92. data/sig/unit_test/spy.rbs +28 -0
  93. data/sig/unit_test/type_assertions.rbs +194 -0
  94. data/sig/unit_test/with_aliases.rbs +136 -0
  95. data/stdlib/base64/0/base64.rbs +307 -45
  96. data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
  97. data/stdlib/coverage/0/coverage.rbs +2 -2
  98. data/stdlib/csv/0/csv.rbs +25 -55
  99. data/stdlib/date/0/date.rbs +1 -43
  100. data/stdlib/date/0/date_time.rbs +1 -13
  101. data/stdlib/delegate/0/delegator.rbs +186 -0
  102. data/stdlib/delegate/0/kernel.rbs +47 -0
  103. data/stdlib/delegate/0/simple_delegator.rbs +98 -0
  104. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
  105. data/stdlib/erb/0/erb.rbs +2 -2
  106. data/stdlib/fileutils/0/fileutils.rbs +0 -19
  107. data/stdlib/io-console/0/io-console.rbs +12 -1
  108. data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
  109. data/stdlib/json/0/json.rbs +320 -81
  110. data/stdlib/logger/0/logger.rbs +9 -5
  111. data/stdlib/monitor/0/monitor.rbs +78 -0
  112. data/stdlib/net-http/0/net-http.rbs +1880 -543
  113. data/stdlib/objspace/0/objspace.rbs +19 -13
  114. data/stdlib/openssl/0/openssl.rbs +508 -127
  115. data/stdlib/optparse/0/optparse.rbs +25 -11
  116. data/stdlib/pathname/0/pathname.rbs +1 -1
  117. data/stdlib/pp/0/pp.rbs +2 -5
  118. data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
  119. data/stdlib/pstore/0/pstore.rbs +2 -4
  120. data/stdlib/rdoc/0/comment.rbs +1 -2
  121. data/stdlib/resolv/0/resolv.rbs +4 -2
  122. data/stdlib/socket/0/socket.rbs +2 -2
  123. data/stdlib/socket/0/unix_socket.rbs +2 -2
  124. data/stdlib/strscan/0/string_scanner.rbs +3 -2
  125. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  126. data/stdlib/uri/0/common.rbs +245 -123
  127. metadata +23 -4
  128. data/lib/rbs/test/spy.rb +0 -6
data/core/ruby_vm.rbs CHANGED
@@ -11,21 +11,21 @@ class RubyVM < Object
11
11
  end
12
12
 
13
13
  # <!-- rdoc-file=vm.c -->
14
- # DEFAULT_PARAMS This constant exposes the VM's default parameters. Note that
15
- # changing these values does not affect VM execution. Specification is not
16
- # stable and you should not depend on this value. Of course, this constant is
17
- # MRI specific.
14
+ # ::RubyVM::DEFAULT_PARAMS This constant exposes the VM's default parameters.
15
+ # Note that changing these values does not affect VM execution. Specification is
16
+ # not stable and you should not depend on this value. Of course, this constant
17
+ # is MRI specific.
18
18
  #
19
19
  RubyVM::DEFAULT_PARAMS: Hash[Symbol, Integer]
20
20
 
21
21
  # <!-- rdoc-file=vm.c -->
22
- # INSTRUCTION_NAMES A list of bytecode instruction names in MRI. This constant
23
- # is MRI specific.
22
+ # ::RubyVM::INSTRUCTION_NAMES A list of bytecode instruction names in MRI. This
23
+ # constant is MRI specific.
24
24
  #
25
25
  RubyVM::INSTRUCTION_NAMES: Array[String]
26
26
 
27
27
  # <!-- rdoc-file=vm.c -->
28
- # OPTS An Array of VM build options. This constant is MRI specific.
28
+ # ::RubyVM::OPTS An Array of VM build options. This constant is MRI specific.
29
29
  #
30
30
  RubyVM::OPTS: Array[String]
31
31
 
@@ -73,7 +73,7 @@ end
73
73
  module RubyVM::AbstractSyntaxTree
74
74
  # <!--
75
75
  # rdoc-file=ast.rb
76
- # - RubyVM::AbstractSyntaxTree.parse(string, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
76
+ # - RubyVM::AbstractSyntaxTree.parse(string, keep_script_lines: RubyVM.keep_script_lines, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
77
77
  # -->
78
78
  # Parses the given *string* into an abstract syntax tree, returning the root
79
79
  # node of that tree.
@@ -106,13 +106,13 @@ module RubyVM::AbstractSyntaxTree
106
106
  # # (ERROR@1:7-1:11),
107
107
  # # (LASGN@1:12-1:15 :y (LIT@1:14-1:15 2))]
108
108
  #
109
- # Note that parsing continues even after the errored expresion.
109
+ # Note that parsing continues even after the errored expression.
110
110
  #
111
111
  def self.parse: (String string, ?keep_script_lines: bool, ?error_tolerant: bool, ?keep_tokens: bool) -> Node
112
112
 
113
113
  # <!--
114
114
  # rdoc-file=ast.rb
115
- # - RubyVM::AbstractSyntaxTree.parse_file(pathname, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
115
+ # - RubyVM::AbstractSyntaxTree.parse_file(pathname, keep_script_lines: RubyVM.keep_script_lines, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
116
116
  # -->
117
117
  # Reads the file from *pathname*, then parses it like ::parse, returning the
118
118
  # root node of the abstract syntax tree.
@@ -128,8 +128,8 @@ module RubyVM::AbstractSyntaxTree
128
128
 
129
129
  # <!--
130
130
  # rdoc-file=ast.rb
131
- # - RubyVM::AbstractSyntaxTree.of(proc, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
132
- # - RubyVM::AbstractSyntaxTree.of(method, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
131
+ # - RubyVM::AbstractSyntaxTree.of(proc, keep_script_lines: RubyVM.keep_script_lines, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
132
+ # - RubyVM::AbstractSyntaxTree.of(method, keep_script_lines: RubyVM.keep_script_lines, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node
133
133
  # -->
134
134
  # Returns AST nodes of the given *proc* or *method*.
135
135
  #
@@ -260,4 +260,118 @@ module RubyVM::AbstractSyntaxTree
260
260
  #
261
261
  def children: () -> Array[untyped]
262
262
  end
263
+
264
+ # <!-- rdoc-file=yjit.rb -->
265
+ # This module allows for introspection of YJIT, CRuby's just-in-time compiler.
266
+ # Everything in the module is highly implementation specific and the API might
267
+ # be less stable compared to the standard library.
268
+ # This module may not exist if YJIT does not support the particular platform
269
+ # for which CRuby is built.
270
+ #
271
+ module YJIT
272
+ # <!--
273
+ # rdoc-file=yjit.rb
274
+ # - code_gc()
275
+ # -->
276
+ # Discard existing compiled code to reclaim memory
277
+ # and allow for recompilations in the future.
278
+ #
279
+ def self.code_gc: () -> void
280
+
281
+ # <!--
282
+ # rdoc-file=yjit.rb
283
+ # - dump_exit_locations(filename)
284
+ # -->
285
+ # Marshal dumps exit locations to the given filename.
286
+ # Usage:
287
+ # If `--yjit-exit-locations` is passed, a file named
288
+ # "yjit_exit_locations.dump" will automatically be generated.
289
+ # If you want to collect traces manually, call `dump_exit_locations`
290
+ # directly.
291
+ # Note that calling this in a script will generate stats after the
292
+ # dump is created, so the stats data may include exits from the
293
+ # dump itself.
294
+ # In a script call:
295
+ # at_exit do
296
+ # RubyVM::YJIT.dump_exit_locations("my_file.dump")
297
+ # end
298
+ #
299
+ # Then run the file with the following options:
300
+ # ruby --yjit --yjit-trace-exits test.rb
301
+ #
302
+ # Once the code is done running, use Stackprof to read the dump file.
303
+ # See Stackprof documentation for options.
304
+ #
305
+ def self.dump_exit_locations: (untyped filename) -> void
306
+
307
+ # <!--
308
+ # rdoc-file=yjit.rb
309
+ # - enable()
310
+ # -->
311
+ # Enable YJIT compilation.
312
+ #
313
+ def self.enable: () -> void
314
+
315
+ # <!--
316
+ # rdoc-file=yjit.rb
317
+ # - enabled?()
318
+ # -->
319
+ # Check if YJIT is enabled.
320
+ #
321
+ def self.enabled?: () -> bool
322
+
323
+ # <!--
324
+ # rdoc-file=yjit.rb
325
+ # - format_number(pad, number)
326
+ # -->
327
+ # Format large numbers with comma separators for readability
328
+ #
329
+ def self.format_number: (untyped pad, untyped number) -> untyped
330
+
331
+ # <!--
332
+ # rdoc-file=yjit.rb
333
+ # - format_number_pct(pad, number, total)
334
+ # -->
335
+ # Format a number along with a percentage over a total value
336
+ #
337
+ def self.format_number_pct: (untyped pad, untyped number, untyped total) -> untyped
338
+
339
+ # <!--
340
+ # rdoc-file=yjit.rb
341
+ # - reset_stats!()
342
+ # -->
343
+ # Discard statistics collected for `--yjit-stats`.
344
+ #
345
+ def self.reset_stats!: () -> void
346
+
347
+ # <!--
348
+ # rdoc-file=yjit.rb
349
+ # - runtime_stats(context: false)
350
+ # -->
351
+ # Return a hash for statistics generated for the `--yjit-stats` command line
352
+ # option.
353
+ # Return `nil` when option is not passed or unavailable.
354
+ #
355
+ def self.runtime_stats: (?context: bool) -> Hash[untyped, untyped]?
356
+
357
+ # <!--
358
+ # rdoc-file=yjit.rb
359
+ # - stats_enabled?()
360
+ # -->
361
+ # Check if `--yjit-stats` is used.
362
+ #
363
+ def self.stats_enabled?: () -> bool
364
+
365
+ # <!--
366
+ # rdoc-file=yjit.rb
367
+ # - stats_string()
368
+ # -->
369
+ # Format and print out counters as a String. This returns a non-empty
370
+ # content only when `--yjit-stats` is enabled.
371
+ #
372
+ def self.stats_string: () -> String
373
+ end
374
+
375
+ module RJIT
376
+ end
263
377
  end
@@ -1,3 +1,12 @@
1
+ # <!-- rdoc-file=lib/rubygems.rb -->
2
+ # TruffleRuby >= 24 defines REUSE_AS_BINARY_ON_TRUFFLERUBY in
3
+ # defaults/truffleruby. However, TruffleRuby < 24 defines
4
+ # REUSE_AS_BINARY_ON_TRUFFLERUBY directly in its copy of
5
+ # lib/rubygems/platform.rb, so it is not defined if RubyGems is updated (gem
6
+ # update --system). Instead, we define it here in that case, similar to
7
+ # bundler/lib/bundler/rubygems_ext.rb. We must define it here and not in
8
+ # platform.rb because platform.rb is loaded before defaults/truffleruby.
9
+ #
1
10
  # <!-- rdoc-file=lib/rubygems/platform.rb -->
2
11
  # Available list of platforms for targeting Gem installations.
3
12
  #
@@ -156,7 +156,7 @@ module Gem
156
156
  # - activated_gem_paths()
157
157
  # -->
158
158
  # The number of paths in the +$LOAD_PATH+ from activated gems. Used to
159
- # prioritize `-I` and +[ENV]('RUBYLIB')+ entries during `require`.
159
+ # prioritize `-I` and `ENV['RUBYLIB']` entries during `require`.
160
160
  #
161
161
  def self.activated_gem_paths: () -> Integer
162
162
 
@@ -138,7 +138,9 @@ module Gem
138
138
  #
139
139
  # ## Preventing Version Catastrophe:
140
140
  #
141
- # From: http://blog.zenspider.com/2008/10/rubygems-howto-preventing-cata.html
141
+ # From:
142
+ # https://www.zenspider.com/ruby/2008/10/rubygems-how-to-preventing-catastrophe.
143
+ # html
142
144
  #
143
145
  # Let's say you're depending on the fnord gem version 2.y.z. If you specify your
144
146
  # dependency as ">= 2.0.0" then, you're good, right? What happens if fnord 3.0
@@ -225,6 +227,8 @@ module Gem
225
227
  # rdoc-file=lib/rubygems/version.rb
226
228
  # - canonical_segments()
227
229
  # -->
230
+ # remove trailing zeros segments before first letter or at the end of the
231
+ # version
228
232
  #
229
233
  def canonical_segments: () -> Array[Integer | String]
230
234
 
data/core/set.rbs CHANGED
@@ -1,11 +1,8 @@
1
1
  # <!-- rdoc-file=lib/set.rb -->
2
- # This library provides the Set class, which deals with a collection
2
+ # This library provides the Set class, which implements a collection
3
3
  # of unordered values with no duplicates. It is a hybrid of Array's
4
4
  # intuitive inter-operation facilities and Hash's fast lookup.
5
5
  # The method `to_set` is added to Enumerable for convenience.
6
- # Set implements a collection of unordered values with no duplicates.
7
- # This is a hybrid of Array's intuitive inter-operation facilities and
8
- # Hash's fast lookup.
9
6
  # Set is easy to use with Enumerable objects (implementing `each`).
10
7
  # Most of the initializer methods and binary operators accept generic
11
8
  # Enumerable objects besides sets and arrays. An Enumerable object
@@ -60,7 +57,7 @@
60
57
  #
61
58
  # ### Methods for Creating a Set
62
59
  # * ::[]:
63
- # Returns a new set containing the given objects.
60
+ # Returns a new set containing the given objects.
64
61
  # * ::new:
65
62
  # Returns a new set containing either the given objects
66
63
  # (if no block given) or the return values from the called block
@@ -89,13 +86,13 @@
89
86
  # as determined by Object#eql?.
90
87
  # * #compare_by_identity?:
91
88
  # Returns whether the set considers only identity
92
- # when comparing elements.
89
+ # when comparing elements.
93
90
  #
94
91
  # ### Methods for Querying
95
92
  # * #length (aliased as #size):
96
- # Returns the count of elements.
93
+ # Returns the count of elements.
97
94
  # * #empty?:
98
- # Returns whether the set has no elements.
95
+ # Returns whether the set has no elements.
99
96
  # * #include? (aliased as #member? and #===):
100
97
  # Returns whether a given object is an element in the set.
101
98
  # * #subset? (aliased as [<=](#method-i-3C-3D)):
@@ -114,37 +111,38 @@
114
111
  # have any common elements, `false` otherwise.
115
112
  # * #compare_by_identity?:
116
113
  # Returns whether the set considers only identity
117
- # when comparing elements.
114
+ # when comparing elements.
118
115
  #
119
116
  # ### Methods for Assigning
120
117
  # * #add (aliased as #<<):
121
- # Adds a given object to the set; returns `self`.
118
+ # Adds a given object to the set; returns `self`.
122
119
  # * #add?:
123
120
  # If the given object is not an element in the set,
124
121
  # adds it and returns `self`; otherwise, returns `nil`.
125
122
  # * #merge:
126
- # Adds each given object to the set; returns `self`.
123
+ # Merges the elements of each given enumerable object to the set; returns
124
+ # `self`.
127
125
  # * #replace:
128
126
  # Replaces the contents of the set with the contents
129
127
  # of a given enumerable.
130
128
  #
131
129
  # ### Methods for Deleting
132
130
  # * #clear:
133
- # Removes all elements in the set; returns `self`.
131
+ # Removes all elements in the set; returns `self`.
134
132
  # * #delete:
135
- # Removes a given object from the set; returns `self`.
133
+ # Removes a given object from the set; returns `self`.
136
134
  # * #delete?:
137
135
  # If the given object is an element in the set,
138
136
  # removes it and returns `self`; otherwise, returns `nil`.
139
137
  # * #subtract:
140
- # Removes each given object from the set; returns `self`.
138
+ # Removes each given object from the set; returns `self`.
141
139
  # * #delete_if - Removes elements specified by a given block.
142
140
  # * #select! (aliased as #filter!):
143
141
  # Removes elements not specified by a given block.
144
142
  # * #keep_if:
145
- # Removes elements not specified by a given block.
143
+ # Removes elements not specified by a given block.
146
144
  # * #reject!
147
- # Removes elements specified by a given block.
145
+ # Removes elements specified by a given block.
148
146
  #
149
147
  # ### Methods for Converting
150
148
  # * #classify:
@@ -162,20 +160,20 @@
162
160
  # #flatten!:
163
161
  # Replaces each nested set in `self` with the elements from that set.
164
162
  # * #inspect (aliased as #to_s):
165
- # Returns a string displaying the elements.
163
+ # Returns a string displaying the elements.
166
164
  # * #join:
167
165
  # Returns a string containing all elements, converted to strings
168
166
  # as needed, and joined by the given record separator.
169
167
  # * #to_a:
170
- # Returns an array containing all set elements.
168
+ # Returns an array containing all set elements.
171
169
  # * #to_set:
172
170
  # Returns `self` if given no arguments and no block;
173
171
  # with a block given, returns a new set consisting of block
174
- # return values.
172
+ # return values.
175
173
  #
176
174
  # ### Methods for Iterating
177
175
  # * #each:
178
- # Calls the block with each successive element; returns `self`.
176
+ # Calls the block with each successive element; returns `self`.
179
177
  #
180
178
  # ### Other Methods
181
179
  # * #reset:
@@ -531,9 +529,9 @@ class Set[unchecked out A]
531
529
 
532
530
  # <!--
533
531
  # rdoc-file=lib/set.rb
534
- # - merge(enum)
532
+ # - merge(*enums, **nil)
535
533
  # -->
536
- # Merges the elements of the given enumerable object to the set and
534
+ # Merges the elements of the given enumerable objects to the set and
537
535
  # returns self.
538
536
  #
539
537
  def merge: (_Each[A]) -> self
data/core/signal.rbs CHANGED
@@ -26,9 +26,9 @@
26
26
  # # ...
27
27
  # Process.kill("TERM", pid)
28
28
  #
29
- # produces:
30
- # Debug now: true
31
- # Debug now: false
29
+ # *produces:*
30
+ # Debug now: true
31
+ # Debug now: false
32
32
  # Terminating...
33
33
  #
34
34
  # The list of available signal names and their interpretation is system
@@ -84,7 +84,7 @@ module Signal
84
84
  # Signal.trap("CLD") { puts "Child died" }
85
85
  # fork && Process.wait
86
86
  #
87
- # produces:
87
+ # *produces:*
88
88
  # Terminating: 27461
89
89
  # Child died
90
90
  # Terminating: 27460