rbs 0.2.0 → 0.6.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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +35 -0
  5. data/COPYING +1 -1
  6. data/Gemfile +16 -2
  7. data/README.md +87 -48
  8. data/Rakefile +54 -22
  9. data/bin/rbs-prof +9 -0
  10. data/bin/run_in_md.rb +49 -0
  11. data/bin/test_runner.rb +0 -2
  12. data/docs/sigs.md +6 -6
  13. data/docs/stdlib.md +3 -5
  14. data/docs/syntax.md +6 -3
  15. data/goodcheck.yml +65 -0
  16. data/lib/rbs.rb +3 -0
  17. data/lib/rbs/ast/declarations.rb +115 -14
  18. data/lib/rbs/ast/members.rb +41 -17
  19. data/lib/rbs/cli.rb +301 -123
  20. data/lib/rbs/constant.rb +4 -4
  21. data/lib/rbs/constant_table.rb +64 -53
  22. data/lib/rbs/definition.rb +175 -59
  23. data/lib/rbs/definition_builder.rb +646 -603
  24. data/lib/rbs/environment.rb +352 -210
  25. data/lib/rbs/environment_walker.rb +14 -23
  26. data/lib/rbs/errors.rb +159 -3
  27. data/lib/rbs/factory.rb +14 -0
  28. data/lib/rbs/namespace.rb +18 -0
  29. data/lib/rbs/parser.y +75 -21
  30. data/lib/rbs/prototype/rb.rb +119 -117
  31. data/lib/rbs/prototype/rbi.rb +5 -3
  32. data/lib/rbs/prototype/runtime.rb +34 -7
  33. data/lib/rbs/substitution.rb +8 -1
  34. data/lib/rbs/test.rb +81 -3
  35. data/lib/rbs/test/errors.rb +1 -1
  36. data/lib/rbs/test/hook.rb +133 -259
  37. data/lib/rbs/test/observer.rb +17 -0
  38. data/lib/rbs/test/setup.rb +13 -14
  39. data/lib/rbs/test/spy.rb +0 -321
  40. data/lib/rbs/test/tester.rb +116 -0
  41. data/lib/rbs/test/type_check.rb +44 -7
  42. data/lib/rbs/type_name_resolver.rb +58 -0
  43. data/lib/rbs/types.rb +94 -2
  44. data/lib/rbs/validator.rb +51 -0
  45. data/lib/rbs/variance_calculator.rb +12 -2
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs/writer.rb +127 -91
  48. data/rbs.gemspec +0 -9
  49. data/schema/annotation.json +14 -0
  50. data/schema/comment.json +26 -0
  51. data/schema/decls.json +353 -0
  52. data/schema/function.json +87 -0
  53. data/schema/location.json +56 -0
  54. data/schema/members.json +248 -0
  55. data/schema/methodType.json +44 -0
  56. data/schema/types.json +299 -0
  57. data/stdlib/benchmark/benchmark.rbs +151 -151
  58. data/stdlib/builtin/encoding.rbs +2 -0
  59. data/stdlib/builtin/enumerable.rbs +2 -2
  60. data/stdlib/builtin/enumerator.rbs +3 -1
  61. data/stdlib/builtin/fiber.rbs +5 -1
  62. data/stdlib/builtin/file.rbs +0 -3
  63. data/stdlib/builtin/io.rbs +4 -4
  64. data/stdlib/builtin/proc.rbs +1 -2
  65. data/stdlib/builtin/symbol.rbs +1 -1
  66. data/stdlib/builtin/thread.rbs +2 -2
  67. data/stdlib/csv/csv.rbs +4 -6
  68. data/stdlib/fiber/fiber.rbs +117 -0
  69. data/stdlib/json/json.rbs +1 -1
  70. data/stdlib/logger/formatter.rbs +23 -0
  71. data/stdlib/logger/log_device.rbs +39 -0
  72. data/stdlib/logger/logger.rbs +507 -0
  73. data/stdlib/logger/period.rbs +7 -0
  74. data/stdlib/logger/severity.rbs +8 -0
  75. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  76. data/stdlib/pathname/pathname.rbs +6 -6
  77. data/stdlib/prime/integer-extension.rbs +1 -1
  78. data/stdlib/prime/prime.rbs +44 -44
  79. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  80. metadata +26 -116
  81. data/lib/rbs/test/test_helper.rb +0 -183
@@ -139,7 +139,7 @@ module Benchmark
139
139
  # >total: 2.930000 0.000000 2.930000 ( 2.932889)
140
140
  # >avg: 0.976667 0.000000 0.976667 ( 0.977630)
141
141
  #
142
- def self?.benchmark: (String caption, ?Integer? label_width, ?String? format, *String labels) { (Report report) -> (Array[Tms] | void) } -> ::Array[Benchmark::Tms]
142
+ def self?.benchmark: (String caption, ?Integer? label_width, ?String? format, *String labels) { (Report report) -> (Array[Tms] | void) } -> Array[Tms]
143
143
 
144
144
  # A simple interface to the #benchmark method, #bm generates sequential reports
145
145
  # with labels. `label_width` and `labels` parameters have the same meaning as
@@ -161,7 +161,7 @@ module Benchmark
161
161
  # times: 0.960000 0.000000 0.960000 ( 0.960423)
162
162
  # upto: 0.950000 0.000000 0.950000 ( 0.954864)
163
163
  #
164
- def self?.bm: (?Integer label_width, *String labels) { (Report report) -> void } -> ::Array[Benchmark::Tms]
164
+ def self?.bm: (?Integer label_width, *String labels) { (Report report) -> void } -> Array[Tms]
165
165
 
166
166
  # Sometimes benchmark results are skewed because code executed earlier
167
167
  # encounters different garbage collection overheads than that run later. #bmbm
@@ -198,7 +198,7 @@ module Benchmark
198
198
  # #bmbm yields a Benchmark::Job object and returns an array of Benchmark::Tms
199
199
  # objects.
200
200
  #
201
- def self?.bmbm: (?Integer width) { (Job job) -> void } -> ::Array[Benchmark::Tms]
201
+ def self?.bmbm: (?Integer width) { (Job job) -> void } -> Array[Tms]
202
202
 
203
203
  # Returns the time used to execute the given block as a Benchmark::Tms object.
204
204
  # Takes `label` option.
@@ -216,157 +216,157 @@ module Benchmark
216
216
  #
217
217
  # 0.220000 0.000000 0.220000 ( 0.227313)
218
218
  #
219
- def self?.measure: (?String label) { () -> void } -> Benchmark::Tms
219
+ def self?.measure: (?String label) { () -> void } -> Tms
220
220
 
221
221
  # Returns the elapsed real time used to execute the given block.
222
222
  #
223
223
  def self?.realtime: () { () -> void } -> Float
224
- end
225
-
226
- Benchmark::BENCHMARK_VERSION: String
227
-
228
- # The default caption string (heading above the output times).
229
- #
230
- Benchmark::CAPTION: String
231
-
232
- # The default format string used to display times. See also
233
- # Benchmark::Tms#format.
234
- #
235
- Benchmark::FORMAT: String
236
-
237
- class Benchmark::Job
238
- # Prints the `label` and measured time for the block,
239
- # formatted by `format`. See Tms#format for the
240
- # formatting rules.
241
- def item: (?String label) { () -> void } -> self
242
-
243
- # An array of 2-element arrays, consisting of label and block pairs.
244
- def list: () -> ::Array[untyped]
245
-
246
- alias report item
247
-
248
- # Length of the widest label in the #list.
249
- def width: () -> Integer
250
- end
251
-
252
- class Benchmark::Report
253
- # Prints the `label` and measured time for the block,
254
- # formatted by `format`. See Tms#format for the
255
- # formatting rules.
256
- def item: (?String label, *untyped format) { () -> void } -> Tms
257
-
258
- # An array of Benchmark::Tms objects representing each item.
259
- def list: () -> ::Array[Benchmark::Tms]
260
-
261
- alias report item
262
- end
263
-
264
- # A data object, representing the times associated with a benchmark measurement.
265
- #
266
- class Benchmark::Tms
267
- # Returns a new Tms object obtained by memberwise multiplication of the
268
- # individual times for this Tms object by `x`.
269
- #
270
- def *: (untyped x) -> untyped
271
-
272
- # Returns a new Tms object obtained by memberwise summation of the individual
273
- # times for this Tms object with those of the `other` Tms object. This method
274
- # and #/() are useful for taking statistics.
275
- #
276
- def +: (untyped other) -> untyped
277
-
278
- # Returns a new Tms object obtained by memberwise subtraction of the individual
279
- # times for the `other` Tms object from those of this Tms object.
280
- #
281
- def -: (untyped other) -> untyped
282
-
283
- # Returns a new Tms object obtained by memberwise division of the individual
284
- # times for this Tms object by `x`. This method and #+() are useful for taking
285
- # statistics.
286
- #
287
- def /: (untyped x) -> untyped
288
-
289
- # Returns a new Tms object whose times are the sum of the times for this Tms
290
- # object, plus the time required to execute the code block (`blk`).
291
- #
292
- def add: () { (*untyped) -> untyped } -> untyped
293
-
294
- # An in-place version of #add. Changes the times of this Tms object by making it
295
- # the sum of the times for this Tms object, plus the time required to execute
296
- # the code block (`blk`).
297
- #
298
- def add!: () { (*untyped) -> untyped } -> untyped
299
-
300
- # System CPU time of children
301
- #
302
- def cstime: () -> Float
303
-
304
- # User CPU time of children
305
- #
306
- def cutime: () -> Float
307
-
308
- # Returns the contents of this Tms object as a formatted string, according to a
309
- # `format` string like that passed to Kernel.format. In addition, #format
310
- # accepts the following extensions:
311
- #
312
- # `%u`
313
- # : Replaced by the user CPU time, as reported by Tms#utime.
314
- # `%y`
315
- # : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
316
- # "s*y*stem")
317
- # `%U`
318
- # : Replaced by the children's user CPU time, as reported by Tms#cutime
319
- # `%Y`
320
- # : Replaced by the children's system CPU time, as reported by Tms#cstime
321
- # `%t`
322
- # : Replaced by the total CPU time, as reported by Tms#total
323
- # `%r`
324
- # : Replaced by the elapsed real time, as reported by Tms#real
325
- # `%n`
326
- # : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
327
- # "*n*ame")
328
- #
329
- #
330
- # If `format` is not given, FORMAT is used as default value, detailing the user,
331
- # system and real elapsed time.
332
- #
333
- def format: (?String format, *untyped args) -> String
334
-
335
- # Label
336
- #
337
- def label: () -> String
338
-
339
- # Elapsed real time
340
- #
341
- def real: () -> Float
342
224
 
