rbs 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) 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/Gemfile +14 -0
  6. data/README.md +86 -47
  7. data/Rakefile +53 -21
  8. data/bin/rbs-prof +9 -0
  9. data/bin/run_in_md.rb +49 -0
  10. data/docs/stdlib.md +0 -2
  11. data/docs/syntax.md +6 -3
  12. data/goodcheck.yml +65 -0
  13. data/lib/rbs.rb +3 -0
  14. data/lib/rbs/ast/comment.rb +6 -0
  15. data/lib/rbs/ast/declarations.rb +106 -13
  16. data/lib/rbs/ast/members.rb +41 -17
  17. data/lib/rbs/cli.rb +317 -121
  18. data/lib/rbs/constant.rb +4 -4
  19. data/lib/rbs/constant_table.rb +51 -45
  20. data/lib/rbs/definition.rb +175 -59
  21. data/lib/rbs/definition_builder.rb +814 -604
  22. data/lib/rbs/environment.rb +352 -210
  23. data/lib/rbs/environment_walker.rb +14 -23
  24. data/lib/rbs/errors.rb +184 -3
  25. data/lib/rbs/factory.rb +14 -0
  26. data/lib/rbs/location.rb +15 -0
  27. data/lib/rbs/parser.y +100 -34
  28. data/lib/rbs/prototype/rb.rb +101 -113
  29. data/lib/rbs/prototype/rbi.rb +5 -3
  30. data/lib/rbs/prototype/runtime.rb +11 -7
  31. data/lib/rbs/substitution.rb +12 -1
  32. data/lib/rbs/test.rb +82 -3
  33. data/lib/rbs/test/errors.rb +5 -1
  34. data/lib/rbs/test/hook.rb +133 -259
  35. data/lib/rbs/test/observer.rb +17 -0
  36. data/lib/rbs/test/setup.rb +35 -19
  37. data/lib/rbs/test/setup_helper.rb +29 -0
  38. data/lib/rbs/test/spy.rb +0 -321
  39. data/lib/rbs/test/tester.rb +116 -0
  40. data/lib/rbs/test/type_check.rb +43 -7
  41. data/lib/rbs/type_name_resolver.rb +58 -0
  42. data/lib/rbs/types.rb +94 -2
  43. data/lib/rbs/validator.rb +55 -0
  44. data/lib/rbs/variance_calculator.rb +12 -2
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +127 -91
  47. data/rbs.gemspec +0 -10
  48. data/schema/decls.json +36 -10
  49. data/schema/members.json +3 -0
  50. data/stdlib/benchmark/benchmark.rbs +151 -151
  51. data/stdlib/builtin/enumerable.rbs +3 -3
  52. data/stdlib/builtin/file.rbs +0 -3
  53. data/stdlib/builtin/io.rbs +4 -4
  54. data/stdlib/builtin/proc.rbs +1 -2
  55. data/stdlib/builtin/thread.rbs +2 -2
  56. data/stdlib/csv/csv.rbs +4 -6
  57. data/stdlib/fiber/fiber.rbs +1 -1
  58. data/stdlib/json/json.rbs +7 -1
  59. data/stdlib/logger/formatter.rbs +23 -0
  60. data/stdlib/logger/log_device.rbs +39 -0
  61. data/stdlib/logger/logger.rbs +507 -0
  62. data/stdlib/logger/period.rbs +7 -0
  63. data/stdlib/logger/severity.rbs +8 -0
  64. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  65. data/stdlib/pathname/pathname.rbs +6 -6
  66. data/stdlib/prime/integer-extension.rbs +1 -1
  67. data/stdlib/prime/prime.rbs +44 -44
  68. data/stdlib/pty/pty.rbs +159 -0
  69. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  70. metadata +19 -130
  71. data/lib/rbs/test/test_helper.rb +0 -183
@@ -34,14 +34,4 @@ Gem::Specification.new do |spec|
34
34
  spec.bindir = "exe"
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
-
38
- spec.add_development_dependency "bundler"
39
- spec.add_development_dependency "rake", "~> 13.0"
40
- spec.add_development_dependency "minitest", "~> 5.0"
41
- spec.add_development_dependency "racc", "~> 1.4.16"
42
- spec.add_development_dependency "rubocop"
43
- spec.add_development_dependency "rubocop-rubycw"
44
- spec.add_development_dependency "minitest-reporters", "~> 1.3.6"
45
- spec.add_development_dependency "json", "~> 2.3.0"
46
- spec.add_development_dependency "json-schema", "~> 2.8"
47
37
  end
@@ -116,6 +116,21 @@
116
116
  },
117
117
  {
118
118
  "$ref": "members.json#/definitions/alias"
119
+ },
120
+ {
121
+ "$ref": "#/definitions/alias"
122
+ },
123
+ {
124
+ "$ref": "#/definitions/constant"
125
+ },
126
+ {
127
+ "$ref": "#/definitions/class"
128
+ },
129
+ {
130
+ "$ref": "#/definitions/module"
131
+ },
132
+ {
133
+ "$ref": "#/definitions/interface"
119
134
  }
120
135
  ]
121
136
  },
@@ -211,15 +226,11 @@
211
226
  "$ref": "#/definitions/classMember"
212
227
  }
213
228
  },
214
- "self_type": {
215
- "oneOf": [
216
- {
217
- "$ref": "types.json"
218
- },
219
- {
220
- "type": "null"
221
- }
222
- ]
229
+ "self_types": {
230
+ "type": "array",
231
+ "items": {
232
+ "$ref": "#/definitions/moduleSelf"
233
+ }
223
234
  },
224
235
  "annotations": {
225
236
  "type": "array",
@@ -234,7 +245,22 @@
234
245
  "$ref": "location.json"
235
246
  }
236
247
  },
237
- "required": ["declaration", "name", "type_params", "members", "self_type", "annotations", "location", "comment"]
248
+ "required": ["declaration", "name", "type_params", "members", "self_types", "annotations", "location", "comment"]
249
+ },
250
+ "moduleSelf": {
251
+ "type": "object",
252
+ "properties": {
253
+ "name": {
254
+ "type": "string"
255
+ },
256
+ "args": {
257
+ "type": "array",
258
+ "items": {
259
+ "$ref": "types.json"
260
+ }
261
+ }
262
+ },
263
+ "required": ["name", "args"]
238
264
  },
239
265
  "interfaceMember": {
240
266
  "oneOf": [
@@ -34,6 +34,9 @@
34
34
  },
35
35
  "location": {
36
36
  "$ref": "location.json"
37
+ },
38
+ "overload": {
39
+ "type": "boolean"
37
40
  }
38
41
  },
39
42
  "required": ["member", "kind", "types", "comment", "annotations", "location"]
@@ -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
@@ -46,7 +46,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
46
46
  | () { (Elem arg0) -> untyped } -> bool
47
47
 
48
48
  def collect: [U] () { (Elem arg0) -> U } -> ::Array[U]
49
- | () -> ::Enumerator[Elem, Return]
49
+ | () -> ::Enumerator[Elem, ::Array[untyped]]
50
50
 
51
51
  def collect_concat: [U] () { (Elem arg0) -> ::Enumerator[U, untyped] } -> ::Array[U]
52
52
 
@@ -317,7 +317,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
317
317
  | () -> ::Enumerator[Elem, Return]
318
318
 
319
319
  def map: [U] () { (Elem arg0) -> U } -> ::Array[U]
320
- | () -> ::Enumerator[Elem, Return]
320
+ | () -> ::Enumerator[Elem, ::Array[untyped]]
321
321
 
322
322
  def member?: (untyped arg0) -> bool
323
323
 
@@ -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]]
@@ -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.