sorbet-runtime 0.5.6466 → 0.5.6479
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32d01a68ba67b1c6236b4d8e04cbca7937e3dfc9e413b71d12e95df2a66f2fcb
|
4
|
+
data.tar.gz: 612f745d5c3c547aac1ab0c4b14f4f0f050402b7b1bd2aef4994d687396d4a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2839c3841676ac7639bf276cd6a52f074a8d19dccd2b8b51290210e689c33c78f6db094d9bc52c177864559fee22858bc389f7cd8961b60dd133083a14b2b24f
|
7
|
+
data.tar.gz: e33e3b5bd8b1901e666e969ddb18a85795dbd8c7ccf4b4db2939bbd553bd18e9a63597879b4284c88ce6d9857a5fee7a50741ee1aa7046c2eec1b5aeda7d3ff1
|
@@ -26,14 +26,23 @@ module T::Private::Methods
|
|
26
26
|
# in installed_hooks.
|
27
27
|
@old_hooks = nil
|
28
28
|
|
29
|
-
@declaring_final_method = false
|
30
|
-
|
31
29
|
ARG_NOT_PROVIDED = Object.new
|
32
30
|
PROC_TYPE = Object.new
|
33
31
|
|
34
|
-
DeclarationBlock = Struct.new(:mod, :loc, :blk, :final)
|
32
|
+
DeclarationBlock = Struct.new(:mod, :loc, :blk, :final, :raw)
|
33
|
+
|
34
|
+
def self.declare_sig(mod, loc, arg, &blk)
|
35
|
+
T::Private::DeclState.current.active_declaration = _declare_sig_internal(mod, loc, arg, &blk)
|
36
|
+
|
37
|
+
nil
|
38
|
+
end
|
35
39
|
|
36
|
-
|
40
|
+
# See tests for how to use this. But you shouldn't be using this.
|
41
|
+
def self._declare_sig(mod, arg=nil, &blk)
|
42
|
+
_declare_sig_internal(mod, caller_locations(1, 1).first, arg, raw: true, &blk)
|
43
|
+
end
|
44
|
+
|
45
|
+
private_class_method def self._declare_sig_internal(mod, loc, arg, raw: false, &blk)
|
37
46
|
install_hooks(mod)
|
38
47
|
|
39
48
|
if T::Private::DeclState.current.active_declaration
|
@@ -45,15 +54,26 @@ module T::Private::Methods
|
|
45
54
|
raise "Invalid argument to `sig`: #{arg}"
|
46
55
|
end
|
47
56
|
|
48
|
-
loc
|
49
|
-
|
50
|
-
T::Private::DeclState.current.active_declaration = DeclarationBlock.new(mod, loc, blk, arg == :final)
|
57
|
+
DeclarationBlock.new(mod, loc, blk, arg == :final, raw)
|
58
|
+
end
|
51
59
|
|
52
|
-
|
60
|
+
def self._with_declared_signature(mod, declblock, &blk)
|
61
|
+
# If declblock is provided, this code is equivalent to the check in
|
62
|
+
# _declare_sig_internal, above.
|
63
|
+
# If declblock is not provided and we have an active declaration, we are
|
64
|
+
# obviously doing something wrong.
|
65
|
+
if T::Private::DeclState.current.active_declaration
|
66
|
+
T::Private::DeclState.current.reset!
|
67
|
+
raise "You called sig twice without declaring a method in between"
|
68
|
+
end
|
69
|
+
if declblock
|
70
|
+
T::Private::DeclState.current.active_declaration = declblock
|
71
|
+
end
|
72
|
+
mod.module_exec(&blk)
|
53
73
|
end
|
54
74
|
|
55
75
|
def self.start_proc
|
56
|
-
DeclBuilder.new(PROC_TYPE)
|
76
|
+
DeclBuilder.new(PROC_TYPE, false)
|
57
77
|
end
|
58
78
|
|
59
79
|
def self.finalize_proc(decl)
|
@@ -182,17 +202,6 @@ module T::Private::Methods
|
|
182
202
|
@modules_with_final[mod.singleton_class]
|
183
203
|
end
|
184
204
|
|
185
|
-
# See tests for how to use this.
|
186
|
-
def self._with_declaring_final_method_INTERNAL(&blk)
|
187
|
-
begin
|
188
|
-
prev_value = @declaring_final_method
|
189
|
-
@declaring_final_method = true
|
190
|
-
yield
|
191
|
-
ensure
|
192
|
-
@declaring_final_method = prev_value
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
205
|
# Only public because it needs to get called below inside the replace_method blocks below.
|
197
206
|
def self._on_method_added(hook_mod, method_name, is_singleton_method: false)
|
198
207
|
if T::Private::DeclState.current.skip_on_method_added
|
@@ -202,9 +211,7 @@ module T::Private::Methods
|
|
202
211
|
current_declaration = T::Private::DeclState.current.active_declaration
|
203
212
|
mod = is_singleton_method ? hook_mod.singleton_class : hook_mod
|
204
213
|
|
205
|
-
|
206
|
-
method_is_final = directly_declaring_final_method || current_declaration&.final
|
207
|
-
if T::Private::Final.final_module?(mod) && !method_is_final
|
214
|
+
if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
|
208
215
|
raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
|
209
216
|
end
|
210
217
|
# Don't compute mod.ancestors if we don't need to bother checking final-ness.
|
@@ -227,17 +234,17 @@ module T::Private::Methods
|
|
227
234
|
)
|
228
235
|
end
|
229
236
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
237
|
+
original_method = mod.instance_method(method_name)
|
238
|
+
sig_block = lambda do
|
239
|
+
T::Private::Methods.run_sig(hook_mod, method_name, original_method, current_declaration)
|
240
|
+
end
|
235
241
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
242
|
+
# Always replace the original method with this wrapper,
|
243
|
+
# which is called only on the *first* invocation.
|
244
|
+
# This wrapper is very slow, so it will subsequently re-wrap with a much faster wrapper
|
245
|
+
# (or unwrap back to the original method).
|
246
|
+
key = method_owner_and_name_to_key(mod, method_name)
|
247
|
+
unless current_declaration.raw
|
241
248
|
T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
|
242
249
|
method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
|
243
250
|
method_sig ||= T::Private::Methods._handle_missing_method_signature(
|
@@ -265,11 +272,10 @@ module T::Private::Methods
|
|
265
272
|
original_method.bind(self).call(*args, &blk)
|
266
273
|
end
|
267
274
|
end
|
268
|
-
|
269
|
-
@sig_wrappers[key] = sig_block
|
270
275
|
end
|
271
276
|
|
272
|
-
|
277
|
+
@sig_wrappers[key] = sig_block
|
278
|
+
if current_declaration.final
|
273
279
|
@was_ever_final_names.add(method_name)
|
274
280
|
# use hook_mod, not mod, because for example, we want class C to be marked as having final if we def C.foo as
|
275
281
|
# final. change this to mod to see some final_method tests fail.
|
@@ -338,7 +344,7 @@ module T::Private::Methods
|
|
338
344
|
end
|
339
345
|
|
340
346
|
def self.run_builder(declaration_block)
|
341
|
-
builder = DeclBuilder.new(declaration_block.mod)
|
347
|
+
builder = DeclBuilder.new(declaration_block.mod, declaration_block.raw)
|
342
348
|
builder
|
343
349
|
.instance_exec(&declaration_block.blk)
|
344
350
|
.finalize!
|
@@ -369,6 +375,7 @@ module T::Private::Methods
|
|
369
375
|
check_level: current_declaration.checked,
|
370
376
|
on_failure: current_declaration.on_failure,
|
371
377
|
override_allow_incompatible: current_declaration.override_allow_incompatible,
|
378
|
+
defined_raw: current_declaration.raw,
|
372
379
|
)
|
373
380
|
|
374
381
|
SignatureValidation.validate(signature)
|
@@ -27,6 +27,8 @@ module T::Private::Methods::CallValidation
|
|
27
27
|
)
|
28
28
|
end
|
29
29
|
end
|
30
|
+
# Do nothing in this case; this method was not wrapped in _on_method_added.
|
31
|
+
elsif method_sig.defined_raw
|
30
32
|
# Note, this logic is duplicated (intentionally, for micro-perf) at `Methods._on_method_added`,
|
31
33
|
# make sure to keep changes in sync.
|
32
34
|
# This is a trapdoor point for each method:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# typed: true
|
3
3
|
|
4
4
|
module T::Private::Methods
|
5
|
-
Declaration = Struct.new(:mod, :params, :returns, :bind, :mode, :checked, :finalized, :on_failure, :override_allow_incompatible, :type_parameters)
|
5
|
+
Declaration = Struct.new(:mod, :params, :returns, :bind, :mode, :checked, :finalized, :on_failure, :override_allow_incompatible, :type_parameters, :raw)
|
6
6
|
|
7
7
|
class DeclBuilder
|
8
8
|
attr_reader :decl
|
@@ -15,7 +15,7 @@ module T::Private::Methods
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(mod)
|
18
|
+
def initialize(mod, raw)
|
19
19
|
# TODO RUBYPLAT-1278 - with ruby 2.5, use kwargs here
|
20
20
|
@decl = Declaration.new(
|
21
21
|
mod,
|
@@ -28,6 +28,7 @@ module T::Private::Methods
|
|
28
28
|
ARG_NOT_PROVIDED, # on_failure
|
29
29
|
nil, # override_allow_incompatible
|
30
30
|
ARG_NOT_PROVIDED, # type_parameters
|
31
|
+
raw
|
31
32
|
)
|
32
33
|
end
|
33
34
|
|
@@ -5,7 +5,8 @@ class T::Private::Methods::Signature
|
|
5
5
|
attr_reader :method, :method_name, :arg_types, :kwarg_types, :block_type, :block_name,
|
6
6
|
:rest_type, :rest_name, :keyrest_type, :keyrest_name, :bind,
|
7
7
|
:return_type, :mode, :req_arg_count, :req_kwarg_names, :has_rest, :has_keyrest,
|
8
|
-
:check_level, :parameters, :on_failure, :override_allow_incompatible
|
8
|
+
:check_level, :parameters, :on_failure, :override_allow_incompatible,
|
9
|
+
:defined_raw
|
9
10
|
|
10
11
|
def self.new_untyped(method:, mode: T::Private::Methods::Modes.untyped, parameters: method.parameters)
|
11
12
|
# Using `Untyped` ensures we'll get an error if we ever try validation on these.
|
@@ -32,7 +33,7 @@ class T::Private::Methods::Signature
|
|
32
33
|
)
|
33
34
|
end
|
34
35
|
|
35
|
-
def initialize(method:, method_name:, raw_arg_types:, raw_return_type:, bind:, mode:, check_level:, on_failure:, parameters: method.parameters, override_allow_incompatible: false)
|
36
|
+
def initialize(method:, method_name:, raw_arg_types:, raw_return_type:, bind:, mode:, check_level:, on_failure:, parameters: method.parameters, override_allow_incompatible: false, defined_raw: false)
|
36
37
|
@method = method
|
37
38
|
@method_name = method_name
|
38
39
|
@arg_types = []
|
@@ -54,6 +55,7 @@ class T::Private::Methods::Signature
|
|
54
55
|
@parameters = parameters
|
55
56
|
@on_failure = on_failure
|
56
57
|
@override_allow_incompatible = override_allow_incompatible
|
58
|
+
@defined_raw = defined_raw
|
57
59
|
|
58
60
|
declared_param_names = raw_arg_types.keys
|
59
61
|
# If sig params are declared but there is a single parameter with a missing name
|
data/lib/types/sig.rb
CHANGED
@@ -25,6 +25,6 @@ module T::Sig
|
|
25
25
|
# {T::Helpers}
|
26
26
|
T::Sig::WithoutRuntime.sig {params(arg0: T.nilable(Symbol), blk: T.proc.bind(T::Private::Methods::DeclBuilder).void).void}
|
27
27
|
def sig(arg0=nil, &blk)
|
28
|
-
T::Private::Methods.declare_sig(self, arg0, &blk)
|
28
|
+
T::Private::Methods.declare_sig(self, Kernel.caller_locations(1, 1)&.first, arg0, &blk)
|
29
29
|
end
|
30
30
|
end
|
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.
|
4
|
+
version: 0.5.6479
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|