sorbet-runtime 0.6.13299 → 0.6.13301
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/call_validation.rb +38 -1
- data/lib/types/private/methods/call_validation_2_7.rb +1026 -0
- data/lib/types/private/methods/signature_validation.rb +38 -12
- data/lib/types/props/constructor.rb +2 -2
- data/lib/types/props/custom_type.rb +7 -1
- data/lib/types/props/decorator.rb +42 -25
- data/lib/types/props/generated_code_validation.rb +10 -4
- data/lib/types/props/has_lazily_specialized_methods.rb +36 -4
- data/lib/types/props/optional.rb +2 -2
- data/lib/types/props/private/apply_default.rb +21 -21
- data/lib/types/props/private/deserializer_generator.rb +7 -1
- data/lib/types/props/private/serde_transform.rb +4 -4
- data/lib/types/props/private/setter_factory.rb +68 -5
- data/lib/types/props/utils.rb +38 -10
- data/lib/types/props/weak_constructor.rb +9 -4
- data/lib/types/types/base.rb +10 -0
- data/lib/types/types/typed_set.rb +5 -9
- 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: 11be14e5fdfd480b79b5c799ffc878c604f8cdd3c5776f5b7eb55eaf143d59ee
|
|
4
|
+
data.tar.gz: c90d13ff890616e82d414249178bbd5dfb080c7604bc5b4a5c2b706ef9fd63c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40aebdc992a72011d67c62214f0cd36d7cf1a6a728c1c9db44beb6b2af5d97b4a7783b2896892382bdc10cde4bb9a4a3be8aa9ea901da409902569a6e52ee9ed
|
|
7
|
+
data.tar.gz: efbf3fff51bae607d1e0c25e12c768c95ce5e289677ab9f22fd5fb88b7f8045c9dd0940c5d3efba7b9d1ac66c53d6da166d062311b2a4b0e812166b17ba867cf
|
|
@@ -72,8 +72,16 @@ module T::Private::Methods::CallValidation
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def self.create_validator_method(mod, original_method, method_sig, original_visibility)
|
|
75
|
+
# Wrapper-shape decisions must read the parameters of the method actually being wrapped, not
|
|
76
|
+
# `method_sig.parameters` (captured at sig-build time). The two diverge when a sig'd method is
|
|
77
|
+
# re-wrapped over a different implementation: a stub redefined as `def m(*args, **kwargs, &blk)`
|
|
78
|
+
# then re-validated against the original fixed-arity sig would otherwise pick a fixed-arity wrapper,
|
|
79
|
+
# which binds args to named positionals and forwards them without the `ruby2_keywords` flag, turning
|
|
80
|
+
# a trailing `key: val` into a positional hash. Reading from `original_method` costs one array per
|
|
81
|
+
# wrap, off the hot path.
|
|
82
|
+
parameters = original_method.parameters
|
|
75
83
|
has_fixed_arity = method_sig.kwarg_types.empty? && method_sig.rest_type.nil? && method_sig.keyrest_type.nil? &&
|
|
76
|
-
|
|
84
|
+
parameters.all? { |(kind, _name)| kind == :req || kind == :block }
|
|
77
85
|
|
|
78
86
|
# nil implies block_type.nil?
|
|
79
87
|
# true implies !block_type.nil? and block_type.valid?(nil)
|
|
@@ -83,6 +91,29 @@ module T::Private::Methods::CallValidation
|
|
|
83
91
|
|
|
84
92
|
ok_for_fast_path = has_fixed_arity && can_skip_block_type && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
|
85
93
|
|
|
94
|
+
# Like `ok_for_fast_path`, but for the specialized wrappers below, each of
|
|
95
|
+
# which supports exactly one extra call shape (kwargs, a required block, or
|
|
96
|
+
# optional positional args) on top of what the fast/medium wrappers support.
|
|
97
|
+
ok_for_specialized_path = !ok_for_fast_path && !method_sig.bind && method_sig.rest_type.nil? &&
|
|
98
|
+
method_sig.keyrest_type.nil? && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
|
99
|
+
|
|
100
|
+
# Restricted to methods with no positional args. The kwargs wrapper's `|**kwargs, &blk|` declares a
|
|
101
|
+
# keyword-rest, which would capture a bare `key: val` hash that a method with a positional parameter
|
|
102
|
+
# expects to receive positionally, starving that parameter. All-kwargs methods have no such parameter,
|
|
103
|
+
# so the wrapper matches a direct call. (Most kwargs-shaped sigs take only kwargs.)
|
|
104
|
+
kwargs_path = ok_for_specialized_path && can_skip_block_type && !method_sig.kwarg_types.empty? &&
|
|
105
|
+
method_sig.arg_types.empty? &&
|
|
106
|
+
parameters.all? { |(kind, _name)| kind == :key || kind == :keyreq || kind == :block }
|
|
107
|
+
|
|
108
|
+
required_block_path = ok_for_specialized_path && !can_skip_block_type && has_fixed_arity
|
|
109
|
+
|
|
110
|
+
# At least one param is `:opt` here (otherwise `ok_for_fast_path` would hold). The wrapper forwards
|
|
111
|
+
# through a `ruby2_keywords`-flagged `|*args, &blk|` splat (see below), not named optional parameters:
|
|
112
|
+
# named params have no `*rest` for `def_with_visibility` to flag, so a trailing `key: val` that Ruby
|
|
113
|
+
# packs into an optional positional would lose the keyword flag the slow path preserves.
|
|
114
|
+
optional_args_path = ok_for_specialized_path && can_skip_block_type && method_sig.kwarg_types.empty? &&
|
|
115
|
+
parameters.all? { |(kind, _name)| kind == :req || kind == :opt || kind == :block }
|
|
116
|
+
|
|
86
117
|
all_args_are_simple = ok_for_fast_path && method_sig.arg_types.all? { |_name, type| type.is_a?(T::Types::Simple) }
|
|
87
118
|
|
|
88
119
|
effective_return_type = method_sig.effective_return_type
|
|
@@ -115,6 +146,12 @@ module T::Private::Methods::CallValidation
|
|
|
115
146
|
create_validator_method_skip_return_medium(mod, original_method, method_sig, original_visibility)
|
|
116
147
|
elsif ok_for_fast_path
|
|
117
148
|
create_validator_method_medium(mod, original_method, method_sig, original_visibility)
|
|
149
|
+
elsif kwargs_path
|
|
150
|
+
create_validator_method_kwargs(mod, original_method, method_sig, original_visibility)
|
|
151
|
+
elsif required_block_path
|
|
152
|
+
create_validator_method_with_block(mod, original_method, method_sig, original_visibility)
|
|
153
|
+
elsif optional_args_path
|
|
154
|
+
create_validator_method_optional_args(mod, original_method, method_sig, original_visibility)
|
|
118
155
|
elsif can_skip_block_type
|
|
119
156
|
# The Ruby VM already validates that any block passed to a method
|
|
120
157
|
# must be either `nil` or a `Proc` object, so there's no need to also
|