steep 1.8.0.dev.2 → 1.8.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 +33 -0
- data/bin/mem_graph.rb +67 -0
- data/bin/mem_prof.rb +102 -0
- data/bin/stackprof_test.rb +19 -0
- data/bin/steep-check.rb +251 -0
- data/lib/steep/annotation_parser.rb +1 -1
- data/lib/steep/ast/builtin.rb +5 -5
- data/lib/steep/ast/node/type_application.rb +7 -6
- data/lib/steep/ast/types/any.rb +1 -9
- data/lib/steep/ast/types/boolean.rb +8 -16
- data/lib/steep/ast/types/bot.rb +2 -10
- data/lib/steep/ast/types/class.rb +1 -13
- data/lib/steep/ast/types/factory.rb +101 -85
- data/lib/steep/ast/types/instance.rb +1 -13
- data/lib/steep/ast/types/intersection.rb +8 -15
- data/lib/steep/ast/types/literal.rb +2 -8
- data/lib/steep/ast/types/logic.rb +3 -24
- data/lib/steep/ast/types/name.rb +5 -16
- data/lib/steep/ast/types/nil.rb +3 -12
- data/lib/steep/ast/types/proc.rb +4 -13
- data/lib/steep/ast/types/record.rb +21 -12
- data/lib/steep/ast/types/self.rb +1 -13
- data/lib/steep/ast/types/shared_instance.rb +11 -0
- data/lib/steep/ast/types/top.rb +1 -9
- data/lib/steep/ast/types/tuple.rb +4 -10
- data/lib/steep/ast/types/union.rb +10 -15
- data/lib/steep/ast/types/var.rb +4 -13
- data/lib/steep/ast/types/void.rb +2 -10
- data/lib/steep/diagnostic/ruby.rb +4 -4
- data/lib/steep/drivers/check.rb +11 -14
- data/lib/steep/drivers/checkfile.rb +8 -10
- data/lib/steep/drivers/stats.rb +17 -13
- data/lib/steep/drivers/utils/driver_helper.rb +24 -3
- data/lib/steep/drivers/watch.rb +3 -3
- data/lib/steep/interface/builder.rb +162 -138
- data/lib/steep/interface/method_type.rb +12 -20
- data/lib/steep/interface/shape.rb +66 -10
- data/lib/steep/interface/substitution.rb +2 -0
- data/lib/steep/interface/type_param.rb +20 -7
- data/lib/steep/located_value.rb +20 -0
- data/lib/steep/server/change_buffer.rb +5 -7
- data/lib/steep/server/custom_methods.rb +61 -0
- data/lib/steep/server/delay_queue.rb +8 -1
- data/lib/steep/server/interaction_worker.rb +10 -5
- data/lib/steep/server/lsp_formatter.rb +8 -6
- data/lib/steep/server/master.rb +193 -140
- data/lib/steep/server/type_check_worker.rb +18 -19
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/services/completion_provider.rb +24 -22
- data/lib/steep/services/goto_service.rb +3 -2
- data/lib/steep/services/hover_provider/ruby.rb +7 -6
- data/lib/steep/services/signature_help_provider.rb +7 -6
- data/lib/steep/services/signature_service.rb +1 -1
- data/lib/steep/services/type_check_service.rb +3 -3
- data/lib/steep/signature/validator.rb +17 -20
- data/lib/steep/subtyping/check.rb +105 -55
- data/lib/steep/subtyping/constraints.rb +11 -15
- data/lib/steep/type_construction.rb +100 -100
- data/lib/steep/type_inference/block_params.rb +6 -6
- data/lib/steep/type_inference/logic_type_interpreter.rb +11 -7
- data/lib/steep/type_inference/method_call.rb +3 -3
- data/lib/steep/type_inference/method_params.rb +1 -1
- data/lib/steep/type_inference/send_args.rb +1 -1
- data/lib/steep/typing.rb +158 -102
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +28 -3
- data/steep.gemspec +2 -2
- metadata +16 -9
- data/lib/steep/type_inference/context_array.rb +0 -112
@@ -36,77 +36,103 @@ module Steep
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def normalize_args(type_name, args)
|
40
|
+
case
|
41
|
+
when type_name.class?
|
42
|
+
if entry = env.normalized_module_class_entry(type_name)
|
43
|
+
type_params = entry.type_params
|
44
|
+
end
|
45
|
+
when type_name.interface?
|
46
|
+
if entry = env.interface_decls.fetch(type_name, nil)
|
47
|
+
type_params = entry.decl.type_params
|
48
|
+
end
|
49
|
+
when type_name.alias?
|
50
|
+
if entry = env.type_alias_decls.fetch(type_name, nil)
|
51
|
+
type_params = entry.decl.type_params
|
43
52
|
end
|
44
53
|
end
|
45
54
|
|
55
|
+
if type_params && !type_params.empty?
|
56
|
+
RBS::AST::TypeParam.normalize_args(type_params, args)
|
57
|
+
else
|
58
|
+
args
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def type(type)
|
63
|
+
if ty = type_cache[type]
|
64
|
+
return ty
|
65
|
+
end
|
66
|
+
|
46
67
|
type_cache[type] =
|
47
68
|
case type
|
48
69
|
when RBS::Types::Bases::Any
|
49
|
-
Any.
|
70
|
+
Any.instance
|
50
71
|
when RBS::Types::Bases::Class
|
51
|
-
Class.
|
72
|
+
Class.instance
|
52
73
|
when RBS::Types::Bases::Instance
|
53
|
-
Instance.
|
74
|
+
Instance.instance
|
54
75
|
when RBS::Types::Bases::Self
|
55
|
-
Self.
|
76
|
+
Self.instance
|
56
77
|
when RBS::Types::Bases::Top
|
57
|
-
Top.
|
78
|
+
Top.instance
|
58
79
|
when RBS::Types::Bases::Bottom
|
59
|
-
Bot.
|
80
|
+
Bot.instance
|
60
81
|
when RBS::Types::Bases::Bool
|
61
|
-
Boolean.
|
82
|
+
Boolean.instance
|
62
83
|
when RBS::Types::Bases::Void
|
63
|
-
Void.
|
84
|
+
Void.instance
|
64
85
|
when RBS::Types::Bases::Nil
|
65
|
-
Nil.
|
86
|
+
Nil.instance
|
66
87
|
when RBS::Types::Variable
|
67
|
-
Var.new(name: type.name
|
88
|
+
Var.new(name: type.name)
|
68
89
|
when RBS::Types::ClassSingleton
|
69
90
|
type_name = type.name
|
70
|
-
Name::Singleton.new(name: type_name
|
91
|
+
Name::Singleton.new(name: type_name)
|
71
92
|
when RBS::Types::ClassInstance
|
72
93
|
type_name = type.name
|
73
|
-
args = type.args.map {|arg| type(arg) }
|
74
|
-
Name::Instance.new(name: type_name, args: args
|
94
|
+
args = normalize_args(type_name, type.args).map {|arg| type(arg) }
|
95
|
+
Name::Instance.new(name: type_name, args: args)
|
75
96
|
when RBS::Types::Interface
|
76
97
|
type_name = type.name
|
77
|
-
args = type.args.map {|arg| type(arg) }
|
78
|
-
Name::Interface.new(name: type_name, args: args
|
98
|
+
args = normalize_args(type_name, type.args).map {|arg| type(arg) }
|
99
|
+
Name::Interface.new(name: type_name, args: args)
|
79
100
|
when RBS::Types::Alias
|
80
101
|
type_name = type.name
|
81
|
-
args = type.args.map {|arg| type(arg) }
|
82
|
-
Name::Alias.new(name: type_name, args: args
|
102
|
+
args = normalize_args(type_name, type.args).map {|arg| type(arg) }
|
103
|
+
Name::Alias.new(name: type_name, args: args)
|
83
104
|
when RBS::Types::Union
|
84
|
-
Union.build(types: type.types.map {|ty| type(ty) }
|
105
|
+
Union.build(types: type.types.map {|ty| type(ty) })
|
85
106
|
when RBS::Types::Intersection
|
86
|
-
Intersection.build(types: type.types.map {|ty| type(ty) }
|
107
|
+
Intersection.build(types: type.types.map {|ty| type(ty) })
|
87
108
|
when RBS::Types::Optional
|
88
|
-
Union.build(types: [type(type.type), Nil.
|
109
|
+
Union.build(types: [type(type.type), Nil.instance()])
|
89
110
|
when RBS::Types::Literal
|
90
|
-
Literal.new(value: type.literal
|
111
|
+
Literal.new(value: type.literal)
|
91
112
|
when RBS::Types::Tuple
|
92
|
-
Tuple.new(types: type.types.map {|ty| type(ty) }
|
113
|
+
Tuple.new(types: type.types.map {|ty| type(ty) })
|
93
114
|
when RBS::Types::Record
|
94
|
-
elements =
|
95
|
-
|
115
|
+
elements = {} #: Hash[Record::key, AST::Types::t]
|
116
|
+
required_keys = Set[] #: Set[Record::key]
|
117
|
+
|
118
|
+
type.all_fields.each do |key, (value, required)|
|
119
|
+
required_keys << key if required
|
120
|
+
elements[key] = type(value)
|
96
121
|
end
|
97
|
-
|
122
|
+
|
123
|
+
Record.new(elements: elements, required_keys: required_keys)
|
98
124
|
when RBS::Types::Proc
|
99
125
|
func = Interface::Function.new(
|
100
126
|
params: params(type.type),
|
101
127
|
return_type: type(type.type.return_type),
|
102
|
-
location:
|
128
|
+
location: nil
|
103
129
|
)
|
104
130
|
block = if type.block
|
105
131
|
Interface::Block.new(
|
106
132
|
type: Interface::Function.new(
|
107
133
|
params: params(type.block.type),
|
108
134
|
return_type: type(type.block.type.return_type),
|
109
|
-
location:
|
135
|
+
location: nil
|
110
136
|
),
|
111
137
|
optional: !type.block.required,
|
112
138
|
self_type: type_opt(type.block.self_type)
|
@@ -126,67 +152,69 @@ module Steep
|
|
126
152
|
def type_1(type)
|
127
153
|
case type
|
128
154
|
when Any
|
129
|
-
RBS::Types::Bases::Any.new(location:
|
155
|
+
RBS::Types::Bases::Any.new(location: nil)
|
130
156
|
when Class
|
131
|
-
RBS::Types::Bases::Class.new(location:
|
157
|
+
RBS::Types::Bases::Class.new(location: nil)
|
132
158
|
when Instance
|
133
|
-
RBS::Types::Bases::Instance.new(location:
|
159
|
+
RBS::Types::Bases::Instance.new(location: nil)
|
134
160
|
when Self
|
135
|
-
RBS::Types::Bases::Self.new(location:
|
161
|
+
RBS::Types::Bases::Self.new(location: nil)
|
136
162
|
when Top
|
137
|
-
RBS::Types::Bases::Top.new(location:
|
163
|
+
RBS::Types::Bases::Top.new(location: nil)
|
138
164
|
when Bot
|
139
|
-
RBS::Types::Bases::Bottom.new(location:
|
165
|
+
RBS::Types::Bases::Bottom.new(location: nil)
|
140
166
|
when Boolean
|
141
|
-
RBS::Types::Bases::Bool.new(location:
|
167
|
+
RBS::Types::Bases::Bool.new(location: nil)
|
142
168
|
when Void
|
143
|
-
RBS::Types::Bases::Void.new(location:
|
169
|
+
RBS::Types::Bases::Void.new(location: nil)
|
144
170
|
when Nil
|
145
|
-
RBS::Types::Bases::Nil.new(location:
|
171
|
+
RBS::Types::Bases::Nil.new(location: nil)
|
146
172
|
when Var
|
147
|
-
RBS::Types::Variable.new(name: type.name, location:
|
173
|
+
RBS::Types::Variable.new(name: type.name, location: nil)
|
148
174
|
when Name::Singleton
|
149
|
-
RBS::Types::ClassSingleton.new(name: type.name, location:
|
175
|
+
RBS::Types::ClassSingleton.new(name: type.name, location: nil)
|
150
176
|
when Name::Instance
|
151
177
|
RBS::Types::ClassInstance.new(
|
152
178
|
name: type.name,
|
153
179
|
args: type.args.map {|arg| type_1(arg) },
|
154
|
-
location:
|
180
|
+
location: nil
|
155
181
|
)
|
156
182
|
when Name::Interface
|
157
183
|
RBS::Types::Interface.new(
|
158
184
|
name: type.name,
|
159
185
|
args: type.args.map {|arg| type_1(arg) },
|
160
|
-
location:
|
186
|
+
location: nil
|
161
187
|
)
|
162
188
|
when Name::Alias
|
163
189
|
RBS::Types::Alias.new(
|
164
190
|
name: type.name,
|
165
191
|
args: type.args.map {|arg| type_1(arg) },
|
166
|
-
location:
|
192
|
+
location: nil
|
167
193
|
)
|
168
194
|
when Union
|
169
195
|
RBS::Types::Union.new(
|
170
196
|
types: type.types.map {|ty| type_1(ty) },
|
171
|
-
location:
|
197
|
+
location: nil
|
172
198
|
)
|
173
199
|
when Intersection
|
174
200
|
RBS::Types::Intersection.new(
|
175
201
|
types: type.types.map {|ty| type_1(ty) },
|
176
|
-
location:
|
202
|
+
location: nil
|
177
203
|
)
|
178
204
|
when Literal
|
179
|
-
RBS::Types::Literal.new(literal: type.value, location:
|
205
|
+
RBS::Types::Literal.new(literal: type.value, location: nil)
|
180
206
|
when Tuple
|
181
207
|
RBS::Types::Tuple.new(
|
182
208
|
types: type.types.map {|ty| type_1(ty) },
|
183
|
-
location:
|
209
|
+
location: nil
|
184
210
|
)
|
185
211
|
when Record
|
186
|
-
|
187
|
-
|
212
|
+
all_fields = {} #: Hash[Symbol, [RBS::Types::t, bool]]
|
213
|
+
type.elements.each do |key, value|
|
214
|
+
raise unless key.is_a?(Symbol)
|
215
|
+
all_fields[key] = [type_1(value), type.required?(key)]
|
188
216
|
end
|
189
|
-
RBS::Types::Record.new(
|
217
|
+
RBS::Types::Record.new(all_fields: all_fields, location: nil)
|
190
218
|
when Proc
|
191
219
|
block = if type.block
|
192
220
|
RBS::Types::Block.new(
|
@@ -199,10 +227,10 @@ module Steep
|
|
199
227
|
type: function_1(type.type),
|
200
228
|
self_type: type_1_opt(type.self_type),
|
201
229
|
block: block,
|
202
|
-
location:
|
230
|
+
location: nil
|
203
231
|
)
|
204
232
|
when Logic::Base
|
205
|
-
RBS::Types::Bases::Bool.new(location:
|
233
|
+
RBS::Types::Bases::Bool.new(location: nil)
|
206
234
|
else
|
207
235
|
raise "Unexpected type given: #{type} (#{type.class})"
|
208
236
|
end
|
@@ -247,9 +275,10 @@ module Steep
|
|
247
275
|
def type_param(type_param)
|
248
276
|
Interface::TypeParam.new(
|
249
277
|
name: type_param.name,
|
250
|
-
upper_bound: type_opt(type_param.
|
278
|
+
upper_bound: type_opt(type_param.upper_bound_type),
|
251
279
|
variance: type_param.variance,
|
252
|
-
unchecked: type_param.unchecked
|
280
|
+
unchecked: type_param.unchecked?,
|
281
|
+
default_type: type_opt(type_param.default_type)
|
253
282
|
)
|
254
283
|
end
|
255
284
|
|
@@ -269,8 +298,8 @@ module Steep
|
|
269
298
|
).unchecked!(type_param.unchecked)
|
270
299
|
end
|
271
300
|
|
272
|
-
def method_type(method_type
|
273
|
-
|
301
|
+
def method_type(method_type)
|
302
|
+
@method_type_cache[method_type] ||=
|
274
303
|
Interface::MethodType.new(
|
275
304
|
type_params: method_type.type_params.map {|param| type_param(param) },
|
276
305
|
type: Interface::Function.new(
|
@@ -288,11 +317,8 @@ module Steep
|
|
288
317
|
),
|
289
318
|
self_type: type_opt(block.self_type)
|
290
319
|
)
|
291
|
-
end
|
292
|
-
method_decls: Set[]
|
320
|
+
end
|
293
321
|
)
|
294
|
-
|
295
|
-
mt.with(method_decls: method_decls)
|
296
322
|
end
|
297
323
|
|
298
324
|
def method_type_1(method_type)
|
@@ -337,10 +363,10 @@ module Steep
|
|
337
363
|
end
|
338
364
|
when AST::Types::Union
|
339
365
|
types = type.types.map {|ty| deep_expand_alias(ty, recursive: recursive) or return }
|
340
|
-
AST::Types::Union.build(types: types
|
366
|
+
AST::Types::Union.build(types: types)
|
341
367
|
when AST::Types::Intersection
|
342
368
|
types = type.types.map {|ty| deep_expand_alias(ty, recursive: recursive) or return }
|
343
|
-
AST::Types::Intersection.build(types: types
|
369
|
+
AST::Types::Intersection.build(types: types)
|
344
370
|
else
|
345
371
|
type
|
346
372
|
end
|
@@ -445,11 +471,11 @@ module Steep
|
|
445
471
|
type_name_resolver.resolve(type_name, context: context)
|
446
472
|
end
|
447
473
|
|
448
|
-
def instance_type(type_name, args: nil
|
474
|
+
def instance_type(type_name, args: nil)
|
449
475
|
raise unless type_name.class?
|
450
476
|
|
451
477
|
definition = definition_builder.build_singleton(type_name)
|
452
|
-
def_args = definition.type_params.map { Any.
|
478
|
+
def_args = definition.type_params.map { Any.instance }
|
453
479
|
|
454
480
|
if args
|
455
481
|
raise if def_args.size != args.size
|
@@ -457,7 +483,7 @@ module Steep
|
|
457
483
|
args = def_args
|
458
484
|
end
|
459
485
|
|
460
|
-
AST::Types::Name::Instance.new(
|
486
|
+
AST::Types::Name::Instance.new(name: type_name, args: args)
|
461
487
|
end
|
462
488
|
|
463
489
|
def try_instance_type(type)
|
@@ -485,13 +511,11 @@ module Steep
|
|
485
511
|
when AST::Types::Name::Instance
|
486
512
|
AST::Types::Name::Instance.new(
|
487
513
|
name: env.normalize_module_name(type.name),
|
488
|
-
args: type.args.map {|ty| normalize_type(ty) }
|
489
|
-
location: type.location
|
514
|
+
args: type.args.map {|ty| normalize_type(ty) }
|
490
515
|
)
|
491
516
|
when AST::Types::Name::Singleton
|
492
517
|
AST::Types::Name::Singleton.new(
|
493
|
-
name: env.normalize_module_name(type.name)
|
494
|
-
location: type.location
|
518
|
+
name: env.normalize_module_name(type.name)
|
495
519
|
)
|
496
520
|
when AST::Types::Any, AST::Types::Boolean, AST::Types::Bot, AST::Types::Nil,
|
497
521
|
AST::Types::Top, AST::Types::Void, AST::Types::Literal, AST::Types::Class, AST::Types::Instance,
|
@@ -499,37 +523,29 @@ module Steep
|
|
499
523
|
type
|
500
524
|
when AST::Types::Intersection
|
501
525
|
AST::Types::Intersection.build(
|
502
|
-
types: type.types.map {|type| normalize_type(type) }
|
503
|
-
location: type.location
|
526
|
+
types: type.types.map {|type| normalize_type(type) }
|
504
527
|
)
|
505
528
|
when AST::Types::Union
|
506
529
|
AST::Types::Union.build(
|
507
|
-
types: type.types.map {|type| normalize_type(type) }
|
508
|
-
location: type.location
|
530
|
+
types: type.types.map {|type| normalize_type(type) }
|
509
531
|
)
|
510
532
|
when AST::Types::Record
|
511
|
-
|
512
|
-
elements: type.elements.transform_values {|type| normalize_type(type) },
|
513
|
-
location: type.location
|
514
|
-
)
|
533
|
+
type.map_type {|type| normalize_type(type) }
|
515
534
|
when AST::Types::Tuple
|
516
535
|
AST::Types::Tuple.new(
|
517
|
-
types: type.types.map {|type| normalize_type(type) }
|
518
|
-
location: type.location
|
536
|
+
types: type.types.map {|type| normalize_type(type) }
|
519
537
|
)
|
520
538
|
when AST::Types::Proc
|
521
539
|
type.map_type {|type| normalize_type(type) }
|
522
540
|
when AST::Types::Name::Alias
|
523
541
|
AST::Types::Name::Alias.new(
|
524
542
|
name: type.name,
|
525
|
-
args: type.args.map {|ty| normalize_type(ty) }
|
526
|
-
location: type.location
|
543
|
+
args: type.args.map {|ty| normalize_type(ty) }
|
527
544
|
)
|
528
545
|
when AST::Types::Name::Interface
|
529
546
|
AST::Types::Name::Interface.new(
|
530
547
|
name: type.name,
|
531
|
-
args: type.args.map {|ty| normalize_type(ty) }
|
532
|
-
location: type.location
|
548
|
+
args: type.args.map {|ty| normalize_type(ty) }
|
533
549
|
)
|
534
550
|
end
|
535
551
|
end
|
@@ -2,15 +2,7 @@ module Steep
|
|
2
2
|
module AST
|
3
3
|
module Types
|
4
4
|
class Instance
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(location: nil)
|
8
|
-
@location = location
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.instance
|
12
|
-
@instance ||= new()
|
13
|
-
end
|
5
|
+
extend SharedInstance
|
14
6
|
|
15
7
|
def ==(other)
|
16
8
|
other.is_a?(Instance)
|
@@ -44,10 +36,6 @@ module Steep
|
|
44
36
|
def level
|
45
37
|
[0]
|
46
38
|
end
|
47
|
-
|
48
|
-
def with_location(new_location)
|
49
|
-
self.class.new(location: new_location)
|
50
|
-
end
|
51
39
|
end
|
52
40
|
end
|
53
41
|
end
|
@@ -3,14 +3,12 @@ module Steep
|
|
3
3
|
module Types
|
4
4
|
class Intersection
|
5
5
|
attr_reader :types
|
6
|
-
attr_reader :location
|
7
6
|
|
8
|
-
def initialize(types
|
7
|
+
def initialize(types:)
|
9
8
|
@types = types
|
10
|
-
@location = location
|
11
9
|
end
|
12
10
|
|
13
|
-
def self.build(types
|
11
|
+
def self.build(types:)
|
14
12
|
types.flat_map do |type|
|
15
13
|
if type.is_a?(Intersection)
|
16
14
|
type.types
|
@@ -20,9 +18,9 @@ module Steep
|
|
20
18
|
end.map do |type|
|
21
19
|
case type
|
22
20
|
when AST::Types::Any
|
23
|
-
return AST::Types::Any.
|
21
|
+
return AST::Types::Any.instance()
|
24
22
|
when AST::Types::Bot
|
25
|
-
return AST::Types::Bot.
|
23
|
+
return AST::Types::Bot.instance
|
26
24
|
when AST::Types::Top
|
27
25
|
nil
|
28
26
|
else
|
@@ -33,11 +31,11 @@ module Steep
|
|
33
31
|
|
34
32
|
case dups.size
|
35
33
|
when 0
|
36
|
-
AST::Types::Top.
|
34
|
+
AST::Types::Top.instance
|
37
35
|
when 1
|
38
36
|
tys.first || raise
|
39
37
|
else
|
40
|
-
new(types: dups.to_a
|
38
|
+
new(types: dups.to_a)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -53,7 +51,7 @@ module Steep
|
|
53
51
|
alias eql? ==
|
54
52
|
|
55
53
|
def subst(s)
|
56
|
-
self.class.build(
|
54
|
+
self.class.build(types: types.map {|ty| ty.subst(s) })
|
57
55
|
end
|
58
56
|
|
59
57
|
def to_s
|
@@ -82,18 +80,13 @@ module Steep
|
|
82
80
|
|
83
81
|
def map_type(&block)
|
84
82
|
self.class.build(
|
85
|
-
types: each_child.map(&block)
|
86
|
-
location: location
|
83
|
+
types: each_child.map(&block)
|
87
84
|
)
|
88
85
|
end
|
89
86
|
|
90
87
|
def level
|
91
88
|
[0] + level_of_children(types)
|
92
89
|
end
|
93
|
-
|
94
|
-
def with_location(new_location)
|
95
|
-
self.class.new(types: types, location: new_location)
|
96
|
-
end
|
97
90
|
end
|
98
91
|
end
|
99
92
|
end
|
@@ -2,11 +2,9 @@ module Steep
|
|
2
2
|
module AST
|
3
3
|
module Types
|
4
4
|
class Literal
|
5
|
-
attr_reader :location
|
6
5
|
attr_reader :value
|
7
6
|
|
8
|
-
def initialize(value
|
9
|
-
@location = location
|
7
|
+
def initialize(value:)
|
10
8
|
@value = value
|
11
9
|
end
|
12
10
|
|
@@ -37,10 +35,6 @@ module Steep
|
|
37
35
|
[0]
|
38
36
|
end
|
39
37
|
|
40
|
-
def with_location(new_location)
|
41
|
-
_ = self.class.new(value: value, location: new_location)
|
42
|
-
end
|
43
|
-
|
44
38
|
def back_type
|
45
39
|
klass = case value
|
46
40
|
when Integer
|
@@ -57,7 +51,7 @@ module Steep
|
|
57
51
|
raise "Unexpected literal type: #{(_ = value).inspect}"
|
58
52
|
end
|
59
53
|
|
60
|
-
Name::Instance.new(name: klass.module_name, args: []
|
54
|
+
Name::Instance.new(name: klass.module_name, args: [])
|
61
55
|
end
|
62
56
|
end
|
63
57
|
end
|
@@ -3,8 +3,8 @@ module Steep
|
|
3
3
|
module Types
|
4
4
|
module Logic
|
5
5
|
class Base
|
6
|
-
|
7
|
-
|
6
|
+
extend SharedInstance
|
7
|
+
|
8
8
|
def subst(s)
|
9
9
|
self
|
10
10
|
end
|
@@ -33,51 +33,30 @@ module Steep
|
|
33
33
|
end
|
34
34
|
|
35
35
|
class Not < Base
|
36
|
-
def initialize(location: nil)
|
37
|
-
@location = location
|
38
|
-
end
|
39
36
|
end
|
40
37
|
|
41
38
|
class ReceiverIsNil < Base
|
42
|
-
def initialize(location: nil)
|
43
|
-
@location = location
|
44
|
-
end
|
45
39
|
end
|
46
40
|
|
47
41
|
class ReceiverIsNotNil < Base
|
48
|
-
def initialize(location: nil)
|
49
|
-
@location = location
|
50
|
-
end
|
51
42
|
end
|
52
43
|
|
53
44
|
class ReceiverIsArg < Base
|
54
|
-
def initialize(location: nil)
|
55
|
-
@location = location
|
56
|
-
end
|
57
45
|
end
|
58
46
|
|
59
47
|
class ArgIsReceiver < Base
|
60
|
-
def initialize(location: nil)
|
61
|
-
@location = location
|
62
|
-
end
|
63
48
|
end
|
64
49
|
|
65
50
|
class ArgEqualsReceiver < Base
|
66
|
-
def initialize(location: nil)
|
67
|
-
@location = location
|
68
|
-
end
|
69
51
|
end
|
70
52
|
|
71
53
|
class ArgIsAncestor < Base
|
72
|
-
def initialize(location: nil)
|
73
|
-
@location = location
|
74
|
-
end
|
75
54
|
end
|
76
55
|
|
77
56
|
class Env < Base
|
78
57
|
attr_reader :truthy, :falsy, :type
|
79
58
|
|
80
|
-
def initialize(truthy:, falsy:, type
|
59
|
+
def initialize(truthy:, falsy:, type:)
|
81
60
|
@truthy = truthy
|
82
61
|
@falsy = falsy
|
83
62
|
@type = type
|
data/lib/steep/ast/types/name.rb
CHANGED
@@ -3,11 +3,9 @@ module Steep
|
|
3
3
|
module Types
|
4
4
|
module Name
|
5
5
|
class Base
|
6
|
-
attr_reader :location
|
7
6
|
attr_reader :name
|
8
7
|
|
9
|
-
def initialize(name
|
10
|
-
@location = location
|
8
|
+
def initialize(name:)
|
11
9
|
@name = name
|
12
10
|
end
|
13
11
|
|
@@ -29,8 +27,8 @@ module Steep
|
|
29
27
|
class Applying < Base
|
30
28
|
attr_reader :args
|
31
29
|
|
32
|
-
def initialize(name:, args
|
33
|
-
super(name: name
|
30
|
+
def initialize(name:, args:)
|
31
|
+
super(name: name)
|
34
32
|
@args = args
|
35
33
|
end
|
36
34
|
|
@@ -54,14 +52,9 @@ module Steep
|
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
def with_location(new_location)
|
58
|
-
_ = self.class.new(name: name, args: args, location: new_location)
|
59
|
-
end
|
60
|
-
|
61
55
|
def subst(s)
|
62
56
|
if free_variables.intersect?(s.domain)
|
63
57
|
_ = self.class.new(
|
64
|
-
location: location,
|
65
58
|
name: name,
|
66
59
|
args: args.map {|a| a.subst(s) }
|
67
60
|
)
|
@@ -95,7 +88,7 @@ module Steep
|
|
95
88
|
def map_type(&block)
|
96
89
|
args = self.args.map(&block)
|
97
90
|
|
98
|
-
_ = self.class.new(name: self.name, args: self.args
|
91
|
+
_ = self.class.new(name: self.name, args: self.args)
|
99
92
|
end
|
100
93
|
end
|
101
94
|
|
@@ -115,16 +108,12 @@ module Steep
|
|
115
108
|
"singleton(#{name.to_s})"
|
116
109
|
end
|
117
110
|
|
118
|
-
def with_location(new_location)
|
119
|
-
self.class.new(name: name, location: new_location)
|
120
|
-
end
|
121
|
-
|
122
111
|
include Helper::NoChild
|
123
112
|
end
|
124
113
|
|
125
114
|
class Instance < Applying
|
126
115
|
def to_module
|
127
|
-
Singleton.new(name: name
|
116
|
+
Singleton.new(name: name)
|
128
117
|
end
|
129
118
|
end
|
130
119
|
|
data/lib/steep/ast/types/nil.rb
CHANGED
@@ -2,12 +2,8 @@ module Steep
|
|
2
2
|
module AST
|
3
3
|
module Types
|
4
4
|
class Nil
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(location: nil)
|
8
|
-
@location = location
|
9
|
-
end
|
10
|
-
|
5
|
+
extend SharedInstance
|
6
|
+
|
11
7
|
def ==(other)
|
12
8
|
other.is_a?(Nil)
|
13
9
|
end
|
@@ -34,14 +30,9 @@ module Steep
|
|
34
30
|
[0]
|
35
31
|
end
|
36
32
|
|
37
|
-
def with_location(new_location)
|
38
|
-
self.class.new(location: new_location)
|
39
|
-
end
|
40
|
-
|
41
33
|
def back_type
|
42
34
|
Name::Instance.new(name: Builtin::NilClass.module_name,
|
43
|
-
args: []
|
44
|
-
location: location)
|
35
|
+
args: [])
|
45
36
|
end
|
46
37
|
end
|
47
38
|
end
|