summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorAlan Wu <alanwu@ruby-lang.org>2022-04-19 14:40:21 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2022-04-27 11:00:22 -0400
commitf90549cd38518231a6a74432fe1168c943a7cc18 (patch)
treec277bbfab47e230bd549bd5f607f60c3e812a714 /ruby.c
parentf553180a86b71830a1de49dd04874b3880c5c698 (diff)
Rust YJIT
In December 2021, we opened an [issue] to solicit feedback regarding the porting of the YJIT codebase from C99 to Rust. There were some reservations, but this project was given the go ahead by Ruby core developers and Matz. Since then, we have successfully completed the port of YJIT to Rust. The new Rust version of YJIT has reached parity with the C version, in that it passes all the CRuby tests, is able to run all of the YJIT benchmarks, and performs similarly to the C version (because it works the same way and largely generates the same machine code). We've even incorporated some design improvements, such as a more fine-grained constant invalidation mechanism which we expect will make a big difference in Ruby on Rails applications. Because we want to be careful, YJIT is guarded behind a configure option: ```shell ./configure --enable-yjit # Build YJIT in release mode ./configure --enable-yjit=dev # Build YJIT in dev/debug mode ``` By default, YJIT does not get compiled and cargo/rustc is not required. If YJIT is built in dev mode, then `cargo` is used to fetch development dependencies, but when building in release, `cargo` is not required, only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer. The YJIT command-line options remain mostly unchanged, and more details about the build process are documented in `doc/yjit/yjit.md`. The CI tests have been updated and do not take any more resources than before. The development history of the Rust port is available at the following commit for interested parties: https://github.com/Shopify/ruby/commit/1fd9573d8b4b65219f1c2407f30a0a60e537f8be Our hope is that Rust YJIT will be compiled and included as a part of system packages and compiled binaries of the Ruby 3.2 release. We do not anticipate any major problems as Rust is well supported on every platform which YJIT supports, but to make sure that this process works smoothly, we would like to reach out to those who take care of building systems packages before the 3.2 release is shipped and resolve any issues that may come up. [issue]: https://bugs.ruby-lang.org/issues/18481 Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com> Co-authored-by: Kevin Newton <kddnewton@gmail.com>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5826
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c53
1 files changed, 20 insertions, 33 deletions
diff --git a/ruby.c b/ruby.c
index ade434cff3..9e38572751 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1028,36 +1028,23 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen
#define yjit_opt_match_arg(s, l, name) \
opt_match(s, l, name) && (*(s) && *(s+1) ? 1 : (rb_raise(rb_eRuntimeError, "--yjit-" name " needs an argument"), 0))
-#if YJIT_SUPPORTED_P
-static void
-setup_yjit_options(const char *s, struct rb_yjit_options *yjit_opt)
+#if YJIT_BUILD
+static bool
+setup_yjit_options(const char *s)
{
- const size_t l = strlen(s);
- if (l == 0) {
- return;
- }
- else if (yjit_opt_match_arg(s, l, "exec-mem-size")) {
- yjit_opt->exec_mem_size = atoi(s + 1);
- }
- else if (yjit_opt_match_arg(s, l, "call-threshold")) {
- yjit_opt->call_threshold = atoi(s + 1);
- }
- else if (yjit_opt_match_arg(s, l, "max-versions")) {
- yjit_opt->max_versions = atoi(s + 1);
- }
- else if (yjit_opt_match_noarg(s, l, "greedy-versioning")) {
- yjit_opt->greedy_versioning = true;
- }
- else if (yjit_opt_match_noarg(s, l, "no-type-prop")) {
- yjit_opt->no_type_prop = true;
- }
- else if (yjit_opt_match_noarg(s, l, "stats")) {
- yjit_opt->gen_stats = true;
- }
- else {
- rb_raise(rb_eRuntimeError,
- "invalid yjit option `%s' (--help will show valid yjit options)", s);
+ // The option parsing is done in yjit/src/options.rs
+ bool rb_yjit_parse_option(const char* s);
+ bool success = rb_yjit_parse_option(s);
+
+ if (success) {
+ return true;
}
+
+ rb_raise(
+ rb_eRuntimeError,
+ "invalid YJIT option `%s' (--help will show valid yjit options)",
+ s
+ );
}
#endif
@@ -1446,11 +1433,11 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
#endif
}
else if (is_option_with_optarg("yjit", '-', true, false, false)) {
-#if YJIT_SUPPORTED_P
+#if YJIT_BUILD
FEATURE_SET(opt->features, FEATURE_BIT(yjit));
- setup_yjit_options(s, &opt->yjit);
+ setup_yjit_options(s);
#else
- rb_warn("Ruby was built without JIT support");
+ rb_warn("Ruby was built without YJIT support");
#endif
}
else if (strcmp("yydebug", s) == 0) {
@@ -1835,8 +1822,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
exit(1);
}
#endif
-#if YJIT_SUPPORTED_P
- rb_yjit_init(&opt->yjit);
+#if YJIT_BUILD
+ rb_yjit_init();
#endif
}
if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) {