rbs 3.10.0 → 4.0.0.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -0,0 +1,60 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Declarations
5
+ type t = ClassDecl | ModuleDecl
6
+
7
+ class Base
8
+ attr_reader buffer: Buffer
9
+
10
+ include Helpers::ConstantHelper
11
+ include Helpers::LocationHelper
12
+
13
+ def initialize: (Buffer) -> void
14
+ end
15
+
16
+ class ClassDecl < Base
17
+ type member = t | Members::t
18
+
19
+ attr_reader class_name: TypeName
20
+
21
+ attr_reader node: Prism::ClassNode
22
+
23
+ attr_reader members: Array[member]
24
+
25
+ def initialize: (Buffer, TypeName, Prism::ClassNode) -> void
26
+
27
+ def each_decl: () { (t) -> void } -> void
28
+ | () -> Enumerator[t]
29
+
30
+ def super_class: () -> nil
31
+
32
+ def type_params: () -> Array[AST::TypeParam]
33
+
34
+ def location: () -> Location
35
+ end
36
+
37
+ class ModuleDecl < Base
38
+ type member = t | Members::t
39
+
40
+ attr_reader module_name: TypeName
41
+
42
+ attr_reader node: Prism::ModuleNode
43
+
44
+ attr_reader members: Array[member]
45
+
46
+ def initialize: (Buffer, TypeName, Prism::ModuleNode) -> void
47
+
48
+ def each_decl: () { (t) -> void } -> void
49
+ | () -> Enumerator[t]
50
+
51
+ def type_params: () -> Array[AST::TypeParam]
52
+
53
+ def location: () -> Location
54
+
55
+ def self_types: () -> Array[AST::Declarations::Module::Self]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Helpers
5
+ module ConstantHelper
6
+ def self?.constant_as_type_name: (Prism::node?) -> TypeName?
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Helpers
5
+ module LocationHelper : _WithBuffer
6
+ interface _WithBuffer
7
+ def buffer: () -> Buffer
8
+ end
9
+
10
+ def rbs_location: (Prism::Location) -> Location
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Members
5
+ class Base
6
+ attr_reader buffer: Buffer
7
+
8
+ def initialize: (Buffer) -> void
9
+
10
+ include Helpers::LocationHelper
11
+ end
12
+
13
+ type t = DefMember
14
+
15
+ class MethodTypeAnnotation
16
+ class DocStyle
17
+ attr_accessor return_type_annotation: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil
18
+
19
+ def initialize: () -> void
20
+
21
+ def map_type_name: () { (TypeName) -> TypeName } -> self
22
+
23
+ def method_type: () -> MethodType
24
+ end
25
+
26
+ type type_annotations = DocStyle | Array[Annotations::ColonMethodTypeAnnotation | Annotations::MethodTypesAnnotation] | nil
27
+
28
+ attr_reader type_annotations: type_annotations
29
+
30
+ def initialize: (type_annotations: type_annotations) -> void
31
+
32
+ def map_type_name: { (TypeName) -> TypeName } -> self
33
+
34
+ # Returns the method type annotations from the comment block
35
+ #
36
+ # Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation.
37
+ #
38
+ def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [
39
+ MethodTypeAnnotation,
40
+ Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError],
41
+ Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
42
+ ]
43
+
44
+ # Returns `true` if it doesn't have any annotation
45
+ def empty?: () -> bool
46
+
47
+ # Returns the method type overloads
48
+ #
49
+ def overloads: () -> Array[AST::Members::MethodDefinition::Overload]
50
+ end
51
+
52
+ class DefMember < Base
53
+ class Overload = AST::Members::MethodDefinition::Overload
54
+
55
+ attr_reader name: Symbol
56
+ attr_reader node: Prism::DefNode
57
+ attr_reader method_type: MethodTypeAnnotation
58
+
59
+ def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation) -> void
60
+
61
+ def location: () -> Location
62
+
63
+ def overloads: () -> Array[Overload]
64
+
65
+ def overloading?: () -> bool
66
+
67
+ def annotations: () -> Array[AST::Annotation]
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
data/sig/buffer.rbs CHANGED
@@ -6,21 +6,45 @@ module RBS
6
6
  type loc = [Integer, Integer]
7
7
 
8
8
  # Name to identify Buffer.
9
- attr_reader name: untyped
9
+ attr_reader name: Pathname
10
10
 
11
11
  # The content of the buffer.
12
12
  attr_reader content: String
13
13
 
14
- @lines: Array[String]
14
+ attr_reader parent: [Buffer, Array[Range[Integer]]]?
15
15
 
16
- @ranges: Array[Range[Integer]]
17
-
18
- def initialize: (name: untyped name, content: String content) -> void
16
+ def initialize: (name: Pathname name, content: String content) -> void
17
+ | (content: String content, parent: [Buffer, Array[Range[Integer]]] parent) -> void
19
18
 
19
+ # Array of lines of the content, without the EOL
20
+ #
21
+ # ```rb
22
+ # buffer = Buffer.new(name: name, content: "123\nabc")
23
+ # buffer.lines # => ["123", "abc"]
24
+ # ```
25
+ #
26
+ # If the input has EOL at the end of the file, the `lines` has an empty string at the end.
27
+ #
28
+ # ```rb
29
+ # buffer = Buffer.new(name: name, content: "123\nabc\n")
30
+ # buffer.lines # => ["123", "abc", ""]
31
+ # ```
32
+ #
20
33
  def lines: () -> Array[String]
21
34
 
35
+ @ranges: Array[Range[Integer]]?
36
+ # Array of ranges that stores the ranges of the each line, without the EOL
37
+ #
38
+ # ```rb
39
+ # buffer = Buffer.new(name: name, content: "123\nabc\n")
40
+ # buffer.ranges # => [0...3, 4...7, 8...8]
41
+ # ```
42
+ #
22
43
  def ranges: () -> Array[Range[Integer]]
23
44
 
45
+ # Returns the number of the lines
46
+ def line_count: () -> Integer
47
+
24
48
  # Translate position to location.
25
49
  def pos_to_loc: (Integer pos) -> loc
26
50
 
@@ -28,5 +52,39 @@ module RBS
28
52
  def loc_to_pos: (loc loc) -> Integer
29
53
 
30
54
  def last_position: () -> Integer
55
+
56
+ # Translate `Prism::Location` to `RBS::Location` attached to this buffer
57
+ #
58
+ # It assumes the `Prism::Location` has a source which is equivalent to `self`.
59
+ #
60
+ def rbs_location: (Prism::Location) -> Location
61
+ | (Prism::Location, Prism::Location) -> Location
62
+
63
+ # Construct a buffer from substrings of this buffer.
64
+ #
65
+ # The returned buffer contains lines from given ranges.
66
+ #
67
+ # ```rb
68
+ # buffer = Buffer.new(name: name, content: <<TEXT)
69
+ # 12345
70
+ # abcde
71
+ # ABCDE
72
+ # TEXT
73
+ #
74
+ # buffer.sub_buffer(lines: [0...1, 2...3]) # => Buffer with content = 1\n34
75
+ # buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline
76
+ # ```
77
+ #
78
+ %a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer
79
+
80
+ %a{pure} def parent_buffer: () -> Buffer?
81
+
82
+ %a{pure} def parent_position: (Integer) -> Integer?
83
+
84
+ %a{pure} def absolute_position: (Integer) -> Integer?
85
+
86
+ %a{pure} def top_buffer: () -> Buffer
87
+
88
+ %a{pure} def detach: () -> Buffer
31
89
  end
32
90
  end
data/sig/definition.rbs CHANGED
@@ -21,6 +21,7 @@ module RBS
21
21
 
22
22
  class Method
23
23
  type method_member = AST::Members::MethodDefinition | AST::Members::AttrReader | AST::Members::AttrAccessor | AST::Members::AttrWriter
