rbs 3.9.4 → 3.10.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/ruby.yml +33 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/CHANGELOG.md +81 -0
  11. data/README.md +38 -1
  12. data/Rakefile +152 -23
  13. data/config.yml +190 -62
  14. data/core/array.rbs +96 -46
  15. data/core/comparable.rbs +13 -6
  16. data/core/complex.rbs +40 -25
  17. data/core/dir.rbs +4 -4
  18. data/core/encoding.rbs +6 -9
  19. data/core/enumerable.rbs +90 -3
  20. data/core/enumerator.rbs +43 -1
  21. data/core/errno.rbs +8 -0
  22. data/core/errors.rbs +28 -1
  23. data/core/exception.rbs +2 -2
  24. data/core/fiber.rbs +29 -20
  25. data/core/file.rbs +49 -19
  26. data/core/file_test.rbs +1 -1
  27. data/core/float.rbs +224 -33
  28. data/core/gc.rbs +417 -281
  29. data/core/hash.rbs +1023 -727
  30. data/core/integer.rbs +104 -63
  31. data/core/io/buffer.rbs +21 -10
  32. data/core/io/wait.rbs +11 -33
  33. data/core/io.rbs +14 -12
  34. data/core/kernel.rbs +61 -51
  35. data/core/marshal.rbs +1 -1
  36. data/core/match_data.rbs +1 -1
  37. data/core/math.rbs +42 -3
  38. data/core/method.rbs +63 -25
  39. data/core/module.rbs +101 -23
  40. data/core/nil_class.rbs +3 -3
  41. data/core/numeric.rbs +25 -17
  42. data/core/object.rbs +3 -3
  43. data/core/object_space.rbs +21 -15
  44. data/core/pathname.rbs +1272 -0
  45. data/core/proc.rbs +30 -24
  46. data/core/process.rbs +2 -2
  47. data/core/ractor.rbs +361 -509
  48. data/core/range.rbs +7 -8
  49. data/core/rational.rbs +56 -34
  50. data/core/rbs/unnamed/argf.rbs +2 -2
  51. data/core/rbs/unnamed/env_class.rbs +1 -1
  52. data/core/rbs/unnamed/random.rbs +4 -2
  53. data/core/regexp.rbs +25 -20
  54. data/core/ruby.rbs +53 -0
  55. data/core/ruby_vm.rbs +6 -4
  56. data/core/rubygems/errors.rbs +3 -70
  57. data/core/rubygems/rubygems.rbs +11 -79
  58. data/core/rubygems/version.rbs +2 -3
  59. data/core/set.rbs +488 -359
  60. data/core/signal.rbs +24 -14
  61. data/core/string.rbs +3164 -1235
  62. data/core/struct.rbs +1 -1
  63. data/core/symbol.rbs +17 -11
  64. data/core/thread.rbs +95 -33
  65. data/core/time.rbs +35 -9
  66. data/core/trace_point.rbs +7 -4
  67. data/core/unbound_method.rbs +14 -6
  68. data/docs/aliases.md +79 -0
  69. data/docs/collection.md +2 -2
  70. data/docs/encoding.md +56 -0
  71. data/docs/gem.md +0 -1
  72. data/docs/sigs.md +3 -3
  73. data/ext/rbs_extension/ast_translation.c +1016 -0
  74. data/ext/rbs_extension/ast_translation.h +37 -0
  75. data/ext/rbs_extension/class_constants.c +155 -0
  76. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  77. data/ext/rbs_extension/compat.h +10 -0
  78. data/ext/rbs_extension/extconf.rb +25 -1
  79. data/ext/rbs_extension/legacy_location.c +317 -0
  80. data/ext/rbs_extension/legacy_location.h +45 -0
  81. data/ext/rbs_extension/main.c +367 -23
  82. data/ext/rbs_extension/rbs_extension.h +6 -21
  83. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  84. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  85. data/include/rbs/ast.h +687 -0
  86. data/include/rbs/defines.h +86 -0
  87. data/include/rbs/lexer.h +199 -0
  88. data/include/rbs/location.h +59 -0
  89. data/include/rbs/parser.h +135 -0
  90. data/include/rbs/string.h +47 -0
  91. data/include/rbs/util/rbs_allocator.h +59 -0
  92. data/include/rbs/util/rbs_assert.h +20 -0
  93. data/include/rbs/util/rbs_buffer.h +83 -0
  94. data/include/rbs/util/rbs_constant_pool.h +6 -67
  95. data/include/rbs/util/rbs_encoding.h +282 -0
  96. data/include/rbs/util/rbs_unescape.h +24 -0
  97. data/include/rbs.h +1 -2
  98. data/lib/rbs/annotate/formatter.rb +3 -13
  99. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  100. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  101. data/lib/rbs/cli/validate.rb +2 -2
  102. data/lib/rbs/cli.rb +1 -1
  103. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  104. data/lib/rbs/collection.rb +1 -0
  105. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  106. data/lib/rbs/environment.rb +64 -59
  107. data/lib/rbs/environment_loader.rb +0 -6
  108. data/lib/rbs/errors.rb +1 -1
  109. data/lib/rbs/parser_aux.rb +5 -0
  110. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  111. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  112. data/lib/rbs/subtractor.rb +3 -1
  113. data/lib/rbs/test/type_check.rb +14 -0
  114. data/lib/rbs/types.rb +3 -1
  115. data/lib/rbs/version.rb +1 -1
  116. data/lib/rbs.rb +1 -1
  117. data/lib/rdoc/discover.rb +1 -1
  118. data/lib/rdoc_plugin/parser.rb +3 -3
  119. data/sig/annotate/formatter.rbs +2 -2
  120. data/sig/annotate/rdoc_annotater.rbs +1 -1
  121. data/sig/environment.rbs +57 -6
  122. data/sig/manifest.yaml +0 -1
  123. data/sig/parser.rbs +20 -0
  124. data/sig/resolver/type_name_resolver.rbs +38 -7
  125. data/sig/types.rbs +4 -1
  126. data/src/ast.c +1256 -0
  127. data/src/lexer.c +2956 -0
  128. data/src/lexer.re +147 -0
  129. data/src/lexstate.c +205 -0
  130. data/src/location.c +71 -0
  131. data/src/parser.c +3507 -0
  132. data/src/string.c +41 -0
  133. data/src/util/rbs_allocator.c +165 -0
  134. data/src/util/rbs_assert.c +19 -0
  135. data/src/util/rbs_buffer.c +54 -0
  136. data/src/util/rbs_constant_pool.c +18 -88
  137. data/src/util/rbs_encoding.c +21308 -0
  138. data/src/util/rbs_unescape.c +167 -0
  139. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  140. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  141. data/stdlib/cgi/0/core.rbs +9 -393
  142. data/stdlib/cgi/0/manifest.yaml +1 -0
  143. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  144. data/stdlib/coverage/0/coverage.rbs +3 -1
  145. data/stdlib/date/0/date.rbs +67 -59
  146. data/stdlib/date/0/date_time.rbs +1 -1
  147. data/stdlib/delegate/0/delegator.rbs +10 -7
  148. data/stdlib/erb/0/erb.rbs +737 -347
  149. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  150. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  151. data/stdlib/json/0/json.rbs +68 -48
  152. data/stdlib/net-http/0/net-http.rbs +3 -0
  153. data/stdlib/objspace/0/objspace.rbs +9 -4
  154. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  155. data/stdlib/openssl/0/openssl.rbs +331 -228
  156. data/stdlib/optparse/0/optparse.rbs +3 -3
  157. data/stdlib/pathname/0/pathname.rbs +9 -1379
  158. data/stdlib/psych/0/psych.rbs +3 -3
  159. data/stdlib/rdoc/0/code_object.rbs +2 -2
  160. data/stdlib/rdoc/0/comment.rbs +2 -0
  161. data/stdlib/rdoc/0/options.rbs +76 -0
  162. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  163. data/stdlib/rdoc/0/store.rbs +1 -1
  164. data/stdlib/resolv/0/resolv.rbs +25 -68
  165. data/stdlib/ripper/0/ripper.rbs +5 -2
  166. data/stdlib/singleton/0/singleton.rbs +3 -0
  167. data/stdlib/socket/0/socket.rbs +13 -1
  168. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  169. data/stdlib/stringio/0/stringio.rbs +1176 -85
  170. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  171. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  172. data/stdlib/time/0/time.rbs +1 -1
  173. data/stdlib/timeout/0/timeout.rbs +63 -7
  174. data/stdlib/tsort/0/cyclic.rbs +3 -0
  175. data/stdlib/uri/0/common.rbs +11 -2
  176. data/stdlib/uri/0/file.rbs +1 -1
  177. data/stdlib/uri/0/generic.rbs +17 -16
  178. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  179. data/stdlib/zlib/0/zstream.rbs +1 -0
  180. metadata +44 -18
  181. data/ext/rbs_extension/lexer.c +0 -2728
  182. data/ext/rbs_extension/lexer.h +0 -179
  183. data/ext/rbs_extension/lexer.re +0 -147
  184. data/ext/rbs_extension/lexstate.c +0 -175
  185. data/ext/rbs_extension/location.c +0 -325
  186. data/ext/rbs_extension/location.h +0 -85
  187. data/ext/rbs_extension/parser.c +0 -2982
  188. data/ext/rbs_extension/parser.h +0 -18
  189. data/ext/rbs_extension/parserstate.c +0 -411
  190. data/ext/rbs_extension/parserstate.h +0 -163
  191. data/ext/rbs_extension/unescape.c +0 -32
  192. data/include/rbs/ruby_objs.h +0 -72
  193. data/src/constants.c +0 -153
  194. data/src/ruby_objs.c +0 -799
