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

Commits on Feb 18, 2015

  1. [Truffle] Propagate naming of anonymous modules.

    * Lexical children modules get named when their parent gets named.
    * MRI seems to do it slightly differently but this approach is
      rather clean and seems to respect the full behavior.
    eregon committed Feb 18, 2015
    Copy the full SHA
    b41331c View commit details
  2. Copy the full SHA
    09a7e9b View commit details
  3. [Truffle] Pass all specs for Module#const_set.

    * IdUtil.isValidConstantName19 is the right way to validate.
    eregon committed Feb 18, 2015
    Copy the full SHA
    8edc32d View commit details
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/util/IdUtil.java
Original file line number Diff line number Diff line change
@@ -33,22 +33,22 @@ public final class IdUtil {
/**
* rb_is_const_id and is_const_id
*/
public static boolean isConstant(String id) {
return Character.isUpperCase(id.charAt(0));
public static boolean isConstant(String id) {
return Character.isUpperCase(id.charAt(0));
}

/**
* rb_is_class_id and is_class_id
*/
public static boolean isClassVariable(String id) {
return id.length()>1 && id.charAt(0) == '@' && id.charAt(1) == '@';
public static boolean isClassVariable(String id) {
return id.length() > 1 && id.charAt(0) == '@' && id.charAt(1) == '@';
}

/**
* rb_is_instance_id and is_instance_id
*/
public static boolean isInstanceVariable(String id) {
return id.length()>0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
public static boolean isInstanceVariable(String id) {
return id.length() > 0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
}

/**
@@ -65,8 +65,8 @@ public static boolean isPredicate(String id) {
/**
* rb_is_local_id and is_local_id
*/
public static boolean isLocal(String id) {
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
public static boolean isLocal(String id) {
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
}

/**
@@ -77,9 +77,9 @@ public static boolean isSpecial(String id) {
return id.startsWith("%");
}

public static boolean isAttrSet(String id) {
return id.endsWith("=");
}
public static boolean isAttrSet(String id) {
return id.endsWith("=");
}

public static boolean isValidConstantName(String id) {
char c;
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/module/const_set_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/module/name_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
fails:Module#name is nil when assigned to a constant in an anonymous module
fails:Module#name is set with a conditional assignment to a nested constant
fails:Module#name preserves the encoding in which the class was defined
fails:Module#name is set when the anonymous outer module name is set
2 changes: 0 additions & 2 deletions spec/truffle/tags/language/module_tags.txt

This file was deleted.

32 changes: 20 additions & 12 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ public RubyNilClass autoload(RubyModule module, RubyString name, RubyString file
}

private RubyNilClass autoload(RubyModule module, String name, RubyString filename) {
if (invalidConstantName.profile(!IdUtil.isConstant(name))) {
if (invalidConstantName.profile(!IdUtil.isValidConstantName19(name))) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("autoload must be constant name: %s", name), this));
}
@@ -782,6 +782,8 @@ public Object methodMissing(RubyModule module, RubySymbol name) {
@CoreMethod(names = "const_set", required = 2)
public abstract static class ConstSetNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public ConstSetNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -791,25 +793,31 @@ public ConstSetNode(ConstSetNode prev) {
}

@Specialization
public RubyModule setConstant(RubyModule module, RubyString name, Object object) {
public Object setConstant(RubyModule module, RubySymbol name, Object value) {
notDesignedForCompilation();
setConstant(module, name.toString(), object);
return module;

return setConstant(module, name.toString(), value);
}

@Specialization
public RubyModule setConstant(RubyModule module, RubySymbol name, Object object) {
notDesignedForCompilation();
setConstant(module, name.toString(), object);
return module;
@Specialization(guards = "!isRubySymbol(arguments[1])")
public Object setConstant(VirtualFrame frame, RubyModule module, Object name, Object value) {
if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

return setConstant(module, toStrNode.executeRubyString(frame, name).toString(), value);
}

public void setConstant(RubyModule module, String name, Object object) {
if (!IdUtil.isConstant(name)) {
public Object setConstant(RubyModule module, String name, Object value) {
notDesignedForCompilation();

if (!IdUtil.isValidConstantName19(name)) {
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("wrong constant name %s", name), this));
}

module.setConstant(this, name, object);
module.setConstant(this, name, value);
return value;
}

}
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.truffle.runtime.subsystems.ObjectSpaceManager;

import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

/**
@@ -134,8 +135,26 @@ public void getAdoptedByLexicalParent(RubyModule lexicalParent, String name, Rub

if (lexicalParent == objectClass) {
this.name = name;
updateAnonymousChildrenModules();
} else if (lexicalParent.hasName()) {
this.name = lexicalParent.getName() + "::" + name;
updateAnonymousChildrenModules();
}
// else: Our lexicalParent is also an anonymous module
// and will name us when it gets named via updateAnonymousChildrenModules()
}
}

private void updateAnonymousChildrenModules() {
RubyNode.notDesignedForCompilation();

for (Entry<String, RubyConstant> entry : constants.entrySet()) {
RubyConstant constant = entry.getValue();
if (constant.getValue() instanceof RubyModule) {
RubyModule module = (RubyModule) constant.getValue();
if (!module.hasName()) {
module.getAdoptedByLexicalParent(this, entry.getKey(), null);
}
}
}
}