24
+ | AST::Ruby::Members::DefMember
24
25
 
25
26
  class TypeDef
26
27
  attr_reader type: MethodType
@@ -103,7 +103,7 @@ module RBS
103
103
 
104
104
  def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
105
105
 
106
- def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
106
+ def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t | AST::Ruby::Declarations::t) -> Location[untyped, untyped]?
107
107
 
108
108
  def validate_variable: (Definition::Variable) -> void
109
109
 
@@ -0,0 +1,50 @@
1
+ module RBS
2
+ class Environment
3
+ # Represents a class entry in the environment
4
+ #
5
+ # ```rb
6
+ # entry = ClassEntry.new(TypeName.parse("::String"))
7
+ # entry << [nil, declaration]
8
+ # entry << [[nil, TypeName.parse("::Kernel")], declaration]
9
+ # ```
10
+ class ClassEntry
11
+ attr_reader name: TypeName
12
+
13
+ type declaration = AST::Declarations::Class | AST::Ruby::Declarations::ClassDecl
14
+
15
+ type context_decl = [Resolver::context, declaration]
16
+
17
+ attr_reader context_decls: Array[context_decl]
18
+
19
+ @primary_decl: declaration?
20
+
21
+ def initialize: (TypeName) -> void
22
+
23
+ def <<: (context_decl) -> self
24
+
25
+ def each_decl: { (declaration) -> void } -> void
26
+ | () -> Enumerator[declaration]
27
+
28
+ # Returns true if the entry doesn't have any declaration
29
+ #
30
+ def empty?: () -> bool
31
+
32
+ # Find the *primary* declaration of the class
33
+ #
34
+ # * Returns the first declaration with super class
35
+ # * Returns the first declaration if the declaration doesn't have super class
36
+ #
37
+ %a{pure} def primary_decl: () -> declaration
38
+
39
+ # Returns the generics declaration
40
+ #
41
+ def type_params: () -> Array[AST::TypeParam]
42
+
43
+ # Confirms if the type parameters in the declaration are compatible
44
+ #
45
+ # * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
46
+ #
47
+ def validate_type_params: () -> void
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ module RBS
2
+ class Environment
3
+ # Represents a class entry in the environment
4
+ #
5
+ # ```rb
6
+ # entry = ModuleEntry.new(TypeName.parse("::Kernel"))
7
+ # entry << [nil, declaration]
8
+ # entry << [[nil, TypeName.parse("::Object")], declaration]
9
+ # ```
10
+ #
11
+ class ModuleEntry
12
+ attr_reader name: TypeName
13
+
14
+ type declaration = AST::Declarations::Module | AST::Ruby::Declarations::ModuleDecl
15
+
16
+ type context_decl = [Resolver::context, declaration]
17
+
18
+ attr_reader context_decls: Array[context_decl]
19
+
20
+ def initialize: (TypeName) -> void
21
+
22
+ def <<: (context_decl) -> self
23
+
24
+ def each_decl: { (declaration) -> void } -> void
25
+ | () -> Enumerator[declaration]
26
+
27
+ # Returns true if the entry doesn't have any declaration
28
+ #
29
+ def empty?: () -> bool
30
+
31
+ # Returns the first declaration
32
+ #
33
+ # This method helps using the class with `ClassEntry` objects.
34
+ #
35
+ def primary_decl: () -> declaration
36
+
37
+ # Returns the generics declaration
38
+ #
39
+ def type_params: () -> Array[AST::TypeParam]
40
+
41
+ # Confirms if the type parameters in the declaration are compatible
42
+ #
43
+ # * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
44
+ #
45
+ def validate_type_params: () -> void
46
+
47
+ def self_types: () -> Array[AST::Declarations::Module::Self]
48
+ end
49
+ end
50
+ end
data/sig/environment.rbs CHANGED
@@ -2,75 +2,14 @@ module RBS
2
2
  class Environment
3
3
  type module_decl = AST::Declarations::Class | AST::Declarations::Module
4
4
 
