typeprof 0.15.3 → 0.20.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (366) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +1 -1
  3. data/Gemfile.lock +5 -5
  4. data/doc/ide.md +81 -0
  5. data/doc/typeprof-for-ide-log.png +0 -0
  6. data/doc/typeprof-for-ide.png +0 -0
  7. data/exe/typeprof +5 -1
  8. data/lib/typeprof/analyzer.rb +235 -56
  9. data/lib/typeprof/arguments.rb +1 -0
  10. data/lib/typeprof/builtin.rb +23 -23
  11. data/lib/typeprof/cli.rb +23 -5
  12. data/lib/typeprof/code-range.rb +177 -0
  13. data/lib/typeprof/config.rb +41 -20
  14. data/lib/typeprof/container-type.rb +3 -0
  15. data/lib/typeprof/export.rb +191 -15
  16. data/lib/typeprof/import.rb +33 -9
  17. data/lib/typeprof/insns-def.rb +1 -0
  18. data/lib/typeprof/iseq.rb +224 -17
  19. data/lib/typeprof/lsp.rb +884 -0
  20. data/lib/typeprof/method.rb +15 -11
  21. data/lib/typeprof/type.rb +50 -42
  22. data/lib/typeprof/utils.rb +18 -1
  23. data/lib/typeprof/version.rb +1 -1
  24. data/lib/typeprof.rb +3 -5
  25. data/typeprof-lsp +3 -0
  26. data/typeprof.gemspec +2 -2
  27. data/vscode/.gitignore +5 -0
  28. data/vscode/.vscode/launch.json +16 -0
  29. data/vscode/.vscodeignore +7 -0
  30. data/vscode/README.md +22 -0
  31. data/vscode/development.md +31 -0
  32. data/vscode/package-lock.json +3249 -0
  33. data/vscode/package.json +71 -0
  34. data/vscode/sandbox/test.rb +24 -0
  35. data/vscode/src/extension.ts +299 -0
  36. data/vscode/tsconfig.json +15 -0
  37. metadata +21 -334
  38. data/smoke/alias.rb +0 -31
  39. data/smoke/alias2.rb +0 -21
  40. data/smoke/any-cbase.rb +0 -5
  41. data/smoke/any1.rb +0 -16
  42. data/smoke/any2.rb +0 -18
  43. data/smoke/arguments.rb +0 -17
  44. data/smoke/arguments2.rb +0 -56
  45. data/smoke/array-each.rb +0 -15
  46. data/smoke/array-each2.rb +0 -16
  47. data/smoke/array-each3.rb +0 -13
  48. data/smoke/array-ltlt.rb +0 -14
  49. data/smoke/array-ltlt2.rb +0 -17
  50. data/smoke/array-map.rb +0 -12
  51. data/smoke/array-map2.rb +0 -11
  52. data/smoke/array-map3.rb +0 -23
  53. data/smoke/array-mul.rb +0 -18
  54. data/smoke/array-plus1.rb +0 -11
  55. data/smoke/array-plus2.rb +0 -16
  56. data/smoke/array-pop.rb +0 -12
  57. data/smoke/array-range-aref.rb +0 -71
  58. data/smoke/array-replace.rb +0 -13
  59. data/smoke/array-s-aref.rb +0 -12
  60. data/smoke/array1.rb +0 -27
  61. data/smoke/array10.rb +0 -15
  62. data/smoke/array11.rb +0 -14
  63. data/smoke/array12.rb +0 -25
  64. data/smoke/array13.rb +0 -31
  65. data/smoke/array14.rb +0 -14
  66. data/smoke/array15.rb +0 -16
  67. data/smoke/array2.rb +0 -28
  68. data/smoke/array3.rb +0 -26
  69. data/smoke/array4.rb +0 -15
  70. data/smoke/array5.rb +0 -14
  71. data/smoke/array6.rb +0 -17
  72. data/smoke/array7.rb +0 -14
  73. data/smoke/array8.rb +0 -13
  74. data/smoke/array9.rb +0 -13
  75. data/smoke/attr-module.rb +0 -24
  76. data/smoke/attr-vis.rb +0 -43
  77. data/smoke/attr-vis.rbs +0 -4
  78. data/smoke/attr.rb +0 -28
  79. data/smoke/autoload.rb +0 -14
  80. data/smoke/backtrace.rb +0 -33
  81. data/smoke/block-ambiguous.rb +0 -37
  82. data/smoke/block-args1-rest.rb +0 -64
  83. data/smoke/block-args1.rb +0 -60
  84. data/smoke/block-args2-rest.rb +0 -64
  85. data/smoke/block-args2.rb +0 -60
  86. data/smoke/block-args3-rest.rb +0 -75
  87. data/smoke/block-args3.rb +0 -71
  88. data/smoke/block-blockarg.rb +0 -28
  89. data/smoke/block-kwarg.rb +0 -53
  90. data/smoke/block1.rb +0 -23
  91. data/smoke/block10.rb +0 -15
  92. data/smoke/block11.rb +0 -40
  93. data/smoke/block12.rb +0 -23
  94. data/smoke/block13.rb +0 -9
  95. data/smoke/block13.rbs +0 -3
  96. data/smoke/block14.rb +0 -18
  97. data/smoke/block2.rb +0 -15
  98. data/smoke/block3.rb +0 -38
  99. data/smoke/block4.rb +0 -19
  100. data/smoke/block5.rb +0 -21
  101. data/smoke/block6.rb +0 -21
  102. data/smoke/block7.rb +0 -19
  103. data/smoke/block8.rb +0 -28
  104. data/smoke/block9.rb +0 -13
  105. data/smoke/block_given.rb +0 -37
  106. data/smoke/blown.rb +0 -13
  107. data/smoke/break1.rb +0 -19
  108. data/smoke/break2.rb +0 -16
  109. data/smoke/break3.rb +0 -13
  110. data/smoke/break4.rb +0 -17
  111. data/smoke/case.rb +0 -17
  112. data/smoke/case2.rb +0 -18
  113. data/smoke/case3.rb +0 -17
  114. data/smoke/class-hierarchy.rb +0 -54
  115. data/smoke/class-hierarchy2.rb +0 -27
  116. data/smoke/class-new.rb +0 -15
  117. data/smoke/class.rb +0 -7
  118. data/smoke/class_eval.rb +0 -22
  119. data/smoke/class_instance_var.rb +0 -9
  120. data/smoke/class_method.rb +0 -25
  121. data/smoke/class_method2.rb +0 -21
  122. data/smoke/class_method3.rb +0 -29
  123. data/smoke/constant1.rb +0 -46
  124. data/smoke/constant2.rb +0 -36
  125. data/smoke/constant3.rb +0 -10
  126. data/smoke/constant4.rb +0 -12
  127. data/smoke/context-sensitive1.rb +0 -13
  128. data/smoke/cvar.rb +0 -31
  129. data/smoke/cvar2.rb +0 -17
  130. data/smoke/define_method.rb +0 -16
  131. data/smoke/define_method2.rb +0 -18
  132. data/smoke/define_method3.rb +0 -14
  133. data/smoke/define_method3.rbs +0 -3
  134. data/smoke/define_method4.rb +0 -15
  135. data/smoke/define_method4.rbs +0 -3
  136. data/smoke/define_method5.rb +0 -12
  137. data/smoke/define_method6.rb +0 -19
  138. data/smoke/define_method7.rb +0 -18
  139. data/smoke/demo.rb +0 -81
  140. data/smoke/demo1.rb +0 -17
  141. data/smoke/demo10.rb +0 -21
  142. data/smoke/demo11.rb +0 -12
  143. data/smoke/demo2.rb +0 -15
  144. data/smoke/demo3.rb +0 -17
  145. data/smoke/demo4.rb +0 -27
  146. data/smoke/demo5.rb +0 -16
  147. data/smoke/demo6.rb +0 -22
  148. data/smoke/demo7.rb +0 -15
  149. data/smoke/demo8.rb +0 -19
  150. data/smoke/demo9.rb +0 -18
  151. data/smoke/dummy-execution1.rb +0 -15
  152. data/smoke/dummy-execution2.rb +0 -16
  153. data/smoke/dummy_element.rb +0 -14
  154. data/smoke/ensure1.rb +0 -21
  155. data/smoke/enum_for.rb +0 -15
  156. data/smoke/enum_for2.rb +0 -17
  157. data/smoke/enumerator.rb +0 -16
  158. data/smoke/expandarray1.rb +0 -23
  159. data/smoke/expandarray2.rb +0 -24
  160. data/smoke/extended.rb +0 -38
  161. data/smoke/fib.rb +0 -28
  162. data/smoke/flip-flop.rb +0 -28
  163. data/smoke/flow1.rb +0 -17
  164. data/smoke/flow10.rb +0 -17
  165. data/smoke/flow11.rb +0 -17
  166. data/smoke/flow2.rb +0 -15
  167. data/smoke/flow3.rb +0 -15
  168. data/smoke/flow4.rb +0 -5
  169. data/smoke/flow5.rb +0 -20
  170. data/smoke/flow6.rb +0 -20
  171. data/smoke/flow7.rb +0 -21
  172. data/smoke/flow8.rb +0 -14
  173. data/smoke/flow9.rb +0 -12
  174. data/smoke/for.rb +0 -9
  175. data/smoke/freeze.rb +0 -12
  176. data/smoke/function.rb +0 -17
  177. data/smoke/gvar.rb +0 -14
  178. data/smoke/gvar2.rb +0 -15
  179. data/smoke/gvar2.rbs +0 -1
  180. data/smoke/hash-bot.rb +0 -12
  181. data/smoke/hash-fetch.rb +0 -28
  182. data/smoke/hash-merge-bang.rb +0 -12
  183. data/smoke/hash1.rb +0 -20
  184. data/smoke/hash2.rb +0 -13
  185. data/smoke/hash3.rb +0 -14
  186. data/smoke/hash4.rb +0 -11
  187. data/smoke/hash5.rb +0 -14
  188. data/smoke/huge_union.rb +0 -86
  189. data/smoke/identifier_keywords.rb +0 -17
  190. data/smoke/included.rb +0 -38
  191. data/smoke/inheritance.rb +0 -34
  192. data/smoke/inheritance2.rb +0 -35
  193. data/smoke/inherited.rb +0 -26
  194. data/smoke/initialize.rb +0 -28
  195. data/smoke/instance_eval.rb +0 -18
  196. data/smoke/instance_eval2.rb +0 -10
  197. data/smoke/instance_eval3.rb +0 -25
  198. data/smoke/instance_eval4.rb +0 -12
  199. data/smoke/int_times.rb +0 -15
  200. data/smoke/integer.rb +0 -11
  201. data/smoke/ivar.rb +0 -31
  202. data/smoke/ivar2.rb +0 -30
  203. data/smoke/ivar3.rb +0 -17
  204. data/smoke/ivar3.rbs +0 -3
  205. data/smoke/ivar4.rb +0 -21
  206. data/smoke/kernel-class.rb +0 -13
  207. data/smoke/keyword1.rb +0 -12
  208. data/smoke/keyword2.rb +0 -12
  209. data/smoke/keyword3.rb +0 -12
  210. data/smoke/keyword4.rb +0 -12
  211. data/smoke/keyword5.rb +0 -16
  212. data/smoke/kwrest.rb +0 -13
  213. data/smoke/kwrest.rbs +0 -3
  214. data/smoke/kwsplat1.rb +0 -43
  215. data/smoke/kwsplat2.rb +0 -13
  216. data/smoke/lit-complex.rb +0 -10
  217. data/smoke/lit-encoding.rb +0 -10
  218. data/smoke/manual-rbs.rb +0 -29
  219. data/smoke/manual-rbs.rbs +0 -3
  220. data/smoke/manual-rbs2.rb +0 -21
  221. data/smoke/manual-rbs2.rbs +0 -8
  222. data/smoke/manual-rbs3.rb +0 -13
  223. data/smoke/manual-rbs3.rbs +0 -3
  224. data/smoke/masgn1.rb +0 -14
  225. data/smoke/masgn2.rb +0 -18
  226. data/smoke/masgn3.rb +0 -13
  227. data/smoke/method_in_branch.rb +0 -23
  228. data/smoke/method_missing.rb +0 -29
  229. data/smoke/module1.rb +0 -29
  230. data/smoke/module2.rb +0 -28
  231. data/smoke/module3.rb +0 -33
  232. data/smoke/module4.rb +0 -35
  233. data/smoke/module5.rb +0 -17
  234. data/smoke/module6.rb +0 -40
  235. data/smoke/module_function1.rb +0 -29
  236. data/smoke/module_function2.rb +0 -29
  237. data/smoke/multiple-include.rb +0 -15
  238. data/smoke/multiple-superclass.rb +0 -28
  239. data/smoke/next1.rb +0 -21
  240. data/smoke/next2.rb +0 -17
  241. data/smoke/noname.rb +0 -9
  242. data/smoke/object-send1.rb +0 -23
  243. data/smoke/object-send2.rb +0 -10
  244. data/smoke/object-send3.rb +0 -18
  245. data/smoke/once.rb +0 -13
  246. data/smoke/optional1.rb +0 -14
  247. data/smoke/optional2.rb +0 -16
  248. data/smoke/optional3.rb +0 -11
  249. data/smoke/or_raise.rb +0 -18
  250. data/smoke/parameterizedd-self.rb +0 -20
  251. data/smoke/parameterizedd-self2.rb +0 -15
  252. data/smoke/pathname1.rb +0 -14
  253. data/smoke/pathname2.rb +0 -14
  254. data/smoke/pattern-match1.rb +0 -19
  255. data/smoke/pattern-match2.rb +0 -16
  256. data/smoke/prepend1.rb +0 -33
  257. data/smoke/prepend2.rb +0 -10
  258. data/smoke/prepend2.rbs +0 -9
  259. data/smoke/primitive_method.rb +0 -19
  260. data/smoke/printf.rb +0 -20
  261. data/smoke/proc.rb +0 -20
  262. data/smoke/proc2.rb +0 -17
  263. data/smoke/proc3.rb +0 -15
  264. data/smoke/proc4.rb +0 -12
  265. data/smoke/proc5.rb +0 -19
  266. data/smoke/proc6.rb +0 -13
  267. data/smoke/proc7.rb +0 -32
  268. data/smoke/public.rb +0 -38
  269. data/smoke/range.rb +0 -14
  270. data/smoke/rbs-alias.rb +0 -10
  271. data/smoke/rbs-alias.rbs +0 -4
  272. data/smoke/rbs-attr.rb +0 -27
  273. data/smoke/rbs-attr.rbs +0 -5
  274. data/smoke/rbs-attr2.rb +0 -11
  275. data/smoke/rbs-attr2.rbs +0 -3
  276. data/smoke/rbs-extend.rb +0 -10
  277. data/smoke/rbs-extend.rbs +0 -7
  278. data/smoke/rbs-interface.rb +0 -25
  279. data/smoke/rbs-interface.rbs +0 -12
  280. data/smoke/rbs-module.rb +0 -26
  281. data/smoke/rbs-module.rbs +0 -4
  282. data/smoke/rbs-opt-and-rest.rb +0 -10
  283. data/smoke/rbs-opt-and-rest.rbs +0 -3
  284. data/smoke/rbs-proc1.rb +0 -10
  285. data/smoke/rbs-proc1.rbs +0 -3
  286. data/smoke/rbs-proc2.rb +0 -21
  287. data/smoke/rbs-proc2.rbs +0 -3
  288. data/smoke/rbs-proc3.rb +0 -14
  289. data/smoke/rbs-proc3.rbs +0 -4
  290. data/smoke/rbs-record.rb +0 -18
  291. data/smoke/rbs-record.rbs +0 -4
  292. data/smoke/rbs-tyvar.rb +0 -19
  293. data/smoke/rbs-tyvar.rbs +0 -5
  294. data/smoke/rbs-tyvar2.rb +0 -21
  295. data/smoke/rbs-tyvar2.rbs +0 -9
  296. data/smoke/rbs-tyvar3.rb +0 -18
  297. data/smoke/rbs-tyvar3.rbs +0 -5
  298. data/smoke/rbs-tyvar4.rb +0 -37
  299. data/smoke/rbs-tyvar5.rb +0 -13
  300. data/smoke/rbs-tyvar5.rbs +0 -8
  301. data/smoke/rbs-tyvar6.rb +0 -18
  302. data/smoke/rbs-tyvar6.rbs +0 -12
  303. data/smoke/rbs-tyvar7.rb +0 -12
  304. data/smoke/rbs-tyvar7.rbs +0 -7
  305. data/smoke/rbs-vars.rb +0 -35
  306. data/smoke/rbs-vars.rbs +0 -7
  307. data/smoke/redo1.rb +0 -22
  308. data/smoke/redo2.rb +0 -23
  309. data/smoke/req-keyword.rb +0 -13
  310. data/smoke/require1.rb +0 -13
  311. data/smoke/require2.rb +0 -13
  312. data/smoke/rescue1.rb +0 -21
  313. data/smoke/rescue2.rb +0 -23
  314. data/smoke/rescue3.rb +0 -20
  315. data/smoke/rescue4.rb +0 -17
  316. data/smoke/respond_to.rb +0 -23
  317. data/smoke/rest-farg.rb +0 -11
  318. data/smoke/rest1.rb +0 -26
  319. data/smoke/rest2.rb +0 -31
  320. data/smoke/rest3.rb +0 -37
  321. data/smoke/rest4.rb +0 -19
  322. data/smoke/rest5.rb +0 -11
  323. data/smoke/rest6.rb +0 -12
  324. data/smoke/retry1.rb +0 -21
  325. data/smoke/return.rb +0 -14
  326. data/smoke/reveal.rb +0 -13
  327. data/smoke/simple.rb +0 -12
  328. data/smoke/singleton_class.rb +0 -8
  329. data/smoke/singleton_method.rb +0 -12
  330. data/smoke/step.rb +0 -18
  331. data/smoke/string-split.rb +0 -12
  332. data/smoke/struct-keyword_init.rb +0 -10
  333. data/smoke/struct.rb +0 -13
  334. data/smoke/struct2.rb +0 -25
  335. data/smoke/struct3.rb +0 -14
  336. data/smoke/struct4.rb +0 -7
  337. data/smoke/struct5.rb +0 -16
  338. data/smoke/struct6.rb +0 -15
  339. data/smoke/struct7.rb +0 -17
  340. data/smoke/stub-keyword.rb +0 -10
  341. data/smoke/super1.rb +0 -69
  342. data/smoke/super2.rb +0 -16
  343. data/smoke/super3.rb +0 -20
  344. data/smoke/super4.rb +0 -45
  345. data/smoke/super5.rb +0 -38
  346. data/smoke/svar1.rb +0 -13
  347. data/smoke/symbol-proc-attr.rb +0 -22
  348. data/smoke/symbol-proc-attr2.rb +0 -15
  349. data/smoke/symbol-proc-bot.rb +0 -13
  350. data/smoke/symbol-proc.rb +0 -25
  351. data/smoke/tap1.rb +0 -18
  352. data/smoke/toplevel.rb +0 -13
  353. data/smoke/two-map.rb +0 -18
  354. data/smoke/type_var.rb +0 -11
  355. data/smoke/typed_method.rb +0 -16
  356. data/smoke/uninitialize-var.rb +0 -13
  357. data/smoke/union-recv.rb +0 -35
  358. data/smoke/user-demo.rb +0 -15
  359. data/smoke/wrong-extend.rb +0 -27
  360. data/smoke/wrong-include.rb +0 -27
  361. data/smoke/wrong-include2.rb +0 -17
  362. data/smoke/wrong-rbs.rb +0 -15
  363. data/smoke/wrong-rbs.rbs +0 -7
  364. data/testbed/ao.rb +0 -297
  365. data/testbed/diff-lcs-entrypoint.rb +0 -4
  366. data/testbed/goodcheck-Gemfile.lock +0 -51
@@ -14,6 +14,8 @@ module TypeProf
14
14
  @pub_meth = pub_meth
15
15
  end
16
16
 
17
+ attr_reader :iseq
18
+
17
19
  def do_send(recv, mid, aargs, caller_ep, caller_env, scratch, &ctn)
18
20
  recv = recv.base_type while recv.respond_to?(:base_type)
19
21
  recv = scratch.globalize_type(recv, caller_env, caller_ep)
@@ -35,7 +37,7 @@ module TypeProf
35
37
  locals.each_with_index do |ty, i|
36
38
  alloc_site2 = alloc_site.add_id(i)
37
39
  # nenv is top-level, so it is okay to call Type#localize directly
38
- nenv, ty = ty.localize(nenv, alloc_site2, Config.options[:type_depth_limit])
40
+ nenv, ty = ty.localize(nenv, alloc_site2, Config.current.options[:type_depth_limit])
39
41
  nenv = nenv.local_update(i, ty)
40
42
  end
41
43
 
@@ -95,14 +97,14 @@ module TypeProf
95
97
  idx = 0
96
98
  msig.lead_tys.each_with_index do |ty, i|
97
99
  alloc_site2 = alloc_site.add_id(idx += 1)
98
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
100
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
99
101
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
100
102
  nenv = nenv.local_update(i, ty)
101
103
  end
102
104
  if msig.opt_tys
103
105
  msig.opt_tys.each_with_index do |ty, i|
104
106
  alloc_site2 = alloc_site.add_id(idx += 1)
105
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
107
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
106
108
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
107
109
  nenv = nenv.local_update(lead_num + i, ty)
108
110
  end
@@ -110,14 +112,14 @@ module TypeProf
110
112
  if msig.rest_ty
111
113
  alloc_site2 = alloc_site.add_id(idx += 1)
112
114
  ty = Type::Array.new(Type::Array::Elements.new([], msig.rest_ty), Type::Instance.new(Type::Builtin[:ary]))
113
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
115
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
114
116
  nenv, rest_ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
115
117
  nenv = nenv.local_update(rest_start, rest_ty)
116
118
  end
117
119
  if msig.post_tys
118
120
  msig.post_tys.each_with_index do |ty, i|
119
121
  alloc_site2 = alloc_site.add_id(idx += 1)
120
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
122
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
121
123
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
122
124
  nenv = nenv.local_update(post_start + i, ty)
123
125
  end
@@ -130,7 +132,7 @@ module TypeProf
130
132
  next
131
133
  end
132
134
  alloc_site2 = alloc_site.add_id(key)
133
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
135
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
134
136
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
135
137
  nenv = nenv.local_update(kw_start + i, ty)
136
138
  end
@@ -138,7 +140,7 @@ module TypeProf
138
140
  if msig.kw_rest_ty
139
141
  ty = msig.kw_rest_ty
140
142
  alloc_site2 = alloc_site.add_id(:**)
141
- ty = ty.substitute(cur_subst, Config.options[:type_depth_limit]).remove_type_vars
143
+ ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
142
144
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
143
145
  nenv = nenv.local_update(kw_rest, ty)
144
146
  end
@@ -209,9 +211,10 @@ module TypeProf
209
211
  @sig_rets = sig_rets
210
212
  @rbs_source = rbs_source
211
213
  @pub_meth = pub_meth
214
+ @iseq = nil
212
215
  end
213
216
 
214
- attr_reader :rbs_source
217
+ attr_reader :rbs_source, :iseq
215
218
 
216
219
  def do_send(recv_orig, mid, aargs, caller_ep, caller_env, scratch, &ctn)
217
220
  recv = scratch.globalize_type(recv_orig, caller_env, caller_ep)
@@ -254,7 +257,7 @@ module TypeProf
254
257
  bsig = msig.blk_ty.block_body.msig
255
258
  alloc_site = AllocationSite.new(caller_ep).add_id(self)
256
259
  nlead_tys = (bsig.lead_tys + bsig.opt_tys).map.with_index do |ty, i|
257
- ty = ty.substitute(subst, Config.options[:type_depth_limit]).remove_type_vars
260
+ ty = ty.substitute(subst, Config.current.options[:type_depth_limit]).remove_type_vars
258
261
  dummy_env, ty = scratch.localize_type(ty, dummy_env, dummy_ep, alloc_site.add_id(i))
259
262
  ty
260
263
  end
@@ -268,7 +271,7 @@ module TypeProf
268
271
  ncaller_env = recv_orig.update_container_elem_type(subst2, ncaller_env, caller_ep, scratch)
269
272
  scratch.merge_return_env(caller_ep) {|env| env ? env.merge(ncaller_env) : ncaller_env }
270
273
  end
271
- ret_ty2 = ret_ty.substitute(subst2, Config.options[:type_depth_limit]).remove_type_vars
274
+ ret_ty2 = ret_ty.substitute(subst2, Config.current.options[:type_depth_limit]).remove_type_vars
272
275
  else
273
276
  ret_ty2 = Type.any
274
277
  end
@@ -286,7 +289,7 @@ module TypeProf
286
289
  ctn[ret_ty, caller_ep, ncaller_env] if ret_ty != Type.bot
287
290
  end
288
291
  else
289
- ret_ty = ret_ty.substitute(subst, Config.options[:type_depth_limit])
292
+ ret_ty = ret_ty.substitute(subst, Config.current.options[:type_depth_limit])
290
293
  ret_ty = ret_ty.remove_type_vars
