typeprof 0.1.0

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.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +26 -0
  3. data/.gitignore +7 -0
  4. data/.gitmodules +6 -0
  5. data/Gemfile +12 -0
  6. data/Gemfile.lock +41 -0
  7. data/README.md +53 -0
  8. data/Rakefile +10 -0
  9. data/doc/doc.ja.md +415 -0
  10. data/doc/doc.md +429 -0
  11. data/doc/ppl2019.pdf +0 -0
  12. data/exe/typeprof +5 -0
  13. data/lib/typeprof.rb +13 -0
  14. data/lib/typeprof/analyzer.rb +1911 -0
  15. data/lib/typeprof/builtin.rb +554 -0
  16. data/lib/typeprof/cli.rb +110 -0
  17. data/lib/typeprof/container-type.rb +626 -0
  18. data/lib/typeprof/export.rb +203 -0
  19. data/lib/typeprof/import.rb +546 -0
  20. data/lib/typeprof/insns-def.rb +61 -0
  21. data/lib/typeprof/iseq.rb +387 -0
  22. data/lib/typeprof/method.rb +267 -0
  23. data/lib/typeprof/type.rb +1092 -0
  24. data/lib/typeprof/utils.rb +209 -0
  25. data/run.sh +3 -0
  26. data/smoke/alias.rb +30 -0
  27. data/smoke/alias2.rb +19 -0
  28. data/smoke/any-cbase.rb +5 -0
  29. data/smoke/any1.rb +15 -0
  30. data/smoke/any2.rb +17 -0
  31. data/smoke/arguments.rb +16 -0
  32. data/smoke/array-each.rb +14 -0
  33. data/smoke/array-each2.rb +15 -0
  34. data/smoke/array-each3.rb +15 -0
  35. data/smoke/array-ltlt.rb +13 -0
  36. data/smoke/array-ltlt2.rb +16 -0
  37. data/smoke/array-map.rb +11 -0
  38. data/smoke/array-map2.rb +10 -0
  39. data/smoke/array-map3.rb +22 -0
  40. data/smoke/array-mul.rb +17 -0
  41. data/smoke/array-plus1.rb +10 -0
  42. data/smoke/array-plus2.rb +15 -0
  43. data/smoke/array-pop.rb +11 -0
  44. data/smoke/array-replace.rb +12 -0
  45. data/smoke/array-s-aref.rb +11 -0
  46. data/smoke/array1.rb +26 -0
  47. data/smoke/array10.rb +14 -0
  48. data/smoke/array11.rb +13 -0
  49. data/smoke/array12.rb +24 -0
  50. data/smoke/array13.rb +30 -0
  51. data/smoke/array14.rb +13 -0
  52. data/smoke/array2.rb +27 -0
  53. data/smoke/array3.rb +25 -0
  54. data/smoke/array4.rb +14 -0
  55. data/smoke/array5.rb +13 -0
  56. data/smoke/array6.rb +14 -0
  57. data/smoke/array7.rb +13 -0
  58. data/smoke/array8.rb +13 -0
  59. data/smoke/array9.rb +12 -0
  60. data/smoke/attr.rb +28 -0
  61. data/smoke/backtrace.rb +32 -0
  62. data/smoke/block1.rb +22 -0
  63. data/smoke/block10.rb +14 -0
  64. data/smoke/block11.rb +39 -0
  65. data/smoke/block12.rb +22 -0
  66. data/smoke/block2.rb +14 -0
  67. data/smoke/block3.rb +38 -0
  68. data/smoke/block4.rb +18 -0
  69. data/smoke/block5.rb +18 -0
  70. data/smoke/block6.rb +20 -0
  71. data/smoke/block7.rb +20 -0
  72. data/smoke/block8.rb +27 -0
  73. data/smoke/block9.rb +12 -0
  74. data/smoke/blown.rb +12 -0
  75. data/smoke/break1.rb +18 -0
  76. data/smoke/break2.rb +15 -0
  77. data/smoke/case.rb +16 -0
  78. data/smoke/case2.rb +17 -0
  79. data/smoke/class.rb +5 -0
  80. data/smoke/class_instance_var.rb +9 -0
  81. data/smoke/class_method.rb +25 -0
  82. data/smoke/class_method2.rb +21 -0
  83. data/smoke/class_method3.rb +27 -0
  84. data/smoke/constant1.rb +38 -0
  85. data/smoke/constant2.rb +33 -0
  86. data/smoke/constant3.rb +9 -0
  87. data/smoke/constant4.rb +11 -0
  88. data/smoke/context-sensitive1.rb +12 -0
  89. data/smoke/cvar.rb +28 -0
  90. data/smoke/cvar2.rb +17 -0
  91. data/smoke/demo.rb +80 -0
  92. data/smoke/demo1.rb +16 -0
  93. data/smoke/demo10.rb +20 -0
  94. data/smoke/demo11.rb +11 -0
  95. data/smoke/demo2.rb +14 -0
  96. data/smoke/demo3.rb +16 -0
  97. data/smoke/demo4.rb +27 -0
  98. data/smoke/demo5.rb +13 -0
  99. data/smoke/demo6.rb +21 -0
  100. data/smoke/demo7.rb +14 -0
  101. data/smoke/demo8.rb +18 -0
  102. data/smoke/demo9.rb +18 -0
  103. data/smoke/dummy-execution1.rb +14 -0
  104. data/smoke/dummy-execution2.rb +16 -0
  105. data/smoke/ensure1.rb +20 -0
  106. data/smoke/enumerator.rb +15 -0
  107. data/smoke/expandarray1.rb +22 -0
  108. data/smoke/expandarray2.rb +23 -0
  109. data/smoke/fib.rb +28 -0
  110. data/smoke/flow1.rb +16 -0
  111. data/smoke/flow2.rb +14 -0
  112. data/smoke/flow3.rb +14 -0
  113. data/smoke/flow4.rb +5 -0
  114. data/smoke/flow5.rb +19 -0
  115. data/smoke/flow6.rb +19 -0
  116. data/smoke/flow7.rb +26 -0
  117. data/smoke/for.rb +9 -0
  118. data/smoke/freeze.rb +11 -0
  119. data/smoke/function.rb +16 -0
  120. data/smoke/gvar.rb +13 -0
  121. data/smoke/hash-fetch.rb +27 -0
  122. data/smoke/hash1.rb +18 -0
  123. data/smoke/hash2.rb +12 -0
  124. data/smoke/hash3.rb +13 -0
  125. data/smoke/hash4.rb +10 -0
  126. data/smoke/hash5.rb +14 -0
  127. data/smoke/inheritance.rb +34 -0
  128. data/smoke/inheritance2.rb +29 -0
  129. data/smoke/initialize.rb +26 -0
  130. data/smoke/instance_eval.rb +18 -0
  131. data/smoke/int_times.rb +14 -0
  132. data/smoke/integer.rb +10 -0
  133. data/smoke/ivar.rb +29 -0
  134. data/smoke/ivar2.rb +30 -0
  135. data/smoke/kernel-class.rb +12 -0
  136. data/smoke/keyword1.rb +11 -0
  137. data/smoke/keyword2.rb +11 -0
  138. data/smoke/keyword3.rb +12 -0
  139. data/smoke/keyword4.rb +11 -0
  140. data/smoke/keyword5.rb +15 -0
  141. data/smoke/kwsplat1.rb +42 -0
  142. data/smoke/kwsplat2.rb +12 -0
  143. data/smoke/manual-rbs.rb +27 -0
  144. data/smoke/manual-rbs.rbs +3 -0
  145. data/smoke/manual-rbs2.rb +20 -0
  146. data/smoke/manual-rbs2.rbs +8 -0
  147. data/smoke/masgn1.rb +13 -0
  148. data/smoke/masgn2.rb +17 -0
  149. data/smoke/masgn3.rb +12 -0
  150. data/smoke/method_in_branch.rb +22 -0
  151. data/smoke/module1.rb +29 -0
  152. data/smoke/module2.rb +28 -0
  153. data/smoke/module3.rb +33 -0
  154. data/smoke/module4.rb +29 -0
  155. data/smoke/module_function1.rb +28 -0
  156. data/smoke/module_function2.rb +28 -0
  157. data/smoke/multiple-include.rb +14 -0
  158. data/smoke/multiple-superclass.rb +16 -0
  159. data/smoke/next1.rb +20 -0
  160. data/smoke/next2.rb +16 -0
  161. data/smoke/object-send1.rb +22 -0
  162. data/smoke/once.rb +12 -0
  163. data/smoke/optional1.rb +13 -0
  164. data/smoke/optional2.rb +15 -0
  165. data/smoke/parameterizedd-self.rb +18 -0
  166. data/smoke/pathname1.rb +13 -0
  167. data/smoke/pathname2.rb +13 -0
  168. data/smoke/printf.rb +20 -0
  169. data/smoke/proc.rb +19 -0
  170. data/smoke/proc2.rb +16 -0
  171. data/smoke/proc3.rb +14 -0
  172. data/smoke/proc4.rb +11 -0
  173. data/smoke/range.rb +13 -0
  174. data/smoke/redo1.rb +21 -0
  175. data/smoke/redo2.rb +22 -0
  176. data/smoke/req-keyword.rb +12 -0
  177. data/smoke/rescue1.rb +20 -0
  178. data/smoke/rescue2.rb +22 -0
  179. data/smoke/respond_to.rb +22 -0
  180. data/smoke/rest-farg.rb +10 -0
  181. data/smoke/rest1.rb +25 -0
  182. data/smoke/rest2.rb +30 -0
  183. data/smoke/rest3.rb +36 -0
  184. data/smoke/rest4.rb +18 -0
  185. data/smoke/rest5.rb +10 -0
  186. data/smoke/rest6.rb +11 -0
  187. data/smoke/retry1.rb +20 -0
  188. data/smoke/return.rb +13 -0
  189. data/smoke/reveal.rb +13 -0
  190. data/smoke/singleton_class.rb +8 -0
  191. data/smoke/singleton_method.rb +9 -0
  192. data/smoke/step.rb +17 -0
  193. data/smoke/string-split.rb +11 -0
  194. data/smoke/struct.rb +9 -0
  195. data/smoke/struct2.rb +24 -0
  196. data/smoke/super1.rb +50 -0
  197. data/smoke/super2.rb +16 -0
  198. data/smoke/super3.rb +19 -0
  199. data/smoke/svar1.rb +12 -0
  200. data/smoke/tap1.rb +17 -0
  201. data/smoke/toplevel.rb +12 -0
  202. data/smoke/two-map.rb +17 -0
  203. data/smoke/type_var.rb +10 -0
  204. data/smoke/typed_method.rb +15 -0
  205. data/smoke/union-recv.rb +29 -0
  206. data/smoke/variadic1.rb.notyet +5 -0
  207. data/smoke/wrong-extend.rb +25 -0
  208. data/smoke/wrong-include.rb +26 -0
  209. data/smoke/wrong-rbs.rb +15 -0
  210. data/smoke/wrong-rbs.rbs +7 -0
  211. data/testbed/ao.rb +297 -0
  212. data/testbed/diff-lcs-entrypoint.rb +4 -0
  213. data/testbed/goodcheck-Gemfile.lock +51 -0
  214. data/tools/coverage.rb +14 -0
  215. data/tools/setup-insns-def.rb +30 -0
  216. data/tools/stackprof-wrapper.rb +10 -0
  217. data/typeprof.gemspec +24 -0
  218. metadata +262 -0
@@ -0,0 +1,12 @@
1
+ def foo(a:)
2
+ foo(a: a + 1) if rand < 0.5
3
+ a
4
+ end
5
+
6
+ foo(a:1)
7
+
8
+ __END__
9
+ # Classes
10
+ class Object
11
+ def foo : (a: Integer) -> Integer
12
+ end
@@ -0,0 +1,20 @@
1
+ def foo(x)
2
+ 42
3
+ end
4
+
5
+ def bar
6
+ x = 1
7
+ x = "str"
8
+ x = :sym
9
+ rescue
10
+ foo(x)
11
+ end
12
+
13
+ bar
14
+
15
+ __END__
16
+ # Classes
17
+ class Object
18
+ def foo : ((:sym | Integer | String)?) -> Integer
19
+ def bar : -> (:sym | Integer)
20
+ end
@@ -0,0 +1,22 @@
1
+ def foo(x)
2
+ 42
3
+ end
4
+
5
+ def bar
6
+ begin
7
+ x = 1
8
+ x = "str"
9
+ x = :sym
10
+ rescue
11
+ end
12
+ foo(x)
13
+ end
14
+
15
+ bar
16
+
17
+ __END__
18
+ # Classes
19
+ class Object
20
+ def foo : ((:sym | Integer | String)?) -> Integer
21
+ def bar : -> Integer
22
+ end
@@ -0,0 +1,22 @@
1
+ def foo(n)
2
+ if n.respond_to?(:times)
3
+ n.times {|_| n = :sym }
4
+ elsif n.respond_to?(:+)
5
+ n + "foo"
6
+ else
7
+ n & false
8
+ end
9
+ end
10
+
11
+
12
+ foo(1)
13
+ foo("str")
14
+ foo(true)
15
+
16
+ # no error expected
17
+
18
+ __END__
19
+ # Classes
20
+ class Object
21
+ def foo : (Integer | String | true) -> (Integer | String | bool)
22
+ end
@@ -0,0 +1,10 @@
1
+ def foo
2
+ a = ["", ""]
3
+ "".start_with?("", *a)
4
+ end
5
+
6
+ __END__
7
+ # Classes
8
+ class Object
9
+ def foo : -> bool
10
+ end
@@ -0,0 +1,25 @@
1
+ def foo(a, *r, z)
2
+ r
3
+ end
4
+
5
+ foo(1, 2, "S", 3)
6
+ foo(1, 2, 3)
7
+ foo("a", "b", "c")
8
+ foo(:a, :z)
9
+
10
+ def bar(a, o=1, *r, z)
11
+ r
12
+ end
13
+
14
+ bar("A", "Z")
15
+ bar("A", "B", "Z")
16
+ bar("A", "B", "C", "Z")
17
+ bar("A", "B", "C", "D", "Z")
18
+ bar("A", "B", "C", "D", "E", "Z")
19
+
20
+ __END__
21
+ # Classes
22
+ class Object
23
+ def foo : (:a | Integer | String, *Integer | String, :z | Integer | String) -> (Array[Integer | String])
24
+ def bar : (String, ?String, *String, String) -> Array[String]
25
+ end
@@ -0,0 +1,30 @@
1
+ def foo(a, b, c)
2
+ [a, b, c]
3
+ end
4
+
5
+ a = [1, "S", :s]
6
+ foo(*a)
7
+
8
+ #def bar(a, b, c)
9
+ # [a, b, d]
10
+ #end
11
+ #def baz(a, b, c)
12
+ # [a, b, d]
13
+ #end
14
+ #def qux(a, b, c)
15
+ # [a, b, d]
16
+ #end
17
+ #a = ["S", :s]
18
+ #bar(1, *a)
19
+
20
+ #a = ["S"] + [:s]
21
+ #baz(1, *a)
22
+
23
+ #a = [1, "S"]
24
+ #qux(*a, :s)
25
+
26
+ __END__
27
+ # Classes
28
+ class Object
29
+ def foo : (:s | Integer | String, :s | Integer | String, :s | Integer | String) -> ([:s | Integer | String, :s | Integer | String, :s | Integer | String])
30
+ end
@@ -0,0 +1,36 @@
1
+ string_array = ["str"] + ["str"]
2
+
3
+ def foo(*r)
4
+ end
5
+ foo(*string_array)
6
+
7
+ def bar(*r)
8
+ end
9
+ bar(1, *string_array)
10
+
11
+ def baz(x, *r)
12
+ end
13
+ baz(*string_array)
14
+
15
+ def qux(x, *r)
16
+ end
17
+ qux(1, *string_array)
18
+
19
+ def corge(*r, z)
20
+ end
21
+ corge(1, *string_array)
22
+
23
+ def grault(a, o=1, *r, z)
24
+ end
25
+ grault(*string_array)
26
+
27
+ __END__
28
+ # Classes
29
+ class Object
30
+ def foo : (*String) -> nil
31
+ def bar : (*Integer | String) -> nil
32
+ def baz : (String, *String) -> nil
33
+ def qux : (Integer, *String) -> nil
34
+ def corge : (*Integer | String, Integer | String) -> nil
35
+ def grault : (String, ?String, *String, String) -> nil
36
+ end
@@ -0,0 +1,18 @@
1
+ def foo(*a)
2
+ end
3
+
4
+ a = ["str"] + ["str"]
5
+ foo(1, *a, :s)
6
+
7
+ def bar(x, y, z)
8
+ end
9
+
10
+ a = ["str"] + ["str"]
11
+ bar(1, *a, :s)
12
+
13
+ __END__
14
+ # Classes
15
+ class Object
16
+ def foo : (*:s | Integer | String) -> nil
17
+ def bar : (Integer, :s | String, :s | String) -> nil
18
+ end
@@ -0,0 +1,10 @@
1
+ def foo(*args)
2
+ args
3
+ end
4
+
5
+ foo(42)
6
+ __END__
7
+ # Classes
8
+ class Object
9
+ def foo : (*Integer) -> Array[Integer]
10
+ end
@@ -0,0 +1,11 @@
1
+ def foo(o1=1, *r)
2
+ [r]
3
+ end
4
+
5
+ foo()
6
+ foo("x", "x")
7
+ __END__
8
+ # Classes
9
+ class Object
10
+ def foo : (?String, *String) -> [Array[String]]
11
+ end
@@ -0,0 +1,20 @@
1
+ def bar(x)
2
+ x
3
+ end
4
+
5
+ def foo(x)
6
+ bar(x)
7
+ rescue
8
+ x = "str"
9
+ retry
10
+ 42
11
+ end
12
+
13
+ foo(42)
14
+
15
+ __END__
16
+ # Classes
17
+ class Object
18
+ def bar : (Integer | String) -> (Integer | String)
19
+ def foo : (Integer) -> (Integer | String)
20
+ end
@@ -0,0 +1,13 @@
1
+ def foo
2
+ loop do |_|
3
+ return 42
4
+ end
5
+ nil
6
+ end
7
+
8
+ foo
9
+ __END__
10
+ # Classes
11
+ class Object
12
+ def foo : -> Integer
13
+ end
@@ -0,0 +1,13 @@
1
+ p(1)
2
+ p("str")
3
+ p(:sym)
4
+ p([1, "str", :sym])
5
+
6
+ __END__
7
+ # Revealed types
8
+ # smoke/reveal.rb:1 #=> Integer
9
+ # smoke/reveal.rb:2 #=> String
10
+ # smoke/reveal.rb:3 #=> :sym
11
+ # smoke/reveal.rb:4 #=> [Integer, String, :sym]
12
+
13
+ # Classes
@@ -0,0 +1,8 @@
1
+ class << Object.new
2
+ end
3
+
4
+ __END__
5
+ # Errors
6
+ smoke/singleton_class.rb:1: [warning] A singleton class is open for Object; handled as any
7
+
8
+ # Classes
@@ -0,0 +1,9 @@
1
+ V = Object.new
2
+ def V.foo
3
+ # Currently, this call is ignored because the recv of the call is any
4
+ # We may allow a call whose recv is any to invoke Kernel's methods
5
+ p(1)
6
+ end
7
+
8
+ __END__
9
+ # Classes
@@ -0,0 +1,17 @@
1
+ def log1(x)
2
+ end
3
+ def log2(x)
4
+ end
5
+ def log3(x)
6
+ end
7
+
8
+ log2(1.step(5) {|n| log1(n) })
9
+ log3(1.step(5))
10
+
11
+ __END__
12
+ # Classes
13
+ class Object
14
+ def log1 : (Integer | Numeric) -> nil
15
+ def log2 : (untyped) -> nil
16
+ def log3 : (Enumerator[Integer | Numeric]) -> nil
17
+ end
@@ -0,0 +1,11 @@
1
+ def foo
2
+ "".split("").map {|n| n.to_i }
3
+ end
4
+
5
+ foo
6
+
7
+ __END__
8
+ # Classes
9
+ class Object
10
+ def foo : -> Array[Integer]
11
+ end
@@ -0,0 +1,9 @@
1
+ # tentative
2
+ class Foo < Struct.new(:a)
3
+ end
4
+ Foo.new.a = 1
5
+ __END__
6
+ # Classes
7
+ class (Struct) < Struct
8
+ attr_accessor a() : untyped
9
+ end
@@ -0,0 +1,24 @@
1
+ FooBar = Struct.new(:foo, :bar)
2
+ class FooBar
3
+ def my_foo
4
+ foo
5
+ end
6
+ end
7
+ def gen_foobar
8
+ FooBar.new(1)
9
+ end
10
+ foobar = gen_foobar
11
+ foobar.foo = "str"
12
+ foobar.bar = :sym
13
+
14
+ __END__
15
+ # Classes
16
+ class Object
17
+ def gen_foobar : -> FooBar
18
+ end
19
+
20
+ class FooBar < Struct
21
+ attr_accessor foo() : Integer | String
22
+ attr_accessor bar() : :sym?
23
+ def my_foo : -> (Integer | String)
24
+ end
@@ -0,0 +1,50 @@
1
+ def log(x)
2
+ end
3
+
4
+ class A; end
5
+ class B; end
6
+ class C; end
7
+ class X; end
8
+ class Y; end
9
+ class Z; end
10
+
11
+ class Foo
12
+ def f(x)
13
+ log(self)
14
+ X.new
15
+ end
16
+ end
17
+
18
+ class Bar < Foo
19
+ def f(x)
20
+ super(C.new)
21
+ Y.new
22
+ end
23
+ end
24
+
25
+ class Baz < Bar
26
+ def f(x)
27
+ super(B.new)
28
+ Z.new
29
+ end
30
+ end
31
+
32
+ Baz.new.f(A.new)
33
+
34
+ __END__
35
+ # Classes
36
+ class Object
37
+ def log : (Baz) -> nil
38
+ end
39
+
40
+ class Foo
41
+ def f : (C) -> X
42
+ end
43
+
44
+ class Bar < Foo
45
+ def f : (B) -> Y
46
+ end
47
+
48
+ class Baz < Bar
49
+ def f : (A) -> Z
50
+ end
@@ -0,0 +1,16 @@
1
+ class Foo
2
+ def f
3
+ super
4
+ end
5
+ end
6
+
7
+ Foo.new.f
8
+
9
+ __END__
10
+ # Errors
11
+ smoke/super2.rb:3: [error] no superclass method: Foo#f
12
+
13
+ # Classes
14
+ class Foo
15
+ def f : -> untyped
16
+ end
@@ -0,0 +1,19 @@
1
+ class Foo
2
+ def self.new(a)
3
+ super(a)
4
+ end
5
+
6
+ def initialize(a)
7
+ @a = a
8
+ end
9
+ end
10
+
11
+ Foo.new(1)
12
+
13
+ __END__
14
+ # Classes
15
+ class Foo
16
+ @a : Integer
17
+ def self.new : (Integer) -> Foo
18
+ def initialize : (Integer) -> Integer
19
+ end