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 <randy@r4s6.net>

* Use warn and always return nil if YJIT disasm not available.

---------

Co-authored-by: Randy Stauner <randy@r4s6.net>
This commit is contained in:
Maxime Chevalier-Boisvert 2024-04-30 13:57:18 -04:00 коммит произвёл GitHub
Родитель bd419a6578
Коммит ade22339e3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 21 добавлений и 6 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -167,6 +167,7 @@ lcov*.info
# /coroutine/
!/coroutine/**/*.s
!/coroutine/**/*.S
# /enc/trans/
/enc/trans/*.c

26
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