rbs 4.0.3 → 4.1.0.pre.2

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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +3 -0
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/jruby.yml +67 -0
  5. data/.github/workflows/milestone.yml +4 -1
  6. data/.github/workflows/ruby.yml +40 -0
  7. data/.github/workflows/rust.yml +3 -2
  8. data/.github/workflows/truffleruby.yml +54 -0
  9. data/.github/workflows/typecheck.yml +3 -0
  10. data/.github/workflows/wasm.yml +53 -0
  11. data/.github/workflows/windows.yml +3 -0
  12. data/.gitignore +7 -0
  13. data/CHANGELOG.md +0 -8
  14. data/README.md +3 -3
  15. data/Rakefile +118 -3
  16. data/Steepfile +7 -0
  17. data/config.yml +24 -0
  18. data/core/array.rbs +144 -144
  19. data/core/builtin.rbs +7 -6
  20. data/core/class.rbs +5 -3
  21. data/core/enumerable.rbs +109 -109
  22. data/core/enumerator/product.rbs +5 -5
  23. data/core/enumerator.rbs +28 -28
  24. data/core/file.rbs +24 -1018
  25. data/core/file_constants.rbs +463 -0
  26. data/core/file_stat.rbs +534 -0
  27. data/core/hash.rbs +117 -101
  28. data/core/integer.rbs +21 -58
  29. data/core/io.rbs +25 -7
  30. data/core/kernel.rbs +26 -11
  31. data/core/module.rbs +88 -74
  32. data/core/numeric.rbs +3 -0
  33. data/core/object_space/weak_key_map.rbs +7 -7
  34. data/core/range.rbs +23 -23
  35. data/core/rbs/ops.rbs +154 -0
  36. data/core/rbs/unnamed/argf.rbs +3 -3
  37. data/core/ruby_vm.rbs +40 -0
  38. data/core/set.rbs +3 -3
  39. data/core/struct.rbs +16 -16
  40. data/core/thread.rbs +6 -6
  41. data/docs/CONTRIBUTING.md +2 -1
  42. data/docs/inline.md +65 -7
  43. data/docs/rbs_by_example.md +20 -20
  44. data/docs/syntax.md +2 -2
  45. data/docs/wasm_serialization.md +80 -0
  46. data/ext/rbs_extension/ast_translation.c +1298 -956
  47. data/ext/rbs_extension/ast_translation.h +4 -0
  48. data/ext/rbs_extension/class_constants.c +2 -0
  49. data/ext/rbs_extension/class_constants.h +1 -0
  50. data/ext/rbs_extension/extconf.rb +1 -0
  51. data/ext/rbs_extension/main.c +139 -4
  52. data/include/rbs/ast.h +323 -298
  53. data/include/rbs/defines.h +13 -0
  54. data/include/rbs/lexer.h +1 -0
  55. data/include/rbs/serialize.h +39 -0
  56. data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
  57. data/lib/rbs/ast/ruby/annotations.rb +42 -0
  58. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  59. data/lib/rbs/ast/ruby/declarations.rb +11 -1
  60. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  61. data/lib/rbs/ast/ruby/members.rb +40 -1
  62. data/lib/rbs/buffer.rb +48 -11
  63. data/lib/rbs/cli.rb +3 -5
  64. data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
  65. data/lib/rbs/collection/sources/git.rb +6 -0
  66. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  67. data/lib/rbs/environment.rb +10 -3
  68. data/lib/rbs/inline_parser.rb +54 -28
  69. data/lib/rbs/namespace.rb +47 -11
  70. data/lib/rbs/prototype/runtime.rb +2 -0
  71. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  72. data/lib/rbs/rewriter.rb +70 -0
  73. data/lib/rbs/test/type_check.rb +6 -1
  74. data/lib/rbs/type_name.rb +33 -13
  75. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  76. data/lib/rbs/version.rb +1 -1
  77. data/lib/rbs/wasm/deserializer.rb +213 -0
  78. data/lib/rbs/wasm/location.rb +61 -0
  79. data/lib/rbs/wasm/parser.rb +137 -0
  80. data/lib/rbs/wasm/runtime.rb +217 -0
  81. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  82. data/lib/rbs.rb +14 -2
  83. data/rbs.gemspec +19 -2
  84. data/sig/annotate/rdoc_annotater.rbs +12 -9
  85. data/sig/ast/ruby/annotations.rbs +49 -0
  86. data/sig/ast/ruby/members.rbs +21 -1
  87. data/sig/buffer.rbs +19 -1
  88. data/sig/collection/config/lockfile_generator.rbs +2 -0
  89. data/sig/inline_parser.rbs +2 -0
  90. data/sig/manifest.yaml +0 -1
  91. data/sig/namespace.rbs +20 -0
  92. data/sig/parser.rbs +10 -0
  93. data/sig/resolver/type_name_resolver.rbs +2 -4
  94. data/sig/rewriter.rbs +45 -0
  95. data/sig/typename.rbs +15 -0
  96. data/sig/unit_test/type_assertions.rbs +4 -0
  97. data/sig/wasm/deserializer.rbs +66 -0
  98. data/sig/wasm/serialization_schema.rbs +13 -0
  99. data/src/ast.c +186 -162
  100. data/src/lexer.c +137 -114
  101. data/src/lexer.re +1 -0
  102. data/src/lexstate.c +6 -1
  103. data/src/parser.c +55 -5
  104. data/src/serialize.c +958 -0
  105. data/src/util/rbs_allocator.c +1 -4
  106. data/stdlib/abbrev/0/array.rbs +1 -1
  107. data/stdlib/csv/0/csv.rbs +5 -5
  108. data/stdlib/digest/0/digest.rbs +1 -1
  109. data/stdlib/etc/0/etc.rbs +18 -4
  110. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/openssl/0/openssl.rbs +7 -7
  113. data/stdlib/resolv/0/resolv.rbs +1 -1
  114. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  115. data/stdlib/stringio/0/stringio.rbs +32 -10
  116. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  117. data/stdlib/tsort/0/cyclic.rbs +1 -1
  118. data/stdlib/tsort/0/interfaces.rbs +8 -8
  119. data/stdlib/tsort/0/tsort.rbs +9 -9
  120. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  121. data/wasm/README.md +59 -0
  122. data/wasm/rbs_wasm.c +411 -0
  123. metadata +23 -5
  124. data/.vscode/extensions.json +0 -5
  125. data/.vscode/settings.json +0 -19
data/core/integer.rbs CHANGED
@@ -93,6 +93,8 @@
93
93
  # given value.
94
94
  #
95
95
  class Integer < Numeric
96
+ # TODO: `undef self.new`
97
+
96
98
  # <!--
97
99
  # rdoc-file=numeric.c
98
100
  # - Integer.sqrt(numeric) -> integer
@@ -421,7 +423,7 @@ class Integer < Numeric
421
423
  #
422
424
  # Related: Integer#eql? (requires `other` to be an Integer).
423
425
  #
424
- def ==: (untyped) -> bool
426
+ def ==: (untyped other) -> bool
425
427
 
426
428
  # <!--
427
429
  # rdoc-file=numeric.c
@@ -434,7 +436,7 @@ class Integer < Numeric
434
436
  #
435
437
  # Related: Integer#eql? (requires `other` to be an Integer).
436
438
  #
437
- def ===: (untyped) -> bool
439
+ alias === ==
438
440
 
439
441
  # <!--
440
442
  # rdoc-file=numeric.c
@@ -687,8 +689,7 @@ class Integer < Numeric
687
689
  # -5| 100000| 0
688
690
  # Related: Integer#floor.
689
691
  #
690
- def ceil: () -> Integer
691
- | (int digits) -> (Integer | Float)
692
+ def ceil: (?int digits) -> Integer
692
693
 
693
694
  # <!--
694
695
  # rdoc-file=numeric.rb
@@ -726,7 +727,7 @@ class Integer < Numeric
726
727
  #
727
728
  # Related: Integer#ord.
728
729
  #
729
- def chr: (?encoding) -> String
730
+ def chr: (?encoding encoding) -> String
730
731
 
731
732
  # <!--
732
733
  # rdoc-file=bignum.c
@@ -749,7 +750,7 @@ class Integer < Numeric
749
750
  # -->
750
751
  # Returns `1`.
751
752
  #
752
- def denominator: () -> Integer
753
+ def denominator: () -> 1
753
754
 
754
755
  # <!--
755
756
  # rdoc-file=numeric.c
@@ -764,7 +765,7 @@ class Integer < Numeric
764
765
  #
765
766
  # Raises an exception if `self` is negative or `base` is less than 2.
766
767
  #
767
- def digits: (?int base) -> ::Array[Integer]
768
+ def digits: (?int base) -> Array[Integer]
768
769
 
769
770
  # <!--
770
771
  # rdoc-file=numeric.c
@@ -912,7 +913,7 @@ class Integer < Numeric
912
913
  # 3.gcd(-7) #=> 1
913
914
  # ((1<<31)-1).gcd((1<<61)-1) #=> 1
914
915
  #
915
- def gcd: (Integer) -> Integer
916
+ def gcd: (Integer other_int) -> Integer
916
917
 
917
918
  # <!--
918
919
  # rdoc-file=rational.c
@@ -926,7 +927,7 @@ class Integer < Numeric
926
927
  # 3.gcdlcm(-7) #=> [1, 21]
927
928
  # ((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]
928
929
  #
929
- def gcdlcm: (Integer) -> [ Integer, Integer ]
930
+ def gcdlcm: (Integer other_int) -> [ Integer, Integer ]
930
931
 
931
932
  # <!-- rdoc-file=numeric.c -->
932
933
  # Returns a string containing the place-value representation of `self` in radix
@@ -964,14 +965,14 @@ class Integer < Numeric
964
965
  # 3.lcm(-7) #=> 21
965
966
  # ((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297
966
967
  #
967
- def lcm: (Integer) -> Integer
968
+ def lcm: (Integer other_int) -> Integer
968
969
 
969
970
  # <!--
970
971
  # rdoc-file=numeric.rb
971
972
  # - magnitude()
972
973
  # -->
973
974
  #
974
- def magnitude: () -> Integer
975
+ alias magnitude abs
975
976
 
976
977
  # <!-- rdoc-file=numeric.c -->
977
978
  # Returns `self` modulo `other` as a real numeric (Integer, Float, or Rational).
@@ -1009,7 +1010,7 @@ class Integer < Numeric
1009
1010
  #
1010
1011
  # Related: Integer#pred (predecessor value).
1011
1012
  #
1012
- def next: () -> Integer
1013
+ alias next succ
1013
1014
 
1014
1015
  # <!--
1015
1016
  # rdoc-file=numeric.c
@@ -1040,7 +1041,7 @@ class Integer < Numeric
1040
1041
  # -->
1041
1042
  # Returns `self`.
1042
1043
  #
1043
- def numerator: () -> Integer
1044
+ def numerator: () -> self
1044
1045
 
1045
1046
  # <!--
1046
1047
  # rdoc-file=numeric.rb
@@ -1056,7 +1057,7 @@ class Integer < Numeric
1056
1057
  # -->
1057
1058
  # Returns `self`; intended for compatibility to character literals in Ruby 1.9.
1058
1059
  #
1059
- def ord: () -> Integer
1060
+ def ord: () -> self
1060
1061
 
1061
1062
  def polar: () -> [ Integer, Integer | Float ]
1062
1063
 
