rbs 4.1.0.pre.1 → 4.1.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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +37 -0
  3. data/.github/workflows/bundle-update.yml +1 -1
  4. data/.github/workflows/c-check.yml +14 -6
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/jruby.yml +79 -0
  8. data/.github/workflows/milestone.yml +13 -2
  9. data/.github/workflows/ruby.yml +16 -4
  10. data/.github/workflows/rust.yml +13 -8
  11. data/.github/workflows/truffleruby.yml +54 -0
  12. data/.github/workflows/typecheck.yml +5 -2
  13. data/.github/workflows/wasm.yml +55 -0
  14. data/.github/workflows/windows.yml +8 -2
  15. data/.gitignore +8 -0
  16. data/CHANGELOG.md +88 -0
  17. data/Dockerfile.jruby +53 -0
  18. data/README.md +3 -3
  19. data/Rakefile +103 -1
  20. data/Steepfile +9 -0
  21. data/core/array.rbs +243 -180
  22. data/core/builtin.rbs +6 -6
  23. data/core/enumerable.rbs +109 -109
  24. data/core/enumerator/product.rbs +5 -5
  25. data/core/enumerator.rbs +28 -28
  26. data/core/file.rbs +24 -1018
  27. data/core/file_constants.rbs +463 -0
  28. data/core/file_stat.rbs +534 -0
  29. data/core/float.rbs +0 -24
  30. data/core/hash.rbs +117 -101
  31. data/core/integer.rbs +21 -58
  32. data/core/io.rbs +25 -7
  33. data/core/match_data.rbs +1 -1
  34. data/core/module.rbs +88 -74
  35. data/core/numeric.rbs +3 -0
  36. data/core/object_space/weak_key_map.rbs +7 -7
  37. data/core/pathname.rbs +0 -10
  38. data/core/ractor.rbs +0 -10
  39. data/core/range.rbs +23 -23
  40. data/core/rbs/ops.rbs +154 -0
  41. data/core/rbs/unnamed/argf.rbs +3 -3
  42. data/core/rubygems/errors.rbs +4 -1
  43. data/core/rubygems/requirement.rbs +0 -10
  44. data/core/rubygems/rubygems.rbs +4 -1
  45. data/core/rubygems/specification.rbs +8 -0
  46. data/core/rubygems/version.rbs +0 -160
  47. data/core/set.rbs +3 -3
  48. data/core/struct.rbs +16 -16
  49. data/core/thread.rbs +9 -14
  50. data/docs/CONTRIBUTING.md +2 -1
  51. data/docs/inline.md +36 -6
  52. data/docs/rbs_by_example.md +20 -20
  53. data/docs/release.md +69 -0
  54. data/docs/syntax.md +2 -2
  55. data/docs/wasm_serialization.md +80 -0
  56. data/ext/rbs_extension/ast_translation.c +1294 -973
  57. data/ext/rbs_extension/ast_translation.h +4 -0
  58. data/ext/rbs_extension/legacy_location.c +11 -6
  59. data/ext/rbs_extension/main.c +139 -4
  60. data/include/rbs/ast.h +9 -1
  61. data/include/rbs/serialize.h +39 -0
  62. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  63. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  64. data/lib/rbs/ast/ruby/members.rb +12 -1
  65. data/lib/rbs/buffer.rb +48 -11
  66. data/lib/rbs/collection/sources/git.rb +6 -0
  67. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  68. data/lib/rbs/environment.rb +4 -3
  69. data/lib/rbs/inline_parser.rb +5 -3
  70. data/lib/rbs/namespace.rb +47 -11
  71. data/lib/rbs/parser_aux.rb +4 -2
  72. data/lib/rbs/prototype/rbi.rb +193 -25
  73. data/lib/rbs/prototype/runtime.rb +2 -0
  74. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  75. data/lib/rbs/type_name.rb +33 -13
  76. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  77. data/lib/rbs/version.rb +1 -1
  78. data/lib/rbs/wasm/deserializer.rb +213 -0
  79. data/lib/rbs/wasm/location.rb +61 -0
  80. data/lib/rbs/wasm/parser.rb +137 -0
  81. data/lib/rbs/wasm/runtime.rb +196 -0
  82. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  83. data/lib/rbs.rb +13 -2
  84. data/lib/rbs_jars.rb +39 -0
  85. data/lib/rdoc_plugin/parser.rb +5 -0
  86. data/rbs.gemspec +32 -2
  87. data/sig/ast/ruby/members.rbs +6 -1
  88. data/sig/buffer.rbs +19 -1
  89. data/sig/namespace.rbs +20 -0
  90. data/sig/parser.rbs +10 -0
  91. data/sig/prototype/rbi.rbs +33 -4
  92. data/sig/resolver/type_name_resolver.rbs +2 -4
  93. data/sig/typename.rbs +15 -0
  94. data/sig/unit_test/type_assertions.rbs +4 -0
  95. data/sig/wasm/deserializer.rbs +66 -0
  96. data/sig/wasm/serialization_schema.rbs +13 -0
  97. data/src/ast.c +78 -78
  98. data/src/lexer.c +97 -93
  99. data/src/lexer.re +1 -1
  100. data/src/lexstate.c +9 -1
  101. data/src/serialize.c +958 -0
  102. data/src/util/rbs_allocator.c +14 -8
  103. data/stdlib/abbrev/0/array.rbs +1 -1
  104. data/stdlib/csv/0/csv.rbs +5 -5
  105. data/stdlib/delegate/0/delegator.rbs +2 -1
  106. data/stdlib/digest/0/digest.rbs +11 -5
  107. data/stdlib/erb/0/erb.rbs +1 -1
  108. data/stdlib/etc/0/etc.rbs +18 -4
  109. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  110. data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/monitor/0/monitor.rbs +2 -2
  113. data/stdlib/openssl/0/openssl.rbs +44 -38
  114. data/stdlib/resolv/0/resolv.rbs +1 -1
  115. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  116. data/stdlib/stringio/0/stringio.rbs +32 -10
  117. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  118. data/stdlib/tempfile/0/manifest.yaml +3 -0
  119. data/stdlib/timeout/0/timeout.rbs +0 -5
  120. data/stdlib/tsort/0/cyclic.rbs +1 -1
  121. data/stdlib/tsort/0/interfaces.rbs +8 -8
  122. data/stdlib/tsort/0/tsort.rbs +9 -9
  123. data/stdlib/uri/0/generic.rbs +0 -5
  124. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  125. data/stdlib/zlib/0/zstream.rbs +0 -1
  126. data/wasm/README.md +60 -0
  127. data/wasm/rbs_wasm.c +423 -0
  128. metadata +26 -5
  129. data/.vscode/extensions.json +0 -5
  130. data/.vscode/settings.json +0 -19
