sorbet-runtime 0.5.6386 → 0.5.6395

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f43636d0022878d4f29cbae70939ce88678dad66e12157ec0e89b01b069c54bb
4
- data.tar.gz: c96e93ca2a2f3dbb31aea372b525dfff900ad460194bf5d2ed5ac51f822a9381
3
+ metadata.gz: a3f7e712765bc8cf3eb2bb0677e1a9bc7c076ccd0a45ec264dea11fa45a0602b
4
+ data.tar.gz: aa45bd7ec5aa309fd5431992dd240f0558f37806b721a9f266b544492b34351c
5
5
  SHA512:
6
- metadata.gz: 043b5548593afb627f357293bc57302ebfa3f9b120af6bfae466cb3fc10b2f5abb948b844aef81c4ca4a1761ee3e090a3c2f1ca66ff0fecd1fd521741c3be4f8
7
- data.tar.gz: 4ae533c54e8985fcd218639498f8cbe308689bd792037651e0d03b378f187d01d32fe9198357e20c9215a0cf31d1157aba475432b2777a06debb07473139ee71
6
+ metadata.gz: a8ce05d54623d9e6961f5af4e8efe72a2be490c847da79719bc4dfbd38b2ddfd49a3ed24341c14b13fff4f3b32c03742788f7ee4b50ab69cf5204b2c86d4d2da
7
+ data.tar.gz: 421508b1b085f4d3a111a961ae56cbc2afc92c5077fa81c7560c952d92d32458172336e52091b8d1ff1aff7635e592765f526d79e7885bf97a1666a79e9b039b
@@ -19,7 +19,6 @@ require 'set'
19
19
 
20
20
  # These are pre-reqs for almost everything in here.
21
21
  require_relative 'types/configuration'
22
- require_relative 'types/profile'
23
22
  require_relative 'types/_types'
24
23
  require_relative 'types/private/decl_state'
25
24
  require_relative 'types/private/class_utils'
data/lib/types/_types.rb CHANGED
@@ -147,6 +147,25 @@ module T
147
147
  Private::Casts.cast(value, type, cast_method: "T.let")
148
148
  end
149
149
 
150
+ # Tells the type checker to treat `self` in the current block as `type`.
151
+ # Useful for blocks that are captured and executed later with instance_exec.
152
+ # Use like:
153
+ #
154
+ # seconds = lambda do
155
+ # T.bind(self, NewBinding)
156
+ # ...
157
+ # end
158
+ #
159
+ # `T.bind` behaves like `T.cast` in that it is assumed to be true statically.
160
+ #
161
+ # If `checked` is true, raises an exception at runtime if the value
162
+ # doesn't match the type (this is the default).
163
+ def self.bind(value, type, checked: true)
164
+ return value unless checked
165
+
166
+ Private::Casts.cast(value, type, cast_method: "T.bind")
167
+ end
168
+
150
169
  # Tells the typechecker to ensure that `value` is of type `type` (if not, the typechecker will
151
170
  # fail). Use this for debugging typechecking errors, or to ensure that type information is
152
171
  # statically known and being checked appropriately. If `checked` is true, raises an exception at
@@ -73,6 +73,27 @@ module T::Configuration
73
73
  @include_value_in_type_errors = true
74
74
  end
75
75
 
76
+ # Whether to use VM-defined prop serialization/deserialization routines.
77
+ #
78
+ # The default is to use runtime codegen inside sorbet-runtime itself.
79
+ #
80
+ # @return [T::Boolean]
81
+ def self.use_vm_prop_serde?
82
+ @use_vm_prop_serde || false
83
+ end
84
+
85
+ # Enable using VM-defined prop serialization/deserialization routines.
86
+ #
87
+ # This method is likely to break things outside of Stripe's systems.
88
+ def self.enable_vm_prop_serde
89
+ @use_vm_prop_serde = true
90
+ end
91
+
92
+ # Disable using VM-defined prop serialization/deserialization routines.
93
+ def self.disable_vm_prop_serde
94
+ @use_vm_prop_serde = false
95
+ end
96
+
76
97
  # Configure the default checked level for a sig with no explicit `.checked`
77
98
  # builder. When unset, the default checked level is `:always`.
78
99
  #
@@ -59,16 +59,22 @@ module T::Private::Methods::CallValidation
59
59
  def self.create_validator_method(mod, original_method, method_sig, original_visibility)
60
60
  has_fixed_arity = method_sig.kwarg_types.empty? && !method_sig.has_rest && !method_sig.has_keyrest &&
61
61
  original_method.parameters.all? {|(kind, _name)| kind == :req}
62
- all_args_are_simple = method_sig.arg_types.all? {|_name, type| type.is_a?(T::Types::Simple)}
63
- has_simple_method_types = all_args_are_simple && method_sig.return_type.is_a?(T::Types::Simple)
64
- has_simple_procedure_types = all_args_are_simple && method_sig.return_type.is_a?(T::Private::Types::Void)
62
+ ok_for_fast_path = has_fixed_arity && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
63
+
64
+ all_args_are_simple = ok_for_fast_path && method_sig.arg_types.all? {|_name, type| type.is_a?(T::Types::Simple)}
65
+ simple_method = all_args_are_simple && method_sig.return_type.is_a?(T::Types::Simple)
66
+ simple_procedure = all_args_are_simple && method_sig.return_type.is_a?(T::Private::Types::Void)
65
67
 
66
68
  T::Configuration.without_ruby_warnings do
67
69
  T::Private::DeclState.current.without_on_method_added do
68
- if has_fixed_arity && has_simple_method_types && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
70
+ if simple_method
69
71
  create_validator_method_fast(mod, original_method, method_sig)
70
- elsif has_fixed_arity && has_simple_procedure_types && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
72
+ elsif simple_procedure
71
73
  create_validator_procedure_fast(mod, original_method, method_sig)
74
+ elsif ok_for_fast_path && method_sig.return_type.is_a?(T::Private::Types::Void)
75
+ create_validator_procedure_medium(mod, original_method, method_sig)
76
+ elsif ok_for_fast_path
77
+ create_validator_method_medium(mod, original_method, method_sig)
72
78
  else
73
79
  create_validator_slow(mod, original_method, method_sig)
74
80
  end
@@ -90,14 +96,6 @@ module T::Private::Methods::CallValidation
90
96
  # This method is called for every `sig`. It's critical to keep it fast and
91
97
  # reduce number of allocations that happen here.
92
98
 
93
- T::Profile.typecheck_sample_attempts -= 1
94
- should_sample = T::Profile.typecheck_sample_attempts == 0
95
- if should_sample
96
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
97
- T::Profile.typecheck_samples += 1
98
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
99
- end
100
-
101
99
  if method_sig.bind
102
100
  message = method_sig.bind.error_message_for_obj(instance)
103
101
  if message
@@ -143,10 +141,6 @@ module T::Private::Methods::CallValidation
143
141
  end
144
142
  end
145
143
 
146
- if should_sample
147
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
148
- end
149
-
150
144
  # The following line breaks are intentional to show nice pry message
151
145
 
152
146
 
@@ -163,9 +157,6 @@ module T::Private::Methods::CallValidation
163
157
  # Please issue `finish` to step out of it
164
158
 
165
159
  return_value = T::Configuration::AT_LEAST_RUBY_2_7 ? original_method.bind_call(instance, *args, &blk) : original_method.bind(instance).call(*args, &blk)
166
- if should_sample
167
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
168
- end
169
160
 
170
161
  # The only type that is allowed to change the return value is `.void`.
171
162
  # It ignores what you returned and changes it to be a private singleton.
@@ -183,9 +174,6 @@ module T::Private::Methods::CallValidation
183
174
  return_value,
184
175
  )
185
176
  end
186
- if should_sample
187
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
188
- end
189
177
  return_value
190
178
  end
191
179
  end
@@ -38,21 +38,7 @@ module T::Private::Methods::CallValidation
38
38
 
39
39
  def self.create_validator_method_fast0(mod, original_method, method_sig, return_type)
40
40
  mod.send(:define_method, method_sig.method_name) do |&blk|
41
- # This block is called for every `sig`. It's critical to keep it fast and
42
- # reduce number of allocations that happen here.
43
41
  # This method is a manually sped-up version of more general code in `validate_call`
44
- T::Profile.typecheck_sample_attempts -= 1
45
- should_sample = T::Profile.typecheck_sample_attempts == 0
46
- if should_sample
47
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
48
- T::Profile.typecheck_samples += 1
49
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50
- end
51
-
52
- if should_sample
53
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
54
- end
55
-
56
42
  # The following line breaks are intentional to show nice pry message
57
43
 
58
44
 
@@ -69,10 +55,6 @@ module T::Private::Methods::CallValidation
69
55
  # Please issue `finish` to step out of it
70
56
 
71
57
  return_value = original_method.bind(self).call(&blk)
72
- if should_sample
73
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
74
- end
75
-
76
58
  unless return_value.is_a?(return_type)
77
59
  message = method_sig.return_type.error_message_for_obj(return_value)
78
60
  if message
@@ -87,26 +69,13 @@ module T::Private::Methods::CallValidation
87
69
  )
88
70
  end
89
71
  end
90
- if should_sample
91
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
92
- end
93
72
  return_value
94
73
  end
95
74
  end
96
75
 
97
76
  def self.create_validator_method_fast1(mod, original_method, method_sig, return_type, arg0_type)
98
77
  mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
99
- # This block is called for every `sig`. It's critical to keep it fast and
100
- # reduce number of allocations that happen here.
101
78
  # This method is a manually sped-up version of more general code in `validate_call`
102
- T::Profile.typecheck_sample_attempts -= 1
103
- should_sample = T::Profile.typecheck_sample_attempts == 0
104
- if should_sample
105
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
106
- T::Profile.typecheck_samples += 1
107
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
108
- end
109
-
110
79
  unless arg0.is_a?(arg0_type)
111
80
  CallValidation.report_error(
112
81
  method_sig,
@@ -119,10 +88,6 @@ module T::Private::Methods::CallValidation
119
88
  )
120
89
  end
121
90
 
122
- if should_sample
123
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
124
- end
125
-
126
91
  # The following line breaks are intentional to show nice pry message
127
92
 
128
93
 
@@ -139,10 +104,6 @@ module T::Private::Methods::CallValidation
139
104
  # Please issue `finish` to step out of it
140
105
 
141
106
  return_value = original_method.bind(self).call(arg0, &blk)
142
- if should_sample
143
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
144
- end
145
-
146
107
  unless return_value.is_a?(return_type)
147
108
  message = method_sig.return_type.error_message_for_obj(return_value)
148
109
  if message
@@ -157,26 +118,13 @@ module T::Private::Methods::CallValidation
157
118
  )
158
119
  end
159
120
  end
160
- if should_sample
161
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
162
- end
163
121
  return_value
164
122
  end
165
123
  end
166
124
 
167
125
  def self.create_validator_method_fast2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
168
126
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
169
- # This block is called for every `sig`. It's critical to keep it fast and
170
- # reduce number of allocations that happen here.
171
127
  # This method is a manually sped-up version of more general code in `validate_call`
172
- T::Profile.typecheck_sample_attempts -= 1
173
- should_sample = T::Profile.typecheck_sample_attempts == 0
174
- if should_sample
175
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
176
- T::Profile.typecheck_samples += 1
177
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
178
- end
179
-
180
128
  unless arg0.is_a?(arg0_type)
181
129
  CallValidation.report_error(
182
130
  method_sig,
@@ -201,10 +149,6 @@ module T::Private::Methods::CallValidation
201
149
  )
202
150
  end
203
151
 
204
- if should_sample
205
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
206
- end
207
-
208
152
  # The following line breaks are intentional to show nice pry message
209
153
 
210
154
 
@@ -221,10 +165,6 @@ module T::Private::Methods::CallValidation
221
165
  # Please issue `finish` to step out of it
222
166
 
223
167
  return_value = original_method.bind(self).call(arg0, arg1, &blk)
224
- if should_sample
225
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
226
- end
227
-
228
168
  unless return_value.is_a?(return_type)
229
169
  message = method_sig.return_type.error_message_for_obj(return_value)
230
170
  if message
@@ -239,26 +179,13 @@ module T::Private::Methods::CallValidation
239
179
  )
240
180
  end
241
181
  end
242
- if should_sample
243
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
244
- end
245
182
  return_value
246
183
  end
247
184
  end
248
185
 
249
186
  def self.create_validator_method_fast3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
250
187
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
251
- # This block is called for every `sig`. It's critical to keep it fast and
252
- # reduce number of allocations that happen here.
253
188
  # This method is a manually sped-up version of more general code in `validate_call`
254
- T::Profile.typecheck_sample_attempts -= 1
255
- should_sample = T::Profile.typecheck_sample_attempts == 0
256
- if should_sample
257
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
258
- T::Profile.typecheck_samples += 1
259
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
260
- end
261
-
262
189
  unless arg0.is_a?(arg0_type)
263
190
  CallValidation.report_error(
264
191
  method_sig,
@@ -295,10 +222,6 @@ module T::Private::Methods::CallValidation
295
222
  )
296
223
  end
297
224
 
298
- if should_sample
299
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
300
- end
301
-
302
225
  # The following line breaks are intentional to show nice pry message
303
226
 
304
227
 
@@ -315,10 +238,6 @@ module T::Private::Methods::CallValidation
315
238
  # Please issue `finish` to step out of it
316
239
 
317
240
  return_value = original_method.bind(self).call(arg0, arg1, arg2, &blk)
318
- if should_sample
319
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
320
- end
321
-
322
241
  unless return_value.is_a?(return_type)
323
242
  message = method_sig.return_type.error_message_for_obj(return_value)
324
243
  if message
@@ -333,26 +252,13 @@ module T::Private::Methods::CallValidation
333
252
  )
334
253
  end
335
254
  end
336
- if should_sample
337
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
338
- end
339
255
  return_value
340
256
  end
341
257
  end
342
258
 
343
259
  def self.create_validator_method_fast4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
344
260
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
345
- # This block is called for every `sig`. It's critical to keep it fast and
346
- # reduce number of allocations that happen here.
347
261
  # This method is a manually sped-up version of more general code in `validate_call`
348
- T::Profile.typecheck_sample_attempts -= 1
349
- should_sample = T::Profile.typecheck_sample_attempts == 0
350
- if should_sample
351
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
352
- T::Profile.typecheck_samples += 1
353
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
354
- end
355
-
356
262
  unless arg0.is_a?(arg0_type)
357
263
  CallValidation.report_error(
358
264
  method_sig,
@@ -401,10 +307,6 @@ module T::Private::Methods::CallValidation
401
307
  )
402
308
  end
403
309
 
404
- if should_sample
405
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
406
- end
407
-
408
310
  # The following line breaks are intentional to show nice pry message
409
311
 
410
312
 
@@ -421,10 +323,6 @@ module T::Private::Methods::CallValidation
421
323
  # Please issue `finish` to step out of it
422
324
 
423
325
  return_value = original_method.bind(self).call(arg0, arg1, arg2, arg3, &blk)
424
- if should_sample
425
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
426
- end
427
-
428
326
  unless return_value.is_a?(return_type)
429
327
  message = method_sig.return_type.error_message_for_obj(return_value)
430
328
  if message
@@ -439,9 +337,6 @@ module T::Private::Methods::CallValidation
439
337
  )
440
338
  end
441
339
  end
442
- if should_sample
443
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
444
- end
445
340
  return_value
446
341
  end
447
342
  end
@@ -475,21 +370,7 @@ module T::Private::Methods::CallValidation
475
370
 
476
371
  def self.create_validator_procedure_fast0(mod, original_method, method_sig)
477
372
  mod.send(:define_method, method_sig.method_name) do |&blk|
478
- # This block is called for every `sig`. It's critical to keep it fast and
479
- # reduce number of allocations that happen here.
480
373
  # This method is a manually sped-up version of more general code in `validate_call`
481
- T::Profile.typecheck_sample_attempts -= 1
482
- should_sample = T::Profile.typecheck_sample_attempts == 0
483
- if should_sample
484
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
485
- T::Profile.typecheck_samples += 1
486
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
487
- end
488
-
489
- if should_sample
490
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
491
- end
492
-
493
374
  # The following line breaks are intentional to show nice pry message
494
375
 
495
376
 
@@ -512,17 +393,7 @@ module T::Private::Methods::CallValidation
512
393
 
513
394
  def self.create_validator_procedure_fast1(mod, original_method, method_sig, arg0_type)
514
395
  mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
515
- # This block is called for every `sig`. It's critical to keep it fast and
516
- # reduce number of allocations that happen here.
517
396
  # This method is a manually sped-up version of more general code in `validate_call`
518
- T::Profile.typecheck_sample_attempts -= 1
519
- should_sample = T::Profile.typecheck_sample_attempts == 0
520
- if should_sample
521
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
522
- T::Profile.typecheck_samples += 1
523
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
524
- end
525
-
526
397
  unless arg0.is_a?(arg0_type)
527
398
  CallValidation.report_error(
528
399
  method_sig,
@@ -535,10 +406,6 @@ module T::Private::Methods::CallValidation
535
406
  )
536
407
  end
537
408
 
538
- if should_sample
539
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
540
- end
541
-
542
409
  # The following line breaks are intentional to show nice pry message
543
410
 
544
411
 
@@ -561,17 +428,7 @@ module T::Private::Methods::CallValidation
561
428
 
562
429
  def self.create_validator_procedure_fast2(mod, original_method, method_sig, arg0_type, arg1_type)
563
430
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
564
- # This block is called for every `sig`. It's critical to keep it fast and
565
- # reduce number of allocations that happen here.
566
431
  # This method is a manually sped-up version of more general code in `validate_call`
567
- T::Profile.typecheck_sample_attempts -= 1
568
- should_sample = T::Profile.typecheck_sample_attempts == 0
569
- if should_sample
570
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
571
- T::Profile.typecheck_samples += 1
572
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
573
- end
574
-
575
432
  unless arg0.is_a?(arg0_type)
576
433
  CallValidation.report_error(
577
434
  method_sig,
@@ -596,10 +453,6 @@ module T::Private::Methods::CallValidation
596
453
  )
597
454
  end
598
455
 
599
- if should_sample
600
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
601
- end
602
-
603
456
  # The following line breaks are intentional to show nice pry message
604
457
 
605
458
 
@@ -622,17 +475,7 @@ module T::Private::Methods::CallValidation
622
475
 
623
476
  def self.create_validator_procedure_fast3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
624
477
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
625
- # This block is called for every `sig`. It's critical to keep it fast and
626
- # reduce number of allocations that happen here.
627
478
  # This method is a manually sped-up version of more general code in `validate_call`
628
- T::Profile.typecheck_sample_attempts -= 1
629
- should_sample = T::Profile.typecheck_sample_attempts == 0
630
- if should_sample
631
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
632
- T::Profile.typecheck_samples += 1
633
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
634
- end
635
-
636
479
  unless arg0.is_a?(arg0_type)
637
480
  CallValidation.report_error(
638
481
  method_sig,
@@ -669,10 +512,6 @@ module T::Private::Methods::CallValidation
669
512
  )
670
513
  end
671
514
 
672
- if should_sample
673
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
674
- end
675
-
676
515
  # The following line breaks are intentional to show nice pry message
677
516
 
678
517
 
@@ -695,17 +534,7 @@ module T::Private::Methods::CallValidation
695
534
 
696
535
  def self.create_validator_procedure_fast4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
697
536
  mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
698
- # This block is called for every `sig`. It's critical to keep it fast and
699
- # reduce number of allocations that happen here.
700
537
  # This method is a manually sped-up version of more general code in `validate_call`
701
- T::Profile.typecheck_sample_attempts -= 1
702
- should_sample = T::Profile.typecheck_sample_attempts == 0
703
- if should_sample
704
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
705
- T::Profile.typecheck_samples += 1
706
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
707
- end
708
-
709
538
  unless arg0.is_a?(arg0_type)
710
539
  CallValidation.report_error(
711
540
  method_sig,
@@ -754,8 +583,601 @@ module T::Private::Methods::CallValidation
754
583
  )
755
584
  end
756
585
 
757
- if should_sample
758
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
586
+ # The following line breaks are intentional to show nice pry message
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+ # PRY note:
598
+ # this code is sig validation code.
599
+ # Please issue `finish` to step out of it
600
+
601
+ original_method.bind(self).call(arg0, arg1, arg2, arg3, &blk)
602
+ T::Private::Types::Void::VOID
603
+ end
604
+ end
605
+
606
+ def self.create_validator_method_medium(mod, original_method, method_sig)
607
+ if method_sig.return_type.is_a?(T::Private::Types::Void)
608
+ raise 'Should have used create_validator_procedure_medium'
609
+ end
610
+ # trampoline to reduce stack frame size
611
+ if method_sig.arg_types.empty?
612
+ create_validator_method_medium0(mod, original_method, method_sig, method_sig.return_type)
613
+ elsif method_sig.arg_types.length == 1
614
+ create_validator_method_medium1(mod, original_method, method_sig, method_sig.return_type,
615
+ method_sig.arg_types[0][1])
616
+ elsif method_sig.arg_types.length == 2
617
+ create_validator_method_medium2(mod, original_method, method_sig, method_sig.return_type,
618
+ method_sig.arg_types[0][1],
619
+ method_sig.arg_types[1][1])
620
+ elsif method_sig.arg_types.length == 3
621
+ create_validator_method_medium3(mod, original_method, method_sig, method_sig.return_type,
622
+ method_sig.arg_types[0][1],
623
+ method_sig.arg_types[1][1],
624
+ method_sig.arg_types[2][1])
625
+ elsif method_sig.arg_types.length == 4
626
+ create_validator_method_medium4(mod, original_method, method_sig, method_sig.return_type,
627
+ method_sig.arg_types[0][1],
628
+ method_sig.arg_types[1][1],
629
+ method_sig.arg_types[2][1],
630
+ method_sig.arg_types[3][1])
631
+ else
632
+ raise 'should not happen'
633
+ end
634
+ end
635
+
636
+ def self.create_validator_method_medium0(mod, original_method, method_sig, return_type)
637
+ mod.send(:define_method, method_sig.method_name) do |&blk|
638
+ # This method is a manually sped-up version of more general code in `validate_call`
639
+ # The following line breaks are intentional to show nice pry message
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+ # PRY note:
651
+ # this code is sig validation code.
652
+ # Please issue `finish` to step out of it
653
+
654
+ return_value = original_method.bind(self).call(&blk)
655
+ unless return_type.valid?(return_value)
656
+ message = method_sig.return_type.error_message_for_obj(return_value)
657
+ if message
658
+ CallValidation.report_error(
659
+ method_sig,
660
+ message,
661
+ 'Return value',
662
+ nil,
663
+ method_sig.return_type,
664
+ return_value,
665
+ caller_offset: -1
666
+ )
667
+ end
668
+ end
669
+ return_value
670
+ end
671
+ end
672
+
673
+ def self.create_validator_method_medium1(mod, original_method, method_sig, return_type, arg0_type)
674
+ mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
675
+ # This method is a manually sped-up version of more general code in `validate_call`
676
+ unless arg0_type.valid?(arg0)
677
+ CallValidation.report_error(
678
+ method_sig,
679
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
680
+ 'Parameter',
681
+ method_sig.arg_types[0][0],
682
+ arg0_type,
683
+ arg0,
684
+ caller_offset: -1
685
+ )
686
+ end
687
+
688
+ # The following line breaks are intentional to show nice pry message
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+ # PRY note:
700
+ # this code is sig validation code.
701
+ # Please issue `finish` to step out of it
702
+
703
+ return_value = original_method.bind(self).call(arg0, &blk)
704
+ unless return_type.valid?(return_value)
705
+ message = method_sig.return_type.error_message_for_obj(return_value)
706
+ if message
707
+ CallValidation.report_error(
708
+ method_sig,
709
+ message,
710
+ 'Return value',
711
+ nil,
712
+ method_sig.return_type,
713
+ return_value,
714
+ caller_offset: -1
715
+ )
716
+ end
717
+ end
718
+ return_value
719
+ end
720
+ end
721
+
722
+ def self.create_validator_method_medium2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
723
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
724
+ # This method is a manually sped-up version of more general code in `validate_call`
725
+ unless arg0_type.valid?(arg0)
726
+ CallValidation.report_error(
727
+ method_sig,
728
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
729
+ 'Parameter',
730
+ method_sig.arg_types[0][0],
731
+ arg0_type,
732
+ arg0,
733
+ caller_offset: -1
734
+ )
735
+ end
736
+
737
+ unless arg1_type.valid?(arg1)
738
+ CallValidation.report_error(
739
+ method_sig,
740
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
741
+ 'Parameter',
742
+ method_sig.arg_types[1][0],
743
+ arg1_type,
744
+ arg1,
745
+ caller_offset: -1
746
+ )
747
+ end
748
+
749
+ # The following line breaks are intentional to show nice pry message
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+ # PRY note:
761
+ # this code is sig validation code.
762
+ # Please issue `finish` to step out of it
763
+
764
+ return_value = original_method.bind(self).call(arg0, arg1, &blk)
765
+ unless return_type.valid?(return_value)
766
+ message = method_sig.return_type.error_message_for_obj(return_value)
767
+ if message
768
+ CallValidation.report_error(
769
+ method_sig,
770
+ message,
771
+ 'Return value',
772
+ nil,
773
+ method_sig.return_type,
774
+ return_value,
775
+ caller_offset: -1
776
+ )
777
+ end
778
+ end
779
+ return_value
780
+ end
781
+ end
782
+
783
+ def self.create_validator_method_medium3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
784
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
785
+ # This method is a manually sped-up version of more general code in `validate_call`
786
+ unless arg0_type.valid?(arg0)
787
+ CallValidation.report_error(
788
+ method_sig,
789
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
790
+ 'Parameter',
791
+ method_sig.arg_types[0][0],
792
+ arg0_type,
793
+ arg0,
794
+ caller_offset: -1
795
+ )
796
+ end
797
+
798
+ unless arg1_type.valid?(arg1)
799
+ CallValidation.report_error(
800
+ method_sig,
801
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
802
+ 'Parameter',
803
+ method_sig.arg_types[1][0],
804
+ arg1_type,
805
+ arg1,
806
+ caller_offset: -1
807
+ )
808
+ end
809
+
810
+ unless arg2_type.valid?(arg2)
811
+ CallValidation.report_error(
812
+ method_sig,
813
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
814
+ 'Parameter',
815
+ method_sig.arg_types[2][0],
816
+ arg2_type,
817
+ arg2,
818
+ caller_offset: -1
819
+ )
820
+ end
821
+
822
+ # The following line breaks are intentional to show nice pry message
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+ # PRY note:
834
+ # this code is sig validation code.
835
+ # Please issue `finish` to step out of it
836
+
837
+ return_value = original_method.bind(self).call(arg0, arg1, arg2, &blk)
838
+ unless return_type.valid?(return_value)
839
+ message = method_sig.return_type.error_message_for_obj(return_value)
840
+ if message
841
+ CallValidation.report_error(
842
+ method_sig,
843
+ message,
844
+ 'Return value',
845
+ nil,
846
+ method_sig.return_type,
847
+ return_value,
848
+ caller_offset: -1
849
+ )
850
+ end
851
+ end
852
+ return_value
853
+ end
854
+ end
855
+
856
+ def self.create_validator_method_medium4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
857
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
858
+ # This method is a manually sped-up version of more general code in `validate_call`
859
+ unless arg0_type.valid?(arg0)
860
+ CallValidation.report_error(
861
+ method_sig,
862
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
863
+ 'Parameter',
864
+ method_sig.arg_types[0][0],
865
+ arg0_type,
866
+ arg0,
867
+ caller_offset: -1
868
+ )
869
+ end
870
+
871
+ unless arg1_type.valid?(arg1)
872
+ CallValidation.report_error(
873
+ method_sig,
874
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
875
+ 'Parameter',
876
+ method_sig.arg_types[1][0],
877
+ arg1_type,
878
+ arg1,
879
+ caller_offset: -1
880
+ )
881
+ end
882
+
883
+ unless arg2_type.valid?(arg2)
884
+ CallValidation.report_error(
885
+ method_sig,
886
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
887
+ 'Parameter',
888
+ method_sig.arg_types[2][0],
889
+ arg2_type,
890
+ arg2,
891
+ caller_offset: -1
892
+ )
893
+ end
894
+
895
+ unless arg3_type.valid?(arg3)
896
+ CallValidation.report_error(
897
+ method_sig,
898
+ method_sig.arg_types[3][1].error_message_for_obj(arg3),
899
+ 'Parameter',
900
+ method_sig.arg_types[3][0],
901
+ arg3_type,
902
+ arg3,
903
+ caller_offset: -1
904
+ )
905
+ end
906
+
907
+ # The following line breaks are intentional to show nice pry message
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+
917
+
918
+ # PRY note:
919
+ # this code is sig validation code.
920
+ # Please issue `finish` to step out of it
921
+
922
+ return_value = original_method.bind(self).call(arg0, arg1, arg2, arg3, &blk)
923
+ unless return_type.valid?(return_value)
924
+ message = method_sig.return_type.error_message_for_obj(return_value)
925
+ if message
926
+ CallValidation.report_error(
927
+ method_sig,
928
+ message,
929
+ 'Return value',
930
+ nil,
931
+ method_sig.return_type,
932
+ return_value,
933
+ caller_offset: -1
934
+ )
935
+ end
936
+ end
937
+ return_value
938
+ end
939
+ end
940
+
941
+ def self.create_validator_procedure_medium(mod, original_method, method_sig)
942
+ # trampoline to reduce stack frame size
943
+ if method_sig.arg_types.empty?
944
+ create_validator_procedure_medium0(mod, original_method, method_sig)
945
+ elsif method_sig.arg_types.length == 1
946
+ create_validator_procedure_medium1(mod, original_method, method_sig,
947
+ method_sig.arg_types[0][1])
948
+ elsif method_sig.arg_types.length == 2
949
+ create_validator_procedure_medium2(mod, original_method, method_sig,
950
+ method_sig.arg_types[0][1],
951
+ method_sig.arg_types[1][1])
952
+ elsif method_sig.arg_types.length == 3
953
+ create_validator_procedure_medium3(mod, original_method, method_sig,
954
+ method_sig.arg_types[0][1],
955
+ method_sig.arg_types[1][1],
956
+ method_sig.arg_types[2][1])
957
+ elsif method_sig.arg_types.length == 4
958
+ create_validator_procedure_medium4(mod, original_method, method_sig,
959
+ method_sig.arg_types[0][1],
960
+ method_sig.arg_types[1][1],
961
+ method_sig.arg_types[2][1],
962
+ method_sig.arg_types[3][1])
963
+ else
964
+ raise 'should not happen'
965
+ end
966
+ end
967
+
968
+ def self.create_validator_procedure_medium0(mod, original_method, method_sig)
969
+ mod.send(:define_method, method_sig.method_name) do |&blk|
970
+ # This method is a manually sped-up version of more general code in `validate_call`
971
+ # The following line breaks are intentional to show nice pry message
972
+
973
+
974
+
975
+
976
+
977
+
978
+
979
+
980
+
981
+
982
+ # PRY note:
983
+ # this code is sig validation code.
984
+ # Please issue `finish` to step out of it
985
+
986
+ original_method.bind(self).call(&blk)
987
+ T::Private::Types::Void::VOID
988
+ end
989
+ end
990
+
991
+ def self.create_validator_procedure_medium1(mod, original_method, method_sig, arg0_type)
992
+ mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
993
+ # This method is a manually sped-up version of more general code in `validate_call`
994
+ unless arg0_type.valid?(arg0)
995
+ CallValidation.report_error(
996
+ method_sig,
997
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
998
+ 'Parameter',
999
+ method_sig.arg_types[0][0],
1000
+ arg0_type,
1001
+ arg0,
1002
+ caller_offset: -1
1003
+ )
1004
+ end
1005
+
1006
+ # The following line breaks are intentional to show nice pry message
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+ # PRY note:
1018
+ # this code is sig validation code.
1019
+ # Please issue `finish` to step out of it
1020
+
1021
+ original_method.bind(self).call(arg0, &blk)
1022
+ T::Private::Types::Void::VOID
1023
+ end
1024
+ end
1025
+
1026
+ def self.create_validator_procedure_medium2(mod, original_method, method_sig, arg0_type, arg1_type)
1027
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
1028
+ # This method is a manually sped-up version of more general code in `validate_call`
1029
+ unless arg0_type.valid?(arg0)
1030
+ CallValidation.report_error(
1031
+ method_sig,
1032
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1033
+ 'Parameter',
1034
+ method_sig.arg_types[0][0],
1035
+ arg0_type,
1036
+ arg0,
1037
+ caller_offset: -1
1038
+ )
1039
+ end
1040
+
1041
+ unless arg1_type.valid?(arg1)
1042
+ CallValidation.report_error(
1043
+ method_sig,
1044
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
1045
+ 'Parameter',
1046
+ method_sig.arg_types[1][0],
1047
+ arg1_type,
1048
+ arg1,
1049
+ caller_offset: -1
1050
+ )
1051
+ end
1052
+
1053
+ # The following line breaks are intentional to show nice pry message
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+ # PRY note:
1065
+ # this code is sig validation code.
1066
+ # Please issue `finish` to step out of it
1067
+
1068
+ original_method.bind(self).call(arg0, arg1, &blk)
1069
+ T::Private::Types::Void::VOID
1070
+ end
1071
+ end
1072
+
1073
+ def self.create_validator_procedure_medium3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
1074
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
1075
+ # This method is a manually sped-up version of more general code in `validate_call`
1076
+ unless arg0_type.valid?(arg0)
1077
+ CallValidation.report_error(
1078
+ method_sig,
1079
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1080
+ 'Parameter',
1081
+ method_sig.arg_types[0][0],
1082
+ arg0_type,
1083
+ arg0,
1084
+ caller_offset: -1
1085
+ )
1086
+ end
1087
+
1088
+ unless arg1_type.valid?(arg1)
1089
+ CallValidation.report_error(
1090
+ method_sig,
1091
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
1092
+ 'Parameter',
1093
+ method_sig.arg_types[1][0],
1094
+ arg1_type,
1095
+ arg1,
1096
+ caller_offset: -1
1097
+ )
1098
+ end
1099
+
1100
+ unless arg2_type.valid?(arg2)
1101
+ CallValidation.report_error(
1102
+ method_sig,
1103
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
1104
+ 'Parameter',
1105
+ method_sig.arg_types[2][0],
1106
+ arg2_type,
1107
+ arg2,
1108
+ caller_offset: -1
1109
+ )
1110
+ end
1111
+
1112
+ # The following line breaks are intentional to show nice pry message
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+ # PRY note:
1124
+ # this code is sig validation code.
1125
+ # Please issue `finish` to step out of it
1126
+
1127
+ original_method.bind(self).call(arg0, arg1, arg2, &blk)
1128
+ T::Private::Types::Void::VOID
1129
+ end
1130
+ end
1131
+
1132
+ def self.create_validator_procedure_medium4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
1133
+ mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
1134
+ # This method is a manually sped-up version of more general code in `validate_call`
1135
+ unless arg0_type.valid?(arg0)
1136
+ CallValidation.report_error(
1137
+ method_sig,
1138
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1139
+ 'Parameter',
1140
+ method_sig.arg_types[0][0],
1141
+ arg0_type,
1142
+ arg0,
1143
+ caller_offset: -1
1144
+ )
1145
+ end
1146
+
1147
+ unless arg1_type.valid?(arg1)
1148
+ CallValidation.report_error(
1149
+ method_sig,
1150
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
1151
+ 'Parameter',
1152
+ method_sig.arg_types[1][0],
1153
+ arg1_type,
1154
+ arg1,
1155
+ caller_offset: -1
1156
+ )
1157
+ end
1158
+
1159
+ unless arg2_type.valid?(arg2)
1160
+ CallValidation.report_error(
1161
+ method_sig,
1162
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
1163
+ 'Parameter',
1164
+ method_sig.arg_types[2][0],
1165
+ arg2_type,
1166
+ arg2,
1167
+ caller_offset: -1
1168
+ )
1169
+ end
1170
+
1171
+ unless arg3_type.valid?(arg3)
1172
+ CallValidation.report_error(
1173
+ method_sig,
1174
+ method_sig.arg_types[3][1].error_message_for_obj(arg3),
1175
+ 'Parameter',
1176
+ method_sig.arg_types[3][0],
1177
+ arg3_type,
1178
+ arg3,
1179
+ caller_offset: -1
1180
+ )
759
1181
  end
760
1182
 
761
1183
  # The following line breaks are intentional to show nice pry message