sorbet-runtime 0.6.13615 → 0.6.13616

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: 83afd87671f904e0e627730dbefaa1f70173159106c48dc129e684627236bb6d
4
- data.tar.gz: 3b0f25dc28f65cd39e560ebdc0b625eda8651030693f9a185fd86557b2363628
3
+ metadata.gz: 53d7992bc3b757a09cec54c0adaf659670b8e2f13d1429a42c9af6289575a75b
4
+ data.tar.gz: 59f61eb250810f11570be0509ca0c06a1642d1898b0f260891735ce435e97d2f
5
5
  SHA512:
6
- metadata.gz: 8bc6a890b37dda640b8c830f3385319a1bb4ef01239e0bec56138240117e0e5f4f14aa64806027f4918c2ee60d31521c876ce072d7f853d1ff77892f2336ecc3
7
- data.tar.gz: 1befcd02c403f3d20652f7637d365085e296e00ff178a496a72e700b943aa5ff8a744d80597fc02d6a6528a25114f86cf2ab289edd80987ef3d9a4ce7abe901a
6
+ metadata.gz: 9236e351b585061fd58490a603d75d19ca1f43a6e742a3abd57a648214a5b050d4d4408409004c150bbbfb87e8af9afbba11633067aa253c739acc39d718f727
7
+ data.tar.gz: f69a44eda94a3646b1d0422bf15d9bc2cf92da478c3f0a1615ac986a16a10371470621813d65c6d3222ce7382e7b55c7b6aead62916ee99f1c11dc422536ddad
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
+ # Every sig keeps one of these for the life of the process. At 18 or fewer instance variables an
5
+ # instance fits in a 160-byte GC slot; a 19th moves every instance to the 320-byte slot, so prefer
6
+ # deriving new state over storing it.
4
7
  class T::Private::Methods::Signature
5
- attr_reader :method, :method_name, :arg_types, :kwarg_types, :block_type, :block_name,
6
- :rest_type, :rest_name, :keyrest_type, :keyrest_name, :bind, :effective_return_type,
8
+ attr_reader :method, :method_name, :arg_types, :kwarg_types, :block_type,
9
+ :rest_type, :keyrest_type, :bind, :effective_return_type,
7
10
  :return_type, :mode, :req_arg_count, :req_kwarg_names,
8
11
  :check_level, :parameters, :on_failure, :override_allow_incompatible,
9
12
  :defined_raw
@@ -47,11 +50,8 @@ class T::Private::Methods::Signature
47
50
  @method = method
48
51
  @method_name = method_name
49
52
  @block_type = nil
50
- @block_name = nil
51
53
  @rest_type = nil
52
- @rest_name = nil
53
54
  @keyrest_type = nil
54
- @keyrest_name = nil
55
55
  @return_type = T::Utils.coerce(raw_return_type)
56
56
  @effective_return_type = if check_level == :tests && @return_type.is_a?(T::Private::Types::Void)
57
57
  T::Types::Anything::Private::INSTANCE
@@ -147,13 +147,10 @@ class T::Private::Methods::Signature
147
147
  (req_kwarg_names ||= []) << param_name
148
148
  end
149
149
  when :block
150
- @block_name = param_name
151
150
  @block_type = type
152
151
  when :rest
153
- @rest_name = param_name
154
152
  @rest_type = type
155
153
  when :keyrest
156
- @keyrest_name = param_name
157
154
  @keyrest_type = type
158
155
  else
159
156
  raise "Unexpected param_kind: `#{param_kind}`. Method: #{method_desc}"
@@ -177,6 +174,19 @@ class T::Private::Methods::Signature
177
174
  new_sig
178
175
  end
179
176
 
177
+ # Names are derived rather than stored so that Signature fits in a smaller GC slot.
178
+ def block_name
179
+ parameter_name(:block)
180
+ end
181
+
182
+ def rest_name
183
+ parameter_name(:rest)
184
+ end
185
+
186
+ def keyrest_name
187
+ parameter_name(:keyrest)
188
+ end
189
+
180
190
  def arg_count
181
191
  @arg_types.length
182
192
  end
@@ -227,11 +237,14 @@ class T::Private::Methods::Signature
227
237
 
228
238
  if !@rest_type.nil?
229
239
  rest_count = args_length - @arg_types.length
230
- rest_count = 0 if rest_count.negative?
231
240
 
232
- rest_count.times do
233
- yield @rest_name, args[it], @rest_type
234
- it += 1
241
+ if rest_count > 0
242
+ rest_name = fast_rest_name
243
+
244
+ rest_count.times do
245
+ yield rest_name, args[it], @rest_type
246
+ it += 1
247
+ end
235
248
  end
236
249
  end
237
250
  end
@@ -268,6 +281,16 @@ class T::Private::Methods::Signature
268
281
  @return_type.build_type
269
282
  end
270
283
 
284
+ # The rest param directly follows the positional params unless required params come after it.
285
+ private def fast_rest_name
286
+ param_kind, param_name = @parameters[@arg_types.length]
287
+ param_kind == :rest ? param_name : parameter_name(:rest)
288
+ end
289
+
290
+ private def parameter_name(kind)
291
+ @parameters.assoc(kind)&.[](1)
292
+ end
293
+
271
294
  EMPTY_LIST = [].freeze
272
295
  EMPTY_HASH = {}.freeze
273
296
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13615
4
+ version: 0.6.13616
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe