sorbet-runtime 0.5.6295 → 0.5.6300

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: 1499d7c137f6d9b53c61885843cc7631c7e8984fdcb5c83e3e9c06316706a7bd
4
- data.tar.gz: 63f24495ef2ef2b14e9afa6b30db65109631684c91b5cf400f0896027c7cd91f
3
+ metadata.gz: 42bb5dc2bac9a729a674f1acc718f65bf21569a3f30059eb6e70bb708c399f09
4
+ data.tar.gz: 5ca2ad1aebe9b9c25ec2f74c316b6bc5dfb28a0432046dbb475055143545237f
5
5
  SHA512:
6
- metadata.gz: f1642f8bfb9f6c69a9496837e270d916e1a187044d721484235ed1a0e292a4ed8199b520f766f77e7e6c9a1ab3006bf6f4a6c2158511524fdb3cfaf91b96c093
7
- data.tar.gz: 16157845afa712815f96724daff65a38b3e73f16a46110c76571ff4c75410b1e0d464f246478e7ae5c5a77532ddddb0dccf6d1ccbbe6865bfdc7989e3832e7ca
6
+ metadata.gz: ca04cc3d6a2aec318c0ce4f131ddba85a5c024846f8daf82733a6c291afa15a89516413e8842085e0720b95a96cd717b853664cdbbb69a01923353b1a24d9e1c
7
+ data.tar.gz: a1406ca1482a4d5db675e6294061518e787bb45f30fee18ca89cf4d47c1c49c1583cc0dde4c060500a8118a5c3bf96677dd2096466bd4f187ab4bdbfdb543c39
@@ -47,110 +47,6 @@ module T::Private::Methods::CallValidation
47
47
  mod.instance_method(method_sig.method_name)
48
48
  end
49
49
 
50
- def self.validate_call(instance, original_method, method_sig, args, blk)
51
- # This method is called for every `sig`. It's critical to keep it fast and
52
- # reduce number of allocations that happen here.
53
-
54
- T::Profile.typecheck_sample_attempts -= 1
55
- should_sample = T::Profile.typecheck_sample_attempts == 0
56
- if should_sample
57
- T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
58
- T::Profile.typecheck_samples += 1
59
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
60
- end
61
-
62
- if method_sig.bind
63
- message = method_sig.bind.error_message_for_obj(instance)
64
- if message
65
- CallValidation.report_error(
66
- method_sig,
67
- message,
68
- 'Bind',
69
- nil,
70
- method_sig.bind,
71
- instance
72
- )
73
- end
74
- end
75
-
76
- # NOTE: We don't bother validating for missing or extra kwargs;
77
- # the method call itself will take care of that.
78
- method_sig.each_args_value_type(args) do |name, arg, type|
79
- message = type.error_message_for_obj(arg)
80
- if message
81
- CallValidation.report_error(
82
- method_sig,
83
- message,
84
- 'Parameter',
85
- name,
86
- type,
87
- arg,
88
- caller_offset: 2
89
- )
90
- end
91
- end
92
-
93
- if method_sig.block_type
94
- message = method_sig.block_type.error_message_for_obj(blk)
95
- if message
96
- CallValidation.report_error(
97
- method_sig,
98
- message,
99
- 'Block parameter',
100
- method_sig.block_name,
101
- method_sig.block_type,
102
- blk
103
- )
104
- end
105
- end
106
-
107
- if should_sample
108
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
109
- end
110
-
111
- # The following line breaks are intentional to show nice pry message
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
- # PRY note:
123
- # this code is sig validation code.
124
- # Please issue `finish` to step out of it
125
-
126
- return_value = original_method.bind(instance).call(*args, &blk)
127
- if should_sample
128
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
129
- end
130
-
131
- # The only type that is allowed to change the return value is `.void`.
132
- # It ignores what you returned and changes it to be a private singleton.
133
- if method_sig.return_type.is_a?(T::Private::Types::Void)
134
- T::Private::Types::Void::VOID
135
- else
136
- message = method_sig.return_type.error_message_for_obj(return_value)
137
- if message
138
- CallValidation.report_error(
139
- method_sig,
140
- message,
141
- 'Return value',
142
- nil,
143
- method_sig.return_type,
144
- return_value,
145
- )
146
- end
147
- if should_sample
148
- T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
149
- end
150
- return_value
151
- end
152
- end
153
-
154
50
  @is_allowed_to_have_fast_path = true
155
51
  def self.is_allowed_to_have_fast_path
156
52
  @is_allowed_to_have_fast_path
@@ -169,9 +65,9 @@ module T::Private::Methods::CallValidation
169
65
 
170
66
  T::Configuration.without_ruby_warnings do
171
67
  T::Private::DeclState.current.without_on_method_added do
172
- if has_fixed_arity && has_simple_method_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
68
+ if has_fixed_arity && has_simple_method_types && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
173
69
  create_validator_method_fast(mod, original_method, method_sig)
174
- elsif has_fixed_arity && has_simple_procedure_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
70
+ elsif has_fixed_arity && has_simple_procedure_types && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
175
71
  create_validator_procedure_fast(mod, original_method, method_sig)
176
72
  else
177
73
  create_validator_slow(mod, original_method, method_sig)
@@ -181,15 +77,6 @@ module T::Private::Methods::CallValidation
181
77
  mod.send(original_visibility, method_sig.method_name)
182
78
  end
183
79
 
184
- def self.create_validator_slow(mod, original_method, method_sig)
185
- mod.send(:define_method, method_sig.method_name) do |*args, &blk|
186
- CallValidation.validate_call(self, original_method, method_sig, args, blk)
187
- end
188
- if mod.respond_to?(:ruby2_keywords, true)
189
- mod.send(:ruby2_keywords, method_sig.method_name)
190
- end
191
- end
192
-
193
80
  def self.create_validator_method_fast(mod, original_method, method_sig)
194
81
  if method_sig.return_type.is_a?(T::Private::Types::Void)
195
82
  raise "Should have used create_validator_procedure_fast"
@@ -233,20 +120,6 @@ module T::Private::Methods::CallValidation
233
120
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
234
121
  end
235
122
 
236
- if method_sig.bind
237
- message = method_sig.bind.error_message_for_obj(self)
238
- if message
239
- CallValidation.report_error(
240
- method_sig,
241
- message,
242
- 'Bind',
243
- nil,
244
- method_sig.bind,
245
- self
246
- )
247
- end
248
- end
249
-
250
123
  if should_sample
251
124
  T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
252
125
  end
@@ -306,20 +179,6 @@ module T::Private::Methods::CallValidation
306
179
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
307
180
  end
308
181
 
309
- if method_sig.bind
310
- message = method_sig.bind.error_message_for_obj(self)
311
- if message
312
- CallValidation.report_error(
313
- method_sig,
314
- message,
315
- 'Bind',
316
- nil,
317
- method_sig.bind,
318
- self
319
- )
320
- end
321
- end
322
-
323
182
  unless arg0.is_a?(arg0_type)
324
183
  CallValidation.report_error(
325
184
  method_sig,
@@ -391,20 +250,6 @@ module T::Private::Methods::CallValidation
391
250
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
392
251
  end
393
252
 
394
- if method_sig.bind
395
- message = method_sig.bind.error_message_for_obj(self)
396
- if message
397
- CallValidation.report_error(
398
- method_sig,
399
- message,
400
- 'Bind',
401
- nil,
402
- method_sig.bind,
403
- self
404
- )
405
- end
406
- end
407
-
408
253
  unless arg0.is_a?(arg0_type)
409
254
  CallValidation.report_error(
410
255
  method_sig,
@@ -488,20 +333,6 @@ module T::Private::Methods::CallValidation
488
333
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
489
334
  end
490
335
 
491
- if method_sig.bind
492
- message = method_sig.bind.error_message_for_obj(self)
493
- if message
494
- CallValidation.report_error(
495
- method_sig,
496
- message,
497
- 'Bind',
498
- nil,
499
- method_sig.bind,
500
- self
501
- )
502
- end
503
- end
504
-
505
336
  unless arg0.is_a?(arg0_type)
506
337
  CallValidation.report_error(
507
338
  method_sig,
@@ -598,20 +429,6 @@ module T::Private::Methods::CallValidation
598
429
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
599
430
  end
600
431
 
601
- if method_sig.bind
602
- message = method_sig.bind.error_message_for_obj(self)
603
- if message
604
- CallValidation.report_error(
605
- method_sig,
606
- message,
607
- 'Bind',
608
- nil,
609
- method_sig.bind,
610
- self
611
- )
612
- end
613
- end
614
-
615
432
  unless arg0.is_a?(arg0_type)
616
433
  CallValidation.report_error(
617
434
  method_sig,
@@ -747,20 +564,6 @@ module T::Private::Methods::CallValidation
747
564
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
748
565
  end
749
566
 
750
- if method_sig.bind
751
- message = method_sig.bind.error_message_for_obj(self)
752
- if message
753
- CallValidation.report_error(
754
- method_sig,
755
- message,
756
- 'Bind',
757
- nil,
758
- method_sig.bind,
759
- self
760
- )
761
- end
762
- end
763
-
764
567
  if should_sample
765
568
  T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
766
569
  end
@@ -800,20 +603,6 @@ module T::Private::Methods::CallValidation
800
603
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
801
604
  end
802
605
 
803
- if method_sig.bind
804
- message = method_sig.bind.error_message_for_obj(self)
805
- if message
806
- CallValidation.report_error(
807
- method_sig,
808
- message,
809
- 'Bind',
810
- nil,
811
- method_sig.bind,
812
- self
813
- )
814
- end
815
- end
816
-
817
606
  unless arg0.is_a?(arg0_type)
818
607
  CallValidation.report_error(
819
608
  method_sig,
@@ -863,20 +652,6 @@ module T::Private::Methods::CallValidation
863
652
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
864
653
  end
865
654
 
866
- if method_sig.bind
867
- message = method_sig.bind.error_message_for_obj(self)
868
- if message
869
- CallValidation.report_error(
870
- method_sig,
871
- message,
872
- 'Bind',
873
- nil,
874
- method_sig.bind,
875
- self
876
- )
877
- end
878
- end
879
-
880
655
  unless arg0.is_a?(arg0_type)
881
656
  CallValidation.report_error(
882
657
  method_sig,
@@ -939,20 +714,6 @@ module T::Private::Methods::CallValidation
939
714
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
940
715
  end
941
716
 
942
- if method_sig.bind
943
- message = method_sig.bind.error_message_for_obj(self)
944
- if message
945
- CallValidation.report_error(
946
- method_sig,
947
- message,
948
- 'Bind',
949
- nil,
950
- method_sig.bind,
951
- self
952
- )
953
- end
954
- end
955
-
956
717
  unless arg0.is_a?(arg0_type)
957
718
  CallValidation.report_error(
958
719
  method_sig,
@@ -1028,20 +789,6 @@ module T::Private::Methods::CallValidation
1028
789
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1029
790
  end
1030
791
 
1031
- if method_sig.bind
1032
- message = method_sig.bind.error_message_for_obj(self)
1033
- if message
1034
- CallValidation.report_error(
1035
- method_sig,
1036
- message,
1037
- 'Bind',
1038
- nil,
1039
- method_sig.bind,
1040
- self
1041
- )
1042
- end
1043
- end
1044
-
1045
792
  unless arg0.is_a?(arg0_type)
1046
793
  CallValidation.report_error(
1047
794
  method_sig,
@@ -1114,6 +861,119 @@ module T::Private::Methods::CallValidation
1114
861
  end
1115
862
  end
1116
863
 
864
+ def self.create_validator_slow(mod, original_method, method_sig)
865
+ mod.send(:define_method, method_sig.method_name) do |*args, &blk|
866
+ CallValidation.validate_call(self, original_method, method_sig, args, blk)
867
+ end
868
+ if mod.respond_to?(:ruby2_keywords, true)
869
+ mod.send(:ruby2_keywords, method_sig.method_name)
870
+ end
871
+ end
872
+
873
+ def self.validate_call(instance, original_method, method_sig, args, blk)
874
+ # This method is called for every `sig`. It's critical to keep it fast and
875
+ # reduce number of allocations that happen here.
876
+
877
+ T::Profile.typecheck_sample_attempts -= 1
878
+ should_sample = T::Profile.typecheck_sample_attempts == 0
879
+ if should_sample
880
+ T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE
881
+ T::Profile.typecheck_samples += 1
882
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
883
+ end
884
+
885
+ if method_sig.bind
886
+ message = method_sig.bind.error_message_for_obj(instance)
887
+ if message
888
+ CallValidation.report_error(
889
+ method_sig,
890
+ message,
891
+ 'Bind',
892
+ nil,
893
+ method_sig.bind,
894
+ instance
895
+ )
896
+ end
897
+ end
898
+
899
+ # NOTE: We don't bother validating for missing or extra kwargs;
900
+ # the method call itself will take care of that.
901
+ method_sig.each_args_value_type(args) do |name, arg, type|
902
+ message = type.error_message_for_obj(arg)
903
+ if message
904
+ CallValidation.report_error(
905
+ method_sig,
906
+ message,
907
+ 'Parameter',
908
+ name,
909
+ type,
910
+ arg,
911
+ caller_offset: 2
912
+ )
913
+ end
914
+ end
915
+
916
+ if method_sig.block_type
917
+ message = method_sig.block_type.error_message_for_obj(blk)
918
+ if message
919
+ CallValidation.report_error(
920
+ method_sig,
921
+ message,
922
+ 'Block parameter',
923
+ method_sig.block_name,
924
+ method_sig.block_type,
925
+ blk
926
+ )
927
+ end
928
+ end
929
+
930
+ if should_sample
931
+ T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
932
+ end
933
+
934
+ # The following line breaks are intentional to show nice pry message
935
+
936
+
937
+
938
+
939
+
940
+
941
+
942
+
943
+
944
+
945
+ # PRY note:
946
+ # this code is sig validation code.
947
+ # Please issue `finish` to step out of it
948
+
949
+ return_value = original_method.bind(instance).call(*args, &blk)
950
+ if should_sample
951
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
952
+ end
953
+
954
+ # The only type that is allowed to change the return value is `.void`.
955
+ # It ignores what you returned and changes it to be a private singleton.
956
+ if method_sig.return_type.is_a?(T::Private::Types::Void)
957
+ T::Private::Types::Void::VOID
958
+ else
959
+ message = method_sig.return_type.error_message_for_obj(return_value)
960
+ if message
961
+ CallValidation.report_error(
962
+ method_sig,
963
+ message,
964
+ 'Return value',
965
+ nil,
966
+ method_sig.return_type,
967
+ return_value,
968
+ )
969
+ end
970
+ if should_sample
971
+ T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1)
972
+ end
973
+ return_value
974
+ end
975
+ end
976
+
1117
977
  def self.report_error(method_sig, error_message, kind, name, type, value, caller_offset: 0)
1118
978
  caller_loc = T.must(caller_locations(3 + caller_offset, 1))[0]
1119
979
  definition_file, definition_line = method_sig.method.source_location
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6295
4
+ version: 0.5.6300
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest