rbs 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +7 -1
- data/.gitignore +1 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +12 -0
- data/README.md +86 -47
- data/Rakefile +54 -21
- data/bin/rbs-prof +9 -0
- data/bin/run_in_md.rb +49 -0
- data/lib/rbs.rb +2 -0
- data/lib/rbs/ast/declarations.rb +62 -7
- data/lib/rbs/ast/members.rb +41 -17
- data/lib/rbs/cli.rb +299 -121
- data/lib/rbs/constant.rb +4 -4
- data/lib/rbs/constant_table.rb +50 -44
- data/lib/rbs/definition.rb +175 -59
- data/lib/rbs/definition_builder.rb +647 -603
- data/lib/rbs/environment.rb +338 -209
- data/lib/rbs/environment_walker.rb +14 -23
- data/lib/rbs/errors.rb +141 -3
- data/lib/rbs/parser.y +14 -9
- data/lib/rbs/prototype/rb.rb +100 -112
- data/lib/rbs/prototype/rbi.rb +4 -2
- data/lib/rbs/prototype/runtime.rb +10 -6
- data/lib/rbs/substitution.rb +8 -1
- data/lib/rbs/test/hook.rb +2 -2
- data/lib/rbs/test/setup.rb +3 -1
- data/lib/rbs/test/test_helper.rb +2 -5
- data/lib/rbs/test/type_check.rb +1 -2
- data/lib/rbs/type_name_resolver.rb +58 -0
- data/lib/rbs/types.rb +94 -2
- data/lib/rbs/validator.rb +51 -0
- data/lib/rbs/variance_calculator.rb +12 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +125 -89
- data/rbs.gemspec +0 -10
- data/schema/decls.json +15 -0
- data/schema/members.json +3 -0
- data/stdlib/benchmark/benchmark.rbs +151 -151
- data/stdlib/builtin/enumerable.rbs +1 -1
- data/stdlib/builtin/file.rbs +0 -3
- data/stdlib/builtin/io.rbs +4 -4
- data/stdlib/builtin/thread.rbs +2 -2
- data/stdlib/csv/csv.rbs +4 -6
- data/stdlib/fiber/fiber.rbs +1 -1
- data/stdlib/json/json.rbs +1 -1
- data/stdlib/mutex_m/mutex_m.rbs +77 -0
- data/stdlib/pathname/pathname.rbs +6 -6
- data/stdlib/prime/integer-extension.rbs +1 -1
- data/stdlib/prime/prime.rbs +44 -44
- data/stdlib/tmpdir/tmpdir.rbs +1 -1
- metadata +8 -129
@@ -107,9 +107,19 @@ module RBS
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
when Types::ClassInstance, Types::Interface
|
110
|
-
|
110
|
+
NoTypeFoundError.check!(type.name,
|
111
|
+
env: env,
|
112
|
+
location: type.location)
|
113
|
+
|
114
|
+
type_params = case type
|
115
|
+
when Types::ClassInstance
|
116
|
+
env.class_decls[type.name]&.type_params
|
117
|
+
when Types::Interface
|
118
|
+
env.interface_decls[type.name]&.decl&.type_params
|
119
|
+
end
|
120
|
+
|
111
121
|
type.args.each.with_index do |ty, i|
|
112
|
-
var =
|
122
|
+
var = type_params.params[i]
|
113
123
|
case var.variance
|
114
124
|
when :invariant
|
115
125
|
type(ty, result: result, context: :invariant)
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs/writer.rb
CHANGED
@@ -1,37 +1,59 @@
|
|
1
1
|
module RBS
|
2
2
|
class Writer
|
3
3
|
attr_reader :out
|
4
|
+
attr_reader :indentation
|
4
5
|
|
5
6
|
def initialize(out:)
|
6
7
|
@out = out
|
8
|
+
@indentation = []
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
+
def indent(size = 2)
|
12
|
+
indentation.push(" " * size)
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
indentation.pop
|
16
|
+
end
|
17
|
+
|
18
|
+
def prefix
|
19
|
+
indentation.join()
|
20
|
+
end
|
21
|
+
|
22
|
+
def puts(string = "")
|
23
|
+
if string.size > 0
|
24
|
+
@out.puts("#{prefix}#{string}")
|
25
|
+
else
|
26
|
+
@out.puts
|
27
|
+
end
|
28
|
+
end
|
11
29
|
|
30
|
+
def write_annotation(annotations)
|
12
31
|
annotations.each do |annotation|
|
13
32
|
string = annotation.string
|
14
33
|
case
|
15
34
|
when string !~ /\}/
|
16
|
-
|
35
|
+
puts "%a{#{string}}"
|
17
36
|
when string !~ /\)/
|
18
|
-
|
37
|
+
puts "%a(#{string})"
|
19
38
|
when string !~ /\]/
|
20
|
-
|
39
|
+
puts "%a[#{string}]"
|
21
40
|
when string !~ /\>/
|
22
|
-
|
41
|
+
puts "%a<#{string}>"
|
23
42
|
when string !~ /\|/
|
24
|
-
|
43
|
+
puts "%a|#{string}|"
|
25
44
|
end
|
26
45
|
end
|
27
46
|
end
|
28
47
|
|
29
|
-
def write_comment(comment
|
48
|
+
def write_comment(comment)
|
30
49
|
if comment
|
31
|
-
prefix = " " * level
|
32
50
|
comment.string.lines.each do |line|
|
33
|
-
line =
|
34
|
-
|
51
|
+
line = line.chomp
|
52
|
+
unless line.empty?
|
53
|
+
puts "# #{line}"
|
54
|
+
else
|
55
|
+
puts "#"
|
56
|
+
end
|
35
57
|
end
|
36
58
|
end
|
37
59
|
end
|
@@ -49,68 +71,72 @@ module RBS
|
|
49
71
|
super_class = if decl.super_class
|
50
72
|
" < #{name_and_args(decl.super_class.name, decl.super_class.args)}"
|
51
73
|
end
|
52
|
-
write_comment decl.comment
|
53
|
-
write_annotation decl.annotations
|
54
|
-
|
74
|
+
write_comment decl.comment
|
75
|
+
write_annotation decl.annotations
|
76
|
+
puts "class #{name_and_params(decl.name, decl.type_params)}#{super_class}"
|
55
77
|
|
56
|
-
|
57
|
-
|
58
|
-
|
78
|
+
indent do
|
79
|
+
[nil, *decl.members].each_cons(2) do |prev, member|
|
80
|
+
preserve_empty_line prev, member
|
81
|
+
write_member member
|
82
|
+
end
|
59
83
|
end
|
60
84
|
|
61
|
-
|
85
|
+
puts "end"
|
62
86
|
|
63
87
|
when AST::Declarations::Module
|
64
88
|
self_type = if decl.self_type
|
65
89
|
" : #{decl.self_type}"
|
66
90
|
end
|
67
91
|
|
68
|
-
write_comment decl.comment
|
69
|
-
write_annotation decl.annotations
|
70
|
-
|
71
|
-
decl.
|
72
|
-
|
73
|
-
|
92
|
+
write_comment decl.comment
|
93
|
+
write_annotation decl.annotations
|
94
|
+
|
95
|
+
puts "module #{name_and_params(decl.name, decl.type_params)}#{self_type}"
|
96
|
+
|
97
|
+
indent do
|
98
|
+
decl.members.each.with_index do |member, index|
|
99
|
+
if index > 0
|
100
|
+
puts
|
101
|
+
end
|
102
|
+
write_member member
|
74
103
|
end
|
75
|
-
write_member member
|
76
104
|
end
|
77
|
-
|
105
|
+
|
106
|
+
puts "end"
|
78
107
|
when AST::Declarations::Constant
|
79
|
-
write_comment decl.comment
|
80
|
-
|
108
|
+
write_comment decl.comment
|
109
|
+
puts "#{decl.name}: #{decl.type}"
|
81
110
|
|
82
111
|
when AST::Declarations::Global
|
83
|
-
write_comment decl.comment
|
84
|
-
|
112
|
+
write_comment decl.comment
|
113
|
+
puts "#{decl.name}: #{decl.type}"
|
85
114
|
|
86
115
|
when AST::Declarations::Alias
|
87
|
-
write_comment decl.comment
|
88
|
-
write_annotation decl.annotations
|
89
|
-
|
116
|
+
write_comment decl.comment
|
117
|
+
write_annotation decl.annotations
|
118
|
+
puts "type #{decl.name} = #{decl.type}"
|
90
119
|
|
91
120
|
when AST::Declarations::Interface
|
92
|
-
write_comment decl.comment
|
93
|
-
write_annotation decl.annotations
|
94
|
-
|
95
|
-
decl.
|
96
|
-
|
97
|
-
|
121
|
+
write_comment decl.comment
|
122
|
+
write_annotation decl.annotations
|
123
|
+
|
124
|
+
puts "interface #{name_and_params(decl.name, decl.type_params)}"
|
125
|
+
|
126
|
+
indent do
|
127
|
+
decl.members.each.with_index do |member, index|
|
128
|
+
if index > 0
|
129
|
+
puts
|
130
|
+
end
|
131
|
+
write_member member
|
98
132
|
end
|
99
|
-
write_member member
|
100
133
|
end
|
101
|
-
|
134
|
+
|
135
|
+
puts "end"
|
102
136
|
|
103
137
|
when AST::Declarations::Extension
|
104
|
-
|
105
|
-
|
106
|
-
out.puts "extension #{name_and_args(decl.name, decl.type_params)} (#{decl.extension_name})"
|
107
|
-
decl.members.each.with_index do |member, index|
|
108
|
-
if index > 0
|
109
|
-
out.puts
|
110
|
-
end
|
111
|
-
write_member member
|
112
|
-
end
|
113
|
-
out.puts "end"
|
138
|
+
RBS.logger.warn "Extension is ignored: #{decl.name}"
|
139
|
+
|
114
140
|
end
|
115
141
|
end
|
116
142
|
|
@@ -151,52 +177,54 @@ module RBS
|
|
151
177
|
def write_member(member)
|
152
178
|
case member
|
153
179
|
when AST::Members::Include
|
154
|
-
write_comment member.comment
|
155
|
-
write_annotation member.annotations
|
156
|
-
|
180
|
+
write_comment member.comment
|
181
|
+
write_annotation member.annotations
|
182
|
+
puts "include #{name_and_args(member.name, member.args)}"
|
157
183
|
when AST::Members::Extend
|
158
|
-
write_comment member.comment
|
159
|
-
write_annotation member.annotations
|
160
|
-
|
184
|
+
write_comment member.comment
|
185
|
+
write_annotation member.annotations
|
186
|
+
puts "extend #{name_and_args(member.name, member.args)}"
|
161
187
|
when AST::Members::Prepend
|
162
|
-
write_comment member.comment
|
163
|
-
write_annotation member.annotations
|
164
|
-
|
188
|
+
write_comment member.comment
|
189
|
+
write_annotation member.annotations
|
190
|
+
puts "prepend #{name_and_args(member.name, member.args)}"
|
165
191
|
when AST::Members::AttrAccessor
|
166
|
-
write_comment member.comment
|
167
|
-
write_annotation member.annotations
|
168
|
-
|
192
|
+
write_comment member.comment
|
193
|
+
write_annotation member.annotations
|
194
|
+
puts "#{attribute(:accessor, member)}"
|
169
195
|
when AST::Members::AttrReader
|
170
|
-
write_comment member.comment
|
171
|
-
write_annotation member.annotations
|
172
|
-
|
196
|
+
write_comment member.comment
|
197
|
+
write_annotation member.annotations
|
198
|
+
puts "#{attribute(:reader, member)}"
|
173
199
|
when AST::Members::AttrWriter
|
174
|
-
write_comment member.comment
|
175
|
-
write_annotation member.annotations
|
176
|
-
|
200
|
+
write_comment member.comment
|
201
|
+
write_annotation member.annotations
|
202
|
+
puts "#{attribute(:writer, member)}"
|
177
203
|
when AST::Members::Public
|
178
|
-
|
204
|
+
puts "public"
|
179
205
|
when AST::Members::Private
|
180
|
-
|
206
|
+
puts "private"
|
181
207
|
when AST::Members::Alias
|
182
|
-
write_comment member.comment
|
183
|
-
write_annotation member.annotations
|
208
|
+
write_comment member.comment
|
209
|
+
write_annotation member.annotations
|
184
210
|
new_name = member.singleton? ? "self.#{member.new_name}" : member.new_name
|
185
211
|
old_name = member.singleton? ? "self.#{member.old_name}" : member.old_name
|
186
|
-
|
212
|
+
puts "alias #{new_name} #{old_name}"
|
187
213
|
when AST::Members::InstanceVariable
|
188
|
-
write_comment member.comment
|
189
|
-
|
214
|
+
write_comment member.comment
|
215
|
+
puts "#{member.name}: #{member.type}"
|
190
216
|
when AST::Members::ClassInstanceVariable
|
191
|
-
write_comment member.comment
|
192
|
-
|
217
|
+
write_comment member.comment
|
218
|
+
puts "self.#{member.name}: #{member.type}"
|
193
219
|
when AST::Members::ClassVariable
|
194
|
-
write_comment member.comment
|
195
|
-
|
220
|
+
write_comment member.comment
|
221
|
+
puts "#{member.name}: #{member.type}"
|
196
222
|
when AST::Members::MethodDefinition
|
197
|
-
write_comment member.comment
|
198
|
-
write_annotation member.annotations
|
223
|
+
write_comment member.comment
|
224
|
+
write_annotation member.annotations
|
199
225
|
write_def member
|
226
|
+
else
|
227
|
+
write_decl member
|
200
228
|
end
|
201
229
|
end
|
202
230
|
|
@@ -220,18 +248,26 @@ module RBS
|
|
220
248
|
"self.#{method_name(member.name)}"
|
221
249
|
end
|
222
250
|
|
251
|
+
string = ""
|
252
|
+
|
223
253
|
attrs = member.attributes.empty? ? "" : member.attributes.join(" ") + " "
|
224
|
-
|
254
|
+
overload = member.overload? ? "overload " : ""
|
255
|
+
prefix = "#{overload}#{attrs}def #{name}:"
|
225
256
|
padding = " " * (prefix.size-1)
|
226
257
|
|
227
|
-
|
258
|
+
string << prefix
|
228
259
|
|
229
260
|
member.types.each.with_index do |type, index|
|
230
261
|
if index > 0
|
231
|
-
|
232
|
-
|
262
|
+
string << padding
|
263
|
+
string << "|"
|
233
264
|
end
|
234
|
-
|
265
|
+
|
266
|
+
string << " #{type}\n"
|
267
|
+
end
|
268
|
+
|
269
|
+
string.each_line do |line|
|
270
|
+
puts line.chomp
|
235
271
|
end
|
236
272
|
end
|
237
273
|
|
@@ -255,14 +291,14 @@ module RBS
|
|
255
291
|
# When the signature is not constructed by the parser,
|
256
292
|
# it always inserts an empty line.
|
257
293
|
if !prev.location || !decl.location
|
258
|
-
|
294
|
+
puts
|
259
295
|
return
|
260
296
|
end
|
261
297
|
|
262
298
|
prev_end_line = prev.location.end_line
|
263
299
|
start_line = decl.location.start_line
|
264
300
|
if start_line - prev_end_line > 1
|
265
|
-
|
301
|
+
puts
|
266
302
|
end
|
267
303
|
end
|
268
304
|
end
|
data/rbs.gemspec
CHANGED
@@ -34,14 +34,4 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.bindir = "exe"
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ["lib"]
|
37
|
-
|
38
|
-
spec.add_development_dependency "bundler"
|
39
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
40
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
41
|
-
spec.add_development_dependency "racc", "~> 1.4.16"
|
42
|
-
spec.add_development_dependency "rubocop"
|
43
|
-
spec.add_development_dependency "rubocop-rubycw"
|
44
|
-
spec.add_development_dependency "minitest-reporters", "~> 1.3.6"
|
45
|
-
spec.add_development_dependency "json", "~> 2.3.0"
|
46
|
-
spec.add_development_dependency "json-schema", "~> 2.8"
|
47
37
|
end
|
data/schema/decls.json
CHANGED
@@ -116,6 +116,21 @@
|
|
116
116
|
},
|
117
117
|
{
|
118
118
|
"$ref": "members.json#/definitions/alias"
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"$ref": "#/definitions/alias"
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"$ref": "#/definitions/constant"
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"$ref": "#/definitions/class"
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"$ref": "#/definitions/module"
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"$ref": "#/definitions/interface"
|
119
134
|
}
|
120
135
|
]
|
121
136
|
},
|
data/schema/members.json
CHANGED
@@ -139,7 +139,7 @@ module Benchmark
|
|
139
139
|
# >total: 2.930000 0.000000 2.930000 ( 2.932889)
|
140
140
|
# >avg: 0.976667 0.000000 0.976667 ( 0.977630)
|
141
141
|
#
|
142
|
-
def self?.benchmark: (String caption, ?Integer? label_width, ?String? format, *String labels) { (Report report) -> (Array[Tms] | void) } ->
|
142
|
+
def self?.benchmark: (String caption, ?Integer? label_width, ?String? format, *String labels) { (Report report) -> (Array[Tms] | void) } -> Array[Tms]
|
143
143
|
|
144
144
|
# A simple interface to the #benchmark method, #bm generates sequential reports
|
145
145
|
# with labels. `label_width` and `labels` parameters have the same meaning as
|
@@ -161,7 +161,7 @@ module Benchmark
|
|
161
161
|
# times: 0.960000 0.000000 0.960000 ( 0.960423)
|
162
162
|
# upto: 0.950000 0.000000 0.950000 ( 0.954864)
|
163
163
|
#
|
164
|
-
def self?.bm: (?Integer label_width, *String labels) { (Report report) -> void } ->
|
164
|
+
def self?.bm: (?Integer label_width, *String labels) { (Report report) -> void } -> Array[Tms]
|
165
165
|
|
166
166
|
# Sometimes benchmark results are skewed because code executed earlier
|
167
167
|
# encounters different garbage collection overheads than that run later. #bmbm
|
@@ -198,7 +198,7 @@ module Benchmark
|
|
198
198
|
# #bmbm yields a Benchmark::Job object and returns an array of Benchmark::Tms
|
199
199
|
# objects.
|
200
200
|
#
|
201
|
-
def self?.bmbm: (?Integer width) { (Job job) -> void } ->
|
201
|
+
def self?.bmbm: (?Integer width) { (Job job) -> void } -> Array[Tms]
|
202
202
|
|
203
203
|
# Returns the time used to execute the given block as a Benchmark::Tms object.
|
204
204
|
# Takes `label` option.
|
@@ -216,157 +216,157 @@ module Benchmark
|
|
216
216
|
#
|
217
217
|
# 0.220000 0.000000 0.220000 ( 0.227313)
|
218
218
|
#
|
219
|
-
def self?.measure: (?String label) { () -> void } ->
|
219
|
+
def self?.measure: (?String label) { () -> void } -> Tms
|
220
220
|
|
221
221
|
# Returns the elapsed real time used to execute the given block.
|
222
222
|
#
|
223
223
|
def self?.realtime: () { () -> void } -> Float
|
224
|
-
end
|
225
|
-
|
226
|
-
Benchmark::BENCHMARK_VERSION: String
|
227
|
-
|
228
|
-
# The default caption string (heading above the output times).
|
229
|
-
#
|
230
|
-
Benchmark::CAPTION: String
|
231
|
-
|
232
|
-
# The default format string used to display times. See also
|
233
|
-
# Benchmark::Tms#format.
|
234
|
-
#
|
235
|
-
Benchmark::FORMAT: String
|
236
|
-
|
237
|
-
class Benchmark::Job
|
238
|
-
# Prints the `label` and measured time for the block,
|
239
|
-
# formatted by `format`. See Tms#format for the
|
240
|
-
# formatting rules.
|
241
|
-
def item: (?String label) { () -> void } -> self
|
242
|
-
|
243
|
-
# An array of 2-element arrays, consisting of label and block pairs.
|
244
|
-
def list: () -> ::Array[untyped]
|
245
|
-
|
246
|
-
alias report item
|
247
|
-
|
248
|
-
# Length of the widest label in the #list.
|
249
|
-
def width: () -> Integer
|
250
|
-
end
|
251
|
-
|
252
|
-
class Benchmark::Report
|
253
|
-
# Prints the `label` and measured time for the block,
|
254
|
-
# formatted by `format`. See Tms#format for the
|
255
|
-
# formatting rules.
|
256
|
-
def item: (?String label, *untyped format) { () -> void } -> Tms
|
257
|
-
|
258
|
-
# An array of Benchmark::Tms objects representing each item.
|
259
|
-
def list: () -> ::Array[Benchmark::Tms]
|
260
|
-
|
261
|
-
alias report item
|
262
|
-
end
|
263
|
-
|
264
|
-
# A data object, representing the times associated with a benchmark measurement.
|
265
|
-
#
|
266
|
-
class Benchmark::Tms
|
267
|
-
# Returns a new Tms object obtained by memberwise multiplication of the
|
268
|
-
# individual times for this Tms object by `x`.
|
269
|
-
#
|
270
|
-
def *: (untyped x) -> untyped
|
271
|
-
|
272
|
-
# Returns a new Tms object obtained by memberwise summation of the individual
|
273
|
-
# times for this Tms object with those of the `other` Tms object. This method
|
274
|
-
# and #/() are useful for taking statistics.
|
275
|
-
#
|
276
|
-
def +: (untyped other) -> untyped
|
277
|
-
|
278
|
-
# Returns a new Tms object obtained by memberwise subtraction of the individual
|
279
|
-
# times for the `other` Tms object from those of this Tms object.
|
280
|
-
#
|
281
|
-
def -: (untyped other) -> untyped
|
282
|
-
|
283
|
-
# Returns a new Tms object obtained by memberwise division of the individual
|
284
|
-
# times for this Tms object by `x`. This method and #+() are useful for taking
|
285
|
-
# statistics.
|
286
|
-
#
|
287
|
-
def /: (untyped x) -> untyped
|
288
|
-
|
289
|
-
# Returns a new Tms object whose times are the sum of the times for this Tms
|
290
|
-
# object, plus the time required to execute the code block (`blk`).
|
291
|
-
#
|
292
|
-
def add: () { (*untyped) -> untyped } -> untyped
|
293
|
-
|
294
|
-
# An in-place version of #add. Changes the times of this Tms object by making it
|
295
|
-
# the sum of the times for this Tms object, plus the time required to execute
|
296
|
-
# the code block (`blk`).
|
297
|
-
#
|
298
|
-
def add!: () { (*untyped) -> untyped } -> untyped
|
299
|
-
|
300
|
-
# System CPU time of children
|
301
|
-
#
|
302
|
-
def cstime: () -> Float
|
303
|
-
|
304
|
-
# User CPU time of children
|
305
|
-
#
|
306
|
-
def cutime: () -> Float
|
307
|
-
|
308
|
-
# Returns the contents of this Tms object as a formatted string, according to a
|
309
|
-
# `format` string like that passed to Kernel.format. In addition, #format
|
310
|
-
# accepts the following extensions:
|
311
|
-
#
|
312
|
-
# `%u`
|
313
|
-
# : Replaced by the user CPU time, as reported by Tms#utime.
|
314
|
-
# `%y`
|
315
|
-
# : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
|
316
|
-
# "s*y*stem")
|
317
|
-
# `%U`
|
318
|
-
# : Replaced by the children's user CPU time, as reported by Tms#cutime
|
319
|
-
# `%Y`
|
320
|
-
# : Replaced by the children's system CPU time, as reported by Tms#cstime
|
321
|
-
# `%t`
|
322
|
-
# : Replaced by the total CPU time, as reported by Tms#total
|
323
|
-
# `%r`
|
324
|
-
# : Replaced by the elapsed real time, as reported by Tms#real
|
325
|
-
# `%n`
|
326
|
-
# : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
|
327
|
-
# "*n*ame")
|
328
|
-
#
|
329
|
-
#
|
330
|
-
# If `format` is not given, FORMAT is used as default value, detailing the user,
|
331
|
-
# system and real elapsed time.
|
332
|
-
#
|
333
|
-
def format: (?String format, *untyped args) -> String
|
334
|
-
|
335
|
-
# Label
|
336
|
-
#
|
337
|
-
def label: () -> String
|
338
|
-
|
339
|
-
# Elapsed real time
|
340
|
-
#
|
341
|
-
def real: () -> Float
|
342
224
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
#
|
350
|
-
#
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
225
|
+
BENCHMARK_VERSION: String
|
226
|
+
|
227
|
+
# The default caption string (heading above the output times).
|
228
|
+
#
|
229
|
+
CAPTION: String
|
230
|
+
|
231
|
+
# The default format string used to display times. See also
|
232
|
+
# Benchmark::Tms#format.
|
233
|
+
#
|
234
|
+
FORMAT: String
|
235
|
+
|
236
|
+
class Job
|
237
|
+
# Prints the `label` and measured time for the block,
|
238
|
+
# formatted by `format`. See Tms#format for the
|
239
|
+
# formatting rules.
|
240
|
+
def item: (?String label) { () -> void } -> self
|
241
|
+
|
242
|
+
# An array of 2-element arrays, consisting of label and block pairs.
|
243
|
+
def list: () -> Array[untyped]
|
244
|
+
|
245
|
+
alias report item
|
246
|
+
|
247
|
+
# Length of the widest label in the #list.
|
248
|
+
def width: () -> Integer
|
249
|
+
end
|
250
|
+
|
251
|
+
class Report
|
252
|
+
# Prints the `label` and measured time for the block,
|
253
|
+
# formatted by `format`. See Tms#format for the
|
254
|
+
# formatting rules.
|
255
|
+
def item: (?String label, *untyped format) { () -> void } -> Tms
|
256
|
+
|
257
|
+
# An array of Benchmark::Tms objects representing each item.
|
258
|
+
def list: () -> Array[Tms]
|
259
|
+
|
260
|
+
alias report item
|
261
|
+
end
|
262
|
+
|
263
|
+
# A data object, representing the times associated with a benchmark measurement.
|
264
|
+
#
|
265
|
+
class Tms
|
266
|
+
# Returns a new Tms object obtained by memberwise multiplication of the
|
267
|
+
# individual times for this Tms object by `x`.
|
268
|
+
#
|
269
|
+
def *: (untyped x) -> untyped
|
270
|
+
|
271
|
+
# Returns a new Tms object obtained by memberwise summation of the individual
|
272
|
+
# times for this Tms object with those of the `other` Tms object. This method
|
273
|
+
# and #/() are useful for taking statistics.
|
274
|
+
#
|
275
|
+
def +: (untyped other) -> untyped
|
276
|
+
|
277
|
+
# Returns a new Tms object obtained by memberwise subtraction of the individual
|
278
|
+
# times for the `other` Tms object from those of this Tms object.
|
279
|
+
#
|
280
|
+
def -: (untyped other) -> untyped
|
281
|
+
|
282
|
+
# Returns a new Tms object obtained by memberwise division of the individual
|
283
|
+
# times for this Tms object by `x`. This method and #+() are useful for taking
|
284
|
+
# statistics.
|
285
|
+
#
|
286
|
+
def /: (untyped x) -> untyped
|
287
|
+
|
288
|
+
# Returns a new Tms object whose times are the sum of the times for this Tms
|
289
|
+
# object, plus the time required to execute the code block (`blk`).
|
290
|
+
#
|
291
|
+
def add: () { (*untyped) -> untyped } -> untyped
|
292
|
+
|
293
|
+
# An in-place version of #add. Changes the times of this Tms object by making it
|
294
|
+
# the sum of the times for this Tms object, plus the time required to execute
|
295
|
+
# the code block (`blk`).
|
296
|
+
#
|
297
|
+
def add!: () { (*untyped) -> untyped } -> untyped
|
298
|
+
|
299
|
+
# System CPU time of children
|
300
|
+
#
|
301
|
+
def cstime: () -> Float
|
302
|
+
|
303
|
+
# User CPU time of children
|
304
|
+
#
|
305
|
+
def cutime: () -> Float
|
306
|
+
|
307
|
+
# Returns the contents of this Tms object as a formatted string, according to a
|
308
|
+
# `format` string like that passed to Kernel.format. In addition, #format
|
309
|
+
# accepts the following extensions:
|
310
|
+
#
|
311
|
+
# `%u`
|
312
|
+
# : Replaced by the user CPU time, as reported by Tms#utime.
|
313
|
+
# `%y`
|
314
|
+
# : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
|
315
|
+
# "s*y*stem")
|
316
|
+
# `%U`
|
317
|
+
# : Replaced by the children's user CPU time, as reported by Tms#cutime
|
318
|
+
# `%Y`
|
319
|
+
# : Replaced by the children's system CPU time, as reported by Tms#cstime
|
320
|
+
# `%t`
|
321
|
+
# : Replaced by the total CPU time, as reported by Tms#total
|
322
|
+
# `%r`
|
323
|
+
# : Replaced by the elapsed real time, as reported by Tms#real
|
324
|
+
# `%n`
|
325
|
+
# : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
|
326
|
+
# "*n*ame")
|
327
|
+
#
|
328
|
+
#
|
329
|
+
# If `format` is not given, FORMAT is used as default value, detailing the user,
|
330
|
+
# system and real elapsed time.
|
331
|
+
#
|
332
|
+
def format: (?String format, *untyped args) -> String
|
333
|
+
|
334
|
+
# Label
|
335
|
+
#
|
336
|
+
def label: () -> String
|
337
|
+
|
338
|
+
# Elapsed real time
|
339
|
+
#
|
340
|
+
def real: () -> Float
|
341
|
+
|
342
|
+
# System CPU time
|
343
|
+
#
|
344
|
+
def stime: () -> Float
|
345
|
+
|
346
|
+
# Returns a new 6-element array, consisting of the label, user CPU time, system
|
347
|
+
# CPU time, children's user CPU time, children's system CPU time and elapsed
|
348
|
+
# real time.
|
349
|
+
#
|
350
|
+
def to_a: () -> untyped
|
351
|
+
|
352
|
+
# Same as #format.
|
353
|
+
#
|
354
|
+
def to_s: () -> String
|
355
|
+
|
356
|
+
# Total time, that is `utime` + `stime` + `cutime` + `cstime`
|
357
|
+
#
|
358
|
+
def total: () -> Float
|
359
|
+
|
360
|
+
# User CPU time
|
361
|
+
#
|
362
|
+
def utime: () -> Float
|
363
|
+
|
364
|
+
# Default caption, see also Benchmark::CAPTION
|
365
|
+
#
|
366
|
+
CAPTION: String
|
367
|
+
|
368
|
+
# Default format string, see also Benchmark::FORMAT
|
369
|
+
#
|
370
|
+
FORMAT: String
|
371
|
+
end
|
364
372
|
end
|
365
|
-
|
366
|
-
# Default caption, see also Benchmark::CAPTION
|
367
|
-
#
|
368
|
-
Benchmark::Tms::CAPTION: String
|
369
|
-
|
370
|
-
# Default format string, see also Benchmark::FORMAT
|
371
|
-
#
|
372
|
-
Benchmark::Tms::FORMAT: String
|