ruby-changes:51783
From: k0kubun <ko1@a...>
Date: Wed, 18 Jul 2018 21:46:00 +0900 (JST)
Subject: [ruby-changes:51783] k0kubun:r63995 (trunk): ruby.c: accept --disable-jit option
k0kubun 2018-07-18 21:45:54 +0900 (Wed, 18 Jul 2018) New Revision: 63995 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63995 Log: ruby.c: accept --disable-jit option by promoting jit to feature flag. mjit.h: update comment about mjit_opts.on test_rubyoptions.rb: add test for switching JIT enablement "--jit" flag usage may be deprecated later, but not discussed yet. [Feature #14878] Modified files: trunk/mjit.h trunk/ruby.c trunk/test/ruby/test_rubyoptions.rb Index: mjit.h =================================================================== --- mjit.h (revision 63994) +++ mjit.h (revision 63995) @@ -27,7 +27,9 @@ enum rb_mjit_iseq_func { https://github.com/ruby/ruby/blob/trunk/mjit.h#L27 /* MJIT options which can be defined on the MRI command line. */ struct mjit_options { - char on; /* flag of MJIT usage */ + /* Converted from "jit" feature flag to tell the enablement + information to ruby_show_version(). */ + char on; /* Save temporary files after MRI finish. The temporary files include the pre-compiled header, C code file generated for ISEQ, and the corresponding object file. */ Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 63994) +++ test/ruby/test_rubyoptions.rb (revision 63995) @@ -181,15 +181,34 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L181 end assert_equal([], e) end + + [ + %w(--version --jit --disable=jit), + %w(--version --enable=jit --disable=jit), + %w(--version --enable-jit --disable-jit), + ].each do |args| + assert_in_out_err(args) do |r, e| + assert_match(VERSION_PATTERN, r[0]) + assert_match(NO_JIT_DESCRIPTION, r[0]) + assert_equal([], e) + end + end + if JITSupport.supported? - assert_in_out_err(%w(--version --jit)) do |r, e| - assert_match(VERSION_PATTERN_WITH_JIT, r[0]) - if RubyVM::MJIT.enabled? - assert_equal(RUBY_DESCRIPTION, r[0]) - else - assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + [ + %w(--version --jit), + %w(--version --enable=jit), + %w(--version --enable-jit), + ].each do |args| + assert_in_out_err(args) do |r, e| + assert_match(VERSION_PATTERN_WITH_JIT, r[0]) + if RubyVM::MJIT.enabled? + assert_equal(RUBY_DESCRIPTION, r[0]) + else + assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + end + assert_equal([], e) end - assert_equal([], e) end end end Index: ruby.c =================================================================== --- ruby.c (revision 63994) +++ ruby.c (revision 63995) @@ -77,6 +77,8 @@ char *getenv(); https://github.com/ruby/ruby/blob/trunk/ruby.c#L77 X(rubyopt) \ SEP \ X(frozen_string_literal) \ + SEP \ + X(jit) \ /* END OF FEATURES */ #define EACH_DEBUG_FEATURES(X, SEP) \ X(frozen_string_literal) \ @@ -167,6 +169,7 @@ enum { https://github.com/ruby/ruby/blob/trunk/ruby.c#L169 & ~FEATURE_BIT(gems) #endif & ~FEATURE_BIT(frozen_string_literal) + & ~FEATURE_BIT(jit) ) }; @@ -180,7 +183,7 @@ cmdline_options_init(ruby_cmdline_option https://github.com/ruby/ruby/blob/trunk/ruby.c#L183 opt->intern.enc.index = -1; opt->features = DEFAULT_FEATURES; #ifdef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */ - opt->mjit.on = MJIT_FORCE_ENABLE; + opt->features |= FEATURE_BIT(jit); #endif return opt; } @@ -272,6 +275,7 @@ usage(const char *name, int help) https://github.com/ruby/ruby/blob/trunk/ruby.c#L275 M("did_you_mean", "", "did_you_mean (default: "DEFAULT_RUBYGEMS_ENABLED")"), M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"), M("frozen-string-literal", "", "freeze all string literals (default: disabled)"), + M("jit", "", "MJIT (default: disabled)"), }; static const struct message mjit_options[] = { M("--jit-warnings", "", "Enable printing MJIT warnings"), @@ -945,7 +949,6 @@ set_option_encoding_once(const char *typ https://github.com/ruby/ruby/blob/trunk/ruby.c#L949 static void setup_mjit_options(const char *s, struct mjit_options *mjit_opt) { - mjit_opt->on = 1; if (*s == 0) return; else if (strcmp(s, "-warnings") == 0) { mjit_opt->warnings = 1; @@ -1327,6 +1330,7 @@ proc_options(long argc, char **argv, rub https://github.com/ruby/ruby/blob/trunk/ruby.c#L1330 ruby_verbose = Qtrue; } else if (strncmp("jit", s, 3) == 0) { + opt->features |= FEATURE_BIT(jit); setup_mjit_options(s + 3, &opt->mjit); } else if (strcmp("yydebug", s) == 0) { @@ -1568,8 +1572,11 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1572 if (opt->src.enc.name) rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); + if (opt->features & FEATURE_BIT(jit)) { + opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */ + } if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) { - mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() is still not called here. */ + mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() still can't be called here. */ ruby_show_version(); if (opt->dump & DUMP_BIT(version)) return Qtrue; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/