Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cd4a1e60bada
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3eb736a450db
Choose a head ref
  • 4 commits
  • 10 files changed
  • 1 contributor

Commits on May 19, 2016

  1. Copy the full SHA
    b3fb6e4 View commit details
  2. Copy the full SHA
    7103f60 View commit details
  3. Copy the full SHA
    70bdd74 View commit details
  4. privateConsts is not used

    enebo committed May 19, 2016
    Copy the full SHA
    3eb736a View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4846,7 +4846,7 @@ public void setFFI(FFI ffi) {
}

public RubyString getDefinedMessage(DefinedMessage definedMessage) {
return definedMessages.get(definedMessage);
return freezeAndDedupString(definedMessages.get(definedMessage));
}

public RubyString getThreadStatus(RubyThread.Status status) {
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -3663,6 +3663,10 @@ public IRubyObject getConstantNoConstMissing(String name, boolean inherit) {
return getConstantNoConstMissing(name, inherit, true);
}

public IRubyObject getConstantNoConstMissingSKipAutoload(String name) {
return getConstantSkipAutoload(name, true, true);
}

public IRubyObject getConstantNoConstMissing(String name, boolean inherit, boolean includeObject) {
IRubyObject constant = iterateConstantNoConstMissing(name, this, inherit, true);

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1403,7 +1403,7 @@ private Operand protectCodeWithRescue(CodeBlock protectedCode, CodeBlock rescueB
// Receive 'exc' and verify that 'exc' is of ruby-type 'Exception'
addInstr(new LabelInstr(rescueLabel));
addInstr(new ReceiveRubyExceptionInstr(exc));
addInstr(new InheritanceSearchConstInstr(excType, new ObjectClass(), "Exception", false));
addInstr(new InheritanceSearchConstInstr(excType, new ObjectClass(), "Exception"));
outputExceptionCheck(excType, exc, caughtLabel);

// Fall-through when the exc !== Exception; rethrow 'exc'
@@ -1525,7 +1525,7 @@ public Operand run() {
String constName = ((ConstNode) node).getName();
addInstr(new LexicalSearchConstInstr(tmpVar, startingSearchScope(), constName));
addInstr(BNEInstr.create(defLabel, tmpVar, UndefinedValue.UNDEFINED));
addInstr(new InheritanceSearchConstInstr(tmpVar, findContainerModule(), constName, false)); // SSS FIXME: should this be the current-module var or something else?
addInstr(new InheritanceSearchConstInstr(tmpVar, findContainerModule(), constName)); // SSS FIXME: should this be the current-module var or something else?
addInstr(BNEInstr.create(defLabel, tmpVar, UndefinedValue.UNDEFINED));
addInstr(new CopyInstr(tmpVar, manager.getNil()));
addInstr(new JumpInstr(doneLabel));
@@ -2471,7 +2471,7 @@ public Operand buildFlip(FlipNode flipNode) {
// for JIT/AOT. Also it means needing to grow the size of any heap scope for variables.
if (nearestNonClosureBuilder == null) {
Variable excType = createTemporaryVariable();
addInstr(new InheritanceSearchConstInstr(excType, new ObjectClass(), "NotImplementedError", false));
addInstr(new InheritanceSearchConstInstr(excType, new ObjectClass(), "NotImplementedError"));
Variable exc = addResultInstr(CallInstr.create(scope, createTemporaryVariable(), "new", excType, new Operand[] {new FrozenString("Flip support currently broken")}, null));
addInstr(new ThrowExceptionInstr(exc));
return buildNil();
Original file line number Diff line number Diff line change
@@ -22,18 +22,21 @@

public class InheritanceSearchConstInstr extends OneOperandResultBaseInstr implements FixedArityInstr {
String constName;
private final boolean noPrivateConsts;

// Constant caching
private volatile transient ConstantCache cache;

public InheritanceSearchConstInstr(Variable result, Operand currentModule, String constName, boolean noPrivateConsts) {
public InheritanceSearchConstInstr(Variable result, Operand currentModule, String constName) {
super(Operation.INHERITANCE_SEARCH_CONST, result, currentModule);

assert result != null: "InheritanceSearchConstInstr result is null";

this.constName = constName;
this.noPrivateConsts = noPrivateConsts;
}

@Deprecated
public InheritanceSearchConstInstr(Variable result, Operand currentModule, String constName, boolean unused) {
this(result, currentModule, constName);
}

public Operand getCurrentModule() {
@@ -44,23 +47,23 @@ public String getConstName() {
return constName;
}

@Deprecated
public boolean isNoPrivateConsts() {
return noPrivateConsts;
return false;
}

@Override
public Instr clone(CloneInfo ii) {
return new InheritanceSearchConstInstr(ii.getRenamedVariable(result),
getCurrentModule().cloneForInlining(ii), constName, noPrivateConsts);
return new InheritanceSearchConstInstr(ii.getRenamedVariable(result), getCurrentModule().cloneForInlining(ii), constName);
}

@Override
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + constName, "no_priv: " + noPrivateConsts};
return new String[] { "name: " + constName };
}

private Object cache(Ruby runtime, RubyModule module) {
Object constant = noPrivateConsts ? module.getConstantFromNoConstMissing(constName, false) : module.getConstantNoConstMissing(constName);
Object constant = module.getConstantNoConstMissingSKipAutoload(constName);
if (constant == null) {
constant = UndefinedValue.UNDEFINED;
} else {
@@ -76,11 +79,10 @@ public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getCurrentModule());
e.encode(getConstName());
e.encode(isNoPrivateConsts());
}

public static InheritanceSearchConstInstr decode(IRReaderDecoder d) {
return new InheritanceSearchConstInstr(d.decodeVariable(), d.decodeOperand(), d.decodeString(), d.decodeBoolean());
return new InheritanceSearchConstInstr(d.decodeVariable(), d.decodeOperand(), d.decodeString());
}

@Override
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ public static LexicalSearchConstInstr decode(IRReaderDecoder d) {
private Object cache(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
StaticScope staticScope = (StaticScope) getDefiningScope().retrieve(context, self, currScope, currDynScope, temp);

IRubyObject constant = staticScope.getConstantInner(constName);
IRubyObject constant = staticScope.getConstantDefined(constName);

if (constant == null) {
constant = UndefinedValue.UNDEFINED;
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public IRubyObject inheritanceSearchConst(ThreadContext context, IRubyObject cmV
throw runtime.newTypeError(cmVal + " is not a type/class");
}

IRubyObject constant = publicOnly ? module.getConstantFromNoConstMissing(name, false) : module.getConstantNoConstMissing(name);
IRubyObject constant = module.getConstantNoConstMissingSKipAutoload(name);

if (constant == null) {
constant = UndefinedValue.UNDEFINED;
@@ -190,7 +190,7 @@ public IRubyObject inheritanceSearchConst(ThreadContext context, IRubyObject cmV
public IRubyObject lexicalSearchConst(ThreadContext context, StaticScope scope) {
Ruby runtime = context.runtime;

IRubyObject constant = scope.getConstantInner(name);
IRubyObject constant = scope.getConstantDefined(name);

if (constant == null) {
constant = UndefinedValue.UNDEFINED;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -1220,7 +1220,7 @@ public void InheritanceSearchConstInstr(InheritanceSearchConstInstr inheritances
jvmMethod().loadContext();
visit(inheritancesearchconstinstr.getCurrentModule());

jvmMethod().inheritanceSearchConst(inheritancesearchconstinstr.getConstName(), inheritancesearchconstinstr.isNoPrivateConsts());
jvmMethod().inheritanceSearchConst(inheritancesearchconstinstr.getConstName(), false);
jvmStoreLocal(inheritancesearchconstinstr.getResult());
}

19 changes: 19 additions & 0 deletions core/src/main/java/org/jruby/parser/StaticScope.java
Original file line number Diff line number Diff line change
@@ -258,6 +258,25 @@ public void setVariables(String[] names) {
System.arraycopy(names, 0, variableNames, 0, names.length);
}

/**
* Gets a constant back from lexical search from the cref in this scope.
* As it is for defined? we will not forced resolution of autoloads nor
* call const_defined
*/
public IRubyObject getConstantDefined(String internedName) {
IRubyObject result = cref.fetchConstant(internedName);

if (result != null) return result;

return previousCRefScope == null ? null : previousCRefScope.getConstantDefinedNoObject(internedName);
}

public IRubyObject getConstantDefinedNoObject(String internedName) {
if (previousCRefScope == null) return null;

return getConstantDefined(internedName);
}

public IRubyObject getConstant(String internedName) {
IRubyObject result = getConstantInner(internedName);

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -2140,7 +2140,7 @@ public static boolean isModuleAndHasConstant(IRubyObject left, String name) {

public static RubyString getDefinedConstantOrBoundMethod(IRubyObject left, String name) {
if (isModuleAndHasConstant(left, name)) return left.getRuntime().getDefinedMessage(DefinedMessage.CONSTANT);
if (left.getMetaClass().isMethodBound(name, true)) left.getRuntime().getDefinedMessage(DefinedMessage.METHOD);
if (left.getMetaClass().isMethodBound(name, true)) return left.getRuntime().getDefinedMessage(DefinedMessage.METHOD);
return null;
}

2 changes: 0 additions & 2 deletions test/mri/excludes/TestDefined.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
exclude :test_autoloaded_noload, "needs investigation"
exclude :test_autoloaded_subclass, "needs investigation"
exclude :test_defined, "needs investigation"