sorbet-runtime 0.5.6294 → 0.5.6305

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a256ee0dabdde01c3340aaa37de9f6087b07796fa1d4750e9d29e3de32984a86
4
- data.tar.gz: b492eff42df0d3a3f551783d45e39273acee9336327f36e6b30f798180fae958
3
+ metadata.gz: b991b6d3b1e4a952f6f1b321c3a0d740dfd81ef5bd919ff0b5132cfaed853edd
4
+ data.tar.gz: fbbfc89a63e874c2266171e802200275da17791edc37444f1aa056071534ea50
5
5
  SHA512:
6
- metadata.gz: 92c340a4a1f7497b7c4be890058eda75ecbf3b54949ab3f30412d8f8a4289b3547b9cb5db1c7285817abd3e0cb4e142c6e390309c41a25016ff45f062bcc1dc6
7
- data.tar.gz: 6211f37dd7142f87ba110421240c1c02c0ac9634e9a2c43f6b0618ebb68490f94639c5cf828aaaa75a8bec5d9215f051acfce01165c4f830957843c7daad16b9
6
+ metadata.gz: 7c775efd5d498bcf6c0c99e833533d1091aaa1144428340cd350b74f83a336a1c1787f29d452ea9f681e12e51a62c9be37d95996200786efd9560acf79b3d806
7
+ data.tar.gz: fcb0323f9c22cda96c4cb2f27d1e2be305704fb74cbcbab0bdb0c03230dea2d91c3e94b78165ee8e9074b250ad0954d6c34937226d14584ae72cd2360f17ed97
@@ -2,18 +2,26 @@
2
2
  # typed: strict
3
3
 
4
4
  module T::NonForcingConstants
5
+ T::Sig::WithoutRuntime.sig {returns(T::Boolean)}
6
+ private_class_method def self.stripe_packages_enabled?
7
+ const_defined?('StripePackages') && const_get('StripePackages').enabled?
8
+ end
9
+
5
10
  # NOTE: This method is documented on the RBI in Sorbet's payload, so that it
6
11
  # shows up in the hover/completion documentation via LSP.
7
12
  T::Sig::WithoutRuntime.sig {params(val: BasicObject, klass: String, package: T.nilable(String)).returns(T::Boolean)}
8
13
  def self.non_forcing_is_a?(val, klass, package: nil)
9
- # TODO(gdritter): once we have a runtime implementation of
10
- # packages, we'll need to actually handle the `package` argument
11
- # here.
12
14
  method_name = "T::NonForcingConstants.non_forcing_is_a?"
13
15
  if klass.empty?
14
16
  raise ArgumentError.new("The string given to `#{method_name}` must not be empty")
15
17
  end
16
18
 
19
+ # TODO(gdritter): this might not be want we want in a multipackage
20
+ # world; revisit this implementation we move on from the monopackage
21
+ if stripe_packages_enabled?
22
+ klass = "PkgRegistry::#{package}::#{klass}"
23
+ end
24
+
17
25
  current_klass = T.let(nil, T.nilable(Module))
18
26
  current_prefix = T.let(nil, T.nilable(String))
19
27
 
@@ -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.6294
4
+ version: 0.5.6305
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-20 00:00:00.000000000 Z
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest