From: "k0kubun (Takashi Kokubun) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "k0kubun (Takashi Kokubun)" <noreply@ruby-lang.org>
Subject: [ruby-core:121868] [Ruby Bug#21310] YJIT optimization causes incorrect is_a? method evaluation
Date: Tue, 06 May 2025 22:32:24 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-112931.20250506223224.58012@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21310.20250506010807.58012@ruby-lang.org>
Issue #21310 has been updated by k0kubun (Takashi Kokubun).
Status changed from Open to Feedback
I think it's most likely fixed by https://github.com/ruby/ruby/pull/13245. It's going to be shipped in the next release. I'm thinking of releasing it as soon as we address a few other similar cases.
----------------------------------------
Bug #21310: YJIT optimization causes incorrect is_a? method evaluation
https://bugs.ruby-lang.org/issues/21310#change-112931
* Author: ravron-hb (Riley Avron)
* Status: Feedback
* Assignee: jit
* ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin24]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Our Rails application contains code like the following:
```ruby
result = a_proc.call
if result.is_a?(Result) && result.nil?
puts('This should be impossible')
end
```
With YJIT enabled in dev mode and the `yjit-call-threshold` set to 2, the seemingly impossible condition always evaluates to true, and the `puts` is evaluated. If YJIT is disabled, the code behaves as expected: namely, the condition never evaluates to true. If YJIT is enabled but not in dev mode, with the `yjit-call-threshold` is set to 1,500 (as in our original configuration), the error occurs non-deterministically.
We originally discovered this issue while updating to Rails 7.2. The following code began to occasionally fail with a `NoMethodError`, complaining that `nil:NilClass` does not define `success?`:
```ruby
result = a_proc.call
raise ResultRollbackError, result if result.is_a?(Result) && !result.success?
```
`Result` *does* define `success?`, so it seemed impossible that `result.success?` would be invoked unless `result.is_a?(Result)`, and especially impossible that it would be invoked if `result.nil?`. After various debugging, we added the `if` statement shown in the first code block and discovered that YJIT’s optimizations seem to be incorrect.
The inability to predict the possible errors this could cause in our application led us to disable YJIT for our entire application while this behavior persists.
Unfortunately, we have not been able to reproduce the error in a self-contained case, which I know will make investigation more difficult. That said, we would like to assist in solving it however possible. We would appreciate guidance on how to obtain relevant debugging information, or suggestions on how we might generate a self-contained reproduction of the issue. We would also be willing to consider allowing a Ruby maintainer to review the actual code demonstrating the issue, though we would probably request that they sign an NDA in that case.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
next prev parent reply other threads:[~2025-05-06 22:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 1:08 [ruby-core:121835] " ravron-hb (Riley Avron) via ruby-core
2025-05-06 22:27 ` [ruby-core:121867] " k0kubun (Takashi Kokubun) via ruby-core
2025-05-06 22:32 ` k0kubun (Takashi Kokubun) via ruby-core [this message]
2025-05-24 7:39 ` [ruby-core:122273] " nagachika (Tomoyuki Chikanaga) via ruby-core
2025-05-24 9:15 ` [ruby-core:122276] " nagachika (Tomoyuki Chikanaga) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-112931.20250506223224.58012@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).