Skip to content

Commit 3246bbd

Browse files
tekknolagiXrXr
authored andcommitted
ZJIT: Add codegen for uncached setinstancevariable
1 parent 6a46ca3 commit 3246bbd

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ def test() = @foo
559559
}
560560
end
561561

562+
def test_setinstancevariable
563+
assert_compiles '1', %q{
564+
def test() = @foo = 1
565+
566+
test()
567+
@foo
568+
}
569+
end
570+
562571
# tool/ruby_vm/views/*.erb relies on the zjit instructions a) being contiguous and
563572
# b) being reliably ordered after all the other instructions.
564573
def test_instruction_order

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ fn main() {
381381
.allowlist_function("rb_attr_get")
382382
.allowlist_function("rb_ivar_defined")
383383
.allowlist_function("rb_ivar_get")
384+
.allowlist_function("rb_ivar_set")
384385
.allowlist_function("rb_mod_name")
385386

386387
// From include/ruby/internal/intern/vm.h

zjit/src/codegen.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
275275
Insn::PatchPoint(_) => return Some(()), // For now, rb_zjit_bop_redefined() panics. TODO: leave a patch point and fix rb_zjit_bop_redefined()
276276
Insn::CCall { cfun, args, name: _, return_type: _, elidable: _ } => gen_ccall(jit, asm, *cfun, args)?,
277277
Insn::GetIvar { self_val, id, state: _ } => gen_getivar(asm, opnd!(self_val), *id),
278+
Insn::SetIvar { self_val, id, val, state: _ } => gen_setivar(asm, opnd!(self_val), *id, opnd!(val)),
278279
_ => {
279280
debug!("ZJIT: gen_function: unexpected insn {:?}", insn);
280281
return None;
@@ -307,6 +308,15 @@ fn gen_getivar(asm: &mut Assembler, recv: Opnd, id: ID) -> Opnd {
307308
)
308309
}
309310

311+
/// Emit an uncached instance variable store
312+
fn gen_setivar(asm: &mut Assembler, recv: Opnd, id: ID, val: Opnd) -> Opnd {
313+
asm_comment!(asm, "call rb_ivar_set");
314+
asm.ccall(
315+
rb_ivar_set as *const u8,
316+
vec![recv, Opnd::UImm(id.0), val],
317+
)
318+
}
319+
310320
/// Compile an interpreter entry block to be inserted into an ISEQ
311321
fn gen_entry_prologue(asm: &mut Assembler, iseq: IseqPtr) {
312322
asm_comment!(asm, "ZJIT entry point: {}", iseq_get_location(iseq, 0));

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.

0 commit comments

Comments
 (0)