Skip to content

Commit

Permalink
Merge pull request #4 from Shopify/pass-self-type
Browse files Browse the repository at this point in the history
Pass self type through method calls
  • Loading branch information
maximecb authored Apr 20, 2021
2 parents c66460a + 3c04d6d commit d1eade0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ YJIT - Yet Another Ruby JIT

YJIT is a lightweight, minimalistic Ruby JIT built inside the CRuby/MRI binary.
It lazily compiles code using a Basic Block Versioning (BBV) architecture. The target use case is that of servers running
Ruby on Rails, an area where CRuby's MJIT has not yet managed to deliver speedups.
Ruby on Rails, an area where CRuby's MJIT has not yet managed to deliver speedups.
To simplify development, we currently support only MacOS and Linux on x86-64, but an ARM64 backend
is part of future plans.
This project is open source and falls under the same license as CRuby.
Expand Down Expand Up @@ -35,13 +35,12 @@ Start by cloning the `yjit` branch of the `Shopify/ruby` repository:
```
git clone https://github.com/Shopify/ruby.git yjit
cd yjit
git checkout yjit
```

The YJIT `ruby` binary can be built with either GCC or Clang. We recommend enabling debug symbols so that assertions are enabled during development as this makes debugging easier. More detailed build instructions are provided in the [Ruby README](https://github.com/ruby/ruby#how-to-compile-and-install).

```
autoconf
./autogen.sh
./configure cppflags=-DRUBY_DEBUG --prefix=$HOME/.rubies/ruby-yjit
make -j16 install
```
Expand Down
8 changes: 5 additions & 3 deletions yjit_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ static codegen_status_t
gen_putself(jitstate_t* jit, ctx_t* ctx)
{
// Load self from CFP
mov(cb, RAX, member_opnd(REG_CFP, rb_control_frame_t, self));
mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, self));

// Write it on the stack
x86opnd_t stack_top = ctx_stack_push_self(ctx);
mov(cb, stack_top, RAX);
mov(cb, stack_top, REG0);

return YJIT_KEEP_COMPILING;
}
Expand Down Expand Up @@ -1792,11 +1792,13 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
// Create a context for the callee
ctx_t callee_ctx = DEFAULT_CTX;

// Set the argument type in the callee's context
// Set the argument types in the callee's context
for (int32_t arg_idx = 0; arg_idx < argc; ++arg_idx) {
val_type_t arg_type = ctx_get_opnd_type(ctx, OPND_STACK(argc - arg_idx - 1));
ctx_set_local_type(&callee_ctx, arg_idx, arg_type);
}
val_type_t recv_type = ctx_get_opnd_type(ctx, OPND_STACK(argc));
ctx_set_opnd_type(&callee_ctx, OPND_SELF, recv_type);

// Pop arguments and receiver in return context, push the return value
// After the return, the JIT and interpreter SP will match up
Expand Down
3 changes: 1 addition & 2 deletions yjit_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ Set the type of an instruction operand
*/
void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type)
{
RUBY_ASSERT(opnd.idx < ctx->stack_size);

if (opnd.is_self) {
ctx->self_type = type;
return;
Expand All @@ -170,6 +168,7 @@ void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type)
if (ctx->stack_size > MAX_TEMP_TYPES)
return;

RUBY_ASSERT(opnd.idx < ctx->stack_size);
temp_mapping_t mapping = ctx->temp_mapping[ctx->stack_size - 1 - opnd.idx];

switch (mapping.kind)
Expand Down

0 comments on commit d1eade0

Please sign in to comment.