Skip to content

Commit

Permalink
Revert "[Truffle] Make SharedMethodInfo properly immutable by moving …
Browse files Browse the repository at this point in the history
…the name parts to another object."

This reverts commit ee95689.
  • Loading branch information
chrisseaton committed Dec 13, 2016
1 parent 37e90a2 commit 7e88131
Show file tree
Hide file tree
Showing 38 changed files with 322 additions and 398 deletions.
Expand Up @@ -41,7 +41,6 @@
import org.jruby.truffle.language.methods.Arity;
import org.jruby.truffle.language.methods.ExceptionTranslatingNode;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.NamedSharedMethodInfo;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.options.Options;
Expand Down Expand Up @@ -140,55 +139,54 @@ private void addCoreMethod(DynamicObject module, MethodDetails methodDetails) {
System.err.println("WARNING: Either onSingleton or constructor for " + methodDetails.getIndicativeName());
}

final NamedSharedMethodInfo namedSharedMethodInfo = makeSharedMethodInfo(context, module, methodDetails);
final CallTarget callTarget = makeGenericMethod(context, methodDetails, namedSharedMethodInfo);
final SharedMethodInfo sharedMethodInfo = makeSharedMethodInfo(context, module, methodDetails);
final CallTarget callTarget = makeGenericMethod(context, methodDetails, sharedMethodInfo);

if (method.isModuleFunction()) {
addMethod(context, module, namedSharedMethodInfo, callTarget, names, Visibility.PRIVATE);
addMethod(context, getSingletonClass(module), namedSharedMethodInfo, callTarget, names, Visibility.PUBLIC);
addMethod(context, module, sharedMethodInfo, callTarget, names, Visibility.PRIVATE);
addMethod(context, getSingletonClass(module), sharedMethodInfo, callTarget, names, Visibility.PUBLIC);
} else if (method.onSingleton() || method.constructor()) {
addMethod(context, getSingletonClass(module), namedSharedMethodInfo, callTarget, names, visibility);
addMethod(context, getSingletonClass(module), sharedMethodInfo, callTarget, names, visibility);
} else {
addMethod(context, module, namedSharedMethodInfo, callTarget, names, visibility);
addMethod(context, module, sharedMethodInfo, callTarget, names, visibility);
}
}

private static void addMethod(RubyContext context, DynamicObject module, NamedSharedMethodInfo namedSharedMethodInfo, CallTarget callTarget, String[] names, Visibility originalVisibility) {
private static void addMethod(RubyContext context, DynamicObject module, SharedMethodInfo sharedMethodInfo, CallTarget callTarget, String[] names, Visibility originalVisibility) {
assert RubyGuards.isRubyModule(module);

for (String name : names) {
Visibility visibility = originalVisibility;
if (ModuleOperations.isMethodPrivateFromName(name)) {
visibility = Visibility.PRIVATE;
}
final InternalMethod method = new InternalMethod(context, namedSharedMethodInfo, namedSharedMethodInfo.getLexicalScope(), name, module, visibility, callTarget);
final InternalMethod method = new InternalMethod(context, sharedMethodInfo, sharedMethodInfo.getLexicalScope(), name, module, visibility, callTarget);

Layouts.MODULE.getFields(module).addMethod(context, null, method);
}
}

private static NamedSharedMethodInfo makeSharedMethodInfo(RubyContext context, DynamicObject module, MethodDetails methodDetails) {
private static SharedMethodInfo makeSharedMethodInfo(RubyContext context, DynamicObject module, MethodDetails methodDetails) {
final CoreMethod method = methodDetails.getMethodAnnotation();
final LexicalScope lexicalScope = new LexicalScope(context.getRootLexicalScope(), module);

return new NamedSharedMethodInfo(
new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),
lexicalScope,
new Arity(method.required(), method.optional(), method.rest()),
module,
null,
context.getOptions().CORE_ALWAYS_CLONE,
method.needsCallerFrame() && context.getOptions().INLINE_NEEDS_CALLER_FRAME,
method.needsCallerFrame()),
return new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),
lexicalScope,
new Arity(method.required(), method.optional(), method.rest()),
module,
methodDetails.getPrimaryName(),
"builtin");
"builtin",
null,
context.getOptions().CORE_ALWAYS_CLONE,
method.needsCallerFrame() && context.getOptions().INLINE_NEEDS_CALLER_FRAME,
method.needsCallerFrame());
}

private static CallTarget makeGenericMethod(RubyContext context, MethodDetails methodDetails, NamedSharedMethodInfo namedSharedMethodInfo) {
private static CallTarget makeGenericMethod(RubyContext context, MethodDetails methodDetails, SharedMethodInfo sharedMethodInfo) {
final CoreMethod method = methodDetails.getMethodAnnotation();

final SourceSection sourceSection = namedSharedMethodInfo.getSourceSection();
final SourceSection sourceSection = sharedMethodInfo.getSourceSection();
final RubySourceSection rubySourceSection = new RubySourceSection(sourceSection);

final RubyNode methodNode = createCoreMethodNode(context, sourceSection, methodDetails.getNodeFactory(), method);
Expand All @@ -197,7 +195,7 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
AmbiguousOptionalArgumentChecker.verifyNoAmbiguousOptionalArguments(methodDetails);
}

final RubyNode checkArity = Translator.createCheckArityNode(context, sourceSection.getSource(), rubySourceSection, namedSharedMethodInfo.getArity());
final RubyNode checkArity = Translator.createCheckArityNode(context, sourceSection.getSource(), rubySourceSection, sharedMethodInfo.getArity());

RubyNode node;
if (!isSafe(context, method.unsafe())) {
Expand All @@ -213,7 +211,7 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
bodyNode = ChaosNodeGen.create(bodyNode);
}

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, namedSharedMethodInfo, bodyNode, false);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, bodyNode, false);

return Truffle.getRuntime().createCallTarget(rootNode);
}
Expand Down
6 changes: 3 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Expand Up @@ -119,7 +119,7 @@
import org.jruby.truffle.language.loader.SourceLoader;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.NamedSharedMethodInfo;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.objects.FreezeNode;
import org.jruby.truffle.language.objects.FreezeNodeGen;
import org.jruby.truffle.language.objects.SingletonClassNode;
Expand Down Expand Up @@ -1533,8 +1533,8 @@ public boolean isSend(InternalMethod method) {
return callTarget == basicObjectSendMethod.getCallTarget();
}

