sorbet-runtime 0.5.6304 → 0.5.6322
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/configuration.rb +9 -1
- data/lib/types/private/methods/_methods.rb +3 -4
- data/lib/types/private/methods/call_validation.rb +7 -785
- data/lib/types/private/methods/call_validation_2_6.rb +781 -0
- data/lib/types/private/methods/call_validation_2_7.rb +781 -0
- data/lib/types/types/typed_enumerable.rb +5 -1
- data/lib/types/utils.rb +7 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c77d695c5b2ad896c9bf845303e742d41c07c24d55c4aedcfd8f6acb9580dc
|
4
|
+
data.tar.gz: 8cbbe5d304fb8f7742a5785232511c92eb68948490216202a7c6faf1fdf90bc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aea4d354cc43e0797dd8e651f514f316508806b8d557248a31c5cf21ab651d8537788ad90f635634a684c1183e5066862e1bfef56748b9d722cd8edab8e0a3c3
|
7
|
+
data.tar.gz: 32f1bd879783697530fc548ce7fbf2477a7dc0458e6e3d7904f5f88c3c304f6f148029f2ab16afddc90993c8103bb80ad8d9afeaeb765a0cfe1c97606a864231
|
data/lib/types/configuration.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module T::Configuration
|
5
|
+
# Cache this comparisonn to avoid two allocations all over the place.
|
6
|
+
AT_LEAST_RUBY_2_7 = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
|
7
|
+
|
5
8
|
# Announces to Sorbet that we are currently in a test environment, so it
|
6
9
|
# should treat any sigs which are marked `.checked(:tests)` as if they were
|
7
10
|
# just a normal sig.
|
@@ -395,7 +398,12 @@ module T::Configuration
|
|
395
398
|
MODULE_NAME = Module.instance_method(:name)
|
396
399
|
private_constant :MODULE_NAME
|
397
400
|
|
398
|
-
|
401
|
+
if T::Configuration::AT_LEAST_RUBY_2_7
|
402
|
+
@default_module_name_mangler = ->(type) {MODULE_NAME.bind_call(type)}
|
403
|
+
else
|
404
|
+
@default_module_name_mangler = ->(type) {MODULE_NAME.bind(type).call}
|
405
|
+
end
|
406
|
+
|
399
407
|
@module_name_mangler = nil
|
400
408
|
|
401
409
|
def self.module_name_mangler
|
@@ -108,10 +108,7 @@ module T::Private::Methods
|
|
108
108
|
# method_to_key(ancestor.instance_method(method_name)) is not (just) an optimization, but also required for
|
109
109
|
# correctness, since ancestor.method_defined?(method_name) may return true even if method_name is not defined
|
110
110
|
# directly on ancestor but instead an ancestor of ancestor.
|
111
|
-
if (ancestor
|
112
|
-
ancestor.private_method_defined?(method_name) ||
|
113
|
-
ancestor.protected_method_defined?(method_name)) &&
|
114
|
-
final_method?(method_owner_and_name_to_key(ancestor, method_name))
|
111
|
+
if final_method?(method_owner_and_name_to_key(ancestor, method_name))
|
115
112
|
definition_file, definition_line = T::Private::Methods.signature_for_method(ancestor.instance_method(method_name)).method.source_location
|
116
113
|
is_redefined = target == ancestor
|
117
114
|
caller_loc = caller_locations&.find {|l| !l.to_s.match?(%r{sorbet-runtime[^/]*/lib/}) }
|
@@ -220,6 +217,8 @@ module T::Private::Methods
|
|
220
217
|
# make sure to keep changes in sync.
|
221
218
|
elsif method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
222
219
|
CallValidation.validate_call(self, original_method, method_sig, args, blk)
|
220
|
+
elsif T::Configuration::AT_LEAST_RUBY_2_7
|
221
|
+
original_method.bind_call(self, *args, &blk)
|
223
222
|
else
|
224
223
|
original_method.bind(self).call(*args, &blk)
|
225
224
|
end
|
@@ -77,790 +77,6 @@ module T::Private::Methods::CallValidation
|
|
77
77
|
mod.send(original_visibility, method_sig.method_name)
|
78
78
|
end
|
79
79
|
|
80
|
-
def self.create_validator_method_fast(mod, original_method, method_sig)
|
81
|
-
if method_sig.return_type.is_a?(T::Private::Types::Void)
|
82
|
-
raise "Should have used create_validator_procedure_fast"
|
83
|
-
end
|
84
|
-
# trampoline to reduce stack frame size
|
85
|
-
if method_sig.arg_types.empty?
|
86
|
-
create_validator_method_fast0(mod, original_method, method_sig, method_sig.return_type.raw_type)
|
87
|
-
elsif method_sig.arg_types.length == 1
|
88
|
-
create_validator_method_fast1(mod, original_method, method_sig, method_sig.return_type.raw_type,
|
89
|
-
method_sig.arg_types[0][1].raw_type)
|
90
|
-
elsif method_sig.arg_types.length == 2
|
91
|
-
create_validator_method_fast2(mod, original_method, method_sig, method_sig.return_type.raw_type,
|
92
|
-
method_sig.arg_types[0][1].raw_type,
|
93
|
-
method_sig.arg_types[1][1].raw_type)
|
94
|
-
elsif method_sig.arg_types.length == 3
|
95
|
-
create_validator_method_fast3(mod, original_method, method_sig, method_sig.return_type.raw_type,
|
96
|
-
method_sig.arg_types[0][1].raw_type,
|
97
|
-
method_sig.arg_types[1][1].raw_type,
|
98
|
-
method_sig.arg_types[2][1].raw_type)
|
99
|
-
elsif method_sig.arg_types.length == 4
|
100
|
-
create_validator_method_fast4(mod, original_method, method_sig, method_sig.return_type.raw_type,
|
101
|
-
method_sig.arg_types[0][1].raw_type,
|
102
|
-
method_sig.arg_types[1][1].raw_type,
|
103
|
-
method_sig.arg_types[2][1].raw_type,
|
104
|
-
method_sig.arg_types[3][1].raw_type)
|
105
|
-
else
|
106
|
-
raise "should not happen"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.create_validator_method_fast0(mod, original_method, method_sig, return_type)
|
111
|
-
mod.send(:define_method, method_sig.method_name) do |&blk|
|
112
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
113
|
-
# reduce number of allocations that happen here.
|
114
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
115
|
-
T::Profile.typecheck_sample_attempts -= 1
|
116
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
117
|
-
if should_sample
|
118
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
119
|
-
T::Profile.typecheck_samples += 1
|
120
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
121
|
-
end
|
122
|
-
|
123
|
-
if should_sample
|
124
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
125
|
-
end
|
126
|
-
|
127
|
-
# The following line breaks are intentional to show nice pry message
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
# PRY note:
|
139
|
-
# this code is sig validation code.
|
140
|
-
# Please issue `finish` to step out of it
|
141
|
-
|
142
|
-
return_value = original_method.bind(self).call(&blk)
|
143
|
-
if should_sample
|
144
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
145
|
-
end
|
146
|
-
|
147
|
-
unless return_value.is_a?(return_type)
|
148
|
-
message = method_sig.return_type.error_message_for_obj(return_value)
|
149
|
-
if message
|
150
|
-
CallValidation.report_error(
|
151
|
-
method_sig,
|
152
|
-
message,
|
153
|
-
'Return value',
|
154
|
-
nil,
|
155
|
-
return_type,
|
156
|
-
return_value,
|
157
|
-
caller_offset: -1
|
158
|
-
)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
if should_sample
|
162
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
163
|
-
end
|
164
|
-
return_value
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.create_validator_method_fast1(mod, original_method, method_sig, return_type, arg0_type)
|
169
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
|
170
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
171
|
-
# reduce number of allocations that happen here.
|
172
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
173
|
-
|
174
|
-
T::Profile.typecheck_sample_attempts -= 1
|
175
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
176
|
-
if should_sample
|
177
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
178
|
-
T::Profile.typecheck_samples += 1
|
179
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
180
|
-
end
|
181
|
-
|
182
|
-
unless arg0.is_a?(arg0_type)
|
183
|
-
CallValidation.report_error(
|
184
|
-
method_sig,
|
185
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
186
|
-
'Parameter',
|
187
|
-
method_sig.arg_types[0][0],
|
188
|
-
arg0_type,
|
189
|
-
arg0,
|
190
|
-
caller_offset: -1
|
191
|
-
)
|
192
|
-
end
|
193
|
-
|
194
|
-
if should_sample
|
195
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
196
|
-
end
|
197
|
-
|
198
|
-
# The following line breaks are intentional to show nice pry message
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
# PRY note:
|
210
|
-
# this code is sig validation code.
|
211
|
-
# Please issue `finish` to step out of it
|
212
|
-
|
213
|
-
return_value = original_method.bind(self).call(arg0, &blk)
|
214
|
-
if should_sample
|
215
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
216
|
-
end
|
217
|
-
|
218
|
-
unless return_value.is_a?(return_type)
|
219
|
-
message = method_sig.return_type.error_message_for_obj(return_value)
|
220
|
-
if message
|
221
|
-
CallValidation.report_error(
|
222
|
-
method_sig,
|
223
|
-
message,
|
224
|
-
'Return value',
|
225
|
-
nil,
|
226
|
-
method_sig.return_type,
|
227
|
-
return_value,
|
228
|
-
caller_offset: -1
|
229
|
-
)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
if should_sample
|
233
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
234
|
-
end
|
235
|
-
return_value
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def self.create_validator_method_fast2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
|
240
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
|
241
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
242
|
-
# reduce number of allocations that happen here.
|
243
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
244
|
-
|
245
|
-
T::Profile.typecheck_sample_attempts -= 1
|
246
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
247
|
-
if should_sample
|
248
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
249
|
-
T::Profile.typecheck_samples += 1
|
250
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
251
|
-
end
|
252
|
-
|
253
|
-
unless arg0.is_a?(arg0_type)
|
254
|
-
CallValidation.report_error(
|
255
|
-
method_sig,
|
256
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
257
|
-
'Parameter',
|
258
|
-
method_sig.arg_types[0][0],
|
259
|
-
arg0_type,
|
260
|
-
arg0,
|
261
|
-
caller_offset: -1
|
262
|
-
)
|
263
|
-
end
|
264
|
-
|
265
|
-
unless arg1.is_a?(arg1_type)
|
266
|
-
CallValidation.report_error(
|
267
|
-
method_sig,
|
268
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
269
|
-
'Parameter',
|
270
|
-
method_sig.arg_types[1][0],
|
271
|
-
arg1_type,
|
272
|
-
arg1,
|
273
|
-
caller_offset: -1
|
274
|
-
)
|
275
|
-
end
|
276
|
-
|
277
|
-
if should_sample
|
278
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
279
|
-
end
|
280
|
-
|
281
|
-
# The following line breaks are intentional to show nice pry message
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
# PRY note:
|
293
|
-
# this code is sig validation code.
|
294
|
-
# Please issue `finish` to step out of it
|
295
|
-
|
296
|
-
return_value = original_method.bind(self).call(arg0, arg1, &blk)
|
297
|
-
if should_sample
|
298
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
299
|
-
end
|
300
|
-
|
301
|
-
unless return_value.is_a?(return_type)
|
302
|
-
message = method_sig.return_type.error_message_for_obj(return_value)
|
303
|
-
if message
|
304
|
-
CallValidation.report_error(
|
305
|
-
method_sig,
|
306
|
-
message,
|
307
|
-
'Return value',
|
308
|
-
nil,
|
309
|
-
method_sig.return_type,
|
310
|
-
return_value,
|
311
|
-
caller_offset: -1
|
312
|
-
)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
if should_sample
|
316
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
317
|
-
end
|
318
|
-
return_value
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
def self.create_validator_method_fast3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
|
323
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
|
324
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
325
|
-
# reduce number of allocations that happen here.
|
326
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
327
|
-
|
328
|
-
T::Profile.typecheck_sample_attempts -= 1
|
329
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
330
|
-
if should_sample
|
331
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
332
|
-
T::Profile.typecheck_samples += 1
|
333
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
334
|
-
end
|
335
|
-
|
336
|
-
unless arg0.is_a?(arg0_type)
|
337
|
-
CallValidation.report_error(
|
338
|
-
method_sig,
|
339
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
340
|
-
'Parameter',
|
341
|
-
method_sig.arg_types[0][0],
|
342
|
-
arg0_type,
|
343
|
-
arg0,
|
344
|
-
caller_offset: -1
|
345
|
-
)
|
346
|
-
end
|
347
|
-
|
348
|
-
unless arg1.is_a?(arg1_type)
|
349
|
-
CallValidation.report_error(
|
350
|
-
method_sig,
|
351
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
352
|
-
'Parameter',
|
353
|
-
method_sig.arg_types[1][0],
|
354
|
-
arg1_type,
|
355
|
-
arg1,
|
356
|
-
caller_offset: -1
|
357
|
-
)
|
358
|
-
end
|
359
|
-
|
360
|
-
unless arg2.is_a?(arg2_type)
|
361
|
-
CallValidation.report_error(
|
362
|
-
method_sig,
|
363
|
-
method_sig.arg_types[2][1].error_message_for_obj(arg2),
|
364
|
-
'Parameter',
|
365
|
-
method_sig.arg_types[2][0],
|
366
|
-
arg2_type,
|
367
|
-
arg2,
|
368
|
-
caller_offset: -1
|
369
|
-
)
|
370
|
-
end
|
371
|
-
|
372
|
-
if should_sample
|
373
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
374
|
-
end
|
375
|
-
|
376
|
-
# The following line breaks are intentional to show nice pry message
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
# PRY note:
|
388
|
-
# this code is sig validation code.
|
389
|
-
# Please issue `finish` to step out of it
|
390
|
-
|
391
|
-
return_value = original_method.bind(self).call(arg0, arg1, arg2, &blk)
|
392
|
-
if should_sample
|
393
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
394
|
-
end
|
395
|
-
|
396
|
-
unless return_value.is_a?(return_type)
|
397
|
-
message = method_sig.return_type.error_message_for_obj(return_value)
|
398
|
-
if message
|
399
|
-
CallValidation.report_error(
|
400
|
-
method_sig,
|
401
|
-
message,
|
402
|
-
'Return value',
|
403
|
-
nil,
|
404
|
-
method_sig.return_type,
|
405
|
-
return_value,
|
406
|
-
caller_offset: -1
|
407
|
-
)
|
408
|
-
end
|
409
|
-
end
|
410
|
-
if should_sample
|
411
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
412
|
-
end
|
413
|
-
return_value
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
def self.create_validator_method_fast4(mod, original_method, method_sig, return_type,
|
418
|
-
arg0_type, arg1_type, arg2_type, arg3_type)
|
419
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
|
420
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
421
|
-
# reduce number of allocations that happen here.
|
422
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
423
|
-
|
424
|
-
T::Profile.typecheck_sample_attempts -= 1
|
425
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
426
|
-
if should_sample
|
427
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
428
|
-
T::Profile.typecheck_samples += 1
|
429
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
430
|
-
end
|
431
|
-
|
432
|
-
unless arg0.is_a?(arg0_type)
|
433
|
-
CallValidation.report_error(
|
434
|
-
method_sig,
|
435
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
436
|
-
'Parameter',
|
437
|
-
method_sig.arg_types[0][0],
|
438
|
-
arg0_type,
|
439
|
-
arg0,
|
440
|
-
caller_offset: -1
|
441
|
-
)
|
442
|
-
end
|
443
|
-
|
444
|
-
unless arg1.is_a?(arg1_type)
|
445
|
-
CallValidation.report_error(
|
446
|
-
method_sig,
|
447
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
448
|
-
'Parameter',
|
449
|
-
method_sig.arg_types[1][0],
|
450
|
-
arg1_type,
|
451
|
-
arg1,
|
452
|
-
caller_offset: -1
|
453
|
-
)
|
454
|
-
end
|
455
|
-
|
456
|
-
unless arg2.is_a?(arg2_type)
|
457
|
-
CallValidation.report_error(
|
458
|
-
method_sig,
|
459
|
-
method_sig.arg_types[2][1].error_message_for_obj(arg2),
|
460
|
-
'Parameter',
|
461
|
-
method_sig.arg_types[2][0],
|
462
|
-
arg2_type,
|
463
|
-
arg2,
|
464
|
-
caller_offset: -1
|
465
|
-
)
|
466
|
-
end
|
467
|
-
|
468
|
-
unless arg3.is_a?(arg3_type)
|
469
|
-
CallValidation.report_error(
|
470
|
-
method_sig,
|
471
|
-
method_sig.arg_types[3][1].error_message_for_obj(arg3),
|
472
|
-
'Parameter',
|
473
|
-
method_sig.arg_types[3][0],
|
474
|
-
arg3_type,
|
475
|
-
arg3,
|
476
|
-
caller_offset: -1
|
477
|
-
)
|
478
|
-
end
|
479
|
-
|
480
|
-
if should_sample
|
481
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
482
|
-
end
|
483
|
-
|
484
|
-
# The following line breaks are intentional to show nice pry message
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
# PRY note:
|
496
|
-
# this code is sig validation code.
|
497
|
-
# Please issue `finish` to step out of it
|
498
|
-
|
499
|
-
return_value = original_method.bind(self).call(arg0, arg1, arg2, arg3, &blk)
|
500
|
-
if should_sample
|
501
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
502
|
-
end
|
503
|
-
|
504
|
-
unless return_value.is_a?(return_type)
|
505
|
-
message = method_sig.return_type.error_message_for_obj(return_value)
|
506
|
-
if message
|
507
|
-
CallValidation.report_error(
|
508
|
-
method_sig,
|
509
|
-
message,
|
510
|
-
'Return value',
|
511
|
-
nil,
|
512
|
-
method_sig.return_type,
|
513
|
-
return_value,
|
514
|
-
caller_offset: -1
|
515
|
-
)
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
if should_sample
|
520
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
521
|
-
end
|
522
|
-
return_value
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
def self.create_validator_procedure_fast(mod, original_method, method_sig)
|
527
|
-
# trampoline to reduce stack frame size
|
528
|
-
if method_sig.arg_types.empty?
|
529
|
-
create_validator_procedure_fast0(mod, original_method, method_sig)
|
530
|
-
elsif method_sig.arg_types.length == 1
|
531
|
-
create_validator_procedure_fast1(mod, original_method, method_sig,
|
532
|
-
method_sig.arg_types[0][1].raw_type)
|
533
|
-
elsif method_sig.arg_types.length == 2
|
534
|
-
create_validator_procedure_fast2(mod, original_method, method_sig,
|
535
|
-
method_sig.arg_types[0][1].raw_type,
|
536
|
-
method_sig.arg_types[1][1].raw_type)
|
537
|
-
elsif method_sig.arg_types.length == 3
|
538
|
-
create_validator_procedure_fast3(mod, original_method, method_sig,
|
539
|
-
method_sig.arg_types[0][1].raw_type,
|
540
|
-
method_sig.arg_types[1][1].raw_type,
|
541
|
-
method_sig.arg_types[2][1].raw_type)
|
542
|
-
elsif method_sig.arg_types.length == 4
|
543
|
-
create_validator_procedure_fast4(mod, original_method, method_sig,
|
544
|
-
method_sig.arg_types[0][1].raw_type,
|
545
|
-
method_sig.arg_types[1][1].raw_type,
|
546
|
-
method_sig.arg_types[2][1].raw_type,
|
547
|
-
method_sig.arg_types[3][1].raw_type)
|
548
|
-
else
|
549
|
-
raise "should not happen"
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
def self.create_validator_procedure_fast0(mod, original_method, method_sig)
|
554
|
-
mod.send(:define_method, method_sig.method_name) do |&blk|
|
555
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
556
|
-
# reduce number of allocations that happen here.
|
557
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
558
|
-
|
559
|
-
T::Profile.typecheck_sample_attempts -= 1
|
560
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
561
|
-
if should_sample
|
562
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
563
|
-
T::Profile.typecheck_samples += 1
|
564
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
565
|
-
end
|
566
|
-
|
567
|
-
if should_sample
|
568
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
569
|
-
end
|
570
|
-
|
571
|
-
# The following line breaks are intentional to show nice pry message
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
# PRY note:
|
583
|
-
# this code is sig validation code.
|
584
|
-
# Please issue `finish` to step out of it
|
585
|
-
|
586
|
-
original_method.bind(self).call(&blk)
|
587
|
-
T::Private::Types::Void::VOID
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def self.create_validator_procedure_fast1(mod, original_method, method_sig, arg0_type)
|
592
|
-
|
593
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
|
594
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
595
|
-
# reduce number of allocations that happen here.
|
596
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
597
|
-
|
598
|
-
T::Profile.typecheck_sample_attempts -= 1
|
599
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
600
|
-
if should_sample
|
601
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
602
|
-
T::Profile.typecheck_samples += 1
|
603
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
604
|
-
end
|
605
|
-
|
606
|
-
unless arg0.is_a?(arg0_type)
|
607
|
-
CallValidation.report_error(
|
608
|
-
method_sig,
|
609
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
610
|
-
'Parameter',
|
611
|
-
method_sig.arg_types[0][0],
|
612
|
-
arg0_type,
|
613
|
-
arg0,
|
614
|
-
caller_offset: -1
|
615
|
-
)
|
616
|
-
end
|
617
|
-
|
618
|
-
if should_sample
|
619
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
620
|
-
end
|
621
|
-
|
622
|
-
# The following line breaks are intentional to show nice pry message
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
# PRY note:
|
634
|
-
# this code is sig validation code.
|
635
|
-
# Please issue `finish` to step out of it
|
636
|
-
original_method.bind(self).call(arg0, &blk)
|
637
|
-
T::Private::Types::Void::VOID
|
638
|
-
end
|
639
|
-
end
|
640
|
-
|
641
|
-
def self.create_validator_procedure_fast2(mod, original_method, method_sig, arg0_type, arg1_type)
|
642
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
|
643
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
644
|
-
# reduce number of allocations that happen here.
|
645
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
646
|
-
|
647
|
-
T::Profile.typecheck_sample_attempts -= 1
|
648
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
649
|
-
if should_sample
|
650
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
651
|
-
T::Profile.typecheck_samples += 1
|
652
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
653
|
-
end
|
654
|
-
|
655
|
-
unless arg0.is_a?(arg0_type)
|
656
|
-
CallValidation.report_error(
|
657
|
-
method_sig,
|
658
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
659
|
-
'Parameter',
|
660
|
-
method_sig.arg_types[0][0],
|
661
|
-
arg0_type,
|
662
|
-
arg0,
|
663
|
-
caller_offset: -1
|
664
|
-
)
|
665
|
-
end
|
666
|
-
|
667
|
-
unless arg1.is_a?(arg1_type)
|
668
|
-
CallValidation.report_error(
|
669
|
-
method_sig,
|
670
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
671
|
-
'Parameter',
|
672
|
-
method_sig.arg_types[1][0],
|
673
|
-
arg1_type,
|
674
|
-
arg1,
|
675
|
-
caller_offset: -1
|
676
|
-
)
|
677
|
-
end
|
678
|
-
|
679
|
-
if should_sample
|
680
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
681
|
-
end
|
682
|
-
|
683
|
-
# The following line breaks are intentional to show nice pry message
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
# PRY note:
|
695
|
-
# this code is sig validation code.
|
696
|
-
# Please issue `finish` to step out of it
|
697
|
-
|
698
|
-
original_method.bind(self).call(arg0, arg1, &blk)
|
699
|
-
T::Private::Types::Void::VOID
|
700
|
-
end
|
701
|
-
end
|
702
|
-
|
703
|
-
def self.create_validator_procedure_fast3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
|
704
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
|
705
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
706
|
-
# reduce number of allocations that happen here.
|
707
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
708
|
-
|
709
|
-
T::Profile.typecheck_sample_attempts -= 1
|
710
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
711
|
-
if should_sample
|
712
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
713
|
-
T::Profile.typecheck_samples += 1
|
714
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
715
|
-
end
|
716
|
-
|
717
|
-
unless arg0.is_a?(arg0_type)
|
718
|
-
CallValidation.report_error(
|
719
|
-
method_sig,
|
720
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
721
|
-
'Parameter',
|
722
|
-
method_sig.arg_types[0][0],
|
723
|
-
arg0_type,
|
724
|
-
arg0,
|
725
|
-
caller_offset: -1
|
726
|
-
)
|
727
|
-
end
|
728
|
-
|
729
|
-
unless arg1.is_a?(arg1_type)
|
730
|
-
CallValidation.report_error(
|
731
|
-
method_sig,
|
732
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
733
|
-
'Parameter',
|
734
|
-
method_sig.arg_types[1][0],
|
735
|
-
arg1_type,
|
736
|
-
arg1,
|
737
|
-
caller_offset: -1
|
738
|
-
)
|
739
|
-
end
|
740
|
-
|
741
|
-
unless arg2.is_a?(arg2_type)
|
742
|
-
CallValidation.report_error(
|
743
|
-
method_sig,
|
744
|
-
method_sig.arg_types[2][1].error_message_for_obj(arg2),
|
745
|
-
'Parameter',
|
746
|
-
method_sig.arg_types[2][0],
|
747
|
-
arg2_type,
|
748
|
-
arg2,
|
749
|
-
caller_offset: -1
|
750
|
-
)
|
751
|
-
end
|
752
|
-
|
753
|
-
if should_sample
|
754
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
755
|
-
end
|
756
|
-
|
757
|
-
# The following line breaks are intentional to show nice pry message
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
# PRY note:
|
769
|
-
# this code is sig validation code.
|
770
|
-
# Please issue `finish` to step out of it
|
771
|
-
|
772
|
-
original_method.bind(self).call(arg0, arg1, arg2, &blk)
|
773
|
-
T::Private::Types::Void::VOID
|
774
|
-
end
|
775
|
-
end
|
776
|
-
|
777
|
-
def self.create_validator_procedure_fast4(mod, original_method, method_sig,
|
778
|
-
arg0_type, arg1_type, arg2_type, arg3_type)
|
779
|
-
mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
|
780
|
-
# This block is called for every `sig`. It's critical to keep it fast and
|
781
|
-
# reduce number of allocations that happen here.
|
782
|
-
# This method is a manually sped-up version of more general code in `validate_call`
|
783
|
-
|
784
|
-
T::Profile.typecheck_sample_attempts -= 1
|
785
|
-
should_sample = T::Profile.typecheck_sample_attempts == 0
|
786
|
-
if should_sample
|
787
|
-
T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
|
788
|
-
T::Profile.typecheck_samples += 1
|
789
|
-
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
790
|
-
end
|
791
|
-
|
792
|
-
unless arg0.is_a?(arg0_type)
|
793
|
-
CallValidation.report_error(
|
794
|
-
method_sig,
|
795
|
-
method_sig.arg_types[0][1].error_message_for_obj(arg0),
|
796
|
-
'Parameter',
|
797
|
-
method_sig.arg_types[0][0],
|
798
|
-
arg0_type,
|
799
|
-
arg0,
|
800
|
-
caller_offset: -1
|
801
|
-
)
|
802
|
-
end
|
803
|
-
|
804
|
-
unless arg1.is_a?(arg1_type)
|
805
|
-
CallValidation.report_error(
|
806
|
-
method_sig,
|
807
|
-
method_sig.arg_types[1][1].error_message_for_obj(arg1),
|
808
|
-
'Parameter',
|
809
|
-
method_sig.arg_types[1][0],
|
810
|
-
arg1_type,
|
811
|
-
arg1,
|
812
|
-
caller_offset: -1
|
813
|
-
)
|
814
|
-
end
|
815
|
-
|
816
|
-
unless arg2.is_a?(arg2_type)
|
817
|
-
CallValidation.report_error(
|
818
|
-
method_sig,
|
819
|
-
method_sig.arg_types[2][1].error_message_for_obj(arg2),
|
820
|
-
'Parameter',
|
821
|
-
method_sig.arg_types[2][0],
|
822
|
-
arg2_type,
|
823
|
-
arg2,
|
824
|
-
caller_offset: -1
|
825
|
-
)
|
826
|
-
end
|
827
|
-
|
828
|
-
unless arg3.is_a?(arg3_type)
|
829
|
-
CallValidation.report_error(
|
830
|
-
method_sig,
|
831
|
-
method_sig.arg_types[3][1].error_message_for_obj(arg3),
|
832
|
-
'Parameter',
|
833
|
-
method_sig.arg_types[3][0],
|
834
|
-
arg3_type,
|
835
|
-
arg3,
|
836
|
-
caller_offset: -1
|
837
|
-
)
|
838
|
-
end
|
839
|
-
|
840
|
-
if should_sample
|
841
|
-
T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
|
842
|
-
end
|
843
|
-
|
844
|
-
# The following line breaks are intentional to show nice pry message
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
# PRY note:
|
856
|
-
# this code is sig validation code.
|
857
|
-
# Please issue `finish` to step out of it
|
858
|
-
|
859
|
-
original_method.bind(self).call(arg0, arg1, arg2, arg3, &blk)
|
860
|
-
T::Private::Types::Void::VOID
|
861
|
-
end
|
862
|
-
end
|
863
|
-
|
864
80
|
def self.create_validator_slow(mod, original_method, method_sig)
|
865
81
|
mod.send(:define_method, method_sig.method_name) do |*args, &blk|
|
866
82
|
CallValidation.validate_call(self, original_method, method_sig, args, blk)
|
@@ -946,7 +162,7 @@ module T::Private::Methods::CallValidation
|
|
946
162
|
# this code is sig validation code.
|
947
163
|
# Please issue `finish` to step out of it
|
948
164
|
|
949
|
-
return_value = original_method.bind(instance).call(*args, &blk)
|
165
|
+
return_value = T::Configuration::AT_LEAST_RUBY_2_7 ? original_method.bind_call(instance, *args, &blk) : original_method.bind(instance).call(*args, &blk)
|
950
166
|
if should_sample
|
951
167
|
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
952
168
|
end
|
@@ -1007,3 +223,9 @@ module T::Private::Methods::CallValidation
|
|
1007
223
|
end
|
1008
224
|
end
|
1009
225
|
end
|
226
|
+
|
227
|
+
if T::Configuration::AT_LEAST_RUBY_2_7
|
228
|
+
require_relative './call_validation_2_7'
|
229
|
+
else
|
230
|
+
require_relative './call_validation_2_6'
|
231
|
+
end
|