typeprof 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -3
  3. data/lib/typeprof/analyzer.rb +35 -23
  4. data/lib/typeprof/builtin.rb +37 -3
  5. data/lib/typeprof/config.rb +2 -2
  6. data/lib/typeprof/export.rb +9 -3
  7. data/lib/typeprof/import.rb +4 -11
  8. data/lib/typeprof/method.rb +7 -4
  9. data/lib/typeprof/type.rb +3 -3
  10. data/lib/typeprof/version.rb +1 -1
  11. data/smoke/alias.rb +1 -0
  12. data/smoke/any1.rb +1 -0
  13. data/smoke/any2.rb +1 -0
  14. data/smoke/arguments.rb +1 -0
  15. data/smoke/arguments2.rb +1 -0
  16. data/smoke/array-each.rb +1 -0
  17. data/smoke/array-each2.rb +1 -0
  18. data/smoke/array-each3.rb +1 -0
  19. data/smoke/array-ltlt.rb +1 -0
  20. data/smoke/array-ltlt2.rb +1 -0
  21. data/smoke/array-map.rb +1 -0
  22. data/smoke/array-map2.rb +1 -0
  23. data/smoke/array-map3.rb +1 -0
  24. data/smoke/array-mul.rb +1 -0
  25. data/smoke/array-plus1.rb +1 -0
  26. data/smoke/array-pop.rb +1 -0
  27. data/smoke/array-range-aref.rb +1 -0
  28. data/smoke/array-replace.rb +1 -0
  29. data/smoke/array-s-aref.rb +1 -0
  30. data/smoke/array1.rb +1 -0
  31. data/smoke/array10.rb +1 -0
  32. data/smoke/array11.rb +1 -0
  33. data/smoke/array12.rb +1 -0
  34. data/smoke/array13.rb +1 -0
  35. data/smoke/array14.rb +1 -0
  36. data/smoke/array2.rb +1 -0
  37. data/smoke/array4.rb +1 -0
  38. data/smoke/array5.rb +1 -0
  39. data/smoke/array6.rb +1 -0
  40. data/smoke/array7.rb +1 -0
  41. data/smoke/array9.rb +1 -0
  42. data/smoke/autoload.rb +1 -0
  43. data/smoke/backtrace.rb +1 -0
  44. data/smoke/block-ambiguous.rb +1 -0
  45. data/smoke/block-args1-rest.rb +1 -0
  46. data/smoke/block-args1.rb +1 -0
  47. data/smoke/block-args2-rest.rb +1 -0
  48. data/smoke/block-args2.rb +1 -0
  49. data/smoke/block-args3-rest.rb +1 -0
  50. data/smoke/block-args3.rb +1 -0
  51. data/smoke/block-blockarg.rb +1 -0
  52. data/smoke/block-kwarg.rb +1 -0
  53. data/smoke/block1.rb +1 -0
  54. data/smoke/block10.rb +1 -0
  55. data/smoke/block11.rb +1 -0
  56. data/smoke/block12.rb +1 -0
  57. data/smoke/block14.rb +1 -0
  58. data/smoke/block2.rb +1 -0
  59. data/smoke/block4.rb +1 -0
  60. data/smoke/block5.rb +1 -0
  61. data/smoke/block6.rb +1 -0
  62. data/smoke/block7.rb +1 -0
  63. data/smoke/block8.rb +1 -0
  64. data/smoke/block9.rb +1 -0
  65. data/smoke/blown.rb +1 -0
  66. data/smoke/break1.rb +1 -0
  67. data/smoke/break2.rb +1 -0
  68. data/smoke/case.rb +1 -0
  69. data/smoke/case2.rb +1 -0
  70. data/smoke/class_method3.rb +2 -0
  71. data/smoke/constant2.rb +1 -0
  72. data/smoke/constant3.rb +1 -0
  73. data/smoke/constant4.rb +1 -0
  74. data/smoke/context-sensitive1.rb +1 -0
  75. data/smoke/cvar.rb +1 -0
  76. data/smoke/demo.rb +1 -0
  77. data/smoke/demo1.rb +1 -0
  78. data/smoke/demo10.rb +1 -0
  79. data/smoke/demo11.rb +1 -0
  80. data/smoke/demo2.rb +1 -0
  81. data/smoke/demo3.rb +1 -0
  82. data/smoke/demo7.rb +1 -0
  83. data/smoke/demo8.rb +1 -0
  84. data/smoke/demo9.rb +1 -0
  85. data/smoke/dummy-execution1.rb +1 -0
  86. data/smoke/ensure1.rb +1 -0
  87. data/smoke/enumerator.rb +1 -0
  88. data/smoke/expandarray1.rb +1 -0
  89. data/smoke/expandarray2.rb +1 -0
  90. data/smoke/flow1.rb +1 -0
  91. data/smoke/flow2.rb +1 -0
  92. data/smoke/flow3.rb +1 -0
  93. data/smoke/flow5.rb +1 -0
  94. data/smoke/flow6.rb +1 -0
  95. data/smoke/flow7.rb +1 -0
  96. data/smoke/flow8.rb +1 -0
  97. data/smoke/freeze.rb +1 -0
  98. data/smoke/function.rb +1 -0
  99. data/smoke/gvar.rb +1 -0
  100. data/smoke/gvar2.rb +1 -0
  101. data/smoke/hash-fetch.rb +1 -0
  102. data/smoke/hash-merge-bang.rb +1 -0
  103. data/smoke/hash1.rb +1 -0
  104. data/smoke/hash2.rb +1 -0
  105. data/smoke/hash3.rb +1 -0
  106. data/smoke/hash4.rb +1 -0
  107. data/smoke/initialize.rb +1 -0
  108. data/smoke/int_times.rb +1 -0
  109. data/smoke/integer.rb +1 -0
  110. data/smoke/ivar.rb +1 -0
  111. data/smoke/kernel-class.rb +1 -0
  112. data/smoke/keyword1.rb +1 -0
  113. data/smoke/keyword2.rb +1 -0
  114. data/smoke/keyword3.rb +1 -0
  115. data/smoke/keyword4.rb +1 -0
  116. data/smoke/keyword5.rb +1 -0
  117. data/smoke/kwsplat1.rb +1 -0
  118. data/smoke/kwsplat2.rb +1 -0
  119. data/smoke/manual-rbs.rb +1 -0
  120. data/smoke/manual-rbs2.rb +1 -0
  121. data/smoke/masgn1.rb +1 -0
  122. data/smoke/masgn2.rb +1 -0
  123. data/smoke/masgn3.rb +1 -0
  124. data/smoke/method_in_branch.rb +1 -0
  125. data/smoke/next1.rb +1 -0
  126. data/smoke/next2.rb +1 -0
  127. data/smoke/object-send1.rb +1 -0
  128. data/smoke/once.rb +1 -0
  129. data/smoke/optional1.rb +1 -0
  130. data/smoke/optional2.rb +1 -0
  131. data/smoke/optional3.rb +1 -0
  132. data/smoke/parameterizedd-self.rb +1 -0
  133. data/smoke/pathname1.rb +1 -0
  134. data/smoke/pathname2.rb +1 -0
  135. data/smoke/pattern-match1.rb +1 -0
  136. data/smoke/pattern-match2.rb +1 -0
  137. data/smoke/proc.rb +1 -0
  138. data/smoke/proc2.rb +1 -0
  139. data/smoke/proc3.rb +1 -0
  140. data/smoke/proc4.rb +1 -0
  141. data/smoke/range.rb +1 -0
  142. data/smoke/rbs-alias.rb +1 -0
  143. data/smoke/rbs-attr.rb +1 -0
  144. data/smoke/rbs-extend.rb +1 -0
  145. data/smoke/rbs-interface.rb +1 -0
  146. data/smoke/rbs-proc1.rb +1 -0
  147. data/smoke/rbs-proc2.rb +1 -0
  148. data/smoke/rbs-proc3.rb +1 -0
  149. data/smoke/rbs-record.rb +1 -0
  150. data/smoke/rbs-tyvar.rb +1 -0
  151. data/smoke/rbs-tyvar2.rb +1 -0
  152. data/smoke/rbs-tyvar3.rb +1 -0
  153. data/smoke/rbs-tyvar5.rb +1 -0
  154. data/smoke/rbs-tyvar6.rb +1 -0
  155. data/smoke/rbs-tyvar7.rb +1 -0
  156. data/smoke/rbs-vars.rb +1 -0
  157. data/smoke/redo1.rb +1 -0
  158. data/smoke/redo2.rb +1 -0
  159. data/smoke/req-keyword.rb +1 -0
  160. data/smoke/rescue1.rb +1 -0
  161. data/smoke/rescue2.rb +1 -0
  162. data/smoke/respond_to.rb +1 -0
  163. data/smoke/rest-farg.rb +1 -0
  164. data/smoke/rest1.rb +1 -0
  165. data/smoke/rest2.rb +1 -0
  166. data/smoke/rest3.rb +1 -0
  167. data/smoke/rest4.rb +1 -0
  168. data/smoke/rest5.rb +1 -0
  169. data/smoke/rest6.rb +1 -0
  170. data/smoke/retry1.rb +1 -0
  171. data/smoke/return.rb +1 -0
  172. data/smoke/step.rb +1 -0
  173. data/smoke/string-split.rb +1 -0
  174. data/smoke/struct2.rb +1 -0
  175. data/smoke/super1.rb +1 -0
  176. data/smoke/svar1.rb +1 -0
  177. data/smoke/symbol-proc.rb +1 -0
  178. data/smoke/tap1.rb +1 -0
  179. data/smoke/toplevel.rb +1 -0
  180. data/smoke/two-map.rb +1 -0
  181. data/smoke/type_var.rb +1 -0
  182. data/smoke/typed_method.rb +1 -0
  183. data/smoke/uninitialize-var.rb +1 -0
  184. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8ecd99e5448a244b11714710dfbb5fd3f36274c5f72fa97da034059018fc32f
4
- data.tar.gz: ed322065cf15d08f7bb50105cce19d74d923d4d7af7f94a563668788849d636d
3
+ metadata.gz: dd38b5e501a5d4fbe4db1ad43015c44ab39dbfefc3f7638516faeb5bcafd21a9
4
+ data.tar.gz: 000f140ab750e4ddd57863851c21a830bfe470c0eb7be9e38442ca535f4ef041
5
5
  SHA512:
6
- metadata.gz: 528dcf83aa2ceec79ea602f3505eb48230baf87bae8409212f8f152b45e308c66490ff5d10a9153698870e02b0ee5f031ce81cbb48a4460187992269708957ef
7
- data.tar.gz: a03594cb0b6a88ba905dc860ba9de64beb82a6cb1ebc562aad94cf20ecf14e36534bbf8a29a0b629189c62c32c26437104acb4387159c17bb222c708614cc303
6
+ metadata.gz: '00924963d5f91c4609224615507fcfb240a140c8119bf76f24aa28973342e6b61c528fc579781690f9f0392bf0d125c8bdb70499525791603c111ed9251da931'
7
+ data.tar.gz: ee07e0636cd3e26271c468e1927e676a1b320ddefe13dc2412c254cac9aaeac7ca5db1936a26ccc477c2494473fde1d2bdde7a28bd1fa384c6995d7ae4d085ea
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typeprof (0.7.0)
4
+ typeprof (0.8.0)
5
5
  rbs (>= 0.17.0)
6
6
 
7
7
  GEM
@@ -11,11 +11,13 @@ GEM
11
11
  docile (1.3.2)
12
12
  power_assert (1.2.0)
13
13
  rake (13.0.1)
14
- rbs (0.17.0)
15
- simplecov (0.19.1)
14
+ rbs (0.18.1)
15
+ simplecov (0.20.0)
16
16
  docile (~> 1.1)
17
17
  simplecov-html (~> 0.11)
18
+ simplecov_json_formatter (~> 0.1)
18
19
  simplecov-html (0.12.3)
20
+ simplecov_json_formatter (0.1.2)
19
21
  stackprof (0.2.16)
20
22
  test-unit (3.3.7)
21
23
  power_assert
@@ -83,10 +83,11 @@ module TypeProf
83
83
  class StaticEnv
84
84
  include Utils::StructuralEquality
85
85
 
86
- def initialize(recv_ty, blk_ty, mod_func)
86
+ def initialize(recv_ty, blk_ty, mod_func, pub_meth)
87
87
  @recv_ty = recv_ty
88
88
  @blk_ty = blk_ty
89
89
  @mod_func = mod_func
90
+ @pub_meth = pub_meth
90
91
 
91
92
  return if recv_ty == :top #OK
92
93
  recv_ty.each_child_global do |ty|
@@ -94,13 +95,14 @@ module TypeProf
94
95
  end
95
96
  end
96
97
 
97
- attr_reader :recv_ty, :blk_ty, :mod_func
98
+ attr_reader :recv_ty, :blk_ty, :mod_func, :pub_meth
98
99
 
99
100
  def merge(other)
100
101
  recv_ty = @recv_ty.union(other.recv_ty)
101
102
  blk_ty = @blk_ty.union(other.blk_ty)
102
103
  mod_func = @mod_func & other.mod_func # ??
103
- StaticEnv.new(recv_ty, blk_ty, mod_func)
104
+ pub_meth = @pub_meth & other.pub_meth # ??
105
+ StaticEnv.new(recv_ty, blk_ty, mod_func, pub_meth)
104
106
  end
105
107
  end
106
108
 
@@ -195,12 +197,17 @@ module TypeProf
195
197
  end
196
198
 
197
199
  def enable_module_function
198
- senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, true)
200
+ senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, true, @static_env.pub_meth)
201
+ Env.new(senv, @locals, @stack, @type_params)
202
+ end
203
+
204
+ def method_public_set(flag)
205
+ senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, @static_env.mod_func, flag)
199
206
  Env.new(senv, @locals, @stack, @type_params)
200
207
  end
201
208
 
202
209
  def replace_recv_ty(ty)
203
- senv = StaticEnv.new(ty, @static_env.blk_ty, @static_env.mod_func)
210
+ senv = StaticEnv.new(ty, @static_env.blk_ty, @static_env.mod_func, @static_env.pub_meth)
204
211
  Env.new(senv, @locals, @stack, @type_params)
205
212
  end
206
213
 
@@ -380,12 +387,12 @@ module TypeProf
380
387
  cbase && cbase.idx != 1 ? @class_defs[cbase.idx].name : []
381
388
  end
382
389
 
383
- def new_class(cbase, name, type_params, superclass, superclass_type_args, absolute_path)
390
+ def new_class(cbase, name, type_params, superclass, absolute_path)
384
391
  show_name = cbase_path(cbase) + [name]
385
392
  idx = @class_defs.size
386
393
  if superclass
387
394
  @class_defs[idx] = ClassDef.new(:class, show_name, absolute_path)
388
- klass = Type::Class.new(:class, idx, type_params, superclass, superclass_type_args, show_name)
395
+ klass = Type::Class.new(:class, idx, type_params, superclass, show_name)
389
396
  @class_defs[idx].klass_obj = klass
390
397
  cbase ||= klass # for bootstrap
391
398
  add_constant(cbase, name, klass, absolute_path)
@@ -393,13 +400,17 @@ module TypeProf
393
400
  else
394
401
  # module
395
402
  @class_defs[idx] = ClassDef.new(:module, show_name, absolute_path)
396
- mod = Type::Class.new(:module, idx, type_params, nil, nil, show_name)
403
+ mod = Type::Class.new(:module, idx, type_params, nil, show_name)
397
404
  @class_defs[idx].klass_obj = mod
398
405
  add_constant(cbase, name, mod, absolute_path)
399
406
  return mod
400
407
  end
401
408
  end
402
409
 
410
+ def add_superclass_type_args!(klass, tyargs)
411
+ klass.superclass_type_args = tyargs
412
+ end
413
+
403
414
  def new_struct(ep)
404
415
  return @struct_defs[ep] if @struct_defs[ep]
405
416
 
@@ -407,7 +418,8 @@ module TypeProf
407
418
  superclass = Type::Builtin[:struct]
408
419
  name = "AnonymousStruct_generated_#{ @anonymous_struct_gen_id += 1 }"
409
420
  @class_defs[idx] = ClassDef.new(:class, [name], ep.ctx.iseq.absolute_path)
410
- klass = Type::Class.new(:class, idx, [], superclass, [Type.any], name)
421
+ klass = Type::Class.new(:class, idx, [], superclass, name)
422
+ add_superclass_type_args!(klass, [Type.any])
411
423
  @class_defs[idx].klass_obj = klass
412
424
 
413
425
  @struct_defs[ep] = klass
@@ -563,12 +575,12 @@ module TypeProf
563
575
  end
564
576
  end
565
577
 
566
- def add_iseq_method(klass, mid, iseq, cref, outer_ep)
567
- add_method(klass, mid, false, ISeqMethodDef.new(iseq, cref, outer_ep))
578
+ def add_iseq_method(klass, mid, iseq, cref, outer_ep, pub_meth)
579
+ add_method(klass, mid, false, ISeqMethodDef.new(iseq, cref, outer_ep, pub_meth))
568
580
  end
569
581
 
570
- def add_singleton_iseq_method(klass, mid, iseq, cref, outer_ep)
571
- add_method(klass, mid, true, ISeqMethodDef.new(iseq, cref, outer_ep))
582
+ def add_singleton_iseq_method(klass, mid, iseq, cref, outer_ep, pub_meth)
583
+ add_method(klass, mid, true, ISeqMethodDef.new(iseq, cref, outer_ep, pub_meth))
572
584
  end
573
585
 
574
586
  def set_custom_method(klass, mid, impl)
@@ -953,7 +965,7 @@ module TypeProf
953
965
  locals[kwrest_index] = Type.any if kwrest_index
954
966
  locals[block_index] = Type.nil if block_index
955
967
 
956
- env = Env.new(StaticEnv.new(recv, Type.nil, false), locals, [], Utils::HashWrapper.new({}))
968
+ env = Env.new(StaticEnv.new(recv, Type.nil, false, true), locals, [], Utils::HashWrapper.new({}))
957
969
 
958
970
  if !@pending_execution[iseq] || @pending_execution[iseq][0] == :block
959
971
  @pending_execution[iseq] = [:method, [meth, ep, env]]
@@ -1148,7 +1160,7 @@ module TypeProf
1148
1160
  cref = ep.ctx.cref
1149
1161
  recv.each_child do |recv|
1150
1162
  if recv.is_a?(Type::Class)
1151
- meth = add_singleton_iseq_method(recv, mid, iseq, cref, nil)
1163
+ meth = add_singleton_iseq_method(recv, mid, iseq, cref, nil, env.static_env.pub_meth)
1152
1164
  pend_method_execution(iseq, meth, recv, mid, ep.ctx.cref, nil)
1153
1165
  else
1154
1166
  recv = Type.any # XXX: what to do?
@@ -1188,8 +1200,8 @@ module TypeProf
1188
1200
  if cbase == Type.any
1189
1201
  klass = Type.any
1190
1202
  else
1191
- superclass_type_args = superclass.type_params.map { Type.any } if superclass
1192
- klass = new_class(cbase, id, [], superclass, superclass_type_args, ep.ctx.iseq.absolute_path)
1203
+ klass = new_class(cbase, id, [], superclass, ep.ctx.iseq.absolute_path)
1204
+ add_superclass_type_args!(klass, superclass.type_params.map { Type.any }) if superclass
1193
1205
  end
1194
1206
  end
1195
1207
  singleton = false
@@ -1211,7 +1223,7 @@ module TypeProf
1211
1223
  nctx = Context.new(iseq, ncref, nil)
1212
1224
  nep = ExecutionPoint.new(nctx, 0, nil)
1213
1225
  locals = [Type.nil] * iseq.locals.size
1214
- nenv = Env.new(StaticEnv.new(recv, blk, false), locals, [], Utils::HashWrapper.new({}))
1226
+ nenv = Env.new(StaticEnv.new(recv, blk, false, true), locals, [], Utils::HashWrapper.new({}))
1215
1227
  merge_env(nep, nenv)
1216
1228
  add_callsite!(nep.ctx, ep, env) do |ret_ty, ep, env|
1217
1229
  nenv, ret_ty = localize_type(ret_ty, env, ep)
@@ -1940,7 +1952,7 @@ module TypeProf
1940
1952
  nctx = Context.new(blk_iseq, ep.ctx.cref, ep.ctx.mid)
1941
1953
  nep = ExecutionPoint.new(nctx, 0, ep)
1942
1954
  nlocals = [Type.any] * blk_iseq.locals.size
1943
- nsenv = StaticEnv.new(env.static_env.recv_ty, Type.any, env.static_env.mod_func)
1955
+ nsenv = StaticEnv.new(env.static_env.recv_ty, Type.any, env.static_env.mod_func, env.static_env.pub_meth)
1944
1956
  nenv = Env.new(nsenv, nlocals, [], nil)
1945
1957
  pend_block_dummy_execution(blk_ty, blk_iseq, nep, nenv)
1946
1958
  merge_return_env(ep) {|tenv| tenv ? tenv.merge(env) : env }
@@ -1996,17 +2008,17 @@ module TypeProf
1996
2008
  typed_mdef = check_typed_method(cref.klass, mid, ep.ctx.cref.singleton)
1997
2009
  recv = Type::Instance.new(recv) if recv.is_a?(Type::Class)
1998
2010
  if typed_mdef
1999
- mdef = ISeqMethodDef.new(iseq, cref, outer_ep)
2011
+ mdef = ISeqMethodDef.new(iseq, cref, outer_ep, env.static_env.pub_meth)
2000
2012
  typed_mdef.each do |typed_mdef|
