sorbet-runtime 0.5.5848 → 0.5.5862

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: 4e36df8a78c0d43e49da28e22b8b3a8db6094d50227f3be131ba05133b09cfd7
4
- data.tar.gz: 1bfe28320c26f5749aff854bfbf9616d540a5f4d458dd35bc0e1add778a7e653
3
+ metadata.gz: 0e4f3bc5286319a6e352ee08fc7316790786e2f851d0854d1a265edeb423e913
4
+ data.tar.gz: 372eb903da66e3755c01f6ec548cf0cb90b4e94e5e4792a67a4ad410bae1c36c
5
5
  SHA512:
6
- metadata.gz: a8d0946d74e2a13eb6ffad4eb44633161da79d42b1a0e39a099a126f081e3346e6b7eecba85c50dfd333b890530a6d75bc85e7676a889fe9a1d0043198e502f6
7
- data.tar.gz: 8e44416ca05dd56362fc4a36457885713dc02ac4b9367cddabfefd33f80c0ec087befd957cc2c5dd4a66361313c82a87dc4e86157415c50e1ede2851fceb2d91
6
+ metadata.gz: 5d64a67fcc199c3f9d6c6ad7333be494c2ad0572d80ad0fbe080501183544fb844e8defbc2a8ba29ce4f525fe9dfef5ee2bf60a867a5c20cd00d96f81c4d6aac
7
+ data.tar.gz: de6518e01af0b32d22bd60372b8e49c0e01ae0369fc2939c4fd9c96916d99e7af2d8e3207ec4d07d0e2de2bca9aa06d40bbb396a3ecc66ea9faa88e41fc8de17
@@ -207,7 +207,11 @@ module T::Private::Methods
207
207
  new_method = nil
208
208
  T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
209
209
  method_sig = T::Private::Methods.maybe_run_sig_block_for_method(new_method)
210
- method_sig ||= T::Private::Methods._handle_missing_method_signature(mod, original_method, __callee__)
210
+ method_sig ||= T::Private::Methods._handle_missing_method_signature(
211
+ self,
212
+ original_method,
213
+ __callee__,
214
+ )
211
215
 
212
216
  # Should be the same logic as CallValidation.wrap_method_if_needed but we
213
217
  # don't want that extra layer of indirection in the callstack
@@ -238,28 +242,40 @@ module T::Private::Methods
238
242
  end
239
243
  end
240
244
 
241
- def self._handle_missing_method_signature(mod, original_method, callee)
245
+ def self._handle_missing_method_signature(receiver, original_method, callee)
242
246
  method_sig = T::Private::Methods.signature_for_method(original_method)
243
- aliasing_method = mod.instance_method(callee)
244
-
245
- if method_sig && aliasing_method != original_method && aliasing_method.original_name == original_method.name
246
- # We're handling a case where `alias` or `alias_method` was called for a
247
- # method which had already had a `sig` applied.
248
- #
249
- # Note, this logic is duplicated above, make sure to keep changes in sync.
250
- if method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
251
- # Checked, so copy the original signature to the aliased copy.
252
- T::Private::Methods.unwrap_method(mod, method_sig, aliasing_method)
253
- else
254
- # Unchecked, so just make `alias_method` behave as if it had been called pre-sig.
255
- mod.send(:alias_method, callee, original_method.name)
256
- end
257
- else
258
- raise "`sig` not present for method `#{aliasing_method.name}` but you're trying to run it anyways. " \
247
+ if !method_sig
248
+ raise "`sig` not present for method `#{callee}` on #{receiver.inspect} but you're trying to run it anyways. " \
259
249
  "This should only be executed if you used `alias_method` to grab a handle to a method after `sig`ing it, but that clearly isn't what you are doing. " \
260
250
  "Maybe look to see if an exception was thrown in your `sig` lambda or somehow else your `sig` wasn't actually applied to the method."
261
251
  end
262
252
 
