rbs 1.0.0.pre → 1.0.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +10 -4
  3. data/CHANGELOG.md +41 -6
  4. data/Gemfile +7 -2
  5. data/README.md +1 -1
  6. data/Rakefile +11 -4
  7. data/Steepfile +2 -1
  8. data/bin/annotate-with-rdoc +0 -4
  9. data/bin/test_runner.rb +4 -5
  10. data/core/encoding.rbs +1 -1
  11. data/core/file.rbs +4 -0
  12. data/core/io.rbs +81 -5
  13. data/core/kernel.rbs +56 -56
  14. data/core/module.rbs +43 -2
  15. data/core/unbound_method.rbs +16 -0
  16. data/docs/CONTRIBUTING.md +2 -2
  17. data/docs/stdlib.md +50 -12
  18. data/docs/syntax.md +0 -17
  19. data/goodcheck.yml +3 -3
  20. data/lib/rbs/ast/declarations.rb +0 -47
  21. data/lib/rbs/definition_builder.rb +102 -64
  22. data/lib/rbs/definition_builder/ancestor_builder.rb +52 -3
  23. data/lib/rbs/environment.rb +1 -7
  24. data/lib/rbs/environment_loader.rb +7 -3
  25. data/lib/rbs/errors.rb +22 -57
  26. data/lib/rbs/parser.rb +1003 -1027
  27. data/lib/rbs/parser.y +12 -21
  28. data/lib/rbs/prototype/rb.rb +18 -4
  29. data/lib/rbs/prototype/runtime.rb +30 -14
  30. data/lib/rbs/test/hook.rb +7 -6
  31. data/lib/rbs/test/setup_helper.rb +0 -1
  32. data/lib/rbs/types.rb +6 -2
  33. data/lib/rbs/version.rb +1 -1
  34. data/lib/rbs/writer.rb +4 -3
  35. data/rbs.gemspec +1 -0
  36. data/sig/ancestor_builder.rbs +98 -0
  37. data/sig/declarations.rbs +4 -16
  38. data/sig/definition_builder.rbs +17 -71
  39. data/sig/errors.rbs +141 -2
  40. data/sig/method_builder.rbs +71 -0
  41. data/sig/substitution.rbs +3 -0
  42. data/sig/types.rbs +1 -15
  43. data/stdlib/csv/0/csv.rbs +3 -0
  44. data/stdlib/fileutils/0/fileutils.rbs +585 -0
  45. data/stdlib/pathname/0/pathname.rbs +2 -2
  46. data/stdlib/prettyprint/0/prettyprint.rbs +366 -0
  47. data/stdlib/prime/0/prime.rbs +6 -0
  48. data/stdlib/securerandom/0/securerandom.rbs +2 -0
  49. data/stdlib/uri/0/common.rbs +1 -1
  50. metadata +10 -7
  51. data/core/data.rbs +0 -5
@@ -1,100 +1,46 @@
1
1
  module RBS
2
2
  class DefinitionBuilder
3
- class OneAncestors
4
- attr_reader type_name: TypeName
5
- attr_reader params: Array[Symbol]?
6
- attr_reader super_class: Definition::Ancestor::t?
7
- attr_reader self_types: Array[Definition::Ancestor::Instance]?
8
- attr_reader included_modules: Array[Definition::Ancestor::Instance]?
9
- attr_reader prepended_modules: Array[Definition::Ancestor::Instance]?
10
- attr_reader extended_modules: Array[Definition::Ancestor::Instance]?
11
-
12
- def initialize: (type_name: TypeName,
13
- params: Array[Symbol]?,
14
- super_class: Definition::Ancestor::t?,
15
- self_types: Array[Definition::Ancestor::Instance]?,
16
- included_modules: Array[Definition::Ancestor::Instance]?,
17
- prepended_modules: Array[Definition::Ancestor::Instance]?,
18
- extended_modules: Array[Definition::Ancestor::Instance]?) -> void
19
-
20
- def each_ancestor: { (Definition::Ancestor::t) -> void } -> void
21
- | -> Enumerator[Definition::Ancestor::t, void]
22
-
23
- def self.class_instance: (type_name: TypeName, params: Array[Symbol], super_class: Definition::Ancestor::t?) -> instance
24
-
25
- def self.singleton: (type_name: TypeName, super_class: Definition::Ancestor::t?) -> instance
26
-
27
- def self.module_instance: (type_name: TypeName, params: Array[Symbol]) -> instance
28
- end
29
-
30
3
  attr_reader env: Environment
31
4
  attr_reader type_name_resolver: TypeNameResolver
5
+ attr_reader ancestor_builder: AncestorBuilder
6
+ attr_reader method_builder: MethodBuilder
32
7
 
33
- attr_reader instance_cache: Hash[TypeName, Definition | false | nil]
8
+ attr_reader instance_cache: Hash[[TypeName, bool], Definition | false | nil]
34
9
  attr_reader singleton_cache: Hash[TypeName, Definition | false | nil]
10
+ attr_reader singleton0_cache: Hash[TypeName, Definition | false | nil]
35
11
  attr_reader interface_cache: Hash[TypeName, Definition | false | nil]
36
12
 
37
- attr_reader one_instance_cache: Hash[TypeName, Definition]
38
- attr_reader one_singleton_cache: Hash[TypeName, Definition]
39
-
40
- attr_reader instance_ancestors_cache: Hash[TypeName, Definition::InstanceAncestors]
41
- attr_reader singleton_ancestor_cache: Hash[TypeName, Definition::SingletonAncestors]
42
-
43
- attr_reader one_instance_ancestors_cache: Hash[TypeName, OneAncestors]
44
- attr_reader one_singleton_ancestors_cache: Hash[TypeName, OneAncestors]
45
-
46
13
  def initialize: (env: Environment) -> void
47
14
 
48
15
  def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
49
16
 
50
- def one_instance_ancestors: (TypeName) -> OneAncestors
51
-
52
- def one_singleton_ancestors: (TypeName) -> OneAncestors
53
-
54
- def instance_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
55
-
56
- def singleton_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::SingletonAncestors
57
-
58
- def mixin_ancestors: (Environment::ClassEntry | Environment::ModuleEntry, included_modules: Array[Definition::Ancestor::Instance]?, prepended_modules: Array[Definition::Ancestor::Instance]?, extended_modules: Array[Definition::Ancestor::Instance]?) -> void
59
-
60
- def each_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
61
-
62
17
  def ensure_namespace!: (Namespace, location: Location?) -> void
63
18
 
64
- def build_singleton: (TypeName) -> Definition
65
-
66
- def build_instance: (TypeName) -> Definition
67
-
68
19
  def build_interface: (TypeName) -> Definition
69
20
 
70
- def build_one_instance: (TypeName) -> Definition
21
+ def build_instance: (TypeName, ?no_self_types: bool) -> Definition
71
22
 
72
- def build_one_singleton: (TypeName) -> Definition
23
+ def build_singleton0: (TypeName) -> Definition
73
24
 
74
- type ancestors = Definition::InstanceAncestors | Definition::SingletonAncestors | nil
75
- def merge_definitions: (TypeName,
76
- Array[[Definition::Ancestor::t, Definition]],
77
- entry: Environment::ModuleEntry | Environment::ClassEntry,
78
- self_type: Definition::self_type,
79
- ancestors: ancestors) -> Definition
25
+ def build_singleton: (TypeName) -> Definition
80
26
 
81
- type method_kind = :instance | :singleton
82
- def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, kind: method_kind) -> void
27
+ def merge_definition: (src: Definition, dest: Definition, subst: Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
83
28
 
84
- def merge_variable: (Hash[Symbol, Definition::Variable], Symbol, Definition::Variable) -> void
29
+ def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
85
30
 
86
- def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
31
+ def merge_variable: (Hash[Symbol, Definition::Variable], Symbol, Definition::Variable, Substitution, ?keep_super: bool) -> void
87
32
 
88
- type member_detail = [Definition::accessibility, Definition::Method?, AST::Members::MethodDefinition?, Array[AST::Members::MethodDefinition]]
89
- def method_definition_members: (TypeName, Environment::ClassEntry | Environment::ModuleEntry, kind: :singleton | :instance) -> Hash[Symbol, member_detail]
33
+ def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
34
+ | [A] (TypeName, cache: Hash[A, Definition | false | nil], key: A) { () -> Definition } -> Definition
90
35
 
91
36
  def validate_params_with: (AST::Declarations::ModuleTypeParams, result: VarianceCalculator::Result) { (AST::Declarations::ModuleTypeParams::TypeParam) -> void } -> void
92
37
 
93
- def validate_parameter_variance: (decl: AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface, methods: Hash[Symbol, Definition::Method]) -> void
38
+ def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
39
+
40
+ def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location?
94
41
 
95
- def expand_alias: (TypeName) -> Types::t
42
+ def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
96
43
 
97
- type attributes = AST::Members::AttrReader | AST::Members::AttrWriter | AST::Members::AttrAccessor
98
- def build_attribute: (type_name: TypeName, definition: Definition, member: attributes, accessibility: Definition::accessibility) -> void
44
+ def define_methods: (Definition, interface_methods: Hash[Symbol, Definition::Method], methods: MethodBuilder::Methods, super_interface_method: bool) -> void
99
45
  end
100
46
  end
@@ -1,9 +1,13 @@
1
1
  module RBS
2
- interface _Kinded
2
+ interface _MethodName
3
3
  def kind: () -> (:instance | :singleton)
4
+
5
+ def type_name: () -> TypeName
6
+
7
+ def method_name: () -> Symbol
4
8
  end
5
9
 
6
- module MethodNameHelper : _Kinded
10
+ module MethodNameHelper : _MethodName
7
11
  def method_name_string: () -> String
8
12
  end
9
13
 
@@ -17,4 +21,139 @@ module RBS
17
21
 
18
22
  def self.check!: (type_name: TypeName, args: Array[Types::t], params: Array[Symbol], location: Location?) -> void
19
23
  end
24
+
25
+ class RecursiveAncestorError < StandardError
26
+ attr_reader ancestors: Array[Definition::Ancestor::t]
27
+ attr_reader location: Location
28
+
29
+ def initialize: (ancestors: Array[Definition::Ancestor::t], location: Location?) -> void
30
+
31
+ def self.check!: (Definition::Ancestor::t, ancestors: Array[Definition::Ancestor::t], location: Location?) -> void
32
+ end
33
+
34
+ class NoTypeFoundError < StandardError
35
+ attr_reader type_name: TypeName
36
+ attr_reader location: Location?
37
+
38
+ def initialize: (type_name: TypeName, location: Location?) -> void
39
+
40
+ def self.check!: (TypeName, env: Environment, location: Location?) -> TypeName
41
+ end
42
+
43
+ class NoSuperclassFoundError < StandardError
44
+ attr_reader type_name: TypeName
45
+ attr_reader location: Location?
46
+
47
+ def initialize: (type_name: TypeName, location: Location?) -> void
48
+
49
+ def self.check!: (TypeName, env: Environment, location: Location?) -> void
50
+ end
51
+
52
+ class NoSelfTypeFoundError < StandardError
53
+ attr_reader type_name: TypeName
54
+ attr_reader location: Location?
55
+
56
+ def initialize: (type_name: TypeName, location: Location?) -> void
57
+
58
+ def self.check!: (AST::Declarations::Module::Self, env: Environment) -> void
59
+ end
60
+
61
+ class NoMixinFoundError < StandardError
62
+ attr_reader type_name: TypeName
63
+ attr_reader member: AST::Members::t
64
+
65
+ def initialize: (type_name: TypeName, member: AST::Members::t) -> void
66
+
67
+ def location: () -> Location?
68
+
69
+ def self.check!: (TypeName, env: Environment, member: AST::Members::t) -> void
70
+ end
71
+
72
+ class DuplicatedMethodDefinitionError < StandardError
73
+ type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
74
+ type original = DefinitionBuilder::MethodBuilder::Methods::Definition::original
75
+
76
+ attr_reader type: ty
77
+ attr_reader method_name: Symbol
78
+ attr_reader members: Array[original]
79
+
80
+ def initialize: (type: ty, method_name: Symbol, members: Array[original]) -> void
81
+
82
+ def qualified_method_name: () -> String
83
+
84
+ def location: () -> Location?
85
+
86
+ def other_locations: () -> Array[Location?]
87
+ end
88
+
89
+ class DuplicatedInterfaceMethodDefinitionError < StandardError
90
+ type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
91
+ type mixin_member = AST::Members::Include | AST::Members::Extend
92
+
93
+ attr_reader type: ty
94
+ attr_reader method_name: Symbol
95
+ attr_reader member: mixin_member
96
+
97
+ def initialize: (type: ty, method_name: Symbol, member: mixin_member) -> void
98
+
99
+ def qualified_method_name: () -> String
100
+ end
101
+
102
+ class UnknownMethodAliasError < StandardError
103
+ attr_reader original_name: Symbol
104
+ attr_reader aliased_name: Symbol
105
+ attr_reader location: Location?
106
+
107
+ def initialize: (original_name: Symbol, aliased_name: Symbol, location: Location?) -> void
108
+ end
109
+
110
+ class SuperclassMismatchError < StandardError
111
+ attr_reader name: TypeName
112
+ attr_reader entry: Environment::ClassEntry
113
+
114
+ def initialize: (name: TypeName, entry: Environment::ClassEntry) -> void
115
+ end
116
+
117
+ class InvalidOverloadMethodError < StandardError
118
+ attr_reader type_name: TypeName
119
+ attr_reader method_name: Symbol
120
+ attr_reader kind: :instance | :singleton
121
+ attr_reader members: Array[AST::Members::MethodDefinition]
122
+
123
+ def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[AST::Members::MethodDefinition]) -> void
124
+ end
125
+
126
+ class GenericParameterMismatchError < StandardError
127
+ attr_reader name: TypeName
128
+ attr_reader decl: AST::Declarations::Class | AST::Declarations::Module
129
+
130
+ def initialize: (name: TypeName, decl: AST::Declarations::Class | AST::Declarations::Module) -> void
131
+ end
132
+
133
+ class DuplicatedDeclarationError < StandardError
134
+ attr_reader name: TypeName | Symbol
135
+ attr_reader decls: Array[AST::Declarations::t]
136
+
137
+ def initialize: (TypeName | Symbol, *AST::Declarations::t) -> void
138
+ end
139
+
140
+ class InvalidVarianceAnnotationError < StandardError
141
+ attr_reader type_name: TypeName
142
+ attr_reader param: AST::Declarations::ModuleTypeParams::TypeParam
143
+ attr_reader location: Location?
144
+
145
+ def initialize: (type_name: TypeName, param: AST::Declarations::ModuleTypeParams::TypeParam, location: Location?) -> void
146
+ end
147
+
148
+ class RecursiveAliasDefinitionError < StandardError
149
+ type ty = Types::ClassInstance | Types::ClassSingleton | Types::Interface
150
+ type defn = DefinitionBuilder::MethodBuilder::Methods::Definition
151
+
152
+ attr_reader type: ty
153
+ attr_reader defs: Array[defn]
154
+
155
+ def initialize: (type: ty, defs: Array[defn]) -> void
156
+
157
+ def location: () -> Location?
158
+ end
20
159
  end
@@ -0,0 +1,71 @@
1
+ module RBS
2
+ class DefinitionBuilder
3
+ class MethodBuilder
4
+ class Methods
5
+ type instance_type = Types::ClassInstance | Types::ClassSingleton | Types::Interface
6
+
7
+ class Definition
8
+ type original = AST::Members::MethodDefinition | AST::Members::Alias | AST::Members::AttrAccessor | AST::Members::AttrWriter | AST::Members::AttrReader
9
+ type accessibility = :public | :private
10
+
11
+ attr_reader name: Symbol
12
+ attr_reader type: instance_type
13
+ attr_reader originals: Array[original]
14
+ attr_reader overloads: Array[AST::Members::MethodDefinition]
15
+ attr_reader accessibilities: Array[accessibility]
16
+
17
+ def initialize: (name: Symbol, type: instance_type, originals: Array[original], overloads: Array[AST::Members::MethodDefinition], accessibilities: Array[accessibility]) -> void
18
+
19
+ def original: () -> original?
20
+
21
+ def accessibility: () -> accessibility
22
+
23
+ def self.empty: (name: Symbol, type: instance_type) -> instance
24
+ end
25
+
26
+ attr_reader type: instance_type
27
+ attr_reader methods: Hash[Symbol, Definition]
28
+
29
+ def initialize: (type: instance_type) -> void
30
+
31
+ def validate!: () -> self
32
+
33
+ def each: () { (Definition) -> void } -> void
34
+ | () -> Enumerator[Definition, void]
35
+
36
+ class Sorter
37
+ include TSort[Definition]
38
+
39
+ attr_reader methods: Hash[Symbol, Definition]
40
+
41
+ def initialize: (Hash[Symbol, Definition]) -> void
42
+
43
+ def tsort_each_node: { (Definition) -> void } -> void
44
+
45
+ def tsort_each_child: (Definition) { (Definition) -> void } -> void
46
+ end
47
+ end
48
+
49
+ attr_reader env: Environment
50
+ attr_reader instance_methods: Hash[TypeName, Methods]
51
+ attr_reader singleton_methods: Hash[TypeName, Methods]
52
+ attr_reader interface_methods: Hash[TypeName, Methods]
53
+
54
+ def initialize: (env: Environment) -> void
55
+
56
+ def build_instance: (TypeName) -> Methods
57
+
58
+ def build_singleton: (TypeName) -> Methods
59
+
60
+ def build_interface: (TypeName) -> Methods
61
+
62
+ def build_alias: (Methods, Methods::instance_type, member: AST::Members::Alias, accessibility: Methods::Definition::accessibility) -> void
63
+
64
+ def build_attribute: (Methods, Methods::instance_type, member: AST::Members::AttrAccessor | AST::Members::AttrReader | AST::Members::AttrWriter, accessibility: Methods::Definition::accessibility) -> void
65
+
66
+ def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Methods::Definition::accessibility) -> void
67
+
68
+ def each_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
69
+ end
70
+ end
71
+ end
@@ -35,5 +35,8 @@ module RBS
35
35
 
36
36
  # Returns a substitution without variables given in `vars`.
37
37
  def without: (*Symbol vars) -> Substitution
38
+
39
+ # Returns true if given substitution is identity.
40
+ def empty?: () -> bool
38
41
  end
39
42
  end
@@ -115,7 +115,6 @@ module RBS
115
115
 
116
116
  class Variable
117
117
  attr_reader name: Symbol
118
- attr_reader location: Location?
119
118
 
120
119
  @@count: Integer
121
120
 
@@ -140,7 +139,6 @@ module RBS
140
139
 
141
140
  class ClassSingleton
142
141
  attr_reader name: TypeName
143
- attr_reader location: Location?
144
142
 
145
143
  include _TypeBase
146
144
 
@@ -178,8 +176,6 @@ module RBS
178
176
  class Interface
179
177
  include Application
180
178
 
181
- attr_reader location: Location?
182
-
183
179
  def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
184
180
 
185
181
  include _TypeBase
@@ -194,15 +190,12 @@ module RBS
194
190
  class ClassInstance
195
191
  include Application
196
192
 
197
- attr_reader location: Location?
198
-
199
193
  def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
200
194
 
201
195
  include _TypeBase
202
196
  end
203
197
 
204
198
  class Alias
205
- attr_reader location: Location?
206
199
  attr_reader name: TypeName
207
200
 
208
201
  def initialize: (name: TypeName, location: Location?) -> void
@@ -215,7 +208,6 @@ module RBS
215
208
 
216
209
  class Tuple
217
210
  attr_reader types: Array[t]
218
- attr_reader location: Location?
219
211
 
220
212
  def initialize: (types: Array[t], location: Location?) -> void
221
213
 
@@ -224,7 +216,6 @@ module RBS
224
216
 
225
217
  class Record
226
218
  attr_reader fields: Hash[Symbol, t]
227
- attr_reader location: Location?
228
219
 
229
220
  def initialize: (fields: Hash[Symbol, t], location: Location?) -> void
230
221
 
@@ -233,7 +224,6 @@ module RBS
233
224
 
234
225
  class Optional
235
226
  attr_reader type: t
236
- attr_reader location: Location?
237
227
 
238
228
  def initialize: (type: t, location: Location?) -> void
239
229
 
@@ -242,7 +232,6 @@ module RBS
242
232
 
243
233
  class Union
244
234
  attr_reader types: Array[t]
245
- attr_reader location: Location?
246
235
 
247
236
  def initialize: (types: Array[t], location: Location?) -> void
248
237
 
@@ -254,7 +243,6 @@ module RBS
254
243
 
255
244
  class Intersection
256
245
  attr_reader types: Array[t]
257
- attr_reader location: Location?
258
246
 
259
247
  def initialize: (types: Array[t], location: Location?) -> void
260
248
 
@@ -336,7 +324,7 @@ module RBS
336
324
 
337
325
  class Block
338
326
  attr_reader type: Types::Function
339
- attr_reader required: boolish
327
+ attr_reader required: bool
340
328
 
341
329
  def initialize: (type: Types::Function, required: boolish) -> void
342
330
 
@@ -352,7 +340,6 @@ module RBS
352
340
  class Proc
353
341
  attr_reader type: Function
354
342
  attr_reader block: Block?
355
- attr_reader location: Location?
356
343
 
357
344
  def initialize: (location: Location?, type: Function, block: Block?) -> void
358
345
 
@@ -363,7 +350,6 @@ module RBS
363
350
  type literal = String | Integer | Symbol | TrueClass | FalseClass
364
351
 
365
352
  attr_reader literal: literal
366
- attr_reader location: Location?
367
353
 
368
354
  def initialize: (literal: literal, location: Location?) -> void
369
355