rbs 4.0.3 → 4.1.3

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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +37 -0
  3. data/.github/dependabot.yml +1 -1
  4. data/.github/workflows/bundle-update.yml +2 -2
  5. data/.github/workflows/c-check.yml +14 -6
  6. data/.github/workflows/comments.yml +2 -2
  7. data/.github/workflows/dependabot.yml +2 -2
  8. data/.github/workflows/jruby.yml +74 -0
  9. data/.github/workflows/release-gems.yml +235 -0
  10. data/.github/workflows/ruby.yml +43 -3
  11. data/.github/workflows/rust.yml +13 -10
  12. data/.github/workflows/truffleruby.yml +54 -0
  13. data/.github/workflows/typecheck.yml +5 -2
  14. data/.github/workflows/wasm.yml +55 -0
  15. data/.github/workflows/windows.yml +5 -2
  16. data/.gitignore +8 -0
  17. data/CHANGELOG.md +113 -0
  18. data/Dockerfile.jruby +53 -0
  19. data/README.md +4 -4
  20. data/Rakefile +512 -82
  21. data/Steepfile +9 -0
  22. data/config.yml +26 -0
  23. data/core/array.rbs +243 -180
  24. data/core/builtin.rbs +7 -6
  25. data/core/class.rbs +5 -3
  26. data/core/enumerable.rbs +109 -109
  27. data/core/enumerator/product.rbs +5 -5
  28. data/core/enumerator.rbs +28 -28
  29. data/core/file.rbs +24 -1018
  30. data/core/file_constants.rbs +463 -0
  31. data/core/file_stat.rbs +534 -0
  32. data/core/float.rbs +0 -24
  33. data/core/hash.rbs +117 -101
  34. data/core/integer.rbs +21 -58
  35. data/core/io.rbs +25 -7
  36. data/core/kernel.rbs +26 -11
  37. data/core/match_data.rbs +1 -1
  38. data/core/module.rbs +88 -74
  39. data/core/numeric.rbs +3 -0
  40. data/core/object_space/weak_key_map.rbs +7 -7
  41. data/core/pathname.rbs +0 -10
  42. data/core/ractor.rbs +0 -10
  43. data/core/range.rbs +23 -23
  44. data/core/rbs/ops.rbs +154 -0
  45. data/core/rbs/unnamed/argf.rbs +3 -3
  46. data/core/ruby_vm.rbs +40 -0
  47. data/core/rubygems/errors.rbs +4 -1
  48. data/core/rubygems/requirement.rbs +0 -10
  49. data/core/rubygems/rubygems.rbs +4 -1
  50. data/core/rubygems/specification.rbs +8 -0
  51. data/core/rubygems/version.rbs +0 -160
  52. data/core/set.rbs +3 -3
  53. data/core/struct.rbs +16 -16
  54. data/core/thread.rbs +9 -14
  55. data/docs/CONTRIBUTING.md +2 -1
  56. data/docs/inline.md +65 -7
  57. data/docs/rbs_by_example.md +20 -20
  58. data/docs/release.md +247 -0
  59. data/docs/syntax.md +2 -2
  60. data/docs/wasm_serialization.md +80 -0
  61. data/ext/rbs_extension/ast_translation.c +1298 -956
  62. data/ext/rbs_extension/ast_translation.h +4 -0
  63. data/ext/rbs_extension/class_constants.c +2 -0
  64. data/ext/rbs_extension/class_constants.h +1 -0
  65. data/ext/rbs_extension/extconf.rb +1 -0
  66. data/ext/rbs_extension/legacy_location.c +11 -6
  67. data/ext/rbs_extension/main.c +139 -4
  68. data/include/rbs/ast.h +323 -298
  69. data/include/rbs/defines.h +18 -0
  70. data/include/rbs/lexer.h +1 -0
  71. data/include/rbs/serialize.h +39 -0
  72. data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
  73. data/lib/rbs/ast/ruby/annotations.rb +42 -0
  74. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  75. data/lib/rbs/ast/ruby/declarations.rb +11 -1
  76. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  77. data/lib/rbs/ast/ruby/members.rb +40 -1
  78. data/lib/rbs/buffer.rb +48 -11
  79. data/lib/rbs/cli.rb +3 -5
  80. data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
  81. data/lib/rbs/collection/sources/git.rb +6 -0
  82. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  83. data/lib/rbs/environment.rb +10 -3
  84. data/lib/rbs/inline_parser.rb +54 -28
  85. data/lib/rbs/namespace.rb +47 -11
  86. data/lib/rbs/parser_aux.rb +4 -2
  87. data/lib/rbs/prototype/rbi.rb +193 -25
  88. data/lib/rbs/prototype/runtime.rb +2 -0
  89. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  90. data/lib/rbs/rewriter.rb +70 -0
  91. data/lib/rbs/test/type_check.rb +6 -1
  92. data/lib/rbs/type_name.rb +33 -13
  93. data/lib/rbs/unit_test/type_assertions.rb +14 -5
  94. data/lib/rbs/version.rb +1 -1
  95. data/lib/rbs/wasm/deserializer.rb +213 -0
  96. data/lib/rbs/wasm/location.rb +61 -0
  97. data/lib/rbs/wasm/parser.rb +137 -0
  98. data/lib/rbs/wasm/runtime.rb +196 -0
  99. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  100. data/lib/rbs.rb +14 -2
  101. data/lib/rbs_jars.rb +39 -0
  102. data/lib/rdoc_plugin/parser.rb +5 -0
  103. data/rbs.gemspec +32 -2
  104. data/sig/annotate/rdoc_annotater.rbs +12 -9
  105. data/sig/ast/ruby/annotations.rbs +49 -0
  106. data/sig/ast/ruby/members.rbs +21 -1
  107. data/sig/buffer.rbs +19 -1
  108. data/sig/collection/config/lockfile_generator.rbs +2 -0
  109. data/sig/inline_parser.rbs +2 -0
  110. data/sig/manifest.yaml +0 -1
  111. data/sig/namespace.rbs +20 -0
  112. data/sig/parser.rbs +10 -0
  113. data/sig/prototype/rbi.rbs +33 -4
  114. data/sig/resolver/type_name_resolver.rbs +2 -4
  115. data/sig/rewriter.rbs +45 -0
  116. data/sig/typename.rbs +15 -0
  117. data/sig/unit_test/type_assertions.rbs +6 -2
  118. data/sig/wasm/deserializer.rbs +66 -0
  119. data/sig/wasm/serialization_schema.rbs +13 -0
  120. data/src/ast.c +186 -162
  121. data/src/lexer.c +220 -193
  122. data/src/lexer.re +2 -1
  123. data/src/lexstate.c +10 -1
  124. data/src/parser.c +61 -8
  125. data/src/serialize.c +958 -0
  126. data/src/util/rbs_allocator.c +14 -8
  127. data/stdlib/abbrev/0/array.rbs +1 -1
  128. data/stdlib/csv/0/csv.rbs +5 -5
  129. data/stdlib/delegate/0/delegator.rbs +2 -1
  130. data/stdlib/digest/0/digest.rbs +11 -5
  131. data/stdlib/erb/0/erb.rbs +1 -1
  132. data/stdlib/etc/0/etc.rbs +18 -4
  133. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  134. data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
  135. data/stdlib/json/0/json.rbs +6 -6
  136. data/stdlib/monitor/0/monitor.rbs +2 -2
  137. data/stdlib/openssl/0/openssl.rbs +46 -40
  138. data/stdlib/resolv/0/resolv.rbs +1 -1
  139. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  140. data/stdlib/stringio/0/stringio.rbs +32 -10
  141. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  142. data/stdlib/tempfile/0/manifest.yaml +3 -0
  143. data/stdlib/timeout/0/timeout.rbs +0 -5
  144. data/stdlib/tsort/0/cyclic.rbs +1 -1
  145. data/stdlib/tsort/0/interfaces.rbs +8 -8
  146. data/stdlib/tsort/0/tsort.rbs +9 -9
  147. data/stdlib/uri/0/generic.rbs +0 -5
  148. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  149. data/stdlib/zlib/0/zstream.rbs +0 -1
  150. data/wasm/README.md +93 -0
  151. data/wasm/rbs_wasm.c +423 -0
  152. metadata +29 -6
  153. data/.github/workflows/milestone.yml +0 -80
  154. data/.vscode/extensions.json +0 -5
  155. data/.vscode/settings.json +0 -19
