rbs 4.0.0.dev.5 → 4.0.1.dev.1

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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +1 -0
  3. data/.github/workflows/c-check.yml +8 -4
  4. data/.github/workflows/comments.yml +3 -1
  5. data/.github/workflows/dependabot.yml +1 -1
  6. data/.github/workflows/ruby.yml +10 -0
  7. data/.github/workflows/rust.yml +95 -0
  8. data/CHANGELOG.md +323 -0
  9. data/Rakefile +12 -29
  10. data/Steepfile +1 -0
  11. data/config.yml +393 -37
  12. data/core/array.rbs +218 -188
  13. data/core/basic_object.rbs +9 -8
  14. data/core/class.rbs +6 -5
  15. data/core/comparable.rbs +45 -31
  16. data/core/complex.rbs +52 -40
  17. data/core/dir.rbs +57 -45
  18. data/core/encoding.rbs +5 -5
  19. data/core/enumerable.rbs +96 -91
  20. data/core/enumerator.rbs +4 -3
  21. data/core/errno.rbs +3 -2
  22. data/core/errors.rbs +31 -29
  23. data/core/exception.rbs +12 -12
  24. data/core/fiber.rbs +36 -36
  25. data/core/file.rbs +186 -113
  26. data/core/file_test.rbs +2 -2
  27. data/core/float.rbs +41 -32
  28. data/core/gc.rbs +78 -70
  29. data/core/hash.rbs +70 -60
  30. data/core/integer.rbs +32 -28
  31. data/core/io/buffer.rbs +36 -36
  32. data/core/io/wait.rbs +7 -7
  33. data/core/io.rbs +120 -135
  34. data/core/kernel.rbs +189 -139
  35. data/core/marshal.rbs +3 -3
  36. data/core/match_data.rbs +14 -12
  37. data/core/math.rbs +69 -67
  38. data/core/method.rbs +6 -6
  39. data/core/module.rbs +146 -85
  40. data/core/nil_class.rbs +4 -3
  41. data/core/numeric.rbs +35 -32
  42. data/core/object.rbs +6 -8
  43. data/core/object_space.rbs +11 -10
  44. data/core/pathname.rbs +131 -81
  45. data/core/proc.rbs +65 -33
  46. data/core/process.rbs +219 -201
  47. data/core/ractor.rbs +15 -11
  48. data/core/random.rbs +4 -3
  49. data/core/range.rbs +52 -47
  50. data/core/rational.rbs +5 -5
  51. data/core/rbs/unnamed/argf.rbs +58 -51
  52. data/core/rbs/unnamed/env_class.rbs +18 -13
  53. data/core/rbs/unnamed/main_class.rbs +123 -0
  54. data/core/rbs/unnamed/random.rbs +7 -5
  55. data/core/regexp.rbs +236 -197
  56. data/core/ruby.rbs +1 -1
  57. data/core/ruby_vm.rbs +32 -30
  58. data/core/rubygems/config_file.rbs +5 -5
  59. data/core/rubygems/errors.rbs +1 -1
  60. data/core/rubygems/requirement.rbs +5 -5
  61. data/core/rubygems/rubygems.rbs +5 -3
  62. data/core/set.rbs +17 -16
  63. data/core/signal.rbs +2 -2
  64. data/core/string.rbs +311 -292
  65. data/core/struct.rbs +26 -25
  66. data/core/symbol.rbs +25 -24
  67. data/core/thread.rbs +40 -34
  68. data/core/time.rbs +47 -42
  69. data/core/trace_point.rbs +34 -31
  70. data/core/true_class.rbs +2 -2
  71. data/core/unbound_method.rbs +10 -10
  72. data/core/warning.rbs +7 -7
  73. data/docs/collection.md +1 -1
  74. data/docs/config.md +171 -0
  75. data/docs/inline.md +110 -4
  76. data/docs/syntax.md +13 -12
  77. data/ext/rbs_extension/ast_translation.c +489 -135
  78. data/ext/rbs_extension/class_constants.c +8 -0
  79. data/ext/rbs_extension/class_constants.h +4 -0
  80. data/ext/rbs_extension/legacy_location.c +28 -51
  81. data/ext/rbs_extension/legacy_location.h +37 -0
  82. data/ext/rbs_extension/main.c +12 -20
  83. data/include/rbs/ast.h +423 -195
  84. data/include/rbs/lexer.h +2 -2
  85. data/include/rbs/location.h +25 -44
  86. data/include/rbs/parser.h +2 -2
  87. data/include/rbs/util/rbs_constant_pool.h +0 -3
  88. data/include/rbs.h +8 -0
  89. data/lib/rbs/ast/ruby/annotations.rb +157 -4
  90. data/lib/rbs/ast/ruby/members.rb +374 -22
  91. data/lib/rbs/cli/validate.rb +5 -60
  92. data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
  93. data/lib/rbs/definition_builder.rb +60 -27
  94. data/lib/rbs/errors.rb +0 -11
  95. data/lib/rbs/inline_parser.rb +1 -1
  96. data/lib/rbs/parser_aux.rb +20 -7
  97. data/lib/rbs/prototype/helpers.rb +57 -0
  98. data/lib/rbs/prototype/rb.rb +1 -26
  99. data/lib/rbs/prototype/rbi.rb +1 -20
  100. data/lib/rbs/test/type_check.rb +3 -0
  101. data/lib/rbs/types.rb +62 -52
  102. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  103. data/lib/rbs/version.rb +1 -1
  104. data/lib/rbs.rb +0 -1
  105. data/rbs.gemspec +1 -1
  106. data/rust/.gitignore +1 -0
  107. data/rust/Cargo.lock +378 -0
  108. data/rust/Cargo.toml +7 -0
  109. data/rust/ruby-rbs/Cargo.toml +22 -0
  110. data/rust/ruby-rbs/build.rs +764 -0
  111. data/rust/ruby-rbs/examples/locations.rs +60 -0
  112. data/rust/ruby-rbs/src/lib.rs +1 -0
  113. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  114. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  115. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  116. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  117. data/rust/ruby-rbs-sys/build.rs +204 -0
  118. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  119. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  120. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  121. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  122. data/sig/ast/ruby/annotations.rbs +191 -4
  123. data/sig/ast/ruby/members.rbs +21 -1
  124. data/sig/cli/validate.rbs +1 -6
  125. data/sig/definition_builder.rbs +2 -0
  126. data/sig/errors.rbs +0 -8
  127. data/sig/method_types.rbs +1 -1
  128. data/sig/parser.rbs +17 -13
  129. data/sig/prototype/helpers.rbs +2 -0
  130. data/sig/types.rbs +10 -11
  131. data/sig/unit_test/spy.rbs +0 -8
  132. data/sig/unit_test/type_assertions.rbs +11 -0
  133. data/src/ast.c +339 -161
  134. data/src/lexstate.c +1 -1
  135. data/src/location.c +7 -47
  136. data/src/parser.c +674 -480
  137. data/src/util/rbs_constant_pool.c +0 -4
  138. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
  139. data/stdlib/cgi-escape/0/escape.rbs +4 -4
  140. data/stdlib/coverage/0/coverage.rbs +4 -3
  141. data/stdlib/date/0/date.rbs +33 -28
  142. data/stdlib/date/0/date_time.rbs +24 -23
  143. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  144. data/stdlib/erb/0/erb.rbs +64 -53
  145. data/stdlib/etc/0/etc.rbs +55 -50
  146. data/stdlib/fileutils/0/fileutils.rbs +138 -125
  147. data/stdlib/forwardable/0/forwardable.rbs +10 -10
  148. data/stdlib/io-console/0/io-console.rbs +2 -2
  149. data/stdlib/json/0/json.rbs +135 -108
  150. data/stdlib/monitor/0/monitor.rbs +3 -3
  151. data/stdlib/net-http/0/net-http.rbs +159 -134
  152. data/stdlib/objspace/0/objspace.rbs +8 -7
  153. data/stdlib/open-uri/0/open-uri.rbs +8 -8
  154. data/stdlib/open3/0/open3.rbs +36 -35
  155. data/stdlib/openssl/0/openssl.rbs +144 -129
  156. data/stdlib/optparse/0/optparse.rbs +18 -14
  157. data/stdlib/pathname/0/pathname.rbs +2 -2
  158. data/stdlib/pp/0/pp.rbs +9 -8
  159. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  160. data/stdlib/pstore/0/pstore.rbs +35 -30
  161. data/stdlib/psych/0/psych.rbs +61 -8
  162. data/stdlib/psych/0/store.rbs +2 -4
  163. data/stdlib/pty/0/pty.rbs +9 -6
  164. data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
  165. data/stdlib/ripper/0/ripper.rbs +20 -17
  166. data/stdlib/securerandom/0/securerandom.rbs +1 -1
  167. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  168. data/stdlib/socket/0/addrinfo.rbs +7 -7
  169. data/stdlib/socket/0/basic_socket.rbs +3 -3
  170. data/stdlib/socket/0/ip_socket.rbs +10 -8
  171. data/stdlib/socket/0/socket.rbs +10 -9
  172. data/stdlib/socket/0/tcp_server.rbs +1 -1
  173. data/stdlib/socket/0/tcp_socket.rbs +1 -1
  174. data/stdlib/socket/0/udp_socket.rbs +1 -1
  175. data/stdlib/socket/0/unix_server.rbs +1 -1
  176. data/stdlib/stringio/0/stringio.rbs +55 -54
  177. data/stdlib/strscan/0/string_scanner.rbs +46 -44
  178. data/stdlib/tempfile/0/tempfile.rbs +24 -20
  179. data/stdlib/time/0/time.rbs +7 -5
  180. data/stdlib/tsort/0/tsort.rbs +7 -6
  181. data/stdlib/uri/0/common.rbs +26 -18
  182. data/stdlib/uri/0/file.rbs +2 -2
  183. data/stdlib/uri/0/generic.rbs +2 -2
  184. data/stdlib/uri/0/http.rbs +2 -2
  185. data/stdlib/uri/0/ldap.rbs +2 -2
  186. data/stdlib/uri/0/mailto.rbs +3 -3
  187. data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
  188. data/stdlib/zlib/0/deflate.rbs +4 -3
  189. data/stdlib/zlib/0/gzip_reader.rbs +4 -4
  190. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  191. data/stdlib/zlib/0/inflate.rbs +1 -1
  192. data/stdlib/zlib/0/need_dict.rbs +1 -1
  193. metadata +23 -5
  194. data/.github/workflows/valgrind.yml +0 -42
data/include/rbs/lexer.h CHANGED
@@ -136,8 +136,8 @@ typedef struct {
136
136
  * */
137
137
  typedef struct {
138
138
  rbs_string_t string;
139
- int start_pos; /* The character position that defines the start of the input */
140
- int end_pos; /* The character position that defines the end of the input */
139
+ int start_pos; /* The byte position that defines the start of the input */
140
+ int end_pos; /* The byte position that defines the end of the input */
141
141
  rbs_position_t current; /* The current position: just before the current_character */
142
142
  rbs_position_t start; /* The start position of the current token */
143
143
 
@@ -1,59 +1,40 @@
1
1
  #ifndef RBS__RBS_LOCATION_H
2
2
  #define RBS__RBS_LOCATION_H
3
3
 
4
- #include "lexer.h"
5
-
6
- #include "rbs/util/rbs_constant_pool.h"
7
4
  #include "rbs/util/rbs_allocator.h"
8
5
 
9
- typedef struct {
10
- int start;
11
- int end;
12
- } rbs_loc_range;
6
+ #define RBS_LOCATION_NULL_RANGE ((rbs_location_range) { -1, -1, -1, -1 })
7
+ #define RBS_LOCATION_NULL_RANGE_P(rg) ((rg).start_char == -1)
8
+
9
+ /**
10
+ * Converts a lexer range (rbs_range_t) to an AST location range (rbs_location_range) by extracting character and byte positions.
11
+ */
12
+ #define RBS_RANGE_LEX2AST(rg) ((rbs_location_range) { .start_char = (rg).start.char_pos, .start_byte = (rg).start.byte_pos, .end_char = (rg).end.char_pos, .end_byte = (rg).end.byte_pos })
13
13
 
14
14
  typedef struct {
15
- rbs_constant_id_t name;
16
- rbs_loc_range rg;
17
- } rbs_loc_entry;
15
+ int start_char;
16
+ int start_byte;
18
17
 
19
- typedef unsigned int rbs_loc_entry_bitmap;
18
+ int end_char;
19
+ int end_byte;
20
+ } rbs_location_range;
20
21
 
21
- // The flexible array always allocates, but it's okay.
22
- // This struct is not allocated when the `rbs_loc` doesn't have children.
23
- typedef struct {
24
- unsigned short len;
25
- unsigned short cap;
26
- rbs_loc_entry_bitmap required_p;
27
- rbs_loc_entry entries[1];
28
- } rbs_loc_children;
29
-
30
- typedef struct rbs_location {
31
- rbs_range_t rg;
32
- rbs_loc_children *children;
33
- } rbs_location_t;
34
-
35
- typedef struct rbs_location_list_node {
36
- rbs_location_t *loc;
37
- struct rbs_location_list_node *next;
38
- } rbs_location_list_node_t;
39
-
40
- typedef struct rbs_location_list {
22
+ typedef struct rbs_location_range_list_node {
23
+ rbs_location_range range;
24
+ struct rbs_location_range_list_node *next;
25
+ } rbs_location_range_list_node_t;
26
+
27
+ typedef struct rbs_location_range_list {
41
28
  rbs_allocator_t *allocator;
42
- rbs_location_list_node_t *head;
43
- rbs_location_list_node_t *tail;
29
+ struct rbs_location_range_list_node *head;
30
+ struct rbs_location_range_list_node *tail;
44
31
  size_t length;
45
- } rbs_location_list_t;
46
-
47
- void rbs_loc_alloc_children(rbs_allocator_t *, rbs_location_t *loc, size_t capacity);
48
- void rbs_loc_add_required_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r);
49
- void rbs_loc_add_optional_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r);
32
+ } rbs_location_range_list_t;
50
33
 
51
34
  /**
52
- * Allocate new rbs_location_t object through the given allocator.
53
- * */
54
- rbs_location_t *rbs_location_new(rbs_allocator_t *, rbs_range_t rg);
55
-
56
- rbs_location_list_t *rbs_location_list_new(rbs_allocator_t *allocator);
57
- void rbs_location_list_append(rbs_location_list_t *list, rbs_location_t *loc);
35
+ * Allocate new rbs_location_range_list_t object through the given allocator.
36
+ */
37
+ rbs_location_range_list_t *rbs_location_range_list_new(rbs_allocator_t *allocator);
38
+ void rbs_location_range_list_append(rbs_location_range_list_t *list, rbs_location_range range);
58
39
 
59
40
  #endif
data/include/rbs/parser.h CHANGED
@@ -126,8 +126,8 @@ rbs_ast_comment_t *rbs_parser_get_comment(rbs_parser_t *parser, int subject_line
126
126
 
127
127
  void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_error, const char *fmt, ...) RBS_ATTRIBUTE_FORMAT(4, 5);
128
128
 
129
- bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed);
130
- bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof);
129
+ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed);
130
+ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof, bool classish_allowed);
131
131
  bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature);
132
132
 
133
133
  bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params);
@@ -81,9 +81,6 @@ typedef struct {
81
81
  uint32_t capacity;
82
82
  } rbs_constant_pool_t;