@@ -1180,8 +1181,7 @@ class Integer < Numeric
1180
1181
  #
1181
1182
  # Related: Integer#truncate.
1182
1183
  #
1183
- def round: (?half: :up | :down | :even) -> Integer
1184
- | (int digits, ?half: :up | :down | :even) -> (Integer | Float)
1184
+ def round: (?int digits, ?half: Numeric::round_mode) -> Integer
1185
1185
 
1186
1186
  # <!--
1187
1187
  # rdoc-file=numeric.rb
@@ -1226,8 +1226,8 @@ class Integer < Numeric
1226
1226
  #
1227
1227
  # With no block given, returns an Enumerator.
1228
1228
  #
1229
- def times: () { (Integer) -> void } -> self
1230
- | () -> ::Enumerator[Integer, self]
1229
+ def times: () { (Integer i) -> void } -> self
1230
+ | () -> Enumerator[Integer, self]
1231
1231
 
1232
1232
  # <!--
1233
1233
  # rdoc-file=numeric.c
@@ -1251,7 +1251,7 @@ class Integer < Numeric
1251
1251
  # -->
1252
1252
  # Returns `self` (which is already an Integer).
1253
1253
  #
1254
- def to_i: () -> Integer
1254
+ def to_i: () -> self
1255
1255
 
1256
1256
  # <!--
1257
1257
  # rdoc-file=numeric.rb
@@ -1289,43 +1289,7 @@ class Integer < Numeric
1289
1289
  #
1290
1290
  # Raises an exception if `base` is out of range.
1291
1291
  #
1292
- def to_s: () -> String
1293
- | (2) -> String
1294
- | (3) -> String
1295
- | (4) -> String
1296
- | (5) -> String
1297
- | (6) -> String
1298
- | (7) -> String
1299
- | (8) -> String
1300
- | (9) -> String
1301
- | (10) -> String
1302
- | (11) -> String
1303
- | (12) -> String
1304
- | (13) -> String
1305
- | (14) -> String
1306
- | (15) -> String
1307
- | (16) -> String
1308
- | (17) -> String
1309
- | (18) -> String
1310
- | (19) -> String
1311
- | (20) -> String
1312
- | (21) -> String
1313
- | (22) -> String
1314
- | (23) -> String
1315
- | (24) -> String
1316
- | (25) -> String
1317
- | (26) -> String
1318
- | (27) -> String
1319
- | (28) -> String
1320
- | (29) -> String
1321
- | (30) -> String
1322
- | (31) -> String
1323
- | (32) -> String
1324
- | (33) -> String
1325
- | (34) -> String
1326
- | (35) -> String
1327
- | (36) -> String
1328
- | (int base) -> String
1292
+ def to_s: (?int base) -> String
1329
1293
 
1330
1294
  # <!--
1331
1295
  # rdoc-file=numeric.c
@@ -1348,8 +1312,7 @@ class Integer < Numeric
1348
1312
  #
1349
1313
  # Related: Integer#round.
1350
1314
  #
1351
- def truncate: () -> Integer
1352
- | (int ndigits) -> Integer
1315
+ def truncate: (?int ndigits) -> Integer
1353
1316
 
1354
1317
  # <!--
1355
1318
  # rdoc-file=numeric.c
data/core/io.rbs CHANGED
@@ -1230,6 +1230,24 @@ class IO < Object
1230
1230
  #
1231
1231
  def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer
1232
1232
 
1233
+ # <!--
1234
+ # rdoc-file=ext/etc/etc.c
1235
+ # - pathconf(name) -> Integer
1236
+ # -->
1237
+ # Returns pathname configuration variable using fpathconf().
1238
+ #
1239
+ # *name* should be a constant under `Etc` which begins with `PC_`.
1240
+ #
1241
+ # The return value is an integer or nil. nil means indefinite limit.
1242
+ # (fpathconf() returns -1 but errno is not set.)
1243
+ #
1244
+ # require 'etc'
1245
+ # IO.pipe {|r, w|
1246
+ # p w.pathconf(Etc::PC_PIPE_BUF) #=> 4096
1247
+ # }
1248
+ #
1249
+ def pathconf: (Integer name) -> Integer?
1250
+
1233
1251
  # <!--
1234
1252
  # rdoc-file=io.c
1235
1253
  # - isatty -> true or false
@@ -1474,7 +1492,7 @@ class IO < Object
1474
1492
  #
1475
1493
  # Not available on some platforms.
1476
1494
  #
1477
- def pread: (int maxlen, int offset, ?string out_string) -> String
1495
+ def pread: (int maxlen, int offset, ?string? out_string) -> String
1478
1496
 
1479
1497
  # <!--
1480
1498
  # rdoc-file=io.c
@@ -1571,8 +1589,8 @@ class IO < Object
1571
1589
  #
1572
1590
  # Related: IO#write.
1573
1591
  #
1574
- def read: (?nil, ?string outbuf) -> String
1575
- | (int? length, ?string outbuf) -> String?
1592
+ def read: (?nil, ?string? outbuf) -> String
1593
+ | (int? length, ?string? outbuf) -> String?
1576
1594
 
1577
1595
  # <!--
1578
1596
  # rdoc-file=io.rb
@@ -1627,8 +1645,8 @@ class IO < Object
1627
1645
  # symbol <code>:wait_readable</code> instead. At EOF, it will return nil instead
1628
1646
  # of raising EOFError.
1629
1647
  #
1630
- def read_nonblock: (int len, ?string buf, ?exception: true) -> String
1631
- | (int len, ?string buf, exception: false) -> (String | :wait_readable | nil)
1648
+ def read_nonblock: (int len, ?string? buf, ?exception: true) -> String
1649
+ | (int len, ?string? buf, exception: false) -> (String | :wait_readable | nil)
1632
1650
 
1633
1651
  # <!--
1634
1652
  # rdoc-file=io.c
@@ -1828,7 +1846,7 @@ class IO < Object
1828
1846
  # r.readpartial(4096) # => "def\n" "" "ghi\n"
1829
1847
  # r.readpartial(4096) # => "ghi\n" "" ""
1830
1848
  #
1831
- def readpartial: (int maxlen, ?string outbuf) -> String
1849
+ def readpartial: (int maxlen, ?string? outbuf) -> String
1832
1850
 
1833
1851
  # <!--
1834
1852
  # rdoc-file=io.c
@@ -2049,7 +2067,7 @@ class IO < Object
2049
2067
  #
2050
2068
  # This method should not be used with other stream-reader methods.
2051
2069
  #
2052
- def sysread: (Integer maxlen, String outbuf) -> String
2070
+ def sysread: (Integer maxlen, ?String? outbuf) -> String
2053
2071
 
2054
2072
  # <!--
2055
2073
  # rdoc-file=io.c
data/core/kernel.rbs CHANGED
@@ -182,9 +182,9 @@ module Kernel : BasicObject
182
182
  # c(4) #=> []
183
183
  # c(5) #=> nil
184
184
  #
185
- def self?.caller: (Integer start_or_range, ?Integer length) -> ::Array[String]?
186
- | (::Range[Integer] start_or_range) -> ::Array[String]?
187
- | () -> ::Array[String]
185
+ def self?.caller: () -> Array[String]
186
+ | (int start, ?int? length) -> Array[String]?
187
+ | (range[int] range) -> Array[String]?
188
188
 
189
189
  # <!--
190
190
  # rdoc-file=vm_backtrace.c
@@ -207,9 +207,9 @@ module Kernel : BasicObject
207
207
  # Optionally you can pass a range, which will return an array containing the
208
208
  # entries within the specified range.
209
209
  #
210
- def self?.caller_locations: (Integer start_or_range, ?Integer length) -> ::Array[Thread::Backtrace::Location]?
211
- | (::Range[Integer] start_or_range) -> ::Array[Thread::Backtrace::Location]?
212
- | () -> ::Array[Thread::Backtrace::Location]
210
+ def self?.caller_locations: () -> Array[Thread::Backtrace::Location]
211
+ | (int start, ?int? length) -> Array[Thread::Backtrace::Location]?
212
+ | (range[int] range) -> Array[Thread::Backtrace::Location]?
213
213
 
214
214
  # <!--
215
215
  # rdoc-file=vm_eval.c
@@ -314,6 +314,16 @@ module Kernel : BasicObject
314
314
  #
315
315
  def self?.block_given?: () -> bool
316
316
 
317
+ alias self.iterator? self.block_given?
318
+
319
+ # <!--
320
+ # rdoc-file=vm_eval.c
321
+ # - iterator? -> true or false
322
+ # -->
323
+ # Deprecated. Use block_given? instead.
324
+ #
325
+ alias iterator? block_given?
326
+
317
327
  # <!--
318
328
  # rdoc-file=vm_eval.c
319
329
  # - local_variables -> array
@@ -326,7 +336,7 @@ module Kernel : BasicObject
326
336
  # end
327
337
  # local_variables #=> [:fred, :i]
328
338
  #
329
- def self?.local_variables: () -> ::Array[Symbol]
339
+ def self?.local_variables: () -> Array[Symbol]
330
340
 
331
341
  # <!--
332
342
  # rdoc-file=random.c
@@ -788,7 +798,7 @@ module Kernel : BasicObject
788
798
  #
789
799
  # Files that are currently being loaded must not be registered for autoload.
790
800
  #
791
- def self?.autoload: (interned _module, String filename) -> NilClass
801
+ def self?.autoload: (interned const, path filename) -> nil
792
802
 
793
803
  # <!--
794
804
  # rdoc-file=load.c
@@ -812,7 +822,7 @@ module Kernel : BasicObject
812
822
  # autoload?(:B) #=> "b"
813
823
  # end
814
824
  #
815
- def self?.autoload?: (interned name) -> String?
825
+ def self?.autoload?: (interned name, ?boolish inherit) -> String?
816
826
 
817
827
  # <!--
818
828
  # rdoc-file=proc.c
@@ -1193,7 +1203,7 @@ module Kernel : BasicObject
1193
1203
  #
1194
1204
  # global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
1195
1205
  #
1196
- def self?.global_variables: () -> ::Array[Symbol]
1206
+ def self?.global_variables: () -> Array[Symbol]
1197
1207
 
1198
1208
  # <!--
1199
1209
  # rdoc-file=load.c
@@ -1843,7 +1853,12 @@ module Kernel : BasicObject
1843
1853
  # ----------------|---------------------------------------------
1844
1854
  # <code>'-'</code>|Whether the entities exist and are identical.
1845
1855
  #
1846
- def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
1856
+ def self?.test: ('b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'G' | 'k' | 'l' | 'o' | 'O' | 'p' | 'r' | 'R' | 'S' | 'u' | 'w' | 'W' | 'x' | 'X' | 'z' |
1857
+ 98 | 99 | 100 | 101 | 102 | 103 | 71 | 107 | 108 | 111 | 79 | 112 | 114 | 82 | 83 | 117 | 119 | 87 | 120 | 88 | 122, path filepath) -> bool
1858
+ | ('s' | 115, path filepath) -> Integer?
1859
+ | ('A' | 'M' | 'C' | 65 | 77 | 67, path filepath) -> Time
1860
+ | ('<' | '=' | '>' | '-' | 60 | 61 | 62 | 45, path filepath1, path filepath2) -> bool
1861
+ | (String | int cmd, path filepath1, ?path filepath2) -> (bool | Time | Integer | nil)
1847
1862
 
1848
1863
  # <!--
1849
1864
  # rdoc-file=vm_eval.c