steep 1.8.0.dev.2 → 1.8.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -59,7 +59,7 @@ module Steep
|
|
59
59
|
def variable_upper_bound(name)
|
60
60
|
@bounds.reverse_each do |hash|
|
61
61
|
if hash.key?(name)
|
62
|
-
return hash
|
62
|
+
return hash.fetch(name)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -129,20 +129,17 @@ module Steep
|
|
129
129
|
if ancestor.name.class?
|
130
130
|
AST::Types::Name::Instance.new(
|
131
131
|
name: name,
|
132
|
-
args: args
|
133
|
-
location: nil
|
132
|
+
args: args
|
134
133
|
)
|
135
134
|
else
|
136
135
|
AST::Types::Name::Interface.new(
|
137
136
|
name: name,
|
138
|
-
args: args
|
139
|
-
location: nil
|
137
|
+
args: args
|
140
138
|
)
|
141
139
|
end
|
142
140
|
when RBS::Definition::Ancestor::Singleton
|
143
141
|
AST::Types::Name::Singleton.new(
|
144
|
-
name: name
|
145
|
-
location: nil
|
142
|
+
name: name
|
146
143
|
)
|
147
144
|
end
|
148
145
|
end
|
@@ -163,20 +160,17 @@ module Steep
|
|
163
160
|
if ancestor.name.class?
|
164
161
|
AST::Types::Name::Instance.new(
|
165
162
|
name: name,
|
166
|
-
args: args
|
167
|
-
location: nil
|
163
|
+
args: args
|
168
164
|
)
|
169
165
|
else
|
170
166
|
AST::Types::Name::Interface.new(
|
171
167
|
name: name,
|
172
|
-
args: args
|
173
|
-
location: nil
|
168
|
+
args: args
|
174
169
|
)
|
175
170
|
end
|
176
171
|
when RBS::Definition::Ancestor::Singleton
|
177
172
|
AST::Types::Name::Singleton.new(
|
178
|
-
name: name
|
179
|
-
location: nil
|
173
|
+
name: name
|
180
174
|
)
|
181
175
|
end
|
182
176
|
end
|
@@ -271,9 +265,6 @@ module Steep
|
|
271
265
|
when relation.sub_type.is_a?(AST::Types::Bot)
|
272
266
|
success(relation)
|
273
267
|
|
274
|
-
when relation.sub_type.is_a?(AST::Types::Logic::Base) && (true_type?(relation.super_type) || false_type?(relation.super_type))
|
275
|
-
success(relation)
|
276
|
-
|
277
268
|
when relation.super_type.is_a?(AST::Types::Boolean)
|
278
269
|
Expand(relation) do
|
279
270
|
check_type(
|
@@ -284,7 +275,7 @@ module Steep
|
|
284
275
|
)
|
285
276
|
end
|
286
277
|
|
287
|
-
when relation.sub_type.is_a?(AST::Types::Boolean)
|
278
|
+
when relation.sub_type.is_a?(AST::Types::Boolean) || relation.sub_type.is_a?(AST::Types::Logic::Base)
|
288
279
|
Expand(relation) do
|
289
280
|
check_type(
|
290
281
|
Relation.new(
|
@@ -357,20 +348,51 @@ module Steep
|
|
357
348
|
constraints.add(relation.sub_type.name, super_type: relation.super_type)
|
358
349
|
Success(relation)
|
359
350
|
|
360
|
-
when relation.sub_type.is_a?(AST::Types::
|
351
|
+
when relation.sub_type.is_a?(AST::Types::Var) && ub = variable_upper_bound(relation.sub_type.name)
|
352
|
+
Expand(relation) do
|
353
|
+
check_type(Relation.new(sub_type: ub, super_type: relation.super_type))
|
354
|
+
end
|
355
|
+
|
356
|
+
when relation.sub_type.is_a?(AST::Types::Intersection) && relation.super_type.is_a?(AST::Types::Union)
|
357
|
+
Any(relation) do |base_result|
|
358
|
+
# Expand the super_type first
|
359
|
+
base_result.add(relation) do
|
360
|
+
Any(relation) do |result|
|
361
|
+
relation.super_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |super_type|
|
362
|
+
rel = Relation.new(sub_type: relation.sub_type, super_type: super_type)
|
363
|
+
result.add(rel) do
|
364
|
+
check_type(rel)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# Expand the sub_type if it fails
|
371
|
+
base_result.add(relation) do
|
372
|
+
Any(relation) do |result|
|
373
|
+
relation.sub_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |sub_type|
|
374
|
+
rel = Relation.new(sub_type: sub_type, super_type: relation.super_type)
|
375
|
+
result.add(rel) do
|
376
|
+
check_type(rel)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
when relation.super_type.is_a?(AST::Types::Intersection)
|
361
384
|
All(relation) do |result|
|
362
|
-
relation.
|
363
|
-
|
364
|
-
result.add(rel) do
|
385
|
+
relation.super_type.types.each do |super_type|
|
386
|
+
result.add(Relation.new(sub_type: relation.sub_type, super_type: super_type)) do |rel|
|
365
387
|
check_type(rel)
|
366
388
|
end
|
367
389
|
end
|
368
390
|
end
|
369
391
|
|
370
|
-
when relation.
|
371
|
-
|
372
|
-
relation.
|
373
|
-
rel = Relation.new(sub_type:
|
392
|
+
when relation.sub_type.is_a?(AST::Types::Union)
|
393
|
+
All(relation) do |result|
|
394
|
+
relation.sub_type.types.each do |sub_type|
|
395
|
+
rel = Relation.new(sub_type: sub_type, super_type: relation.super_type)
|
374
396
|
result.add(rel) do
|
375
397
|
check_type(rel)
|
376
398
|
end
|
@@ -387,23 +409,16 @@ module Steep
|
|
387
409
|
end
|
388
410
|
end
|
389
411
|
|
390
|
-
when relation.super_type.is_a?(AST::Types::
|
391
|
-
|
392
|
-
relation.super_type.types.each do |super_type|
|
393
|
-
|
412
|
+
when relation.super_type.is_a?(AST::Types::Union)
|
413
|
+
Any(relation) do |result|
|
414
|
+
relation.super_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |super_type|
|
415
|
+
rel = Relation.new(sub_type: relation.sub_type, super_type: super_type)
|
416
|
+
result.add(rel) do
|
394
417
|
check_type(rel)
|
395
418
|
end
|
396
419
|
end
|
397
420
|
end
|
398
421
|
|
399
|
-
when relation.sub_type.is_a?(AST::Types::Var) && ub = variable_upper_bound(relation.sub_type.name)
|
400
|
-
Expand(relation) do
|
401
|
-
check_type(Relation.new(sub_type: ub, super_type: relation.super_type))
|
402
|
-
end
|
403
|
-
|
404
|
-
when relation.super_type.is_a?(AST::Types::Var) || relation.sub_type.is_a?(AST::Types::Var)
|
405
|
-
Failure(relation, Result::Failure::UnknownPairError.new(relation: relation))
|
406
|
-
|
407
422
|
when relation.super_type.is_a?(AST::Types::Name::Interface)
|
408
423
|
Expand(relation) do
|
409
424
|
check_interface(
|
@@ -497,37 +512,72 @@ module Steep
|
|
497
512
|
Expand(relation) do
|
498
513
|
tuple_element_type =
|
499
514
|
AST::Types::Union.build(
|
500
|
-
types: relation.sub_type.types
|
501
|
-
location: relation.sub_type.location
|
515
|
+
types: relation.sub_type.types
|
502
516
|
)
|
503
517
|
|
504
518
|
check_type(Relation.new(sub_type: tuple_element_type, super_type: super_type.args[0]))
|
505
519
|
end
|
506
520
|
|
521
|
+
when relation.sub_type.is_a?(AST::Types::Tuple)
|
522
|
+
Any(relation) do |result|
|
523
|
+
# Check by converting the tuple to array
|
524
|
+
tuple_element_type = AST::Types::Union.build(types: relation.sub_type.types)
|
525
|
+
array_type = AST::Builtin::Array.instance_type(tuple_element_type)
|
526
|
+
result.add(Relation.new(sub_type: array_type, super_type: relation.super_type)) do
|
527
|
+
check_type(_1)
|
528
|
+
end
|
529
|
+
|
530
|
+
# Check by shapes
|
531
|
+
shape_relation = relation.map {|type|
|
532
|
+
# @type break: nil
|
533
|
+
builder.shape(
|
534
|
+
type, Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
|
535
|
+
)&.public_shape or break
|
536
|
+
}
|
537
|
+
if shape_relation
|
538
|
+
result.add(shape_relation) { check_interface(_1) }
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
507
542
|
when relation.sub_type.is_a?(AST::Types::Record) && relation.super_type.is_a?(AST::Types::Record)
|
508
543
|
All(relation) do |result|
|
509
544
|
relation.super_type.elements.each_key do |key|
|
510
|
-
|
511
|
-
sub_type: relation.sub_type.elements[key] || AST::Builtin.nil_type,
|
512
|
-
super_type: relation.super_type.elements[key]
|
513
|
-
)
|
545
|
+
super_element_type = relation.super_type.elements[key]
|
514
546
|
|
515
|
-
|
516
|
-
|
547
|
+
if relation.sub_type.elements.key?(key)
|
548
|
+
sub_element_type = relation.sub_type.elements[key]
|
549
|
+
else
|
550
|
+
if relation.super_type.required?(key)
|
551
|
+
sub_element_type = AST::Builtin.nil_type
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
if sub_element_type
|
556
|
+
rel = Relation.new(sub_type: sub_element_type, super_type: super_element_type)
|
557
|
+
result.add(rel) { check_type(rel) }
|
517
558
|
end
|
518
559
|
end
|
519
560
|
end
|
520
561
|
|
521
|
-
when relation.sub_type.is_a?(AST::Types::Record)
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
562
|
+
when relation.sub_type.is_a?(AST::Types::Record)
|
563
|
+
Any(relation) do |result|
|
564
|
+
# Check by converting the record to hash
|
565
|
+
key_type = AST::Types::Union.build(types: relation.sub_type.elements.each_key.map {|key| AST::Types::Literal.new(value: key) })
|
566
|
+
value_type = AST::Types::Union.build(types: relation.sub_type.elements.each_value.map {|key| key })
|
567
|
+
hash_type = AST::Builtin::Hash.instance_type(key_type, value_type)
|
568
|
+
result.add(Relation.new(sub_type: hash_type, super_type: relation.super_type)) { check_type(_1) }
|
569
|
+
|
570
|
+
# Check by the shapes
|
571
|
+
shape_relation = relation.map do |type|
|
572
|
+
# @type break: nil
|
573
|
+
builder.shape(
|
574
|
+
type,
|
575
|
+
Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
|
576
|
+
)&.public_shape or break
|
577
|
+
end
|
578
|
+
if shape_relation
|
579
|
+
result.add(shape_relation) { check_interface(_1) }
|
580
|
+
end
|
531
581
|
end
|
532
582
|
|
533
583
|
when relation.sub_type.is_a?(AST::Types::Proc) && AST::Builtin::Proc.instance_type?(relation.super_type)
|
@@ -113,13 +113,13 @@ module Steep
|
|
113
113
|
end
|
114
114
|
|
115
115
|
if super_type && !super_type.is_a?(AST::Types::Top)
|
116
|
-
type = eliminate_variable(super_type, to: AST::Types::Top.
|
116
|
+
type = eliminate_variable(super_type, to: AST::Types::Top.instance)
|
117
117
|
supers << type
|
118
118
|
skips << type if skip
|
119
119
|
end
|
120
120
|
|
121
121
|
if sub_type && !sub_type.is_a?(AST::Types::Bot)
|
122
|
-
type = eliminate_variable(sub_type, to: AST::Types::Bot.
|
122
|
+
type = eliminate_variable(sub_type, to: AST::Types::Bot.instance)
|
123
123
|
subs << type
|
124
124
|
skips << type if skip
|
125
125
|
end
|
@@ -147,19 +147,19 @@ module Steep
|
|
147
147
|
case type
|
148
148
|
when AST::Types::Name::Instance, AST::Types::Name::Alias, AST::Types::Name::Interface
|
149
149
|
type.args.map do |ty|
|
150
|
-
eliminate_variable(ty, to: AST::Types::Any.
|
150
|
+
eliminate_variable(ty, to: AST::Types::Any.instance)
|
151
151
|
end.yield_self do |args|
|
152
|
-
type.class.new(name: type.name, args: args
|
152
|
+
type.class.new(name: type.name, args: args)
|
153
153
|
end
|
154
154
|
when AST::Types::Union
|
155
155
|
type.types.map do |ty|
|
156
|
-
eliminate_variable(ty, to: AST::Types::Any.
|
156
|
+
eliminate_variable(ty, to: AST::Types::Any.instance)
|
157
157
|
end.yield_self do |types|
|
158
158
|
AST::Types::Union.build(types: types)
|
159
159
|
end
|
160
160
|
when AST::Types::Intersection
|
161
161
|
type.types.map do |ty|
|
162
|
-
eliminate_variable(ty, to: AST::Types::Any.
|
162
|
+
eliminate_variable(ty, to: AST::Types::Any.instance)
|
163
163
|
end.yield_self do |types|
|
164
164
|
AST::Types::Intersection.build(types: types)
|
165
165
|
end
|
@@ -171,14 +171,10 @@ module Steep
|
|
171
171
|
end
|
172
172
|
when AST::Types::Tuple
|
173
173
|
AST::Types::Tuple.new(
|
174
|
-
types: type.types.map {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) }
|
175
|
-
location: type.location
|
174
|
+
types: type.types.map {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) }
|
176
175
|
)
|
177
176
|
when AST::Types::Record
|
178
|
-
AST::
|
179
|
-
elements: type.elements.transform_values {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) },
|
180
|
-
location: type.location
|
181
|
-
)
|
177
|
+
type.map_type { eliminate_variable(_1, to: AST::Builtin.any_type) }
|
182
178
|
when AST::Types::Proc
|
183
179
|
type.map_type {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) }
|
184
180
|
else
|
@@ -213,7 +209,7 @@ module Steep
|
|
213
209
|
|
214
210
|
case upper_bound.size
|
215
211
|
when 0
|
216
|
-
AST::Types::Top.
|
212
|
+
AST::Types::Top.instance
|
217
213
|
when 1
|
218
214
|
upper_bound.first || raise
|
219
215
|
else
|
@@ -226,7 +222,7 @@ module Steep
|
|
226
222
|
|
227
223
|
case lower_bound.size
|
228
224
|
when 0
|
229
|
-
AST::Types::Bot.
|
225
|
+
AST::Types::Bot.instance
|
230
226
|
when 1
|
231
227
|
lower_bound.first || raise
|
232
228
|
else
|
@@ -293,7 +289,7 @@ module Steep
|
|
293
289
|
end
|
294
290
|
else
|
295
291
|
vars << var
|
296
|
-
types << AST::Types::Any.
|
292
|
+
types << AST::Types::Any.instance
|
297
293
|
end
|
298
294
|
end
|
299
295
|
end
|