typeprof 0.8.0 → 0.9.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/Gemfile.lock +3 -3
- data/lib/typeprof/analyzer.rb +96 -44
- data/lib/typeprof/arguments.rb +2 -0
- data/lib/typeprof/block.rb +6 -2
- data/lib/typeprof/builtin.rb +125 -62
- data/lib/typeprof/container-type.rb +5 -4
- data/lib/typeprof/export.rb +7 -7
- data/lib/typeprof/import.rb +14 -2
- data/lib/typeprof/iseq.rb +23 -7
- data/lib/typeprof/method.rb +13 -14
- data/lib/typeprof/type.rb +52 -2
- data/lib/typeprof/version.rb +1 -1
- data/smoke/alias.rb +4 -4
- data/smoke/alias2.rb +4 -4
- data/smoke/any1.rb +1 -1
- data/smoke/any2.rb +2 -2
- data/smoke/arguments.rb +2 -2
- data/smoke/arguments2.rb +10 -10
- data/smoke/array-each.rb +1 -1
- data/smoke/array-each2.rb +1 -1
- data/smoke/array-each3.rb +1 -1
- data/smoke/array-ltlt.rb +1 -1
- data/smoke/array-ltlt2.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 +2 -2
- data/smoke/array-pop.rb +1 -1
- data/smoke/array-range-aref.rb +11 -11
- data/smoke/array-replace.rb +1 -1
- data/smoke/array-s-aref.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 +3 -3
- data/smoke/array13.rb +4 -4
- data/smoke/array14.rb +1 -1
- data/smoke/array15.rb +16 -0
- data/smoke/array2.rb +3 -3
- data/smoke/array3.rb +4 -4
- data/smoke/array4.rb +1 -1
- data/smoke/array5.rb +1 -1
- data/smoke/array6.rb +2 -2
- data/smoke/array7.rb +1 -1
- data/smoke/array8.rb +1 -1
- data/smoke/array9.rb +1 -1
- data/smoke/attr-module.rb +26 -0
- data/smoke/attr.rb +5 -5
- data/smoke/autoload.rb +1 -1
- data/smoke/backtrace.rb +3 -3
- data/smoke/block-ambiguous.rb +8 -8
- data/smoke/block-args1-rest.rb +11 -11
- data/smoke/block-args1.rb +10 -10
- data/smoke/block-args2-rest.rb +11 -11
- data/smoke/block-args2.rb +10 -10
- data/smoke/block-args3-rest.rb +13 -13
- data/smoke/block-args3.rb +12 -12
- data/smoke/block-blockarg.rb +4 -4
- data/smoke/block-kwarg.rb +10 -10
- data/smoke/block1.rb +1 -1
- data/smoke/block10.rb +1 -1
- data/smoke/block11.rb +5 -5
- data/smoke/block12.rb +2 -2
- data/smoke/block14.rb +2 -2
- data/smoke/block2.rb +1 -1
- data/smoke/block3.rb +3 -3
- data/smoke/block4.rb +2 -2
- data/smoke/block5.rb +2 -2
- data/smoke/block6.rb +2 -2
- data/smoke/block7.rb +1 -1
- data/smoke/block8.rb +3 -3
- data/smoke/block9.rb +1 -1
- data/smoke/blown.rb +1 -1
- data/smoke/break1.rb +2 -2
- data/smoke/break2.rb +1 -1
- data/smoke/break3.rb +13 -0
- data/smoke/case.rb +1 -1
- data/smoke/case2.rb +1 -1
- data/smoke/case3.rb +17 -0
- data/smoke/class-hierarchy.rb +5 -5
- data/smoke/class-hierarchy2.rb +3 -3
- data/smoke/class-new.rb +15 -0
- data/smoke/class_instance_var.rb +1 -1
- data/smoke/class_method.rb +2 -2
- data/smoke/class_method2.rb +2 -2
- data/smoke/class_method3.rb +2 -2
- data/smoke/constant1.rb +6 -6
- data/smoke/constant2.rb +4 -4
- data/smoke/constant3.rb +1 -1
- data/smoke/constant4.rb +1 -1
- data/smoke/context-sensitive1.rb +1 -1
- data/smoke/cvar.rb +5 -5
- data/smoke/cvar2.rb +2 -2
- data/smoke/define_method.rb +2 -2
- data/smoke/define_method2.rb +2 -2
- data/smoke/define_method3.rb +13 -0
- data/smoke/define_method3.rbs +3 -0
- data/smoke/define_method4.rb +15 -0
- data/smoke/define_method4.rbs +3 -0
- data/smoke/define_method5.rb +12 -0
- data/smoke/demo.rb +6 -6
- data/smoke/demo1.rb +1 -1
- data/smoke/demo10.rb +2 -2
- 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 +3 -3
- data/smoke/demo7.rb +1 -1
- data/smoke/demo8.rb +2 -2
- data/smoke/demo9.rb +2 -2
- data/smoke/dummy-execution1.rb +2 -2
- data/smoke/dummy-execution2.rb +2 -2
- data/smoke/dummy_element.rb +14 -0
- data/smoke/ensure1.rb +2 -2
- data/smoke/enumerator.rb +2 -2
- data/smoke/expandarray1.rb +1 -1
- data/smoke/expandarray2.rb +1 -1
- data/smoke/fib.rb +2 -2
- data/smoke/flip-flop.rb +28 -0
- data/smoke/flow1.rb +1 -1
- 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 +12 -0
- data/smoke/freeze.rb +1 -1
- data/smoke/function.rb +2 -2
- data/smoke/gvar.rb +2 -2
- data/smoke/gvar2.rb +2 -2
- data/smoke/hash-bot.rb +12 -0
- data/smoke/hash-fetch.rb +3 -3
- data/smoke/hash-merge-bang.rb +1 -1
- data/smoke/hash1.rb +2 -2
- data/smoke/hash2.rb +1 -1
- data/smoke/hash3.rb +1 -1
- data/smoke/hash4.rb +1 -1
- data/smoke/hash5.rb +1 -1
- data/smoke/inheritance.rb +4 -4
- data/smoke/inheritance2.rb +2 -2
- data/smoke/initialize.rb +5 -5
- data/smoke/instance_eval.rb +2 -2
- data/smoke/instance_eval2.rb +10 -0
- data/smoke/instance_eval3.rb +25 -0
- data/smoke/int_times.rb +1 -1
- data/smoke/integer.rb +1 -1
- data/smoke/ivar.rb +4 -4
- data/smoke/ivar2.rb +4 -4
- data/smoke/ivar3.rb +2 -2
- data/smoke/kernel-class.rb +1 -1
- data/smoke/keyword1.rb +1 -1
- data/smoke/keyword2.rb +1 -1
- data/smoke/keyword3.rb +1 -1
- data/smoke/keyword4.rb +1 -1
- data/smoke/keyword5.rb +1 -1
- data/smoke/kwrest.rb +2 -2
- data/smoke/kwsplat1.rb +4 -4
- data/smoke/kwsplat2.rb +1 -1
- data/smoke/lit-complex.rb +10 -0
- data/smoke/lit-encoding.rb +10 -0
- data/smoke/manual-rbs.rb +3 -3
- data/smoke/manual-rbs2.rb +1 -1
- data/smoke/manual-rbs3.rb +2 -2
- data/smoke/masgn1.rb +1 -1
- data/smoke/masgn2.rb +2 -2
- data/smoke/masgn3.rb +1 -1
- data/smoke/method_in_branch.rb +2 -2
- data/smoke/method_missing.rb +4 -4
- data/smoke/module1.rb +2 -2
- data/smoke/module2.rb +1 -1
- data/smoke/module3.rb +2 -2
- data/smoke/module4.rb +2 -2
- data/smoke/module5.rb +17 -0
- data/smoke/module6.rb +40 -0
- data/smoke/module_function1.rb +3 -3
- data/smoke/module_function2.rb +3 -3
- data/smoke/multiple-include.rb +1 -1
- data/smoke/multiple-superclass.rb +1 -1
- data/smoke/next1.rb +2 -2
- data/smoke/next2.rb +1 -1
- data/smoke/object-send1.rb +3 -3
- data/smoke/object-send2.rb +10 -0
- data/smoke/object-send3.rb +18 -0
- data/smoke/once.rb +1 -1
- data/smoke/optional1.rb +1 -1
- data/smoke/optional2.rb +1 -1
- data/smoke/optional3.rb +1 -1
- data/smoke/parameterizedd-self.rb +2 -2
- data/smoke/parameterizedd-self2.rb +1 -1
- data/smoke/pathname1.rb +1 -1
- data/smoke/pathname2.rb +1 -1
- data/smoke/pattern-match1.rb +1 -1
- data/smoke/pattern-match2.rb +1 -1
- data/smoke/printf.rb +2 -2
- data/smoke/proc.rb +2 -2
- data/smoke/proc2.rb +1 -1
- data/smoke/proc3.rb +1 -1
- data/smoke/proc4.rb +1 -1
- data/smoke/proc5.rb +19 -0
- data/smoke/public.rb +34 -0
- data/smoke/range.rb +1 -1
- data/smoke/rbs-alias.rb +1 -1
- data/smoke/rbs-attr.rb +3 -3
- data/smoke/rbs-attr2.rb +1 -1
- data/smoke/rbs-extend.rb +1 -1
- data/smoke/rbs-interface.rb +4 -4
- data/smoke/rbs-module.rb +26 -0
- data/smoke/rbs-module.rbs +4 -0
- data/smoke/rbs-opt-and-rest.rb +10 -0
- data/smoke/rbs-opt-and-rest.rbs +3 -0
- data/smoke/rbs-proc1.rb +1 -1
- data/smoke/rbs-proc2.rb +2 -2
- data/smoke/rbs-proc3.rb +1 -1
- data/smoke/rbs-record.rb +2 -2
- data/smoke/rbs-tyvar.rb +2 -2
- data/smoke/rbs-tyvar2.rb +2 -2
- data/smoke/rbs-tyvar3.rb +2 -2
- data/smoke/rbs-tyvar4.rb +3 -3
- data/smoke/rbs-tyvar5.rb +1 -1
- data/smoke/rbs-tyvar6.rb +3 -3
- data/smoke/rbs-tyvar7.rb +1 -1
- data/smoke/rbs-vars.rb +6 -6
- data/smoke/redo1.rb +2 -2
- data/smoke/redo2.rb +2 -2
- data/smoke/req-keyword.rb +1 -1
- data/smoke/rescue1.rb +2 -2
- data/smoke/rescue2.rb +2 -2
- data/smoke/rescue3.rb +19 -0
- data/smoke/rescue4.rb +17 -0
- data/smoke/respond_to.rb +1 -1
- data/smoke/rest-farg.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/return.rb +1 -1
- data/smoke/singleton_method.rb +1 -1
- data/smoke/step.rb +3 -3
- data/smoke/string-split.rb +1 -1
- data/smoke/struct-keyword_init.rb +20 -0
- data/smoke/struct.rb +1 -1
- data/smoke/struct2.rb +4 -4
- data/smoke/struct3.rb +2 -2
- data/smoke/struct4.rb +7 -0
- data/smoke/struct5.rb +16 -0
- data/smoke/struct6.rb +15 -0
- data/smoke/struct7.rb +17 -0
- data/smoke/stub-keyword.rb +10 -0
- data/smoke/super1.rb +4 -4
- data/smoke/super2.rb +1 -1
- data/smoke/super3.rb +3 -3
- data/smoke/super4.rb +5 -5
- data/smoke/super5.rb +4 -4
- data/smoke/svar1.rb +1 -1
- data/smoke/symbol-proc-attr.rb +22 -0
- data/smoke/symbol-proc-attr2.rb +15 -0
- data/smoke/symbol-proc-bot.rb +13 -0
- data/smoke/symbol-proc.rb +3 -3
- data/smoke/tap1.rb +2 -2
- data/smoke/toplevel.rb +1 -1
- data/smoke/two-map.rb +2 -2
- data/smoke/type_var.rb +1 -1
- data/smoke/typed_method.rb +1 -1
- data/smoke/uninitialize-var.rb +1 -1
- data/smoke/union-recv.rb +2 -2
- data/smoke/user-demo.rb +3 -3
- data/smoke/wrong-extend.rb +2 -2
- data/smoke/wrong-include.rb +2 -2
- data/smoke/wrong-include2.rb +17 -0
- data/typeprof.gemspec +1 -1
- metadata +44 -5
- data/tools/stackprof-wrapper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3bf54ec6fee3b06397893d2f10f1fae8e7af82b8f1640a4ddd305c33922ff7
|
4
|
+
data.tar.gz: 944d40a75789b4805e53ca70e169fe68fcd4dbca7f24bc4ccc779964085e980d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726cdbfcda694f189a96f3f35088cbcbd9a3064e79e3838f7758d7bc393bf8591c0559db1c17993f971f9ae2ee4ca3b4c09f5c0ef6d6675752b00b6948cdfe62
|
7
|
+
data.tar.gz: b2b7353855183df391d8bc78c247eb7de09c1b65b2753789eb1e1fb0208275d10fec6d2d95745f36771de30af5e32281476100a0654db6f7cf87c8e442b36a65
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
typeprof (0.
|
5
|
-
rbs (>= 0.
|
4
|
+
typeprof (0.9.0)
|
5
|
+
rbs (>= 0.20.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
docile (1.3.2)
|
12
12
|
power_assert (1.2.0)
|
13
13
|
rake (13.0.1)
|
14
|
-
rbs (0.
|
14
|
+
rbs (0.20.1)
|
15
15
|
simplecov (0.20.0)
|
16
16
|
docile (~> 1.1)
|
17
17
|
simplecov-html (~> 0.11)
|
data/lib/typeprof/analyzer.rb
CHANGED
@@ -34,6 +34,14 @@ module TypeProf
|
|
34
34
|
end
|
35
35
|
|
36
36
|
attr_reader :iseq, :cref, :mid
|
37
|
+
|
38
|
+
def source_location(pc)
|
39
|
+
if @iseq
|
40
|
+
@iseq.source_location(pc)
|
41
|
+
else
|
42
|
+
"<builtin>"
|
43
|
+
end
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
class TypedContext
|
@@ -45,6 +53,14 @@ module TypeProf
|
|
45
53
|
end
|
46
54
|
|
47
55
|
attr_reader :caller_ep, :mid
|
56
|
+
|
57
|
+
def source_location(_pc)
|
58
|
+
if @caller_ep
|
59
|
+
@caller_ep.source_location
|
60
|
+
else
|
61
|
+
"<typed-context:#{ @mid }>"
|
62
|
+
end
|
63
|
+
end
|
48
64
|
end
|
49
65
|
|
50
66
|
class ExecutionPoint
|
@@ -71,12 +87,7 @@ module TypeProf
|
|
71
87
|
end
|
72
88
|
|
73
89
|
def source_location
|
74
|
-
|
75
|
-
if iseq
|
76
|
-
iseq.source_location(@pc)
|
77
|
-
else
|
78
|
-
"<builtin>"
|
79
|
-
end
|
90
|
+
@ctx.source_location(@pc)
|
80
91
|
end
|
81
92
|
end
|
82
93
|
|
@@ -91,7 +102,7 @@ module TypeProf
|
|
91
102
|
|
92
103
|
return if recv_ty == :top #OK
|
93
104
|
recv_ty.each_child_global do |ty|
|
94
|
-
raise ty.inspect if !ty.is_a?(Type::Instance) && !ty.is_a?(Type::Class) && ty != Type.any
|
105
|
+
raise ty.inspect if !ty.is_a?(Type::Instance) && !ty.is_a?(Type::Class) && !ty.is_a?(Type::Symbol) && ty != Type.any
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
@@ -298,8 +309,8 @@ module TypeProf
|
|
298
309
|
attr_accessor :name, :klass_obj
|
299
310
|
|
300
311
|
def include_module(mod, type_args, singleton, absolute_path)
|
301
|
-
|
302
|
-
if
|
312
|
+
mod_, module_type_args, absolute_paths = @modules[singleton].find {|m,| m == mod }
|
313
|
+
if mod_
|
303
314
|
raise "inconsistent include/extend type args in RBS?" if module_type_args != type_args && type_args != [] && type_args != nil
|
304
315
|
else
|
305
316
|
absolute_paths = Utils::MutableSet.new
|
@@ -335,11 +346,14 @@ module TypeProf
|
|
335
346
|
end
|
336
347
|
end
|
337
348
|
|
338
|
-
def search_method(singleton, mid, &blk)
|
349
|
+
def search_method(singleton, mid, visited, &blk)
|
350
|
+
# Currently, circular inclusion of modules is allowed
|
351
|
+
return if visited[self]
|
352
|
+
visited[self] = true
|
339
353
|
mthds = @methods[[singleton, mid]]
|
340
354
|
yield mthds, @klass_obj, singleton if mthds
|
341
355
|
@modules[singleton].each do |mod_def,|
|
342
|
-
mod_def.search_method(false, mid, &blk)
|
356
|
+
mod_def.search_method(false, mid, visited, &blk)
|
343
357
|
end
|
344
358
|
end
|
345
359
|
|
@@ -367,7 +381,7 @@ module TypeProf
|
|
367
381
|
end
|
368
382
|
end
|
369
383
|
|
370
|
-
def include_module(including_mod, included_mod, type_args, singleton,
|
384
|
+
def include_module(including_mod, included_mod, type_args, singleton, caller_ep)
|
371
385
|
return if included_mod == Type.any
|
372
386
|
|
373
387
|
including_mod = @class_defs[including_mod.idx]
|
@@ -375,9 +389,9 @@ module TypeProf
|
|
375
389
|
if included_mod.is_a?(Type::Class)
|
376
390
|
included_mod = @class_defs[included_mod.idx]
|
377
391
|
if included_mod && included_mod.kind == :module
|
378
|
-
including_mod.include_module(included_mod, type_args, singleton, absolute_path)
|
392
|
+
including_mod.include_module(included_mod, type_args, singleton, caller_ep ? caller_ep.ctx.iseq.absolute_path : nil)
|
379
393
|
else
|
380
|
-
warn "including something that is not a module"
|
394
|
+
warn(caller_ep, "including something that is not a module")
|
381
395
|
end
|
382
396
|
end
|
383
397
|
end
|
@@ -479,13 +493,13 @@ module TypeProf
|
|
479
493
|
if klass.kind == :class
|
480
494
|
while klass != :__root__
|
481
495
|
class_def = @class_defs[klass.idx]
|
482
|
-
class_def.search_method(singleton, mid, &blk)
|
496
|
+
class_def.search_method(singleton, mid, {}, &blk)
|
483
497
|
klass = klass.superclass
|
484
498
|
end
|
485
499
|
else
|
486
500
|
# module
|
487
501
|
class_def = @class_defs[klass.idx]
|
488
|
-
class_def.search_method(singleton, mid, &blk)
|
502
|
+
class_def.search_method(singleton, mid, {}, &blk)
|
489
503
|
end
|
490
504
|
if singleton
|
491
505
|
search_method(Type::Builtin[klass_orig.kind], false, mid, &blk)
|
@@ -545,9 +559,7 @@ module TypeProf
|
|
545
559
|
end
|
546
560
|
|
547
561
|
def add_constant(klass, name, value, user_defined)
|
548
|
-
if klass
|
549
|
-
self
|
550
|
-
else
|
562
|
+
if klass.is_a?(Type::Class)
|
551
563
|
@class_defs[klass.idx].add_constant(name, value, user_defined)
|
552
564
|
end
|
553
565
|
end
|
@@ -613,6 +625,10 @@ module TypeProf
|
|
613
625
|
@iseq_method_to_ctxs[iseq_mdef] << ctx
|
614
626
|
end
|
615
627
|
|
628
|
+
def add_executed_iseq(iseq)
|
629
|
+
@executed_iseqs << iseq
|
630
|
+
end
|
631
|
+
|
616
632
|
def add_callsite!(callee_ctx, caller_ep, caller_env, &ctn)
|
617
633
|
@executed_iseqs << callee_ctx.iseq if callee_ctx.is_a?(Context)
|
618
634
|
|
@@ -672,7 +688,7 @@ module TypeProf
|
|
672
688
|
def add_read!(site, ep, &ctn)
|
673
689
|
entry = @tbl[site] ||= Entry.new(false, {}, Type.bot, Utils::MutableSet.new)
|
674
690
|
entry.read_continuations[ep] = ctn
|
675
|
-
entry.absolute_paths << ep.ctx.iseq.absolute_path
|
691
|
+
entry.absolute_paths << ep.ctx.iseq.absolute_path if ep.ctx.is_a?(Context)
|
676
692
|
ctn[entry.type, ep]
|
677
693
|
end
|
678
694
|
|
@@ -731,6 +747,7 @@ module TypeProf
|
|
731
747
|
|
732
748
|
def add_cvar_read!(klass, var, ep, &ctn)
|
733
749
|
klass.each_child do |klass|
|
750
|
+
next unless klass.is_a?(Type::Class)
|
734
751
|
class_def = @class_defs[klass.idx]
|
735
752
|
next unless class_def
|
736
753
|
class_def.cvars.add_read!(var, ep, &ctn)
|
@@ -739,6 +756,7 @@ module TypeProf
|
|
739
756
|
|
740
757
|
def add_cvar_write!(klass, var, ty, ep)
|
741
758
|
klass.each_child do |klass|
|
759
|
+
next unless klass.is_a?(Type::Class)
|
742
760
|
class_def = @class_defs[klass.idx]
|
743
761
|
next unless class_def
|
744
762
|
class_def.cvars.add_write!(var, ty, ep, self)
|
@@ -870,7 +888,7 @@ module TypeProf
|
|
870
888
|
@pending_execution.delete(iseq)
|
871
889
|
end while @executed_iseqs.include?(iseq)
|
872
890
|
|
873
|
-
puts "DEBUG: trigger
|
891
|
+
puts "DEBUG: trigger stub execution (#{ iseq&.name || "(nil)" }): rest #{ @pending_execution.size }" if Config.verbose >= 2
|
874
892
|
|
875
893
|
break if !iseq
|
876
894
|
case kind
|
@@ -974,10 +992,14 @@ module TypeProf
|
|
974
992
|
|
975
993
|
def pend_block_dummy_execution(blk, iseq, nep, nenv)
|
976
994
|
@pending_execution[iseq] ||= [:block, [blk, {}]]
|
977
|
-
if @pending_execution[iseq][
|
978
|
-
|
995
|
+
if @pending_execution[iseq][0] == :block
|
996
|
+
if @pending_execution[iseq][1][1][nep]
|
997
|
+
@pending_execution[iseq][1][1][nep] = @pending_execution[iseq][1][1][nep].merge(nenv)
|
998
|
+
else
|
999
|
+
@pending_execution[iseq][1][1][nep] = nenv
|
1000
|
+
end
|
979
1001
|
else
|
980
|
-
|
1002
|
+
# XXX: what to do?
|
981
1003
|
end
|
982
1004
|
end
|
983
1005
|
|
@@ -1026,7 +1048,7 @@ module TypeProf
|
|
1026
1048
|
block_start = iseq.fargs_format[:block_start]
|
1027
1049
|
|
1028
1050
|
lead_tys = env.locals[0, lead_num].map {|ty| globalize_type(ty, env, ep) }
|
1029
|
-
opt_tys = opt.size > 1 ? env.locals[lead_num, opt.size - 1].map {|ty| globalize_type(ty, env, ep) } :
|
1051
|
+
opt_tys = opt.size > 1 ? env.locals[lead_num, opt.size - 1].map {|ty| globalize_type(ty, env, ep) } : []
|
1030
1052
|
if rest_start # XXX:squash
|
1031
1053
|
ty = globalize_type(env.locals[lead_num + opt.size - 1], env, ep)
|
1032
1054
|
rest_ty = Type.bot
|
@@ -1197,11 +1219,11 @@ module TypeProf
|
|
1197
1219
|
else # module
|
1198
1220
|
superclass = nil
|
1199
1221
|
end
|
1200
|
-
if cbase
|
1201
|
-
klass = Type.any
|
1202
|
-
else
|
1222
|
+
if cbase.is_a?(Type::Class)
|
1203
1223
|
klass = new_class(cbase, id, [], superclass, ep.ctx.iseq.absolute_path)
|
1204
1224
|
add_superclass_type_args!(klass, superclass.type_params.map { Type.any }) if superclass
|
1225
|
+
else
|
1226
|
+
klass = Type.any
|
1205
1227
|
end
|
1206
1228
|
end
|
1207
1229
|
singleton = false
|
@@ -1339,11 +1361,24 @@ module TypeProf
|
|
1339
1361
|
return
|
1340
1362
|
when :break
|
1341
1363
|
tmp_ep = ep
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1364
|
+
while true
|
1365
|
+
if tmp_ep.ctx.iseq.type == :block
|
1366
|
+
tmp_ep = tmp_ep.outer
|
1367
|
+
nenv = @return_envs[tmp_ep].push(ty)
|
1368
|
+
merge_env(tmp_ep.next, nenv)
|
1369
|
+
break
|
1370
|
+
end
|
1371
|
+
_type, _iseq, cont, stack_depth = tmp_ep.ctx.iseq.catch_table[tmp_ep.pc]&.find {|type,| type == :break }
|
1372
|
+
if cont
|
1373
|
+
nenv = @return_envs[tmp_ep]
|
1374
|
+
nenv, = nenv.pop(nenv.stack.size - stack_depth)
|
1375
|
+
nenv = nenv.push(ty)
|
1376
|
+
tmp_ep = tmp_ep.jump(cont)
|
1377
|
+
merge_env(tmp_ep, nenv)
|
1378
|
+
break
|
1379
|
+
end
|
1380
|
+
tmp_ep = tmp_ep.outer
|
1381
|
+
end
|
1347
1382
|
when :next, :redo
|
1348
1383
|
# begin; rescue; next; end
|
1349
1384
|
tmp_ep = ep.outer
|
@@ -1585,7 +1620,7 @@ module TypeProf
|
|
1585
1620
|
warn(ep, "already initialized constant #{ Type::Instance.new(cbase).screen_name(self) }::#{ name }")
|
1586
1621
|
end
|
1587
1622
|
ty.each_child do |ty|
|
1588
|
-
if ty.is_a?(Type::Class) && ty.superclass == Type::Builtin[:struct]
|
1623
|
+
if ty.is_a?(Type::Class) && cbase.is_a?(Type::Class) && ty.superclass == Type::Builtin[:struct]
|
1589
1624
|
@class_defs[ty.idx].name = cbase_path(cbase) + [name]
|
1590
1625
|
end
|
1591
1626
|
end
|
@@ -1594,7 +1629,6 @@ module TypeProf
|
|
1594
1629
|
when :getspecial
|
1595
1630
|
key, type = operands
|
1596
1631
|
if type == 0
|
1597
|
-
raise NotImplementedError
|
1598
1632
|
case key
|
1599
1633
|
when 0 # VM_SVAR_LASTLINE
|
1600
1634
|
env = env.push(Type.any) # or String | NilClass only?
|
@@ -1612,8 +1646,12 @@ module TypeProf
|
|
1612
1646
|
return
|
1613
1647
|
end
|
1614
1648
|
when :setspecial
|
1615
|
-
|
1616
|
-
|
1649
|
+
key, = operands
|
1650
|
+
if key >= 2 # flip-flop
|
1651
|
+
env, = env.pop(1)
|
1652
|
+
else
|
1653
|
+
raise "unknown setspecial key: #{ key }"
|
1654
|
+
end
|
1617
1655
|
|
1618
1656
|
when :dup
|
1619
1657
|
env, (ty,) = env.pop(1)
|
@@ -1664,10 +1702,16 @@ module TypeProf
|
|
1664
1702
|
env = env.push(Type.optional(sym_ty))
|
1665
1703
|
when :checkmatch
|
1666
1704
|
flag, = operands
|
1705
|
+
|
1706
|
+
# This flag means that the stack top is an array, and the check needs to be applied to find all elements
|
1707
|
+
# However, currently TypeProf uses very conservative interpretation (all check returns both true and false),
|
1708
|
+
# so we just ignore the flag now
|
1667
1709
|
_array = flag & 4 != 0
|
1710
|
+
|
1668
1711
|
case flag & 3
|
1669
|
-
when 1
|
1670
|
-
|
1712
|
+
when 1 # VM_CHECKMATCH_TYPE_WHEN
|
1713
|
+
env, = env.pop(2)
|
1714
|
+
env = env.push(Type.bool)
|
1671
1715
|
when 2 # VM_CHECKMATCH_TYPE_CASE
|
1672
1716
|
env, = env.pop(2)
|
1673
1717
|
env = env.push(Type.bool)
|
@@ -1877,6 +1921,10 @@ module TypeProf
|
|
1877
1921
|
rest_ty = aargs.last
|
1878
1922
|
aargs = aargs[0..-2]
|
1879
1923
|
if flag_args_kw_splat
|
1924
|
+
# XXX: The types contained in ActualArguments are expected to be all local types.
|
1925
|
+
# This "globalize_type" breaks the invariant, and violates the assertion of Union#globalize that asserts @elems be nil.
|
1926
|
+
# To fix this issue fundamentally, ActualArguments should keep all arguments as-is (as like the VM does),
|
1927
|
+
# and globalize some types on the on-demand bases.
|
1880
1928
|
ty = globalize_type(rest_ty, env, ep)
|
1881
1929
|
if ty.is_a?(Type::Array)
|
1882
1930
|
_, (ty,) = ty.elems.take_last(1)
|
@@ -1909,6 +1957,10 @@ module TypeProf
|
|
1909
1957
|
aargs = ActualArguments.new(aargs, rest_ty, kw_tys, blk_ty)
|
1910
1958
|
elsif flag_args_kw_splat
|
1911
1959
|
last = aargs.last
|
1960
|
+
# XXX: The types contained in ActualArguments are expected to be all local types.
|
1961
|
+
# This "globalize_type" breaks the invariant, and violates the assertion of Union#globalize that asserts @elems be nil.
|
1962
|
+
# To fix this issue fundamentally, ActualArguments should keep all arguments as-is (as like the VM does),
|
1963
|
+
# and globalize some types on the on-demand bases.
|
1912
1964
|
ty = globalize_type(last, env, ep)
|
1913
1965
|
case ty
|
1914
1966
|
when Type::Hash
|
@@ -2003,10 +2055,10 @@ module TypeProf
|
|
2003
2055
|
|
2004
2056
|
def do_define_iseq_method(ep, env, mid, iseq, outer_ep)
|
2005
2057
|
cref = ep.ctx.cref
|
2006
|
-
recv = env.static_env.recv_ty
|
2007
2058
|
if cref.klass.is_a?(Type::Class)
|
2008
2059
|
typed_mdef = check_typed_method(cref.klass, mid, ep.ctx.cref.singleton)
|
2009
|
-
recv =
|
2060
|
+
recv = cref.klass
|
2061
|
+
recv = Type::Instance.new(recv) unless ep.ctx.cref.singleton
|
2010
2062
|
if typed_mdef
|
2011
2063
|
mdef = ISeqMethodDef.new(iseq, cref, outer_ep, env.static_env.pub_meth)
|
2012
2064
|
typed_mdef.each do |typed_mdef|
|
@@ -2021,9 +2073,9 @@ module TypeProf
|
|
2021
2073
|
add_singleton_iseq_method(cref.klass, mid, iseq, cref, outer_ep, true)
|
2022
2074
|
end
|
2023
2075
|
end
|
2024
|
-
|
2025
|
-
pend_method_execution(iseq, meth, recv, mid, ep.ctx.cref, outer_ep)
|
2026
2076
|
end
|
2077
|
+
|
2078
|
+
pend_method_execution(iseq, meth, recv, mid, ep.ctx.cref, outer_ep)
|
2027
2079
|
else
|
2028
2080
|
# XXX: what to do?
|
2029
2081
|
end
|
@@ -2069,7 +2121,7 @@ module TypeProf
|
|
2069
2121
|
next unless @block_to_ctx[blk.block_body] # this occurs when screen_name is called before type-profiling finished (e.g., error message)
|
2070
2122
|
@block_to_ctx[blk.block_body].each do |blk_ctx|
|
2071
2123
|
if farg_tys
|
2072
|
-
farg_tys = farg_tys.
|
2124
|
+
farg_tys = farg_tys.merge_as_block_arguments(@method_signatures[blk_ctx])
|
2073
2125
|
else
|
2074
2126
|
farg_tys = @method_signatures[blk_ctx]
|
2075
2127
|
end
|
data/lib/typeprof/arguments.rb
CHANGED
@@ -3,6 +3,7 @@ module TypeProf
|
|
3
3
|
class ActualArguments
|
4
4
|
def initialize(lead_tys, rest_ty, kw_tys, blk_ty)
|
5
5
|
@lead_tys = lead_tys
|
6
|
+
raise unless lead_tys
|
6
7
|
@rest_ty = rest_ty
|
7
8
|
@kw_tys = kw_tys # kw_tys should be {:key1 => Type, :key2 => Type, ...} or {nil => Type}
|
8
9
|
raise if !kw_tys.is_a?(::Hash)
|
@@ -58,6 +59,7 @@ module TypeProf
|
|
58
59
|
subst = Type.merge_substitution(subst, subst2)
|
59
60
|
end
|
60
61
|
msig.opt_tys.each do |farg|
|
62
|
+
break if aargs.empty?
|
61
63
|
aarg = aargs.shift
|
62
64
|
return nil unless subst2 = Type.match?(aarg, farg)
|
63
65
|
subst = Type.merge_substitution(subst, subst2)
|
data/lib/typeprof/block.rb
CHANGED
@@ -29,7 +29,10 @@ module TypeProf
|
|
29
29
|
|
30
30
|
def do_call(aargs, caller_ep, caller_env, scratch, replace_recv_ty:, &ctn)
|
31
31
|
blk_env = scratch.return_envs[@outer_ep]
|
32
|
-
|
32
|
+
if replace_recv_ty
|
33
|
+
replace_recv_ty = scratch.globalize_type(replace_recv_ty, caller_env, caller_ep)
|
34
|
+
blk_env = blk_env.replace_recv_ty(replace_recv_ty)
|
35
|
+
end
|
33
36
|
aargs = scratch.globalize_type(aargs, caller_env, caller_ep)
|
34
37
|
|
35
38
|
scratch.add_block_signature!(self, aargs.to_block_signature)
|
@@ -119,11 +122,12 @@ module TypeProf
|
|
119
122
|
def do_call(aargs, caller_ep, caller_env, scratch, replace_recv_ty:, &ctn)
|
120
123
|
if aargs.lead_tys.size >= 1
|
121
124
|
recv = aargs.lead_tys[0]
|
125
|
+
recv = Type.any if recv == Type.bot
|
122
126
|
aargs = ActualArguments.new(aargs.lead_tys[1..], aargs.rest_ty, aargs.kw_tys, aargs.blk_ty)
|
123
127
|
elsif aargs.rest_ty
|
124
128
|
recv = aargs.rest_ty.elems.squash_or_any # XXX: need to shift
|
125
129
|
else
|
126
|
-
|
130
|
+
recv = Type.any
|
127
131
|
end
|
128
132
|
|
129
133
|
scratch.add_block_signature!(self, aargs.to_block_signature)
|
data/lib/typeprof/builtin.rb
CHANGED
@@ -82,14 +82,17 @@ module TypeProf
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def object_is_a?(recv, mid, aargs, ep, env, scratch, &ctn)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
if aargs.lead_tys.size == 1
|
86
|
+
if recv.is_a?(Type::Instance)
|
87
|
+
if recv.klass == aargs.lead_tys[0] # XXX: inheritance
|
88
|
+
true_val = Type::Instance.new(Type::Builtin[:true])
|
89
|
+
ctn[true_val, ep, env]
|
90
|
+
else
|
91
|
+
false_val = Type::Instance.new(Type::Builtin[:false])
|
92
|
+
ctn[false_val, ep, env]
|
93
|
+
end
|
90
94
|
else
|
91
|
-
|
92
|
-
ctn[false_val, ep, env]
|
95
|
+
ctn[Type.bool, ep, env]
|
93
96
|
end
|
94
97
|
else
|
95
98
|
ctn[Type.bool, ep, env]
|
@@ -97,16 +100,19 @@ module TypeProf
|
|
97
100
|
end
|
98
101
|
|
99
102
|
def object_respond_to?(recv, mid, aargs, ep, env, scratch, &ctn)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
if aargs.lead_tys.size == 1
|
104
|
+
sym = get_sym("respond_to?", aargs.lead_tys[0], ep, scratch)
|
105
|
+
if sym
|
106
|
+
klass, singleton = recv.method_dispatch_info
|
107
|
+
if scratch.get_method(klass, singleton, sym)
|
108
|
+
true_val = Type::Instance.new(Type::Builtin[:true])
|
109
|
+
ctn[true_val, ep, env]
|
110
|
+
else
|
111
|
+
false_val = Type::Instance.new(Type::Builtin[:false])
|
112
|
+
ctn[false_val, ep, env]
|
113
|
+
end
|
107
114
|
else
|
108
|
-
|
109
|
-
ctn[false_val, ep, env]
|
115
|
+
ctn[Type.bool, ep, env]
|
110
116
|
end
|
111
117
|
else
|
112
118
|
ctn[Type.bool, ep, env]
|
@@ -124,10 +130,12 @@ module TypeProf
|
|
124
130
|
def object_send(recv, mid, aargs, ep, env, scratch, &ctn)
|
125
131
|
if aargs.lead_tys.size >= 1
|
126
132
|
mid_ty, = aargs.lead_tys
|
127
|
-
|
133
|
+
elsif aargs.rest_ty
|
128
134
|
mid_ty = aargs.rest_ty
|
135
|
+
else
|
136
|
+
return ctn[Type.any, ep, env]
|
129
137
|
end
|
130
|
-
aargs = ActualArguments.new(aargs.lead_tys[1
|
138
|
+
aargs = ActualArguments.new(aargs.lead_tys[1..] || [], aargs.rest_ty, aargs.kw_tys, aargs.blk_ty)
|
131
139
|
found = false
|
132
140
|
mid_ty.each_child do |mid|
|
133
141
|
if mid.is_a?(Type::Symbol)
|
@@ -148,8 +156,10 @@ module TypeProf
|
|
148
156
|
return
|
149
157
|
end
|
150
158
|
naargs = ActualArguments.new([recv], nil, {}, Type.nil)
|
151
|
-
|
152
|
-
|
159
|
+
nrecv = recv
|
160
|
+
nrecv = nrecv.base_type if nrecv.is_a?(Type::ContainerType)
|
161
|
+
scratch.do_invoke_block(aargs.blk_ty, naargs, ep, env, replace_recv_ty: nrecv) do |_ret_ty, ep|
|
162
|
+
ctn[recv, ep, env]
|
153
163
|
end
|
154
164
|
end
|
155
165
|
|
@@ -159,10 +169,16 @@ module TypeProf
|
|
159
169
|
ctn[Type.any, ep, env]
|
160
170
|
return
|
161
171
|
end
|
172
|
+
|
173
|
+
unless recv.is_a?(Type::Class)
|
174
|
+
# XXX: warn?
|
175
|
+
return ctn[Type.any, ep, env]
|
176
|
+
end
|
177
|
+
|
162
178
|
arg = aargs.lead_tys[0]
|
163
179
|
arg.each_child do |arg|
|
164
180
|
if arg.is_a?(Type::Class)
|
165
|
-
scratch.include_module(recv, arg, nil, false, ep
|
181
|
+
scratch.include_module(recv, arg, nil, false, ep)
|
166
182
|
end
|
167
183
|
end
|
168
184
|
ctn[recv, ep, env]
|
@@ -174,10 +190,16 @@ module TypeProf
|
|
174
190
|
ctn[Type.any, ep, env]
|
175
191
|
return
|
176
192
|
end
|
193
|
+
|
194
|
+
unless recv.is_a?(Type::Class)
|
195
|
+
# XXX: warn?
|
196
|
+
return ctn[Type.any, ep, env]
|
197
|
+
end
|
198
|
+
|
177
199
|
arg = aargs.lead_tys[0]
|
178
200
|
arg.each_child do |arg|
|
179
201
|
if arg.is_a?(Type::Class)
|
180
|
-
scratch.include_module(recv, arg, nil, true, ep
|
202
|
+
scratch.include_module(recv, arg, nil, true, ep)
|
181
203
|
end
|
182
204
|
end
|
183
205
|
ctn[recv, ep, env]
|
@@ -202,13 +224,17 @@ module TypeProf
|
|
202
224
|
if aargs.lead_tys.empty?
|
203
225
|
ctn[recv, ep, env.method_public_set(true)]
|
204
226
|
else
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
227
|
+
if recv.is_a?(Type::Class)
|
228
|
+
aargs.lead_tys.each do |aarg|
|
229
|
+
sym = get_sym("public", aarg, ep, scratch) or next
|
230
|
+
meths = scratch.get_method(recv, false, sym)
|
231
|
+
next unless meths
|
232
|
+
meths.each do |mdef|
|
233
|
+
mdef.pub_meth = true if mdef.respond_to?(:pub_meth=)
|
234
|
+
end
|
211
235
|
end
|
236
|
+
else
|
237
|
+
# XXX: warn?
|
212
238
|
end
|
213
239
|
ctn[recv, ep, env]
|
214
240
|
end
|
@@ -218,13 +244,17 @@ module TypeProf
|
|
218
244
|
if aargs.lead_tys.empty?
|
219
245
|
ctn[recv, ep, env.method_public_set(false)]
|
220
246
|
else
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
247
|
+
if recv.is_a?(Type::Class)
|
248
|
+
aargs.lead_tys.each do |aarg|
|
249
|
+
sym = get_sym("private", aarg, ep, scratch) or next
|
250
|
+
meths = scratch.get_method(recv, false, sym)
|
251
|
+
next unless meths
|
252
|
+
meths.each do |mdef|
|
253
|
+
mdef.pub_meth = false if mdef.respond_to?(:pub_meth=)
|
254
|
+
end
|
227
255
|
end
|
256
|
+
else
|
257
|
+
# XXX: warn?
|
228
258
|
end
|
229
259
|
ctn[recv, ep, env]
|
230
260
|
end
|
@@ -245,7 +275,7 @@ module TypeProf
|
|
245
275
|
blk = blk_ty.block_body
|
246
276
|
case blk
|
247
277
|
when ISeqBlock
|
248
|
-
scratch.do_define_iseq_method(ep, env, mid, blk.iseq,
|
278
|
+
scratch.do_define_iseq_method(ep, env, mid, blk.iseq, blk.outer_ep)
|
249
279
|
else
|
250
280
|
# XXX: what to do?
|
251
281
|
end
|
@@ -323,14 +353,19 @@ module TypeProf
|
|
323
353
|
return ctn[Type.any, ep, env] unless recv.is_a?(Type::Local) && recv.kind == Type::Array
|
324
354
|
|
325
355
|
if aargs.lead_tys.size != 2
|
356
|
+
# XXX: Support `ary[idx, len] = val`
|
326
357
|
#raise NotImplementedError # XXX
|
327
|
-
ctn[Type.any, ep, env]
|
358
|
+
return ctn[Type.any, ep, env]
|
328
359
|
end
|
329
360
|
|
330
361
|
idx = aargs.lead_tys.first
|
331
362
|
if idx.is_a?(Type::Literal)
|
332
363
|
idx = idx.lit
|
333
|
-
|
364
|
+
if !idx.is_a?(Integer)
|
365
|
+
# XXX: Support `ary[idx..end] = val`
|
366
|
+
#raise NotImplementedError # XXX
|
367
|
+
return ctn[Type.any, ep, env]
|
368
|
+
end
|
334
369
|
else
|
335
370
|
idx = nil
|
336
371
|
end
|
@@ -367,6 +402,7 @@ module TypeProf
|
|
367
402
|
recv.each_child do |recv|
|
368
403
|
if recv.is_a?(Type::Local) && recv.kind == Type::Hash
|
369
404
|
ty = scratch.get_hash_elem_type(env, ep, recv.id, idx)
|
405
|
+
ty = Type.nil if ty == Type.bot
|
370
406
|
else
|
371
407
|
ty = Type.any
|
372
408
|
end
|
@@ -377,7 +413,11 @@ module TypeProf
|
|
377
413
|
def hash_aset(recv, mid, aargs, ep, env, scratch, &ctn)
|
378
414
|
return ctn[Type.any, ep, env] unless recv.is_a?(Type::Local) && recv.kind == Type::Hash
|
379
415
|
|
380
|
-
|
416
|
+
if aargs.lead_tys.size != 2
|
417
|
+
# XXX: error?
|
418
|
+
ctn[Type.any, ep, env]
|
419
|
+
return
|
420
|
+
end
|
381
421
|
|
382
422
|
idx = aargs.lead_tys.first
|
383
423
|
idx = scratch.globalize_type(idx, env, ep)
|
@@ -396,18 +436,7 @@ module TypeProf
|
|
396
436
|
end
|
397
437
|
|
398
438
|
def struct_initialize(recv, mid, aargs, ep, env, scratch, &ctn)
|
399
|
-
|
400
|
-
scratch.add_ivar_read!(recv, :_members, ep) do |member_ary_ty, ep|
|
401
|
-
member_ary_ty.elems.lead_tys.zip(aargs.lead_tys) do |sym, ty|
|
402
|
-
ty ||= Type.nil
|
403
|
-
scratch.set_instance_variable(recv, sym.sym, ty, ep, env)
|
404
|
-
end
|
405
|
-
end
|
406
|
-
ctn[recv, ep, env]
|
407
|
-
end
|
408
|
-
|
409
|
-
def struct_i_new(recv, mid, aargs, ep, env, scratch, &ctn)
|
410
|
-
struct_klass = recv
|
439
|
+
struct_klass = recv.klass
|
411
440
|
while struct_klass.superclass != Type::Builtin[:struct]
|
412
441
|
struct_klass = struct_klass.superclass
|
413
442
|
end
|
@@ -415,15 +444,24 @@ module TypeProf
|
|
415
444
|
ctn[Type.any, ep, env]
|
416
445
|
return
|
417
446
|
end
|
418
|
-
|
419
|
-
|
420
|
-
|
447
|
+
scratch.add_ivar_read!(Type::Instance.new(struct_klass), :_members, ep) do |member_ary_ty, ep|
|
448
|
+
next if member_ary_ty == Type.bot
|
449
|
+
member_ary_ty.elems.lead_tys.zip(aargs.lead_tys) do |sym, ty|
|
450
|
+
ty ||= Type.nil
|
451
|
+
scratch.set_instance_variable(recv, sym.sym, ty, ep, env)
|
421
452
|
end
|
422
453
|
end
|
454
|
+
ctn[recv, ep, env]
|
455
|
+
end
|
456
|
+
|
457
|
+
def struct_i_new(recv, mid, aargs, ep, env, scratch, &ctn)
|
458
|
+
# TODO: keyword_init
|
459
|
+
|
423
460
|
meths = scratch.get_method(recv, false, :initialize)
|
461
|
+
recv = Type::Instance.new(recv)
|
424
462
|
meths.flat_map do |meth|
|
425
463
|
meth.do_send(recv, :initialize, aargs, ep, env, scratch) do |ret_ty, ep, env|
|
426
|
-
ctn[
|
464
|
+
ctn[recv, ep, env]
|
427
465
|
end
|
428
466
|
end
|
429
467
|
end
|
@@ -491,11 +529,20 @@ module TypeProf
|
|
491
529
|
end
|
492
530
|
|
493
531
|
def kernel_require(recv, mid, aargs, ep, env, scratch, &ctn)
|
494
|
-
|
532
|
+
if aargs.lead_tys.size != 1
|
533
|
+
# XXX: handle correctly
|
534
|
+
ctn[Type.any, ep, env]
|
535
|
+
return
|
536
|
+
end
|
537
|
+
|
495
538
|
feature = aargs.lead_tys.first
|
496
539
|
if feature.is_a?(Type::Literal)
|
497
540
|
feature = feature.lit
|
498
541
|
|
542
|
+
unless feature.is_a?(String)
|
543
|
+
return ctn[Type.any, ep, env]
|
544
|
+
end
|
545
|
+
|
499
546
|
action, arg = Builtin.file_require(feature, scratch)
|
500
547
|
case action
|
501
548
|
when :do
|
@@ -505,22 +552,31 @@ module TypeProf
|
|
505
552
|
ctn[result, ep, env]
|
506
553
|
when :error
|
507
554
|
scratch.warn(ep, arg)
|
508
|
-
result = Type
|
555
|
+
result = Type.bool
|
509
556
|
ctn[result, ep, env]
|
510
557
|
end
|
511
558
|
else
|
512
559
|
scratch.warn(ep, "require target cannot be identified statically")
|
513
|
-
result = Type
|
560
|
+
result = Type.bool
|
514
561
|
ctn[result, ep, env]
|
515
562
|
end
|
516
563
|
end
|
517
564
|
|
518
565
|
def kernel_require_relative(recv, mid, aargs, ep, env, scratch, &ctn)
|
519
|
-
|
566
|
+
if aargs.lead_tys.size != 1
|
567
|
+
# XXX: handle correctly
|
568
|
+
ctn[Type.any, ep, env]
|
569
|
+
return
|
570
|
+
end
|
571
|
+
|
520
572
|
feature = aargs.lead_tys.first
|
521
573
|
if feature.is_a?(Type::Literal)
|
522
574
|
feature = feature.lit
|
523
575
|
|
576
|
+
unless feature.is_a?(String)
|
577
|
+
return ctn[Type.any, ep, env]
|
578
|
+
end
|
579
|
+
|
524
580
|
if scratch.loaded_features[feature]
|
525
581
|
result = Type::Instance.new(Type::Builtin[:false])
|
526
582
|
return ctn[result, ep, env]
|
@@ -541,7 +597,12 @@ module TypeProf
|
|
541
597
|
end
|
542
598
|
|
543
599
|
def kernel_autoload(recv, mid, aargs, ep, env, scratch, &ctn)
|
544
|
-
|
600
|
+
if aargs.lead_tys.size != 2
|
601
|
+
# XXX: handle correctly
|
602
|
+
ctn[Type.any, ep, env]
|
603
|
+
return
|
604
|
+
end
|
605
|
+
|
545
606
|
feature = aargs.lead_tys[1]
|
546
607
|
if feature.is_a?(Type::Literal)
|
547
608
|
feature = feature.lit
|
@@ -597,6 +658,7 @@ module TypeProf
|
|
597
658
|
Type::Builtin[:int] = scratch.get_constant(klass_obj, :Integer)
|
598
659
|
Type::Builtin[:float] = scratch.get_constant(klass_obj, :Float)
|
599
660
|
Type::Builtin[:rational] = scratch.get_constant(klass_obj, :Rational)
|
661
|
+
Type::Builtin[:complex] = scratch.get_constant(klass_obj, :Complex)
|
600
662
|
Type::Builtin[:sym] = scratch.get_constant(klass_obj, :Symbol)
|
601
663
|
Type::Builtin[:str] = scratch.get_constant(klass_obj, :String)
|
602
664
|
Type::Builtin[:struct] = scratch.get_constant(klass_obj, :Struct)
|
@@ -610,6 +672,7 @@ module TypeProf
|
|
610
672
|
Type::Builtin[:class] = scratch.get_constant(klass_obj, :Class)
|
611
673
|
Type::Builtin[:module] = scratch.get_constant(klass_obj, :Module)
|
612
674
|
Type::Builtin[:exc] = scratch.get_constant(klass_obj, :Exception)
|
675
|
+
Type::Builtin[:encoding] = scratch.get_constant(klass_obj, :Encoding)
|
613
676
|
|
614
677
|
klass_vmcore = Type::Builtin[:vmcore]
|
615
678
|
klass_ary = Type::Builtin[:ary]
|
@@ -624,9 +687,6 @@ module TypeProf
|
|
624
687
|
scratch.set_custom_method(klass_vmcore, :"core#raise", Builtin.method(:vmcore_raise))
|
625
688
|
scratch.set_custom_method(klass_vmcore, :lambda, Builtin.method(:lambda))
|
626
689
|
scratch.set_singleton_custom_method(klass_obj, :"new", Builtin.method(:object_s_new))
|
627
|
-
scratch.set_singleton_custom_method(klass_obj, :"attr_accessor", Builtin.method(:module_attr_accessor))
|
628
|
-
scratch.set_singleton_custom_method(klass_obj, :"attr_reader", Builtin.method(:module_attr_reader))
|
629
|
-
scratch.set_singleton_custom_method(klass_obj, :"attr_writer", Builtin.method(:module_attr_writer))
|
630
690
|
scratch.set_custom_method(klass_obj, :p, Builtin.method(:kernel_p))
|
631
691
|
scratch.set_custom_method(klass_obj, :is_a?, Builtin.method(:object_is_a?))
|
632
692
|
scratch.set_custom_method(klass_obj, :respond_to?, Builtin.method(:object_respond_to?))
|
@@ -641,6 +701,9 @@ module TypeProf
|
|
641
701
|
scratch.set_custom_method(klass_module, :public, Builtin.method(:module_public))
|
642
702
|
scratch.set_custom_method(klass_module, :private, Builtin.method(:module_private))
|
643
703
|
scratch.set_custom_method(klass_module, :define_method, Builtin.method(:module_define_method))
|
704
|
+
scratch.set_custom_method(klass_module, :"attr_accessor", Builtin.method(:module_attr_accessor))
|
705
|
+
scratch.set_custom_method(klass_module, :"attr_reader", Builtin.method(:module_attr_reader))
|
706
|
+
scratch.set_custom_method(klass_module, :"attr_writer", Builtin.method(:module_attr_writer))
|
644
707
|
|
645
708
|
scratch.set_custom_method(klass_proc, :[], Builtin.method(:proc_call))
|
646
709
|
scratch.set_custom_method(klass_proc, :call, Builtin.method(:proc_call))
|