253
+ if receiver.class <= original_method.owner
254
+ receiving_class = receiver.class
255
+ elsif receiver.singleton_class <= original_method.owner
256
+ receiving_class = receiver.singleton_class
257
+ elsif receiver.is_a?(Module) && receiver <= original_method.owner
258
+ receiving_class = receiver
259
+ else
260
+ raise "#{receiver} is not related to #{original_method} - how did we get here?"
261
+ end
262
+
263
+ # Check for a case where `alias` or `alias_method` was called for a
264
+ # method which had already had a `sig` applied. In that case, we want
265
+ # to avoid hitting this slow path again, by moving to a faster validator
266
+ # just like we did or will for the original method.
267
+ #
268
+ # If this isn't an `alias` or `alias_method` case, we're probably in the
269
+ # middle of some metaprogramming using a Method object, e.g. a pattern like
270
+ # `arr.map(&method(:foo))`. There's nothing really we can do to optimize
271
+ # that here.
272
+ receiving_method = receiving_class.instance_method(callee)
273
+ if receiving_method != original_method && receiving_method.original_name == original_method.name
274
+ aliasing_mod = receiving_method.owner
275
+ method_sig = method_sig.as_alias(callee)
276
+ unwrap_method(aliasing_mod, method_sig, original_method)
277
+ end
278
+
263
279
  method_sig
264
280
  end
265
281
 
@@ -281,7 +297,7 @@ module T::Private::Methods
281
297
  Signature.new_untyped(method: original_method)
282
298
  end
283
299
 
284
- unwrap_method(hook_mod, signature, original_method)
300
+ unwrap_method(signature.method.owner, signature, original_method)
285
301
  signature
286
302
  end
287
303
 
@@ -333,8 +349,8 @@ module T::Private::Methods
333
349
  end
334
350
  end
335
351
 
336
- def self.unwrap_method(hook_mod, signature, original_method)
337
- maybe_wrapped_method = CallValidation.wrap_method_if_needed(signature.method.owner, signature, original_method)
352
+ def self.unwrap_method(mod, signature, original_method)
353
+ maybe_wrapped_method = CallValidation.wrap_method_if_needed(mod, signature, original_method)
338
354
  @signatures_by_method[method_to_key(maybe_wrapped_method)] = signature
339
355
  end
340
356
 
@@ -121,6 +121,15 @@ class T::Private::Methods::Signature
121
121
  end
122
122
  end
123
123
 
124
+ attr_writer :method_name
125
+ protected :method_name=
126
+
127
+ def as_alias(alias_name)
128
+ new_sig = clone
129
+ new_sig.method_name = alias_name
130
+ new_sig
131
+ end
132
+
124
133
  def arg_count
125
134
  @arg_types.length
126
135
  end
@@ -146,9 +155,10 @@ class T::Private::Methods::Signature
146
155
  # can't) match the definition of the method we're validating. In addition, Ruby has a bug that
147
156
  # causes forwarding **kwargs to do the wrong thing: see https://bugs.ruby-lang.org/issues/10708
148
157
  # and https://bugs.ruby-lang.org/issues/11860.
149
- if (args.length > @req_arg_count) && (!@kwarg_types.empty? || @has_keyrest) && args[-1].is_a?(Hash)
158
+ args_length = args.length
159
+ if (args_length > @req_arg_count) && (!@kwarg_types.empty? || @has_keyrest) && args[-1].is_a?(Hash)
150
160
  kwargs = args[-1]
151
- args = args[0...-1]
161
+ args_length -= 1
152
162
  else
153
163
  kwargs = EMPTY_HASH
154
164
  end
@@ -156,19 +166,19 @@ class T::Private::Methods::Signature
156
166
  arg_types = @arg_types
157
167
 
158
168
  if @has_rest
159
- arg_types += [[@rest_name, @rest_type]] * (args.length - @arg_types.length)
169
+ arg_types += [[@rest_name, @rest_type]] * (args_length - @arg_types.length)
160
170
 
161
- elsif (args.length < @req_arg_count) || (args.length > @arg_types.length)
171
+ elsif (args_length < @req_arg_count) || (args_length > @arg_types.length)
162
172
  expected_str = @req_arg_count.to_s
163
173
  if @arg_types.length != @req_arg_count
164
174
  expected_str += "..#{@arg_types.length}"
165
175
  end
166
- raise ArgumentError.new("wrong number of arguments (given #{args.length}, expected #{expected_str})")
176
+ raise ArgumentError.new("wrong number of arguments (given #{args_length}, expected #{expected_str})")
167
177
  end
168
178
 
169
179
  begin
170
180
  it = 0
171
- while it < args.length
181
+ while it < args_length
172
182
  yield arg_types[it][0], args[it], arg_types[it][1]
173
183
  it += 1
174
184
  end
@@ -12,7 +12,11 @@ module T::Types
12
12
 
13
13
  # @override Base
14
14
  def name
15
- @raw_type.name
15
+ # Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
16
+ #
17
+ # `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
18
+ # and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
19
+ @name ||= @raw_type.name.freeze
16
20
  end
17
21
 
18
22
  # @override Base
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.5848
4
+ version: 0.5.5862
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest