Skip to content

Commit

Permalink
Revert "[Truffle] Fixed class variable lookup from singleton classes …
Browse files Browse the repository at this point in the history
…by attaching their companion class to them."

This reverts commit 0e29b6b.

The approach needs overall refinement.
  • Loading branch information
nirvdrum committed Mar 7, 2015
1 parent 41ce8ce commit a7e148f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
Expand Up @@ -243,14 +243,6 @@ public static Object lookupClassVariable(RubyModule module, String name) {
}
}

if (module instanceof RubyClass) {
RubyClass klass = (RubyClass) module;

if (klass.isSingleton()) {
return lookupClassVariable(((RubyClass) module).getAttached(), name);
}
}

// Nothing found

return null;
Expand Down
Expand Up @@ -104,13 +104,8 @@ public RubyClass getSingletonClass(Node currentNode) {

final RubyClass logicalClass = metaClass;

if (this instanceof RubyModule) {
metaClass = RubyClass.createSingletonClassOfObject(getContext(), logicalClass, (RubyModule) this,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()));
} else {
metaClass = RubyClass.createSingletonClassOfObject(getContext(), logicalClass, logicalClass,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()));
}
metaClass = RubyClass.createSingletonClassOfObject(getContext(), logicalClass,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()));

if (DebugOperations.verySlowIsFrozen(this)) {
DebugOperations.verySlowFreeze(metaClass);
Expand Down
Expand Up @@ -33,7 +33,6 @@ public class RubyClass extends RubyModule {

private final boolean isSingleton;
private final Set<RubyClass> subClasses = Collections.newSetFromMap(new WeakHashMap<RubyClass, Boolean>());
@CompilationFinal private RubyModule attached;

/**
* This constructor supports initialization and solves boot-order problems and should not
Expand All @@ -49,10 +48,10 @@ public RubyClass(RubyContext context, RubyModule lexicalParent, RubyClass superc
ensureSingletonConsistency();
}

protected static RubyClass createSingletonClassOfObject(RubyContext context, RubyClass superclass, RubyModule attached, String name) {
protected static RubyClass createSingletonClassOfObject(RubyContext context, RubyClass superclass, String name) {
// We also need to create the singleton class of a singleton class for proper lookup and consistency.
// See rb_singleton_class() documentation in MRI.
return new RubyClass(context, superclass.getLogicalClass(), null, superclass, name, true, attached).ensureSingletonConsistency();
return new RubyClass(context, superclass.getLogicalClass(), null, superclass, name, true).ensureSingletonConsistency();
}

protected RubyClass(RubyContext context, RubyClass classClass, RubyModule lexicalParent, RubyClass superclass, String name, boolean isSingleton) {
Expand All @@ -65,14 +64,6 @@ protected RubyClass(RubyContext context, RubyClass classClass, RubyModule lexica
}
}

protected RubyClass(RubyContext context, RubyClass classClass, RubyModule lexicalParent, RubyClass superclass, String name, boolean isSingleton, RubyModule attached) {
this(context, classClass, lexicalParent, superclass, name, isSingleton);

assert isSingleton == true;

this.attached = attached;
}

public void initialize(RubyClass superclass) {
unsafeSetSuperclass(superclass);
ensureSingletonConsistency();
Expand Down Expand Up @@ -133,7 +124,7 @@ private RubyClass createOneSingletonClass() {
}

metaClass = new RubyClass(getContext(),
getLogicalClass(), null, singletonSuperclass, String.format("#<Class:%s>", getName()), true, this);
getLogicalClass(), null, singletonSuperclass, String.format("#<Class:%s>", getName()), true);

return metaClass;
}
Expand All @@ -146,10 +137,6 @@ public boolean isSingleton() {
return isSingleton;
}

public RubyModule getAttached() {
return attached;
}

public RubyClass getSuperClass() {
CompilerAsserts.neverPartOfCompilation();

Expand Down

0 comments on commit a7e148f

Please sign in to comment.