ruby-changes:57986
From: Nobuyoshi <ko1@a...>
Date: Fri, 27 Sep 2019 21:17:29 +0900 (JST)
Subject: [ruby-changes:57986] 79d5332a2d (master): Drop eliminated catch-entries
https://git.ruby-lang.org/ruby.git/commit/?id=79d5332a2d From 79d5332a2da0e2743a77480aebfca256a54a962e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 27 Sep 2019 21:12:27 +0900 Subject: Drop eliminated catch-entries Drop catch table entries used in eliminated block, as well as call_infos. [Bug #16184] diff --git a/compile.c b/compile.c index 68c7e5a..5bd2315 100644 --- a/compile.c +++ b/compile.c @@ -5118,6 +5118,8 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int https://github.com/ruby/ruby/blob/trunk/compile.c#L5118 LABEL *then_label, *else_label, *end_label; VALUE branches = Qfalse; int ci_size, ci_kw_size; + VALUE catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary; + long catch_table_size = NIL_P(catch_table) ? 0 : RARRAY_LEN(catch_table); INIT_ANCHOR(cond_seq); INIT_ANCHOR(then_seq); @@ -5132,17 +5134,27 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int https://github.com/ruby/ruby/blob/trunk/compile.c#L5134 ci_size = body->ci_size; ci_kw_size = body->ci_kw_size; CHECK(COMPILE_(then_seq, "then", node_body, popped)); + catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary; if (!then_label->refcnt) { body->ci_size = ci_size; body->ci_kw_size = ci_kw_size; + if (!NIL_P(catch_table)) rb_ary_set_len(catch_table, catch_table_size); + } + else { + if (!NIL_P(catch_table)) catch_table_size = RARRAY_LEN(catch_table); } ci_size = body->ci_size; ci_kw_size = body->ci_kw_size; CHECK(COMPILE_(else_seq, "else", node_else, popped)); + catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary; if (!else_label->refcnt) { body->ci_size = ci_size; body->ci_kw_size = ci_kw_size; + if (!NIL_P(catch_table)) rb_ary_set_len(catch_table, catch_table_size); + } + else { + if (!NIL_P(catch_table)) catch_table_size = RARRAY_LEN(catch_table); } ADD_SEQ(ret, cond_seq); diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index ed779fe..6a9e960 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -825,4 +825,19 @@ class TestRubyOptimization < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L825 } end; end + + def test_optimized_rescue + assert_in_out_err("", "#{<<~"begin;"}\n#{<<~'end;'}", [], /END \(RuntimeError\)/) + begin; + if false + begin + require "some_mad_stuff" + rescue LoadError + puts "no mad stuff loaded" + end + end + + raise "END" + end; + end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/