291
294
  ctn[ret_ty, caller_ep, ncaller_env] if ret_ty != Type.bot
292
295
  end
@@ -303,6 +306,7 @@ module TypeProf
303
306
  @sig_rets.each do |msig, _ret_ty|
304
307
  iseq_mdef.do_check_send(msig, recv, mid, ep, scratch)
305
308
  end
309
+ @iseq ||= iseq_mdef.iseq
306
310
  end
307
311
  end
308
312
 
data/lib/typeprof/type.rb CHANGED
@@ -168,7 +168,7 @@ module TypeProf
168
168
  end
169
169
 
170
170
  def remove_type_vars
171
- substitute(DummySubstitution, Config.options[:type_depth_limit])
171
+ substitute(DummySubstitution, Config.current.options[:type_depth_limit])
172
172
  end
173
173
 
174
174
  def include_untyped?(_scratch)
@@ -239,7 +239,7 @@ module TypeProf
239
239
  non_class_instances << ty
240
240
  end
241
241
  end
242
- if (Config.options[:union_width_limit] >= 2 && class_instances.size >= Config.options[:union_width_limit]) || (degenerated && class_instances.size >= 2)
242
+ if (Config.current.options[:union_width_limit] >= 2 && class_instances.size >= Config.current.options[:union_width_limit]) || (degenerated && class_instances.size >= 2)
243
243
  create(Utils::Set[Instance.new_degenerate(class_instances), *non_class_instances], elems)
244
244
  else
245
245
  new(tys, elems)
@@ -322,7 +322,7 @@ module TypeProf
322
322
  types.delete(Type::Instance.new(Type::Builtin[:true]))
323
323
  bool = true
324
324
  end
325
- types.delete(Type.any) unless Config.options[:show_untyped]
325
+ types.delete(Type.any) unless Config.current.options[:show_untyped]
326
326
  proc_tys, types = types.partition {|ty| ty.is_a?(Proc) }
327
327
  types = types.map {|ty| ty.screen_name(scratch) }
328
328
  types << scratch.show_proc_signature(proc_tys) unless proc_tys.empty?
@@ -339,9 +339,6 @@ module TypeProf
339
339
  types.join (" | ")
340
340
  end
341
341
  end
342
- rescue SystemStackError
343
- p self
344
- raise
345
342
  end
346
343
 
347
344
  def globalize(env, visited, depth)
@@ -425,22 +422,22 @@ module TypeProf
425
422
  end
426
423
 
427
424
  def self.any
428
- @any ||= Any.new
425
+ Thread.current[:any] ||= Any.new
429
426
  end
430
427
 
431
428
  def self.bot
432
- @bot ||= Union.new(Utils::Set[], nil)
429
+ Thread.current[:bot] ||= Union.new(Utils::Set[], nil)
433
430
  end
434
431
 
435
432
  def self.bool
