typeprof 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/doc/doc.ja.md +5 -0
- data/doc/doc.md +9 -5
- data/lib/typeprof/analyzer.rb +97 -69
- data/lib/typeprof/builtin.rb +96 -92
- data/lib/typeprof/cli.rb +42 -4
- data/lib/typeprof/export.rb +36 -20
- data/lib/typeprof/import.rb +406 -365
- data/lib/typeprof/iseq.rb +1 -1
- data/lib/typeprof/method.rb +34 -33
- data/lib/typeprof/type.rb +1 -4
- data/run.sh +1 -1
- data/smoke/block13.rb +9 -0
- data/smoke/block13.rbs +3 -0
- data/smoke/class.rb +2 -0
- data/smoke/constant1.rb +3 -0
- data/smoke/demo5.rb +3 -0
- data/smoke/gvar.rb +1 -1
- data/smoke/gvar2.rb +17 -0
- data/smoke/gvar2.rbs +1 -0
- data/smoke/inheritance2.rb +6 -0
- data/smoke/ivar3.rb +16 -0
- data/smoke/ivar3.rbs +3 -0
- data/smoke/manual-rbs2.rb +1 -1
- data/smoke/manual-rbs3.rb +12 -0
- data/smoke/manual-rbs3.rbs +3 -0
- data/smoke/module4.rb +3 -0
- data/smoke/multiple-superclass.rb +8 -0
- data/smoke/rbs-alias.rb +9 -0
- data/smoke/rbs-alias.rbs +4 -0
- data/smoke/rbs-attr.rb +26 -0
- data/smoke/rbs-attr.rbs +5 -0
- data/smoke/rbs-vars.rb +39 -0
- data/smoke/rbs-vars.rbs +7 -0
- data/smoke/struct.rb +3 -0
- data/smoke/super1.rb +18 -0
- data/smoke/union-recv.rb +6 -0
- data/tools/setup-insns-def.rb +1 -1
- data/tools/stackprof-wrapper.rb +1 -1
- data/typeprof.gemspec +10 -4
- metadata +26 -7
data/lib/typeprof/iseq.rb
CHANGED
@@ -125,7 +125,7 @@ module TypeProf
|
|
125
125
|
"#{ @path }:#{ @linenos[pc] }"
|
126
126
|
end
|
127
127
|
|
128
|
-
attr_reader :name, :path, :
|
128
|
+
attr_reader :name, :path, :absolute_path, :start_lineno, :type, :locals, :fargs_format, :catch_table, :insns, :linenos
|
129
129
|
attr_reader :id
|
130
130
|
|
131
131
|
def pretty_print(q)
|
data/lib/typeprof/method.rb
CHANGED
@@ -38,7 +38,7 @@ module TypeProf
|
|
38
38
|
|
39
39
|
# XXX: need to check .rbs fargs and .rb fargs
|
40
40
|
|
41
|
-
ctx = Context.new(@iseq, @cref, mid)
|
41
|
+
ctx = Context.new(@iseq, @cref, mid)
|
42
42
|
callee_ep = ExecutionPoint.new(ctx, start_pc, nil)
|
43
43
|
|
44
44
|
locals = [Type.nil] * @iseq.locals.size
|
@@ -110,12 +110,13 @@ module TypeProf
|
|
110
110
|
end
|
111
111
|
|
112
112
|
class AttrMethodDef < MethodDef
|
113
|
-
def initialize(ivar, kind)
|
113
|
+
def initialize(ivar, kind, absolute_path)
|
114
114
|
@ivar = ivar
|
115
115
|
@kind = kind # :reader | :writer
|
116
|
+
@absolute_path = absolute_path
|
116
117
|
end
|
117
118
|
|
118
|
-
attr_reader :ivar, :kind
|
119
|
+
attr_reader :ivar, :kind, :absolute_path
|
119
120
|
|
120
121
|
def do_send(recv, mid, aargs, caller_ep, caller_env, scratch, &ctn)
|
121
122
|
case @kind
|
@@ -153,7 +154,6 @@ module TypeProf
|
|
153
154
|
aargs = scratch.globalize_type(aargs, caller_env, caller_ep)
|
154
155
|
@sigs.each do |fargs, ret_ty|
|
155
156
|
ncaller_env = caller_env
|
156
|
-
# XXX: need to interpret args more correctly
|
157
157
|
#pp [mid, aargs, fargs]
|
158
158
|
# XXX: support self type in fargs
|
159
159
|
subst = { Type::Var.new(:self) => recv }
|
@@ -187,46 +187,48 @@ module TypeProf
|
|
187
187
|
scratch.add_callsite!(dummy_ctx, nil, caller_ep, ncaller_env, &ctn)
|
188
188
|
nfargs = fargs.blk_ty.fargs
|
189
189
|
alloc_site = AllocationSite.new(caller_ep).add_id(self)
|
190
|
-
|
190
|
+
nlead_tys = (nfargs.lead_tys + nfargs.opt_tys).map.with_index do |ty, i|
|
191
191
|
if recv.is_a?(Type::Array)
|
192
192
|
tyvar_elem = Type::Var.new(:Elem)
|
193
|
-
|
193
|
+
ty = ty.substitute(subst.merge({ tyvar_elem => recv.elems.squash }), Config.options[:type_depth_limit])
|
194
194
|
else
|
195
|
-
|
195
|
+
ty = ty.substitute(subst, Config.options[:type_depth_limit])
|
196
196
|
end
|
197
|
-
|
197
|
+
ty = ty.remove_type_vars
|
198
198
|
alloc_site2 = alloc_site.add_id(i)
|
199
|
-
dummy_env,
|
200
|
-
|
199
|
+
dummy_env, ty = scratch.localize_type(ty, dummy_env, dummy_ep, alloc_site2)
|
200
|
+
ty
|
201
201
|
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
if
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
202
|
+
0.upto(nfargs.opt_tys.size) do |n|
|
203
|
+
naargs = ActualArguments.new(nlead_tys[0, nfargs.lead_tys.size + n], nil, nil, Type.nil) # XXX: support block to block?
|
204
|
+
scratch.do_invoke_block(false, aargs.blk_ty, naargs, dummy_ep, dummy_env) do |blk_ret_ty, _ep, _env|
|
205
|
+
subst2 = {}
|
206
|
+
if blk_ret_ty.consistent?(fargs.blk_ty.ret_ty, subst2)
|
207
|
+
if recv.is_a?(Type::Array) && recv_orig.is_a?(Type::LocalArray)
|
208
|
+
tyvar_elem = Type::Var.new(:Elem)
|
209
|
+
if subst2[tyvar_elem]
|
210
|
+
ncaller_env = scratch.update_container_elem_types(ncaller_env, caller_ep, recv_orig.id) do |elems|
|
211
|
+
elems.update(nil, subst2[tyvar_elem])
|
212
|
+
end
|
213
|
+
scratch.merge_return_env(caller_ep) {|env| env ? env.merge(ncaller_env) : ncaller_env }
|
211
214
|
end
|
212
|
-
|
215
|
+
ret_ty = ret_ty.substitute(subst2, Config.options[:type_depth_limit])
|
216
|
+
else
|
217
|
+
ret_ty = ret_ty.substitute(subst2, Config.options[:type_depth_limit])
|
213
218
|
end
|
214
|
-
ret_ty = ret_ty.substitute(subst2, Config.options[:type_depth_limit])
|
215
219
|
else
|
216
|
-
|
220
|
+
# raise "???"
|
221
|
+
# XXX: need warning
|
222
|
+
ret_ty = Type.any
|
217
223
|
end
|
218
|
-
|
219
|
-
#
|
220
|
-
#
|
221
|
-
ret_ty
|
224
|
+
ret_ty = ret_ty.remove_type_vars
|
225
|
+
# XXX: check the return type from the block
|
226
|
+
# sig.blk_ty.ret_ty.eql?(_ret_ty) ???
|
227
|
+
scratch.add_return_type!(dummy_ctx, ret_ty)
|
222
228
|
end
|
223
|
-
|
224
|
-
#
|
225
|
-
# sig.blk_ty.ret_ty.eql?(_ret_ty) ???
|
226
|
-
scratch.add_return_type!(dummy_ctx, ret_ty)
|
229
|
+
# scratch.add_return_type!(dummy_ctx, ret_ty) ?
|
230
|
+
# This makes `def foo; 1.times { return "str" }; end` return Integer|String
|
227
231
|
end
|
228
|
-
# scratch.add_return_type!(dummy_ctx, ret_ty) ?
|
229
|
-
# This makes `def foo; 1.times { return "str" }; end` return Integer|String
|
230
232
|
else
|
231
233
|
# XXX: a block is passed to a method that does not accept block.
|
232
234
|
# Should we call the passed block with any arguments?
|
@@ -259,7 +261,6 @@ module TypeProf
|
|
259
261
|
end
|
260
262
|
|
261
263
|
def do_send(recv, mid, aargs, caller_ep, caller_env, scratch, &ctn)
|
262
|
-
# XXX: ctn?
|
263
264
|
scratch.merge_return_env(caller_ep) {|env| env ? env.merge(caller_env) : caller_env } # for Kernel#lambda
|
264
265
|
@impl[recv, mid, aargs, caller_ep, caller_env, scratch, &ctn]
|
265
266
|
end
|
data/lib/typeprof/type.rb
CHANGED
@@ -533,8 +533,6 @@ module TypeProf
|
|
533
533
|
|
534
534
|
class TypedProc < Type
|
535
535
|
def initialize(fargs, ret_ty, type)
|
536
|
-
# XXX: need to receive blk_ty?
|
537
|
-
# XXX: may refactor "arguments = arg_tys * blk_ty" out
|
538
536
|
@fargs = fargs
|
539
537
|
@ret_ty = ret_ty
|
540
538
|
@type = type
|
@@ -639,10 +637,9 @@ module TypeProf
|
|
639
637
|
end
|
640
638
|
end
|
641
639
|
|
642
|
-
def self.gen_hash
|
640
|
+
def self.gen_hash(base_ty = Type::Instance.new(Type::Builtin[:hash]))
|
643
641
|
hg = HashGenerator.new
|
644
642
|
yield hg
|
645
|
-
base_ty = Type::Instance.new(Type::Builtin[:hash])
|
646
643
|
Type::Hash.new(Type::Hash::Elements.new(hg.map_tys), base_ty)
|
647
644
|
end
|
648
645
|
|
data/run.sh
CHANGED
data/smoke/block13.rb
ADDED
data/smoke/block13.rbs
ADDED
data/smoke/class.rb
CHANGED
data/smoke/constant1.rb
CHANGED
data/smoke/demo5.rb
CHANGED
data/smoke/gvar.rb
CHANGED
data/smoke/gvar2.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$foo = 1
|
2
|
+
|
3
|
+
def log
|
4
|
+
$foo
|
5
|
+
end
|
6
|
+
|
7
|
+
__END__
|
8
|
+
# Errors
|
9
|
+
smoke/gvar2.rb:1: [warning] inconsistent assignment to RBS-declared global variable
|
10
|
+
|
11
|
+
# Global variables
|
12
|
+
#$foo : String
|
13
|
+
|
14
|
+
# Classes
|
15
|
+
class Object
|
16
|
+
def log : -> String
|
17
|
+
end
|
data/smoke/gvar2.rbs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$foo : String
|
data/smoke/inheritance2.rb
CHANGED
data/smoke/ivar3.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Foo
|
2
|
+
def initialize
|
3
|
+
@foo = "str"
|
4
|
+
@bar = "str"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
__END__
|
9
|
+
# Errors
|
10
|
+
smoke/ivar3.rb:3: [warning] inconsistent assignment to RBS-declared global variable
|
11
|
+
|
12
|
+
# Classes
|
13
|
+
class Foo
|
14
|
+
@bar : String
|
15
|
+
def initialize : -> String
|
16
|
+
end
|
data/smoke/ivar3.rbs
ADDED
data/smoke/manual-rbs2.rb
CHANGED
data/smoke/module4.rb
CHANGED
data/smoke/rbs-alias.rb
ADDED
data/smoke/rbs-alias.rbs
ADDED
data/smoke/rbs-attr.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
def read_test_1
|
2
|
+
Foo.new.reader_example
|
3
|
+
end
|
4
|
+
|
5
|
+
def read_test_2
|
6
|
+
Foo.new.accessor_example
|
7
|
+
end
|
8
|
+
|
9
|
+
def write_test
|
10
|
+
Foo.new.writer_example = 1
|
11
|
+
Foo.new.writer_example = "str"
|
12
|
+
Foo.new.accessor_example = 1
|
13
|
+
Foo.new.accessor_example = "str"
|
14
|
+
end
|
15
|
+
|
16
|
+
__END__
|
17
|
+
# Errors
|
18
|
+
smoke/rbs-attr.rb:11: [error] failed to resolve overload: Foo#writer_example=
|
19
|
+
smoke/rbs-attr.rb:13: [error] failed to resolve overload: Foo#accessor_example=
|
20
|
+
|
21
|
+
# Classes
|
22
|
+
class Object
|
23
|
+
def read_test_1 : -> Integer
|
24
|
+
def read_test_2 : -> Integer
|
25
|
+
def write_test : -> String
|
26
|
+
end
|
data/smoke/rbs-attr.rbs
ADDED
data/smoke/rbs-vars.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
def gvar_test
|
2
|
+
$gvar
|
3
|
+
end
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
def const_test
|
7
|
+
CONST
|
8
|
+
end
|
9
|
+
|
10
|
+
def ivar_test
|
11
|
+
@ivar
|
12
|
+
end
|
13
|
+
|
14
|
+
def cvar_test
|
15
|
+
@@cvar
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.cvar_test2
|
19
|
+
@@cvar
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
__END__
|
24
|
+
# Global variables
|
25
|
+
#$gvar : :gvar_example
|
26
|
+
|
27
|
+
# Classes
|
28
|
+
class Object
|
29
|
+
def gvar_test : -> :gvar_example
|
30
|
+
end
|
31
|
+
|
32
|
+
class Foo
|
33
|
+
# @ivar : :ivar_example
|
34
|
+
# @@cvar : :cvar_example
|
35
|
+
def const_test : -> :const_example
|
36
|
+
def ivar_test : -> :ivar_example
|
37
|
+
def cvar_test : -> :cvar_example
|
38
|
+
def self.cvar_test2 : -> :cvar_example
|
39
|
+
end
|
data/smoke/rbs-vars.rbs
ADDED
data/smoke/struct.rb
CHANGED
data/smoke/super1.rb
CHANGED