sorbet-runtime 0.6.13621 → 0.6.13632
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 +4 -4
- data/lib/types/private/methods/signature.rb +49 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4257e8ca00e1add499a378928571bea2674281fc10b65796b343f1ab934ad360
|
|
4
|
+
data.tar.gz: f3960d20e4b93c67c085b8745f5c29560296c741930f3d7f6207a0bfae394260
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1e44f1984ffc3e8b309834a19491128133f0956842ce6372acb4caa2b2b669f7e1669f5d8213a8d614f1c900015b0239d5c0d2e9f87e426dad796a1155b9814
|
|
7
|
+
data.tar.gz: f97d4f469a9ef194c4d169c77eb3653c65ce6990c45dfabeb3b1be0b5247e48c942e75c165ba341d97307e1924567bc62bf9099ac76ac4724d94b5c667ecbb5a
|
|
@@ -7,9 +7,22 @@
|
|
|
7
7
|
class T::Private::Methods::Signature
|
|
8
8
|
attr_reader :method, :method_name, :arg_types, :kwarg_types, :block_type,
|
|
9
9
|
:rest_type, :keyrest_type, :bind, :effective_return_type,
|
|
10
|
-
:return_type, :
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
:return_type, :req_arg_count, :req_kwarg_names, :on_failure
|
|
11
|
+
|
|
12
|
+
# @flags packs, from the low bits up: mode (3 bits), check_level (2 bits),
|
|
13
|
+
# override_allow_incompatible (2 bits), and defined_raw (1 bit).
|
|
14
|
+
FLAG_MODES = T::Private::Methods::Modes::MODES
|
|
15
|
+
FLAG_CHECK_LEVELS = T::Private::RuntimeLevels::LEVELS
|
|
16
|
+
FLAG_ALLOW_INCOMPATIBLE = [false, true, :visibility].freeze
|
|
17
|
+
MODE_MASK = 0b111
|
|
18
|
+
CHECK_LEVEL_SHIFT = 3
|
|
19
|
+
CHECK_LEVEL_MASK = 0b11
|
|
20
|
+
ALLOW_INCOMPATIBLE_SHIFT = 5
|
|
21
|
+
ALLOW_INCOMPATIBLE_MASK = 0b11
|
|
22
|
+
DEFINED_RAW_BIT = 1 << 7
|
|
23
|
+
private_constant :FLAG_MODES, :FLAG_CHECK_LEVELS, :FLAG_ALLOW_INCOMPATIBLE, :MODE_MASK,
|
|
24
|
+
:CHECK_LEVEL_SHIFT, :CHECK_LEVEL_MASK, :ALLOW_INCOMPATIBLE_SHIFT,
|
|
25
|
+
:ALLOW_INCOMPATIBLE_MASK, :DEFINED_RAW_BIT
|
|
13
26
|
|
|
14
27
|
# T.unsafe: `UnboundMethod#parameters` lies and says `T::Array[[Symbol, Symbol]]`.
|
|
15
28
|
# Sorbet can't lub tuple types, meaning that `T.any([Symbol], [Symbol,
|
|
@@ -45,7 +58,7 @@ class T::Private::Methods::Signature
|
|
|
45
58
|
)
|
|
46
59
|
end
|
|
47
60
|
|
|
48
|
-
def initialize(method:, method_name:, raw_arg_types:, raw_return_type:, bind:, mode:, check_level:, on_failure:, parameters:
|
|
61
|
+
def initialize(method:, method_name:, raw_arg_types:, raw_return_type:, bind:, mode:, check_level:, on_failure:, parameters: nil, override_allow_incompatible: false, defined_raw: false)
|
|
49
62
|
check_level = check_level.nil? ? T::Private::RuntimeLevels.default_checked_level : check_level
|
|
50
63
|
@method = method
|
|
51
64
|
@method_name = method_name
|
|
@@ -59,12 +72,13 @@ class T::Private::Methods::Signature
|
|
|
59
72
|
@return_type
|
|
60
73
|
end
|
|
61
74
|
@bind = NilClass.===(bind) ? bind : T::Utils.coerce(bind)
|
|
62
|
-
@mode = mode
|
|
63
|
-
@check_level = check_level
|
|
64
75
|
@parameters = parameters
|
|
76
|
+
parameters ||= method.parameters
|
|
65
77
|
@on_failure = on_failure
|
|
66
|
-
@
|
|
67
|
-
|
|
78
|
+
@flags = flag_index(FLAG_MODES, mode, 'mode') |
|
|
79
|
+
(flag_index(FLAG_CHECK_LEVELS, check_level, 'check_level') << CHECK_LEVEL_SHIFT) |
|
|
80
|
+
(flag_index(FLAG_ALLOW_INCOMPATIBLE, override_allow_incompatible, 'override_allow_incompatible') << ALLOW_INCOMPATIBLE_SHIFT) |
|
|
81
|
+
(defined_raw ? DEFINED_RAW_BIT : 0)
|
|
68
82
|
|
|
69
83
|
# Use T.untyped in lieu of T.nilable to try to avoid unnecessary allocations.
|
|
70
84
|
arg_types = nil
|
|
@@ -159,6 +173,7 @@ class T::Private::Methods::Signature
|
|
|
159
173
|
i += 1
|
|
160
174
|
end
|
|
161
175
|
|
|
176
|
+
@parameters ||= parameters unless @rest_type.nil?
|
|
162
177
|
@arg_types = arg_types || EMPTY_LIST
|
|
163
178
|
@kwarg_types = kwarg_types || EMPTY_HASH
|
|
164
179
|
@req_arg_count = req_arg_count
|
|
@@ -175,6 +190,10 @@ class T::Private::Methods::Signature
|
|
|
175
190
|
end
|
|
176
191
|
|
|
177
192
|
# Names are derived rather than stored so that Signature fits in a smaller GC slot.
|
|
193
|
+
def parameters
|
|
194
|
+
@parameters || @method.parameters
|
|
195
|
+
end
|
|
196
|
+
|
|
178
197
|
def block_name
|
|
179
198
|
parameter_name(:block)
|
|
180
199
|
end
|
|
@@ -187,6 +206,22 @@ class T::Private::Methods::Signature
|
|
|
187
206
|
parameter_name(:keyrest)
|
|
188
207
|
end
|
|
189
208
|
|
|
209
|
+
def mode
|
|
210
|
+
FLAG_MODES.fetch(@flags & MODE_MASK)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def check_level
|
|
214
|
+
FLAG_CHECK_LEVELS.fetch((@flags >> CHECK_LEVEL_SHIFT) & CHECK_LEVEL_MASK)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def override_allow_incompatible
|
|
218
|
+
FLAG_ALLOW_INCOMPATIBLE.fetch((@flags >> ALLOW_INCOMPATIBLE_SHIFT) & ALLOW_INCOMPATIBLE_MASK)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def defined_raw
|
|
222
|
+
@flags.anybits?(DEFINED_RAW_BIT)
|
|
223
|
+
end
|
|
224
|
+
|
|
190
225
|
def arg_count
|
|
191
226
|
@arg_types.length
|
|
192
227
|
end
|
|
@@ -283,12 +318,16 @@ class T::Private::Methods::Signature
|
|
|
283
318
|
|
|
284
319
|
# The rest param directly follows the positional params unless required params come after it.
|
|
285
320
|
private def fast_rest_name
|
|
286
|
-
param_kind, param_name =
|
|
321
|
+
param_kind, param_name = parameters[@arg_types.length]
|
|
287
322
|
param_kind == :rest ? param_name : parameter_name(:rest)
|
|
288
323
|
end
|
|
289
324
|
|
|
290
325
|
private def parameter_name(kind)
|
|
291
|
-
|
|
326
|
+
parameters.assoc(kind)&.[](1)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
private def flag_index(values, value, field)
|
|
330
|
+
values.index(value) || raise(ArgumentError.new("Invalid #{field} for `#{@method_name}`: #{value.inspect}"))
|
|
292
331
|
end
|
|
293
332
|
|
|
294
333
|
EMPTY_LIST = [].freeze
|