436
- @bool ||= Union.new(Utils::Set[
433
+ Thread.current[:bool] ||= Union.new(Utils::Set[
437
434
  Instance.new(Type::Builtin[:true]),
438
435
  Instance.new(Type::Builtin[:false])
439
436
  ], nil)
440
437
  end
441
438
 
442
439
  def self.nil
443
- @nil ||= Instance.new(Type::Builtin[:nil])
440
+ Thread.current[:nil] ||= Instance.new(Type::Builtin[:nil])
444
441
  end
445
442
 
446
443
  def self.optional(ty)
@@ -786,7 +783,7 @@ module TypeProf
786
783
  when ::Hash
787
784
  Type.gen_hash do |h|
788
785
  obj.each do |k, v|
789
- k_ty = guess_literal_type(k).globalize(nil, {}, Config.options[:type_depth_limit])
786
+ k_ty = guess_literal_type(k).globalize(nil, {}, Config.current.options[:type_depth_limit])
790
787
  v_ty = guess_literal_type(v)
791
788
  h[k_ty] = v_ty
792
789
  end
@@ -854,33 +851,46 @@ module TypeProf
854
851
  include Utils::StructuralEquality
855
852
 
856
853
  def screen_name(iseq, scratch)
857
- fargs = @lead_tys.map {|ty| ty.screen_name(scratch) }
858
- farg_names = []
859
- farg_names += iseq.locals[0, @lead_tys.size] if iseq
860
- if @opt_tys
861
- fargs += @opt_tys.map {|ty| "?" + ty.screen_name(scratch) }
862
- farg_names += iseq.locals[@lead_tys.size, @opt_tys.size] if iseq
854
+ fargs_str = "("
855
+ sig_help = {}
856
+ add_farg = -> farg, name, help: false, key: sig_help.size do
857
+ name = "`#{ name }`" if RBS::Parser::KEYWORDS.key?(name.to_s)
858
+ name = "noname_#{ name }" if name.is_a?(Integer)
859
+ fargs_str << ", " if fargs_str != "("
860
+ i = fargs_str.size
861
+ fargs_str << (Config.current.options[:show_parameter_names] && name ? "#{ farg } #{ name }" : farg)
862
+ sig_help[key] = (i...fargs_str.size)
863
863
  end
864
+
865
+ @lead_tys.zip(iseq ? iseq.locals : []) do |ty, name|
866
+ add_farg.call(ty.screen_name(scratch), name, help: true)
867
+ end
868
+
869
+ @opt_tys&.zip(iseq ? iseq.locals[@lead_tys.size, @opt_tys.size] : []) do |ty, name|
870
+ add_farg.call("?" + ty.screen_name(scratch), name, help: true)
871
+ end
872
+
864
873
  if @rest_ty
865
- fargs << ("*" + @rest_ty.screen_name(scratch))
866
874
  if iseq
867
875
  rest_index = iseq.fargs_format[:rest_start]
868
- farg_names << (rest_index ? iseq.locals[rest_index] : nil)
876
+ name = rest_index ? iseq.locals[rest_index] : nil
869
877
  end
878
+ add_farg.call("*" + @rest_ty.screen_name(scratch), name)
870
879
  end
871
- if @post_tys
872
- fargs += @post_tys.map {|ty| ty.screen_name(scratch) }
873
- if iseq
874
- post_start = iseq.fargs_format[:post_start]
875
- farg_names += (post_start ? iseq.locals[post_start, @post_tys.size] : [nil] * @post_tys.size)
876
- end
880
+
881
+ if iseq
882
+ post_start = iseq.fargs_format[:post_start]
883
+ names = post_start ? iseq.locals[post_start, @post_tys.size] : []
877
884
  end
878
- if @kw_tys
879
- @kw_tys.each do |req, sym, ty|
880
- opt = req ? "" : "?"
881
- fargs << "#{ opt }#{ sym }: #{ ty.screen_name(scratch) }"
882
- end
885
+ @post_tys&.zip(names || []) do |ty, name|
886
+ add_farg.call(ty.screen_name(scratch), name)
887
+ end
888
+
889
+ @kw_tys&.each do |req, sym, ty|
890
+ opt = req ? "" : "?"
891
+ add_farg.call("#{ opt }#{ sym }: #{ ty.screen_name(scratch) }", nil, help: true, key: sym)
883
892
  end
893
+
884
894
  if @kw_rest_ty
885
895
  all_val_ty = Type.bot
886
896
  @kw_rest_ty.each_child_global do |ty|
@@ -892,18 +902,16 @@ module TypeProf
892
902
  end
893
903
  all_val_ty = all_val_ty.union(val_ty)
894
904
  end
895
- fargs << ("**" + all_val_ty.screen_name(scratch))
905
+ add_farg.call("**" + all_val_ty.screen_name(scratch), nil)
896
906
  end
897
- if Config.options[:show_parameter_names]
898
- farg_names = farg_names.map {|name| RBS::Parser::KEYWORDS.key?(name.to_s) ? "`#{name}`" : name }
899
- farg_names = farg_names.map {|name| name.is_a?(Integer) ? "noname_#{ name }" : name }
900
- fargs = fargs.zip(farg_names).map {|farg, name| name ? "#{ farg } #{ name }" : farg }
901
- end
902
- fargs = fargs.empty? ? "" : "(#{ fargs.join(", ") })"
907
+
908
+ fargs_str << ")"
909
+
910
+ fargs_str = "" if fargs_str == "()"
903
911
 
904
912
  # Dirty Hack: Stop the iteration at most once!
905
913
  # I'll remove this hack if RBS removes the limitation of nesting blocks
906
- return fargs if caller_locations.any? {|frame| frame.label == "show_block_signature" }
914
+ return fargs_str, sig_help if caller_locations.any? {|frame| frame.label == "show_block_signature" }
907
915
 
908
916
  optional = false
909
917
  blks = []
@@ -916,12 +924,12 @@ module TypeProf
916
924
  end
917
925
  end
918
926
  if blks != []
919
- fargs << " " if fargs != ""
920
- fargs << "?" if optional
921
- fargs << scratch.show_block_signature(blks)
927
+ fargs_str << " " if fargs_str != ""
928
+ fargs_str << "?" if optional
929
+ fargs_str << scratch.show_block_signature(blks)
922
930
  end
923
931
 
924
- fargs
932
+ return fargs_str, sig_help
925
933
  end
926
934
  end
927
935
 
@@ -9,7 +9,7 @@ module TypeProf
9
9
  def self.included(klass)
10
10
  klass.instance_eval do
11
11
  def new(*args)
12
- (@table ||= {})[[self] + args] ||= super
12
+ (Thread.current[:table] ||= {})[[self] + args] ||= super
13
13
  end
14
14
  end
15
15
  end
@@ -191,5 +191,22 @@ module TypeProf
191
191
  "#<#{ self.class }:#{ @heap.map {|_key, val| val }.inspect }>"
192
192
  end
193
193
  end
194
+
195
+ class CancelToken
196
+ def cancelled?
197
+ return false
198
+ end
199
+ end
200
+
201
+ class TimerCancelToken < CancelToken
202
+ def initialize(max_sec)
203
+ @max_sec = max_sec
204
+ @start_time = Time.now
205
+ end
206
+
207
+ def cancelled?
208
+ @max_sec && Time.now - @start_time >= @max_sec
209
+ end
210
+ end
194
211
  end
195
212
  end
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.15.3"
2
+ VERSION = "0.20.3"
3
3
  end
data/lib/typeprof.rb CHANGED
@@ -1,8 +1,3 @@
1
- unless defined?(RubyVM::InstructionSequence)
2
- puts "Currently, TypeProf can work on a Ruby implementation that supports RubyVM::InstructionSequence, such as CRuby."
3
- exit 1
4
- end
5
-
6
1
  module TypeProf end
7
2
 
8
3
  require_relative "typeprof/version"
@@ -20,3 +15,6 @@ require_relative "typeprof/import"
20
15
  require_relative "typeprof/export"
21
16
  require_relative "typeprof/builtin"
22
17
  require_relative "typeprof/cli"
18
+ require_relative "typeprof/code-range"
19
+
20
+ require_relative "typeprof/lsp" if RUBY_VERSION >= "3"
data/typeprof-lsp ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ /home/mame/work/ruby/local/bin/bundle exec exe/typeprof --repo ../gem_rbs_collection/gems -Ilib --lsp
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)/}) }
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(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.3.1"
33
+ spec.add_runtime_dependency "rbs", ">= 1.6.2"
34
34
  end
data/vscode/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /out
2
+ node_modules
3
+ .vscode/*
4
+ !.vscode/launch.json
5
+ *.vsix
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": "0.1.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Launch Extension",
6
+ "type": "extensionHost",
7
+ "request": "launch",
8
+ "runtimeExecutable": "${execPath}",
9
+ "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
10
+ "stopOnEntry": false,
11
+ "sourceMaps": true,
12
+ "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
13
+ "preLaunchTask": "npm: vscode:prepublish"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,7 @@
1
+ /sandbox
2
+ .vscode/**
3
+ /src
4
+ **/*.ts
5
+ **/*.js.map
6
+ **/tsconfig.json
7
+ development.md
data/vscode/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Ruby TypeProf VSCode Integration
2
+
3
+ *NOTE: This extenstion is very preliminary.*
4
+
5
+ This is a VSCode extension to help you write Ruby code by using an code analyzer called [Ruby TypeProf](https://github.com/ruby/typeprof/) as a backend.
6
+
7
+ ## How to use this extension
8
+
9
+ *TBD*
10
+
11
+ Requirements:
12
+
13
+ 1. Use Ruby 3.1.0 or later, and TypeProf 0.20.0 or later
14
+ 2. Add `gem "typeprof"` to your `Gemfile`, and execute `bundle install`
15
+
16
+ Troubleshooting:
17
+
18
+ *TBD*
19
+
20
+ ## How to develop this extension
21
+
22
+ See [development.md](https://github.com/ruby/typeprof/blob/master/development.md).
@@ -0,0 +1,31 @@
1
+ # LSP client for vscode
2
+
3
+ Note: this is under development
4
+
5
+ ## How to run
6
+
7
+ ```
8
+ $ cd vscode
9
+ $ npm install
10
+ $ npx run tsc -p ./
11
+ $ cd ..
12
+ $ code --extensionDevelopmentPath=vscode/ .
13
+ ```
14
+
15
+ Alternatively, you can do it in vscode itself.
16
+
17
+ ```
18
+ $ cd vscode
19
+ $ code
20
+ ```
21
+
22
+ And then press F5 to run another vscode with extension.
23
+
24
+ ## How to release
25
+
26
+ ```
27
+ $ npm run package
28
+ $ npx vsce publish
29
+ ```
30
+
31
+ See also: https://code.visualstudio.com/api/working-with-extensions/publishing-extension