Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now tool/dog_bench.rb cannot handle core/ast/base.rb #211

Closed
hoshinotsuyoshi opened this issue Jun 8, 2024 · 1 comment · Fixed by #212
Closed

Now tool/dog_bench.rb cannot handle core/ast/base.rb #211

hoshinotsuyoshi opened this issue Jun 8, 2024 · 1 comment · Fixed by #212

Comments

@hoshinotsuyoshi
Copy link
Contributor

Recently, I found that the typeprof VSCode extension does not work correctly on lib/typeprof/ when using the latest master branch (50d2d7c). However, it works fine with the previous commit (b21905b).

The execution results of tool/dog_bench.rb also reflect this behavior.

Given that the former results in an error and the latter succeeds, I am reporting this as a problem.

Problem

At 50d2d7c , $ bundle exec ruby tool/dog_bench.rb failed

$ bundle exec ruby tool/dog_bench.rb ; echo $?
lib/typeprof/code_range.rb
lib/typeprof/core/ast/base.rb
/Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/env.rb:297:in `get_var': unhandled exception
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/control.rb:189:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/control.rb:66:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/control.rb:139:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/method.rb:224:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/method.rb:189:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/module.rb:67:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/module.rb:113:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/module.rb:67:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/module.rb:113:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/module.rb:67:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:23:in `block in install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `each'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/misc.rb:22:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:211:in `install0'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/ast/base.rb:93:in `install'
        from /Users/hoshino/ghq/github.com/ruby/typeprof/lib/typeprof/core/service.rb:81:in `update_rb_file'
        from tool/dog_bench.rb:10:in `block in main'
        from <internal:dir>:411:in `glob'
        from tool/dog_bench.rb:7:in `main'
        from tool/dog_bench.rb:31:in `block in <main>'
        from tool/dog_bench.rb:30:in `run'
        from tool/dog_bench.rb:30:in `<main>'
1

At previous commit b21905b , $ bundle exec ruby tool/dog_bench.rb succeeds

$ bundle exec ruby tool/dog_bench.rb ; echo $?
lib/typeprof/code_range.rb
lib/typeprof/core/ast/base.rb
lib/typeprof/core/ast/call.rb
lib/typeprof/core/ast/const.rb
lib/typeprof/core/ast/control.rb
lib/typeprof/core/ast/meta.rb
lib/typeprof/core/ast/method.rb
lib/typeprof/core/ast/misc.rb
lib/typeprof/core/ast/module.rb
lib/typeprof/core/ast/sig_decl.rb
lib/typeprof/core/ast/sig_type.rb
lib/typeprof/core/ast/value.rb
lib/typeprof/core/ast/variable.rb
lib/typeprof/core/ast.rb
lib/typeprof/core/builtin.rb
lib/typeprof/core/env/method.rb
lib/typeprof/core/env/method_entity.rb
lib/typeprof/core/env/module_entity.rb
lib/typeprof/core/env/static_read.rb
lib/typeprof/core/env/type_alias_entity.rb
lib/typeprof/core/env/value_entity.rb
lib/typeprof/core/env.rb
lib/typeprof/core/graph/box.rb
lib/typeprof/core/graph/change_set.rb
lib/typeprof/core/graph/filter.rb
lib/typeprof/core/graph/vertex.rb
lib/typeprof/core/graph.rb
lib/typeprof/core/service.rb
lib/typeprof/core/type.rb
lib/typeprof/core/util.rb
lib/typeprof/core.rb
lib/typeprof/diagnostic.rb
lib/typeprof/version.rb
Elapsed: 0.708826
{TypeProf::Core::Type::Instance=>1822,
 TypeProf::Core::Type::Singleton=>539,
 TypeProf::Core::Type::Array=>615,
 TypeProf::Core::Type::Proc=>1132,
 TypeProf::Core::Type::Symbol=>464,
 TypeProf::Core::Type::Hash=>135,
 TypeProf::Core::Type::Bot=>1,
 TypeProf::Core::Type::Var=>236}
0

Added Known-Issue PR

I believe the following part of core/ast/base.rb is causing typeprof to fail:

until queue.empty?
subnode = queue.shift
next unless subnode

In other words, I think the program fails when it looks like this.

until (cond)
  next
end

Ideally, I would have solved the root cause of the issue, but I was unable to do so 🙏. Therefore, I created a PR marking it as a known issue. I would appreciate it if you could review it. #210 .

Additional Information

This change makes the tests pass, but currently, I am not fully sure what I am doing 😇 😇

--- a/lib/typeprof/core/ast/control.rb
+++ b/lib/typeprof/core/ast/control.rb
@@ -186,7 +186,9 @@ module TypeProf::Core

       def install0(genv)
         @arg.install(genv)
-        @lenv.add_next_box(@changes.add_escape_box(genv, @arg.ret, @lenv.get_var(:"*expected_block_ret")))
+        if @lenv.locals[:"*expected_block_ret"]
+          @lenv.add_next_box(@changes.add_escape_box(genv, @arg.ret, @lenv.get_var(:"*expected_block_ret")))
+        end
         Source.new(Type::Bot.new(genv))
       end
     end
mame added a commit to mame/typeprof that referenced this issue Jun 8, 2024
@mame mame closed this as completed in #212 Jun 8, 2024
mame added a commit that referenced this issue Jun 8, 2024
@mame
Copy link
Member

mame commented Jun 8, 2024

Thanks! I improved handling the next expression in a loop. Also. I have added dog_bench.rb to the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants