Skip to content
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

[WIP] Opt send new #544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WIP
  • Loading branch information
byroot committed Nov 4, 2023
commit 716c856c98e3a7ccda257afabacc969846a13c01
2 changes: 1 addition & 1 deletion compile.c
Original file line number Diff line number Diff line change
@@ -3933,7 +3933,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
switch (vm_ci_mid(ci)) {
case idNew:
iobj->insn_id = BIN(opt_new);
iobj->operands[1] = (VALUE)new_callinfo(iseq, idInitialize, vm_ci_argc(ci), vm_ci_flag(ci) | VM_CALL_FCALL, vm_ci_kwarg(ci), FALSE);
iobj->operands[1] = (VALUE)new_callinfo(iseq, idInitialize, vm_ci_argc(ci) - vm_ci_kwarg(ci)->keyword_len, vm_ci_flag(ci) | VM_CALL_FCALL, vm_ci_kwarg(ci), FALSE);
break;
default:
iobj->insn_id = BIN(opt_send_without_block);
38 changes: 24 additions & 14 deletions insns.def
Original file line number Diff line number Diff line change
@@ -838,22 +838,32 @@ opt_new
// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
{
VALUE recv = TOPN(vm_ci_argc(cd->ci));

val = vm_opt_new_alloc(GET_ISEQ(), recv, cd);
if (val != Qundef) {
TOPN(vm_ci_argc(cd->ci)) = val;
fprintf(stderr, "opt!\n");
if (vm_sendish(ec, GET_CFP(), cd_initialize, VM_BLOCK_HANDLER_NONE, mexp_search_method) == Qundef) {
val = Qundef;
}
}
int argc = vm_ci_argc(cd->ci);
VM_ASSERT((int)vm_ci_argc(cd_initialize->ci) == argc);

if (val == Qundef) {
fprintf(stderr, "de-opt!\n");
VALUE recv = TOPN(argc);
val = Qundef;

VALUE new_obj = vm_opt_new_alloc(GET_ISEQ(), recv, cd);
if (new_obj != Qundef) {
TOPN(argc) = new_obj;

val = vm_sendish(ec, GET_CFP(), cd_initialize, VM_BLOCK_HANDLER_NONE, mexp_search_method);
// FIXME: somehow the `initialize` return is what end up being the `.new` return, instead of `new_obj`.
// I don't get why.

JIT_EXEC(ec, val);

VALUE bh = VM_BLOCK_HANDLER_NONE;
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
if (val == Qundef) {
RESTORE_REGS();
NEXT_INSN();
}
else {
val = new_obj;
}
}
else if (val == Qundef) {
val = vm_sendish(ec, GET_CFP(), cd, VM_BLOCK_HANDLER_NONE, mexp_search_method);
JIT_EXEC(ec, val);

if (val == Qundef) {
2 changes: 2 additions & 0 deletions internal/object.h
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ static inline void RBASIC_CLEAR_CLASS(VALUE obj);
static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
VALUE rb_class_alloc(VALUE klass);
VALUE rb_obj_initialize(VALUE _self);


RUBY_SYMBOL_EXPORT_BEGIN
/* object.c (export) */
6 changes: 5 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
@@ -1222,7 +1222,11 @@ rb_class_search_ancestor(VALUE cl, VALUE c)
*
* Returns a new BasicObject.
*/
#define rb_obj_initialize rb_obj_dummy0
VALUE
rb_obj_initialize(VALUE _self)
{
return Qnil;
}

/*
* Not documented