typeprof 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +26 -0
- data/.gitignore +7 -0
- data/.gitmodules +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +41 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/doc/doc.ja.md +415 -0
- data/doc/doc.md +429 -0
- data/doc/ppl2019.pdf +0 -0
- data/exe/typeprof +5 -0
- data/lib/typeprof.rb +13 -0
- data/lib/typeprof/analyzer.rb +1911 -0
- data/lib/typeprof/builtin.rb +554 -0
- data/lib/typeprof/cli.rb +110 -0
- data/lib/typeprof/container-type.rb +626 -0
- data/lib/typeprof/export.rb +203 -0
- data/lib/typeprof/import.rb +546 -0
- data/lib/typeprof/insns-def.rb +61 -0
- data/lib/typeprof/iseq.rb +387 -0
- data/lib/typeprof/method.rb +267 -0
- data/lib/typeprof/type.rb +1092 -0
- data/lib/typeprof/utils.rb +209 -0
- data/run.sh +3 -0
- data/smoke/alias.rb +30 -0
- data/smoke/alias2.rb +19 -0
- data/smoke/any-cbase.rb +5 -0
- data/smoke/any1.rb +15 -0
- data/smoke/any2.rb +17 -0
- data/smoke/arguments.rb +16 -0
- data/smoke/array-each.rb +14 -0
- data/smoke/array-each2.rb +15 -0
- data/smoke/array-each3.rb +15 -0
- data/smoke/array-ltlt.rb +13 -0
- data/smoke/array-ltlt2.rb +16 -0
- data/smoke/array-map.rb +11 -0
- data/smoke/array-map2.rb +10 -0
- data/smoke/array-map3.rb +22 -0
- data/smoke/array-mul.rb +17 -0
- data/smoke/array-plus1.rb +10 -0
- data/smoke/array-plus2.rb +15 -0
- data/smoke/array-pop.rb +11 -0
- data/smoke/array-replace.rb +12 -0
- data/smoke/array-s-aref.rb +11 -0
- data/smoke/array1.rb +26 -0
- data/smoke/array10.rb +14 -0
- data/smoke/array11.rb +13 -0
- data/smoke/array12.rb +24 -0
- data/smoke/array13.rb +30 -0
- data/smoke/array14.rb +13 -0
- data/smoke/array2.rb +27 -0
- data/smoke/array3.rb +25 -0
- data/smoke/array4.rb +14 -0
- data/smoke/array5.rb +13 -0
- data/smoke/array6.rb +14 -0
- data/smoke/array7.rb +13 -0
- data/smoke/array8.rb +13 -0
- data/smoke/array9.rb +12 -0
- data/smoke/attr.rb +28 -0
- data/smoke/backtrace.rb +32 -0
- data/smoke/block1.rb +22 -0
- data/smoke/block10.rb +14 -0
- data/smoke/block11.rb +39 -0
- data/smoke/block12.rb +22 -0
- data/smoke/block2.rb +14 -0
- data/smoke/block3.rb +38 -0
- data/smoke/block4.rb +18 -0
- data/smoke/block5.rb +18 -0
- data/smoke/block6.rb +20 -0
- data/smoke/block7.rb +20 -0
- data/smoke/block8.rb +27 -0
- data/smoke/block9.rb +12 -0
- data/smoke/blown.rb +12 -0
- data/smoke/break1.rb +18 -0
- data/smoke/break2.rb +15 -0
- data/smoke/case.rb +16 -0
- data/smoke/case2.rb +17 -0
- data/smoke/class.rb +5 -0
- data/smoke/class_instance_var.rb +9 -0
- data/smoke/class_method.rb +25 -0
- data/smoke/class_method2.rb +21 -0
- data/smoke/class_method3.rb +27 -0
- data/smoke/constant1.rb +38 -0
- data/smoke/constant2.rb +33 -0
- data/smoke/constant3.rb +9 -0
- data/smoke/constant4.rb +11 -0
- data/smoke/context-sensitive1.rb +12 -0
- data/smoke/cvar.rb +28 -0
- data/smoke/cvar2.rb +17 -0
- data/smoke/demo.rb +80 -0
- data/smoke/demo1.rb +16 -0
- data/smoke/demo10.rb +20 -0
- data/smoke/demo11.rb +11 -0
- data/smoke/demo2.rb +14 -0
- data/smoke/demo3.rb +16 -0
- data/smoke/demo4.rb +27 -0
- data/smoke/demo5.rb +13 -0
- data/smoke/demo6.rb +21 -0
- data/smoke/demo7.rb +14 -0
- data/smoke/demo8.rb +18 -0
- data/smoke/demo9.rb +18 -0
- data/smoke/dummy-execution1.rb +14 -0
- data/smoke/dummy-execution2.rb +16 -0
- data/smoke/ensure1.rb +20 -0
- data/smoke/enumerator.rb +15 -0
- data/smoke/expandarray1.rb +22 -0
- data/smoke/expandarray2.rb +23 -0
- data/smoke/fib.rb +28 -0
- data/smoke/flow1.rb +16 -0
- data/smoke/flow2.rb +14 -0
- data/smoke/flow3.rb +14 -0
- data/smoke/flow4.rb +5 -0
- data/smoke/flow5.rb +19 -0
- data/smoke/flow6.rb +19 -0
- data/smoke/flow7.rb +26 -0
- data/smoke/for.rb +9 -0
- data/smoke/freeze.rb +11 -0
- data/smoke/function.rb +16 -0
- data/smoke/gvar.rb +13 -0
- data/smoke/hash-fetch.rb +27 -0
- data/smoke/hash1.rb +18 -0
- data/smoke/hash2.rb +12 -0
- data/smoke/hash3.rb +13 -0
- data/smoke/hash4.rb +10 -0
- data/smoke/hash5.rb +14 -0
- data/smoke/inheritance.rb +34 -0
- data/smoke/inheritance2.rb +29 -0
- data/smoke/initialize.rb +26 -0
- data/smoke/instance_eval.rb +18 -0
- data/smoke/int_times.rb +14 -0
- data/smoke/integer.rb +10 -0
- data/smoke/ivar.rb +29 -0
- data/smoke/ivar2.rb +30 -0
- data/smoke/kernel-class.rb +12 -0
- data/smoke/keyword1.rb +11 -0
- data/smoke/keyword2.rb +11 -0
- data/smoke/keyword3.rb +12 -0
- data/smoke/keyword4.rb +11 -0
- data/smoke/keyword5.rb +15 -0
- data/smoke/kwsplat1.rb +42 -0
- data/smoke/kwsplat2.rb +12 -0
- data/smoke/manual-rbs.rb +27 -0
- data/smoke/manual-rbs.rbs +3 -0
- data/smoke/manual-rbs2.rb +20 -0
- data/smoke/manual-rbs2.rbs +8 -0
- data/smoke/masgn1.rb +13 -0
- data/smoke/masgn2.rb +17 -0
- data/smoke/masgn3.rb +12 -0
- data/smoke/method_in_branch.rb +22 -0
- data/smoke/module1.rb +29 -0
- data/smoke/module2.rb +28 -0
- data/smoke/module3.rb +33 -0
- data/smoke/module4.rb +29 -0
- data/smoke/module_function1.rb +28 -0
- data/smoke/module_function2.rb +28 -0
- data/smoke/multiple-include.rb +14 -0
- data/smoke/multiple-superclass.rb +16 -0
- data/smoke/next1.rb +20 -0
- data/smoke/next2.rb +16 -0
- data/smoke/object-send1.rb +22 -0
- data/smoke/once.rb +12 -0
- data/smoke/optional1.rb +13 -0
- data/smoke/optional2.rb +15 -0
- data/smoke/parameterizedd-self.rb +18 -0
- data/smoke/pathname1.rb +13 -0
- data/smoke/pathname2.rb +13 -0
- data/smoke/printf.rb +20 -0
- data/smoke/proc.rb +19 -0
- data/smoke/proc2.rb +16 -0
- data/smoke/proc3.rb +14 -0
- data/smoke/proc4.rb +11 -0
- data/smoke/range.rb +13 -0
- data/smoke/redo1.rb +21 -0
- data/smoke/redo2.rb +22 -0
- data/smoke/req-keyword.rb +12 -0
- data/smoke/rescue1.rb +20 -0
- data/smoke/rescue2.rb +22 -0
- data/smoke/respond_to.rb +22 -0
- data/smoke/rest-farg.rb +10 -0
- data/smoke/rest1.rb +25 -0
- data/smoke/rest2.rb +30 -0
- data/smoke/rest3.rb +36 -0
- data/smoke/rest4.rb +18 -0
- data/smoke/rest5.rb +10 -0
- data/smoke/rest6.rb +11 -0
- data/smoke/retry1.rb +20 -0
- data/smoke/return.rb +13 -0
- data/smoke/reveal.rb +13 -0
- data/smoke/singleton_class.rb +8 -0
- data/smoke/singleton_method.rb +9 -0
- data/smoke/step.rb +17 -0
- data/smoke/string-split.rb +11 -0
- data/smoke/struct.rb +9 -0
- data/smoke/struct2.rb +24 -0
- data/smoke/super1.rb +50 -0
- data/smoke/super2.rb +16 -0
- data/smoke/super3.rb +19 -0
- data/smoke/svar1.rb +12 -0
- data/smoke/tap1.rb +17 -0
- data/smoke/toplevel.rb +12 -0
- data/smoke/two-map.rb +17 -0
- data/smoke/type_var.rb +10 -0
- data/smoke/typed_method.rb +15 -0
- data/smoke/union-recv.rb +29 -0
- data/smoke/variadic1.rb.notyet +5 -0
- data/smoke/wrong-extend.rb +25 -0
- data/smoke/wrong-include.rb +26 -0
- data/smoke/wrong-rbs.rb +15 -0
- data/smoke/wrong-rbs.rbs +7 -0
- data/testbed/ao.rb +297 -0
- data/testbed/diff-lcs-entrypoint.rb +4 -0
- data/testbed/goodcheck-Gemfile.lock +51 -0
- data/tools/coverage.rb +14 -0
- data/tools/setup-insns-def.rb +30 -0
- data/tools/stackprof-wrapper.rb +10 -0
- data/typeprof.gemspec +24 -0
- metadata +262 -0
data/smoke/enumerator.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
def foo
|
2
|
+
if rand < 0.5
|
3
|
+
unknown
|
4
|
+
else
|
5
|
+
[:a, [:b, :c]]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
a, (b, c) = foo
|
10
|
+
|
11
|
+
p(a)
|
12
|
+
__END__
|
13
|
+
# Errors
|
14
|
+
smoke/expandarray1.rb:3: [error] undefined method: Object#unknown
|
15
|
+
|
16
|
+
# Revealed types
|
17
|
+
# smoke/expandarray1.rb:11 #=> :a | untyped
|
18
|
+
|
19
|
+
# Classes
|
20
|
+
class Object
|
21
|
+
def foo : -> ([:a, [:b, :c]] | untyped)
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
def foo
|
2
|
+
if rand < 0.5
|
3
|
+
unknown
|
4
|
+
else
|
5
|
+
[:a, [:b, :c]]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
a, *bc = foo
|
10
|
+
|
11
|
+
p(a)
|
12
|
+
|
13
|
+
__END__
|
14
|
+
# Errors
|
15
|
+
smoke/expandarray2.rb:3: [error] undefined method: Object#unknown
|
16
|
+
|
17
|
+
# Revealed types
|
18
|
+
# smoke/expandarray2.rb:11 #=> :a | untyped
|
19
|
+
|
20
|
+
# Classes
|
21
|
+
class Object
|
22
|
+
def foo : -> ([:a, [:b, :c]] | untyped)
|
23
|
+
end
|
data/smoke/fib.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Fib
|
2
|
+
def fib_loop(x)
|
3
|
+
a, b = 0, 1
|
4
|
+
while x > 0
|
5
|
+
a, b = b, a+b
|
6
|
+
x -= 1
|
7
|
+
end
|
8
|
+
a
|
9
|
+
end
|
10
|
+
|
11
|
+
def fib_rec(x)
|
12
|
+
if x <= 1
|
13
|
+
x
|
14
|
+
else
|
15
|
+
fib_rec(x-1) + fib_rec(x-2)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Fib.new.fib_loop(42)
|
21
|
+
Fib.new.fib_rec(42)
|
22
|
+
|
23
|
+
__END__
|
24
|
+
# Classes
|
25
|
+
class Fib
|
26
|
+
def fib_loop : (Integer) -> Integer
|
27
|
+
def fib_rec : (Integer) -> Integer
|
28
|
+
end
|
data/smoke/flow1.rb
ADDED
data/smoke/flow2.rb
ADDED
data/smoke/flow3.rb
ADDED
data/smoke/flow4.rb
ADDED
data/smoke/flow5.rb
ADDED
data/smoke/flow6.rb
ADDED
data/smoke/flow7.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
def foo(n)
|
2
|
+
case n
|
3
|
+
when Integer
|
4
|
+
n + 1
|
5
|
+
when String
|
6
|
+
n + "STR"
|
7
|
+
else
|
8
|
+
n
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
foo(42)
|
13
|
+
foo("str")
|
14
|
+
foo(:sym)
|
15
|
+
|
16
|
+
__END__
|
17
|
+
# Errors
|
18
|
+
smoke/flow7.rb:4: [error] failed to resolve overload: String#+
|
19
|
+
smoke/flow7.rb:4: [error] undefined method: :sym#+
|
20
|
+
smoke/flow7.rb:6: [error] failed to resolve overload: Integer#+
|
21
|
+
smoke/flow7.rb:6: [error] undefined method: :sym#+
|
22
|
+
|
23
|
+
# Classes
|
24
|
+
class Object
|
25
|
+
def foo : (:sym | Integer | String) -> (:sym | Integer | String | untyped)
|
26
|
+
end
|
data/smoke/for.rb
ADDED
data/smoke/freeze.rb
ADDED
data/smoke/function.rb
ADDED
data/smoke/gvar.rb
ADDED
data/smoke/hash-fetch.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
h = { a: :A, b: :B }
|
2
|
+
|
3
|
+
def foo(h)
|
4
|
+
h.fetch(:a) #=> :A | :B
|
5
|
+
end
|
6
|
+
def bar(h)
|
7
|
+
h.fetch(:a, :C) #=> :A | :B | :C
|
8
|
+
end
|
9
|
+
def baz(h)
|
10
|
+
n = nil
|
11
|
+
[h.fetch(:a) do |k| #=> :A | :B | :C
|
12
|
+
n = k #=> :A | :B
|
13
|
+
:C
|
14
|
+
end, n]
|
15
|
+
end
|
16
|
+
|
17
|
+
foo(h)
|
18
|
+
bar(h)
|
19
|
+
baz(h)
|
20
|
+
|
21
|
+
__END__
|
22
|
+
# Classes
|
23
|
+
class Object
|
24
|
+
def foo : ({:a=>:A, :b=>:B}) -> (:A | :B)
|
25
|
+
def bar : ({:a=>:A, :b=>:B}) -> (:A | :B | :C)
|
26
|
+
def baz : ({:a=>:A, :b=>:B}) -> ([:A | :B | :C, (:a | :b)?])
|
27
|
+
end
|
data/smoke/hash1.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
def foo
|
2
|
+
{ int: 1, str: "str" }
|
3
|
+
end
|
4
|
+
|
5
|
+
foo
|
6
|
+
|
7
|
+
def bar
|
8
|
+
{ 1 => 1, 2 => "str", "s" => "s" }
|
9
|
+
end
|
10
|
+
|
11
|
+
bar
|
12
|
+
|
13
|
+
__END__
|
14
|
+
# Classes
|
15
|
+
class Object
|
16
|
+
def foo : -> {:int=>Integer, :str=>String}
|
17
|
+
def bar : -> ({Integer=>Integer | String, String=>String})
|
18
|
+
end
|
data/smoke/hash2.rb
ADDED
data/smoke/hash3.rb
ADDED
data/smoke/hash4.rb
ADDED
data/smoke/hash5.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class A
|
2
|
+
def foo(x)
|
3
|
+
bar(x)
|
4
|
+
end
|
5
|
+
|
6
|
+
def bar(x)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.test(x)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class B < A
|
14
|
+
def bar(x)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
A.new.foo(1)
|
19
|
+
B.new.foo("str")
|
20
|
+
B.new.bar(nil)
|
21
|
+
A.test(1)
|
22
|
+
B.test("str")
|
23
|
+
|
24
|
+
__END__
|
25
|
+
# Classes
|
26
|
+
class A
|
27
|
+
def foo : (Integer | String) -> nil
|
28
|
+
def bar : (Integer | String) -> nil
|
29
|
+
def self.test : (Integer | String) -> nil
|
30
|
+
end
|
31
|
+
|
32
|
+
class B < A
|
33
|
+
def bar : ((Integer | String)?) -> nil
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class SuperBase
|
2
|
+
def self.foo
|
3
|
+
self
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Base < SuperBase
|
8
|
+
def self.foo
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class A < Base
|
14
|
+
foo
|
15
|
+
end
|
16
|
+
|
17
|
+
class B < Base
|
18
|
+
foo
|
19
|
+
end
|
20
|
+
|
21
|
+
__END__
|
22
|
+
# Classes
|
23
|
+
class SuperBase
|
24
|
+
def self.foo : -> (A.class | B.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
class Base < SuperBase
|
28
|
+
def self.foo : -> (A.class | B.class)
|
29
|
+
end
|