@@ -23,6 +23,10 @@ typedef struct rbs_translation_context {
23
23
  rbs_constant_pool_t *constant_pool;
24
24
  VALUE buffer;
25
25
  rb_encoding *encoding;
26
+
27
+ /// A reusable Hash used for calling `rb_class_new_instance_kw()` without allocating a new Hash each time.
28
+ /// It's vital that the various Nodes' `#initialize` methods take the kwarg values, but don't retain this reusable Hash.
29
+ VALUE reusable_kwargs_hash;
26
30
  } rbs_translation_context_t;
27
31
 
28
32
  rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *, VALUE buffer_string, rb_encoding *ruby_encoding);
@@ -54,6 +54,7 @@ VALUE RBS_AST_Ruby_Annotations_DoubleSplatParamTypeAnnotation;
54
54
  VALUE RBS_AST_Ruby_Annotations_InstanceVariableAnnotation;
55
55
  VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
56
56
  VALUE RBS_AST_Ruby_Annotations_ModuleAliasAnnotation;
57
+ VALUE RBS_AST_Ruby_Annotations_ModuleSelfAnnotation;
57
58
  VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
58
59
  VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
59
60
  VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
@@ -147,6 +148,7 @@ void rbs__init_constants(void) {
147
148
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_InstanceVariableAnnotation, RBS_AST_Ruby_Annotations, "InstanceVariableAnnotation");
148
149
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_MethodTypesAnnotation, RBS_AST_Ruby_Annotations, "MethodTypesAnnotation");
149
150
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ModuleAliasAnnotation, RBS_AST_Ruby_Annotations, "ModuleAliasAnnotation");
151
+ IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ModuleSelfAnnotation, RBS_AST_Ruby_Annotations, "ModuleSelfAnnotation");
150
152
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_NodeTypeAssertion, RBS_AST_Ruby_Annotations, "NodeTypeAssertion");
151
153
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ParamTypeAnnotation, RBS_AST_Ruby_Annotations, "ParamTypeAnnotation");
152
154
  IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, RBS_AST_Ruby_Annotations, "ReturnTypeAnnotation");
@@ -62,6 +62,7 @@ extern VALUE RBS_AST_Ruby_Annotations_DoubleSplatParamTypeAnnotation;
62
62
  extern VALUE RBS_AST_Ruby_Annotations_InstanceVariableAnnotation;
63
63
  extern VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
64
64
  extern VALUE RBS_AST_Ruby_Annotations_ModuleAliasAnnotation;
65
+ extern VALUE RBS_AST_Ruby_Annotations_ModuleSelfAnnotation;
65
66
  extern VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
66
67
  extern VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
67
68
  extern VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
@@ -16,6 +16,7 @@ append_cflags [
16
16
  '-Wimplicit-fallthrough',
17
17
  '-Wunused-result',
18
18
  '-Wc++-compat',
19
+ '-Wnullable-to-nonnull-conversion',
19
20
  ]
20
21
 
21
22
  if ENV['DEBUG']
@@ -91,7 +91,7 @@ static rb_data_type_t location_type = {
91
91
  { rbs_loc_mark, (RUBY_DATA_FUNC) rbs_loc_free, rbs_loc_memsize },
92
92
  0,
93
93
  0,
94
- RUBY_TYPED_FREE_IMMEDIATELY
94
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
95
95
  };
96
96
 
97
97
  static VALUE location_s_allocate(VALUE klass) {
@@ -114,10 +114,11 @@ static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALU
114
114
  int end = FIX2INT(end_pos);
115
115
 
116
116
  *loc = (rbs_loc) {
117
- .buffer = buffer,
117
+ .buffer = Qnil,
118
118
  .rg = (rbs_loc_range) { start, end },
119
119
  .children = NULL,
120
120
  };
121
+ RB_OBJ_WRITE(self, &loc->buffer, buffer);
121
122
 
122
123
  return Qnil;
123
124
  }
@@ -127,10 +128,11 @@ static VALUE location_initialize_copy(VALUE self, VALUE other) {
127
128
  rbs_loc *other_loc = rbs_check_location(other);
128
129
 
129
130
  *self_loc = (rbs_loc) {
130
- .buffer = other_loc->buffer,
131
+ .buffer = Qnil,
131
132
  .rg = other_loc->rg,
132
133
  .children = NULL,
133
134
  };
135
+ RB_OBJ_WRITE(self, &self_loc->buffer, other_loc->buffer);
134
136
 
135
137
  if (other_loc->children != NULL) {
136
138
  rbs_loc_legacy_alloc_children(self_loc, other_loc->children->cap);
@@ -193,7 +195,8 @@ VALUE rbs_new_location(VALUE buffer, rbs_range_t rg) {
193
195
  rbs_loc *loc;
194
196
  VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
195
197
 
196
- rbs_loc_init(loc, buffer, (rbs_loc_range) { rg.start.char_pos, rg.end.char_pos });
198
+ rbs_loc_init(loc, Qnil, (rbs_loc_range) { rg.start.char_pos, rg.end.char_pos });
199
+ RB_OBJ_WRITE(obj, &loc->buffer, buffer);
197
200
 
198
201
  return obj;
199
202
  }
@@ -202,7 +205,8 @@ VALUE rbs_new_location2(VALUE buffer, int start_char, int end_char) {
202
205
  rbs_loc *loc;
203
206
  VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
204
207
 
205
- rbs_loc_init(loc, buffer, (rbs_loc_range) { .start = start_char, .end = end_char });
208
+ rbs_loc_init(loc, Qnil, (rbs_loc_range) { .start = start_char, .end = end_char });
209
+ RB_OBJ_WRITE(obj, &loc->buffer, buffer);
206
210
 
207
211
  return obj;
208
212
  }
@@ -211,7 +215,8 @@ static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
211
215
  rbs_loc *loc;
212
216
  VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
213
217
 
214
- rbs_loc_init(loc, buffer, rg);
218
+ rbs_loc_init(loc, Qnil, rg);
219
+ RB_OBJ_WRITE(obj, &loc->buffer, buffer);
215
220
 
216
221
  return obj;
217
222
  }
@@ -2,6 +2,7 @@
2
2
  #include "rbs/util/rbs_assert.h"
3
3
  #include "rbs/util/rbs_allocator.h"
4
4
  #include "rbs/util/rbs_constant_pool.h"
5
+ #include "rbs/serialize.h"
5
6
  #include "ast_translation.h"
6
7
  #include "legacy_location.h"
7
8
  #include "rbs_string_bridging.h"
@@ -145,10 +146,17 @@ static VALUE parse_type_try(VALUE a) {
145
146
  return rbs_struct_to_ruby_value(ctx, type);
146
147
  }
147
148
 
148
- static rbs_lexer_t *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE string, rb_encoding *encoding, int start_pos, int end_pos) {
149
+ static void validate_position_range(int start_pos, int end_pos) {
149
150
  if (start_pos < 0 || end_pos < 0) {
150
151
  rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
151
152
  }
153
+ if (start_pos > end_pos) {
154
+ rb_raise(rb_eArgError, "invalid position range: %d...%d", start_pos, end_pos);
155
+ }
156
+ }
157
+
158
+ static rbs_lexer_t *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE string, rb_encoding *encoding, int start_pos, int end_pos) {
159
+ validate_position_range(start_pos, end_pos);
152
160
 
153
161
  const char *encoding_name = rb_enc_name(encoding);
154
162
 
@@ -162,9 +170,7 @@ static rbs_lexer_t *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE st
162
170
  }
163
171
 
164
172
  static rbs_parser_t *alloc_parser_from_buffer(VALUE buffer, int start_pos, int end_pos) {
165
- if (start_pos < 0 || end_pos < 0) {
166
- rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
167
- }
173
+ validate_position_range(start_pos, end_pos);
168
174
 
169
175
  VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
170
176
  StringValue(string);
@@ -285,6 +291,132 @@ static VALUE rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE start_pos
285
291
  return result;
286
292
  }
287
293
 
294
+ // Serialize a parsed node into a binary Ruby string using the same encoder the
295
+ // WebAssembly build uses. These `_*_to_bytes` entry points exist so the
296
+ // round-trip (parse -> serialize -> deserialize) can be exercised on CRuby,
297
+ // where it can be compared against the direct C -> Ruby translation.
298
+ static VALUE serialized_node_to_string(rbs_parser_t *parser, rbs_node_t *node) {
299
+ rbs_string_t bytes = rbs_serialize_node(parser->allocator, &parser->constant_pool, node);
300
+ return rb_str_new(bytes.start, (long) rbs_string_len(bytes));
301
+ }
302
+
303
+ static VALUE parse_type_to_bytes_try(VALUE a) {
304
+ struct parse_type_arg *arg = (struct parse_type_arg *) a;
305
+ rbs_parser_t *parser = arg->parser;
306
+
307
+ if (parser->next_token.type == pEOF) {
308
+ return Qnil;
309
+ }
310
+
311
+ rbs_node_t *type;
312
+ rbs_parse_type(parser, &type, RTEST(arg->void_allowed), RTEST(arg->self_allowed), RTEST(arg->classish_allowed));
313
+
314
+ raise_error_if_any(parser, arg->buffer);
315
+
316
+ if (RB_TEST(arg->require_eof)) {
317
+ rbs_parser_advance(parser);
318
+ if (parser->current_token.type != pEOF) {
319
+ rbs_parser_set_error(parser, parser->current_token, true, "expected a token `%s`", rbs_token_type_str(pEOF));
320
+ raise_error(parser->error, arg->buffer);
321
+ }
322
+ }
323
+
324
+ return serialized_node_to_string(parser, type);
325
+ }
326
+
327
+ static VALUE rbsparser_parse_type_to_bytes(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE require_eof, VALUE void_allowed, VALUE self_allowed, VALUE classish_allowed) {
328
+ VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
329
+ StringValue(string);
330
+ rb_encoding *encoding = rb_enc_get(string);
331
+
332
+ rbs_parser_t *parser = alloc_parser_from_buffer(buffer, FIX2INT(start_pos), FIX2INT(end_pos));
333
+ declare_type_variables(parser, variables, buffer);
334
+ struct parse_type_arg arg = {
335
+ .buffer = buffer,
336
+ .encoding = encoding,
337
+ .parser = parser,
338
+ .require_eof = require_eof,
339
+ .void_allowed = void_allowed,
340
+ .self_allowed = self_allowed,
341
+ .classish_allowed = classish_allowed
342
+ };
343
+
344
+ VALUE result = rb_ensure(parse_type_to_bytes_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
345
+
346
+ RB_GC_GUARD(string);
347
+
348
+ return result;
349
+ }
350
+
351
+ static VALUE parse_method_type_to_bytes_try(VALUE a) {
352
+ struct parse_method_type_arg *arg = (struct parse_method_type_arg *) a;
353
+ rbs_parser_t *parser = arg->parser;
354
+
355
+ if (parser->next_token.type == pEOF) {
356
+ return Qnil;
357
+ }
358
+
359
+ rbs_method_type_t *method_type = NULL;
360
+ rbs_parse_method_type(parser, &method_type, RB_TEST(arg->require_eof), true);
361
+
362
+ raise_error_if_any(parser, arg->buffer);
363
+
364
+ return serialized_node_to_string(parser, (rbs_node_t *) method_type);
365
+ }
366
+
367
+ static VALUE rbsparser_parse_method_type_to_bytes(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE require_eof) {
368
+ VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
369
+ StringValue(string);
370
+ rb_encoding *encoding = rb_enc_get(string);
371
+
372
+ rbs_parser_t *parser = alloc_parser_from_buffer(buffer, FIX2INT(start_pos), FIX2INT(end_pos));
373
+ declare_type_variables(parser, variables, buffer);
374
+ struct parse_method_type_arg arg = {
375
+ .buffer = buffer,
376
+ .encoding = encoding,
377
+ .parser = parser,
378
+ .require_eof = require_eof
379
+ };
380
+
381
+ VALUE result = rb_ensure(parse_method_type_to_bytes_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
382
+
383
+ RB_GC_GUARD(string);
384
+
385
+ return result;
386
+ }
387
+
388
+ static VALUE parse_signature_to_bytes_try(VALUE a) {
389
+ struct parse_signature_arg *arg = (struct parse_signature_arg *) a;
390
+ rbs_parser_t *parser = arg->parser;
391
+
392
+ rbs_signature_t *signature = NULL;
393
+ rbs_parse_signature(parser, &signature);
394
+
395
+ raise_error_if_any(parser, arg->buffer);
396
+
397
+ return serialized_node_to_string(parser, (rbs_node_t *) signature);
398
+ }
399
+
400
+ static VALUE rbsparser_parse_signature_to_bytes(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
401
+ VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
402
+ StringValue(string);
403
+ rb_encoding *encoding = rb_enc_get(string);
404
+
405
+ rbs_parser_t *parser = alloc_parser_from_buffer(buffer, FIX2INT(start_pos), FIX2INT(end_pos));
406
+ struct parse_signature_arg arg = {
407
+ .buffer = buffer,
408
+ .encoding = encoding,
409
+ .parser = parser,
410
+ .require_eof = false
411
+ };
412
+
413
+ VALUE result = rb_ensure(parse_signature_to_bytes_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
414
+
415
+ RB_GC_GUARD(string);
416
+
417
+ return result;
418
+ }
419
+
288
420
  struct parse_type_params_arg {
289
421
  VALUE buffer;
290
422
  rb_encoding *encoding;
@@ -457,6 +589,9 @@ void rbs__init_parser(void) {
457
589
  rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 8);
458
590
  rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5);
459
591
  rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3);
592
+ rb_define_singleton_method(RBS_Parser, "_parse_type_to_bytes", rbsparser_parse_type_to_bytes, 8);
593
+ rb_define_singleton_method(RBS_Parser, "_parse_method_type_to_bytes", rbsparser_parse_method_type_to_bytes, 5);
594
+ rb_define_singleton_method(RBS_Parser, "_parse_signature_to_bytes", rbsparser_parse_signature_to_bytes, 3);
460
595
  rb_define_singleton_method(RBS_Parser, "_parse_type_params", rbsparser_parse_type_params, 4);
461
596
  rb_define_singleton_method(RBS_Parser, "_parse_inline_leading_annotation", rbsparser_parse_inline_leading_annotation, 4);
462
597
  rb_define_singleton_method(RBS_Parser, "_parse_inline_trailing_annotation", rbsparser_parse_inline_trailing_annotation, 4);