sorbet-runtime 0.6.13612 → 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: 2a55754bbdc43cfcf4bf7fee9c48115331cc0f1382cdb8419b7892751d2ca1b6
4
- data.tar.gz: 7be4e804bb6055583e367662baacff6217a5f0806b0d069e4dfef05d0837431f
3
+ metadata.gz: 53d7992bc3b757a09cec54c0adaf659670b8e2f13d1429a42c9af6289575a75b
4
+ data.tar.gz: 59f61eb250810f11570be0509ca0c06a1642d1898b0f260891735ce435e97d2f
5
5
  SHA512:
6
- metadata.gz: 559bedbd9597db5b2502796002d6911ee4fc2dba33d8a2f0d4c890bf2156db1079f191e7b6768dd4963fb378691d69a0b1c2200f6eb9ca3a3c97cfc473fcc471
7
- data.tar.gz: e30c5fc33877556d12997f7b2484a4abdeb4fcb4224792c6ba8e3c8310850a41e913c6f761cbc538ad568a792f8c51eae28a4e50f7457ce6464487ba7d23b140
6
+ metadata.gz: 9236e351b585061fd58490a603d75d19ca1f43a6e742a3abd57a648214a5b050d4d4408409004c150bbbfb87e8af9afbba11633067aa253c739acc39d718f727
7
+ data.tar.gz: f69a44eda94a3646b1d0422bf15d9bc2cf92da478c3f0a1615ac986a16a10371470621813d65c6d3222ce7382e7b55c7b6aead62916ee99f1c11dc422536ddad
@@ -616,6 +616,17 @@ module T::Private::Methods
616
616
  @signatures_by_method[method_to_key(maybe_wrapped_method)] = signature
617
617
  end
618
618
 
619
+ # This method tells whether `drop_unchecked_sigs!` can free `signature`.
620
+ # It returns true for a signature whose runtime checks never run.
621
+ # It returns false for an `abstract` signature, because `T::AbstractUtils`
622
+ # reads that signature after load time.
623
+ private_class_method def self.drop_sig?(signature)
624
+ return false if signature.mode == Modes.abstract
625
+
626
+ signature.check_level == :never ||
627
+ (signature.check_level == :tests && !T::Private::RuntimeLevels.check_tests?)
628
+ end
629
+
619
630
  # Only public because it needs to get called inside the first-call wrapper closure.
620
631
  def self._sig_block_is_current?(key, sig_block)
621
632
  @sig_wrappers[key].equal?(sig_block)
@@ -699,6 +710,10 @@ module T::Private::Methods
699
710
  @signatures_by_method.values.select { |sig| sig.check_level == :tests }
700
711
  end
701
712
 
713
+ def self.drop_unchecked_sigs!
714
+ @signatures_by_method.delete_if { |_key, sig| drop_sig?(sig) }
715
+ end
716
+
702
717
  # the module target is adding the methods from the module source to itself. we need to check that for all instance
703
718
  # methods M on source, M is not defined on any of target's ancestors.
704
719
  def self._hook_impl(target, source)
@@ -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
data/lib/types/utils.rb CHANGED
@@ -191,6 +191,18 @@ module T::Utils
191
191
  nil
192
192
  end
193
193
 
194
+ # Free the signatures whose runtime checks never run: the `.checked(:never)`
195
+ # sigs, plus the `.checked(:tests)` sigs outside of a test environment. After
196
+ # this call, `T::Utils.signature_for_method` returns `nil` for those methods,
197
+ # and nothing can rebuild them.
198
+ #
199
+ # Call this once after eagerly preloading a codebase (e.g. at service startup)
200
+ # and after `run_all_sig_blocks`, to trade that introspection for memory.
201
+ def self.drop_unchecked_sigs!
202
+ T::Private::Methods.drop_unchecked_sigs!
203
+ nil
204
+ end
205
+
194
206
  def self.lift_enum(enum)
195
207
  unless enum.is_a?(T::Types::Enum)
196
208
  raise ArgumentError.new("#{enum.inspect} is not a T.deprecated_enum")
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.13612
4
+ version: 0.6.13616
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe