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: a14c8b80bb25
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc1b48facc13
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Aug 12, 2015

  1. Copy the full SHA
    35aa6dd View commit details
  2. Copy the full SHA
    cc1b48f View commit details
4 changes: 4 additions & 0 deletions spec/ruby/core/module/const_get_spec.rb
Original file line number Diff line number Diff line change
@@ -107,6 +107,10 @@
lambda { ConstantSpecs.const_get(:'ClassA::CS_CONST10') }.should raise_error(NameError)
end

it "does read private constants" do
ConstantSpecs.const_get(:CS_PRIVATE).should == :cs_private
end

describe "with statically assigned constants" do
it "searches the immediate class or module first" do
ConstantSpecs::ClassA.const_get(:CS_CONST10).should == :const10_10
3 changes: 3 additions & 0 deletions spec/ruby/fixtures/constants.rb
Original file line number Diff line number Diff line change
@@ -280,6 +280,9 @@ class ClassE

class ClassD < ClassC
end

CS_PRIVATE = :cs_private
private_constant :CS_PRIVATE
end

include ConstantSpecs::ModuleA
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ModuleNodes;
import org.jruby.truffle.nodes.literal.BooleanLiteralNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyConstant;
@@ -33,11 +34,17 @@
* Caches {@link ModuleOperations#lookupConstant}
* and checks visibility.
*/
@NodeChildren({ @NodeChild("module"), @NodeChild("name") })
@NodeChildren({
@NodeChild(value = "module", type = RubyNode.class),
@NodeChild(value = "name", type = RubyNode.class)
})
public abstract class LookupConstantNode extends RubyNode {

public LookupConstantNode(RubyContext context, SourceSection sourceSection) {
private final boolean ignoreVisibility;

public LookupConstantNode(RubyContext context, SourceSection sourceSection, boolean ignoreVisibility) {
super(context, sourceSection);
this.ignoreVisibility = ignoreVisibility;
}

public abstract RubyConstant executeLookupConstant(VirtualFrame frame, Object module, String name);
@@ -48,12 +55,12 @@ public LookupConstantNode(RubyContext context, SourceSection sourceSection) {
"guardName(name, cachedName, sameNameProfile)"
}, assumptions = "getUnmodifiedAssumption(cachedModule)", limit = "getCacheLimit()")
protected RubyConstant lookupConstant(VirtualFrame frame, RubyBasicObject module, String name,
@Cached("module") RubyBasicObject cachedModule,
@Cached("name") String cachedName,
@Cached("doLookup(cachedModule, cachedName)") RubyConstant constant,
@Cached("isVisible(cachedModule, constant)") boolean isVisible,
@Cached("createBinaryProfile()") ConditionProfile sameNameProfile) {
if (!isVisible) {
@Cached("module") RubyBasicObject cachedModule,
@Cached("name") String cachedName,
@Cached("doLookup(cachedModule, cachedName)") RubyConstant constant,
@Cached("isVisible(cachedModule, constant)") boolean isVisible,
@Cached("createBinaryProfile()") ConditionProfile sameNameProfile) {
if (!isVisible && !ignoreVisibility) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorPrivateConstant(module, name, this));
}
@@ -70,7 +77,7 @@ protected RubyConstant lookupConstantUncached(RubyBasicObject module, String nam
RubyConstant constant = doLookup(module, name);
boolean isVisible = isVisible(module, constant);

if (!isVisible) {
if (!isVisible && !ignoreVisibility) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorPrivateConstant(module, name, this));
}
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ public class ReadConstantNode extends RubyNode implements RestartableReadConstan
@Child LookupConstantNode lookupConstantNode;
@Child GetConstantNode getConstantNode;

public ReadConstantNode(RubyContext context, SourceSection sourceSection, RubyNode moduleNode, RubyNode nameNode) {
public ReadConstantNode(RubyContext context, SourceSection sourceSection, boolean ignoreVisibility, RubyNode moduleNode, RubyNode nameNode) {
super(context, sourceSection);
this.moduleNode = moduleNode;
this.nameNode = nameNode;
this.lookupConstantNode = LookupConstantNodeGen.create(context, sourceSection, null, null);
this.lookupConstantNode = LookupConstantNodeGen.create(context, sourceSection, ignoreVisibility, null, null);
this.getConstantNode = GetConstantNodeGen.create(context, sourceSection, this, null, null, null);
}

Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

@@ -27,7 +26,7 @@ public class ReadLiteralConstantNode extends RubyNode {
public ReadLiteralConstantNode(RubyContext context, SourceSection sourceSection, RubyNode moduleNode, String name) {
super(context, sourceSection);
RubyNode nameNode = new LiteralNode(context, sourceSection, name);
this.readConstantNode = new ReadConstantNode(context, sourceSection, moduleNode, nameNode);
this.readConstantNode = new ReadConstantNode(context, sourceSection, false, moduleNode, nameNode);
}

@Override
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@
import org.jruby.truffle.nodes.core.ModuleNodesFactory.GenerateAccessorNodeGen;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetMethodVisibilityNodeGen;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetVisibilityNodeGen;
import org.jruby.truffle.nodes.core.UnboundMethodNodes.BindNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
@@ -93,7 +92,7 @@ public static RubyModule createRubyModule(RubyContext context, RubyBasicObject s
public abstract static class ContainsInstanceNode extends CoreMethodArrayArgumentsNode {

@Child private MetaClassNode metaClassNode;

public ContainsInstanceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
metaClassNode = MetaClassNodeGen.create(context, sourceSection, null);
@@ -108,7 +107,7 @@ public boolean containsInstance(RubyBasicObject module, RubyBasicObject instance
public boolean containsInstance(VirtualFrame frame, RubyBasicObject module, Object instance) {
return includes(metaClassNode.executeMetaClass(frame, instance), module);
}

@TruffleBoundary
public boolean includes(RubyBasicObject metaClass, RubyBasicObject module) {
assert RubyGuards.isRubyModule(metaClass);
@@ -894,7 +893,7 @@ public abstract static class ConstGetNode extends CoreMethodNode {

public ConstGetNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
this.readConstantNode = new ReadConstantNode(context, sourceSection, null, null);
this.readConstantNode = new ReadConstantNode(context, sourceSection, true, null, null);
}

@CreateCast("name")
@@ -1770,7 +1769,7 @@ public RemoveClassVariableNode(RubyContext context, SourceSection sourceSection)
public RubyNode coerceToString(RubyNode name) {
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@TruffleBoundary
@Specialization
public Object removeClassVariableString(RubyBasicObject module, String name) {
Original file line number Diff line number Diff line change
@@ -1699,7 +1699,7 @@ public abstract static class GetIntegerConstantNode extends RubyNode {

public GetIntegerConstantNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readConstantNode = new ReadConstantNode(context, sourceSection, null, null);
readConstantNode = new ReadConstantNode(context, sourceSection, false, null, null);
toIntNode = ToIntNodeGen.create(context, sourceSection, null);
integerCastNode = IntegerCastNodeGen.create(context, sourceSection, null);
}