rbs 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +35 -0
  5. data/COPYING +1 -1
  6. data/Gemfile +16 -2
  7. data/README.md +87 -48
  8. data/Rakefile +54 -22
  9. data/bin/rbs-prof +9 -0
  10. data/bin/run_in_md.rb +49 -0
  11. data/bin/test_runner.rb +0 -2
  12. data/docs/sigs.md +6 -6
  13. data/docs/stdlib.md +3 -5
  14. data/docs/syntax.md +6 -3
  15. data/goodcheck.yml +65 -0
  16. data/lib/rbs.rb +3 -0
  17. data/lib/rbs/ast/declarations.rb +115 -14
  18. data/lib/rbs/ast/members.rb +41 -17
  19. data/lib/rbs/cli.rb +301 -123
  20. data/lib/rbs/constant.rb +4 -4
  21. data/lib/rbs/constant_table.rb +64 -53
  22. data/lib/rbs/definition.rb +175 -59
  23. data/lib/rbs/definition_builder.rb +646 -603
  24. data/lib/rbs/environment.rb +352 -210
  25. data/lib/rbs/environment_walker.rb +14 -23
  26. data/lib/rbs/errors.rb +159 -3
  27. data/lib/rbs/factory.rb +14 -0
  28. data/lib/rbs/namespace.rb +18 -0
  29. data/lib/rbs/parser.y +75 -21
  30. data/lib/rbs/prototype/rb.rb +119 -117
  31. data/lib/rbs/prototype/rbi.rb +5 -3
  32. data/lib/rbs/prototype/runtime.rb +34 -7
  33. data/lib/rbs/substitution.rb +8 -1
  34. data/lib/rbs/test.rb +81 -3
  35. data/lib/rbs/test/errors.rb +1 -1
  36. data/lib/rbs/test/hook.rb +133 -259
  37. data/lib/rbs/test/observer.rb +17 -0
  38. data/lib/rbs/test/setup.rb +13 -14
  39. data/lib/rbs/test/spy.rb +0 -321
  40. data/lib/rbs/test/tester.rb +116 -0
  41. data/lib/rbs/test/type_check.rb +44 -7
  42. data/lib/rbs/type_name_resolver.rb +58 -0
  43. data/lib/rbs/types.rb +94 -2
  44. data/lib/rbs/validator.rb +51 -0
  45. data/lib/rbs/variance_calculator.rb +12 -2
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs/writer.rb +127 -91
  48. data/rbs.gemspec +0 -9
  49. data/schema/annotation.json +14 -0
  50. data/schema/comment.json +26 -0
  51. data/schema/decls.json +353 -0
  52. data/schema/function.json +87 -0
  53. data/schema/location.json +56 -0
  54. data/schema/members.json +248 -0
  55. data/schema/methodType.json +44 -0
  56. data/schema/types.json +299 -0
  57. data/stdlib/benchmark/benchmark.rbs +151 -151
  58. data/stdlib/builtin/encoding.rbs +2 -0
  59. data/stdlib/builtin/enumerable.rbs +2 -2
  60. data/stdlib/builtin/enumerator.rbs +3 -1
  61. data/stdlib/builtin/fiber.rbs +5 -1
  62. data/stdlib/builtin/file.rbs +0 -3
  63. data/stdlib/builtin/io.rbs +4 -4
  64. data/stdlib/builtin/proc.rbs +1 -2
  65. data/stdlib/builtin/symbol.rbs +1 -1
  66. data/stdlib/builtin/thread.rbs +2 -2
  67. data/stdlib/csv/csv.rbs +4 -6
  68. data/stdlib/fiber/fiber.rbs +117 -0
  69. data/stdlib/json/json.rbs +1 -1
  70. data/stdlib/logger/formatter.rbs +23 -0
  71. data/stdlib/logger/log_device.rbs +39 -0
  72. data/stdlib/logger/logger.rbs +507 -0
  73. data/stdlib/logger/period.rbs +7 -0
  74. data/stdlib/logger/severity.rbs +8 -0
  75. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  76. data/stdlib/pathname/pathname.rbs +6 -6
  77. data/stdlib/prime/integer-extension.rbs +1 -1
  78. data/stdlib/prime/prime.rbs +44 -44
  79. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  80. metadata +26 -116
  81. data/lib/rbs/test/test_helper.rb +0 -183
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "point": {
5
+ "type": "object",
6
+ "properties": {
7
+ "line": {
8
+ "type": "integer"
9
+ },
10
+ "column": {
11
+ "type": "integer"
12
+ }
13
+ },
14
+ "required": ["line", "column"]
15
+ },
16
+ "buffer": {
17
+ "type": "object",
18
+ "properties": {
19
+ "name": {
20
+ "oneOf": [
21
+ {
22
+ "type": "string"
23
+ },
24
+ {
25
+ "type": "null"
26
+ }
27
+ ]
28
+ }
29
+ },
30
+ "required": ["name"]
31
+ },
32
+ "location": {
33
+ "type": "object",
34
+ "properties": {
35
+ "start": {
36
+ "$ref": "#/definitions/point"
37
+ },
38
+ "end": {
39
+ "$ref": "#/definitions/point"
40
+ },
41
+ "buffer": {
42
+ "$ref": "#/definitions/buffer"
43
+ }
44
+ },
45
+ "required": ["start", "end", "buffer"]
46
+ }
47
+ },
48
+ "oneOf": [
49
+ {
50
+ "$ref": "#/definitions/location"
51
+ },
52
+ {
53
+ "type": "null"
54
+ }
55
+ ]
56
+ }
@@ -0,0 +1,248 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "methodDefinition": {
5
+ "type": "object",
6
+ "properties": {
7
+ "member": {
8
+ "type": "string",
9
+ "enum": ["method_definition"]
10
+ },
11
+ "kind": {
12
+ "enum": ["instance", "singleton", "singleton_instance"]
13
+ },
14
+ "types": {
15
+ "type": "array",
16
+ "items": {
17
+ "$ref": "methodType.json"
18
+ }
19
+ },
20
+ "comment": {
21
+ "$ref": "comment.json"
22
+ },
23
+ "annotations": {
24
+ "type": "array",
25
+ "items": {
26
+ "$ref": "annotation.json"
27
+ }
28
+ },
29
+ "attributes": {
30
+ "type": "array",
31
+ "items": {
32
+ "enum": ["incompatible"]
33
+ }
34
+ },
35
+ "location": {
36
+ "$ref": "location.json"
37
+ },
38
+ "overload": {
39
+ "type": "boolean"
40
+ }
41
+ },
42
+ "required": ["member", "kind", "types", "comment", "annotations", "location"]
43
+ },
44
+ "variable": {
45
+ "title": "Declaration for instance variables and class variables",
46
+ "description": "`@x: Integer`, `self.@x: String`, `@@name: Symbol`, ...",
47
+ "type": "object",
48
+ "properties": {
49
+ "member": {
50
+ "enum": ["instance_variable", "class_instance_variable", "class_variable"]
51
+ },
52
+ "name": {
53
+ "type": "string"
54
+ },
55
+ "type": {
56
+ "$ref": "types.json"
57
+ },
58
+ "location": {
59
+ "$ref": "location.json"
60
+ },
61
+ "comment": {
62
+ "$ref": "comment.json"
63
+ }
64
+ },
65
+ "required": ["member", "name", "type", "location", "comment"]
66
+ },
67
+ "include": {
68
+ "title": "Include mixin",
69
+ "properties": {
70
+ "member": {
71
+ "enum": ["include"]
72
+ },
73
+ "name": {
74
+ "type": "string"
75
+ },
76
+ "args": {
77
+ "type": "array",
78
+ "items": {
79
+ "$ref": "types.json"
80
+ }
81
+ },
82
+ "annotations": {
83
+ "type": "array",
84
+ "items": {
85
+ "$ref": "annotation.json"
86
+ }
87
+ },
88
+ "comment": {
89
+ "$ref": "comment.json"
90
+ },
91
+ "location": {
92
+ "$ref": "location.json"
93
+ }
94
+ },
95
+ "required": ["member", "name", "args", "annotations", "comment", "location"]
96
+ },
97
+ "extend": {
98
+ "title": "Extend mixin",
99
+ "properties": {
100
+ "member": {
101
+ "enum": ["extend"]
102
+ },
103
+ "name": {
104
+ "type": "string"
105
+ },
106
+ "args": {
107
+ "type": "array",
108
+ "items": {
109
+ "$ref": "types.json"
110
+ }
111
+ },
112
+ "annotations": {
113
+ "type": "array",
114
+ "items": {
115
+ "$ref": "annotation.json"
116
+ }
117
+ },
118
+ "comment": {
119
+ "$ref": "comment.json"
120
+ },
121
+ "location": {
122
+ "$ref": "location.json"
123
+ }
124
+ },
125
+ "required": ["member", "name", "args", "annotations", "comment", "location"]
126
+ },
127
+ "prepend": {
128
+ "title": "Prepend mixin",
129
+ "properties": {
130
+ "member": {
131
+ "enum": ["prepend"]
132
+ },
133
+ "name": {
134
+ "type": "string"
135
+ },
136
+ "args": {
137
+ "type": "array",
138
+ "items": {
139
+ "$ref": "types.json"
140
+ }
141
+ },
142
+ "annotations": {
143
+ "type": "array",
144
+ "items": {
145
+ "$ref": "annotation.json"
146
+ }
147
+ },
148
+ "comment": {
149
+ "$ref": "comment.json"
150
+ },
151
+ "location": {
152
+ "$ref": "location.json"
153
+ }
154
+ },
155
+ "required": ["member", "name", "args", "annotations", "comment", "location"]
156
+ },
157
+ "attribute": {
158
+ "title": "Attribute definitions",
159
+ "description": "`attr_reader`, `attr_accessor`, `attr_writer`",
160
+ "properties": {
161
+ "member": {
162
+ "type": "string",
163
+ "enum": ["attr_reader", "attr_accessor", "attr_writer"]
164
+ },
165
+ "name": {
166
+ "type": "string"
167
+ },
168
+ "type": {
169
+ "$ref": "types.json"
170
+ },
171
+ "ivar_name": {
172
+ "oneOf": [
173
+ {
174
+ "type": "string"
175
+ },
176
+ {
177
+ "type": "null"
178
+ },
179
+ {
180
+ "enum": [false]
181
+ }
182
+ ]
183
+ },
184
+ "annotations": {
185
+ "type": "array",
186
+ "items": {
187
+ "$ref": "annotation.json"
188
+ }
189
+ },
190
+ "comment": {
191
+ "$ref": "comment.json"
192
+ },
193
+ "location": {
194
+ "$ref": "location.json"
195
+ }
196
+ },
197
+ "required": ["member", "name", "ivar_name", "type", "annotations", "comment", "location"]
198
+ },
199
+ "visibility": {
200
+ "title": "Visibility specifier",
201
+ "description": "`public` and `private`.",
202
+ "type": "object",
203
+ "properties": {
204
+ "member": {
205
+ "type": "string",
206
+ "enum": ["public", "private"]
207
+ },
208
+ "location": {
209
+ "$ref": "location.json"
210
+ }
211
+ },
212
+ "required": ["member", "location"]
213
+ },
214
+ "alias": {
215
+ "title": "Alias declaration",
216
+ "description": "`alias to_s inspect`, `alias self.new self.allocate`, ...",
217
+ "properties": {
218
+ "member": {
219
+ "type": "string",
220
+ "enum": ["alias"]
221
+ },
222
+ "new_name": {
223
+ "type": "string"
224
+ },
225
+ "old_name": {
226
+ "type": "string"
227
+ },
228
+ "kind": {
229
+ "type": "string",
230
+ "enum": ["instance", "singleton"]
231
+ },
232
+ "annotations": {
233
+ "type": "array",
234
+ "items": {
235
+ "$ref": "annotation.json"
236
+ }
237
+ },
238
+ "comment": {
239
+ "$ref": "comment.json"
240
+ },
241
+ "location": {
242
+ "$ref": "location.json"
243
+ }
244
+ },
245
+ "required": ["member", "new_name", "old_name", "kind", "annotations", "comment", "location"]
246
+ }
247
+ }
248
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "block": {
5
+ "type": "object",
6
+ "properties": {
7
+ "type": {
8
+ "$ref": "function.json"
9
+ },
10
+ "required": {
11
+ "type": "boolean"
12
+ }
13
+ },
14
+ "required": ["type", "required"]
15
+ }
16
+ },
17
+ "title": "Method type: `() -> void`, `[X] (::Integer) { (::String) -> X } -> Array[X]`, ...",
18
+ "type": "object",
19
+ "properties": {
20
+ "type_params": {
21
+ "type": "array",
22
+ "items": {
23
+ "type": "string"
24
+ }
25
+ },
26
+ "type": {
27
+ "$ref": "function.json"
28
+ },
29
+ "block": {
30
+ "oneOf": [
31
+ {
32
+ "$ref": "#/definitions/block"
33
+ },
34
+ {
35
+ "type": "null"
36
+ }
37
+ ]
38
+ },
39
+ "location": {
40
+ "$ref": "location.json"
41
+ }
42
+ },
43
+ "required": ["type_params", "type", "block", "location"]
44
+ }
@@ -0,0 +1,299 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "base": {
5
+ "title": "Base types",
6
+ "type": "object",
7
+ "properties": {
8
+ "class": {
9
+ "type": "string",
10
+ "enum": [
11
+ "bool",
12
+ "void",
13
+ "untyped",
14
+ "nil",
15
+ "top",
16
+ "bot",
17
+ "self",
18
+ "instance",
19
+ "class"
20
+ ]
21
+ },
22
+ "location": {
23
+ "$ref": "location.json"
24
+ }
25
+ },
26
+ "required": ["class", "location"]
27
+ },
28
+ "variable": {
29
+ "title": "Type variables: `X`, `Y`, `Elem`, `Key`, ...",
30
+ "type": "object",
31
+ "properties": {
32
+ "class": {
33
+ "type": "string",
34
+ "enum": ["variable"]
35
+ },
36
+ "name": {
37
+ "type": "string"
38
+ },
39
+ "location": {
40
+ "$ref": "location.json"
41
+ }
42
+ },
43
+ "required": ["class", "name", "location"]
44
+ },
45
+ "classSingleton": {
46
+ "title": "Class singleton type: `singleton(Object)`, `singleton(::Kernel)`, ...",
47
+ "type": "object",
48
+ "properties": {
49
+ "class": {
50
+ "type": "string",
51
+ "enum": ["class_singleton"]
52
+ },
53
+ "name": {
54
+ "type": "string"
55
+ },
56
+ "location": {
57
+ "$ref": "location.json"
58
+ }
59
+ },
60
+ "required": ["class", "name", "location"]
61
+ },
62
+ "classInstance": {
63
+ "title": "Class instance type: `String`, `::Enumerable`, `Array[::Symbol]`, ...",
64
+ "type": "object",
65
+ "properties": {
66
+ "class": {
67
+ "type": "string",
68
+ "enum": ["class_instance"]
69
+ },
70
+ "name": {
71
+ "type": "string"
72
+ },
73
+ "args": {
74
+ "type": "array",
75
+ "items": {
76
+ "$ref": "#"
77
+ }
78
+ },
79
+ "location": {
80
+ "$ref": "location.json"
81
+ }
82
+ },
83
+ "required": ["class", "name", "args", "location"]
84
+ },
85
+ "interface": {
86
+ "title": "Interface type: `_Each[String, void]`, `_ToStr`, ...",
87
+ "type": "object",
88
+ "properties": {
89
+ "class": {
90
+ "type": "string",
91
+ "enum": ["interface"]
92
+ },
93
+ "name": {
94
+ "type": "string"
95
+ },
96
+ "args": {
97
+ "type": "array",
98
+ "items": {
99
+ "$ref": "#"
100
+ }
101
+ },
102
+ "location": {
103
+ "$ref": "location.json"
104
+ }
105
+ },
106
+ "required": ["class", "name", "args", "location"]
107
+ },
108
+ "alias": {
109
+ "title": "Type alias: `u`, `ty`, `json`, ...",
110
+ "type": "object",
111
+ "properties": {
112
+ "class": {
113
+ "type": "string",
114
+ "enum": ["alias"]
115
+ },
116
+ "name": {
117
+ "type": "string"
118
+ },
119
+ "location": {
120
+ "$ref": "location.json"
121
+ }
122
+ },
123
+ "required": ["class", "name", "location"]
124
+ },
125
+ "tuple": {
126
+ "title": "Tuple type: `[Foo, bar]`, ...",
127
+ "type": "object",
128
+ "properties": {
129
+ "class": {
130
+ "type": "string",
131
+ "enum": ["tuple"]
132
+ },
133
+ "types": {
134
+ "type": "array",
135
+ "items": {
136
+ "$ref": "#"
137
+ }
138
+ },
139
+ "location": {
140
+ "$ref": "location.json"
141
+ }
142
+ },
143
+ "required": ["class", "types", "location"]
144
+ },
145
+ "record": {
146
+ "title": "Record type: `{ id: Integer, email: String }`, ...",
147
+ "type": "object",
148
+ "properties": {
149
+ "class": {
150
+ "type": "string",
151
+ "enum": ["record"]
152
+ },
153
+ "fields": {
154
+ "type": "object",
155
+ "additionalProperties": {
156
+ "$ref": "#"
157
+ }
158
+ },
159
+ "location": {
160
+ "$ref": "location.json"
161
+ }
162
+ },
163
+ "required": ["class", "fields", "location"]
164
+ },
165
+ "optional": {
166
+ "title": "Optional types: `Integer?`, ...",
167
+ "type": "object",
168
+ "properties": {
169
+ "class": {
170
+ "type": "string",
171
+ "enum": ["optional"]
172
+ },
173
+ "type": {
174
+ "$ref": "#"
175
+ },
176
+ "location": {
177
+ "$ref": "location.json"
178
+ }
179
+ },
180
+ "required": ["class", "type", "location"]
181
+ },
182
+ "union": {
183
+ "title": "Union types: `Integer | String`, ...",
184
+ "type": "object",
185
+ "properties": {
186
+ "class": {
187
+ "type": "string",
188
+ "enum": ["union"]
189
+ },
190
+ "types": {
191
+ "type": "array",
192
+ "items": {
193
+ "$ref": "#"
194
+ }
195
+ },
196
+ "location": {
197
+ "$ref": "location.json"
198
+ }
199
+ },
200
+ "required": ["class", "types", "location"]
201
+ },
202
+ "intersection": {
203
+ "title": "Intersection types: `Integer & String`, ...",
204
+ "type": "object",
205
+ "properties": {
206
+ "class": {
207
+ "type": "string",
208
+ "enum": ["intersection"]
209
+ },
210
+ "types": {
211
+ "type": "array",
212
+ "items": {
213
+ "$ref": "#"
214
+ }
215
+ },
216
+ "location": {
217
+ "$ref": "location.json"
218
+ }
219
+ },
220
+ "required": ["class", "types", "location"]
221
+ },
222
+ "proc": {
223
+ "title": "Proc types: `^() -> void`, ...",
224
+ "type": "object",
225
+ "properties": {
226
+ "class": {
227
+ "type": "string",
228
+ "enum": ["proc"]
229
+ },
230
+ "type": {
231
+ "$ref": "function.json"
232
+ },
233
+ "location": {
234
+ "$ref": "location.json"
235
+ }
236
+ },
237
+ "required": ["class", "type", "location"]
238
+ },
239
+ "literal": {
240
+ "title": "Literal types: `1`, `:foo`, `\"foo\"`, ...",
241
+ "type": "object",
242
+ "properties": {
243
+ "class": {
244
+ "type": "string",
245
+ "enum": ["literal"]
246
+ },
247
+ "literal": {
248
+ "type": "string"
249
+ },
250
+ "location": {
251
+ "$ref": "location.json"
252
+ }
253
+ },
254
+ "required": ["class", "literal", "location"]
255
+ }
256
+ },
257
+ "title": "Type",
258
+ "oneOf": [
259
+ {
260
+ "$ref": "#/definitions/base"
261
+ },
262
+ {
263
+ "$ref": "#/definitions/variable"
264
+ },
265
+ {
266
+ "$ref": "#/definitions/classInstance"
267
+ },
268
+ {
269
+ "$ref": "#/definitions/classSingleton"
270
+ },
271
+ {
272
+ "$ref": "#/definitions/interface"
273
+ },
274
+ {
275
+ "$ref": "#/definitions/alias"
276
+ },
277
+ {
278
+ "$ref": "#/definitions/tuple"
279
+ },
280
+ {
281
+ "$ref": "#/definitions/record"
282
+ },
283
+ {
284
+ "$ref": "#/definitions/union"
285
+ },
286
+ {
287
+ "$ref": "#/definitions/intersection"
288
+ },
289
+ {
290
+ "$ref": "#/definitions/optional"
291
+ },
292
+ {
293
+ "$ref": "#/definitions/proc"
294
+ },
295
+ {
296
+ "$ref": "#/definitions/literal"
297
+ }
298
+ ]
299
+ }