typeprof 0.9.0 → 0.12.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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/Gemfile.lock +6 -5
- data/doc/demo.md +2 -2
- data/doc/todo.md +133 -0
- data/lib/typeprof/analyzer.rb +89 -37
- data/lib/typeprof/block.rb +34 -0
- data/lib/typeprof/builtin.rb +169 -66
- data/lib/typeprof/cli.rb +7 -0
- data/lib/typeprof/config.rb +25 -3
- data/lib/typeprof/container-type.rb +24 -0
- data/lib/typeprof/export.rb +130 -69
- data/lib/typeprof/import.rb +82 -38
- data/lib/typeprof/iseq.rb +23 -4
- data/lib/typeprof/method.rb +29 -7
- data/lib/typeprof/type.rb +75 -13
- data/lib/typeprof/version.rb +1 -1
- data/smoke/alias.rb +4 -4
- data/smoke/alias2.rb +3 -1
- data/smoke/arguments.rb +2 -2
- data/smoke/arguments2.rb +5 -5
- data/smoke/array-each.rb +1 -1
- data/smoke/array-each3.rb +1 -1
- data/smoke/array-map.rb +1 -1
- data/smoke/array-map2.rb +1 -1
- data/smoke/array-map3.rb +3 -3
- data/smoke/array-mul.rb +2 -2
- data/smoke/array-plus1.rb +1 -1
- data/smoke/array-plus2.rb +1 -0
- data/smoke/array-range-aref.rb +11 -11
- data/smoke/array-replace.rb +1 -1
- data/smoke/array1.rb +5 -5
- data/smoke/array10.rb +1 -1
- data/smoke/array11.rb +1 -1
- data/smoke/array12.rb +1 -1
- data/smoke/array14.rb +1 -1
- data/smoke/array15.rb +1 -1
- data/smoke/array2.rb +2 -2
- data/smoke/array3.rb +1 -0
- data/smoke/array6.rb +2 -1
- data/smoke/array8.rb +1 -1
- data/smoke/array9.rb +1 -1
- data/smoke/attr-module.rb +1 -0
- data/smoke/attr-vis.rb +43 -0
- data/smoke/attr-vis.rbs +4 -0
- data/smoke/attr.rb +2 -2
- data/smoke/block-ambiguous.rb +4 -4
- data/smoke/block-args1-rest.rb +6 -5
- data/smoke/block-args1.rb +5 -5
- data/smoke/block-args2-rest.rb +6 -5
- data/smoke/block-args2.rb +5 -5
- data/smoke/block-args3-rest.rb +7 -6
- data/smoke/block-args3.rb +6 -6
- data/smoke/block-blockarg.rb +3 -3
- data/smoke/block-kwarg.rb +4 -4
- data/smoke/block1.rb +1 -1
- data/smoke/block10.rb +1 -1
- data/smoke/block11.rb +2 -2
- data/smoke/block2.rb +1 -1
- data/smoke/block3.rb +1 -1
- data/smoke/block5.rb +1 -0
- data/smoke/block_given.rb +37 -0
- data/smoke/class_method.rb +2 -2
- data/smoke/class_method2.rb +2 -2
- data/smoke/constant2.rb +3 -2
- data/smoke/context-sensitive1.rb +1 -1
- data/smoke/cvar.rb +3 -2
- data/smoke/define_method.rb +2 -2
- data/smoke/define_method3.rb +1 -0
- data/smoke/define_method4.rb +1 -1
- data/smoke/define_method6.rb +19 -0
- data/smoke/demo.rb +6 -6
- data/smoke/demo1.rb +1 -1
- data/smoke/demo11.rb +1 -1
- data/smoke/demo2.rb +1 -1
- data/smoke/demo3.rb +1 -1
- data/smoke/demo4.rb +3 -3
- data/smoke/demo5.rb +1 -1
- data/smoke/demo6.rb +2 -1
- data/smoke/demo7.rb +1 -1
- data/smoke/demo9.rb +1 -0
- data/smoke/dummy-execution1.rb +1 -1
- data/smoke/dummy-execution2.rb +1 -1
- data/smoke/dummy_element.rb +1 -1
- data/smoke/ensure1.rb +1 -1
- data/smoke/enum_for.rb +15 -0
- data/smoke/enum_for2.rb +17 -0
- data/smoke/fib.rb +2 -2
- data/smoke/flow1.rb +1 -1
- data/smoke/flow10.rb +17 -0
- data/smoke/flow2.rb +1 -1
- data/smoke/flow3.rb +1 -1
- data/smoke/flow5.rb +1 -1
- data/smoke/flow6.rb +1 -1
- data/smoke/flow7.rb +1 -1
- data/smoke/flow8.rb +1 -1
- data/smoke/flow9.rb +1 -1
- data/smoke/function.rb +1 -1
- data/smoke/gvar.rb +1 -1
- data/smoke/gvar2.rb +1 -1
- data/smoke/hash-fetch.rb +3 -3
- data/smoke/inheritance.rb +4 -4
- data/smoke/initialize.rb +3 -2
- data/smoke/instance_eval.rb +1 -1
- data/smoke/int_times.rb +1 -1
- data/smoke/integer.rb +1 -1
- data/smoke/ivar.rb +3 -2
- data/smoke/ivar2.rb +2 -2
- data/smoke/ivar3.rb +2 -1
- data/smoke/ivar4.rb +21 -0
- data/smoke/kernel-class.rb +1 -1
- data/smoke/keyword4.rb +1 -1
- data/smoke/kwrest.rb +1 -0
- data/smoke/kwsplat1.rb +2 -2
- data/smoke/kwsplat2.rb +1 -1
- data/smoke/manual-rbs.rb +2 -1
- data/smoke/manual-rbs3.rb +1 -0
- data/smoke/method_in_branch.rb +1 -1
- data/smoke/method_missing.rb +4 -3
- data/smoke/module3.rb +1 -1
- data/smoke/module4.rb +1 -0
- data/smoke/module5.rb +1 -1
- data/smoke/module_function1.rb +3 -2
- data/smoke/module_function2.rb +3 -2
- data/smoke/multiple-include.rb +1 -0
- data/smoke/next1.rb +1 -1
- data/smoke/object-send1.rb +3 -3
- data/smoke/optional1.rb +1 -1
- data/smoke/optional2.rb +1 -1
- data/smoke/optional3.rb +1 -1
- data/smoke/parameterizedd-self.rb +2 -1
- data/smoke/prepend1.rb +33 -0
- data/smoke/prepend2.rb +10 -0
- data/smoke/prepend2.rbs +9 -0
- data/smoke/primitive_method.rb +19 -0
- data/smoke/proc4.rb +1 -1
- data/smoke/public.rb +4 -0
- data/smoke/range.rb +1 -1
- data/smoke/rbs-attr.rb +2 -2
- data/smoke/rbs-proc2.rb +1 -1
- data/smoke/rbs-proc3.rb +1 -1
- data/smoke/rbs-tyvar4.rb +3 -2
- data/smoke/rbs-tyvar6.rb +3 -3
- data/smoke/redo1.rb +1 -1
- data/smoke/redo2.rb +1 -1
- data/smoke/rescue1.rb +1 -1
- data/smoke/rescue2.rb +1 -1
- data/smoke/rescue3.rb +1 -0
- data/smoke/rescue4.rb +1 -1
- data/smoke/respond_to.rb +1 -1
- data/smoke/rest1.rb +2 -2
- data/smoke/rest2.rb +1 -1
- data/smoke/rest3.rb +6 -6
- data/smoke/rest4.rb +2 -2
- data/smoke/rest5.rb +1 -1
- data/smoke/rest6.rb +1 -1
- data/smoke/retry1.rb +2 -2
- data/smoke/simple.rb +12 -0
- data/smoke/step.rb +3 -3
- data/smoke/struct-keyword_init.rb +6 -16
- data/smoke/struct.rb +1 -1
- data/smoke/struct2.rb +1 -1
- data/smoke/struct3.rb +1 -1
- data/smoke/struct4.rb +1 -1
- data/smoke/struct5.rb +2 -2
- data/smoke/struct6.rb +2 -2
- data/smoke/struct7.rb +1 -1
- data/smoke/super1.rb +4 -4
- data/smoke/super3.rb +3 -2
- data/smoke/super4.rb +7 -5
- data/smoke/super5.rb +6 -4
- data/smoke/symbol-proc-attr.rb +1 -1
- data/smoke/tap1.rb +2 -2
- data/smoke/toplevel.rb +1 -1
- data/smoke/type_var.rb +3 -3
- data/smoke/user-demo.rb +1 -1
- data/smoke/wrong-extend.rb +1 -0
- data/smoke/wrong-include.rb +1 -0
- data/smoke/wrong-include2.rb +1 -1
- data/testbed/goodcheck-Gemfile.lock +1 -1
- data/typeprof.gemspec +1 -1
- metadata +19 -5
data/lib/typeprof/block.rb
CHANGED
@@ -137,4 +137,38 @@ module TypeProf
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
class CustomBlock < Block
|
142
|
+
def initialize(caller_ep, mid, &blk)
|
143
|
+
@caller_ep = caller_ep
|
144
|
+
@mid = mid
|
145
|
+
@blk = blk
|
146
|
+
end
|
147
|
+
|
148
|
+
def inspect
|
149
|
+
"#<CustomBlock>"
|
150
|
+
end
|
151
|
+
|
152
|
+
def consistent?(other)
|
153
|
+
true # XXX
|
154
|
+
end
|
155
|
+
|
156
|
+
def substitute(_subst, _depth)
|
157
|
+
self
|
158
|
+
end
|
159
|
+
|
160
|
+
def do_call(aargs, caller_ep, caller_env, scratch, replace_recv_ty:, &ctn)
|
161
|
+
aargs = scratch.globalize_type(aargs, caller_env, caller_ep)
|
162
|
+
|
163
|
+
dummy_ctx = TypedContext.new(@caller_ep, @mid)
|
164
|
+
|
165
|
+
scratch.add_block_signature!(self, aargs.to_block_signature)
|
166
|
+
scratch.add_block_to_ctx!(self, dummy_ctx)
|
167
|
+
|
168
|
+
@blk.call(aargs, caller_ep, caller_env, scratch, replace_recv_ty: replace_recv_ty) do |ret_ty, ep, env|
|
169
|
+
scratch.add_return_value!(dummy_ctx, ret_ty)
|
170
|
+
ctn[ret_ty, ep, env]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
140
174
|
end
|
data/lib/typeprof/builtin.rb
CHANGED
@@ -19,7 +19,7 @@ module TypeProf
|
|
19
19
|
klass, new_mid, old_mid = aargs.lead_tys
|
20
20
|
new_sym = get_sym("alias", new_mid, ep, scratch) or return
|
21
21
|
old_sym = get_sym("alias", old_mid, ep, scratch) or return
|
22
|
-
scratch.alias_method(klass, ep.ctx.cref.singleton, new_sym, old_sym)
|
22
|
+
scratch.alias_method(klass, ep.ctx.cref.singleton, new_sym, old_sym, ep)
|
23
23
|
ctn[Type.nil, ep, env]
|
24
24
|
end
|
25
25
|
|
@@ -163,6 +163,66 @@ module TypeProf
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
def object_enum_for(recv, mid, aargs, ep, env, scratch, &ctn)
|
167
|
+
if aargs.lead_tys.size >= 1
|
168
|
+
mid_ty, = aargs.lead_tys
|
169
|
+
naargs = ActualArguments.new(aargs.lead_tys[1..], aargs.rest_ty, aargs.kw_tys, aargs.blk_ty)
|
170
|
+
elsif aargs.rest_ty
|
171
|
+
mid_ty = aargs.rest_ty
|
172
|
+
naargs = aargs
|
173
|
+
else
|
174
|
+
mid_ty = Type::Symbol.new(:each, Type::Instance.new(Type::Builtin[:sym]))
|
175
|
+
naargs = aargs
|
176
|
+
end
|
177
|
+
|
178
|
+
elem_ty = Type.bot
|
179
|
+
enum_for_blk = CustomBlock.new(ep, mid) do |aargs, caller_ep, caller_env, scratch, replace_recv_ty:, &blk_ctn|
|
180
|
+
if aargs.lead_tys.size >= 1
|
181
|
+
elem_ty = elem_ty.union(aargs.lead_tys[0])
|
182
|
+
else
|
183
|
+
elem_ty = elem_ty.union(Type.any)
|
184
|
+
end
|
185
|
+
ctn[Type::Cell.new(Type::Cell::Elements.new([elem_ty, Type.any]), Type::Instance.new(Type::Builtin[:enumerator])), ep, env]
|
186
|
+
blk_ctn[Type.any, caller_ep, caller_env]
|
187
|
+
end
|
188
|
+
enum_for_blk_ty = Type::Proc.new(enum_for_blk, Type::Instance.new(Type::Builtin[:proc]))
|
189
|
+
|
190
|
+
naargs = ActualArguments.new(naargs.lead_tys, naargs.rest_ty, naargs.kw_tys, enum_for_blk_ty)
|
191
|
+
mid_ty.each_child do |mid|
|
192
|
+
if mid.is_a?(Type::Symbol)
|
193
|
+
mid = mid.sym
|
194
|
+
scratch.do_send(recv, mid, naargs, ep, env) do |_ret_ty, _ep|
|
195
|
+
ctn[Type::Cell.new(Type::Cell::Elements.new([elem_ty, Type.any]), Type::Instance.new(Type::Builtin[:enumerator])), ep, env]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def object_privitive_method(recv, mid, aargs, ep, env, scratch, &ctn)
|
202
|
+
ctn[Type::Symbol.new(ep.ctx.mid, Type::Instance.new(Type::Builtin[:sym])), ep, env]
|
203
|
+
end
|
204
|
+
|
205
|
+
def object_block_given?(recv, mid, aargs, ep, env, scratch, &ctn)
|
206
|
+
procs = Type.bot
|
207
|
+
no_proc = false
|
208
|
+
env.static_env.blk_ty.each_child do |blk_ty|
|
209
|
+
case blk_ty
|
210
|
+
when Type::Proc
|
211
|
+
procs = procs.union(blk_ty)
|
212
|
+
when Type.nil
|
213
|
+
no_proc = true
|
214
|
+
else
|
215
|
+
ctn[Type.bool, ep, env]
|
216
|
+
end
|
217
|
+
end
|
218
|
+
if procs != Type.bot
|
219
|
+
ctn[Type::Instance.new(Type::Builtin[:true]), ep, env.replace_blk_ty(procs)]
|
220
|
+
end
|
221
|
+
if no_proc
|
222
|
+
ctn[Type::Instance.new(Type::Builtin[:false]), ep, env.replace_blk_ty(Type.nil)]
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
166
226
|
def module_include(recv, mid, aargs, ep, env, scratch, &ctn)
|
167
227
|
if aargs.lead_tys.size != 1
|
168
228
|
scratch.warn(ep, "Module#include without an argument is ignored")
|
@@ -178,7 +238,7 @@ module TypeProf
|
|
178
238
|
arg = aargs.lead_tys[0]
|
179
239
|
arg.each_child do |arg|
|
180
240
|
if arg.is_a?(Type::Class)
|
181
|
-
scratch.
|
241
|
+
scratch.mix_module(:after, recv, arg, nil, ep.ctx.cref.singleton, ep)
|
182
242
|
end
|
183
243
|
end
|
184
244
|
ctn[recv, ep, env]
|
@@ -199,7 +259,29 @@ module TypeProf
|
|
199
259
|
arg = aargs.lead_tys[0]
|
200
260
|
arg.each_child do |arg|
|
201
261
|
if arg.is_a?(Type::Class)
|
202
|
-
|
262
|
+
# if ep.ctx.cref.singleton is true, the meta-meta level is ignored. Should we warn?
|
263
|
+
scratch.mix_module(:after, recv, arg, nil, true, ep)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
ctn[recv, ep, env]
|
267
|
+
end
|
268
|
+
|
269
|
+
def module_prepend(recv, mid, aargs, ep, env, scratch, &ctn)
|
270
|
+
if aargs.lead_tys.size != 1
|
271
|
+
scratch.warn(ep, "Module#prepend without an argument is ignored")
|
272
|
+
ctn[Type.any, ep, env]
|
273
|
+
return
|
274
|
+
end
|
275
|
+
|
276
|
+
unless recv.is_a?(Type::Class)
|
277
|
+
# XXX: warn?
|
278
|
+
return ctn[Type.any, ep, env]
|
279
|
+
end
|
280
|
+
|
281
|
+
arg = aargs.lead_tys[0]
|
282
|
+
arg.each_child do |arg|
|
283
|
+
if arg.is_a?(Type::Class)
|
284
|
+
scratch.mix_module(:before, recv, arg, nil, ep.ctx.cref.singleton, ep)
|
203
285
|
end
|
204
286
|
end
|
205
287
|
ctn[recv, ep, env]
|
@@ -268,23 +350,25 @@ module TypeProf
|
|
268
350
|
end
|
269
351
|
|
270
352
|
mid, = aargs.lead_tys
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
353
|
+
mid.each_child do |mid|
|
354
|
+
if mid.is_a?(Type::Symbol)
|
355
|
+
mid = mid.sym
|
356
|
+
aargs.blk_ty.each_child do |blk_ty|
|
357
|
+
if blk_ty.is_a?(Type::Proc)
|
358
|
+
blk = blk_ty.block_body
|
359
|
+
case blk
|
360
|
+
when ISeqBlock
|
361
|
+
scratch.do_define_iseq_method(ep, env, mid, blk.iseq, blk.outer_ep)
|
362
|
+
else
|
363
|
+
# XXX: what to do?
|
364
|
+
end
|
279
365
|
else
|
280
366
|
# XXX: what to do?
|
281
367
|
end
|
282
|
-
else
|
283
|
-
# XXX: what to do?
|
284
368
|
end
|
369
|
+
else
|
370
|
+
# XXX: what to do?
|
285
371
|
end
|
286
|
-
else
|
287
|
-
# XXX: what to do?
|
288
372
|
end
|
289
373
|
ctn[Type.any, ep, env]
|
290
374
|
end
|
@@ -293,7 +377,7 @@ module TypeProf
|
|
293
377
|
aargs.lead_tys.each do |aarg|
|
294
378
|
sym = get_sym("attr_accessor", aarg, ep, scratch) or next
|
295
379
|
cref = ep.ctx.cref
|
296
|
-
scratch.add_attr_method(cref.klass,
|
380
|
+
scratch.add_attr_method(cref.klass, sym, :"@#{ sym }", :accessor, env.static_env.pub_meth, ep)
|
297
381
|
end
|
298
382
|
ctn[Type.nil, ep, env]
|
299
383
|
end
|
@@ -302,7 +386,7 @@ module TypeProf
|
|
302
386
|
aargs.lead_tys.each do |aarg|
|
303
387
|
sym = get_sym("attr_reader", aarg, ep, scratch) or next
|
304
388
|
cref = ep.ctx.cref
|
305
|
-
scratch.add_attr_method(cref.klass,
|
389
|
+
scratch.add_attr_method(cref.klass, sym, :"@#{ sym }", :reader, env.static_env.pub_meth, ep)
|
306
390
|
end
|
307
391
|
ctn[Type.nil, ep, env]
|
308
392
|
end
|
@@ -311,7 +395,7 @@ module TypeProf
|
|
311
395
|
aargs.lead_tys.each do |aarg|
|
312
396
|
sym = get_sym("attr_writer", aarg, ep, scratch) or next
|
313
397
|
cref = ep.ctx.cref
|
314
|
-
scratch.add_attr_method(cref.klass,
|
398
|
+
scratch.add_attr_method(cref.klass, sym, :"@#{ sym }", :writer, env.static_env.pub_meth, ep)
|
315
399
|
end
|
316
400
|
ctn[Type.nil, ep, env]
|
317
401
|
end
|
@@ -444,43 +528,55 @@ module TypeProf
|
|
444
528
|
ctn[Type.any, ep, env]
|
445
529
|
return
|
446
530
|
end
|
447
|
-
scratch.add_ivar_read!(Type::Instance.new(struct_klass), :
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
531
|
+
scratch.add_ivar_read!(Type::Instance.new(struct_klass), :_keyword_init, ep) do |keyword_init, ep|
|
532
|
+
scratch.add_ivar_read!(Type::Instance.new(struct_klass), :_members, ep) do |member_ary_ty, ep|
|
533
|
+
next if member_ary_ty == Type.nil
|
534
|
+
if keyword_init == Type::Instance.new(Type::Builtin[:true])
|
535
|
+
# TODO: support kw_rest_ty
|
536
|
+
aargs.kw_tys.each do |key, val_ty|
|
537
|
+
found = false
|
538
|
+
member_ary_ty.elems.lead_tys.each do |sym|
|
539
|
+
if sym.sym == key
|
540
|
+
found = true
|
541
|
+
scratch.set_instance_variable(recv, sym.sym, val_ty, ep, env)
|
542
|
+
end
|
543
|
+
end
|
544
|
+
unless found
|
545
|
+
# TODO: what to do when not found?
|
546
|
+
end
|
547
|
+
end
|
548
|
+
else
|
549
|
+
member_ary_ty.elems.lead_tys.zip(aargs.lead_tys) do |sym, ty|
|
550
|
+
ty ||= Type.nil
|
551
|
+
scratch.set_instance_variable(recv, sym.sym, ty, ep, env)
|
552
|
+
end
|
553
|
+
end
|
452
554
|
end
|
453
555
|
end
|
454
556
|
ctn[recv, ep, env]
|
455
557
|
end
|
456
558
|
|
457
|
-
def
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
meths.flat_map do |meth|
|
463
|
-
meth.do_send(recv, :initialize, aargs, ep, env, scratch) do |ret_ty, ep, env|
|
464
|
-
ctn[recv, ep, env]
|
559
|
+
def struct_s_new(recv, mid, aargs, ep, env, scratch, &ctn)
|
560
|
+
keyword_init = false
|
561
|
+
if aargs.kw_tys && aargs.kw_tys[:keyword_init] # XXX: more canonical way to extract keyword...
|
562
|
+
if aargs.kw_tys[:keyword_init] == Type::Instance.new(Type::Builtin[:true])
|
563
|
+
keyword_init = true
|
465
564
|
end
|
466
565
|
end
|
467
|
-
end
|
468
|
-
|
469
|
-
def struct_s_new(recv, mid, aargs, ep, env, scratch, &ctn)
|
470
|
-
# TODO: keyword_init
|
471
566
|
|
472
567
|
fields = aargs.lead_tys.map {|ty| get_sym("Struct.new", ty, ep, scratch) }.compact
|
473
568
|
struct_klass = scratch.new_struct(ep)
|
474
569
|
|
475
|
-
scratch.set_singleton_custom_method(struct_klass, :new, Builtin.method(:
|
476
|
-
scratch.set_singleton_custom_method(struct_klass, :[], Builtin.method(:
|
570
|
+
scratch.set_singleton_custom_method(struct_klass, :new, Builtin.method(:object_s_new))
|
571
|
+
scratch.set_singleton_custom_method(struct_klass, :[], Builtin.method(:object_s_new))
|
477
572
|
fields.each do |field|
|
478
|
-
scratch.add_attr_method(struct_klass,
|
573
|
+
scratch.add_attr_method(struct_klass, field, field, :accessor, true, ep)
|
479
574
|
end
|
480
575
|
fields = fields.map {|field| Type::Symbol.new(field, Type::Instance.new(Type::Builtin[:sym])) }
|
481
576
|
base_ty = Type::Instance.new(Type::Builtin[:ary])
|
482
577
|
fields = Type::Array.new(Type::Array::Elements.new(fields), base_ty)
|
483
578
|
scratch.add_ivar_write!(Type::Instance.new(struct_klass), :_members, fields, ep)
|
579
|
+
scratch.add_ivar_write!(Type::Instance.new(struct_klass), :_keyword_init, Type::Instance.new(Type::Builtin[:true]), ep) if keyword_init
|
484
580
|
#set_singleton_custom_method(struct_klass, :members, Builtin.method(:...))
|
485
581
|
|
486
582
|
ctn[struct_klass, ep, env]
|
@@ -654,25 +750,26 @@ module TypeProf
|
|
654
750
|
|
655
751
|
Import.import_builtin(scratch)
|
656
752
|
|
657
|
-
Type::Builtin[:vmcore]
|
658
|
-
Type::Builtin[:int]
|
659
|
-
Type::Builtin[:float]
|
660
|
-
Type::Builtin[:rational]
|
661
|
-
Type::Builtin[:complex]
|
662
|
-
Type::Builtin[:sym]
|
663
|
-
Type::Builtin[:str]
|
664
|
-
Type::Builtin[:struct]
|
665
|
-
Type::Builtin[:ary]
|
666
|
-
Type::Builtin[:hash]
|
667
|
-
Type::Builtin[:io]
|
668
|
-
Type::Builtin[:proc]
|
669
|
-
Type::Builtin[:range]
|
670
|
-
Type::Builtin[:regexp]
|
671
|
-
Type::Builtin[:matchdata]
|
672
|
-
Type::Builtin[:class]
|
673
|
-
Type::Builtin[:module]
|
674
|
-
Type::Builtin[:exc]
|
675
|
-
Type::Builtin[:encoding]
|
753
|
+
Type::Builtin[:vmcore] = scratch.new_class(klass_obj, :VMCore, [], klass_obj, nil)
|
754
|
+
Type::Builtin[:int] = scratch.get_constant(klass_obj, :Integer)
|
755
|
+
Type::Builtin[:float] = scratch.get_constant(klass_obj, :Float)
|
756
|
+
Type::Builtin[:rational] = scratch.get_constant(klass_obj, :Rational)
|
757
|
+
Type::Builtin[:complex] = scratch.get_constant(klass_obj, :Complex)
|
758
|
+
Type::Builtin[:sym] = scratch.get_constant(klass_obj, :Symbol)
|
759
|
+
Type::Builtin[:str] = scratch.get_constant(klass_obj, :String)
|
760
|
+
Type::Builtin[:struct] = scratch.get_constant(klass_obj, :Struct)
|
761
|
+
Type::Builtin[:ary] = scratch.get_constant(klass_obj, :Array)
|
762
|
+
Type::Builtin[:hash] = scratch.get_constant(klass_obj, :Hash)
|
763
|
+
Type::Builtin[:io] = scratch.get_constant(klass_obj, :IO)
|
764
|
+
Type::Builtin[:proc] = scratch.get_constant(klass_obj, :Proc)
|
765
|
+
Type::Builtin[:range] = scratch.get_constant(klass_obj, :Range)
|
766
|
+
Type::Builtin[:regexp] = scratch.get_constant(klass_obj, :Regexp)
|
767
|
+
Type::Builtin[:matchdata] = scratch.get_constant(klass_obj, :MatchData)
|
768
|
+
Type::Builtin[:class] = scratch.get_constant(klass_obj, :Class)
|
769
|
+
Type::Builtin[:module] = scratch.get_constant(klass_obj, :Module)
|
770
|
+
Type::Builtin[:exc] = scratch.get_constant(klass_obj, :Exception)
|
771
|
+
Type::Builtin[:encoding] = scratch.get_constant(klass_obj, :Encoding)
|
772
|
+
Type::Builtin[:enumerator] = scratch.get_constant(klass_obj, :Enumerator)
|
676
773
|
|
677
774
|
klass_vmcore = Type::Builtin[:vmcore]
|
678
775
|
klass_ary = Type::Builtin[:ary]
|
@@ -687,19 +784,25 @@ module TypeProf
|
|
687
784
|
scratch.set_custom_method(klass_vmcore, :"core#raise", Builtin.method(:vmcore_raise))
|
688
785
|
scratch.set_custom_method(klass_vmcore, :lambda, Builtin.method(:lambda))
|
689
786
|
scratch.set_singleton_custom_method(klass_obj, :"new", Builtin.method(:object_s_new))
|
690
|
-
scratch.set_custom_method(klass_obj, :p, Builtin.method(:kernel_p))
|
787
|
+
scratch.set_custom_method(klass_obj, :p, Builtin.method(:kernel_p), false)
|
691
788
|
scratch.set_custom_method(klass_obj, :is_a?, Builtin.method(:object_is_a?))
|
692
789
|
scratch.set_custom_method(klass_obj, :respond_to?, Builtin.method(:object_respond_to?))
|
693
790
|
scratch.set_custom_method(klass_obj, :class, Builtin.method(:object_class))
|
694
791
|
scratch.set_custom_method(klass_obj, :send, Builtin.method(:object_send))
|
695
792
|
scratch.set_custom_method(klass_obj, :instance_eval, Builtin.method(:object_instance_eval))
|
696
|
-
scratch.set_custom_method(klass_obj, :proc, Builtin.method(:lambda))
|
793
|
+
scratch.set_custom_method(klass_obj, :proc, Builtin.method(:lambda), false)
|
794
|
+
scratch.set_custom_method(klass_obj, :__method__, Builtin.method(:object_privitive_method), false)
|
795
|
+
scratch.set_custom_method(klass_obj, :block_given?, Builtin.method(:object_block_given?), false)
|
796
|
+
|
797
|
+
scratch.set_custom_method(klass_obj, :enum_for, Builtin.method(:object_enum_for))
|
798
|
+
scratch.set_custom_method(klass_obj, :to_enum, Builtin.method(:object_enum_for))
|
697
799
|
|
698
800
|
scratch.set_custom_method(klass_module, :include, Builtin.method(:module_include))
|
699
801
|
scratch.set_custom_method(klass_module, :extend, Builtin.method(:module_extend))
|
700
|
-
scratch.set_custom_method(klass_module, :
|
701
|
-
scratch.set_custom_method(klass_module, :
|
702
|
-
scratch.set_custom_method(klass_module, :
|
802
|
+
scratch.set_custom_method(klass_module, :prepend, Builtin.method(:module_prepend))
|
803
|
+
scratch.set_custom_method(klass_module, :module_function, Builtin.method(:module_module_function), false)
|
804
|
+
scratch.set_custom_method(klass_module, :public, Builtin.method(:module_public), false)
|
805
|
+
scratch.set_custom_method(klass_module, :private, Builtin.method(:module_private), false)
|
703
806
|
scratch.set_custom_method(klass_module, :define_method, Builtin.method(:module_define_method))
|
704
807
|
scratch.set_custom_method(klass_module, :"attr_accessor", Builtin.method(:module_attr_accessor))
|
705
808
|
scratch.set_custom_method(klass_module, :"attr_reader", Builtin.method(:module_attr_reader))
|
@@ -718,10 +821,10 @@ module TypeProf
|
|
718
821
|
scratch.set_custom_method(klass_struct, :initialize, Builtin.method(:struct_initialize))
|
719
822
|
scratch.set_singleton_custom_method(klass_struct, :new, Builtin.method(:struct_s_new))
|
720
823
|
|
721
|
-
scratch.set_custom_method(klass_obj, :require, Builtin.method(:kernel_require))
|
722
|
-
scratch.set_custom_method(klass_obj, :require_relative, Builtin.method(:kernel_require_relative))
|
723
|
-
scratch.set_custom_method(klass_obj, :Array, Builtin.method(:kernel_Array))
|
724
|
-
scratch.set_custom_method(klass_obj, :autoload, Builtin.method(:kernel_autoload))
|
824
|
+
scratch.set_custom_method(klass_obj, :require, Builtin.method(:kernel_require), false)
|
825
|
+
scratch.set_custom_method(klass_obj, :require_relative, Builtin.method(:kernel_require_relative), false)
|
826
|
+
scratch.set_custom_method(klass_obj, :Array, Builtin.method(:kernel_Array), false)
|
827
|
+
scratch.set_custom_method(klass_obj, :autoload, Builtin.method(:kernel_autoload), false)
|
725
828
|
scratch.set_custom_method(klass_module, :autoload, Builtin.method(:module_autoload))
|
726
829
|
|
727
830
|
# remove BasicObject#method_missing
|
data/lib/typeprof/cli.rb
CHANGED
@@ -20,6 +20,7 @@ module TypeProf
|
|
20
20
|
options = {}
|
21
21
|
dir_filter = nil
|
22
22
|
gem_rbs_features = []
|
23
|
+
gem_repo_dirs = []
|
23
24
|
show_version = false
|
24
25
|
max_sec = max_iter = nil
|
25
26
|
|
@@ -31,6 +32,7 @@ module TypeProf
|
|
31
32
|
opt.on("--version", "Display typeprof version") { show_version = true }
|
32
33
|
opt.on("-I DIR", "Add DIR to the load/require path") {|v| $LOAD_PATH << v }
|
33
34
|
opt.on("-r FEATURE", "Require RBS of the FEATURE gem") {|v| gem_rbs_features << v }
|
35
|
+
opt.on("--repo DIR", "Add DIR to the RBS repository") {|v| gem_repo_dirs << v }
|
34
36
|
|
35
37
|
opt.separator ""
|
36
38
|
opt.separator "Analysis output options:"
|
@@ -46,8 +48,12 @@ module TypeProf
|
|
46
48
|
dir_filter ||= ConfigData::DEFAULT_DIR_FILTER
|
47
49
|
dir_filter << [:exclude, File.expand_path(dir)]
|
48
50
|
end
|
51
|
+
opt.on("--exclude-untyped", "Exclude (comment out) all entries including untyped") {|v| options[:exclude_untyped] = v }
|
52
|
+
opt.on("--[no-]show-typeprof-version", "Display TypeProf version in a header") {|v| options[:show_typeprof_version] = v }
|
49
53
|
opt.on("--[no-]show-errors", "Display possible errors found during the analysis") {|v| options[:show_errors] = v }
|
50
54
|
opt.on("--[no-]show-untyped", "Display \"Foo | untyped\" instead of \"Foo\"") {|v| options[:show_untyped] = v }
|
55
|
+
opt.on("--[no-]show-parameter-names", "Display parameter names for methods") {|v| options[:show_parameter_names] = v }
|
56
|
+
opt.on("--[no-]show-source-locations", "Display definition source locations for methods") {|v| options[:show_source_locations] = v }
|
51
57
|
|
52
58
|
opt.separator ""
|
53
59
|
opt.separator "Analysis limit options:"
|
@@ -85,6 +91,7 @@ module TypeProf
|
|
85
91
|
rbs_files: rbs_files,
|
86
92
|
output: output,
|
87
93
|
gem_rbs_features: gem_rbs_features,
|
94
|
+
gem_repo_dirs: gem_repo_dirs,
|
88
95
|
verbose: verbose,
|
89
96
|
dir_filter: dir_filter,
|
90
97
|
max_sec: max_sec,
|
data/lib/typeprof/config.rb
CHANGED
@@ -6,6 +6,7 @@ module TypeProf
|
|
6
6
|
:rbs_files,
|
7
7
|
:output,
|
8
8
|
:gem_rbs_features,
|
9
|
+
:gem_repo_dirs,
|
9
10
|
:verbose,
|
10
11
|
:dir_filter,
|
11
12
|
:max_iter,
|
@@ -14,17 +15,29 @@ module TypeProf
|
|
14
15
|
keyword_init: true
|
15
16
|
)
|
16
17
|
|
18
|
+
class TypeProfError < StandardError
|
19
|
+
def report(output)
|
20
|
+
output.puts "# Analysis Error"
|
21
|
+
output.puts message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
class ConfigData
|
18
26
|
def initialize(**opt)
|
19
27
|
opt[:output] ||= $stdout
|
20
28
|
opt[:gem_rbs_features] ||= []
|
29
|
+
opt[:gem_repo_dirs] ||= []
|
21
30
|
opt[:dir_filter] ||= DEFAULT_DIR_FILTER
|
22
31
|
opt[:verbose] ||= 0
|
23
32
|
opt[:options] ||= {}
|
24
33
|
opt[:options] = {
|
34
|
+
exclude_untyped: false,
|
35
|
+
show_typeprof_version: true,
|
25
36
|
show_indicator: true,
|
26
37
|
show_untyped: false,
|
27
38
|
show_errors: false,
|
39
|
+
show_parameter_names: true,
|
40
|
+
show_source_locations: false,
|
28
41
|
stub_execution: true,
|
29
42
|
type_depth_limit: 5,
|
30
43
|
stackprof: nil,
|
@@ -69,7 +82,7 @@ module TypeProf
|
|
69
82
|
|
70
83
|
prologue_ctx = Context.new(nil, nil, nil)
|
71
84
|
prologue_ep = ExecutionPoint.new(prologue_ctx, -1, nil)
|
72
|
-
prologue_env = Env.new(StaticEnv.new(
|
85
|
+
prologue_env = Env.new(StaticEnv.new(Type.bot, Type.nil, false, true), [], [], Utils::HashWrapper.new({}))
|
73
86
|
|
74
87
|
Config.rb_files.each do |rb|
|
75
88
|
if rb.is_a?(Array) # [String name, String content]
|
@@ -82,13 +95,19 @@ module TypeProf
|
|
82
95
|
scratch.add_callsite!(ep.ctx, prologue_ep, prologue_env) {|ty, ep| }
|
83
96
|
end
|
84
97
|
|
98
|
+
rbs_files = []
|
99
|
+
rbs_codes = []
|
85
100
|
Config.rbs_files.each do |rbs|
|
86
101
|
if rbs.is_a?(Array) # [String name, String content]
|
87
|
-
|
102
|
+
rbs_codes << rbs
|
88
103
|
else
|
89
|
-
|
104
|
+
rbs_files << rbs
|
90
105
|
end
|
91
106
|
end
|
107
|
+
Import.import_rbs_files(scratch, rbs_files)
|
108
|
+
rbs_codes.each do |name, content|
|
109
|
+
Import.import_rbs_code(scratch, name, content)
|
110
|
+
end
|
92
111
|
|
93
112
|
result = scratch.type_profile
|
94
113
|
|
@@ -100,6 +119,9 @@ module TypeProf
|
|
100
119
|
end
|
101
120
|
end
|
102
121
|
|
122
|
+
rescue TypeProfError => exc
|
123
|
+
exc.report(Config.output)
|
124
|
+
|
103
125
|
ensure
|
104
126
|
if Config.options[:stackprof] && defined?(StackProf)
|
105
127
|
StackProf.stop
|