public boolean isTruffleBootMainMethod(NamedSharedMethodInfo info) {
return info == truffleBootMainMethod.getNamedSharedMethodInfo();
public boolean isTruffleBootMainMethod(SharedMethodInfo info) {
return info == truffleBootMainMethod.getSharedMethodInfo();
}

public boolean isCloningEnabled() {
Expand Down
Expand Up @@ -69,7 +69,7 @@ private static DynamicObject createFiber(RubyContext context, DynamicObject thre
}

public static void initialize(final RubyContext context, final DynamicObject fiber, final DynamicObject block, final Node currentNode) {
final SourceSection sourceSection = Layouts.PROC.getNamedSharedMethodInfo(block).getSourceSection();
final SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(block).getSourceSection();
final String name = "Ruby Fiber@" + RubyLanguage.fileLine(sourceSection);
final Thread thread = new Thread(() -> handleFiberExceptions(context, fiber, block, currentNode));
thread.setName(name);
Expand Down
Expand Up @@ -120,7 +120,7 @@
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.LookupMethodNode;
import org.jruby.truffle.language.methods.LookupMethodNodeGen;
import org.jruby.truffle.language.methods.NamedSharedMethodInfo;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.objects.FreezeNode;
import org.jruby.truffle.language.objects.FreezeNodeGen;
import org.jruby.truffle.language.objects.IsANode;
Expand Down Expand Up @@ -631,9 +631,9 @@ public Object evalNoBindingCached(

final InternalMethod method = new InternalMethod(
getContext(),
cachedRootNode.getRootNode().getNamedSharedMethodInfo(),
cachedRootNode.getRootNode().getSharedMethodInfo(),
RubyArguments.getMethod(parentFrame).getLexicalScope(),
cachedRootNode.getRootNode().getNamedSharedMethodInfo().getName(),
cachedRootNode.getRootNode().getSharedMethodInfo().getName(),
RubyArguments.getMethod(parentFrame).getDeclaringModule(),
Visibility.PUBLIC,
cachedCallTarget);
Expand Down Expand Up @@ -1207,7 +1207,7 @@ public DynamicObject lambdaFromBlock(DynamicObject block) {
return ProcOperations.createRubyProc(
coreLibrary().getProcFactory(),
ProcType.LAMBDA,
Layouts.PROC.getNamedSharedMethodInfo(block),
Layouts.PROC.getSharedMethodInfo(block),
Layouts.PROC.getCallTargetForLambdas(block),
Layouts.PROC.getCallTargetForLambdas(block),
Layouts.PROC.getDeclarationFrame(block),
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public abstract static class MethodNameNode extends CoreMethodArrayArgumentsNode
@Specialization
public DynamicObject methodName() {
// the "original/definition name" of the method.
return getSymbol(getContext().getCallStack().getCallingMethodIgnoringSend().getNamedSharedMethodInfo().getName());
return getSymbol(getContext().getCallStack().getCallingMethodIgnoringSend().getSharedMethodInfo().getName());
}

}
Expand Down Expand Up @@ -1309,7 +1309,7 @@ public DynamicObject method(VirtualFrame frame, Object self, DynamicObject name,

@TruffleBoundary
private InternalMethod createMissingMethod(Object self, DynamicObject name, String normalizedName, InternalMethod methodMissing) {
final NamedSharedMethodInfo info = methodMissing.getNamedSharedMethodInfo().withName(normalizedName);
final SharedMethodInfo info = methodMissing.getSharedMethodInfo().withName(normalizedName);

final RubyNode newBody = new CallMethodMissingWithStaticName(getContext(), info.getSourceSection(), name);
final RubyRootNode newRootNode = new RubyRootNode(getContext(), info.getSourceSection(), new FrameDescriptor(nil()), info, newBody, false);
Expand Down
Expand Up @@ -69,7 +69,7 @@ public abstract static class ArityNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int arity(DynamicObject method) {
return Layouts.METHOD.getMethod(method).getNamedSharedMethodInfo().getArity().getArityNumber();
return Layouts.METHOD.getMethod(method).getSharedMethodInfo().getArity().getArityNumber();
}

}
Expand Down Expand Up @@ -110,7 +110,7 @@ public long hash(DynamicObject rubyMethod) {
final InternalMethod method = Layouts.METHOD.getMethod(rubyMethod);
long h = Hashing.start(method.getDeclaringModule().hashCode());
h = Hashing.update(h, Layouts.METHOD.getReceiver(rubyMethod).hashCode());
h = Hashing.update(h, method.getNamedSharedMethodInfo().hashCode());
h = Hashing.update(h, method.getSharedMethodInfo().hashCode());
return Hashing.end(h);
}

Expand All @@ -132,7 +132,7 @@ public abstract static class ParametersNode extends CoreMethodArrayArgumentsNode
@TruffleBoundary
@Specialization
public DynamicObject parameters(DynamicObject method) {
final ArgumentDescriptor[] argsDesc = Layouts.METHOD.getMethod(method).getNamedSharedMethodInfo().getArgumentDescriptors();
final ArgumentDescriptor[] argsDesc = Layouts.METHOD.getMethod(method).getSharedMethodInfo().getArgumentDescriptors();

return ArgumentDescriptorUtils.argumentDescriptorsToParameters(getContext(), argsDesc, true);
}
Expand All @@ -155,7 +155,7 @@ public abstract static class SourceLocationNode extends CoreMethodArrayArguments
@TruffleBoundary
@Specialization
public Object sourceLocation(DynamicObject method) {
SourceSection sourceSection = Layouts.METHOD.getMethod(method).getNamedSharedMethodInfo().getSourceSection();
SourceSection sourceSection = Layouts.METHOD.getMethod(method).getSharedMethodInfo().getSourceSection();

if (sourceSection.getSource() == null) {
return nil();
Expand Down Expand Up @@ -204,7 +204,7 @@ public DynamicObject toProcUncached(DynamicObject methodObject) {
return ProcOperations.createRubyProc(
coreLibrary().getProcFactory(),
ProcType.LAMBDA,
method.getNamedSharedMethodInfo(),
method.getSharedMethodInfo(),
callTarget,
callTarget,
null,
Expand All @@ -220,11 +220,11 @@ protected CallTarget method2proc(DynamicObject methodObject) {
// We need to preserve the method receiver and we want to have the same argument list

final InternalMethod method = Layouts.METHOD.getMethod(methodObject);
final SourceSection sourceSection = method.getNamedSharedMethodInfo().getSourceSection();
final SourceSection sourceSection = method.getSharedMethodInfo().getSourceSection();
final RootNode oldRootNode = ((RootCallTarget) method.getCallTarget()).getRootNode();

final SetReceiverNode setReceiverNode = new SetReceiverNode(getContext(), sourceSection, Layouts.METHOD.getReceiver(methodObject), method.getCallTarget());
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getNamedSharedMethodInfo(), setReceiverNode, false);
final RootNode newRootNode = new RubyRootNode(getContext(), sourceSection, oldRootNode.getFrameDescriptor(), method.getSharedMethodInfo(), setReceiverNode, false);
return Truffle.getRuntime().createCallTarget(newRootNode);
}

Expand Down
Expand Up @@ -58,7 +58,7 @@ public abstract static class ArityNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int arity(DynamicObject method) {
return Layouts.UNBOUND_METHOD.getMethod(method).getNamedSharedMethodInfo().getArity().getArityNumber();
return Layouts.UNBOUND_METHOD.getMethod(method).getSharedMethodInfo().getArity().getArityNumber();
}

}
Expand Down Expand Up @@ -110,7 +110,7 @@ public long hash(DynamicObject rubyMethod) {
final InternalMethod method = Layouts.UNBOUND_METHOD.getMethod(rubyMethod);
long h = Hashing.start(method.getDeclaringModule().hashCode());
h = Hashing.update(h, Layouts.UNBOUND_METHOD.getOrigin(rubyMethod).hashCode());
h = Hashing.update(h, method.getNamedSharedMethodInfo().hashCode());
h = Hashing.update(h, method.getSharedMethodInfo().hashCode());
return Hashing.end(h);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public abstract static class ParametersNode extends CoreMethodArrayArgumentsNode
@TruffleBoundary
@Specialization
public DynamicObject parameters(DynamicObject method) {
final ArgumentDescriptor[] argsDesc = Layouts.UNBOUND_METHOD.getMethod(method).getNamedSharedMethodInfo().getArgumentDescriptors();
final ArgumentDescriptor[] argsDesc = Layouts.UNBOUND_METHOD.getMethod(method).getSharedMethodInfo().getArgumentDescriptors();

return ArgumentDescriptorUtils.argumentDescriptorsToParameters(getContext(), argsDesc, true);
}
Expand All @@ -166,7 +166,7 @@ public abstract static class SourceLocationNode extends CoreMethodArrayArguments
@TruffleBoundary
@Specialization
public Object sourceLocation(DynamicObject unboundMethod) {
SourceSection sourceSection = Layouts.UNBOUND_METHOD.getMethod(unboundMethod).getNamedSharedMethodInfo().getSourceSection();
SourceSection sourceSection = Layouts.UNBOUND_METHOD.getMethod(unboundMethod).getSharedMethodInfo().getSourceSection();

if (sourceSection.getSource() == null) {
return nil();
Expand Down
Expand Up @@ -347,7 +347,7 @@ public void addMethod(RubyContext context, Node currentNode, InternalMethod meth
if (context.getCoreLibrary().isLoadingRubyCore()) {
final InternalMethod currentMethod = methods.get(method.getName());

if (currentMethod != null && currentMethod.getNamedSharedMethodInfo().getSourceSection().getSource() == null) {
if (currentMethod != null && currentMethod.getSharedMethodInfo().getSourceSection().getSource() == null) {
return;
}
}
Expand Down

0 comments on commit 7e88131

Please sign in to comment.