8000 Merge pull request #204 from Shopify/no-yjit-mjit · github/ruby@99e87e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99e87e7

Browse files
authored
Merge pull request #204 from Shopify/no-yjit-mjit
Exit if YJIT and MJIT are both enabled
2 parents 70e3513 + cb596ae commit 99e87e7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

ruby.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ enum {
219219
#endif
220220
& ~FEATURE_BIT(frozen_string_literal)
221221
& ~FEATURE_BIT(jit)
222+
& ~FEATURE_BIT(yjit)
222223
)
223224
};
224225

@@ -233,8 +234,9 @@ cmdline_options_init(ruby_cmdline_options_t *opt)
233234
opt->features.set = DEFAULT_FEATURES;
234235
#ifdef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */
235236
opt->features.set |= FEATURE_BIT(jit);
236-
#endif
237+
#else
237238
opt->features.set |= FEATURE_BIT(yjit);
239+
#endif
238240
return opt;
239241
}
240242

@@ -925,6 +927,7 @@ feature_option(const char *str, int len, void *arg, const unsigned int enable)
925927
if (NAME_MATCH_P(#bit, str, len)) {set |= mask = FEATURE_BIT(bit); FEATURE_FOUND;}
926928
EACH_FEATURES(SET_FEATURE, ;);
927929
if (NAME_MATCH_P("all", str, len)) {
930+
mask &= ~(FEATURE_BIT(jit));
928931
goto found;
929932
}
930933
#if AMBIGUOUS_FEATURE_NAMES
@@ -1824,13 +1827,20 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
18241827
*/
18251828
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
18261829

1827-
if (opt->features.set & FEATURE_BIT(yjit))
1828-
rb_yjit_init(&opt->yjit);
18291830
#if USE_MJIT
18301831
if (opt->features.set & FEATURE_BIT(jit)) {
18311832
opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */
18321833
}
18331834
#endif
1835+
if (opt->features.set & FEATURE_BIT(yjit)) {
1836+
#if USE_MJIT
1837+
if (opt->mjit.on) {
1838+
rb_warn("MJIT and YJIT cannot both be enabled at the same time. Exiting");
1839+
exit(1);
1840+
}
1841+
#endif
1842+
rb_yjit_init(&opt->yjit);
1843+
}
18341844
if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) {
18351845
#if USE_MJIT
18361846
mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() still can't be called here. */

test/ruby/test_rubyoptions.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ def test_version
229229

230230
if JITSupport.supported?
231231
[
232-
%w(--version --jit),
233-
%w(--version --enable=jit),
234-
%w(--version --enable-jit),
232+
%w(--version --disable-yjit --jit),
233+
%w(--version --disable-yjit --enable=jit),
234+
%w(--version --disable-yjit --enable-jit),
235235
].each do |args|
236236
assert_in_out_err(args) do |r, e|
237237
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
238238
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
239239
assert_equal(RUBY_DESCRIPTION, r[0])
240240
else
241-
assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
241+
assert_equal(EnvUtil.invoke_ruby(['--disable-yjit', '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
242242
end
243243
assert_equal([], e)
244244
end
@@ -1103,7 +1103,7 @@ def test_jit_debug
11031103
# mswin uses prebuilt precompiled header. Thus it does not show a pch compilation log to check "-O0 -O1".
11041104
if JITSupport.supported? && !RUBY_PLATFORM.match?(/mswin/)
11051105
env = { 'MJIT_SEARCH_BUILD_DIR' => 'true' }
1106-
assert_in_out_err([env, "--jit-debug=-O0 -O1", "--jit-verbose=2", "" ], "", [], /-O0 -O1/)
1106+
assert_in_out_err([env, "--disable-yjit", "--jit-debug=-O0 -O1", "--jit-verbose=2", "" ], "", [], /-O0 -O1/)
11071107
end
11081108
end
11091109

0 commit comments

Comments
 (0)
0