Skip to content

ZJIT: Guide WB skipping for Insn::SetLocal using HIR type info #13978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Jul 22, 2025

Also tweak the opnd!() macro so that it works with both an &InsnId and
an InsnId.

Following discussions in #13977

@matzbot matzbot requested a review from a team July 22, 2025 22:40

This comment has been minimized.

@@ -353,7 +353,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
Insn::SetGlobal { id, val, state: _ } => return Some(gen_setglobal(asm, *id, opnd!(val))),
Insn::GetGlobal { id, state: _ } => gen_getglobal(asm, *id),
&Insn::GetLocal { ep_offset, level } => gen_getlocal_with_ep(asm, ep_offset, level)?,
Insn::SetLocal { val, ep_offset, level } => return gen_setlocal_with_ep(asm, opnd!(val), *ep_offset, *level),
&Insn::SetLocal { val, ep_offset, level } => return gen_setlocal_with_ep(asm, opnd!(val), function.is_a(val, types::Immediate), ep_offset, level),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function.is_a(val, types::Immediate)

I feel like this kind of type checking (not just fetching the type, but checking that it's "immediate") should be part of the codegen logic (i.e. live inside gen_setlocal_with_ep()). You generally wouldn't want to go back and forth between gen_insn() and gen_setlocal_with_ep() too often when you read/write the logic of codegen.

One way to do that would be to give val_type: Type as an argument. Another way would be to just pass around a reference to function (which seems fine to me) if we want to use the Function::is_a API.

Copy link
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice improvement on opnd! 👍

@XrXr XrXr force-pushed the zjit-setlocal-wb branch from 65d9199 to c38c449 Compare July 22, 2025 23:12
@XrXr
Copy link
Member Author

XrXr commented Jul 22, 2025

Now this crashes when marking an Iseq:

  /home/runner/work/ruby/ruby/src/test/ruby/test_weakkeymap.rb:142: [BUG] Segmentation fault at 0x0000000000000048
  ruby 3.5.0dev (2025-07-22T23:12:12Z pull/13978/merge 844ed0ff83) +ZJIT dev +PRISM [x86_64-linux]
  
  -- C level backtrace information -------------------------------------------
  /home/runner/work/ruby/ruby/build/ruby(rb_print_backtrace+0x8) [0x55e25b22c1e6] ../src/vm_dump.c:843
  /home/runner/work/ruby/ruby/build/ruby(rb_vm_bugreport) ../src/vm_dump.c:1175
  /home/runner/work/ruby/ruby/build/ruby(rb_bug_for_fatal_signal+0xf8) [0x55e25b1e2d58] ../src/error.c:1130
  /home/runner/work/ruby/ruby/build/ruby(sigsegv+0x46) [0x55e25acc0786] ../src/signal.c:946
  /lib/x86_64-linux-gnu/libc.so.6(0x7f2b99a42520) [0x7f2b99a42520]
  /home/runner/work/ruby/ruby/build/ruby(RVALUE_WB_UNPROTECTED+0x17) [0x55e25aba5c10] ../src/gc/default/default.c:1195
  /home/runner/work/ruby/ruby/build/ruby(rgengc_check_relation) ../src/gc/default/default.c:4300
  /home/runner/work/ruby/ruby/build/ruby(RVALUE_MARKED+0x0) [0x55e25abb1eb2] ../src/gc/default/default.c:4369
  /home/runner/work/ruby/ruby/build/ruby(gc_mark_set) ../src/gc/default/default.c:4311
  /home/runner/work/ruby/ruby/build/ruby(gc_mark) ../src/gc/default/default.c:4370
  /home/runner/work/ruby/ruby/build/ruby(rb_zjit_iseq_mark+0x193) [0x55e25ade7a13] zjit/src/gc.rs:88

This could be some bad HIR optimization or some other GC bug...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy