ruby-changes:69163
From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:21:04 +0900 (JST)
Subject: [ruby-changes:69163] efed45966b (master): Show +YJIT in version string and RUBY_DESCRIPTION
https://git.ruby-lang.org/ruby.git/commit/?id=efed45966b From efed45966b3aac728bbbe2cfc7ec937b7712c146 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Thu, 7 Oct 2021 18:05:10 -0400 Subject: Show +YJIT in version string and RUBY_DESCRIPTION There might be code out there that expect `ruby -v` to print only one line. Since MJIT shows +JIT in `ruby -v` and RUBY_DESCRIPTION, let's show +YJIT. The crash report doesn't show anything about MJIT, so adjust the test. The "test_ruby_version" test was unaware of RUBY_YJIT_ENABLE and so was failing when the variable is set and inherited into the children processes it spawns. Explicitly unset the variable in the test. --- test/-ext-/bug_reporter/test_bug_reporter.rb | 1 + test/ruby/test_rubyoptions.rb | 23 +++++++++++++++-------- test/ruby/test_yjit.rb | 28 ++++++++++++++++++++++++++++ version.c | 10 +++++++--- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/test/-ext-/bug_reporter/test_bug_reporter.rb b/test/-ext-/bug_reporter/test_bug_reporter.rb index ac6d92bb67..759e295fb6 100644 --- a/test/-ext-/bug_reporter/test_bug_reporter.rb +++ b/test/-ext-/bug_reporter/test_bug_reporter.rb @@ -8,6 +8,7 @@ class TestBugReporter < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bug_reporter/test_bug_reporter.rb#L8 description = RUBY_DESCRIPTION description = description.sub(/\+JIT /, '') if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? + description = description.sub(/\+YJIT /, '') if defined?(YJIT.enabled?) && YJIT.enabled? expected_stderr = [ :*, /\[BUG\]\sSegmentation\sfault.*\n/, diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 5db0f9efdd..ce59302447 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -10,6 +10,8 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L10 NO_JIT_DESCRIPTION = if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE RUBY_DESCRIPTION.sub(/\+JIT /, '') + elsif defined?(YJIT.enabled?) && YJIT.enabled? + RUBY_DESCRIPTION.sub(/\+YJIT /, '') else RUBY_DESCRIPTION end @@ -140,10 +142,12 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L142 private_constant :VERSION_PATTERN_WITH_JIT def test_verbose - assert_in_out_err(["-vve", ""]) do |r, e| + assert_in_out_err([{'RUBY_YJIT_ENABLE' => nil}, "-vve", ""]) do |r, e| assert_match(VERSION_PATTERN, r[0]) if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE assert_equal(NO_JIT_DESCRIPTION, r[0]) + elsif defined?(YJIT.enabled?) && YJIT.enabled? + assert_equal(NO_JIT_DESCRIPTION, r[0]) else assert_equal(RUBY_DESCRIPTION, r[0]) end @@ -203,10 +207,13 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L207 end def test_version - assert_in_out_err(%w(--version)) do |r, e| + env = {'RUBY_YJIT_ENABLE' => nil} # unset in children + assert_in_out_err([env, '--version']) do |r, e| assert_match(VERSION_PATTERN, r[0]) if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + elsif defined?(YJIT.enabled?) && YJIT.enabled? + assert_equal(NO_JIT_DESCRIPTION, r[0]) else assert_equal(RUBY_DESCRIPTION, r[0]) end @@ -220,7 +227,7 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L227 %w(--version --enable=jit --disable=jit), %w(--version --enable-jit --disable-jit), ].each do |args| - assert_in_out_err(args) do |r, e| + assert_in_out_err([env] + args) do |r, e| assert_match(VERSION_PATTERN, r[0]) assert_match(NO_JIT_DESCRIPTION, r[0]) assert_equal([], e) @@ -229,16 +236,16 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L236 if JITSupport.supported? [ - %w(--version --disable-yjit --jit), - %w(--version --disable-yjit --enable=jit), - %w(--version --disable-yjit --enable-jit), + %w(--version --jit), + %w(--version --enable=jit), + %w(--version --enable-jit), ].each do |args| - assert_in_out_err(args) do |r, e| + assert_in_out_err([env] + args) do |r, e| assert_match(VERSION_PATTERN_WITH_JIT, r[0]) if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE assert_equal(RUBY_DESCRIPTION, r[0]) else - assert_equal(EnvUtil.invoke_ruby(['--disable-yjit', '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + assert_equal(EnvUtil.invoke_ruby([env, '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) end assert_equal([], e) end diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index d7dd599205..24c5c92818 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -8,6 +8,34 @@ return unless YJIT.enabled? https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L8 # Tests for YJIT with assertions on compilation and side exits # insipired by the MJIT tests in test/ruby/test_jit.rb class TestYJIT < Test::Unit::TestCase + def test_yjit_in_ruby_description + assert_includes(RUBY_DESCRIPTION, '+YJIT') + end + + def test_yjit_in_version + [ + %w(--version --yjit), + %w(--version --disable-yjit --yjit), + %w(--version --disable-yjit --enable-yjit), + %w(--version --disable-yjit --enable=yjit), + %w(--version --disable=yjit --yjit), + %w(--version --disable=yjit --enable-yjit), + %w(--version --disable=yjit --enable=yjit), + ].each do |version_args| + assert_in_out_err(version_args) do |stdout, stderr| + assert_equal([RUBY_DESCRIPTION], stdout) + assert_equal([], stderr) + end + end + end + + def test_enable_from_env_var + yjit_child_env = {'RUBY_YJIT_ENABLE' => '1'} + assert_in_out_err([yjit_child_env, '--version'], '', [RUBY_DESCRIPTION]) + assert_in_out_err([yjit_child_env, '-e puts RUBY_DESCRIPTION'], '', [RUBY_DESCRIPTION]) + assert_in_out_err([yjit_child_env, '-e p YJIT.enabled?'], '', ['true']) + end + def test_compile_getclassvariable script = 'class Foo; @@foo = 1; def self.foo; @@foo; end; end; Foo.foo' assert_compiles(script, insns: %i[getclassvariable], result: 1) diff --git a/version.c b/version.c index e8bf51d2dc..5bfc663b4e 100644 --- a/version.c +++ b/version.c @@ -43,6 +43,7 @@ const char ruby_platform[] = RUBY_PLATFORM; https://github.com/ruby/ruby/blob/trunk/version.c#L43 const int ruby_patchlevel = RUBY_PATCHLEVEL; const char ruby_description[] = RUBY_DESCRIPTION_WITH(""); static const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH(" +JIT"); +static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(" +YJIT"); const char ruby_copyright[] = RUBY_COPYRIGHT; const char ruby_engine[] = "ruby"; @@ -105,6 +106,9 @@ Init_ruby_description(void) https://github.com/ruby/ruby/blob/trunk/version.c#L106 if (MJIT_OPTS_ON) { description = MKSTR(description_with_jit); } + else if (rb_yjit_enabled_p()) { + description = MKSTR(description_with_yjit); + } else { description = MKSTR(description); } @@ -121,13 +125,13 @@ ruby_show_version(void) https://github.com/ruby/ruby/blob/trunk/version.c#L125 if (MJIT_OPTS_ON) { PRINT(description_with_jit); } + else if (rb_yjit_enabled_p()) { + PRINT(description_with_yjit); + } else { PRINT(description); } - if (rb_yjit_enabled_p()) { - fputs("YJIT is enabled\n", stdout); - } #ifdef RUBY_LAST_COMMIT_TITLE fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout); #endif -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/