Skip to content

Commit

Permalink
Remove all traces of rubyclass stack from the codebase.
Browse files Browse the repository at this point in the history
* Removed klass arg from method calls.
* Remove the push/pop/get from thread-context and use sites.
* TODO: embed used to inject values into the current-module obtained
  from the rubyclass stack. That code needs investigation.
* Replaced the hacky if (klass==null) prepareSelf(binding) calls
  with information about actual execution context. The primary reason
  to use binding.self instead of self argument in blocks is when
  the block is being used in a binding-eval context. The same soln.
  is applicable in other contexts where this pattern was used (and
  currently marked with SSS FIXME annotations in code comments).
  • Loading branch information
subbuss committed Jun 29, 2014
1 parent 92833b9 commit 525a110
Show file tree
Hide file tree
Showing 35 changed files with 146 additions and 269 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -3224,7 +3224,7 @@ private IRubyObject sortInternal(final ThreadContext context, final Block block)
public int compare(Object o1, Object o2) {
IRubyObject obj1 = (IRubyObject) o1;
IRubyObject obj2 = (IRubyObject) o2;
IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null, null);
IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null);
//TODO: ary_sort_check should be done here
return RubyComparable.cmpint(context, ret, obj1, obj2);
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -42,7 +42,6 @@

import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.evaluator.ASTInterpreter;
import org.jruby.exceptions.JumpException;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.javasupport.JavaObject;
Expand Down Expand Up @@ -1621,10 +1620,10 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
try {
if (args.length == 1) {
IRubyObject valueInYield = args[0];
return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this, context.getRubyClass());
return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this); // context.getRubyClass());
} else {
IRubyObject valueInYield = RubyArray.newArrayNoCopy(context.runtime, args);
return setupBlock(block, evalType).yieldArray(context, valueInYield, this, context.getRubyClass());
return setupBlock(block, evalType).yieldArray(context, valueInYield, this); // context.getRubyClass());
}
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
Expand Down Expand Up @@ -1662,7 +1661,7 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
block.getBinding().setVisibility(PUBLIC);

try {
return setupBlock(block, evalType).yieldNonArray(context, this, this, context.getRubyClass());
return setupBlock(block, evalType).yieldNonArray(context, this, this); // context.getRubyClass());
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
return (IRubyObject) bj.getValue();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Expand Up @@ -763,7 +763,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
larg = RubyArray.newArrayNoCopy(ctx.runtime, largs);
}

IRubyObject value = newAry ? block.yieldArray(ctx, larg, null, null) : block.yield(ctx, larg);
IRubyObject value = newAry ? block.yieldArray(ctx, larg, null) : block.yield(ctx, larg);
synchronized (result) {
result.append(value);
}
Expand Down Expand Up @@ -828,7 +828,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = packEnumValues(runtime, largs);
checkContext(localContext, ctx, "inject");
result[0] = result[0] == null ?
larg : block.yieldArray(ctx, runtime.newArray(result[0], larg), null, null);
larg : block.yieldArray(ctx, runtime.newArray(result[0], larg), null);

return runtime.getNil();
}
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = packEnumValues(runtime, largs);
checkContext(localContext, ctx, "max{}");
if (result[0] == null || RubyComparable.cmpint(ctx, block.yieldArray(ctx,
runtime.newArray(larg, result[0]), null, null), larg, result[0]) > 0) {
runtime.newArray(larg, result[0]), null), larg, result[0]) > 0) {
result[0] = larg;
}
return runtime.getNil();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyHash.java
Expand Up @@ -1364,7 +1364,7 @@ public void visit(IRubyObject key, IRubyObject value) {
if (oneNine) {
block.yield(context, RubyArray.newArray(runtime, key, value));
} else {
block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null);
block.yieldArray(context, RubyArray.newArray(runtime, key, value), null);
}
}
});
Expand Down Expand Up @@ -1604,7 +1604,7 @@ public IRubyObject select19(final ThreadContext context, final Block block) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (block.yieldArray(context, runtime.newArray(key, value), null, null).isTrue()) {
if (block.yieldArray(context, runtime.newArray(key, value), null).isTrue()) {
result.fastASet(key, value);
}
}
Expand All @@ -1624,7 +1624,7 @@ public RubyHash delete_ifInternal(final ThreadContext context, final Block block
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null).isTrue()) {
if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null).isTrue()) {
self.delete(context, key, Block.NULL_BLOCK);
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/RubyProc.java
Expand Up @@ -146,7 +146,6 @@ private void setup(Block procBlock) {
oldBinding.getSelf(),
oldBinding.getFrame().duplicate(),
oldBinding.getVisibility(),
oldBinding.getKlass(),
oldBinding.getDynamicScope(),
oldBinding.getBacktrace().clone());
block = new Block(procBlock.getBody(), newBinding);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyStruct.java
Expand Up @@ -254,7 +254,7 @@ public DynamicMethod dup() {
if (block.isGiven()) {
// Struct bodies should be public by default, so set block visibility to public. JRUBY-1185.
block.getBinding().setVisibility(Visibility.PUBLIC);
block.yieldNonArray(runtime.getCurrentContext(), null, newStruct, newStruct);
block.yieldNonArray(runtime.getCurrentContext(), null, newStruct);
}

return newStruct;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubySymbol.java
Expand Up @@ -391,7 +391,7 @@ private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blo

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type, Block block) {
Binding binding, Type type, Block block) {
RubyProc.prepareArgs(context, type, block.arity(), args);
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), block);
}
Expand All @@ -408,7 +408,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type) {
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type) {
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), Block.NULL_BLOCK);
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/embed/variable/Argv.java
Expand Up @@ -128,7 +128,8 @@ public static boolean isValidName(Object name) {
public void inject() {
updateArgvByJavaObject();
RubyModule rubyModule = getRubyClass(receiver.getRuntime());
if (rubyModule == null) rubyModule = receiver.getRuntime().getCurrentContext().getRubyClass();
// SSS FIXME: With rubyclass stack gone, this needs a replacement
if (rubyModule == null) rubyModule = null; // receiver.getRuntime().getCurrentContext().getRubyClass();
if (rubyModule == null) return;

rubyModule.storeConstant(name, irubyObject);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/embed/variable/Constant.java
Expand Up @@ -218,7 +218,8 @@ public static boolean isValidName(Object name) {
public void inject() {
if (receiver == receiver.getRuntime().getTopSelf()) {
RubyModule rubyModule = getRubyClass(receiver.getRuntime());
if (rubyModule == null) rubyModule = receiver.getRuntime().getCurrentContext().getRubyClass();
// SSS FIXME: With rubyclass stack gone, this needs a replacement
if (rubyModule == null) rubyModule = null; // receiver.getRuntime().getCurrentContext().getRubyClass();
if (rubyModule == null) return;

rubyModule.storeConstant(name, irubyObject);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ext/fiber/ThreadFiber.java
Expand Up @@ -17,7 +17,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.Visibility;

import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.runtime.IRReturnJump;
Expand Down Expand Up @@ -225,7 +224,7 @@ public void run() {
if (init == NEVER) {
result = block.yieldSpecific(context);
} else {
result = block.yieldArray(context, init, null, null);
result = block.yieldArray(context, init, null);
}

data.prev.data.queue.push(context, result);
Expand Down
Expand Up @@ -25,7 +25,6 @@ public List<String[]> getParameterList() {
protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
context.popRubyClass();
context.popScope();
}

Expand Down
Expand Up @@ -123,7 +123,6 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
context.popRubyClass();
if (this.pushScope) {
context.popScope();
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScriptBody.java
Expand Up @@ -116,7 +116,6 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self) {
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} finally {
context.popRubyClass();
context.popScope();
}

Expand Down
Expand Up @@ -393,7 +393,6 @@ private static void processBookKeepingOp(ThreadContext context, Instr instr, Ope
break;
case POP_FRAME:
context.popFrame();
context.popRubyClass();
break;
case POP_BINDING:
context.popScope();
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Expand Up @@ -202,7 +202,7 @@ public static IRubyObject defCompiledIRMethod(ThreadContext context, MethodHandl
Ruby runtime = context.runtime;

// SSS FIXME: this has to be looked up at runtime now
RubyModule containingClass = context.getRubyClass();
RubyModule containingClass = null; // context.getRubyClass();
Visibility currVisibility = context.getCurrentVisibility();
Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, containingClass, rubyName, currVisibility);

Expand Down Expand Up @@ -386,7 +386,7 @@ public static IRubyObject yield(ThreadContext context, Object blk, Object yieldA
if (blk instanceof RubyNil) blk = Block.NULL_BLOCK;
Block b = (Block)blk;
IRubyObject yieldVal = (IRubyObject)yieldArg;
return (unwrapArray && (yieldVal instanceof RubyArray)) ? b.yieldArray(context, yieldVal, null, null) : b.yield(context, yieldVal);
return (unwrapArray && (yieldVal instanceof RubyArray)) ? b.yieldArray(context, yieldVal, null) : b.yield(context, yieldVal);
}

public static IRubyObject yieldSpecific(ThreadContext context, Object blk) {
Expand Down
20 changes: 4 additions & 16 deletions core/src/main/java/org/jruby/runtime/Binding.java
Expand Up @@ -49,7 +49,6 @@ public class Binding {
*/
private final Frame frame;
private final BacktraceElement backtrace;
private final RubyModule klass;

private Visibility visibility;
/**
Expand Down Expand Up @@ -80,37 +79,34 @@ public class Binding {
private Binding evalScopeBinding = this;

public Binding(IRubyObject self, Frame frame,
Visibility visibility, RubyModule klass, DynamicScope dynamicScope, BacktraceElement backtrace) {
Visibility visibility, DynamicScope dynamicScope, BacktraceElement backtrace) {
this.self = self;
this.frame = frame;
this.visibility = visibility;
this.klass = klass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
}

private Binding(IRubyObject self, Frame frame,
Visibility visibility, RubyModule klass, DynamicScope dynamicScope, BacktraceElement backtrace, DynamicScope dummyScope) {
Visibility visibility, DynamicScope dynamicScope, BacktraceElement backtrace, DynamicScope dummyScope) {
this.self = self;
this.frame = frame;
this.visibility = visibility;
this.klass = klass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
this.dummyScope = dummyScope;
}

public Binding(Frame frame, RubyModule bindingClass, DynamicScope dynamicScope, BacktraceElement backtrace) {
public Binding(Frame frame, DynamicScope dynamicScope, BacktraceElement backtrace) {
this.self = frame.getSelf();
this.frame = frame;
this.visibility = frame.getVisibility();
this.klass = bindingClass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
}

private Binding(Binding other) {
this(other.self, other.frame, other.visibility, other.klass, other.dynamicScope, other.backtrace, other.dummyScope);
this(other.self, other.frame, other.visibility, other.dynamicScope, other.backtrace, other.dummyScope);
}

/**
Expand Down Expand Up @@ -179,14 +175,6 @@ public Frame getFrame() {
return frame;
}

/**
* Gets the klass.
* @return Returns a RubyModule
*/
public RubyModule getKlass() {
return klass;
}

public BacktraceElement getBacktrace() {
return backtrace;
}
Expand Down
13 changes: 5 additions & 8 deletions core/src/main/java/org/jruby/runtime/Block.java
Expand Up @@ -43,7 +43,6 @@

import org.jruby.EvalType;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.runtime.builtin.IRubyObject;

Expand Down Expand Up @@ -148,20 +147,18 @@ public IRubyObject yield(ThreadContext context, IRubyObject value) {
return body.yield(context, value, binding, type);
}

public IRubyObject yieldNonArray(ThreadContext context, IRubyObject value, IRubyObject self,
RubyModule klass) {
return body.yield(context, new IRubyObject[] { value }, self, klass, binding, type);
public IRubyObject yieldNonArray(ThreadContext context, IRubyObject value, IRubyObject self) {
return body.yield(context, new IRubyObject[] { value }, self, binding, type);
}

public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObject self,
RubyModule klass) {
public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObject self) {
IRubyObject[] args;
if (!(value instanceof RubyArray)) {
args = new IRubyObject[] { value };
} else {
args = value.convertToArray().toJavaArray();
}
return body.yield(context, args, self, klass, binding, type);
return body.yield(context, args, self, binding, type);
}

public Block cloneBlock() {
Expand All @@ -176,7 +173,7 @@ public Block cloneBlock() {
public Block cloneBlockAndFrame() {
Binding oldBinding = binding;
Binding binding = new Binding(
oldBinding.getSelf(), oldBinding.getFrame().duplicate(), oldBinding.getVisibility(), oldBinding.getKlass(), oldBinding.getDynamicScope(), oldBinding.getBacktrace());
oldBinding.getSelf(), oldBinding.getFrame().duplicate(), oldBinding.getVisibility(), oldBinding.getDynamicScope(), oldBinding.getBacktrace());

Block newBlock = new Block(body, binding);

Expand Down

0 comments on commit 525a110

Please sign in to comment.