83
83
 
84
- // A global constant pool for storing permenant keywords, such as the names of location children in `parser.c`.
85
- extern rbs_constant_pool_t *RBS_GLOBAL_CONSTANT_POOL;
86
-
87
84
  /**
88
85
  * Initialize a new constant pool with a given capacity.
89
86
  *
data/include/rbs.h CHANGED
@@ -1,6 +1,14 @@
1
1
  #ifndef RBS_H
2
2
  #define RBS_H
3
3
 
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
4
8
  #include "rbs/parser.h"
5
9
 
10
+ #ifdef __cplusplus
11
+ }
12
+ #endif
13
+
6
14
  #endif
@@ -109,12 +109,13 @@ module RBS
109
109
  class MethodTypesAnnotation < Base
110
110
  Overload = AST::Members::MethodDefinition::Overload
111
111
 
112
- attr_reader :overloads, :vertical_bar_locations
112
+ attr_reader :overloads, :vertical_bar_locations, :dot3_location
113
113
 
114
- def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:)
114
+ def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:, dot3_location:)
115
115
  super(location, prefix_location)
116
116
  @overloads = overloads
117
117
  @vertical_bar_locations = vertical_bar_locations
118
+ @dot3_location = dot3_location
118
119
  end
119
120
 
120
121
  def map_type_name(&block)
@@ -125,13 +126,14 @@ module RBS
125
126
  )
126
127
  end
127
128
 
128
- self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:) #: self
129
+ self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:, dot3_location:) #: self
129
130
  end
130
131
 
131
132
  def type_fingerprint
132
133
  [
133
134
  "annots/method_types",
134
- overloads.map { |o| [o.annotations.map(&:to_s), o.method_type.to_s] }
135
+ overloads.map { |o| [o.annotations.map(&:to_s), o.method_type.to_s] },
136
+ overloading: dot3_location ? true : false
135
137
  ]
136
138
  end
137
139
  end
@@ -250,6 +252,157 @@ module RBS
250
252
  ]
251
253
  end
252
254
  end
255
+
256
+ class ParamTypeAnnotation < Base
257
+ attr_reader :name_location, :colon_location, :param_type, :comment_location
258
+
259
+ def initialize(location:, prefix_location:, name_location:, colon_location:, param_type:, comment_location:)
260
+ super(location, prefix_location)
261
+ @name_location = name_location
262
+ @colon_location = colon_location
263
+ @param_type = param_type
264
+ @comment_location = comment_location
265
+ end
266
+
267
+ def map_type_name(&block)
268
+ self.class.new(
269
+ location:,
270
+ prefix_location:,
271
+ name_location: name_location,
272
+ colon_location: colon_location,
273
+ param_type: param_type.map_type_name { yield _1 },
274
+ comment_location: comment_location
275
+ ) #: self
276
+ end
277
+
278
+ def type_fingerprint
279
+ [
280
+ "annots/param_type",
281
+ name_location.source,
282
+ param_type.to_s,
283
+ comment_location&.source
284
+ ]
285
+ end
286
+ end
287
+
288
+ class SplatParamTypeAnnotation < Base
289
+ attr_reader :star_location, :name_location, :colon_location, :param_type, :comment_location
290
+
291
+ def initialize(location:, prefix_location:, star_location:, name_location:, colon_location:, param_type:, comment_location:)
292
+ super(location, prefix_location)
293
+ @star_location = star_location
294
+ @name_location = name_location
295
+ @colon_location = colon_location
296
+ @param_type = param_type
297
+ @comment_location = comment_location
298
+ end
299
+
300
+ def map_type_name(&block)
301
+ self.class.new(
302
+ location:,
303
+ prefix_location:,
304
+ star_location: star_location,
305
+ name_location: name_location,
306
+ colon_location: colon_location,
307
+ param_type: param_type.map_type_name { yield _1 },
308
+ comment_location: comment_location
309
+ ) #: self
310
+ end
311
+
312
+ def type_fingerprint
313
+ [
314
+ "annots/splat_param_type",
315
+ name_location&.source,
316
+ param_type.to_s,
317
+ comment_location&.source
318
+ ]
319
+ end
320
+ end
321
+
322
+ class DoubleSplatParamTypeAnnotation < Base
323
+ attr_reader :star2_location, :name_location, :colon_location, :param_type, :comment_location
324
+
325
+ def initialize(location:, prefix_location:, star2_location:, name_location:, colon_location:, param_type:, comment_location:)
326
+ super(location, prefix_location)
327
+ @star2_location = star2_location
328
+ @name_location = name_location
329
+ @colon_location = colon_location
330
+ @param_type = param_type
331
+ @comment_location = comment_location
332
+ end
333
+
334
+ def map_type_name(&block)
335
+ self.class.new(
336
+ location:,
337
+ prefix_location:,
338
+ star2_location: star2_location,
339
+ name_location: name_location,
340
+ colon_location: colon_location,
341
+ param_type: param_type.map_type_name { yield _1 },
342
+ comment_location: comment_location
343
+ ) #: self
344
+ end
345
+
346
+ def type_fingerprint
347
+ [
348
+ "annots/double_splat_param_type",
349
+ name_location&.source,
350
+ param_type.to_s,
351
+ comment_location&.source
352
+ ]
353
+ end
354
+ end
355
+
356
+ class BlockParamTypeAnnotation < Base
357
+ attr_reader :ampersand_location, :name_location, :colon_location, :question_location, :type_location, :type, :comment_location
358
+
359
+ def initialize(location:, prefix_location:, ampersand_location:, name_location:, colon_location:, question_location:, type_location:, type:, comment_location:)
360
+ super(location, prefix_location)
361
+ @ampersand_location = ampersand_location
362
+ @name_location = name_location
363
+ @colon_location = colon_location
364
+ @question_location = question_location
365
+ @type_location = type_location
366
+ @type = type
367
+ @comment_location = comment_location
368
+ end
369
+
370
+ def map_type_name(&block)
371
+ self.class.new(
372
+ location:,
373
+ prefix_location:,
374
+ ampersand_location: ampersand_location,
375
+ name_location: name_location,
376
+ colon_location: colon_location,
377
+ question_location: question_location,
378
+ type_location: type_location,
379
+ type: type.map_type_name { yield _1 },
380
+ comment_location: comment_location
381
+ ) #: self
382
+ end
383
+
384
+ def name
385
+ name_location&.source&.to_sym
386
+ end
387
+
388
+ def optional?
389
+ question_location ? true : false
390
+ end
391
+
392
+ def required?
393
+ !optional?
394
+ end
395
+
396
+ def type_fingerprint
397
+ [
398
+ "annots/block_param_type",
399
+ name_location&.source,
400
+ type.to_s,
401
+ optional? ? "optional" : "required",
402
+ comment_location&.source
403
+ ]
404
+ end
405
+ end
253
406
  end
254
407
  end
255
408
  end