Skip to content

Commit 74e6bdd

Browse files
authored
ZJIT: Parse putspecialobject(VMCore) into Const (ruby#13683)
This way we get more information in HIR for the optimizer. Fix Shopify#587
1 parent 3a9bf4a commit 74e6bdd

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

zjit/src/hir.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,12 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23282328
YARVINSN_putobject => { state.stack_push(fun.push_insn(block, Insn::Const { val: Const::Value(get_arg(pc, 0)) })); },
23292329
YARVINSN_putspecialobject => {
23302330
let value_type = SpecialObjectType::from(get_arg(pc, 0).as_u32());
2331-
state.stack_push(fun.push_insn(block, Insn::PutSpecialObject { value_type }));
2331+
let insn = if value_type == SpecialObjectType::VMCore {
2332+
Insn::Const { val: Const::Value(unsafe { rb_mRubyVMFrozenCore }) }
2333+
} else {
2334+
Insn::PutSpecialObject { value_type }
2335+
};
2336+
state.stack_push(fun.push_insn(block, insn));
23322337
}
23332338
YARVINSN_putstring => {
23342339
let val = fun.push_insn(block, Insn::Const { val: Const::Value(get_arg(pc, 0)) });
@@ -3922,11 +3927,11 @@ mod tests {
39223927
assert_method_hir("test", expect![[r#"
39233928
fn test:
39243929
bb0(v0:BasicObject, v1:BasicObject):
3925-
v3:BasicObject = PutSpecialObject VMCore
3930+
v3:BasicObject[VMFrozenCore] = Const Value(VALUE(0x1000))
39263931
v5:HashExact = NewHash
39273932
v7:BasicObject = SendWithoutBlock v3, :core#hash_merge_kwd, v5, v1
3928-
v8:BasicObject = PutSpecialObject VMCore
3929-
v9:StaticSymbol[VALUE(0x1000)] = Const Value(VALUE(0x1000))
3933+
v8:BasicObject[VMFrozenCore] = Const Value(VALUE(0x1000))
3934+
v9:StaticSymbol[VALUE(0x1008)] = Const Value(VALUE(0x1008))
39303935
v10:Fixnum[1] = Const Value(1)
39313936
v12:BasicObject = SendWithoutBlock v8, :core#hash_merge_ptr, v7, v9, v10
39323937
SideExit
@@ -4374,10 +4379,10 @@ mod tests {
43744379
assert_method_hir_with_opcode("test", YARVINSN_putspecialobject, expect![[r#"
43754380
fn test:
43764381
bb0(v0:BasicObject):
4377-
v2:BasicObject = PutSpecialObject VMCore
4382+
v2:BasicObject[VMFrozenCore] = Const Value(VALUE(0x1000))
43784383
v3:BasicObject = PutSpecialObject CBase
4379-
v4:StaticSymbol[VALUE(0x1000)] = Const Value(VALUE(0x1000))
4380-
v5:StaticSymbol[VALUE(0x1008)] = Const Value(VALUE(0x1008))
4384+
v4:StaticSymbol[VALUE(0x1008)] = Const Value(VALUE(0x1008))
4385+
v5:StaticSymbol[VALUE(0x1010)] = Const Value(VALUE(0x1010))
43814386
v7:BasicObject = SendWithoutBlock v2, :core#set_method_alias, v3, v4, v5
43824387
Return v7
43834388
"#]]);

zjit/src/hir_type/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::cruby::{Qfalse, Qnil, Qtrue, VALUE, RUBY_T_ARRAY, RUBY_T_STRING, RUBY
33
use crate::cruby::{rb_cInteger, rb_cFloat, rb_cArray, rb_cHash, rb_cString, rb_cSymbol, rb_cObject, rb_cTrueClass, rb_cFalseClass, rb_cNilClass, rb_cRange};
44
use crate::cruby::ClassRelationship;
55
use crate::cruby::get_class_name;
6+
use crate::cruby::rb_mRubyVMFrozenCore;
67
use crate::hir::PtrPrintMap;
78

89
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -68,6 +69,7 @@ fn write_spec(f: &mut std::fmt::Formatter, printer: &TypePrinter) -> std::fmt::R
6869
let ty = printer.inner;
6970
match ty.spec {
7071
Specialization::Any | Specialization::Empty => { Ok(()) },
72+
Specialization::Object(val) if val == unsafe { rb_mRubyVMFrozenCore } => write!(f, "[VMFrozenCore]"),
7173
Specialization::Object(val) => write!(f, "[{}]", val.print(printer.ptr_map)),
7274
Specialization::Type(val) => write!(f, "[class:{}]", get_class_name(val)),
7375
Specialization::TypeExact(val) => write!(f, "[class_exact:{}]", get_class_name(val)),

0 commit comments

Comments
 (0)