typeprof 0.20.2 → 0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/typeprof/analyzer.rb +52 -12
- data/lib/typeprof/block.rb +2 -1
- data/lib/typeprof/container-type.rb +3 -2
- data/lib/typeprof/export.rb +39 -4
- data/lib/typeprof/import.rb +37 -5
- data/lib/typeprof/insns-def.rb +1 -0
- data/lib/typeprof/iseq.rb +2 -2
- data/lib/typeprof/method.rb +25 -4
- data/lib/typeprof/type.rb +4 -4
- data/lib/typeprof/version.rb +1 -1
- data/typeprof.gemspec +2 -2
- data/vscode/package-lock.json +1069 -31
- data/vscode/package.json +3 -3
- data/vscode/src/extension.ts +31 -14
- metadata +4 -12
- data/doc/demo.md +0 -398
- data/doc/doc.ja.md +0 -424
- data/doc/doc.md +0 -437
- data/doc/ide.md +0 -81
- data/doc/ppl2019.pdf +0 -0
- data/doc/todo.md +0 -133
- data/doc/typeprof-for-ide-log.png +0 -0
- data/doc/typeprof-for-ide.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dafe7189434a08afb147b33a67d030e17f2dd93f7495b3b42d220375e028a8c4
|
4
|
+
data.tar.gz: '05090ed2b4df798245b2f7e62912e19e8c92176b7eab72bee8d1c6759a85e105'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 934bddb52e1f5ca98df3e3534b400471da72efbf4a0648c9c1c162535cdf1023fff7fdc6620205934a75142401aadba0f739138c7bd96e7522a677d8b5100b63
|
7
|
+
data.tar.gz: 9c047caa1cffa7ffe97f73d17554c271582b28082f949c48fd234950138bd0c9dfcd8e70c4b1493c868ef4dbe75355a8f92dad7100b7eeafb8ff55367ba54e29
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
typeprof (0.
|
5
|
-
rbs (>= 1.
|
4
|
+
typeprof (0.21.0)
|
5
|
+
rbs (>= 1.8.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
coverage-helpers (1.0.0)
|
11
11
|
docile (1.4.0)
|
12
|
-
power_assert (2.0.
|
12
|
+
power_assert (2.0.1)
|
13
13
|
rake (13.0.1)
|
14
|
-
rbs (1.
|
14
|
+
rbs (1.8.1)
|
15
15
|
simplecov (0.21.2)
|
16
16
|
docile (~> 1.1)
|
17
17
|
simplecov-html (~> 0.11)
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
simplecov-html (0.12.3)
|
20
20
|
simplecov_json_formatter (0.1.3)
|
21
21
|
stackprof (0.2.17)
|
22
|
-
test-unit (3.
|
22
|
+
test-unit (3.5.3)
|
23
23
|
power_assert
|
24
24
|
|
25
25
|
PLATFORMS
|
data/lib/typeprof/analyzer.rb
CHANGED
@@ -345,7 +345,7 @@ module TypeProf
|
|
345
345
|
attr_reader :class_defs
|
346
346
|
|
347
347
|
class ClassDef # or ModuleDef
|
348
|
-
def initialize(kind, name, absolute_path)
|
348
|
+
def initialize(kind, name, absolute_path, superclass)
|
349
349
|
raise unless name.is_a?(Array)
|
350
350
|
@kind = kind
|
351
351
|
@modules = {
|
@@ -359,10 +359,11 @@ module TypeProf
|
|
359
359
|
@cvars = VarTable.new
|
360
360
|
@absolute_path = absolute_path
|
361
361
|
@namespace = nil
|
362
|
+
@superclass = superclass
|
362
363
|
@subclasses = []
|
363
364
|
end
|
364
365
|
|
365
|
-
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :subclasses
|
366
|
+
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
|
366
367
|
attr_accessor :name, :klass_obj
|
367
368
|
|
368
369
|
def mix_module(kind, mod, type_args, singleton, absolute_path)
|
@@ -446,14 +447,22 @@ module TypeProf
|
|
446
447
|
end
|
447
448
|
end
|
448
449
|
|
449
|
-
def
|
450
|
+
def check_typed(mid, singleton, klass)
|
450
451
|
set = @methods[[singleton, mid]]
|
451
452
|
return nil unless set
|
452
|
-
set = set.select {|mdef| mdef.is_a?(
|
453
|
+
set = set.select {|mdef| mdef.is_a?(klass) }
|
453
454
|
return nil if set.empty?
|
454
455
|
return set
|
455
456
|
end
|
456
457
|
|
458
|
+
def check_typed_method(mid, singleton)
|
459
|
+
check_typed(mid, singleton, TypedMethodDef)
|
460
|
+
end
|
461
|
+
|
462
|
+
def check_typed_attr(mid, singleton)
|
463
|
+
check_typed(mid, singleton, TypedAttrMethodDef)
|
464
|
+
end
|
465
|
+
|
457
466
|
def add_method(mid, singleton, mdef)
|
458
467
|
@methods[[singleton, mid]] ||= Utils::MutableSet.new
|
459
468
|
@methods[[singleton, mid]] << mdef
|
@@ -494,8 +503,9 @@ module TypeProf
|
|
494
503
|
show_name = cbase_path(cbase) + [name]
|
495
504
|
idx = @class_defs.size
|
496
505
|
if superclass
|
497
|
-
@class_defs[idx]
|
498
|
-
@class_defs[
|
506
|
+
superclass_def = @class_defs[superclass.idx] unless superclass == :__root__
|
507
|
+
@class_defs[idx] = ClassDef.new(:class, show_name, def_ep&.absolute_path, superclass_def)
|
508
|
+
superclass_def.subclasses << idx if superclass_def
|
499
509
|
klass = Type::Class.new(:class, idx, type_params, superclass, show_name)
|
500
510
|
@class_defs[idx].klass_obj = klass
|
501
511
|
cbase ||= klass # for bootstrap
|
@@ -503,7 +513,7 @@ module TypeProf
|
|
503
513
|
return klass
|
504
514
|
else
|
505
515
|
# module
|
506
|
-
@class_defs[idx] = ClassDef.new(:module, show_name, def_ep&.absolute_path)
|
516
|
+
@class_defs[idx] = ClassDef.new(:module, show_name, def_ep&.absolute_path, nil)
|
507
517
|
mod = Type::Class.new(:module, idx, type_params, nil, show_name)
|
508
518
|
@class_defs[idx].klass_obj = mod
|
509
519
|
add_constant(cbase, name, mod, def_ep)
|
@@ -521,7 +531,8 @@ module TypeProf
|
|
521
531
|
idx = @class_defs.size
|
522
532
|
superclass = Type::Builtin[:struct]
|
523
533
|
name = "AnonymousStruct_generated_#{ @anonymous_struct_gen_id += 1 }"
|
524
|
-
|
534
|
+
# Should we pass a superclass here?
|
535
|
+
@class_defs[idx] = ClassDef.new(:class, [name], ep.ctx.iseq.absolute_path, nil)
|
525
536
|
#@class_defs[superclass.idx].subclasses << idx # needed?
|
526
537
|
klass = Type::Class.new(:class, idx, [], superclass, name)
|
527
538
|
add_superclass_type_args!(klass, [Type.any])
|
@@ -701,6 +712,10 @@ module TypeProf
|
|
701
712
|
@class_defs[klass.idx].check_typed_method(mid, singleton)
|
702
713
|
end
|
703
714
|
|
715
|
+
def check_typed_attr(klass, mid, singleton)
|
716
|
+
@class_defs[klass.idx].check_typed_attr(mid, singleton)
|
717
|
+
end
|
718
|
+
|
704
719
|
def add_method(klass, mid, singleton, mdef)
|
705
720
|
@class_defs[klass.idx].add_method(mid, singleton, mdef)
|
706
721
|
mdef
|
@@ -713,13 +728,26 @@ module TypeProf
|
|
713
728
|
|
714
729
|
def add_attr_method(klass, mid, ivar, kind, pub_meth, ep)
|
715
730
|
if kind == :reader || kind == :accessor
|
716
|
-
|
731
|
+
typed_mdef = check_typed_attr(klass, mid, ep.ctx.cref.singleton)
|
732
|
+
unless typed_mdef
|
733
|
+
add_method(klass, mid, false, ExecutedAttrMethodDef.new(ivar, :reader, pub_meth, ep))
|
734
|
+
end
|
717
735
|
end
|
718
736
|
if kind == :writer || kind == :accessor
|
719
|
-
|
737
|
+
mid = :"#{ mid }="
|
738
|
+
typed_mdef = check_typed_attr(klass, mid, ep.ctx.cref.singleton)
|
739
|
+
unless typed_mdef
|
740
|
+
add_method(klass, mid, false, ExecutedAttrMethodDef.new(ivar, :writer, pub_meth, ep))
|
741
|
+
end
|
720
742
|
end
|
721
743
|
end
|
722
744
|
|
745
|
+
def add_typed_attr_method(klass, mdef)
|
746
|
+
name = mdef.ivar[1..-1]
|
747
|
+
name = mdef.kind == :writer ? :"#{ name }=" : name.to_sym
|
748
|
+
add_method(klass, name, false, mdef)
|
749
|
+
end
|
750
|
+
|
723
751
|
def add_iseq_method(klass, mid, iseq, cref, outer_ep, pub_meth)
|
724
752
|
add_method(klass, mid, false, ISeqMethodDef.new(iseq, cref, outer_ep, pub_meth))
|
725
753
|
end
|
@@ -848,7 +876,7 @@ module TypeProf
|
|
848
876
|
end
|
849
877
|
entry.type = entry.type.union(ty)
|
850
878
|
entry.read_continuations.each do |read_ep, ctn|
|
851
|
-
ctn[ty, read_ep, [ep]]
|
879
|
+
ctn[ty, read_ep, ep ? [ep] : []]
|
852
880
|
end
|
853
881
|
end
|
854
882
|
|
@@ -1396,6 +1424,9 @@ module TypeProf
|
|
1396
1424
|
when :tostring, :anytostring
|
1397
1425
|
env, (_ty1, _ty2,) = env.pop(2)
|
1398
1426
|
env = env.push(Type::Instance.new(Type::Builtin[:str]))
|
1427
|
+
when :objtostring
|
1428
|
+
env, (_ty1,) = env.pop(1)
|
1429
|
+
env = env.push(Type::Instance.new(Type::Builtin[:str]))
|
1399
1430
|
when :freezestring
|
1400
1431
|
# do nothing
|
1401
1432
|
when :toregexp
|
@@ -1418,7 +1449,16 @@ module TypeProf
|
|
1418
1449
|
cref = ep.ctx.cref
|
1419
1450
|
recv.each_child do |recv|
|
1420
1451
|
if recv.is_a?(Type::Class)
|
1421
|
-
|
1452
|
+
typed_mdef = check_typed_method(recv, mid, true)
|
1453
|
+
if typed_mdef
|
1454
|
+
mdef = ISeqMethodDef.new(iseq, cref, nil, env.static_env.pub_meth)
|
1455
|
+
typed_mdef.each do |typed_mdef|
|
1456
|
+
typed_mdef.do_match_iseq_mdef(mdef, recv, mid, env, ep, self)
|
1457
|
+
end
|
1458
|
+
else
|
1459
|
+
meth = add_singleton_iseq_method(recv, mid, iseq, cref, nil, env.static_env.pub_meth)
|
1460
|
+
end
|
1461
|
+
|
1422
1462
|
pend_method_execution(iseq, meth, recv, mid, ep.ctx.cref, nil)
|
1423
1463
|
else
|
1424
1464
|
recv = Type.any # XXX: what to do?
|
data/lib/typeprof/block.rb
CHANGED
@@ -97,7 +97,8 @@ module TypeProf
|
|
97
97
|
# check?
|
98
98
|
#subst = { Type::Var.new(:self) => caller_env.static_env.recv_ty }
|
99
99
|
# XXX: Update type vars
|
100
|
-
|
100
|
+
ret_ty = @ret_ty.remove_type_vars
|
101
|
+
ctn[ret_ty, caller_ep, caller_env]
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
@@ -227,8 +227,9 @@ module TypeProf
|
|
227
227
|
|
228
228
|
def screen_name(scratch)
|
229
229
|
str = @elems.screen_name(scratch)
|
230
|
-
if str
|
231
|
-
str = @base_type.
|
230
|
+
if str =~ /\A\*\[(.*)\]\z/
|
231
|
+
str = @base_type.klass.type_params.map {|var_name,| var_name == :Elem ? $1 : "untyped" }.join(", ")
|
232
|
+
str = "#{ @base_type.screen_name(scratch) }[#{ str }]"
|
232
233
|
end
|
233
234
|
str
|
234
235
|
end
|
data/lib/typeprof/export.rb
CHANGED
@@ -163,8 +163,7 @@ module TypeProf
|
|
163
163
|
visibilities[key] ||= mdef.pub_meth
|
164
164
|
source_locations[key] ||= mdef.def_ep&.source_location
|
165
165
|
methods[key] = orig_name
|
166
|
-
when
|
167
|
-
next if !mdef.def_ep
|
166
|
+
when ExecutedAttrMethodDef
|
168
167
|
absolute_path = mdef.def_ep.ctx.iseq.absolute_path
|
169
168
|
next if !absolute_path || Config.current.check_dir_filter(absolute_path) == :exclude
|
170
169
|
mid = mid.to_s[0..-2].to_sym if mid.to_s.end_with?("=")
|
@@ -191,14 +190,46 @@ module TypeProf
|
|
191
190
|
visibilities[key] ||= mdef.pub_meth
|
192
191
|
source_locations[key] ||= mdef.iseq&.source_location(0)
|
193
192
|
end
|
193
|
+
when TypedAttrMethodDef
|
194
|
+
if mdef.rbs_source
|
195
|
+
mid = mid.to_s[0..-2].to_sym if mid.to_s.end_with?("=")
|
196
|
+
method_name = mid
|
197
|
+
method_name = [method_name, :"@#{ mid }" != mdef.ivar]
|
198
|
+
key = [:rbs_attr, method_name]
|
199
|
+
visibilities[key] ||= mdef.pub_meth
|
200
|
+
if methods[key]
|
201
|
+
if methods[key][0] != mdef.kind
|
202
|
+
methods[key][0] = :accessor
|
203
|
+
end
|
204
|
+
else
|
205
|
+
entry = ivars[[singleton, mdef.ivar]]
|
206
|
+
ty = entry ? entry.type : Type.any
|
207
|
+
methods[key] = [mdef.kind, ty.screen_name(@scratch), ty.include_untyped?(@scratch)]
|
208
|
+
end
|
209
|
+
end
|
194
210
|
end
|
195
211
|
end
|
196
212
|
end
|
197
213
|
|
214
|
+
superclass_ivars = {}
|
215
|
+
while (superclass_def = (superclass_def || class_def).superclass)
|
216
|
+
superclass_ivars.merge!(superclass_def.ivars.dump)
|
217
|
+
end
|
218
|
+
|
198
219
|
ivars = ivars.map do |(singleton, var), entry|
|
199
220
|
next if entry.absolute_paths.all? {|path| Config.current.check_dir_filter(path) == :exclude }
|
200
221
|
ty = entry.type
|
201
222
|
next unless var.to_s.start_with?("@")
|
223
|
+
|
224
|
+
if (_, existing = superclass_ivars.find {|((s, v), _)| s == singleton && v == var })
|
225
|
+
existing_types = existing.type.is_a?(Type::Union) ? existing.type.types : [existing.type]
|
226
|
+
entry_types = entry.type.is_a?(Type::Union) ? entry.type.types : [entry.type]
|
227
|
+
if entry_types.all? { |t| existing_types.include?(t) }
|
228
|
+
# This type is a subset of the parent type
|
229
|
+
next
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
202
233
|
var = "self.#{ var }" if singleton
|
203
234
|
next if methods[[:attr, [singleton ? "self.#{ var.to_s[1..] }" : var.to_s[1..].to_sym, false]]]
|
204
235
|
next if entry.rbs_declared
|
@@ -302,7 +333,7 @@ module TypeProf
|
|
302
333
|
visibilities[key] ||= mdef.pub_meth
|
303
334
|
source_locations[key] ||= [mdef.def_ep&.source_location]
|
304
335
|
methods[key] = orig_name
|
305
|
-
when
|
336
|
+
when ExecutedAttrMethodDef
|
306
337
|
next if !mdef.def_ep
|
307
338
|
absolute_path = mdef.def_ep.ctx.iseq.absolute_path
|
308
339
|
next if !absolute_path || Config.current.check_dir_filter(absolute_path) == :exclude
|
@@ -383,7 +414,7 @@ module TypeProf
|
|
383
414
|
source_location, rbs_code_range = class_data.source_locations[key]
|
384
415
|
type, (method_name, hidden) = key
|
385
416
|
case type
|
386
|
-
when :attr
|
417
|
+
when :attr, :rbs_attr
|
387
418
|
kind, ty, untyped = *arg
|
388
419
|
line = "attr_#{ kind } #{ method_name }#{ hidden ? "()" : "" }: #{ ty }"
|
389
420
|
when :rbs
|
@@ -522,11 +553,15 @@ module TypeProf
|
|
522
553
|
end
|
523
554
|
type, (method_name, hidden) = key
|
524
555
|
case type
|
556
|
+
when :rbs_attr
|
557
|
+
kind, ty, untyped = *arg
|
558
|
+
lines << (indent + "# attr_#{ kind } #{ method_name }#{ hidden ? "()" : "" }: #{ ty }")
|
525
559
|
when :attr
|
526
560
|
kind, ty, untyped = *arg
|
527
561
|
exclude = Config.current.options[:exclude_untyped] && untyped ? "#" : " " # XXX
|
528
562
|
lines << (indent + "#{ exclude } attr_#{ kind } #{ method_name }#{ hidden ? "()" : "" }: #{ ty }")
|
529
563
|
when :rbs
|
564
|
+
arg = arg.map { |a| a.split("\n").join("\n" + indent + "#" + " " * (method_name.size + 5)) }
|
530
565
|
sigs = arg.sort.join("\n" + indent + "#" + " " * (method_name.size + 5) + "| ")
|
531
566
|
lines << (indent + "# def #{ method_name }: #{ sigs }")
|
532
567
|
when :iseq
|
data/lib/typeprof/import.rb
CHANGED
@@ -158,7 +158,10 @@ module TypeProf
|
|
158
158
|
decls.each do |decl|
|
159
159
|
decl = decl.decl
|
160
160
|
|
161
|
-
type_params2 = decl.type_params
|
161
|
+
type_params2 = decl.type_params
|
162
|
+
# A hack to deal with the imcompatibility between rbs 1.8 and 2.0
|
163
|
+
type_params2 = type_params2.params if type_params2.respond_to?(:params)
|
164
|
+
type_params2 = type_params2.map {|param| [param.name, param.variance] }
|
162
165
|
raise "inconsistent type parameter declaration" if type_params && type_params != type_params2
|
163
166
|
type_params = type_params2
|
164
167
|
|
@@ -191,12 +194,15 @@ module TypeProf
|
|
191
194
|
when RBS::AST::Members::AttrReader
|
192
195
|
ty = conv_type(member.type)
|
193
196
|
attr_methods[[false, member.name]] = attr_method_def(:reader, member.name, ty, visibility)
|
197
|
+
rbs_sources[[false, member.name]] = attr_rbs_source(member)
|
194
198
|
when RBS::AST::Members::AttrWriter
|
195
199
|
ty = conv_type(member.type)
|
196
200
|
attr_methods[[false, member.name]] = attr_method_def(:writer, member.name, ty, visibility)
|
201
|
+
rbs_sources[[false, member.name]] = attr_rbs_source(member)
|
197
202
|
when RBS::AST::Members::AttrAccessor
|
198
203
|
ty = conv_type(member.type)
|
199
204
|
attr_methods[[false, member.name]] = attr_method_def(:accessor, member.name, ty, visibility)
|
205
|
+
rbs_sources[[false, member.name]] = attr_rbs_source(member)
|
200
206
|
when RBS::AST::Members::Alias
|
201
207
|
# XXX: an alias to attr methods?
|
202
208
|
if member.instance?
|
@@ -394,6 +400,14 @@ module TypeProf
|
|
394
400
|
}
|
395
401
|
end
|
396
402
|
|
403
|
+
def attr_rbs_source(member)
|
404
|
+
[
|
405
|
+
member.name.to_s,
|
406
|
+
member.type.location.source,
|
407
|
+
[member.location.name, CodeRange.from_rbs(member.location)],
|
408
|
+
]
|
409
|
+
end
|
410
|
+
|
397
411
|
def conv_block(rbs_block)
|
398
412
|
blk = rbs_block.type
|
399
413
|
|
@@ -604,11 +618,13 @@ module TypeProf
|
|
604
618
|
end
|
605
619
|
|
606
620
|
attr_methods.each do |(singleton, method_name), mdef|
|
607
|
-
|
608
|
-
ivar = mdef[:ivar]
|
621
|
+
rbs_source = explicit ? rbs_sources[[singleton, method_name]] : nil
|
609
622
|
ty = conv_type(mdef[:ty]).remove_type_vars
|
610
|
-
|
611
|
-
|
623
|
+
mdefs = conv_attr_defs(mdef, rbs_source)
|
624
|
+
mdefs.each do |mdef|
|
625
|
+
@scratch.add_typed_attr_method(klass, mdef)
|
626
|
+
end
|
627
|
+
@scratch.add_ivar_write!(Type::Instance.new(klass), :"@#{ mdef[:ivar] }", ty, nil)
|
612
628
|
end
|
613
629
|
|
614
630
|
ivars.each do |ivar_name, ty|
|
@@ -644,6 +660,22 @@ module TypeProf
|
|
644
660
|
TypedMethodDef.new(sig_rets, rbs_source, mdef[:visibility])
|
645
661
|
end
|
646
662
|
|
663
|
+
def conv_attr_defs(mdef, rbs_source)
|
664
|
+
ivar = :"@#{ mdef[:ivar] }"
|
665
|
+
kind = mdef[:kind]
|
666
|
+
pub_meth = mdef[:visibility]
|
667
|
+
|
668
|
+
defs = []
|
669
|
+
if kind == :reader || kind == :accessor
|
670
|
+
defs << TypedAttrMethodDef.new(ivar, :reader, pub_meth, rbs_source)
|
671
|
+
end
|
672
|
+
if kind == :writer || kind == :accessor
|
673
|
+
defs << TypedAttrMethodDef.new(ivar, :writer, pub_meth, rbs_source)
|
674
|
+
end
|
675
|
+
raise if defs.empty?
|
676
|
+
defs
|
677
|
+
end
|
678
|
+
|
647
679
|
def conv_func(sig_ret)
|
648
680
|
#type_params = sig_ret[:type_params] # XXX
|
649
681
|
lead_tys = sig_ret[:lead_tys]
|
data/lib/typeprof/insns-def.rb
CHANGED
data/lib/typeprof/iseq.rb
CHANGED
@@ -704,7 +704,7 @@ module TypeProf
|
|
704
704
|
sp += 1
|
705
705
|
when :newhashfromarray
|
706
706
|
raise NotImplementedError, "newhashfromarray"
|
707
|
-
when :newrange, :tostring, :anytostring
|
707
|
+
when :newrange, :tostring, :objtostring, :anytostring
|
708
708
|
sp -= 2
|
709
709
|
return nil if sp <= 0
|
710
710
|
sp += 1
|
@@ -753,7 +753,7 @@ module TypeProf
|
|
753
753
|
when :setlocal, :setblockparam
|
754
754
|
return # conservative
|
755
755
|
when :getinstancevariable, :getclassvariable, :getglobal,
|
756
|
-
:getlocal, :getblockparam, :getblockparamproxy
|
756
|
+
:getlocal, :getblockparam, :getblockparamproxy, :getlocal_checkmatch_branch
|
757
757
|
sp += 1
|
758
758
|
when :getconstant
|
759
759
|
sp -= 2
|
data/lib/typeprof/method.rb
CHANGED
@@ -67,6 +67,10 @@ module TypeProf
|
|
67
67
|
if rest_start
|
68
68
|
# almost ok
|
69
69
|
else
|
70
|
+
if msig.rest_ty
|
71
|
+
scratch.error(ep, "RBS says that a rest argument is accepted, but the method definition does not accept one")
|
72
|
+
return
|
73
|
+
end
|
70
74
|
if msig.lead_tys.size + msig.post_tys.size < lead_num + post_num
|
71
75
|
scratch.error(ep, "RBS says that the arity may be %d, but the method definition requires at least %d arguments" % [msig.lead_tys.size + msig.post_tys.size, lead_num + post_num])
|
72
76
|
return
|
@@ -79,7 +83,6 @@ module TypeProf
|
|
79
83
|
|
80
84
|
lead_num = @iseq.fargs_format[:lead_num] || 0
|
81
85
|
post_start = @iseq.fargs_format[:post_start]
|
82
|
-
rest_start = @iseq.fargs_format[:rest_start]
|
83
86
|
kw_start = @iseq.fargs_format[:kwbits]
|
84
87
|
keyword = @iseq.fargs_format[:keyword]
|
85
88
|
kw_start -= keyword.size if kw_start
|
@@ -175,14 +178,13 @@ module TypeProf
|
|
175
178
|
end
|
176
179
|
|
177
180
|
class AttrMethodDef < MethodDef
|
178
|
-
def initialize(ivar, kind, pub_meth
|
181
|
+
def initialize(ivar, kind, pub_meth)
|
179
182
|
@ivar = ivar
|
180
183
|
@kind = kind # :reader | :writer
|
181
184
|
@pub_meth = pub_meth
|
182
|
-
@def_ep = def_ep
|
183
185
|
end
|
184
186
|
|
185
|
-
attr_reader :ivar, :kind
|
187
|
+
attr_reader :ivar, :kind
|
186
188
|
|
187
189
|
def do_send(recv, mid, aargs, caller_ep, caller_env, scratch, &ctn)
|
188
190
|
case @kind
|
@@ -206,6 +208,25 @@ module TypeProf
|
|
206
208
|
end
|
207
209
|
end
|
208
210
|
|
211
|
+
class ExecutedAttrMethodDef < AttrMethodDef
|
212
|
+
def initialize(ivar, kind, pub_meth, def_ep)
|
213
|
+
super(ivar, kind, pub_meth)
|
214
|
+
@def_ep = def_ep
|
215
|
+
end
|
216
|
+
|
217
|
+
attr_reader :def_ep
|
218
|
+
end
|
219
|
+
|
220
|
+
class TypedAttrMethodDef < AttrMethodDef
|
221
|
+
def initialize(ivar, kind, pub_meth, rbs_source)
|
222
|
+
@rbs_source = rbs_source
|
223
|
+
|
224
|
+
super(ivar, kind, pub_meth)
|
225
|
+
end
|
226
|
+
|
227
|
+
attr_reader :rbs_source
|
228
|
+
end
|
229
|
+
|
209
230
|
class TypedMethodDef < MethodDef
|
210
231
|
def initialize(sig_rets, rbs_source, pub_meth) # sig_rets: Array<[MethodSignature, (return)Type]>
|
211
232
|
@sig_rets = sig_rets
|
data/lib/typeprof/type.rb
CHANGED
@@ -422,22 +422,22 @@ module TypeProf
|
|
422
422
|
end
|
423
423
|
|
424
424
|
def self.any
|
425
|
-
|
425
|
+
Thread.current[:any] ||= Any.new
|
426
426
|
end
|
427
427
|
|
428
428
|
def self.bot
|
429
|
-
|
429
|
+
Thread.current[:bot] ||= Union.new(Utils::Set[], nil)
|
430
430
|
end
|
431
431
|
|
432
432
|
def self.bool
|
433
|
-
|
433
|
+
Thread.current[:bool] ||= Union.new(Utils::Set[
|
434
434
|
Instance.new(Type::Builtin[:true]),
|
435
435
|
Instance.new(Type::Builtin[:false])
|
436
436
|
], nil)
|
437
437
|
end
|
438
438
|
|
439
439
|
def self.nil
|
440
|
-
|
440
|
+
Thread.current[:nil] ||= Instance.new(Type::Builtin[:nil])
|
441
441
|
end
|
442
442
|
|
443
443
|
def self.optional(ty)
|
data/lib/typeprof/version.rb
CHANGED
data/typeprof.gemspec
CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
26
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|smoke|testbed)/}) }
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(doc|test|spec|features|smoke|testbed)/}) }
|
28
28
|
end
|
29
29
|
spec.bindir = "exe"
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_runtime_dependency "rbs", ">= 1.
|
33
|
+
spec.add_runtime_dependency "rbs", ">= 1.8.1"
|
34
34
|
end
|