typeprof 0.21.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cfc98929d3481526809f92f41edd0abe30d82aaab6f1e1e95d574c74e1cee9b
4
- data.tar.gz: 895a3f4949b010d2809e32016fec9e7597ae6b5e29175448b668ede33ab20b99
3
+ metadata.gz: c0f10007471912f793ce801817a088aa794bc4baeb15e5179362521f55e41ec0
4
+ data.tar.gz: ed61a2b2f4b9800cfb9c9e75d7aa0d0a5690ec1660e509dd4da456b60d1d03e7
5
5
  SHA512:
6
- metadata.gz: 736ebc69c1715474973c514ca0e013991575732bee3549b7ac80865264bf3fde42065b1e00b408d3a543a8730030979e891be0427f73a297808bfd890c5698f0
7
- data.tar.gz: 6bbe63293cfa70dc393e6a97d7a761865ed76a4cbb12a95a19134649079849a82510671e2d1661c55319958040f30c70f2ab06f255a28af5d0cbb6eba96ac0f0
6
+ metadata.gz: 218064fc39d5eeacfe48c8babb28cfade5a069703d71ec4fb45f1a436491596006a01e46b63a14a25c611924176e7bc7aa5131a687c48f9c35b9d84e03e044e8
7
+ data.tar.gz: 61cca1138af6ab08bb91b9e05cd03a27de7c43bd13a36b9aa5522dffb1a118cb67f4494b0f109097572aa787a334be822773c6fedd87b3f1bcce1d7d221d7eba
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -7,19 +7,26 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false
9
9
  matrix:
10
- ruby-version: [2.7, 3.0,head]
10
+ ruby-version: [2.7, 3.0, 3.1, 3.2, head]
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
14
- with:
15
- submodules: true
13
+ - uses: actions/checkout@v3
16
14
  - name: Set up Ruby
17
15
  uses: ruby/setup-ruby@v1
18
16
  with:
19
17
  ruby-version: ${{ matrix.ruby-version }}
20
- - name: Bundle install
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
- # Specify your gem's dependencies in typeprof.gemspec
4
- gemspec
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typeprof (0.21.2)
4
+ typeprof (0.21.3)
5
5
  rbs (>= 1.8.1)
6
6
 
7
7
  GEM
@@ -11,14 +11,14 @@ GEM
11
11
  docile (1.4.0)
12
12
  power_assert (2.0.1)
13
13
  rake (13.0.1)
14
- rbs (2.0.0)
14
+ rbs (2.8.3)
15
15
  simplecov (0.21.2)
16
16
  docile (~> 1.1)
17
17
  simplecov-html (~> 0.11)
18
18
  simplecov_json_formatter (~> 0.1)
19
19
  simplecov-html (0.12.3)
20
- simplecov_json_formatter (0.1.3)
21
- stackprof (0.2.17)
20
+ simplecov_json_formatter (0.1.4)
21
+ stackprof (0.2.19)
22
22
  test-unit (3.5.3)
23
23
  power_assert
24
24
 
@@ -36,4 +36,4 @@ DEPENDENCIES
36
36
  typeprof!
37
37
 
38
38
  BUNDLED WITH
39
- 2.2.15
39
+ 2.3.11
@@ -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
- merge_env(ep.next, env.push(Type.nil))
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
- merge_env(ep.next, env.push(Type.nil))
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
@@ -92,7 +92,7 @@ module TypeProf
92
92
  aargs = scratch.globalize_type(aargs, caller_env, caller_ep)
93
93
  subst = aargs.consistent_with_method_signature?(@msig)
94
94
  unless subst
95
- scratch.warn(caller_ep, "The arguments is not compatibile to RBS block")
95
+ scratch.warn(caller_ep, "The arguments is not compatible to RBS block")
96
96
  end
97
97
  # check?
98
98
  #subst = { Type::Var.new(:self) => caller_env.static_env.recv_ty }
@@ -170,7 +170,12 @@ module TypeProf
170
170
  when RBS::AST::Members::MethodDefinition
171
171
  name = member.name
172
172
 
173
- method_types = member.types.map do |method_type|
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
- member.types.map {|type| type.location.source },
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
- # https://github.com/ruby/ruby/pull/4468
4
- CASE_WHEN_CHECKMATCH = RubyVM::InstructionSequence.compile("case 1; when Integer; end").to_a.last.any? {|insn,| insn == :checkmatch }
5
- # https://github.com/ruby/ruby/blob/v3_0_2/vm_core.h#L1206
6
- VM_ENV_DATA_SIZE = 3
7
- # Check if Ruby 3.1 or later
8
- RICH_AST = begin RubyVM::AbstractSyntaxTree.parse("1", keep_script_lines: true).node_id; true; rescue; false; end
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/lsp.rb CHANGED
@@ -5,6 +5,8 @@ require "uri"
5
5
  module TypeProf
6
6
  def self.start_lsp_server(config)
7
7
  if config.lsp_options[:stdio]
8
+ $stdin.binmode
9
+ $stdout.binmode
8
10
  reader = LSP::Reader.new($stdin)
9
11
  writer = LSP::Writer.new($stdout)
10
12
  # pipe all builtin print output to stderr to avoid conflicting with lsp
@@ -498,9 +500,11 @@ module TypeProf
498
500
  when "typeprof.enableSignature"
499
501
  @server.signature_enabled = true
500
502
  @server.send_request("workspace/codeLens/refresh")
503
+ respond(nil)
501
504
  when "typeprof.disableSignature"
502
505
  @server.signature_enabled = false
503
506
  @server.send_request("workspace/codeLens/refresh")
507
+ respond(nil)
504
508
  when "typeprof.createPrototypeRBS"
505
509
  class_kind, class_name, sig_str = @params[:arguments]
506
510
  code_range =
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
- return nil if ty1.class != ty2.class
63
- ty1.match?(ty2)
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
- nil
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
- Type.optional(Type::Instance.new(Type::Builtin[:matchdata]))
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 :$?
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.21.2"
2
+ VERSION = "0.21.4"
3
3
  end
data/lib/typeprof.rb CHANGED
@@ -17,4 +17,4 @@ require_relative "typeprof/builtin"
17
17
  require_relative "typeprof/cli"
18
18
  require_relative "typeprof/code-range"
19
19
 
20
- require_relative "typeprof/lsp" if RUBY_VERSION >= "3"
20
+ require_relative "typeprof/lsp" if RUBY_VERSION >= "3" and RUBY_ENGINE != "truffleruby"
data/typeprof.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  # Specify which files should be added to the gem when it is released.
25
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
26
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(doc|test|spec|features|smoke|testbed)/}) }
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(doc|test|spec|features|smoke|testbed|vscode)/}) }
28
28
  end
29
29
  spec.bindir = "exe"
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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.2
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: 2021-12-28 00:00:00.000000000 Z
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
@@ -67,23 +68,13 @@ files:
67
68
  - tools/setup-insns-def.rb
68
69
  - typeprof-lsp
69
70
  - typeprof.gemspec
70
- - vscode/.gitignore
71
- - vscode/.vscode/launch.json
72
- - vscode/.vscodeignore
73
- - vscode/README.md
74
- - vscode/development.md
75
- - vscode/package-lock.json
76
- - vscode/package.json
77
- - vscode/sandbox/test.rb
78
- - vscode/src/extension.ts
79
- - vscode/tsconfig.json
80
71
  homepage: https://github.com/ruby/typeprof
81
72
  licenses:
82
73
  - MIT
83
74
  metadata:
84
75
  homepage_uri: https://github.com/ruby/typeprof
85
76
  source_code_uri: https://github.com/ruby/typeprof
86
- post_install_message:
77
+ post_install_message:
87
78
  rdoc_options: []
88
79
  require_paths:
89
80
  - lib
@@ -98,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
89
  - !ruby/object:Gem::Version
99
90
  version: '0'
100
91
  requirements: []
101
- rubygems_version: 3.4.0.dev
102
- signing_key:
92
+ rubygems_version: 3.3.26
93
+ signing_key:
103
94
  specification_version: 4
104
95
  summary: TypeProf is a type analysis tool for Ruby code based on abstract interpretation
105
96
  test_files: []
data/vscode/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- /out
2
- node_modules
3
- .vscode/*
4
- !.vscode/launch.json
5
- *.vsix
@@ -1,16 +0,0 @@
1
- {
2
- "version": "0.1.0",
3
- "configurations": [
4
- {
5
- "name": "Launch Extension",
6
- "type": "extensionHost",
7
- "request": "launch",
8
- "runtimeExecutable": "${execPath}",
9
- "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
10
- "stopOnEntry": false,
11
- "sourceMaps": true,
12
- "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
13
- "preLaunchTask": "npm: vscode:prepublish"
14
- }
15
- ]
16
- }
data/vscode/.vscodeignore DELETED
@@ -1,7 +0,0 @@
1
- /sandbox
2
- .vscode/**
3
- /src
4
- **/*.ts
5
- **/*.js.map
6
- **/tsconfig.json
7
- development.md
data/vscode/README.md DELETED
@@ -1,22 +0,0 @@
1
- # Ruby TypeProf VSCode Integration
2
-
3
- *NOTE: This extenstion is very preliminary.*
4
-
5
- This is a VSCode extension to help you write Ruby code by using an code analyzer called [Ruby TypeProf](https://github.com/ruby/typeprof/) as a backend.
6
-
7
- ## How to use this extension
8
-
9
- *TBD*
10
-
11
- Requirements:
12
-
13
- 1. Use Ruby 3.1.0 or later, and TypeProf 0.20.0 or later
14
- 2. Add `gem "typeprof"` to your `Gemfile`, and execute `bundle install`
15
-
16
- Troubleshooting:
17
-
18
- *TBD*
19
-
20
- ## How to develop this extension
21
-
22
- See [development.md](https://github.com/ruby/typeprof/blob/master/development.md).
@@ -1,31 +0,0 @@
1
- # LSP client for vscode
2
-
3
- Note: this is under development
4
-
5
- ## How to run
6
-
7
- ```
8
- $ cd vscode
9
- $ npm install
10
- $ npx run tsc -p ./
11
- $ cd ..
12
- $ code --extensionDevelopmentPath=vscode/ .
13
- ```
14
-
15
- Alternatively, you can do it in vscode itself.
16
-
17
- ```
18
- $ cd vscode
19
- $ code
20
- ```
21
-
22
- And then press F5 to run another vscode with extension.
23
-
24
- ## How to release
25
-
26
- ```
27
- $ npm run package
28
- $ npx vsce publish
29
- ```
30
-
31
- See also: https://code.visualstudio.com/api/working-with-extensions/publishing-extension