5
- interface _ModuleOrClass
6
- def name: () -> TypeName
7
-
8
- def type_params: () -> Array[AST::TypeParam]
9
- end
10
-
11
- interface _NamedDecl
12
- def name: () -> TypeName
13
- end
14
-
15
- module ContextUtil
16
- def calculate_context: (Array[_NamedDecl]) -> Resolver::context
17
- end
18
-
19
- # Name of object, it's (multiple) declarations with the outer module declarations
20
- #
21
- class MultiEntry[M < _ModuleOrClass]
22
- class D[M < _ModuleOrClass]
23
- attr_reader decl: M
24
- attr_reader outer: Array[module_decl]
25
-
26
- def initialize: (decl: M, outer: Array[module_decl]) -> void
27
-
28
- include ContextUtil
29
-
30
- @context: Resolver::context
31
-
32
- def context: () -> Resolver::context
33
- end
34
-
35
- attr_reader name: TypeName
36
- attr_reader decls: Array[D[M]]
37
-
38
- @primary: D[M]?
39
-
40
- def initialize: (name: TypeName) -> void
41
-
42
- def insert: (decl: M, outer: Array[module_decl]) -> void
43
-
44
- def validate_type_params: () -> void
45
-
46
- def compatible_params?: (Array[AST::TypeParam], Array[AST::TypeParam]) -> boolish
47
-
48
- def type_params: () -> Array[AST::TypeParam]
49
-
50
- def primary: () -> D[M]
51
- end
52
-
53
- class ModuleEntry < MultiEntry[AST::Declarations::Module]
54
- def self_types: () -> Array[AST::Declarations::Module::Self]
55
- end
56
-
57
- class ClassEntry < MultiEntry[AST::Declarations::Class]
58
- end
59
-
60
5
  # Name of object, it's (single) declaration, and the outer module declarations
61
6
  #
62
7
  class SingleEntry[N, D]
63
8
  attr_reader name: N
64
9
  attr_reader decl: D
65
- attr_reader outer: Array[module_decl]
66
-
67
- def initialize: (name: N, decl: D, outer: Array[module_decl]) -> void
68
-
69
- include ContextUtil
70
-
71
- @context: Resolver::context
10
+ attr_reader context: Resolver::context
72
11
 
73
- def context: () -> Resolver::context
12
+ def initialize: (name: N, decl: D, context: Resolver::context) -> void
74
13
  end
75
14
 
76
15
  class ModuleAliasEntry < SingleEntry[TypeName, AST::Declarations::ModuleAlias]
@@ -91,8 +30,9 @@ module RBS
91
30
  class GlobalEntry < SingleEntry[Symbol, AST::Declarations::Global]
92
31
  end
93
32
 
94
- # Top level declarations
95
- attr_reader declarations: Array[AST::Declarations::t]
33
+ # Array of source objects loaded in the environment
34
+ #
35
+ attr_reader sources: Array[Source::t]
96
36
 
97
37
  # Class declarations
98
38
  attr_reader class_decls: Hash[TypeName, ModuleEntry | ClassEntry]
@@ -111,10 +51,6 @@ module RBS
111
51
  # Global declarations
112
52
  attr_reader global_decls: Hash[Symbol, GlobalEntry]
113
53
 
114
- # A hash from Buffer to it's contents
115
- #
116
- attr_reader signatures: Hash[Buffer, [Array[AST::Directives::t], Array[AST::Declarations::t]]]
117
-
118
54
  def initialize: () -> void
119
55
 
120
56
  def initialize_copy: (Environment) -> void
@@ -123,15 +59,21 @@ module RBS
123
59
  #
124
60
  def self.from_loader: (EnvironmentLoader) -> Environment
125
61
 
126
- def add_signature: (buffer: Buffer, directives: Array[AST::Directives::t], decls: Array[AST::Declarations::t]) -> void
62
+ def add_source: (Source::t) -> void
63
+
64
+ def each_rbs_source: () { (Source::RBS) -> void } -> void
65
+ | () -> Enumerator[Source::RBS]
127
66
 
128
- # Insert a toplevel declaration into the environment
67
+ def each_ruby_source: () { (Source::Ruby) -> void } -> void
68
+ | () -> Enumerator[Source::Ruby]
69
+
70
+ # Insert a declaration into the environment
129
71
  #
130
- def <<: (AST::Declarations::t decl) -> self
72
+ private def insert_rbs_decl: (AST::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
131
73
 
132
74
  # Insert a declaration into the environment
133
75
  #
134
- private def insert_decl: (AST::Declarations::t, outer: Array[module_decl], namespace: Namespace) -> void
76
+ private def insert_ruby_decl: (AST::Ruby::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
135
77
 
136
78
  # Resolve all type names in the environment to absolute type names.
137
79
  # Relative type name will be left if absolute type name cannot be found.
@@ -190,58 +132,22 @@ module RBS
190
132
  # Returns true if the type name is a class alias
191
133
  def class_alias?: (TypeName) -> bool
192
134
 
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)
135
+ def class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | nil)
204
136
 
205
137
  # Returns ClassEntry if the class definition is found, normalized in case of alias
206
138
  #
207
- %a{deprecated: Use `class_entry(type_name, normalized: true)` instead. }
208
139
  def normalized_class_entry: (TypeName) -> ClassEntry?
209
140
 
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)
141
+ def module_entry: (TypeName) -> (ModuleEntry | ModuleAliasEntry | nil)
221
142
 
222
143
  # Returns ModuleEntry if the module definition is found, normalized in case of alias
223
144
  #
224
- %a{deprecated: Use `module_entry(type_name, normalized: true)` instead. }
225
145
  def normalized_module_entry: (TypeName) -> ModuleEntry?
226
146
 
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)
147
+ def constant_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
236
148
 
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)
149
+ def module_class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
243
150
 
244
- %a{deprecated: Use `module_class_entry(type_name, normalized: true)` instead. }
245
151
  def normalized_module_class_entry: (TypeName) -> (ClassEntry | ModuleEntry | nil)
246
152
 
247
153
  @normalize_module_name_cache: Hash[TypeName, TypeName | false | nil]
@@ -252,39 +158,26 @@ module RBS
252
158
  # * Returns `nil` if the rhs name cannot be found
253
159
  # * Returns `false` if the name is cyclic
254
160
  #
255
- # Note that this method assumes the declarations have resolved type names.
256
- #
257
161
  def normalize_module_name?: (TypeName) -> (TypeName | nil | false)
258
162
 
259
- # Returns the original module name that is defined with `module`/`class` declaration
163
+ # Returns the original module name that is defined with `module` declaration
260
164
  #
261
- # * Raises an error if given type name is not module/class
165
+ # * Raises an error if given type name is not module
262
166
  # * Calls `#absolute!` for relative module names
263
167
  # * Returns the name itself if the name cannot be normalized to a class/module
264
168
  #
265
- # Note that this method assumes the declarations have resolved type names.
266
- #
267
169
  def normalize_module_name: (TypeName) -> TypeName
268
170
 
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
-
274
171
  # Returns a normalized module/class name or a type name with a normalized namespace
275
172
  #
276
173
  # * Calls `#absolute!` for relative module names
277
174
  # * Returns `nil` if the typename cannot be found
278
175
  # * Returns `false` if the name is cyclic
279
176
  #
280
- # Note that this method assumes the declarations have resolved type names.
281
- #
282
177
  def normalize_type_name?: (TypeName) -> (TypeName | nil | false)
283
178
 
284
179
  # Normalize the type name or raises an error
285
180
  #
286
- # Note that this method assumes the declarations have resolved type names.
287
- #
288
181
  def normalize_type_name!: (TypeName) -> TypeName
289
182
 
290
183
  # Returns a normalized module/class name or a type name with a normalized namespace
@@ -292,8 +185,6 @@ module RBS
292
185
  # * Calls `#absolute!` for relative module names
293
186
  # * Returns the typename itself if the name cannot be normalized
294
187
  #
295
- # Note that this method assumes the declarations have resolved type names.
296
- #
297
188
  def normalize_type_name: (TypeName) -> TypeName
298
189
 
299
190
  # Returns `true` if given type name is normalized
@@ -315,7 +206,7 @@ module RBS
315
206
 
316
207
  def append_context: (Resolver::context, module_decl) -> Resolver::context
317
208
 
318
- def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, outer: Array[module_decl], prefix: Namespace) -> AST::Declarations::t
209
+ def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, context: Resolver::context, prefix: Namespace) -> AST::Declarations::t
319
210
 
320
211
  def resolve_member: (Resolver::TypeNameResolver, UseMap map, AST::Members::t, context: Resolver::context) -> AST::Members::t
321
212
 
@@ -323,8 +214,12 @@ module RBS
323
214
 
324
215
  def resolve_type_params: (Resolver::TypeNameResolver resolver, UseMap map, Array[AST::TypeParam], context: Resolver::context) -> Array[AST::TypeParam]
325
216
 
326
- def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t
217
+ def resolve_ruby_decl: (Resolver::TypeNameResolver, AST::Ruby::Declarations::t, context: Resolver::context, prefix: Namespace) -> AST::Ruby::Declarations::t
218
+
219
+ def resolve_ruby_member: (Resolver::TypeNameResolver, AST::Ruby::Members::t, context: Resolver::context) -> AST::Ruby::Members::t
220
+
221
+ def absolute_type: (Resolver::TypeNameResolver, UseMap? map, Types::t, context: Resolver::context) -> Types::t
327
222
 
328
- def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName
223
+ def absolute_type_name: (Resolver::TypeNameResolver, UseMap? map, TypeName, context: Resolver::context) -> TypeName
329
224
  end
330
225
  end
data/sig/errors.rbs CHANGED
@@ -226,28 +226,35 @@ module RBS
226
226
  class InvalidOverloadMethodError < DefinitionError
227
227
  include DetailedMessageable
228
228
 
229
+ type member = AST::Members::MethodDefinition | AST::Ruby::Members::DefMember
230
+
229
231
  attr_reader type_name: TypeName
230
232
  attr_reader method_name: Symbol
231
233
  attr_reader kind: :instance | :singleton
232
- attr_reader members: Array[AST::Members::MethodDefinition]
234
+ attr_reader members: Array[member]
233
235
 
234
- def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[AST::Members::MethodDefinition]) -> void
236
+ def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[member]) -> void
235
237
 
236
238
  def location: () -> AST::Members::MethodDefinition::loc?
237
239
  end
238
240
 
239
241
  class GenericParameterMismatchError < LoadingError
242
+ type decl = AST::Declarations::Class | AST::Declarations::Module
243
+ | AST::Ruby::Declarations::ClassDecl | AST::Ruby::Declarations::ModuleDecl
244
+
240
245
  attr_reader name: TypeName
241
- attr_reader decl: AST::Declarations::Class | AST::Declarations::Module
246
+ attr_reader decl: decl
242
247
 
243
- def initialize: (name: TypeName, decl: AST::Declarations::Class | AST::Declarations::Module) -> void
248
+ def initialize: (name: TypeName, decl: decl, ?location: Location) -> void
244
249
  end
245
250
 
246
251
  class DuplicatedDeclarationError < LoadingError
252
+ type declaration = AST::Declarations::t | AST::Ruby::Declarations::t
253
+
247
254
  attr_reader name: TypeName | Symbol
248
- attr_reader decls: Array[AST::Declarations::t]
255
+ attr_reader decls: Array[declaration]
249
256
 
250
- def initialize: (TypeName | Symbol, *AST::Declarations::t) -> void
257
+ def initialize: (TypeName | Symbol, *declaration) -> void
251
258
  end
252
259
 
253
260
  class InvalidVarianceAnnotationError < DefinitionError