2001
2013
  typed_mdef.do_match_iseq_mdef(mdef, recv, mid, env, ep, self)
2002
2014
  end
2003
2015
  else
2004
2016
  if ep.ctx.cref.singleton
2005
- meth = add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep)
2017
+ meth = add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep, true)
2006
2018
  else
2007
- meth = add_iseq_method(cref.klass, mid, iseq, cref, outer_ep)
2019
+ meth = add_iseq_method(cref.klass, mid, iseq, cref, outer_ep, env.static_env.pub_meth)
2008
2020
  if env.static_env.mod_func
2009
- add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep)
2021
+ add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep, true)
2010
2022
  end
2011
2023
  end
2012
2024
 
@@ -198,6 +198,38 @@ module TypeProf
198
198
  end
199
199
  end
200
200
 
201
+ def module_public(recv, mid, aargs, ep, env, scratch, &ctn)
202
+ if aargs.lead_tys.empty?
203
+ ctn[recv, ep, env.method_public_set(true)]
204
+ else
205
+ aargs.lead_tys.each do |aarg|
206
+ sym = get_sym("public", aarg, ep, scratch) or next
207
+ meths = scratch.get_method(recv, false, sym)
208
+ next unless meths
209
+ meths.each do |mdef|
210
+ mdef.pub_meth = true
211
+ end
212
+ end
213
+ ctn[recv, ep, env]
214
+ end
215
+ end
216
+
217
+ def module_private(recv, mid, aargs, ep, env, scratch, &ctn)
218
+ if aargs.lead_tys.empty?
219
+ ctn[recv, ep, env.method_public_set(false)]
220
+ else
221
+ aargs.lead_tys.each do |aarg|
222
+ sym = get_sym("private", aarg, ep, scratch) or next
223
+ meths = scratch.get_method(recv, false, sym)
224
+ next unless meths
225
+ meths.each do |mdef|
226
+ mdef.pub_meth = false
227
+ end
228
+ end
229
+ ctn[recv, ep, env]
230
+ end
231
+ end
232
+
201
233
  def module_define_method(recv, mid, aargs, ep, env, scratch, &ctn)
202
234
  if aargs.lead_tys.size != 1
203
235
  scratch.warn(ep, "Module#define with #{ aargs.lead_tys.size } argument is ignored")
@@ -551,8 +583,8 @@ module TypeProf
551
583
  end
552
584
 
553
585
  def self.setup_initial_global_env(scratch)
554
- klass_basic_obj = scratch.new_class(nil, :BasicObject, [], :__root__, nil, nil) # cbase, name, superclass
555
- klass_obj = scratch.new_class(nil, :Object, [], klass_basic_obj, [], nil)
586
+ klass_basic_obj = scratch.new_class(nil, :BasicObject, [], :__root__, nil) # cbase, name, superclass
587
+ klass_obj = scratch.new_class(nil, :Object, [], klass_basic_obj, nil)
556
588
  scratch.add_constant(klass_obj, :Object, klass_obj, nil)
557
589
  scratch.add_constant(klass_obj, :BasicObject, klass_basic_obj, nil)
558
590
 
@@ -561,7 +593,7 @@ module TypeProf
561
593
 
562
594
  Import.import_builtin(scratch)
563
595
 
564
- Type::Builtin[:vmcore] = scratch.new_class(klass_obj, :VMCore, [], klass_obj, [], nil)
596
+ Type::Builtin[:vmcore] = scratch.new_class(klass_obj, :VMCore, [], klass_obj, nil)
565
597
  Type::Builtin[:int] = scratch.get_constant(klass_obj, :Integer)
566
598
  Type::Builtin[:float] = scratch.get_constant(klass_obj, :Float)
567
599
  Type::Builtin[:rational] = scratch.get_constant(klass_obj, :Rational)
@@ -606,6 +638,8 @@ module TypeProf
606
638
  scratch.set_custom_method(klass_module, :include, Builtin.method(:module_include))
607
639
  scratch.set_custom_method(klass_module, :extend, Builtin.method(:module_extend))
608
640
  scratch.set_custom_method(klass_module, :module_function, Builtin.method(:module_module_function))
641
+ scratch.set_custom_method(klass_module, :public, Builtin.method(:module_public))
642
+ scratch.set_custom_method(klass_module, :private, Builtin.method(:module_private))
609
643
  scratch.set_custom_method(klass_module, :define_method, Builtin.method(:module_define_method))
610
644
 
611
645
  scratch.set_custom_method(klass_proc, :[], Builtin.method(:proc_call))
@@ -69,7 +69,7 @@ module TypeProf
69
69
 
70
70
  prologue_ctx = Context.new(nil, nil, nil)
71
71
  prologue_ep = ExecutionPoint.new(prologue_ctx, -1, nil)
72
- prologue_env = Env.new(StaticEnv.new(:top, Type.nil, false), [], [], Utils::HashWrapper.new({}))
72
+ prologue_env = Env.new(StaticEnv.new(:top, Type.nil, false, true), [], [], Utils::HashWrapper.new({}))
73
73
 
74
74
  Config.rb_files.each do |rb|
75
75
  if rb.is_a?(Array) # [String name, String content]
@@ -113,7 +113,7 @@ module TypeProf
113
113
  ctx = Context.new(iseq, cref, nil)
114
114
  ep = ExecutionPoint.new(ctx, 0, nil)
115
115
  locals = [Type.nil] * iseq.locals.size
116
- env = Env.new(StaticEnv.new(recv, Type.nil, false), locals, [], Utils::HashWrapper.new({}))
116
+ env = Env.new(StaticEnv.new(recv, Type.nil, false, false), locals, [], Utils::HashWrapper.new({}))
117
117
 
118
118
  return ep, env
119
119
  end
@@ -135,8 +135,9 @@ module TypeProf
135
135
  method_name = ctx.mid
136
136
  method_name = "self.#{ method_name }" if singleton
137
137
 
138
- iseq_methods[method_name] ||= []
139
- iseq_methods[method_name] << @scratch.show_method_signature(ctx)
138
+ iseq_methods[method_name] ||= [true, []]
139
+ iseq_methods[method_name][0] &&= mdef.pub_meth
140
+ iseq_methods[method_name][1] << @scratch.show_method_signature(ctx)
140
141
  end
141
142
  when AttrMethodDef
142
143
  next if !mdef.absolute_path || Config.check_dir_filter(mdef.absolute_path) == :exclude
@@ -296,8 +297,13 @@ module TypeProf
296
297
  output.puts indent + "# def #{ method_name } : #{ sigs }"
297
298
  first = false
298
299
  end
299
- class_data.iseq_methods.each do |method_name, sigs|
300
+ prev_pub_meth = true
301
+ class_data.iseq_methods.each do |method_name, (pub_meth, sigs)|
300
302
  sigs = sigs.sort.join("\n" + indent + " " * (method_name.size + 7) + "| ")
303
+ if prev_pub_meth != pub_meth
304
+ output.puts indent + " #{ pub_meth ? "public" : "private" }"
305
+ prev_pub_meth = pub_meth
306
+ end
301
307
  output.puts indent + " def #{ method_name } : #{ sigs }"
302
308
  first = false
303
309
  end
@@ -62,7 +62,6 @@ module TypeProf
62
62
  class RBS2JSON
63
63
  def initialize(all_env, cur_env)
64
64
  @all_env, @cur_env = all_env, cur_env
65
- @env_walker = RBS::EnvironmentWalker.new(env: @cur_env) # Currently, only each_type_name is used
66
65
  end
67
66
 
68
67
  def dump_json
@@ -259,12 +258,6 @@ module TypeProf
259
258
  yield decl.name
260
259
  if decl.super_class
261
260
  name = decl.super_class.name
262
- args = decl.super_class.args
263
- if args
264
- args.each do |ty|
265
- @env_walker.each_type_name(ty, &blk)
266
- end
267
- end
268
261
  else
269
262
  name = RBS::BuiltinNames::Object.name
270
263
  end
@@ -476,8 +469,7 @@ module TypeProf
476
469
 
477
470
  klass = @scratch.get_constant(base_klass, name)
478
471
  if klass.is_a?(Type::Any)
479
- superclass_type_args = superclass_type_args&.map {|ty| conv_type(ty) }
480
- klass = @scratch.new_class(base_klass, name, type_params, superclass, superclass_type_args, nil)
472
+ klass = @scratch.new_class(base_klass, name, type_params, superclass, nil)
481
473
 
482
474
  # There builtin classes are needed to interpret RBS declarations
483
475
  case classpath
@@ -493,10 +485,11 @@ module TypeProf
493
485
  end
494
486
  end
495
487
 
496
- [klass, members]
488
+ [klass, superclass_type_args, members]
497
489
  end
498
490
 