@@ -560,7 +560,8 @@ class StringIO
560
560
  #
561
561
  # Related: StringIO.new.
562
562
  #
563
- def self.open: [U] (?String string, ?String? mode) { (StringIO arg) -> U } -> U
563
+ def self.open: (?String string, ?String? mode) -> StringIO
564
+ | [U] (?String string, ?String? mode) { (StringIO arg) -> U } -> U
564
565
 
565
566
  def <<: (untyped arg0) -> self
566
567
 
@@ -970,7 +971,7 @@ class StringIO
970
971
  # -->
971
972
  # Raises NotImplementedError.
972
973
  #
973
- def fcntl: (Integer integer_cmd, String | Integer arg) -> Integer
974
+ def fcntl: (*untyped) -> bot
974
975
 
975
976
  # <!--
976
977
  # rdoc-file=ext/stringio/stringio.c
@@ -994,7 +995,7 @@ class StringIO
994
995
  # -->
995
996
  # Returns 0; for compatibility with IO.
996
997
  #
997
- def fsync: () -> Integer?
998
+ def fsync: () -> Integer
998
999
 
999
1000
  # <!--
1000
1001
  # rdoc-file=ext/stringio/stringio.c
@@ -1190,7 +1191,7 @@ class StringIO
1190
1191
  # -->
1191
1192
  # Returns `nil`; for compatibility with IO.
1192
1193
  #
1193
- def internal_encoding: () -> Encoding
1194
+ def internal_encoding: () -> nil
1194
1195
 
1195
1196
  # <!--
1196
1197
  # rdoc-file=ext/stringio/stringio.c
@@ -1207,7 +1208,7 @@ class StringIO
1207
1208
  # strio = StringIO.new(nil, 'w+')
1208
1209
  # strio.external_encoding # => nil
1209
1210
  #
1210
- def external_encoding: () -> Encoding
1211
+ def external_encoding: () -> Encoding?
1211
1212
 
1212
1213
  # <!--
1213
1214
  # rdoc-file=ext/stringio/stringio.c
@@ -1281,9 +1282,18 @@ class StringIO
1281
1282
  # -->
1282
1283
  # See IO#read.
1283
1284
  #
1284
- def read: (?int? length, ?string outbuf) -> String?
1285
+ def read: (?int? length, ?string? outbuf) -> String?
1285
1286
 
1286
- def read_nonblock: (int len, ?string buf) -> String
1287
+ # <!--
1288
+ # rdoc-file=ext/stringio/stringio.c
1289
+ # - pread(maxlen, offset) -> string
1290
+ # - pread(maxlen, offset, out_string) -> string
1291
+ # -->
1292
+ # See IO#pread.
1293
+ #
1294
+ def pread: (Integer maxlen, Integer offset, ?String? outbuf) -> String
1295
+
1296
+ def read_nonblock: (int len, ?string? buf, ?exception: bool) -> String?
1287
1297
 
1288
1298
  def readbyte: () -> Integer
1289
1299
 
@@ -1301,7 +1311,7 @@ class StringIO
1301
1311
  #
1302
1312
  def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String]
1303
1313
 
1304
- def readpartial: (int maxlen, ?string outbuf) -> String
1314
+ def readpartial: (int maxlen, ?string? outbuf) -> String
1305
1315
 
1306
1316
  # <!--
1307
1317
  # rdoc-file=ext/stringio/stringio.c
@@ -1358,6 +1368,16 @@ class StringIO
1358
1368
  def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self
1359
1369
  | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self
1360
1370
 
1371
+ # <!--
1372
+ # rdoc-file=ext/stringio/stringio.c
1373
+ # - strio.set_encoding_by_bom => strio or nil
1374
+ # -->
1375
+ # Sets the encoding according to the BOM (Byte Order Mark) in the string.
1376
+ #
1377
+ # Returns `self` if the BOM is found, otherwise +nil.
1378
+ #
1379
+ def set_encoding_by_bom: () -> Encoding?
1380
+
1361
1381
  # <!--
1362
1382
  # rdoc-file=ext/stringio/stringio.c
1363
1383
  # - string -> string
@@ -1429,7 +1449,7 @@ class StringIO
1429
1449
  #
1430
1450
  def sync=: (boolish) -> bool
1431
1451
 
1432
- def sysread: (Integer maxlen, String outbuf) -> String
1452
+ def sysread: (Integer maxlen, ?String? outbuf) -> String
1433
1453
 
1434
1454
  def syswrite: (String arg0) -> Integer
1435
1455
 
@@ -1472,7 +1492,7 @@ class StringIO
1472
1492
  # Pushes back ("unshifts") a character or integer onto the stream; see
1473
1493
  # [Character IO](rdoc-ref:IO@Character+IO).
1474
1494
  #
1475
- def ungetc: (String arg0) -> nil
1495
+ def ungetc: (String | Integer arg0) -> nil
1476
1496
 
1477
1497
  # <!--
1478
1498
  # rdoc-file=ext/stringio/stringio.c
@@ -1485,6 +1505,8 @@ class StringIO
1485
1505
  #
1486
1506
  def write: (*_ToS) -> Integer
1487
1507
 
1508
+ def write_nonblock: (_ToS s, ?exception: bool) -> Integer
1509
+
1488
1510
  # This is a deprecated alias for #each_byte.
1489
1511
  #
1490
1512
  def bytes: () { (Integer arg0) -> untyped } -> self
@@ -498,7 +498,7 @@ class StringScanner
498
498
  # scanner[0] # => nil
499
499
  # scanner[1] # => nil
500
500
  #
501
- def []: (Integer) -> String?
501
+ def []: (Integer | String | Symbol) -> String?
502
502
 
503
503
  # <!--
504
504
  # rdoc-file=ext/strscan/strscan.c
@@ -625,7 +625,7 @@ class StringScanner
625
625
  # scanner.check(/nope/) # => nil
626
626
  # match_values_cleared?(scanner) # => true
627
627
  #
628
- def check: (Regexp) -> String?
628
+ def check: (Regexp | String) -> String?
629
629
 
630
630
  # <!--
631
631
  # rdoc-file=ext/strscan/strscan.c
@@ -673,15 +673,7 @@ class StringScanner
673
673
  # scanner.check_until(/nope/) # => nil
674
674
  # match_values_cleared?(scanner) # => true
675
675
  #
676
- def check_until: (Regexp) -> String
677
-
678
- # <!--
679
- # rdoc-file=ext/strscan/strscan.c
680
- # - clear()
681
- # -->
682
- # Equivalent to #terminate. This method is obsolete; use #terminate instead.
683
- #
684
- def clear: () -> void
676
+ def check_until: (Regexp | String) -> String?
685
677
 
686
678
  # <!--
687
679
  # rdoc-file=ext/strscan/strscan.c
@@ -706,14 +698,6 @@ class StringScanner
706
698
  #
707
699
  alias concat <<
708
700
 
709
- # <!--
710
- # rdoc-file=ext/strscan/strscan.c
711
- # - empty?()
712
- # -->
713
- # Equivalent to #eos?. This method is obsolete, use #eos? instead.
714
- #
715
- def empty?: () -> bool
716
-
717
701
  # <!--
718
702
  # rdoc-file=ext/strscan/strscan.c
719
703
  # - eos? -> true or false
@@ -776,7 +760,7 @@ class StringScanner
776
760
  # scanner.exist?(/nope/) # => nil
777
761
  # match_values_cleared?(scanner) # => true
778
762
  #
779
- def exist?: (Regexp) -> Integer?
763
+ def exist?: (Regexp | String) -> Integer?
780
764
 
781
765
  # <!--
782
766
  # rdoc-file=ext/strscan/strscan.c
@@ -818,14 +802,6 @@ class StringScanner
818
802
  #
819
803
  def get_byte: () -> String?
820
804
 
821
- # <!--
822
- # rdoc-file=ext/strscan/strscan.c
823
- # - getbyte()
824
- # -->
825
- # Equivalent to #get_byte. This method is obsolete; use #get_byte instead.
826
- #
827
- def getbyte: () -> String?
828
-
829
805
  # <!--
830
806
  # rdoc-file=ext/strscan/strscan.c
831
807
  # - getch()
@@ -937,7 +913,7 @@ class StringScanner
937
913
  # scanner.match?(/nope/) # => nil
938
914
  # match_values_cleared?(scanner) # => true
939
915
  #
940
- def match?: (Regexp) -> Integer?
916
+ def match?: (Regexp | String) -> Integer?
941
917
 
942
918
  # <!--
943
919
  # rdoc-file=ext/strscan/strscan.c
@@ -997,6 +973,29 @@ class StringScanner
997
973
  #
998
974
  def matched_size: () -> Integer?
999
975
 
976
+ # <!--
977
+ # rdoc-file=ext/strscan/strscan.c
978
+ # - named_captures -> hash
979
+ # -->
980
+ # Returns the array of captured match values at indexes (1..)
981
+ # if the most recent match attempt succeeded, or nil otherwise;
982
+ # see [Captured Match Values](rdoc-ref:StringScanner@Captured+Match+Values):
983
+ # scanner = StringScanner.new('Fri Dec 12 1975 14:39')
984
+ # scanner.named_captures # => {}
985
+ #
986
+ # pattern = /(?<wday>\w+) (?<month>\w+) (?<day>\d+) /
987
+ # scanner.match?(pattern)
988
+ # scanner.named_captures # => {"wday"=>"Fri", "month"=>"Dec", "day"=>"12"}
989
+ #
990
+ # scanner.string = 'nope'
991
+ # scanner.match?(pattern)
992
+ # scanner.named_captures # => {"wday"=>nil, "month"=>nil, "day"=>nil}
993
+ #
994
+ # scanner.match?(/nosuch/)
995
+ # scanner.named_captures # => {}
996
+ #
997
+ def named_captures: () -> Hash[String, String?]
998
+
1000
999
  # <!--
1001
1000
  # rdoc-file=ext/strscan/strscan.c
1002
1001
  # - peek(length) -> substring
@@ -1014,11 +1013,14 @@ class StringScanner
1014
1013
 
1015
1014
  # <!--
1016
1015
  # rdoc-file=ext/strscan/strscan.c
1017
- # - peep(p1)
1016
+ # - peek_byte()
1018
1017
  # -->
1019
- # Equivalent to #peek. This method is obsolete; use #peek instead.
1018
+ # Peeks at the current byte and returns it as an integer.
1019
+ #
1020
+ # s = StringScanner.new('ab')
1021
+ # s.peek_byte # => 97
1020
1022
  #
1021
- def peep: (Integer) -> String
1023
+ def peek_byte: () -> Integer?
1022
1024
 
1023
1025
  # <!-- rdoc-file=ext/strscan/strscan.c -->
1024
1026
  # call-seq:
@@ -1124,7 +1126,7 @@ class StringScanner
1124
1126
  # scanner.match?(/nope/) # => nil
1125
1127
  # scanner.post_match # => nil
1126
1128
  #
1127
- def post_match: () -> String
1129
+ def post_match: () -> String?
1128
1130
 
1129
1131
  # <!--
1130
1132
  # rdoc-file=ext/strscan/strscan.c
@@ -1144,7 +1146,7 @@ class StringScanner
1144
1146
  # scanner.exist?(/nope/) # => nil
1145
1147
  # scanner.pre_match # => nil
1146
1148
  #
1147
- def pre_match: () -> String
1149
+ def pre_match: () -> String?
1148
1150
 
