rbs 1.5.1 → 1.7.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ruby.yml +0 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +51 -0
- data/Gemfile +2 -0
- data/Rakefile +7 -22
- data/Steepfile +9 -1
- data/core/enumerator.rbs +1 -0
- data/core/io.rbs +3 -1
- data/core/kernel.rbs +4 -4
- data/core/trace_point.rbs +1 -1
- data/docs/collection.md +116 -0
- data/ext/rbs/extension/constants.c +140 -0
- data/ext/rbs/extension/constants.h +72 -0
- data/ext/rbs/extension/extconf.rb +3 -0
- data/ext/rbs/extension/lexer.c +1070 -0
- data/ext/rbs/extension/lexer.h +145 -0
- data/ext/rbs/extension/location.c +295 -0
- data/ext/rbs/extension/location.h +59 -0
- data/ext/rbs/extension/main.c +9 -0
- data/ext/rbs/extension/parser.c +2418 -0
- data/ext/rbs/extension/parser.h +23 -0
- data/ext/rbs/extension/parserstate.c +313 -0
- data/ext/rbs/extension/parserstate.h +141 -0
- data/ext/rbs/extension/rbs_extension.h +40 -0
- data/ext/rbs/extension/ruby_objs.c +585 -0
- data/ext/rbs/extension/ruby_objs.h +46 -0
- data/ext/rbs/extension/unescape.c +65 -0
- data/goodcheck.yml +1 -1
- data/lib/rbs/ast/comment.rb +0 -12
- data/lib/rbs/buffer.rb +4 -0
- data/lib/rbs/builtin_names.rb +1 -0
- data/lib/rbs/cli.rb +98 -10
- data/lib/rbs/collection/cleaner.rb +29 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +95 -0
- data/lib/rbs/collection/config.rb +85 -0
- data/lib/rbs/collection/installer.rb +27 -0
- data/lib/rbs/collection/sources/git.rb +162 -0
- data/lib/rbs/collection/sources/rubygems.rb +40 -0
- data/lib/rbs/collection/sources/stdlib.rb +38 -0
- data/lib/rbs/collection/sources.rb +22 -0
- data/lib/rbs/collection.rb +13 -0
- data/lib/rbs/environment_loader.rb +12 -0
- data/lib/rbs/errors.rb +16 -1
- data/lib/rbs/location.rb +221 -217
- data/lib/rbs/location_aux.rb +108 -0
- data/lib/rbs/locator.rb +10 -7
- data/lib/rbs/parser_aux.rb +24 -0
- data/lib/rbs/repository.rb +13 -7
- data/lib/rbs/types.rb +2 -3
- data/lib/rbs/validator.rb +4 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +4 -2
- data/lib/rbs.rb +4 -7
- data/rbs.gemspec +2 -1
- data/sig/ancestor_builder.rbs +2 -2
- data/sig/annotation.rbs +2 -2
- data/sig/builtin_names.rbs +1 -0
- data/sig/cli.rbs +5 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/collections.rbs +112 -0
- data/sig/collection/config.rbs +69 -0
- data/sig/collection/installer.rbs +15 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +7 -7
- data/sig/constant_table.rbs +1 -1
- data/sig/declarations.rbs +9 -9
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +2 -2
- data/sig/environment_loader.rbs +3 -0
- data/sig/errors.rbs +30 -25
- data/sig/location.rbs +42 -79
- data/sig/locator.rbs +2 -2
- data/sig/members.rbs +7 -7
- data/sig/method_types.rbs +3 -3
- data/sig/parser.rbs +11 -21
- data/sig/polyfill.rbs +12 -3
- data/sig/repository.rbs +4 -0
- data/sig/types.rbs +45 -27
- data/sig/writer.rbs +1 -1
- data/stdlib/json/0/json.rbs +3 -3
- data/stdlib/objspace/0/objspace.rbs +406 -0
- data/stdlib/openssl/0/openssl.rbs +1 -1
- data/stdlib/tempfile/0/tempfile.rbs +270 -0
- data/steep/Gemfile.lock +10 -10
- metadata +43 -7
- data/lib/rbs/parser.rb +0 -3614
data/sig/locator.rbs
CHANGED
@@ -37,8 +37,8 @@ module RBS
|
|
37
37
|
|
38
38
|
def find_in_type: (Integer pos, type: Types::t, array: Array[component]) -> bool
|
39
39
|
|
40
|
-
def find_in_loc: (Integer pos, location: Location
|
40
|
+
def find_in_loc: (Integer pos, location: Location[untyped, untyped]?, array: Array[component]) -> bool
|
41
41
|
|
42
|
-
def test_loc: (Integer pos, location: Location?) -> bool
|
42
|
+
def test_loc: (Integer pos, location: Location[untyped, untyped]?) -> bool
|
43
43
|
end
|
44
44
|
end
|
data/sig/members.rbs
CHANGED
@@ -25,7 +25,7 @@ module RBS
|
|
25
25
|
# ^^^ name
|
26
26
|
# ^^^ overload
|
27
27
|
#
|
28
|
-
type loc = Location
|
28
|
+
type loc = Location[:keyword | :name, :kind | :overload]
|
29
29
|
|
30
30
|
attr_reader name: Symbol
|
31
31
|
attr_reader kind: kind
|
@@ -59,7 +59,7 @@ module RBS
|
|
59
59
|
# ^^^^ name
|
60
60
|
# ^ colon
|
61
61
|
#
|
62
|
-
type loc = Location
|
62
|
+
type loc = Location[:name | :colon, :kind]
|
63
63
|
|
64
64
|
attr_reader name: Symbol
|
65
65
|
attr_reader type: Types::t
|
@@ -97,7 +97,7 @@ module RBS
|
|
97
97
|
# ^ arg_open
|
98
98
|
# ^ arg_close
|
99
99
|
#
|
100
|
-
type loc = Location
|
100
|
+
type loc = Location[:name | :keyword, :args]
|
101
101
|
|
102
102
|
attr_reader name: TypeName
|
103
103
|
attr_reader args: Array[Types::t]
|
@@ -141,7 +141,7 @@ module RBS
|
|
141
141
|
# ^^^^ ivar_name
|
142
142
|
# ^ colon
|
143
143
|
#
|
144
|
-
type loc = Location
|
144
|
+
type loc = Location[:keyword | :name | :colon, :kind | :ivar | :ivar_name]
|
145
145
|
|
146
146
|
attr_reader name: Symbol
|
147
147
|
attr_reader type: Types::t
|
@@ -174,9 +174,9 @@ module RBS
|
|
174
174
|
end
|
175
175
|
|
176
176
|
module LocationOnly
|
177
|
-
attr_reader location: Location?
|
177
|
+
attr_reader location: Location[bot, bot]?
|
178
178
|
|
179
|
-
def initialize: (location: Location?) -> void
|
179
|
+
def initialize: (location: Location[bot, bot]?) -> void
|
180
180
|
|
181
181
|
include _HashEqual
|
182
182
|
end
|
@@ -206,7 +206,7 @@ module RBS
|
|
206
206
|
# ^^^^^ old_kind
|
207
207
|
# ^^^ old_name
|
208
208
|
#
|
209
|
-
type loc = Location
|
209
|
+
type loc = Location[:keyword | :new_name | :old_name, :new_kind | :old_kind]
|
210
210
|
|
211
211
|
attr_reader new_name: Symbol
|
212
212
|
attr_reader old_name: Symbol
|
data/sig/method_types.rbs
CHANGED
@@ -3,9 +3,9 @@ module RBS
|
|
3
3
|
attr_reader type_params: Array[Symbol]
|
4
4
|
attr_reader type: Types::Function
|
5
5
|
attr_reader block: Types::Block?
|
6
|
-
attr_reader location: Location?
|
6
|
+
attr_reader location: Location[untyped, untyped]?
|
7
7
|
|
8
|
-
def initialize: (type_params: Array[Symbol], type: Types::Function, block: Types::Block?, location: Location?) -> void
|
8
|
+
def initialize: (type_params: Array[Symbol], type: Types::Function, block: Types::Block?, location: Location[untyped, untyped]?) -> void
|
9
9
|
|
10
10
|
def ==: (untyped other) -> bool
|
11
11
|
|
@@ -13,7 +13,7 @@ module RBS
|
|
13
13
|
|
14
14
|
def sub: (Substitution) -> MethodType
|
15
15
|
|
16
|
-
def update: (?type_params: Array[Symbol], ?type: Types::Function, ?block: Types::Block?, ?location: Location?) -> MethodType
|
16
|
+
def update: (?type_params: Array[Symbol], ?type: Types::Function, ?block: Types::Block?, ?location: Location[untyped, untyped]?) -> MethodType
|
17
17
|
|
18
18
|
def free_variables: (?Set[Symbol] set) -> Set[Symbol]
|
19
19
|
|
data/sig/parser.rbs
CHANGED
@@ -1,32 +1,22 @@
|
|
1
1
|
module RBS
|
2
2
|
class Parser
|
3
|
-
|
4
|
-
attr_reader token_str: String
|
5
|
-
attr_reader error_value: untyped
|
6
|
-
attr_reader value_stack: untyped?
|
3
|
+
def self.parse_method_type: (Buffer | String, ?line: Integer, ?column: Integer, ?variables: Array[Symbol]) -> MethodType
|
7
4
|
|
8
|
-
|
9
|
-
end
|
5
|
+
def self.parse_type: (Buffer | String, ?line: Integer, ?column: Integer, ?variables: Array[Symbol]) -> Types::t
|
10
6
|
|
11
|
-
|
12
|
-
attr_reader input: String
|
13
|
-
attr_reader location: Location
|
7
|
+
def self.parse_signature: (Buffer | String, ?line: Integer, ?column: Integer) -> Array[AST::Declarations::t]
|
14
8
|
|
15
|
-
|
16
|
-
end
|
9
|
+
private
|
17
10
|
|
18
|
-
|
19
|
-
attr_reader subject: untyped
|
20
|
-
attr_reader location: Location
|
21
|
-
attr_reader original_message: String
|
11
|
+
def self.buffer: (String | Buffer source) -> Buffer
|
22
12
|
|
23
|
-
|
24
|
-
|
13
|
+
%a{no-defn}
|
14
|
+
def self._parse_type: (Buffer, Integer line, Integer column, Array[Symbol] variables) -> Types::t
|
25
15
|
|
26
|
-
|
16
|
+
%a{no-defn}
|
17
|
+
def self._parse_method_type: (Buffer, Integer line, Integer column, Array[Symbol] variables) -> MethodType
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
def self.parse_signature: (String | Buffer, ?eof_re: Regexp?) -> Array[AST::Declarations::t]
|
19
|
+
%a{no-defn}
|
20
|
+
def self._parse_signature: (Buffer, Integer line, Integer column) -> Array[AST::Declarations::t]
|
31
21
|
end
|
32
22
|
end
|
data/sig/polyfill.rbs
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
module Kernel
|
2
|
-
end
|
3
|
-
|
4
1
|
module Gem
|
5
2
|
class Specification
|
6
3
|
attr_reader version (): Version
|
@@ -16,3 +13,15 @@ module Enumerable[unchecked out Elem]
|
|
16
13
|
| [U] () { (Elem) -> U } -> Array[U]
|
17
14
|
| ...
|
18
15
|
end
|
16
|
+
|
17
|
+
module Bundler
|
18
|
+
class LockfileParser
|
19
|
+
def initialize: (String) -> void
|
20
|
+
def specs: () -> Array[LazySpecification]
|
21
|
+
end
|
22
|
+
|
23
|
+
class LazySpecification
|
24
|
+
def name: () -> String
|
25
|
+
def version: () -> String
|
26
|
+
end
|
27
|
+
end
|
data/sig/repository.rbs
CHANGED
@@ -57,6 +57,10 @@ module RBS
|
|
57
57
|
|
58
58
|
attr_reader gems: Hash[String, GemRBS]
|
59
59
|
|
60
|
+
def self.default: () -> instance
|
61
|
+
|
62
|
+
def self.find_best_version: (Gem::Version? version, Array[Gem::Version] candidates) -> Gem::Version
|
63
|
+
|
60
64
|
# An optional keyword argument `no_stdlib` is to skip adding directory for stdlib classes.
|
61
65
|
# Passing truthy value will skip loading stdlib. (You can add the stdlib root by yourself.)
|
62
66
|
#
|
data/sig/types.rbs
CHANGED
@@ -13,7 +13,7 @@ module RBS
|
|
13
13
|
def sub: (Substitution) -> t
|
14
14
|
|
15
15
|
# Maps type names included in the type and returns new instance of type.
|
16
|
-
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> t
|
16
|
+
def map_type_name: () { (TypeName, Location[untyped, untyped]?, t) -> TypeName } -> t
|
17
17
|
|
18
18
|
# Yields all direct sub types included in the type.
|
19
19
|
# It doesn't yield the type itself.
|
@@ -58,16 +58,16 @@ module RBS
|
|
58
58
|
end
|
59
59
|
|
60
60
|
module NoTypeName
|
61
|
-
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> self
|
61
|
+
def map_type_name: () { (TypeName, Location[untyped, untyped]?, t) -> TypeName } -> self
|
62
62
|
end
|
63
63
|
|
64
64
|
module Bases
|
65
65
|
class Base
|
66
66
|
include _TypeBase
|
67
67
|
|
68
|
-
attr_reader location: Location?
|
68
|
+
attr_reader location: Location[bot, bot]?
|
69
69
|
|
70
|
-
def initialize: (location: Location?) -> void
|
70
|
+
def initialize: (location: Location[bot, bot]?) -> void
|
71
71
|
|
72
72
|
def ==: (untyped other) -> bool
|
73
73
|
|
@@ -111,6 +111,8 @@ module RBS
|
|
111
111
|
end
|
112
112
|
|
113
113
|
class Variable
|
114
|
+
type loc = Location[bot, bot]
|
115
|
+
|
114
116
|
attr_reader name: Symbol
|
115
117
|
|
116
118
|
@@count: Integer
|
@@ -119,9 +121,9 @@ module RBS
|
|
119
121
|
include NoTypeName
|
120
122
|
include EmptyEachType
|
121
123
|
|
122
|
-
def initialize: (name: Symbol, location:
|
124
|
+
def initialize: (name: Symbol, location: loc?) -> void
|
123
125
|
|
124
|
-
attr_reader location:
|
126
|
+
attr_reader location: loc?
|
125
127
|
|
126
128
|
def ==: (untyped other) -> bool
|
127
129
|
|
@@ -144,7 +146,7 @@ module RBS
|
|
144
146
|
class ClassSingleton
|
145
147
|
# singleton(::Foo)
|
146
148
|
# ^^^^^ => name
|
147
|
-
type loc = Location
|
149
|
+
type loc = Location[:name, bot]
|
148
150
|
|
149
151
|
def initialize: (name: TypeName, location: loc?) -> void
|
150
152
|
|
@@ -189,7 +191,7 @@ module RBS
|
|
189
191
|
# _Foo[Bar, Baz]
|
190
192
|
# ^^^^ => name
|
191
193
|
# ^^^^^^^^^^ => args
|
192
|
-
type loc = Location
|
194
|
+
type loc = Location[:name, :args]
|
193
195
|
|
194
196
|
def initialize: (name: TypeName, args: Array[t], location: loc?) -> void
|
195
197
|
|
@@ -214,7 +216,8 @@ module RBS
|
|
214
216
|
# Foo[Bar, Baz]
|
215
217
|
# ^^^ => name
|
216
218
|
# ^^^^^^^^^^ => args
|
217
|
-
|
219
|
+
#
|
220
|
+
type loc = Location[:name, :args]
|
218
221
|
|
219
222
|
def initialize: (name: TypeName, args: Array[t], location: loc?) -> void
|
220
223
|
|
@@ -226,54 +229,64 @@ module RBS
|
|
226
229
|
class Alias
|
227
230
|
attr_reader name: TypeName
|
228
231
|
|
229
|
-
|
232
|
+
type loc = Location[bot, bot]
|
233
|
+
|
234
|
+
def initialize: (name: TypeName, location: loc?) -> void
|
230
235
|
|
231
236
|
include _TypeBase
|
232
237
|
include NoFreeVariables
|
233
238
|
include NoSubst
|
234
239
|
include EmptyEachType
|
235
240
|
|
236
|
-
attr_reader location:
|
241
|
+
attr_reader location: loc?
|
237
242
|
end
|
238
243
|
|
239
244
|
class Tuple
|
240
245
|
attr_reader types: Array[t]
|
241
246
|
|
242
|
-
|
247
|
+
type loc = Location[bot, bot]
|
248
|
+
|
249
|
+
def initialize: (types: Array[t], location: loc?) -> void
|
243
250
|
|
244
251
|
include _TypeBase
|
245
252
|
|
246
|
-
attr_reader location:
|
253
|
+
attr_reader location: loc?
|
247
254
|
end
|
248
255
|
|
249
256
|
class Record
|
250
257
|
attr_reader fields: Hash[Symbol, t]
|
251
258
|
|
252
|
-
|
259
|
+
type loc = Location[bot, bot]
|
260
|
+
|
261
|
+
def initialize: (fields: Hash[Symbol, t], location: loc?) -> void
|
253
262
|
|
254
263
|
include _TypeBase
|
255
264
|
|
256
|
-
attr_reader location:
|
265
|
+
attr_reader location: loc?
|
257
266
|
end
|
258
267
|
|
259
268
|
class Optional
|
260
269
|
attr_reader type: t
|
261
270
|
|
262
|
-
|
271
|
+
type loc = Location[bot, bot]
|
272
|
+
|
273
|
+
def initialize: (type: t, location: loc?) -> void
|
263
274
|
|
264
275
|
include _TypeBase
|
265
276
|
|
266
|
-
attr_reader location:
|
277
|
+
attr_reader location: loc?
|
267
278
|
end
|
268
279
|
|
269
280
|
class Union
|
270
281
|
attr_reader types: Array[t]
|
271
282
|
|
272
|
-
|
283
|
+
type loc = Location[bot, bot]
|
284
|
+
|
285
|
+
def initialize: (types: Array[t], location: loc?) -> void
|
273
286
|
|
274
287
|
include _TypeBase
|
275
288
|
|
276
|
-
attr_reader location:
|
289
|
+
attr_reader location: loc?
|
277
290
|
|
278
291
|
def map_type: () { (t) -> t } -> Union
|
279
292
|
| () -> Enumerator[t, Union]
|
@@ -282,11 +295,13 @@ module RBS
|
|
282
295
|
class Intersection
|
283
296
|
attr_reader types: Array[t]
|
284
297
|
|
285
|
-
|
298
|
+
type loc = Location[bot, bot]
|
299
|
+
|
300
|
+
def initialize: (types: Array[t], location: loc?) -> void
|
286
301
|
|
287
302
|
include _TypeBase
|
288
303
|
|
289
|
-
attr_reader location:
|
304
|
+
attr_reader location: loc?
|
290
305
|
|
291
306
|
def map_type: () { (t) -> t } -> Intersection
|
292
307
|
| () -> Enumerator[t, Intersection]
|
@@ -294,7 +309,7 @@ module RBS
|
|
294
309
|
|
295
310
|
class Function
|
296
311
|
class Param
|
297
|
-
type loc = Location
|
312
|
+
type loc = Location[bot, :name]
|
298
313
|
|
299
314
|
attr_reader type: t
|
300
315
|
attr_reader name: Symbol?
|
@@ -329,7 +344,7 @@ module RBS
|
|
329
344
|
def map_type: { (t) -> t } -> Function
|
330
345
|
| -> Enumerator[t, Function]
|
331
346
|
|
332
|
-
def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> Function
|
347
|
+
def map_type_name: () { (TypeName, Location[untyped, untyped]?, t) -> TypeName } -> Function
|
333
348
|
|
334
349
|
def each_type: () { (t) -> void } -> void
|
335
350
|
| -> Enumerator[t, void]
|
@@ -384,19 +399,22 @@ module RBS
|
|
384
399
|
attr_reader type: Function
|
385
400
|
attr_reader block: Block?
|
386
401
|
|
387
|
-
|
402
|
+
type loc = Location[bot, bot]
|
403
|
+
|
404
|
+
def initialize: (location: loc?, type: Function, block: Block?) -> void
|
388
405
|
|
389
406
|
include _TypeBase
|
390
407
|
|
391
|
-
attr_reader location:
|
408
|
+
attr_reader location: loc?
|
392
409
|
end
|
393
410
|
|
394
411
|
class Literal
|
395
412
|
type literal = String | Integer | Symbol | TrueClass | FalseClass
|
413
|
+
type loc = Location[bot, bot]
|
396
414
|
|
397
415
|
attr_reader literal: literal
|
398
416
|
|
399
|
-
def initialize: (literal: literal, location:
|
417
|
+
def initialize: (literal: literal, location: loc?) -> void
|
400
418
|
|
401
419
|
include _TypeBase
|
402
420
|
include NoFreeVariables
|
@@ -404,7 +422,7 @@ module RBS
|
|
404
422
|
include EmptyEachType
|
405
423
|
include NoTypeName
|
406
424
|
|
407
|
-
attr_reader location:
|
425
|
+
attr_reader location: loc?
|
408
426
|
end
|
409
427
|
end
|
410
428
|
end
|
data/sig/writer.rbs
CHANGED
@@ -38,7 +38,7 @@ module RBS
|
|
38
38
|
def attribute: (:reader | :writer | :accessor, AST::Members::Attribute) -> void
|
39
39
|
|
40
40
|
interface _Located
|
41
|
-
def location: () -> Location?
|
41
|
+
def location: () -> Location[untyped, untyped]?
|
42
42
|
end
|
43
43
|
|
44
44
|
def preserve_empty_line: (_Located?, _Located) -> void
|
data/stdlib/json/0/json.rbs
CHANGED
@@ -512,7 +512,7 @@ class Range[out Elem]
|
|
512
512
|
# Deserializes JSON string by constructing new Range object with arguments `a`
|
513
513
|
# serialized by `to_json`.
|
514
514
|
#
|
515
|
-
def self.json_create: (Hash[String, String | [
|
515
|
+
def self.json_create: [A] (Hash[String, String | [A, A, bool]] object) -> Range[A]
|
516
516
|
|
517
517
|
# Returns a hash, that will be turned into a JSON object and represent this
|
518
518
|
# object.
|
@@ -565,7 +565,7 @@ class Set[A]
|
|
565
565
|
#
|
566
566
|
# method used for JSON marshalling support.
|
567
567
|
#
|
568
|
-
def self.json_create: (Hash[String, String | Array[A]] object) ->
|
568
|
+
def self.json_create: [A] (Hash[String, String | Array[A]] object) -> Set[A]
|
569
569
|
|
570
570
|
# Marshal the object to JSON.
|
571
571
|
#
|
@@ -582,7 +582,7 @@ class Struct[Elem]
|
|
582
582
|
# Deserializes JSON string by constructing new Struct object with values `v`
|
583
583
|
# serialized by `to_json`.
|
584
584
|
#
|
585
|
-
def self.json_create: (Hash[String, String | Array[Elem]] object) ->
|
585
|
+
def self.json_create: [Elem] (Hash[String, String | Array[Elem]] object) -> Struct[Elem]
|
586
586
|
|
587
587
|
# Returns a hash, that will be turned into a JSON object and represent this
|
588
588
|
# object.
|
@@ -0,0 +1,406 @@
|
|
1
|
+
# The objspace library extends the ObjectSpace module and adds several methods
|
2
|
+
# to get internal statistic information about object/memory management.
|
3
|
+
#
|
4
|
+
# You need to `require 'objspace'` to use this extension module.
|
5
|
+
#
|
6
|
+
# Generally, you *SHOULD NOT* use this library if you do not know about the MRI
|
7
|
+
# implementation. Mainly, this library is for (memory) profiler developers and
|
8
|
+
# MRI developers who need to know about MRI memory usage.
|
9
|
+
# The ObjectSpace module contains a number of routines that interact with the
|
10
|
+
# garbage collection facility and allow you to traverse all living objects with
|
11
|
+
# an iterator.
|
12
|
+
#
|
13
|
+
# ObjectSpace also provides support for object finalizers, procs that will be
|
14
|
+
# called when a specific object is about to be destroyed by garbage collection.
|
15
|
+
# See the documentation for `ObjectSpace.define_finalizer` for important
|
16
|
+
# information on how to use this method correctly.
|
17
|
+
#
|
18
|
+
# a = "A"
|
19
|
+
# b = "B"
|
20
|
+
#
|
21
|
+
# ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
|
22
|
+
# ObjectSpace.define_finalizer(b, proc {|id| puts "Finalizer two on #{id}" })
|
23
|
+
#
|
24
|
+
# a = nil
|
25
|
+
# b = nil
|
26
|
+
#
|
27
|
+
# *produces:*
|
28
|
+
#
|
29
|
+
# Finalizer two on 537763470
|
30
|
+
# Finalizer one on 537763480
|
31
|
+
module ObjectSpace
|
32
|
+
# Returns the class for the given `object`.
|
33
|
+
#
|
34
|
+
# class A
|
35
|
+
# def foo
|
36
|
+
# ObjectSpace::trace_object_allocations do
|
37
|
+
# obj = Object.new
|
38
|
+
# p "#{ObjectSpace::allocation_class_path(obj)}"
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# A.new.foo #=> "Class"
|
44
|
+
#
|
45
|
+
# See ::trace_object_allocations for more information and examples.
|
46
|
+
#
|
47
|
+
def self.allocation_class_path: (untyped) -> String
|
48
|
+
|
49
|
+
# Returns garbage collector generation for the given `object`.
|
50
|
+
#
|
51
|
+
# class B
|
52
|
+
# include ObjectSpace
|
53
|
+
#
|
54
|
+
# def foo
|
55
|
+
# trace_object_allocations do
|
56
|
+
# obj = Object.new
|
57
|
+
# p "Generation is #{allocation_generation(obj)}"
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# B.new.foo #=> "Generation is 3"
|
63
|
+
#
|
64
|
+
# See ::trace_object_allocations for more information and examples.
|
65
|
+
#
|
66
|
+
def self.allocation_generation: (untyped) -> (Integer | nil)
|
67
|
+
|
68
|
+
# Returns the method identifier for the given `object`.
|
69
|
+
#
|
70
|
+
# class A
|
71
|
+
# include ObjectSpace
|
72
|
+
#
|
73
|
+
# def foo
|
74
|
+
# trace_object_allocations do
|
75
|
+
# obj = Object.new
|
76
|
+
# p "#{allocation_class_path(obj)}##{allocation_method_id(obj)}"
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# A.new.foo #=> "Class#new"
|
82
|
+
#
|
83
|
+
# See ::trace_object_allocations for more information and examples.
|
84
|
+
#
|
85
|
+
def self.allocation_method_id: (untyped) -> Symbol
|
86
|
+
|
87
|
+
# Returns the source file origin from the given `object`.
|
88
|
+
#
|
89
|
+
# See ::trace_object_allocations for more information and examples.
|
90
|
+
#
|
91
|
+
def self.allocation_sourcefile: (untyped) -> String
|
92
|
+
|
93
|
+
# Returns the original line from source for from the given `object`.
|
94
|
+
#
|
95
|
+
# See ::trace_object_allocations for more information and examples.
|
96
|
+
#
|
97
|
+
def self.allocation_sourceline: (untyped) -> Integer
|
98
|
+
|
99
|
+
# Counts objects for each `T_IMEMO` type.
|
100
|
+
#
|
101
|
+
# This method is only for MRI developers interested in performance and memory
|
102
|
+
# usage of Ruby programs.
|
103
|
+
#
|
104
|
+
# It returns a hash as:
|
105
|
+
#
|
106
|
+
# {:imemo_ifunc=>8,
|
107
|
+
# :imemo_svar=>7,
|
108
|
+
# :imemo_cref=>509,
|
109
|
+
# :imemo_memo=>1,
|
110
|
+
# :imemo_throw_data=>1}
|
111
|
+
#
|
112
|
+
# If the optional argument, result_hash, is given, it is overwritten and
|
113
|
+
# returned. This is intended to avoid probe effect.
|
114
|
+
#
|
115
|
+
# The contents of the returned hash is implementation specific and may change in
|
116
|
+
# the future.
|
117
|
+
#
|
118
|
+
# In this version, keys are symbol objects.
|
119
|
+
#
|
120
|
+
# This method is only expected to work with C Ruby.
|
121
|
+
#
|
122
|
+
def self.count_imemo_objects: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
|
123
|
+
|
124
|
+
# Counts nodes for each node type.
|
125
|
+
#
|
126
|
+
# This method is only for MRI developers interested in performance and memory
|
127
|
+
# usage of Ruby programs.
|
128
|
+
#
|
129
|
+
# It returns a hash as:
|
130
|
+
#
|
131
|
+
# {:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
|
132
|
+
#
|
133
|
+
# If the optional argument, result_hash, is given, it is overwritten and
|
134
|
+
# returned. This is intended to avoid probe effect.
|
135
|
+
#
|
136
|
+
# Note: The contents of the returned hash is implementation defined. It may be
|
137
|
+
# changed in future.
|
138
|
+
#
|
139
|
+
# This method is only expected to work with C Ruby.
|
140
|
+
#
|
141
|
+
def self.count_nodes: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
|
142
|
+
|
143
|
+
# Counts objects size (in bytes) for each type.
|
144
|
+
#
|
145
|
+
# Note that this information is incomplete. You need to deal with this
|
146
|
+
# information as only a **HINT**. Especially, total size of T_DATA may be
|
147
|
+
# wrong.
|
148
|
+
#
|
149
|
+
# It returns a hash as:
|
150
|
+
# {:TOTAL=>1461154, :T_CLASS=>158280, :T_MODULE=>20672, :T_STRING=>527249, ...}
|
151
|
+
#
|
152
|
+
# If the optional argument, result_hash, is given, it is overwritten and
|
153
|
+
# returned. This is intended to avoid probe effect.
|
154
|
+
#
|
155
|
+
# The contents of the returned hash is implementation defined. It may be changed
|
156
|
+
# in future.
|
157
|
+
#
|
158
|
+
# This method is only expected to work with C Ruby.
|
159
|
+
#
|
160
|
+
def self.count_objects_size: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
|
161
|
+
|
162
|
+
# Counts symbols for each Symbol type.
|
163
|
+
#
|
164
|
+
# This method is only for MRI developers interested in performance and memory
|
165
|
+
# usage of Ruby programs.
|
166
|
+
#
|
167
|
+
# If the optional argument, result_hash, is given, it is overwritten and
|
168
|
+
# returned. This is intended to avoid probe effect.
|
169
|
+
#
|
170
|
+
# Note: The contents of the returned hash is implementation defined. It may be
|
171
|
+
# changed in future.
|
172
|
+
#
|
173
|
+
# This method is only expected to work with C Ruby.
|
174
|
+
#
|
175
|
+
# On this version of MRI, they have 3 types of Symbols (and 1 total counts).
|
176
|
+
#
|
177
|
+
# * mortal_dynamic_symbol: GC target symbols (collected by GC)
|
178
|
+
# * immortal_dynamic_symbol: Immortal symbols promoted from dynamic symbols (do not collected by GC)
|
179
|
+
# * immortal_static_symbol: Immortal symbols (do not collected by GC)
|
180
|
+
# * immortal_symbol: total immortal symbols (immortal_dynamic_symbol+immortal_static_symbol)
|
181
|
+
#
|
182
|
+
def self.count_symbols: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
|
183
|
+
|
184
|
+
# Counts objects for each `T_DATA` type.
|
185
|
+
#
|
186
|
+
# This method is only for MRI developers interested in performance and memory
|
187
|
+
# usage of Ruby programs.
|
188
|
+
#
|
189
|
+
# It returns a hash as:
|
190
|
+
#
|
191
|
+
# {RubyVM::InstructionSequence=>504, :parser=>5, :barrier=>6,
|
192
|
+
# :mutex=>6, Proc=>60, RubyVM::Env=>57, Mutex=>1, Encoding=>99,
|
193
|
+
# ThreadGroup=>1, Binding=>1, Thread=>1, RubyVM=>1, :iseq=>1,
|
194
|
+
# Random=>1, ARGF.class=>1, Data=>1, :autoload=>3, Time=>2}
|
195
|
+
# # T_DATA objects existing at startup on r32276.
|
196
|
+
#
|
197
|
+
# If the optional argument, result_hash, is given, it is overwritten and
|
198
|
+
# returned. This is intended to avoid probe effect.
|
199
|
+
#
|
200
|
+
# The contents of the returned hash is implementation specific and may change in
|
201
|
+
# the future.
|
202
|
+
#
|
203
|
+
# In this version, keys are Class object or Symbol object.
|
204
|
+
#
|
205
|
+
# If object is kind of normal (accessible) object, the key is Class object. If
|
206
|
+
# object is not a kind of normal (internal) object, the key is symbol name,
|
207
|
+
# registered by rb_data_type_struct.
|
208
|
+
#
|
209
|
+
# This method is only expected to work with C Ruby.
|
210
|
+
#
|
211
|
+
def self.count_tdata_objects: (?Hash[untyped, Integer] result_hash) -> Hash[untyped, Integer]
|
212
|
+
|
213
|
+
def self.dump: (untyped obj, ?output: Symbol) -> (String | File | nil)
|
214
|
+
|
215
|
+
def self.dump_all: (?since: (Integer|nil), ?full: boolish, ?output: Symbol) -> (String | File | nil)
|
216
|
+
|
217
|
+
# MRI specific feature
|
218
|
+
# : Return internal class of obj.
|
219
|
+
#
|
220
|
+
# obj can be an instance of InternalObjectWrapper.
|
221
|
+
#
|
222
|
+
# Note that you should not use this method in your application.
|
223
|
+
#
|
224
|
+
def self.internal_class_of: (untyped) -> Class
|
225
|
+
|
226
|
+
# MRI specific feature
|
227
|
+
# : Return internal super class of cls (Class or Module).
|
228
|
+
#
|
229
|
+
# obj can be an instance of InternalObjectWrapper.
|
230
|
+
#
|
231
|
+
# Note that you should not use this method in your application.
|
232
|
+
#
|
233
|
+
def self.internal_super_of: (untyped) -> untyped
|
234
|
+
|
235
|
+
# Return consuming memory size of obj in bytes.
|
236
|
+
#
|
237
|
+
# Note that the return size is incomplete. You need to deal with this
|
238
|
+
# information as only a **HINT**. Especially, the size of `T_DATA` may not be
|
239
|
+
# correct.
|
240
|
+
#
|
241
|
+
# This method is only expected to work with C Ruby.
|
242
|
+
#
|
243
|
+
# From Ruby 2.2, memsize_of(obj) returns a memory size includes sizeof(RVALUE).
|
244
|
+
#
|
245
|
+
def self.memsize_of: (untyped) -> Integer
|
246
|
+
|
247
|
+
# Return consuming memory size of all living objects in bytes.
|
248
|
+
#
|
249
|
+
# If `klass` (should be Class object) is given, return the total memory size of
|
250
|
+
# instances of the given class.
|
251
|
+
#
|
252
|
+
# Note that the returned size is incomplete. You need to deal with this
|
253
|
+
# information as only a **HINT**. Especially, the size of `T_DATA` may not be
|
254
|
+
# correct.
|
255
|
+
#
|
256
|
+
# Note that this method does **NOT** return total malloc'ed memory size.
|
257
|
+
#
|
258
|
+
# This method can be defined by the following Ruby code:
|
259
|
+
#
|
260
|
+
# def memsize_of_all klass = false
|
261
|
+
# total = 0
|
262
|
+
# ObjectSpace.each_object{|e|
|
263
|
+
# total += ObjectSpace.memsize_of(e) if klass == false || e.kind_of?(klass)
|
264
|
+
# }
|
265
|
+
# total
|
266
|
+
# end
|
267
|
+
#
|
268
|
+
# This method is only expected to work with C Ruby.
|
269
|
+
#
|
270
|
+
def self.memsize_of_all: (?Class) -> Integer
|
271
|
+
|
272
|
+
# MRI specific feature
|
273
|
+
# : Return all reachable objects from `obj'.
|
274
|
+
#
|
275
|
+
#
|
276
|
+
# This method returns all reachable objects from `obj'.
|
277
|
+
#
|
278
|
+
# If `obj' has two or more references to the same object `x', then returned
|
279
|
+
# array only includes one `x' object.
|
280
|
+
#
|
281
|
+
# If `obj' is a non-markable (non-heap management) object such as true, false,
|
282
|
+
# nil, symbols and Fixnums (and Flonum) then it simply returns nil.
|
283
|
+
#
|
284
|
+
# If `obj' has references to an internal object, then it returns instances of
|
285
|
+
# ObjectSpace::InternalObjectWrapper class. This object contains a reference to
|
286
|
+
# an internal object and you can check the type of internal object with `type'
|
287
|
+
# method.
|
288
|
+
#
|
289
|
+
# If `obj' is instance of ObjectSpace::InternalObjectWrapper class, then this
|
290
|
+
# method returns all reachable object from an internal object, which is pointed
|
291
|
+
# by `obj'.
|
292
|
+
#
|
293
|
+
# With this method, you can find memory leaks.
|
294
|
+
#
|
295
|
+
# This method is only expected to work except with C Ruby.
|
296
|
+
#
|
297
|
+
# Example:
|
298
|
+
# ObjectSpace.reachable_objects_from(['a', 'b', 'c'])
|
299
|
+
# #=> [Array, 'a', 'b', 'c']
|
300
|
+
#
|
301
|
+
# ObjectSpace.reachable_objects_from(['a', 'a', 'a'])
|
302
|
+
# #=> [Array, 'a', 'a', 'a'] # all 'a' strings have different object id
|
303
|
+
#
|
304
|
+
# ObjectSpace.reachable_objects_from([v = 'a', v, v])
|
305
|
+
# #=> [Array, 'a']
|
306
|
+
#
|
307
|
+
# ObjectSpace.reachable_objects_from(1)
|
308
|
+
# #=> nil # 1 is not markable (heap managed) object
|
309
|
+
#
|
310
|
+
def self.reachable_objects_from: (untyped) -> ([ untyped ] | nil)
|
311
|
+
|
312
|
+
# MRI specific feature
|
313
|
+
# : Return all reachable objects from root.
|
314
|
+
#
|
315
|
+
#
|
316
|
+
def self.reachable_objects_from_root: () -> Hash[String, untyped]
|
317
|
+
|
318
|
+
# Starts tracing object allocations from the ObjectSpace extension module.
|
319
|
+
#
|
320
|
+
# For example:
|
321
|
+
#
|
322
|
+
# require 'objspace'
|
323
|
+
#
|
324
|
+
# class C
|
325
|
+
# include ObjectSpace
|
326
|
+
#
|
327
|
+
# def foo
|
328
|
+
# trace_object_allocations do
|
329
|
+
# obj = Object.new
|
330
|
+
# p "#{allocation_sourcefile(obj)}:#{allocation_sourceline(obj)}"
|
331
|
+
# end
|
332
|
+
# end
|
333
|
+
# end
|
334
|
+
#
|
335
|
+
# C.new.foo #=> "objtrace.rb:8"
|
336
|
+
#
|
337
|
+
# This example has included the ObjectSpace module to make it easier to read,
|
338
|
+
# but you can also use the ::trace_object_allocations notation (recommended).
|
339
|
+
#
|
340
|
+
# Note that this feature introduces a huge performance decrease and huge memory
|
341
|
+
# consumption.
|
342
|
+
#
|
343
|
+
def self.trace_object_allocations: () { (untyped) -> untyped } -> untyped
|
344
|
+
|
345
|
+
# Clear recorded tracing information.
|
346
|
+
#
|
347
|
+
def self.trace_object_allocations_clear: () -> void
|
348
|
+
|
349
|
+
def self.trace_object_allocations_debug_start: () -> void
|
350
|
+
|
351
|
+
# Starts tracing object allocations.
|
352
|
+
#
|
353
|
+
def self.trace_object_allocations_start: () -> void
|
354
|
+
|
355
|
+
# Stop tracing object allocations.
|
356
|
+
#
|
357
|
+
# Note that if ::trace_object_allocations_start is called n-times, then tracing
|
358
|
+
# will stop after calling ::trace_object_allocations_stop n-times.
|
359
|
+
#
|
360
|
+
def self.trace_object_allocations_stop: () -> void
|
361
|
+
|
362
|
+
private
|
363
|
+
|
364
|
+
# Dump the contents of a ruby object as JSON.
|
365
|
+
#
|
366
|
+
# This method is only expected to work with C Ruby. This is an experimental
|
367
|
+
# method and is subject to change. In particular, the function signature and
|
368
|
+
# output format are not guaranteed to be compatible in future versions of ruby.
|
369
|
+
#
|
370
|
+
def dump: (untyped obj, ?output: Symbol) -> (String|File|nil)
|
371
|
+
|
372
|
+
# Dump the contents of the ruby heap as JSON.
|
373
|
+
#
|
374
|
+
# *since* must be a non-negative integer or `nil`.
|
375
|
+
#
|
376
|
+
# If *since* is a positive integer, only objects of that generation and newer
|
377
|
+
# generations are dumped. The current generation can be accessed using
|
378
|
+
# GC::count.
|
379
|
+
#
|
380
|
+
# Objects that were allocated without object allocation tracing enabled are
|
381
|
+
# ignored. See ::trace_object_allocations for more information and examples.
|
382
|
+
#
|
383
|
+
# If *since* is omitted or is `nil`, all objects are dumped.
|
384
|
+
#
|
385
|
+
# This method is only expected to work with C Ruby. This is an experimental
|
386
|
+
# method and is subject to change. In particular, the function signature and
|
387
|
+
# output format are not guaranteed to be compatible in future versions of ruby.
|
388
|
+
#
|
389
|
+
def dump_all: (?since: (Integer|nil), ?full: boolish, ?output: Symbol) -> (String|File|nil)
|
390
|
+
|
391
|
+
def memsize_of: (untyped) -> Integer
|
392
|
+
|
393
|
+
def memsize_of_all: (?class) -> Integer
|
394
|
+
|
395
|
+
def reachable_objects_from: (untyped) -> ([ untyped ] | nil)
|
396
|
+
|
397
|
+
def reachable_objects_from_root: () -> Hash[String, untyped]
|
398
|
+
|
399
|
+
def trace_object_allocations_clear: () -> void
|
400
|
+
|
401
|
+
def trace_object_allocations_debug_start: () -> void
|
402
|
+
|
403
|
+
def trace_object_allocations_start: () -> void
|
404
|
+
|
405
|
+
def trace_object_allocations_stop: () -> void
|
406
|
+
end
|