steep 1.1.1 → 1.2.0.pre.1
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/CHANGELOG.md +20 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +12 -11
- data/Gemfile.steep +1 -1
- data/Gemfile.steep.lock +9 -9
- data/README.md +3 -3
- data/Steepfile +23 -0
- data/bin/steep-prof +2 -1
- data/lib/steep/annotation_parser.rb +1 -1
- data/lib/steep/ast/types/class.rb +4 -0
- data/lib/steep/ast/types/factory.rb +86 -602
- data/lib/steep/ast/types/instance.rb +4 -0
- data/lib/steep/ast/types/literal.rb +1 -1
- data/lib/steep/ast/types/proc.rb +22 -8
- data/lib/steep/ast/types/self.rb +4 -0
- data/lib/steep/ast/types/union.rb +1 -1
- data/lib/steep/cli.rb +24 -1
- data/lib/steep/diagnostic/ruby.rb +17 -22
- data/lib/steep/drivers/checkfile.rb +205 -0
- data/lib/steep/drivers/validate.rb +3 -1
- data/lib/steep/equatable.rb +2 -0
- data/lib/steep/interface/block.rb +21 -11
- data/lib/steep/interface/builder.rb +756 -0
- data/lib/steep/interface/function.rb +32 -24
- data/lib/steep/interface/method_type.rb +191 -78
- data/lib/steep/interface/shape.rb +132 -0
- data/lib/steep/interface/substitution.rb +23 -12
- data/lib/steep/interface/type_param.rb +1 -2
- data/lib/steep/path_helper.rb +1 -1
- data/lib/steep/project.rb +5 -7
- data/lib/steep/server/base_worker.rb +2 -2
- data/lib/steep/server/change_buffer.rb +4 -3
- data/lib/steep/server/interaction_worker.rb +1 -1
- data/lib/steep/server/master.rb +69 -9
- data/lib/steep/server/type_check_worker.rb +13 -11
- data/lib/steep/server/worker_process.rb +9 -7
- data/lib/steep/services/completion_provider.rb +15 -3
- data/lib/steep/services/hover_provider/singleton_methods.rb +5 -6
- data/lib/steep/services/signature_service.rb +13 -8
- data/lib/steep/services/type_check_service.rb +2 -0
- data/lib/steep/signature/validator.rb +1 -1
- data/lib/steep/subtyping/check.rb +154 -103
- data/lib/steep/subtyping/relation.rb +3 -3
- data/lib/steep/subtyping/result.rb +20 -2
- data/lib/steep/subtyping/variable_variance.rb +9 -0
- data/lib/steep/type_construction.rb +558 -299
- data/lib/steep/type_inference/block_params.rb +169 -86
- data/lib/steep/type_inference/logic_type_interpreter.rb +9 -14
- data/lib/steep/type_inference/method_params.rb +12 -7
- data/lib/steep/type_inference/send_args.rb +41 -35
- data/lib/steep/type_inference/type_env_builder.rb +1 -1
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +71 -2
- data/rbs_collection.steep.lock.yaml +18 -30
- data/rbs_collection.steep.yaml +1 -0
- data/sig/shims/language-server_protocol.rbs +20 -0
- data/sig/shims/tagged_logging.rbs +6 -0
- data/sig/steep/ast/annotation/collection.rbs +6 -6
- data/sig/steep/ast/types/class.rbs +3 -0
- data/sig/steep/ast/types/factory.rbs +38 -32
- data/sig/steep/ast/types/instance.rbs +3 -0
- data/sig/steep/ast/types/intersection.rbs +1 -1
- data/sig/steep/ast/types/literal.rbs +7 -7
- data/sig/steep/ast/types/name.rbs +14 -13
- data/sig/steep/ast/types/proc.rbs +3 -1
- data/sig/steep/ast/types/self.rbs +3 -0
- data/sig/steep/ast/types/var.rbs +1 -1
- data/sig/steep/diagnostic/ruby.rbs +30 -34
- data/sig/steep/drivers/annotations.rbs +17 -0
- data/sig/steep/drivers/check.rbs +33 -0
- data/sig/steep/drivers/checkfile.rbs +26 -0
- data/sig/steep/drivers/diagnostic_printer.rbs +25 -0
- data/sig/steep/drivers/init.rbs +19 -0
- data/sig/steep/drivers/langserver.rbs +35 -0
- data/sig/steep/drivers/print_project.rbs +15 -0
- data/sig/steep/drivers/stats.rbs +37 -0
- data/sig/steep/drivers/utils/driver_helper.rbs +23 -0
- data/sig/steep/drivers/utils/jobs_count.rbs +11 -0
- data/sig/steep/drivers/validate.rbs +15 -0
- data/sig/steep/drivers/vendor.rbs +19 -0
- data/sig/steep/drivers/watch.rbs +27 -0
- data/sig/steep/drivers/worker.rbs +31 -0
- data/sig/steep/equatable.rbs +11 -0
- data/sig/steep/index/rbs_index.rbs +91 -0
- data/sig/steep/index/signature_symbol_provider.rbs +29 -0
- data/sig/steep/index/source_index.rbs +63 -0
- data/sig/steep/interface/block.rbs +3 -1
- data/sig/steep/interface/builder.rbs +152 -0
- data/sig/steep/interface/function.rbs +67 -55
- data/sig/steep/interface/method_type.rbs +60 -12
- data/sig/steep/interface/shape.rbs +61 -0
- data/sig/steep/interface/substitution.rbs +18 -22
- data/sig/steep/interface/type_param.rbs +9 -1
- data/sig/steep/path_helper.rbs +7 -0
- data/sig/steep/project/pattern.rbs +10 -10
- data/sig/steep/project/target.rbs +2 -2
- data/sig/steep/project.rbs +15 -8
- data/sig/steep/server/base_worker.rbs +49 -0
- data/sig/steep/server/change_buffer.rbs +32 -0
- data/sig/steep/server/interaction_worker.rbs +41 -0
- data/sig/steep/server/lsp_formatter.rbs +29 -0
- data/sig/steep/server/master.rbs +260 -0
- data/sig/steep/server/type_check_worker.rbs +135 -0
- data/sig/steep/server/worker_process.rbs +29 -0
- data/sig/steep/services/completion_provider.rbs +5 -5
- data/sig/steep/services/content_change.rbs +14 -12
- data/sig/steep/services/file_loader.rbs +12 -4
- data/sig/steep/services/hover_provider/singleton_methods.rbs +1 -1
- data/sig/steep/services/path_assignment.rbs +7 -7
- data/sig/steep/services/signature_service.rbs +67 -40
- data/sig/steep/services/type_check_service.rbs +53 -39
- data/sig/steep/subtyping/check.rbs +80 -44
- data/sig/steep/subtyping/relation.rbs +24 -22
- data/sig/steep/subtyping/result.rbs +48 -30
- data/sig/steep/subtyping/variable_variance.rbs +2 -0
- data/sig/steep/type_construction.rbs +132 -23
- data/sig/steep/type_inference/block_params.rbs +120 -18
- data/sig/steep/type_inference/context.rbs +45 -20
- data/sig/steep/type_inference/context_array.rbs +37 -0
- data/sig/steep/type_inference/logic_type_interpreter.rbs +3 -1
- data/sig/steep/type_inference/method_params.rbs +13 -9
- data/sig/steep/type_inference/send_args.rbs +229 -0
- data/sig/steep/type_inference/type_env_builder.rbs +1 -1
- data/sig/steep/typing.rbs +4 -4
- data/sig/steep.rbs +4 -2
- data/smoke/block/e.rb +12 -0
- data/smoke/block/e.rbs +4 -0
- data/smoke/block/test_expectations.yml +12 -0
- data/smoke/regression/block_param_split.rb +7 -0
- data/smoke/regression/block_param_split.rbs +3 -0
- data/smoke/regression/empty_yield.rb +5 -0
- data/smoke/regression/empty_yield.rbs +3 -0
- data/smoke/regression/test_expectations.yml +12 -0
- data/smoke/yield/test_expectations.yml +4 -4
- data/steep.gemspec +2 -1
- metadata +61 -9
- data/lib/steep/interface/interface.rb +0 -34
- data/sig/steep/interface/interface.rbs +0 -23
- data/sig/version.rbs +0 -3
@@ -0,0 +1,152 @@
|
|
1
|
+
module Steep
|
2
|
+
module Interface
|
3
|
+
class Builder
|
4
|
+
class Config
|
5
|
+
# Type of `self` type included immediately in the type expression
|
6
|
+
#
|
7
|
+
attr_reader self_type: AST::Types::t
|
8
|
+
|
9
|
+
# Type of `class` type included immediately in the type expression
|
10
|
+
#
|
11
|
+
attr_reader class_type: AST::Types::t | nil
|
12
|
+
|
13
|
+
# Type of `instance` type included immediately in the type expression
|
14
|
+
#
|
15
|
+
attr_reader instance_type: AST::Types::t | nil
|
16
|
+
|
17
|
+
# Resolves `self` types included in shape members
|
18
|
+
#
|
19
|
+
# * `false` only when the type expression is `self`
|
20
|
+
#
|
21
|
+
attr_reader resolve_self: bool
|
22
|
+
|
23
|
+
# Resolves `class` types included in shape members
|
24
|
+
#
|
25
|
+
# * `false` only when the type expression is `class`
|
26
|
+
#
|
27
|
+
attr_reader resolve_class: bool
|
28
|
+
|
29
|
+
# Resolves `instance` types included in shape members
|
30
|
+
#
|
31
|
+
# * `false` only when the type expression is `instance`
|
32
|
+
#
|
33
|
+
attr_reader resolve_instance: bool
|
34
|
+
|
35
|
+
attr_reader variable_bounds: Hash[Symbol, AST::Types::t?]
|
36
|
+
|
37
|
+
def initialize: (
|
38
|
+
self_type: AST::Types::t,
|
39
|
+
class_type: AST::Types::t | nil,
|
40
|
+
instance_type: AST::Types::t | nil,
|
41
|
+
?resolve_self: bool,
|
42
|
+
?resolve_class: bool,
|
43
|
+
?resolve_instance: bool,
|
44
|
+
variable_bounds: Hash[Symbol, AST::Types::t?]
|
45
|
+
) -> void
|
46
|
+
|
47
|
+
def update: (
|
48
|
+
?self_type: AST::Types::t,
|
49
|
+
?class_type: AST::Types::t | nil,
|
50
|
+
?instance_type: AST::Types::t | nil,
|
51
|
+
?resolve_self: bool,
|
52
|
+
?resolve_class: bool,
|
53
|
+
?resolve_instance: bool,
|
54
|
+
?variable_bounds: Hash[Symbol, AST::Types::t?]
|
55
|
+
) -> self
|
56
|
+
|
57
|
+
@no_resolve: self?
|
58
|
+
def no_resolve: () -> self
|
59
|
+
|
60
|
+
def resolve?: () -> bool
|
61
|
+
|
62
|
+
def ==: (untyped) -> bool
|
63
|
+
|
64
|
+
alias eql? ==
|
65
|
+
|
66
|
+
def hash: () -> Integer
|
67
|
+
|
68
|
+
@subst: Substitution
|
69
|
+
|
70
|
+
# Substitution for immediate type expressions
|
71
|
+
def subst: () -> Substitution
|
72
|
+
end
|
73
|
+
|
74
|
+
attr_reader factory: AST::Types::Factory
|
75
|
+
|
76
|
+
type cache_key = [
|
77
|
+
AST::Types::t, # type
|
78
|
+
bool, # public_only
|
79
|
+
AST::Types::t | nil, # self_type
|
80
|
+
AST::Types::t | nil, # class_type
|
81
|
+
AST::Types::t | nil, # instance_type
|
82
|
+
bool, bool, bool, # resolve_self, resolve_class, resolve_instance
|
83
|
+
Hash[Symbol, AST::Types::t?]? # variable_bounds
|
84
|
+
]
|
85
|
+
attr_reader cache: Hash[cache_key, Shape?]
|
86
|
+
|
87
|
+
# No type application (if generic), no self-instance-module resolution
|
88
|
+
attr_reader raw_instance_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
|
89
|
+
|
90
|
+
attr_reader raw_singleton_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
|
91
|
+
|
92
|
+
attr_reader raw_interface_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
|
93
|
+
|
94
|
+
def initialize: (AST::Types::Factory) -> void
|
95
|
+
|
96
|
+
# Calculates the shape of given class, based on `public_only` and Config
|
97
|
+
#
|
98
|
+
# Returns `nil` if a type that cannot calculate Shape is given.
|
99
|
+
#
|
100
|
+
# * `public_only`: If false, returns a shape with private methods.
|
101
|
+
#
|
102
|
+
def shape: (AST::Types::t, public_only: bool, config: Config) -> Shape?
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
@subtyping: Subtyping::Check?
|
107
|
+
|
108
|
+
def subtyping: () -> Subtyping::Check
|
109
|
+
|
110
|
+
# Fetch and update cache
|
111
|
+
#
|
112
|
+
# Cache if given type is cacheable:
|
113
|
+
#
|
114
|
+
# * `self`, `instance`, `class` is not cacheable
|
115
|
+
# * Type variables are not cacheable
|
116
|
+
#
|
117
|
+
def fetch_cache: (AST::Types::t, bool public_only, Config) { () -> Shape? } -> Shape?
|
118
|
+
|
119
|
+
def include_self?: (AST::Types::t) -> bool
|
120
|
+
|
121
|
+
def definition_builder: () -> RBS::DefinitionBuilder
|
122
|
+
|
123
|
+
def object_shape: (
|
124
|
+
AST::Types::Name::Instance | AST::Types::Name::Singleton | AST::Types::Name::Interface,
|
125
|
+
bool public_only,
|
126
|
+
boolish keep_self,
|
127
|
+
boolish keep_instance,
|
128
|
+
boolish keep_singleton
|
129
|
+
) -> Shape
|
130
|
+
|
131
|
+
def raw_object_shape: (
|
132
|
+
AST::Types::Name::Instance | AST::Types::Name::Singleton | AST::Types::Name::Interface,
|
133
|
+
bool public_only,
|
134
|
+
Substitution subst
|
135
|
+
) -> Shape
|
136
|
+
|
137
|
+
def union_shape: (AST::Types::t, Array[Shape], bool public_only) -> Shape
|
138
|
+
|
139
|
+
def intersection_shape: (AST::Types::t, Array[Shape], bool public_only) -> Shape
|
140
|
+
|
141
|
+
def tuple_shape: (AST::Types::Tuple, bool public_only, Config) -> Shape
|
142
|
+
|
143
|
+
def record_shape: (AST::Types::Record, bool public_only, Config) -> Shape?
|
144
|
+
|
145
|
+
def proc_shape: (AST::Types::Proc, bool public_only, Config) -> Shape?
|
146
|
+
|
147
|
+
def replace_primitive_method: (method_name, RBS::Definition::Method::TypeDef, MethodType) -> MethodType
|
148
|
+
|
149
|
+
def method_name_for: (RBS::Definition::Method::TypeDef, Symbol name) -> method_name
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -8,23 +8,25 @@ module Steep
|
|
8
8
|
def intersection: (*AST::Types::t types) -> AST::Types::t
|
9
9
|
end
|
10
10
|
|
11
|
+
type t = PositionalParams::param | KeywordParams
|
12
|
+
|
11
13
|
class PositionalParams
|
12
14
|
class Base
|
13
|
-
attr_reader type:
|
15
|
+
attr_reader type: AST::Types::t
|
14
16
|
|
15
|
-
def initialize: (
|
17
|
+
def initialize: (AST::Types::t `type`) -> void
|
16
18
|
|
17
|
-
def ==: (untyped other) ->
|
19
|
+
def ==: (untyped other) -> bool
|
18
20
|
|
19
21
|
alias eql? ==
|
20
22
|
|
21
|
-
def hash: () ->
|
23
|
+
def hash: () -> Integer
|
22
24
|
|
23
|
-
def subst: (
|
25
|
+
def subst: (Substitution s) -> self
|
24
26
|
|
25
|
-
def var_type: () ->
|
27
|
+
def var_type: () -> AST::Types::t
|
26
28
|
|
27
|
-
def map_type: () { (
|
29
|
+
def map_type: () { (AST::Types::t) -> AST::Types::t } -> self
|
28
30
|
end
|
29
31
|
|
30
32
|
class Required < Base
|
@@ -36,61 +38,65 @@ module Steep
|
|
36
38
|
class Rest < Base
|
37
39
|
end
|
38
40
|
|
39
|
-
|
41
|
+
type param = Required | Optional | Rest
|
40
42
|
|
41
|
-
attr_reader
|
43
|
+
attr_reader head: param
|
42
44
|
|
43
|
-
|
45
|
+
attr_reader tail: PositionalParams?
|
44
46
|
|
45
|
-
def
|
47
|
+
def initialize: (head: param, tail: PositionalParams?) -> void
|
46
48
|
|
47
|
-
def self.
|
49
|
+
def self.required: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
|
48
50
|
|
49
|
-
def self.
|
51
|
+
def self.optional: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
|
50
52
|
|
51
|
-
def
|
53
|
+
def self.rest: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
|
52
54
|
|
53
|
-
def
|
55
|
+
def to_ary: () -> [param, PositionalParams?]
|
54
56
|
|
55
|
-
def
|
57
|
+
def map: () { (param) -> param } -> PositionalParams
|
56
58
|
|
57
|
-
def
|
59
|
+
def map_type: () { (AST::Types::t) -> AST::Types::t } -> PositionalParams
|
58
60
|
|
59
|
-
def
|
61
|
+
def subst: (Substitution s) -> PositionalParams
|
62
|
+
|
63
|
+
def ==: (untyped other) -> bool
|
60
64
|
|
61
65
|
alias eql? ==
|
62
66
|
|
63
|
-
def hash: () ->
|
67
|
+
def hash: () -> Integer
|
64
68
|
|
65
|
-
def each: () { (
|
69
|
+
def each: () { (param) -> void } -> void
|
70
|
+
| () -> Enumerator[param, void]
|
66
71
|
|
67
|
-
def each_type: () { (
|
72
|
+
def each_type: () { (AST::Types::t) -> void } -> void
|
73
|
+
| () -> Enumerator[AST::Types::t, void]
|
68
74
|
|
69
|
-
def size: () ->
|
75
|
+
def size: () -> Integer
|
70
76
|
|
71
|
-
def self.build: (required:
|
77
|
+
def self.build: (required: Array[AST::Types::t], optional: Array[AST::Types::t], rest: AST::Types::t?) -> PositionalParams
|
72
78
|
|
73
79
|
extend Utils
|
74
80
|
|
75
81
|
# Calculates xs + ys.
|
76
82
|
# Never fails.
|
77
|
-
def self.merge_for_overload: (
|
83
|
+
def self.merge_for_overload: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams
|
78
84
|
|
79
85
|
# xs | ys
|
80
|
-
def self.merge_for_union: (
|
86
|
+
def self.merge_for_union: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams?
|
81
87
|
|
82
88
|
# Calculates xs & ys.
|
83
89
|
# Raises when failed.
|
84
90
|
#
|
85
|
-
def self.merge_for_intersection: (
|
91
|
+
def self.merge_for_intersection: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams?
|
86
92
|
end
|
87
93
|
|
88
94
|
class KeywordParams
|
89
|
-
attr_reader requireds:
|
95
|
+
attr_reader requireds: Hash[Symbol, AST::Types::t]
|
90
96
|
|
91
|
-
attr_reader optionals:
|
97
|
+
attr_reader optionals: Hash[Symbol, AST::Types::t]
|
92
98
|
|
93
|
-
attr_reader rest:
|
99
|
+
attr_reader rest: AST::Types::t?
|
94
100
|
|
95
101
|
def initialize: (?requireds: ::Hash[untyped, untyped], ?optionals: ::Hash[untyped, untyped], ?rest: untyped?) -> void
|
96
102
|
|
@@ -102,19 +108,21 @@ module Steep
|
|
102
108
|
|
103
109
|
def update: (?requireds: untyped, ?optionals: untyped, ?rest: untyped) -> untyped
|
104
110
|
|
105
|
-
def empty?: () ->
|
111
|
+
def empty?: () -> bool
|
106
112
|
|
107
|
-
def each: () { (
|
113
|
+
def each: () { ([Symbol?, AST::Types::t]) -> void } -> void
|
114
|
+
| () -> Enumerator[[Symbol?, AST::Types::t], void]
|
108
115
|
|
109
|
-
def each_type: () { (
|
116
|
+
def each_type: () { (AST::Types::t) -> void } -> void
|
117
|
+
| () -> Enumerator[AST::Types::t, void]
|
110
118
|
|
111
|
-
def map_type: () { () ->
|
119
|
+
def map_type: () { (AST::Types::t) -> AST::Types::t } -> KeywordParams
|
112
120
|
|
113
|
-
def subst: (
|
121
|
+
def subst: (Substitution s) -> KeywordParams
|
114
122
|
|
115
|
-
def size: () ->
|
123
|
+
def size: () -> Integer
|
116
124
|
|
117
|
-
def keywords: () ->
|
125
|
+
def keywords: () -> Set[Symbol]
|
118
126
|
|
119
127
|
include Utils
|
120
128
|
|
@@ -134,7 +142,7 @@ module Steep
|
|
134
142
|
|
135
143
|
def rest: () -> AST::Types::t?
|
136
144
|
|
137
|
-
attr_reader positional_params: PositionalParams
|
145
|
+
attr_reader positional_params: PositionalParams?
|
138
146
|
|
139
147
|
attr_reader keyword_params: KeywordParams
|
140
148
|
|
@@ -170,34 +178,35 @@ module Steep
|
|
170
178
|
|
171
179
|
def has_keywords?: () -> untyped
|
172
180
|
|
173
|
-
def each_positional_param: () { () ->
|
181
|
+
def each_positional_param: () { (PositionalParams::Base) -> void } -> void
|
174
182
|
|
175
183
|
def without_keywords: () -> untyped
|
176
184
|
|
177
185
|
def drop_first: () -> untyped
|
178
186
|
|
179
|
-
def each_type: () { () ->
|
187
|
+
def each_type: () { (AST::Types::t) -> void } -> void
|
188
|
+
| () -> Enumerator[AST::Types::t, void]
|
180
189
|
|
181
190
|
def free_variables: () -> untyped
|
182
191
|
|
183
192
|
def closed?: () -> untyped
|
184
193
|
|
185
|
-
def subst: (
|
194
|
+
def subst: (Substitution s) -> Params
|
186
195
|
|
187
196
|
def size: () -> untyped
|
188
197
|
|
189
198
|
def to_s: () -> ::String
|
190
199
|
|
191
|
-
def map_type: () { () ->
|
200
|
+
def map_type: () { (AST::Types::t) -> AST::Types::t } -> Params
|
192
201
|
|
193
|
-
def empty?: () ->
|
202
|
+
def empty?: () -> bool
|
194
203
|
|
195
204
|
# Returns true if all arguments are non-required.
|
196
|
-
def optional?: () ->
|
205
|
+
def optional?: () -> bool
|
197
206
|
|
198
207
|
# self + params returns a new params for overloading.
|
199
208
|
#
|
200
|
-
def +: (
|
209
|
+
def +: (Params other) -> Params
|
201
210
|
|
202
211
|
# Returns the intersection between self and other.
|
203
212
|
# Returns nil if the intersection cannot be computed.
|
@@ -207,7 +216,7 @@ module Steep
|
|
207
216
|
#
|
208
217
|
# `self & other` accept `arg` if `arg` is acceptable for both of `self` and `other`.
|
209
218
|
#
|
210
|
-
def &: (
|
219
|
+
def &: (Params other) -> Params?
|
211
220
|
|
212
221
|
# Returns the union between self and other.
|
213
222
|
#
|
@@ -216,34 +225,37 @@ module Steep
|
|
216
225
|
#
|
217
226
|
# `self | other` accept `arg` if `self` accepts `arg` or `other` accepts `arg`.
|
218
227
|
#
|
219
|
-
def |: (
|
228
|
+
def |: (Params other) -> Params?
|
220
229
|
end
|
221
230
|
|
222
|
-
|
231
|
+
type location = RBS::Location[untyped, untyped]
|
232
|
+
|
233
|
+
attr_reader params: Params
|
223
234
|
|
224
235
|
attr_reader return_type: AST::Types::t
|
225
236
|
|
226
|
-
attr_reader location:
|
237
|
+
attr_reader location: location?
|
227
238
|
|
228
|
-
def initialize: (params:
|
239
|
+
def initialize: (params: Params, return_type: AST::Types::t, location: location?) -> void
|
229
240
|
|
230
|
-
def ==: (untyped other) ->
|
241
|
+
def ==: (untyped other) -> bool
|
231
242
|
|
232
243
|
alias eql? ==
|
233
244
|
|
234
|
-
def hash: () ->
|
245
|
+
def hash: () -> Integer
|
235
246
|
|
236
247
|
def free_variables: () -> Set[Symbol]
|
237
248
|
|
238
249
|
def subst: (Substitution s) -> Function
|
239
250
|
|
240
|
-
|
251
|
+
alias each_child each_type
|
241
252
|
|
242
|
-
def each_type: () { (
|
253
|
+
def each_type: () { (AST::Types::t) -> void } -> void
|
254
|
+
| () -> Enumerator[AST::Types::t, void]
|
243
255
|
|
244
|
-
def map_type: () { (
|
256
|
+
def map_type: () { (AST::Types::t) -> AST::Types::t } -> Function
|
245
257
|
|
246
|
-
def with: (?params:
|
258
|
+
def with: (?params: Params, ?return_type: AST::Types::t) -> Function
|
247
259
|
|
248
260
|
def to_s: () -> ::String
|
249
261
|
|
@@ -5,13 +5,15 @@ module Steep
|
|
5
5
|
|
6
6
|
attr_reader type: Function
|
7
7
|
|
8
|
-
attr_reader block: Block
|
8
|
+
attr_reader block: Block?
|
9
9
|
|
10
|
-
attr_reader method_decls:
|
10
|
+
attr_reader method_decls: Set[TypeInference::MethodCall::MethodDecl]
|
11
11
|
|
12
|
-
|
12
|
+
@fvs: Set[Symbol]
|
13
13
|
|
14
|
-
def
|
14
|
+
def initialize: (type_params: Array[TypeParam], type: Function, block: Block?, method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> void
|
15
|
+
|
16
|
+
def ==: (untyped other) -> bool
|
15
17
|
|
16
18
|
alias eql? ==
|
17
19
|
|
@@ -21,11 +23,12 @@ module Steep
|
|
21
23
|
|
22
24
|
def subst: (Substitution s) -> MethodType
|
23
25
|
|
24
|
-
def each_type: () { (
|
26
|
+
def each_type: () { (AST::Types::t) -> void } -> void
|
27
|
+
| () -> Enumerator[AST::Types::t, void]
|
25
28
|
|
26
29
|
def instantiate: (Substitution s) -> MethodType
|
27
30
|
|
28
|
-
def with: (?type_params:
|
31
|
+
def with: (?type_params: Array[TypeParam], ?type: Function, ?block: Block?, ?method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> MethodType
|
29
32
|
|
30
33
|
def to_s: () -> ::String
|
31
34
|
|
@@ -33,23 +36,68 @@ module Steep
|
|
33
36
|
|
34
37
|
# Returns a new method type which can be used for the method implementation type of both `self` and `other`.
|
35
38
|
#
|
36
|
-
def unify_overload: (
|
39
|
+
def unify_overload: (MethodType other) -> MethodType
|
40
|
+
|
41
|
+
alias + unify_overload
|
42
|
+
|
43
|
+
def equals_modulo_type_params?: (MethodType other) -> bool
|
44
|
+
|
45
|
+
# Returns a method type which is a super-type of both `type1` and `type2`.
|
46
|
+
# `type1` <: union(`type1`, `type2`) && `type2` <: union(`type1`, `type2`)
|
47
|
+
#
|
48
|
+
# Returns `nil` if `type1` and `type2` are incompatible.
|
49
|
+
#
|
50
|
+
# This tries to generate the best result for polymorphic methods, but the support is limited.
|
51
|
+
# It works when:
|
52
|
+
#
|
53
|
+
# * `type1` and `type2` are equal modulo type parameters (`[A] () -> A` | `[B] () -> B` → `[A] () -> A`), or
|
54
|
+
# * The type parameter occurences are identical (`[A] (::Integer) -> A` | `[B] (::String) -> B` → `[A] (::Integer & ::String) -> A`)
|
55
|
+
#
|
56
|
+
# Otherwise it fails (returns `nil`).
|
57
|
+
#
|
58
|
+
def self.union: (MethodType type1, MethodType type2, Subtyping::Check) -> MethodType?
|
59
|
+
|
60
|
+
# Returns a method type which is a sub-type of both `type1` and `type2`.
|
61
|
+
#
|
62
|
+
# ```
|
63
|
+
# intersection(type1, type2) <: type1 && intersection(type1, type2) <: type2
|
64
|
+
# ```
|
65
|
+
#
|
66
|
+
# Returns `nil` if `type1` and `type2` are incompatible.
|
67
|
+
#
|
68
|
+
# This tries to generate the best result for polymorphic methods, but the support is limited.
|
69
|
+
# It works when:
|
70
|
+
#
|
71
|
+
# * `type1` and `type2` are equal modulo type parameters (`[A] () -> A` & `[B] () -> B` → `[A] () -> A`), or
|
72
|
+
# * The type parameter occurences are identical (`[A] (::Integer) -> A` & `[B] (::String) -> B` → `[A] (::Integer | ::String) -> A`)
|
73
|
+
#
|
74
|
+
# Otherwise it fails (returns `nil`).
|
75
|
+
#
|
76
|
+
def self.intersection: (MethodType type1, MethodType type2, Subtyping::Check) -> MethodType?
|
37
77
|
|
38
|
-
def
|
78
|
+
def self.try_type_params: (
|
79
|
+
MethodType type1,
|
80
|
+
MethodType type2,
|
81
|
+
Subtyping::Check,
|
82
|
+
^(MethodType, MethodType) -> MethodType?,
|
83
|
+
^(MethodType original, MethodType generated) -> Subtyping::Relation[MethodType]
|
84
|
+
) -> MethodType?
|
39
85
|
|
40
86
|
# Returns a method type which is a super-type of both self and other.
|
41
87
|
# self <: (self | other) && other <: (self | other)
|
42
88
|
#
|
43
|
-
# Returns nil if self and other are incompatible.
|
89
|
+
# * Returns `nil` if self and other are incompatible.
|
90
|
+
# * Ignores all type parameters.
|
44
91
|
#
|
45
|
-
def |: (
|
92
|
+
def |: (MethodType other) -> MethodType?
|
46
93
|
|
47
94
|
# Returns a method type which is a sub-type of both self and other.
|
48
95
|
# (self & other) <: self && (self & other) <: other
|
49
96
|
#
|
50
|
-
# Returns nil if self and other are incompatible.
|
97
|
+
# * Returns `nil` if self and other are incompatible.
|
98
|
+
# * Ignores all type parameters.
|
51
99
|
#
|
52
|
-
def &: (
|
100
|
+
def &: (MethodType other) -> MethodType?
|
53
101
|
end
|
54
102
|
end
|
55
103
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Steep
|
2
|
+
module Interface
|
3
|
+
class Shape
|
4
|
+
class Entry
|
5
|
+
attr_reader method_types: Array[MethodType]
|
6
|
+
|
7
|
+
def initialize: (method_types: Array[MethodType]) -> void
|
8
|
+
|
9
|
+
def to_s: () -> String
|
10
|
+
end
|
11
|
+
|
12
|
+
class Methods
|
13
|
+
def []=: (Symbol, Entry) -> Entry
|
14
|
+
|
15
|
+
def []: (Symbol) -> Entry?
|
16
|
+
|
17
|
+
def key?: (Symbol) -> bool
|
18
|
+
|
19
|
+
def each: () { ([Symbol, Entry]) -> void } -> void
|
20
|
+
| () -> Enumerator[[Symbol, Entry], void]
|
21
|
+
|
22
|
+
def each_name: () { (Symbol) -> void } -> void
|
23
|
+
| () -> Enumerator[Symbol, void]
|
24
|
+
|
25
|
+
include Enumerable[[Symbol, Entry]]
|
26
|
+
|
27
|
+
attr_reader substs: Array[Substitution]
|
28
|
+
|
29
|
+
attr_reader methods: Hash[Symbol, Entry]
|
30
|
+
attr_reader resolved_methods: Hash[Symbol, Entry?]
|
31
|
+
|
32
|
+
def initialize: (substs: Array[Substitution], methods: Hash[Symbol, Entry]) -> void
|
33
|
+
|
34
|
+
@subst: Substitution?
|
35
|
+
def subst: () -> Substitution
|
36
|
+
|
37
|
+
def push_substitution: (Substitution) -> Methods
|
38
|
+
|
39
|
+
def merge!: (Methods other) -> void
|
40
|
+
|
41
|
+
# def +: (Methods other) -> Methods
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader type: AST::Types::t
|
45
|
+
|
46
|
+
attr_reader methods: Methods
|
47
|
+
|
48
|
+
@private: bool
|
49
|
+
|
50
|
+
def initialize: (type: AST::Types::t, private: bool, ?methods: Methods?) -> void
|
51
|
+
|
52
|
+
def update: (?type: AST::Types::t, ?methods: Methods) -> self
|
53
|
+
|
54
|
+
def private?: () -> bool
|
55
|
+
|
56
|
+
def public?: () -> bool
|
57
|
+
|
58
|
+
def subst: (Substitution, ?type: AST::Types::t?) -> Shape
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -9,45 +9,41 @@ module Steep
|
|
9
9
|
def initialize: (vars_size: untyped, types_size: untyped) -> void
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_reader dictionary:
|
12
|
+
attr_reader dictionary: Hash[Symbol, AST::Types::t]
|
13
13
|
|
14
|
-
attr_reader instance_type:
|
14
|
+
attr_reader instance_type: AST::Types::t
|
15
15
|
|
16
|
-
attr_reader module_type:
|
16
|
+
attr_reader module_type: AST::Types::t
|
17
17
|
|
18
|
-
attr_reader self_type:
|
18
|
+
attr_reader self_type: AST::Types::t
|
19
19
|
|
20
|
-
def initialize: (dictionary:
|
20
|
+
def initialize: (dictionary: Hash[Symbol, AST::Types::t], instance_type: AST::Types::t, module_type: AST::Types::t, self_type: AST::Types::t) -> void
|
21
21
|
|
22
|
-
def self.empty: () ->
|
22
|
+
def self.empty: () -> instance
|
23
23
|
|
24
|
-
def empty?: () ->
|
24
|
+
def empty?: () -> bool
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
CLASS_TYPE: untyped
|
29
|
-
|
30
|
-
SELF_TYPE: untyped
|
31
|
-
|
32
|
-
def domain: () -> untyped
|
26
|
+
def domain: () -> Set[AST::Types::t | Symbol]
|
33
27
|
|
34
28
|
def to_s: () -> ::String
|
35
29
|
|
36
|
-
def []: (
|
30
|
+
def []: (Symbol key) -> AST::Types::t
|
31
|
+
|
32
|
+
def key?: (Symbol var) -> bool
|
37
33
|
|
38
|
-
def
|
34
|
+
def self.build: (Array[Symbol] vars, ?Array[AST::Types::t]? types, ?instance_type: AST::Types::t, ?module_type: AST::Types::t, ?self_type: AST::Types::t) -> Substitution
|
39
35
|
|
40
|
-
def
|
36
|
+
def except: (Array[Symbol] vars) -> Substitution
|
41
37
|
|
42
|
-
def except
|
38
|
+
def except!: (Array[Symbol] vars) -> self
|
43
39
|
|
44
|
-
def
|
40
|
+
def merge!: (Substitution s, ?overwrite: bool) -> self
|
45
41
|
|
46
|
-
def merge
|
42
|
+
def merge: (Substitution s) -> Substitution
|
47
43
|
|
48
|
-
def
|
44
|
+
def apply?: (AST::Types::t) -> bool
|
49
45
|
|
50
|
-
def add!: (
|
46
|
+
def add!: (Symbol v, AST::Types::t ty) -> self
|
51
47
|
end
|
52
48
|
end
|
53
49
|
end
|
@@ -23,7 +23,15 @@ module Steep
|
|
23
23
|
|
24
24
|
def hash: () -> Integer
|
25
25
|
|
26
|
-
|
26
|
+
# Rename the type parameters to fresh names
|
27
|
+
#
|
28
|
+
# Returns a pair of renamed type parameters and substitution.
|
29
|
+
#
|
30
|
+
# ```rb
|
31
|
+
# TypeParam.rename([`X`, `Y`], [:X, :Y]) # [[`X(0)`, `Y(1)`], `{ X => X(0), Y => Y(1) }`]
|
32
|
+
# ```
|
33
|
+
#
|
34
|
+
def self.rename: (Array[TypeParam] params, ?Array[Symbol] conflicting_names, ?Array[Symbol] new_names) -> [Array[TypeParam], Substitution]
|
27
35
|
|
28
36
|
def to_s: () -> String
|
29
37
|
|