From ade22339e3056710dbe27eaa624c2e76fa15567b Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Tue, 30 Apr 2024 13:57:18 -0400 Subject: [PATCH] YJIT: print msg to stderr when RubyVM::YJIT.disasm not available (#10688) * YJIT: print msg to stderr when RubyVM::YJIT.disasm not available Print a more useful error message when people try to use this feature without YJIT dev. Also fix an issue with .gitignore file on macOS * Update yjit.rb Co-authored-by: Randy Stauner * Use warn and always return nil if YJIT disasm not available. --------- Co-authored-by: Randy Stauner --- .gitignore | 1 + yjit.rb | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d7a8b978c9..b6beba3b3e 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,7 @@ lcov*.info # /coroutine/ !/coroutine/**/*.s +!/coroutine/**/*.S # /enc/trans/ /enc/trans/*.c diff --git a/yjit.rb b/yjit.rb index eedd00c358..6612d8bd82 100644 --- a/yjit.rb +++ b/yjit.rb @@ -201,13 +201,27 @@ module RubyVM::YJIT # If a method or proc is passed in, get its iseq iseq = RubyVM::InstructionSequence.of(iseq) - if self.enabled? - # Produce the disassembly string - # Include the YARV iseq disasm in the string for additional context - iseq.disasm + "\n" + Primitive.rb_yjit_disasm_iseq(iseq) - else - iseq.disasm + if !self.enabled? + warn( + "YJIT needs to be enabled to produce disasm output, e.g.\n" + + "ruby --yjit-call-threshold=1 my_script.rb (see doc/yjit/yjit.md)" + ) + return nil end + + disasm_str = Primitive.rb_yjit_disasm_iseq(iseq) + + if !disasm_str + warn( + "YJIT disasm is only available when YJIT is built in dev mode, i.e.\n" + + "./configure --enable-yjit=dev (see doc/yjit/yjit.md)\n" + ) + return nil + end + + # Produce the disassembly string + # Include the YARV iseq disasm in the string for additional context + iseq.disasm + "\n" + disasm_str end # Produce a list of instructions compiled by YJIT for an iseq