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
@@ -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
@@ -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
@@ -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
data/wasm/README.md ADDED
@@ -0,0 +1,59 @@
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 # assemble lib/rbs/wasm/ for JRuby (wasm + Chicory jars)
25
+ ```
26
+
27
+ The compiled `rbs_parser.wasm` is a build artifact and is not checked in.
28
+
29
+ ## Exported functions
30
+
31
+ The module is built as a "reactor": it has no `main`, and the host calls
32
+ `_initialize` once before invoking any export.
33
+
34
+ Memory management and results:
35
+
36
+ | Export | Signature | Description |
37
+ | --- | --- | --- |
38
+ | `rbs_wasm_alloc` | `(i32) -> i32` | Allocate N bytes in linear memory, return the offset. |
39
+ | `rbs_wasm_free` | `(i32) -> ()` | Free a region from `rbs_wasm_alloc`. |
40
+ | `rbs_wasm_result_ptr` | `() -> i32` | Offset of the most recent result. |
41
+ | `rbs_wasm_result_len` | `() -> i32` | Length of the most recent result. |
42
+
43
+ Parsing — each takes the whole buffer (`ptr`/`len`), its Ruby encoding name
44
+ (`enc`/`enc_len`, e.g. `"UTF-8"` or `"EUC-JP"`; falls back to UTF-8 when empty or
45
+ unknown), and the character range to parse (`start`/`end`). Each returns `1` on
46
+ success or `0` on a parse error. On success the result is the serialized AST; on
47
+ error it is an error blob (start/end positions, syntax flag, token type,
48
+ message). Type/method-type parsing also takes a buffer of newline-separated
49
+ type-variable names (`vars`/`vars_len`, with `vars_len < 0` meaning "none"):
50
+
51
+ | Export | Signature |
52
+ | --- | --- |
53
+ | `rbs_wasm_parse_signature` | `(ptr, len, enc, enc_len, start, end) -> i32` |
54
+ | `rbs_wasm_parse_type` | `(ptr, len, enc, enc_len, start, end, vars, vars_len, require_eof, void_allowed, self_allowed, classish_allowed) -> i32` |
55
+ | `rbs_wasm_parse_method_type` | `(ptr, len, enc, enc_len, start, end, vars, vars_len, require_eof) -> i32` |
56
+ | `rbs_wasm_selftest` | `() -> i32` (parses a fixed sample; `1` on success) |
57
+
58
+ For type and method-type parsing, a successful result of length 0 means the input
59
+ was empty (`nil`).