Skip to content

Commit 5fee1b3

Browse files
committed
Pretty-print symbols in HIR
1 parent c628a74 commit 5fee1b3

5 files changed

Lines changed: 17 additions & 0 deletions

File tree

zjit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,5 +739,11 @@ rb_zjit_print_exception(void)
739739
rb_warn("Ruby error: %"PRIsVALUE"", rb_funcall(exception, rb_intern("full_message"), 0));
740740
}
741741

742+
VALUE
743+
rb_zjit_sym2str(VALUE v)
744+
{
745+
return rb_sym2str(v);
746+
}
747+
742748
// Preprocessed zjit.rb generated during build
743749
#include "zjit.rbinc"

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ fn main() {
343343
.allowlist_function("rb_iseq_reset_jit_func")
344344
.allowlist_function("rb_RSTRING_PTR")
345345
.allowlist_function("rb_RSTRING_LEN")
346+
.allowlist_function("rb_zjit_sym2str")
346347
.allowlist_function("rb_ENCODING_GET")
347348
.allowlist_function("rb_optimized_call")
348349
.allowlist_function("rb_zjit_icache_invalidate")

zjit/src/cruby.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,14 @@ fn ruby_str_to_rust(v: VALUE) -> String {
743743
}
744744
}
745745

746+
// Convert a Ruby symbol to a Rust string by going through a Ruby string first.
747+
pub fn ruby_sym_to_rust_str(v: VALUE) -> String {
748+
assert!(v.symbol_p());
749+
let ruby_str = unsafe { rb_zjit_sym2str(v) };
750+
assert!(ruby_str != VALUE(0), "Could not convert symbol to string");
751+
ruby_str_to_rust(ruby_str)
752+
}
753+
746754
/// A location in Rust code for integrating with debugging facilities defined in C.
747755
/// Use the [src_loc!] macro to crate an instance.
748756
pub struct SourceLocation {

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<'a> std::fmt::Display for VALUEPrinter<'a> {
6969
Qnil => write!(f, "nil"),
7070
Qtrue => write!(f, "true"),
7171
Qfalse => write!(f, "false"),
72+
val if val.symbol_p() => write!(f, ":{}", ruby_sym_to_rust_str(val)),
7273
val => write!(f, "VALUE({:p})", self.ptr_map.map_ptr(val.as_ptr::<VALUE>())),
7374
}
7475
}

0 commit comments

Comments
 (0)