data/sig/environment.rbs CHANGED
@@ -190,22 +190,58 @@ module RBS
190
190
  # Returns true if the type name is a class alias
191
191
  def class_alias?: (TypeName) -> bool
192
192
 
193
- def class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | nil)
193
+ # Returns the entry for the class name
194
+ #
195
+ # Returns `nil` when:
196
+ #
197
+ # * The type name is not found
198
+ # * The type name is not a class
199
+ #
200
+ # It normalizes when `normalized: true` is given -- returns `ClassEntry` or `nil`.
201
+ #
202
+ def class_entry: (TypeName, normalized: true) -> ClassEntry?
203
+ | (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | nil)
194
204
 
195
205
  # Returns ClassEntry if the class definition is found, normalized in case of alias
196
206
  #
207
+ %a{deprecated: Use `class_entry(type_name, normalized: true)` instead. }
197
208
  def normalized_class_entry: (TypeName) -> ClassEntry?
198
209
 
199
- def module_entry: (TypeName) -> (ModuleEntry | ModuleAliasEntry | nil)
210
+ # Returns the entry for the module name
211
+ #
212
+ # Returns `nil` when:
213
+ #
214
+ # * The type name is not found
215
+ # * The type name is not a module
216
+ #
217
+ # It normalizes when `normalized: true` is given -- returns `ModuleEntry` or `nil`.
218
+ #
219
+ def module_entry: (TypeName, normalized: true) -> ModuleEntry?
220
+ | (TypeName, ?normalized: bool) -> (ModuleEntry | ModuleAliasEntry | nil)
200
221
 
201
222
  # Returns ModuleEntry if the module definition is found, normalized in case of alias
202
223
  #
224
+ %a{deprecated: Use `module_entry(type_name, normalized: true)` instead. }
203
225
  def normalized_module_entry: (TypeName) -> ModuleEntry?
204
226
 
205
- def constant_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
227
+ # Returns the entry for the type name
228
+ #
229
+ # The entry is one of ClassEntry, ModuleEntry, ConstantEntry, ClassAliasEntry, or ModuleAliasEntry.
230
+ # When `normalized: true` is given, it returns normalized entry -- one of ClassEntry, ModuleEntry, or ConstantEntry.
231
+ #
232
+ # Returns `nil` if not found.
233
+ #
234
+ def constant_entry: (TypeName, normalized: true) -> (ClassEntry | ModuleEntry | ConstantEntry | nil)
235
+ | (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
206
236
 
207
- def module_class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
237
+ # Returns ClassEntry or ModuleEntry if the class/module definition is found
238
+ #
239
+ # Normalizes when `normalized: true` is given.
240
+ #
241
+ def module_class_entry: (TypeName, normalized: true) -> (ClassEntry | ModuleEntry | nil)
242
+ | (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
208
243
 
244
+ %a{deprecated: Use `module_class_entry(type_name, normalized: true)` instead. }
209
245
  def normalized_module_class_entry: (TypeName) -> (ClassEntry | ModuleEntry | nil)
210
246
 
211
247
  @normalize_module_name_cache: Hash[TypeName, TypeName | false | nil]
@@ -216,26 +252,39 @@ module RBS
216
252
  # * Returns `nil` if the rhs name cannot be found
217
253
  # * Returns `false` if the name is cyclic
218
254
  #
255
+ # Note that this method assumes the declarations have resolved type names.
256
+ #
219
257
  def normalize_module_name?: (TypeName) -> (TypeName | nil | false)
220
258
 
221
- # Returns the original module name that is defined with `module` declaration
259
+ # Returns the original module name that is defined with `module`/`class` declaration
222
260
  #
223
- # * Raises an error if given type name is not module
261
+ # * Raises an error if given type name is not module/class
224
262
  # * Calls `#absolute!` for relative module names
225
263
  # * Returns the name itself if the name cannot be normalized to a class/module
226
264
  #
265
+ # Note that this method assumes the declarations have resolved type names.
266
+ #
227
267
  def normalize_module_name: (TypeName) -> TypeName
228
268
 
269
+ # Returns the original module name that is defined with `module`/`class` declaration
270
+ #
271
+ # * Raises an error if given type name is not a module/class
272
+ def normalize_module_name!: (TypeName) -> TypeName
273
+
229
274
  # Returns a normalized module/class name or a type name with a normalized namespace
230
275
  #
231
276
  # * Calls `#absolute!` for relative module names
232
277
  # * Returns `nil` if the typename cannot be found
233
278
  # * Returns `false` if the name is cyclic
234
279
  #
280
+ # Note that this method assumes the declarations have resolved type names.
281
+ #
235
282
  def normalize_type_name?: (TypeName) -> (TypeName | nil | false)
236
283
 
237
284
  # Normalize the type name or raises an error
238
285
  #
286
+ # Note that this method assumes the declarations have resolved type names.
287
+ #
239
288
  def normalize_type_name!: (TypeName) -> TypeName
240
289
 
241
290
  # Returns a normalized module/class name or a type name with a normalized namespace
@@ -243,6 +292,8 @@ module RBS
243
292
  # * Calls `#absolute!` for relative module names
244
293
  # * Returns the typename itself if the name cannot be normalized
245
294
  #
295
+ # Note that this method assumes the declarations have resolved type names.
296
+ #
246
297
  def normalize_type_name: (TypeName) -> TypeName
247
298
 
248
299
  # Returns `true` if given type name is normalized
data/sig/manifest.yaml CHANGED
@@ -1,6 +1,5 @@
1
1
  dependencies:
2
2
  - name: logger
3
- - name: pathname
4
3
  - name: json
5
4
  - name: optparse
6
5
  - name: tsort
data/sig/parser.rbs CHANGED
@@ -68,6 +68,24 @@ module RBS
68
68
  #
69
69
  def self.parse_signature: (Buffer | String) -> [Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]]
70
70
 
71
+ # Parse a list of type parameters and return it
72
+ #
73
+ # ```ruby
74
+ # RBS::Parser.parse_type_params("") # => nil
75
+ # RBS::Parser.parse_type_params("[U, V]") # => `[:U, :V]`
76
+ # RBS::Parser.parse_type_params("[in U, V < Integer]") # => `[:U, :V]`
77
+ # ```
78
+ #
79
+ # When `module_type_params` is `false`, an error is raised if `unchecked`, `in` or `out` are used.
80
+ #
81
+ # ```ruby
82
+ # RBS::Parser.parse_type_params("[unchecked U]", module_type_params: false) # => Raises an error
83
+ # RBS::Parser.parse_type_params("[out U]", module_type_params: false) # => Raises an error
84
+ # RBS::Parser.parse_type_params("[in U]", module_type_params: false) # => Raises an error
85
+ # ```
86
+ #
87
+ def self.parse_type_params: (Buffer | String, ?module_type_params: bool) -> Array[AST::TypeParam]
88
+
71
89
  # Returns the magic comment from the buffer
72
90
  #
73
91
  def self.magic_comment: (Buffer) -> AST::Directives::ResolveTypeNames?
@@ -92,6 +110,8 @@ module RBS
92
110
 
93
111
  def self._parse_signature: (Buffer, Integer start_pos, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
94
112
 
113
+ def self._parse_type_params: (Buffer, Integer start_pos, Integer end_pos, bool module_type_params) -> Array[AST::TypeParam]
114
+
95
115
  def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
96
116
 
97
117
  class LocatedValue
@@ -8,28 +8,59 @@ module RBS
8
8
  class TypeNameResolver
9
9
  type query = [TypeName, context]
10
10
 
11
- def initialize: (Environment) -> void
11
+ def initialize: (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> void
12
12
 
13
- # Translates given type name to absolute type name.
13
+ def self.new: %a{deprecated: Use `build` to build TypeNameResolver from Environment} (Environment) -> instance
14
+ | (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> instance
15
+
16
+ def self.build: (Environment) -> instance
17
+
18
+ # Translates given type name to absolute type name
19
+ #
14
20
  # Returns `nil` if cannot find associated type name.
21
+ # Module names in the type name are normalized.
15
22
  #
16
23
  def resolve: (TypeName, context: context) -> TypeName?
17
24
 
18
- private
25
+ # Translates given type name to absolute type name
26
+ #
27
+ # Returns `false` if a cycle is detected while resolving aliases.
28
+ # Returns `nil` if the type name cannot be resolved.
29
+ #
30
+ def resolve_namespace: (TypeName, context: context) -> (TypeName | false | nil)
19
31
 
20
- attr_reader env: Environment
32
+ private
21
33
 
22
34
  attr_reader all_names: Set[TypeName]
23
35
 
36
+ attr_reader aliases: Hash[TypeName, [TypeName, context]]
37
+
24
38
  attr_reader cache: Hash[query, TypeName?]
25
39
 
26
- def has_name?: (TypeName) -> TypeName?
40
+ # Returns the type name if it exists in `all_names` (normalized)
41
+ #
42
+ def has_type_name?: (TypeName) -> TypeName?
43
+
44
+ # Returns the type name if it is an alias (not normalized)
45
+ #
46
+ def aliased_name?: (TypeName) -> TypeName?
27
47
 
28
48
  def try_cache: (query) { () -> TypeName? } -> TypeName?
29
49
 
30
- def resolve_in: (Symbol, context) -> TypeName?
50
+ # Translates the head module name in the context and returns an absolute type name
51
+ #
52
+ # Returns `nil` if cannot find associated type name.
53
+ # The returned namespace may be an alias
54
+ #
55
+ def resolve_head_namespace: (Symbol, context) -> TypeName?
56
+
57
+ # Resolves the type name in the given context
58
+ #
59
+ def resolve_type_name: (Symbol, context) -> TypeName?
60
+
61
+ def resolve_namespace0: (TypeName, context, Set[TypeName]) -> (TypeName | false | nil)
31
62
 
32
- def partition: (TypeName) -> [Symbol, TypeName?]
63
+ def normalize_namespace: (TypeName, TypeName rhs, context, Set[TypeName]) -> (TypeName | false | nil)
33
64
  end
34
65
  end
35
66
  end
data/sig/types.rbs CHANGED
@@ -518,7 +518,10 @@ module RBS
518
518
 
519
519
  attr_reader self_type: t?
520
520
 
521
- def initialize: (type: function, ?self_type: t?, required: boolish) -> void
521
+ type loc = Location[bot, bot]
522
+ attr_reader location: loc?
523
+
524
+ def initialize: (?location: loc?, type: function, ?self_type: t?, required: boolish) -> void
522
525
 
523
526
  def ==: (untyped other) -> bool
524
527