499
- classes.each do |klass, members|
491
+ classes.each do |klass, superclass_type_args, members|
492
+ @scratch.add_superclass_type_args!(klass, superclass_type_args&.map {|ty| conv_type(ty) })
500
493
  included_modules = members[:included_modules]
501
494
  extended_modules = members[:extended_modules]
502
495
  methods = members[:methods]
@@ -4,13 +4,16 @@ module TypeProf
4
4
  end
5
5
 
6
6
  class ISeqMethodDef < MethodDef
7
- def initialize(iseq, cref, outer_ep)
7
+ def initialize(iseq, cref, outer_ep, pub_meth)
8
8
  @iseq = iseq
9
9
  raise if iseq.nil?
10
10
  @cref = cref
11
11
  @outer_ep = outer_ep
12
+ @pub_meth = pub_meth
12
13
  end
13
14
 
15
+ attr_accessor :pub_meth
16
+
14
17
  def do_send(recv, mid, aargs, caller_ep, caller_env, scratch, &ctn)
15
18
  recv = recv.base_type while recv.respond_to?(:base_type)
16
19
  recv = scratch.globalize_type(recv, caller_env, caller_ep)
@@ -27,7 +30,7 @@ module TypeProf
27
30
 
28
31
  nctx = Context.new(@iseq, @cref, mid)
29
32
  callee_ep = ExecutionPoint.new(nctx, 0, @outer_ep)
30
- nenv = Env.new(StaticEnv.new(recv, blk_ty, false), locals, [], Utils::HashWrapper.new({}))
33
+ nenv = Env.new(StaticEnv.new(recv, blk_ty, false, true), locals, [], Utils::HashWrapper.new({}))
31
34
  alloc_site = AllocationSite.new(callee_ep)
32
35
  locals.each_with_index do |ty, i|
33
36
  alloc_site2 = alloc_site.add_id(i)
@@ -87,7 +90,7 @@ module TypeProf
87
90
  callee_ep = ExecutionPoint.new(ctx, 0, nil)
88
91
 
89
92
  locals = [Type.nil] * @iseq.locals.size
90
- nenv = Env.new(StaticEnv.new(recv, msig.blk_ty, false), locals, [], Utils::HashWrapper.new({}))
93
+ nenv = Env.new(StaticEnv.new(recv, msig.blk_ty, false, true), locals, [], Utils::HashWrapper.new({}))
91
94
  alloc_site = AllocationSite.new(callee_ep)
92
95
  idx = 0
93
96
  msig.lead_tys.each_with_index do |ty, i|
@@ -224,7 +227,7 @@ module TypeProf
224
227
  dummy_ep = ExecutionPoint.new(dummy_ctx, -1, caller_ep)
225
228
  s_recv = recv
226
229
  s_recv = s_recv.base_type while s_recv.respond_to?(:base_type)
227
- dummy_env = Env.new(StaticEnv.new(s_recv, msig.blk_ty, false), [], [], Utils::HashWrapper.new({}))
230
+ dummy_env = Env.new(StaticEnv.new(s_recv, msig.blk_ty, false, true), [], [], Utils::HashWrapper.new({}))
228
231
  if msig.blk_ty.is_a?(Type::Proc)
229
232
  scratch.add_callsite!(dummy_ctx, caller_ep, ncaller_env, &ctn)
230
233
  bsig = msig.blk_ty.block_body.msig
@@ -435,17 +435,17 @@ module TypeProf
435
435
  end
436
436
 
437
437
  class Class < Type # or Module
438
- def initialize(kind, idx, type_params, superclass, superclass_type_args, name)
438
+ def initialize(kind, idx, type_params, superclass, name)
439
439
  @kind = kind # :class | :module
440
440
  @idx = idx
441
441
  @type_params = type_params
442
442
  @superclass = superclass
443
443
  raise if @kind == :class && !@superclass
444
- @superclass_type_args = superclass_type_args
445
444
  @_name = name
446
445
  end
447
446
 
448
- attr_reader :kind, :idx, :type_params, :superclass, :superclass_type_args
447
+ attr_reader :kind, :idx, :type_params, :superclass
448
+ attr_accessor :superclass_type_args
449
449
 
450
450
  def inspect
451
451
  if @_name
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -20,6 +20,7 @@ Test.new.qux("str")
20
20
  __END__
21
21
  # Classes
22
22
  class Object
23
+ private
23
24
  def foo : (Integer) -> Integer
24
25
  def bar : (String) -> String
25
26
  end