MJIT: Make it parsable by Solargraph (#6827)

* Revert "Revert "MJIT: Make it parsable by Solargraph""

This reverts commit 8e18761da1.

* Call rb_gc_register_mark_object
This commit is contained in:
Takashi Kokubun 2022-11-28 21:33:55 -08:00 коммит произвёл GitHub
Родитель acb76663ba
Коммит 9c13fc614c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 902 добавлений и 900 удалений

Просмотреть файл

@ -13,13 +13,16 @@
# DISPATCH_ORIGINAL_INSN(): expanded in _mjit_compile_insn.erb
# THROW_EXCEPTION(): specially defined for JIT
# RESTORE_REGS(): specially defined for `leave`
module RubyVM::MJIT
class RubyVM::MJIT::Compiler
C = RubyVM::MJIT.const_get(:C, false)
INSNS = RubyVM::MJIT.const_get(:INSNS, false)
UNSUPPORTED_INSNS = [
:defineclass, # low priority
]
class << Compiler = Module.new
# @param iseq [RubyVM::MJIT::CPointer::Struct_*]
def initialize = freeze
# @param iseq [RubyVM::MJIT::CPointer::Struct]
# @param funcname [String]
# @param id [Integer]
# @return [String,NilClass]
@ -964,5 +967,4 @@ module RubyVM::MJIT
parent_id
end
end
end
end

5
mjit.c
Просмотреть файл

@ -1324,7 +1324,7 @@ static VALUE rb_mMJIT = 0;
// RubyVM::MJIT::C
VALUE rb_mMJITC = 0;
// RubyVM::MJIT::Compiler
VALUE rb_mMJITCompiler = 0;
VALUE rb_cMJITCompiler = 0;
// [experimental] Call custom RubyVM::MJIT.compile if defined
static void
@ -1765,8 +1765,9 @@ mjit_init(const struct mjit_options *opts)
mjit_enabled = false;
return;
}
rb_mMJITCompiler = rb_const_get(rb_mMJIT, rb_intern("Compiler"));
rb_mMJITC = rb_const_get(rb_mMJIT, rb_intern("C"));
rb_cMJITCompiler = rb_funcall(rb_const_get(rb_mMJIT, rb_intern("Compiler")), rb_intern("new"), 0);
rb_gc_register_mark_object(rb_cMJITCompiler);
mjit_call_p = true;
mjit_pid = getpid();

Просмотреть файл

@ -20,6 +20,7 @@ if RubyVM::MJIT.enabled?
return # miniruby doesn't support MJIT
end
RubyVM::MJIT::C = Object.new # forward declaration for mjit/compiler
require "mjit/c_type"
require "mjit/instruction"
require "mjit/compiler"

Просмотреть файл

@ -2,8 +2,6 @@
# Part of this file is generated by tool/mjit/bindgen.rb.
# Run `make mjit-bindgen` to update code between "MJIT bindgen begin" and "MJIT bindgen end".
module RubyVM::MJIT
C = Object.new
# This `class << C` section is for calling C functions. For importing variables
# or macros as is, please consider using tool/mjit/bindgen.rb instead.
class << C
@ -769,4 +767,4 @@ module RubyVM::MJIT
end
### MJIT bindgen end ###
end if RubyVM::MJIT.enabled?
end if RubyVM::MJIT.enabled? && RubyVM::MJIT.const_defined?(:C) # not defined for miniruby

Просмотреть файл

@ -122,8 +122,8 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id)
bool original_call_p = mjit_call_p;
mjit_call_p = false; // Avoid impacting JIT metrics by itself
extern VALUE rb_mMJITCompiler;
VALUE src = rb_funcall(rb_mMJITCompiler, rb_intern("compile"), 3,
extern VALUE rb_cMJITCompiler;
VALUE src = rb_funcall(rb_cMJITCompiler, rb_intern("compile"), 3,
rb_ptr("rb_iseq_t", iseq), rb_str_new_cstr(funcname), INT2NUM(id));
if (!NIL_P(src)) {
fprintf(f, "%s", RSTRING_PTR(src));