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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2018-07-18 12:45:54 +00:00
Родитель 4bc1669127
Коммит 053cdaf7ee
3 изменённых файлов: 40 добавлений и 12 удалений

4
mjit.h
Просмотреть файл

@ -27,7 +27,9 @@ enum rb_mjit_iseq_func {
/* 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. */

13
ruby.c
Просмотреть файл

@ -77,6 +77,8 @@ char *getenv();
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 {
& ~FEATURE_BIT(gems)
#endif
& ~FEATURE_BIT(frozen_string_literal)
& ~FEATURE_BIT(jit)
)
};
@ -180,7 +183,7 @@ cmdline_options_init(ruby_cmdline_options_t *opt)
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)
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 *type, VALUE *name, const char *e, long elen
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, ruby_cmdline_options_t *opt, int envopt)
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, ruby_cmdline_options_t *opt)
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;
}

Просмотреть файл

@ -181,17 +181,36 @@ class TestRubyOptions < Test::Unit::TestCase
end
assert_equal([], e)
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])
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?
[
%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
end
end
end
def test_eval