343
- # System CPU time
344
- #
345
- def stime: () -> Float
346
-
347
- # Returns a new 6-element array, consisting of the label, user CPU time, system
348
- # CPU time, children's user CPU time, children's system CPU time and elapsed
349
- # real time.
350
- #
351
- def to_a: () -> untyped
352
-
353
- # Same as #format.
354
- #
355
- def to_s: () -> String
356
-
357
- # Total time, that is `utime` + `stime` + `cutime` + `cstime`
358
- #
359
- def total: () -> Float
360
-
361
- # User CPU time
362
- #
363
- def utime: () -> Float
225
+ BENCHMARK_VERSION: String
226
+
227
+ # The default caption string (heading above the output times).
228
+ #
229
+ CAPTION: String
230
+
231
+ # The default format string used to display times. See also
232
+ # Benchmark::Tms#format.
233
+ #
234
+ FORMAT: String
235
+
236
+ class Job
237
+ # Prints the `label` and measured time for the block,
238
+ # formatted by `format`. See Tms#format for the
239
+ # formatting rules.
240
+ def item: (?String label) { () -> void } -> self
241
+
242
+ # An array of 2-element arrays, consisting of label and block pairs.
243
+ def list: () -> Array[untyped]
244
+
245
+ alias report item
246
+
247
+ # Length of the widest label in the #list.
248
+ def width: () -> Integer
249
+ end
250
+
251
+ class Report
252
+ # Prints the `label` and measured time for the block,
253
+ # formatted by `format`. See Tms#format for the
254
+ # formatting rules.
255
+ def item: (?String label, *untyped format) { () -> void } -> Tms
256
+
257
+ # An array of Benchmark::Tms objects representing each item.
258
+ def list: () -> Array[Tms]
259
+
260
+ alias report item
261
+ end
262
+
263
+ # A data object, representing the times associated with a benchmark measurement.
264
+ #
265
+ class Tms
266
+ # Returns a new Tms object obtained by memberwise multiplication of the
267
+ # individual times for this Tms object by `x`.
268
+ #
269
+ def *: (untyped x) -> untyped
270
+
271
+ # Returns a new Tms object obtained by memberwise summation of the individual
272
+ # times for this Tms object with those of the `other` Tms object. This method
273
+ # and #/() are useful for taking statistics.
274
+ #
275
+ def +: (untyped other) -> untyped
276
+
277
+ # Returns a new Tms object obtained by memberwise subtraction of the individual
278
+ # times for the `other` Tms object from those of this Tms object.
279
+ #
280
+ def -: (untyped other) -> untyped
281
+
282
+ # Returns a new Tms object obtained by memberwise division of the individual
283
+ # times for this Tms object by `x`. This method and #+() are useful for taking
284
+ # statistics.
285
+ #
286
+ def /: (untyped x) -> untyped
287
+
288
+ # Returns a new Tms object whose times are the sum of the times for this Tms
289
+ # object, plus the time required to execute the code block (`blk`).
290
+ #
291
+ def add: () { (*untyped) -> untyped } -> untyped
292
+
293
+ # An in-place version of #add. Changes the times of this Tms object by making it
294
+ # the sum of the times for this Tms object, plus the time required to execute
295
+ # the code block (`blk`).
296
+ #
297
+ def add!: () { (*untyped) -> untyped } -> untyped
298
+
299
+ # System CPU time of children
300
+ #
301
+ def cstime: () -> Float
302
+
303
+ # User CPU time of children
304
+ #
305
+ def cutime: () -> Float
306
+
307
+ # Returns the contents of this Tms object as a formatted string, according to a
308
+ # `format` string like that passed to Kernel.format. In addition, #format
309
+ # accepts the following extensions:
310
+ #
311
+ # `%u`
312
+ # : Replaced by the user CPU time, as reported by Tms#utime.
313
+ # `%y`
314
+ # : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
315
+ # "s*y*stem")
316
+ # `%U`
317
+ # : Replaced by the children's user CPU time, as reported by Tms#cutime
318
+ # `%Y`
319
+ # : Replaced by the children's system CPU time, as reported by Tms#cstime
320
+ # `%t`
321
+ # : Replaced by the total CPU time, as reported by Tms#total
322
+ # `%r`
323
+ # : Replaced by the elapsed real time, as reported by Tms#real
324
+ # `%n`
325
+ # : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
326
+ # "*n*ame")
327
+ #
328
+ #
329
+ # If `format` is not given, FORMAT is used as default value, detailing the user,
330
+ # system and real elapsed time.
331
+ #
332
+ def format: (?String format, *untyped args) -> String
333
+
334
+ # Label
335
+ #
336
+ def label: () -> String
337
+
338
+ # Elapsed real time
339
+ #
340
+ def real: () -> Float
341
+
342
+ # System CPU time
343
+ #
344
+ def stime: () -> Float
345
+
346
+ # Returns a new 6-element array, consisting of the label, user CPU time, system
347
+ # CPU time, children's user CPU time, children's system CPU time and elapsed
348
+ # real time.
349
+ #
350
+ def to_a: () -> untyped
351
+
352
+ # Same as #format.
353
+ #
354
+ def to_s: () -> String
355
+
356
+ # Total time, that is `utime` + `stime` + `cutime` + `cstime`
357
+ #
358
+ def total: () -> Float
359
+
360
+ # User CPU time
361
+ #
362
+ def utime: () -> Float
363
+
364
+ # Default caption, see also Benchmark::CAPTION
365
+ #
366
+ CAPTION: String
367
+
368
+ # Default format string, see also Benchmark::FORMAT
369
+ #
370
+ FORMAT: String
371
+ end
364
372
  end
365
-
366
- # Default caption, see also Benchmark::CAPTION
367
- #
368
- Benchmark::Tms::CAPTION: String
369
-
370
- # Default format string, see also Benchmark::FORMAT
371
- #
372
- Benchmark::Tms::FORMAT: String
@@ -173,6 +173,8 @@ Encoding::Big5_HKSCS_2008: Encoding
173
173
 
174
174
  Encoding::Big5_UAO: Encoding
175
175
 
176
+ Encoding::CESU_8: Encoding
177
+
176
178
  Encoding::CP1250: Encoding
177
179
 
178
180
  Encoding::CP1251: Encoding
@@ -374,7 +374,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
374
374
  | [T] (?T arg0) -> (Elem | T)
375
375
  | [U] (?U arg0) { (Elem arg0) -> U } -> U
376
376
 
377
- def filter_map: [U] () { (Elem arg0) -> U? } -> ::Array[U]
377
+ def filter_map: [U] () { (Elem elem) -> (nil | false | U) } -> ::Array[U]
378
378
  | () -> ::Enumerator[Elem, Return]
379
379
 
380
380
  def chain: (*self enumerables) -> ::Enumerator::Chain[Elem, ::Array[self]]
@@ -385,7 +385,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
385
385
  | () { (Elem arg0) -> untyped } -> self
386
386
 
387
387
  # variadic type parameter is not supported yet
388
- # https://github.com/ruby/ruby-signature/issues/21
388
+ # https://github.com/ruby/rbs/issues/21
389
389
  def zip: [Elem2, Return2] (::Enumerable[Elem2, Return2] enum) -> ::Array[[Elem, Elem2 | nil]]
390
390
  | [U, Elem2, Return2] (::Enumerable[Elem2, Return2]) { ([Elem, Elem2 | nil]) -> U } -> nil
391
391
 
@@ -250,9 +250,11 @@ class Enumerator::Lazy[out Elem, out Return] < Enumerator[Elem, Return]
250
250
  end
251
251
 
252
252
  class Enumerator::Yielder < Object
253
- def <<: (*untyped arg0) -> void
253
+ def <<: (untyped arg0) -> void
254
254
 
255
255
  def yield: (*untyped arg0) -> void
256
+
257
+ def to_proc: () -> Proc
256
258
  end
257
259
 
258
260
  class Enumerator::Chain[out Elem, out Return] < Object
@@ -62,7 +62,11 @@
62
62
  class Fiber < Object
63
63
  def self.yield: (*untyped args) -> untyped
64
64
 
65
- def initialize: () { () -> void } -> Fiber
65
+ def initialize: () { () -> untyped } -> void
66
66
 
67
67
  def resume: (*untyped args) -> untyped
68
+
69
+ def raise: () -> untyped
70
+ | (string message) -> untyped
71
+ | (_Exception exception, ?string message, ?Array[String] backtrace) -> untyped
68
72
  end
@@ -60,9 +60,6 @@ class File < IO
60
60
  #
61
61
  # File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
62
62
  #
63
- # # arglists 💪👽🚨 << Delete this section
64
- # File.absolute_path?(file_name) -> true or false
65
- #
66
63
  def self.absolute_path?: (string | _ToPath file_name) -> bool
67
64
 
68
65
  # Returns the last access time for the named file as a Time object.
@@ -480,7 +480,7 @@ class IO < Object
480
480
 
481
481
  def sysseek: (Integer amount, ?Integer whence) -> Integer
482
482
 
483
- def syswrite: (String arg0) -> Integer
483
+ def syswrite: (_ToS arg0) -> Integer
484
484
 
485
485
  # Returns the current offset (in bytes) of *ios* .
486
486
  #
@@ -508,11 +508,11 @@ class IO < Object
508
508
 
509
509
  def ungetc: (String arg0) -> NilClass
510
510
 
511
- def write: (String arg0) -> Integer
511
+ def write: (*_ToS arg0) -> Integer
512
512
 
513
513
  def self.binread: (String name, ?Integer length, ?Integer offset) -> String
514
514
 
515
- def self.binwrite: (String name, String arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
515
+ def self.binwrite: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
516
516
 
517
517
  def self.copy_stream: (String | IO src, String | IO dst, ?Integer copy_length, ?Integer src_offset) -> Integer
518
518
 
@@ -528,7 +528,7 @@ class IO < Object
528
528
 
529
529
  def self.try_convert: (untyped arg0) -> IO?
530
530
 
531
- def self.write: (String name, String arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
531
+ def self.write: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
532
532
 
533
533
  def self.for_fd: (Integer fd, ?Integer mode, ?Integer opt) -> self
534
534
 
@@ -269,8 +269,7 @@ class Proc < Object
269
269
  # See also Object\#hash.
270
270
  def hash: () -> Integer
271
271
 
272
- def initialize: () -> void
273
- | () { (*untyped) -> untyped } -> void
272
+ def initialize: () { (*untyped) -> untyped } -> void
274
273
 
275
274
  # Returns `true` for a [Proc](Proc.downloaded.ruby_doc) object for which
276
275
  # argument handling is rigid. Such procs are typically generated by
@@ -152,7 +152,7 @@ class Symbol
152
152
  # In general, `to_sym` returns the Symbol corresponding to an object. As *sym*
153
153
  # is already a symbol, `self` is returned in this case.
154
154
  #
155
- def intern: () -> self
155
+ def intern: () -> Symbol
156
156
 
157
157
  # Same as `sym.to_s.length`.
158
158
  #
@@ -898,7 +898,7 @@ class Thread::ConditionVariable < Object
898
898
  #
899
899
  # If `timeout` is given, this method returns after `timeout` seconds
900
900
  # passed, even if no other thread doesn't signal.
901
- def wait: (Mutex mutex, ?Integer timeout) -> self
901
+ def wait: (Thread::Mutex mutex, ?Integer timeout) -> self
902
902
  end
903
903
 
904
904
  # [Mutex](Mutex) implements a simple semaphore that
@@ -1078,7 +1078,7 @@ class Thread::SizedQueue < Thread::Queue
1078
1078
  # Alias for: [push](SizedQueue.downloaded.ruby_doc#method-i-push)
1079
1079
  alias enq push
1080
1080
 
1081
- def initialize: (Integer max) -> SizedQueue
1081
+ def initialize: (Integer max) -> void
1082
1082
 
1083
1083
  # Returns the maximum size of the queue.
1084
1084
  def max: () -> Integer