1149
1151
  # <!--
1150
1152
  # rdoc-file=ext/strscan/strscan.c
@@ -1166,7 +1168,7 @@ class StringScanner
1166
1168
  # # => nil
1167
1169
  # match_values_cleared?(scanner) # => true
1168
1170
  #
1169
- def reset: () -> void
1171
+ def reset: () -> self
1170
1172
 
1171
1173
  # <!--
1172
1174
  # rdoc-file=ext/strscan/strscan.c
@@ -1217,15 +1219,6 @@ class StringScanner
1217
1219
  #
1218
1220
  def rest_size: () -> Integer
1219
1221
 
1220
- # <!--
1221
- # rdoc-file=ext/strscan/strscan.c
1222
- # - restsize()
1223
- # -->
1224
- # `s.restsize` is equivalent to `s.rest_size`. This method is obsolete; use
1225
- # #rest_size instead.
1226
- #
1227
- def restsize: () -> Integer
1228
-
1229
1222
  # <!--
1230
1223
  # rdoc-file=ext/strscan/strscan.c
1231
1224
  # - scan(p1)
@@ -1276,7 +1269,16 @@ class StringScanner
1276
1269
  # scanner.scan(/nope/) # => nil
1277
1270
  # match_values_cleared?(scanner) # => true
1278
1271
  #
1279
- def scan: (Regexp) -> String?
1272
+ def scan: (Regexp | String) -> String?
1273
+
1274
+ # <!--
1275
+ # rdoc-file=ext/strscan/strscan.c
1276
+ # - scan_byte -> integer_byte
1277
+ # -->
1278
+ # Scans one byte and returns it as an integer. This method is not multibyte
1279
+ # character sensitive. See also: #getch.
1280
+ #
1281
+ def scan_byte: () -> Integer?
1280
1282
 
1281
1283
  # <!--
1282
1284
  # rdoc-file=ext/strscan/strscan.c
@@ -1288,7 +1290,23 @@ class StringScanner
1288
1290
  #
1289
1291
  # "full" means "#scan with full parameters".
1290
1292
  #
1291
- def scan_full: (Regexp pattern, bool advance_pointer_p, bool return_string_p) -> untyped
1293
+ def scan_full: (Regexp | String pattern, bool advance_pointer_p, true return_string_p) -> String?
1294
+ | (Regexp | String pattern, bool advance_pointer_p, false return_string_p) -> Integer?
1295
+
1296
+ # <!--
1297
+ # rdoc-file=ext/strscan/lib/strscan/strscan.rb
1298
+ # - scan_integer(base: 10)
1299
+ # -->
1300
+ # If `base` isn't provided or is `10`, then it is equivalent to calling
1301
+ # <code>#scan</code> with a `[+-]?d+` pattern, and returns an Integer or nil.
1302
+ #
1303
+ # If `base` is `16`, then it is equivalent to calling <code>#scan</code> with a
1304
+ # `[+-]?(0x)?[0-9a-fA-F]+` pattern, and returns an Integer or nil.
1305
+ #
1306
+ # The scanned string must be encoded with an ASCII compatible encoding,
1307
+ # otherwise Encoding::CompatibilityError will be raised.
1308
+ #
1309
+ def scan_integer: (?base: Integer) -> Integer?
1292
1310
 
1293
1311
  # <!--
1294
1312
  # rdoc-file=ext/strscan/strscan.c
@@ -1341,7 +1359,7 @@ class StringScanner
1341
1359
  # scanner.scan_until(/nope/) # => nil
1342
1360
  # match_values_cleared?(scanner) # => true
1343
1361
  #
1344
- def scan_until: (Regexp) -> String?
1362
+ def scan_until: (Regexp | String) -> String?
1345
1363
 
1346
1364
  # <!--
1347
1365
  # rdoc-file=ext/strscan/strscan.c
@@ -1352,7 +1370,8 @@ class StringScanner
1352
1370
  # `return_string_p` is true, otherwise returns the number of bytes advanced.
1353
1371
  # This method does affect the match register.
1354
1372
  #
1355
- def search_full: (Regexp pattern, bool advance_pointer_p, bool return_string_p) -> untyped
1373
+ def search_full: (Regexp | String pattern, bool advance_pointer_p, true return_string_p) -> String?
1374
+ | (Regexp | String pattern, bool advance_pointer_p, false return_string_p) -> Integer?
1356
1375
 
1357
1376
  # <!--
1358
1377
  # rdoc-file=ext/strscan/strscan.c
@@ -1372,7 +1391,7 @@ class StringScanner
1372
1391
  # scanner.match?(/nope/) # => nil
1373
1392
  # scanner.size # => nil
1374
1393
  #
1375
- def size: () -> Integer
1394
+ def size: () -> Integer?
1376
1395
 
1377
1396
  # <!--
1378
1397
  # rdoc-file=ext/strscan/strscan.c
@@ -1420,7 +1439,7 @@ class StringScanner
1420
1439
  # scanner.skip(/nope/) # => nil
1421
1440
  # match_values_cleared?(scanner) # => true
1422
1441
  #
1423
- def skip: (Regexp) -> Integer?
1442
+ def skip: (Regexp | String) -> Integer?
1424
1443
 
1425
1444
  # <!--
1426
1445
  # rdoc-file=ext/strscan/strscan.c
@@ -1468,7 +1487,7 @@ class StringScanner
1468
1487
  # scanner.skip_until(/nope/) # => nil
1469
1488
  # match_values_cleared?(scanner) # => true
1470
1489
  #
1471
- def skip_until: (Regexp) -> Integer?
1490
+ def skip_until: (Regexp | String) -> Integer?
1472
1491
 
1473
1492
  # <!--
1474
1493
  # rdoc-file=ext/strscan/strscan.c
@@ -1542,7 +1561,7 @@ class StringScanner
1542
1561
  # # rest_size: 0
1543
1562
  # match_values_cleared?(scanner) # => true
1544
1563
  #
1545
- def terminate: () -> void
1564
+ def terminate: () -> self
1546
1565
 
1547
1566
  # <!--
1548
1567
  # rdoc-file=ext/strscan/strscan.c
@@ -1573,7 +1592,7 @@ class StringScanner
1573
1592
  # match_values_cleared?(scanner) # => true
1574
1593
  # scanner.unscan # Raises StringScanner::Error.
1575
1594
  #
1576
- def unscan: () -> void
1595
+ def unscan: () -> self
1577
1596
 
1578
1597
  # <!--
1579
1598
  # rdoc-file=ext/strscan/strscan.c
@@ -1588,7 +1607,7 @@ class StringScanner
1588
1607
  # scanner.values_at(*0..3) # => ["Fri Dec 12 ", "Fri", "Dec", "12"]
1589
1608
  # scanner.values_at(*%i[wday month day]) # => ["Fri", "Dec", "12"]
1590
1609
  #
1591
- def values_at: (*Integer) -> Array[String]?
1610
+ def values_at: (*Integer | String | Symbol) -> Array[String]?
1592
1611
 
1593
1612
  private
1594
1613
 
@@ -1611,7 +1630,7 @@ class StringScanner
1611
1630
  # # rest: "foobarbaz"
1612
1631
  # # rest_size: 9
1613
1632
  #
1614
- def initialize: (String, ?bool dup, ?fixed_anchor: bool) -> untyped
1633
+ def initialize: (String, ?fixed_anchor: bool) -> void
1615
1634
 
1616
1635
  # <!--
1617
1636
  # rdoc-file=ext/strscan/strscan.c
@@ -0,0 +1,3 @@
1
+ dependencies:
2
+ - name: delegate
3
+ - name: tmpdir
@@ -109,11 +109,6 @@ module Timeout
109
109
  # If you want the timeout to only happen on blocking operations one can use
110
110
  # :on_blocking instead of :immediate. However, that means if the block uses no
111
111
  # blocking operations after `sec` seconds, the block will not be interrupted.
112
- # ----
113
- # <!--
114
- # rdoc-file=lib/timeout.rb
115
- # - timeout(*args, &block)
116
- # -->
117
112
  #
118
113
  def self?.timeout: [T] (Numeric? sec, ?singleton(Exception) klass, ?String message) { (Numeric sec) -> T } -> T
119
114
  end
@@ -1,5 +1,5 @@
1
1
  %a{annotate:rdoc:skip}
2
- module TSort[Node]
2
+ module TSort[N]
3
3
  # <!-- rdoc-file=lib/tsort.rb -->
4
4
  # Exception class to be raised when a cycle is found.
5
5
  #
@@ -1,20 +1,20 @@
1
1
  %a{annotate:rdoc:skip}
2
- module TSort[Node]
3
- interface _Sortable[Node]
2
+ module TSort[N]
3
+ interface _Sortable[N]
4
4
  # #tsort_each_node is used to iterate for all nodes over a graph.
5
5
  #
6
- def tsort_each_node: () { (Node) -> void } -> void
6
+ def tsort_each_node: () { (N) -> void } -> void
7
7
 
8
8
  # #tsort_each_child is used to iterate for child nodes of node.
9
9
  #
10
- def tsort_each_child: (Node) { (Node) -> void } -> void
10
+ def tsort_each_child: (N) { (N) -> void } -> void
11
11
  end
12
12
 
13
- interface _EachNode[Node]
14
- def call: () { (Node) -> void } -> void
13
+ interface _EachNode[N]
14
+ def call: () { (N) -> void } -> void
15
15
  end
16
16
 
17
- interface _EachChild[Node]
18
- def call: (Node) { (Node) -> void } -> void
17
+ interface _EachChild[N]
18
+ def call: (N) { (N) -> void } -> void
19
19
  end
20
20
  end
@@ -113,7 +113,7 @@
113
113
  # 1. Tarjan, "Depth First Search and Linear Graph Algorithms",
114
114
  # *SIAM Journal on Computing*, Vol. 1, No. 2, pp. 146-160, June 1972.
115
115
  #
116
- module TSort[Node] : TSort::_Sortable[Node]
116
+ module TSort[N] : TSort::_Sortable[N]
117
117
  # <!--
118
118
  # rdoc-file=lib/tsort.rb
119
119
  # - each_strongly_connected_component(each_node, each_child) { |nodes| ... }
@@ -290,8 +290,8 @@ module TSort[Node] : TSort::_Sortable[Node]
290
290
  # # [2, 3]
291
291
  # # [1]
292
292
  #
293
- def each_strongly_connected_component: () { (Array[Node]) -> void } -> void
294
- | () -> Enumerator[Array[Node], void]
293
+ def each_strongly_connected_component: () { (Array[N]) -> void } -> void
294
+ | () -> Enumerator[Array[N], void]
295
295
 
296
296
  # <!--
297
297
  # rdoc-file=lib/tsort.rb
@@ -323,8 +323,8 @@ module TSort[Node] : TSort::_Sortable[Node]
323
323
  # #=> [4]
324
324
  # # [2, 3]
325
325
  #
326
- def each_strongly_connected_component_from: (Node, ?untyped id_map, ?untyped stack) { (Array[Node]) -> void } -> void
327
- | (Node, ?untyped id_map, ?untyped stack) -> Enumerator[Array[Node], void]
326
+ def each_strongly_connected_component_from: (N, ?untyped id_map, ?untyped stack) { (Array[N]) -> void } -> void
327
+ | (N, ?untyped id_map, ?untyped stack) -> Enumerator[Array[N], void]
328
328
 
329
329
  # <!--
330
330
  # rdoc-file=lib/tsort.rb
@@ -349,7 +349,7 @@ module TSort[Node] : TSort::_Sortable[Node]
349
349
  # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
350
350
  # p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
351
351
  #
352
- def strongly_connected_components: () -> Array[Array[Node]]
352
+ def strongly_connected_components: () -> Array[Array[N]]
353
353
 
354
354
  # <!--
355
355
  # rdoc-file=lib/tsort.rb
@@ -376,7 +376,7 @@ module TSort[Node] : TSort::_Sortable[Node]
376
376
  # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
377
377
  # p graph.tsort # raises TSort::Cyclic
378
378
  #
379
- def tsort: () -> Array[Node]
379
+ def tsort: () -> Array[N]
380
380
 
381
381
  # <!--
382
382
  # rdoc-file=lib/tsort.rb
@@ -405,6 +405,6 @@ module TSort[Node] : TSort::_Sortable[Node]
405
405
  # # 3
406
406
  # # 1
407
407
  #
408
- def tsort_each: () { (Node) -> void } -> void
409
- | () -> Enumerator[Node, void]
408
+ def tsort_each: () { (N) -> void } -> void
409
+ | () -> Enumerator[N, void]
410
410
  end
@@ -909,11 +909,6 @@ module URI
909
909
  #
910
910
  def merge: (URI::Generic | string oth) -> URI::Generic
911
911
 
912
- # <!--
913
- # rdoc-file=lib/uri/generic.rb
914
- # - +(oth)
915
- # -->
916
- #
917
912
  alias + merge
918
913
 
919
914
  # :stopdoc:
@@ -187,7 +187,7 @@ module Zlib
187
187
  # -->
188
188
  # See Zlib::GzipReader documentation for a description.
189
189
  #
190
- def read: (?int? length, ?string outbuf) -> String?
190
+ def read: (?int? length, ?string? outbuf) -> String?
191
191
 
192
192
  # <!--
193
193
  # rdoc-file=ext/zlib/zlib.c
@@ -230,7 +230,7 @@ module Zlib
230
230
  # argument is present, it must reference a String, which will receive the data.
231
231
  # It raises `EOFError` on end of file.
232
232
  #
233
- def readpartial: (int maxlen, ?string outbuf) -> String
233
+ def readpartial: (int maxlen, ?string? outbuf) -> String
234
234
 
235
235
  # <!--
236
236
  # rdoc-file=ext/zlib/zlib.c
@@ -153,7 +153,6 @@ module Zlib
153
153
  # rdoc-file=ext/zlib/zlib.c
154
154
  # - flush_next_in -> input
155
155
  # -->
156
- # Flushes input buffer and returns all data in that buffer.
157
156
  #
158
157
  def flush_next_in: () -> String
159
158
 
data/wasm/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # RBS parser as WebAssembly
2
+
3
+ The parser under [`src/`](../src) is plain, self-contained C with no dependency
4
+ on the Ruby C API, so it can be compiled to WebAssembly as-is. This directory
5
+ holds the small entry-point shim ([`rbs_wasm.c`](rbs_wasm.c)) that exposes a
6
+ stable ABI to a WebAssembly host.
7
+
8
+ This is how RBS runs on Ruby implementations that cannot load the MRI C
9
+ extension (notably JRuby): the host loads `rbs_parser.wasm`, runs the parser over
10
+ a source buffer, and reads the serialized AST back out. The Ruby side then
11
+ rebuilds `RBS::AST` objects with `RBS::WASM::Deserializer` — no native build per
12
+ platform required. See [`lib/rbs/wasm`](../lib/rbs/wasm) and
13
+ [`docs/wasm_serialization.md`](../docs/wasm_serialization.md).
14
+
15
+ ## Building
16
+
17
+ The build needs the [WASI SDK](https://github.com/WebAssembly/wasi-sdk/releases)
18
+ (for `clang`, the wasi-libc sysroot, and the wasm32 compiler-rt builtins):
19
+
20
+ ```console
21
+ $ export WASI_SDK_PATH=/path/to/wasi-sdk
22
+ $ rake wasm:build # compile rbs_parser.wasm
23
+ $ rake wasm:check # also smoke-test it (needs wasmtime)
24
+ $ rake wasm:jruby_setup # copy rbs_parser.wasm into lib/rbs/wasm/ for JRuby
25
+ $ rake wasm:install_jars # download the Chicory/ASM jars into ~/.m2 (run on JRuby)
26
+ ```
27
+
28
+ The compiled `rbs_parser.wasm` is a build artifact and is not checked in.
29
+
30
+ ## Exported functions
31
+
32
+ The module is built as a "reactor": it has no `main`, and the host calls
33
+ `_initialize` once before invoking any export.
34
+
35
+ Memory management and results:
36
+
37
+ | Export | Signature | Description |
38
+ | --- | --- | --- |
39
+ | `rbs_wasm_alloc` | `(i32) -> i32` | Allocate N bytes in linear memory, return the offset. |
40
+ | `rbs_wasm_free` | `(i32) -> ()` | Free a region from `rbs_wasm_alloc`. |
41
+ | `rbs_wasm_result_ptr` | `() -> i32` | Offset of the most recent result. |
42
+ | `rbs_wasm_result_len` | `() -> i32` | Length of the most recent result. |
43
+
44
+ Parsing — each takes the whole buffer (`ptr`/`len`), its Ruby encoding name
45
+ (`enc`/`enc_len`, e.g. `"UTF-8"` or `"EUC-JP"`; falls back to UTF-8 when empty or
46
+ unknown), and the character range to parse (`start`/`end`). Each returns `1` on
47
+ success or `0` on a parse error. On success the result is the serialized AST; on
48
+ error it is an error blob (start/end positions, syntax flag, token type,
49
+ message). Type/method-type parsing also takes a buffer of newline-separated
50
+ type-variable names (`vars`/`vars_len`, with `vars_len < 0` meaning "none"):
51
+
52
+ | Export | Signature |
53
+ | --- | --- |
54
+ | `rbs_wasm_parse_signature` | `(ptr, len, enc, enc_len, start, end) -> i32` |
55
+ | `rbs_wasm_parse_type` | `(ptr, len, enc, enc_len, start, end, vars, vars_len, require_eof, void_allowed, self_allowed, classish_allowed) -> i32` |
56
+ | `rbs_wasm_parse_method_type` | `(ptr, len, enc, enc_len, start, end, vars, vars_len, require_eof) -> i32` |
57
+ | `rbs_wasm_selftest` | `() -> i32` (parses a fixed sample; `1` on success) |
58
+
59
+ For type and method-type parsing, a successful result of length 0 means the input
60
+ was empty (`nil`).