typeprof 0.21.3 → 0.21.4
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/dependabot.yml +6 -0
- data/.github/workflows/main.yml +13 -6
- data/Gemfile +7 -3
- data/Gemfile.lock +3 -3
- data/lib/typeprof/analyzer.rb +4 -2
- data/lib/typeprof/import.rb +7 -2
- data/lib/typeprof/iseq.rb +34 -6
- data/lib/typeprof/type.rb +9 -4
- data/lib/typeprof/version.rb +1 -1
- data/lib/typeprof.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0f10007471912f793ce801817a088aa794bc4baeb15e5179362521f55e41ec0
|
4
|
+
data.tar.gz: ed61a2b2f4b9800cfb9c9e75d7aa0d0a5690ec1660e509dd4da456b60d1d03e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218064fc39d5eeacfe48c8babb28cfade5a069703d71ec4fb45f1a436491596006a01e46b63a14a25c611924176e7bc7aa5131a687c48f9c35b9d84e03e044e8
|
7
|
+
data.tar.gz: 61cca1138af6ab08bb91b9e05cd03a27de7c43bd13a36b9aa5522dffb1a118cb67f4494b0f109097572aa787a334be822773c6fedd87b3f1bcce1d7d221d7eba
|
data/.github/workflows/main.yml
CHANGED
@@ -7,19 +7,26 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
ruby-version: [2.7, 3.0, 3.1, head]
|
10
|
+
ruby-version: [2.7, 3.0, 3.1, 3.2, head]
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v3
|
14
|
-
with:
|
15
|
-
submodules: true
|
16
14
|
- name: Set up Ruby
|
17
15
|
uses: ruby/setup-ruby@v1
|
18
16
|
with:
|
19
17
|
ruby-version: ${{ matrix.ruby-version }}
|
20
|
-
|
21
|
-
run: |
|
22
|
-
bundle install
|
18
|
+
bundler-cache: true
|
23
19
|
- name: Run the test suite
|
24
20
|
run: |
|
25
21
|
bundle exec rake TESTOPT=-v
|
22
|
+
|
23
|
+
truffleruby:
|
24
|
+
runs-on: ubuntu-latest
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v3
|
27
|
+
- name: Set up Ruby
|
28
|
+
uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: truffleruby
|
31
|
+
bundler-cache: true
|
32
|
+
- run: bundle exec typeprof --version
|
data/Gemfile
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
if ENV["RBS_VERSION"]
|
4
|
+
gem "rbs", github: "ruby/rbs", ref: ENV["RBS_VERSION"]
|
5
|
+
else
|
6
|
+
# Specify your gem's dependencies in typeprof.gemspec
|
7
|
+
gemspec
|
8
|
+
end
|
5
9
|
|
6
10
|
group :development do
|
7
11
|
gem "rake"
|
8
|
-
gem "stackprof"
|
12
|
+
gem "stackprof", platforms: :mri
|
9
13
|
gem "test-unit"
|
10
14
|
gem "simplecov"
|
11
15
|
gem "simplecov-html"
|
data/Gemfile.lock
CHANGED
@@ -10,8 +10,8 @@ GEM
|
|
10
10
|
coverage-helpers (1.0.0)
|
11
11
|
docile (1.4.0)
|
12
12
|
power_assert (2.0.1)
|
13
|
-
rake (13.0.
|
14
|
-
rbs (2.
|
13
|
+
rake (13.0.1)
|
14
|
+
rbs (2.8.3)
|
15
15
|
simplecov (0.21.2)
|
16
16
|
docile (~> 1.1)
|
17
17
|
simplecov-html (~> 0.11)
|
@@ -36,4 +36,4 @@ DEPENDENCIES
|
|
36
36
|
typeprof!
|
37
37
|
|
38
38
|
BUNDLED WITH
|
39
|
-
2.
|
39
|
+
2.3.11
|
data/lib/typeprof/analyzer.rb
CHANGED
@@ -1997,7 +1997,8 @@ module TypeProf
|
|
1997
1997
|
env = env.push(Type.any) # or String | NilClass only?
|
1998
1998
|
when 1 # VM_SVAR_BACKREF ($~)
|
1999
1999
|
merge_env(ep.next, env.push(Type::Instance.new(Type::Builtin[:matchdata])))
|
2000
|
-
|
2000
|
+
# tentatively disabled; it is too conservative
|
2001
|
+
#merge_env(ep.next, env.push(Type.nil))
|
2001
2002
|
return
|
2002
2003
|
else # flip-flop
|
2003
2004
|
env = env.push(Type.bool)
|
@@ -2005,7 +2006,8 @@ module TypeProf
|
|
2005
2006
|
else
|
2006
2007
|
# NTH_REF ($1, $2, ...) / BACK_REF ($&, $+, ...)
|
2007
2008
|
merge_env(ep.next, env.push(Type::Instance.new(Type::Builtin[:str])))
|
2008
|
-
|
2009
|
+
# tentatively disabled; it is too conservative
|
2010
|
+
#merge_env(ep.next, env.push(Type.nil))
|
2009
2011
|
return
|
2010
2012
|
end
|
2011
2013
|
when :setspecial
|
data/lib/typeprof/import.rb
CHANGED
@@ -170,7 +170,12 @@ module TypeProf
|
|
170
170
|
when RBS::AST::Members::MethodDefinition
|
171
171
|
name = member.name
|
172
172
|
|
173
|
-
|
173
|
+
if member.respond_to?(:overloads)
|
174
|
+
types = member.overloads.map {|overload| overload.method_type }
|
175
|
+
else
|
176
|
+
types = member.types
|
177
|
+
end
|
178
|
+
method_types = types.map do |method_type|
|
174
179
|
case method_type
|
175
180
|
when RBS::MethodType then method_type
|
176
181
|
when :super then raise NotImplementedError
|
@@ -180,7 +185,7 @@ module TypeProf
|
|
180
185
|
method_def = conv_method_def(method_types, visibility)
|
181
186
|
rbs_source = [
|
182
187
|
(member.kind == :singleton ? "self." : "") + member.name.to_s,
|
183
|
-
|
188
|
+
types.map {|type| type.location.source },
|
184
189
|
[member.location.name, CodeRange.from_rbs(member.location)],
|
185
190
|
]
|
186
191
|
if member.instance?
|
data/lib/typeprof/iseq.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module TypeProf
|
2
2
|
class ISeq
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
if defined?(RubyVM::InstructionSequence)
|
4
|
+
# https://github.com/ruby/ruby/pull/4468
|
5
|
+
CASE_WHEN_CHECKMATCH = RubyVM::InstructionSequence.compile("case 1; when Integer; end").to_a.last.any? {|insn,| insn == :checkmatch }
|
6
|
+
# https://github.com/ruby/ruby/blob/v3_0_2/vm_core.h#L1206
|
7
|
+
VM_ENV_DATA_SIZE = 3
|
8
|
+
# Check if Ruby 3.1 or later
|
9
|
+
RICH_AST = begin RubyVM::AbstractSyntaxTree.parse("1", keep_script_lines: true).node_id; true; rescue; false; end
|
10
|
+
end
|
9
11
|
|
10
12
|
FileInfo = Struct.new(
|
11
13
|
:node_id2node,
|
@@ -447,6 +449,11 @@ module TypeProf
|
|
447
449
|
insn.insn, insn.operands = :branch, [:nil] + insn.operands
|
448
450
|
when :getblockparam, :getblockparamproxy
|
449
451
|
insn.insn = :getlocal
|
452
|
+
when :getglobal
|
453
|
+
if insn.operands == [:$typeprof]
|
454
|
+
insn.insn = :putobject
|
455
|
+
insn.operands = [true]
|
456
|
+
end
|
450
457
|
end
|
451
458
|
end
|
452
459
|
end
|
@@ -687,6 +694,27 @@ module TypeProf
|
|
687
694
|
@insns[i + 1] = Insn.new(:getlocal_branch, [getlocal_operands, branch_operands])
|
688
695
|
end
|
689
696
|
end
|
697
|
+
|
698
|
+
# find a pattern: putobject, branch
|
699
|
+
(@insns.size - 1).times do |i|
|
700
|
+
next if branch_targets[i + 1]
|
701
|
+
insn0 = @insns[i]
|
702
|
+
insn1 = @insns[i + 1]
|
703
|
+
if insn0.insn == :putobject && insn1.insn == :branch
|
704
|
+
putobject_operands = insn0.operands
|
705
|
+
branch_operands = insn1.operands
|
706
|
+
obj = putobject_operands[0]
|
707
|
+
branch_type = branch_operands[0]
|
708
|
+
branch_target = branch_operands[1]
|
709
|
+
case branch_type
|
710
|
+
when :if then jump = !!obj
|
711
|
+
when :unless then jump = !obj
|
712
|
+
when :nil then jump = obj == nil
|
713
|
+
end
|
714
|
+
@insns[i ] = Insn.new(:nop, [])
|
715
|
+
@insns[i + 1] = jump ? Insn.new(:jump, [branch_target]) : Insn.new(:nop, [])
|
716
|
+
end
|
717
|
+
end
|
690
718
|
end
|
691
719
|
|
692
720
|
def check_send_branch(sp, j)
|
data/lib/typeprof/type.rb
CHANGED
@@ -59,10 +59,13 @@ module TypeProf
|
|
59
59
|
else
|
60
60
|
if ty2.is_a?(Type::ContainerType)
|
61
61
|
# ty2 may have type variables
|
62
|
-
|
63
|
-
|
62
|
+
if ty1.class == ty2.class
|
63
|
+
ty1.match?(ty2)
|
64
|
+
else
|
65
|
+
Type.match?(ty1, ty2.base_type)
|
66
|
+
end
|
64
67
|
elsif ty1.is_a?(Type::ContainerType)
|
65
|
-
|
68
|
+
Type.match?(ty1.base_type, ty2)
|
66
69
|
else
|
67
70
|
ty1.consistent?(ty2) ? {} : nil
|
68
71
|
end
|
@@ -810,7 +813,9 @@ module TypeProf
|
|
810
813
|
when :$0, :$PROGRAM_NAME
|
811
814
|
Type::Instance.new(Type::Builtin[:str])
|
812
815
|
when :$~
|
813
|
-
|
816
|
+
# optional type is tentatively disabled; it is too conservative
|
817
|
+
#Type.optional(Type::Instance.new(Type::Builtin[:matchdata]))
|
818
|
+
Type::Instance.new(Type::Builtin[:matchdata])
|
814
819
|
when :$., :$$
|
815
820
|
Type::Instance.new(Type::Builtin[:int])
|
816
821
|
when :$?
|
data/lib/typeprof/version.rb
CHANGED
data/lib/typeprof.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typeprof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.
|
4
|
+
version: 0.21.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Endoh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -37,6 +37,7 @@ executables:
|
|
37
37
|
extensions: []
|
38
38
|
extra_rdoc_files: []
|
39
39
|
files:
|
40
|
+
- ".github/dependabot.yml"
|
40
41
|
- ".github/workflows/main.yml"
|
41
42
|
- ".gitignore"
|
42
43
|
- Gemfile
|
@@ -73,7 +74,7 @@ licenses:
|
|
73
74
|
metadata:
|
74
75
|
homepage_uri: https://github.com/ruby/typeprof
|
75
76
|
source_code_uri: https://github.com/ruby/typeprof
|
76
|
-
post_install_message:
|
77
|
+
post_install_message:
|
77
78
|
rdoc_options: []
|
78
79
|
require_paths:
|
79
80
|
- lib
|
@@ -88,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
89
|
- !ruby/object:Gem::Version
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
|
-
rubygems_version: 3.3.
|
92
|
-
signing_key:
|
92
|
+
rubygems_version: 3.3.26
|
93
|
+
signing_key:
|
93
94
|
specification_version: 4
|
94
95
|
summary: TypeProf is a type analysis tool for Ruby code based on abstract interpretation
|
95
96
|
test_files: []
|