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

Commits on Nov 16, 2016

  1. Copy the full SHA
    d0ae33e View commit details
  2. Copy the full SHA
    4e72110 View commit details
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ private void addCoreMethod(DynamicObject module, MethodDetails methodDetails) {
System.err.println("WARNING: Either onSingleton or constructor for " + methodDetails.getIndicativeName());
}

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

if (method.isModuleFunction()) {
@@ -166,18 +166,20 @@ private static void addMethod(RubyContext context, DynamicObject module, SharedM
}
}

private static SharedMethodInfo makeSharedMethodInfo(RubyContext context, MethodDetails methodDetails) {
private static SharedMethodInfo makeSharedMethodInfo(RubyContext context, DynamicObject module, MethodDetails methodDetails) {
final CoreMethod method = methodDetails.getMethodAnnotation();
final String methodName = methodDetails.getIndicativeName();

final int required = method.required();
final int optional = method.optional();
final boolean needsCallerFrame = method.needsCallerFrame();
final boolean alwaysInline = needsCallerFrame && context.getOptions().INLINE_NEEDS_CALLER_FRAME;

final Arity arity = new Arity(required, optional, method.rest());

return new SharedMethodInfo(context.getCoreLibrary().getSourceSection(), LexicalScope.NONE, arity, methodName, false, null, context.getOptions().CORE_ALWAYS_CLONE, alwaysInline, needsCallerFrame);
return new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),
LexicalScope.NONE,
new Arity(method.required(), method.optional(), method.rest()),
module,
methodDetails.getPrimaryName(),
"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, SharedMethodInfo sharedMethodInfo) {
@@ -385,8 +387,16 @@ public NodeFactory<? extends RubyNode> getNodeFactory() {
return nodeFactory;
}

public String getModuleName() {
return moduleName;
}

public String getPrimaryName() {
return methodAnnotation.names()[0];
}

public String getIndicativeName() {
return moduleName + "#" + methodAnnotation.names()[0];
return moduleName + "#" + getPrimaryName();
}
}

Original file line number Diff line number Diff line change
@@ -380,10 +380,20 @@ private void createAccesor(DynamicObject module, String name) {
final Arity arity = isGetter ? Arity.NO_ARGUMENTS : Arity.ONE_REQUIRED;
final String ivar = "@" + name;
final String accessorName = isGetter ? name : name + "=";
final String indicativeName = name + "(attr_" + (isGetter ? "reader" : "writer") + ")";

final RubyNode checkArity = Translator.createCheckArityNode(getContext(), sourceSection.getSource(), rubySourceSection, arity);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, LexicalScope.NONE, arity, indicativeName, false, null, false, false, false);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection,
LexicalScope.NONE,
arity,
module,
accessorName,
"attr_" + (isGetter ? "reader" : "writer"),
null,
false,
false,
false);

final RubyNode self = new ProfileArgumentNode(new ReadSelfNode());
final RubyNode accessInstanceVariable;
Original file line number Diff line number Diff line change
@@ -110,7 +110,17 @@ protected DynamicObject createProc(InternalMethod method, DynamicObject symbol)
.getCallNode().getEncapsulatingSourceSection();
final RubySourceSection rubySourceSection = new RubySourceSection(sourceSection);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.AT_LEAST_ONE, Layouts.SYMBOL.getString(symbol), true, ArgumentDescriptor.ANON_REST, false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection,
null,
Arity.AT_LEAST_ONE,
null,
Layouts.SYMBOL.getString(symbol),
"proc",
ArgumentDescriptor.ANON_REST,
false,
false,
false);

final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, Translator.sequence(getContext(), sourceSection.getSource(), rubySourceSection, Arrays.asList(Translator.createCheckArityNode(getContext(), sourceSection.getSource(), rubySourceSection, Arity.AT_LEAST_ONE), new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol)))), false);

Original file line number Diff line number Diff line change
@@ -74,12 +74,16 @@ public Node copy() {

@Override
public String getName() {
return sharedMethodInfo.getName();
if (sharedMethodInfo.getName() != null) {
return sharedMethodInfo.getName();
} else {
return sharedMethodInfo.getNotes();
}
}

@Override
public String toString() {
return sharedMethodInfo.toString();
return sharedMethodInfo.getDescriptiveNameAndSource();
}

public SharedMethodInfo getSharedMethodInfo() {
Original file line number Diff line number Diff line change
@@ -9,8 +9,10 @@
*/
package org.jruby.truffle.language.methods;

import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.language.LexicalScope;

/**
@@ -22,9 +24,10 @@ public class SharedMethodInfo {
private final SourceSection sourceSection;
private final LexicalScope lexicalScope;
private final Arity arity;
private final DynamicObject definitionModule;
/** The original name of the method. Does not change when aliased. */
private final String name;
private final boolean isBlock;
private final String notes;
private final ArgumentDescriptor[] argumentDescriptors;
private final boolean alwaysClone;
private final boolean alwaysInline;
@@ -34,8 +37,9 @@ public SharedMethodInfo(
SourceSection sourceSection,
LexicalScope lexicalScope,
Arity arity,
DynamicObject definitionModule,
String name,
boolean isBlock,
String notes,
ArgumentDescriptor[] argumentDescriptors,
boolean alwaysClone,
boolean alwaysInline,
@@ -47,8 +51,9 @@ public SharedMethodInfo(
this.sourceSection = sourceSection;
this.lexicalScope = lexicalScope;
this.arity = arity;
this.definitionModule = definitionModule;
this.name = name;
this.isBlock = isBlock;
this.notes = notes;
this.argumentDescriptors = argumentDescriptors;
this.alwaysClone = alwaysClone;
this.alwaysInline = alwaysInline;
@@ -71,8 +76,8 @@ public String getName() {
return name;
}

public boolean isBlock() {
return isBlock;
public String getNotes() {
return notes;
}

public ArgumentDescriptor[] getArgumentDescriptors() {
@@ -96,23 +101,49 @@ public SharedMethodInfo withName(String newName) {
sourceSection,
lexicalScope,
arity,
definitionModule,
newName,
isBlock,
notes,
argumentDescriptors,
alwaysClone,
alwaysInline,
needsCallerFrame);
}

@Override
public String toString() {
final String suffix;
if (sourceSection == null) {
return name;
} else if (!sourceSection.isAvailable()) {
return String.format("%s %s", name, sourceSection.getSource().getName());
public String getDescriptiveName() {
final StringBuilder descriptiveName = new StringBuilder();

if (definitionModule != null) {
descriptiveName.append(Layouts.MODULE.getFields(definitionModule).getName());
}

if (name != null) {
descriptiveName.append('#');
descriptiveName.append(name);
}

if (notes != null) {
final boolean parens = descriptiveName.length() > 0;

if (parens) {
descriptiveName.append(" (");
}

descriptiveName.append(notes);

if (parens) {
descriptiveName.append(')');
}
}

return descriptiveName.toString();
}

public String getDescriptiveNameAndSource() {
if (sourceSection == null || !sourceSection.isAvailable()) {
return getDescriptiveName();
} else {
return String.format("%s %s:%d", name, sourceSection.getSource().getName(), sourceSection.getStartLine());
return String.format("%s %s:%d", getDescriptiveName(), sourceSection.getSource().getName(), sourceSection.getStartLine());
}
}

38 changes: 34 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/parser/BodyTranslator.java
Original file line number Diff line number Diff line change
@@ -991,7 +991,17 @@ private RubyNode openModule(RubySourceSection sourceSection, RubyNode defineOrGe

LexicalScope newLexicalScope = environment.pushLexicalScope();
try {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(fullSourceSection, newLexicalScope, Arity.NO_ARGUMENTS, name, false, null, false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
fullSourceSection,
newLexicalScope,
Arity.NO_ARGUMENTS,
null,
name,
sclass ? "class body" : "module body",
null,
false,
false,
false);

final ReturnID returnId;

@@ -1385,7 +1395,18 @@ protected RubyNode translateMethodDefinition(RubySourceSection sourceSection, Ru

final Arity arity = MethodTranslator.getArity(argsNode);
final ArgumentDescriptor[] argumentDescriptors = Helpers.argsNodeToArgumentDescriptors(argsNode);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection.toSourceSection(source), environment.getLexicalScope(), arity, methodName, false, argumentDescriptors, false, false, false);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection.toSourceSection(source),
environment.getLexicalScope(),
arity,
null,
methodName,
null,
argumentDescriptors,
false,
false,
false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParseEnvironment(), environment.getParseEnvironment().allocateReturnID(), true, true, sharedMethodInfo, methodName, 0, null);
@@ -1974,10 +1995,19 @@ private RubyNode translateBlockLikeNode(IterParseNode node, boolean isLambda) {
// Unset this flag for any for any blocks within the for statement's body
final boolean hasOwnScope = isLambda || !translatingForStatement;

final String name = isLambda ? "(lambda)" : getIdentifierInNewEnvironment(true, currentCallMethodName);
final boolean isProc = !isLambda;

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection.toSourceSection(source), environment.getLexicalScope(), MethodTranslator.getArity(argsNode), name, true, Helpers.argsNodeToArgumentDescriptors(argsNode), false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection.toSourceSection(source),
environment.getLexicalScope(),
MethodTranslator.getArity(argsNode),
null,
null,
isLambda ? "lambda" : getIdentifierInNewEnvironment(true, currentCallMethodName),
Helpers.argsNodeToArgumentDescriptors(argsNode),
false,
false,
false);

final String namedMethodName = isLambda ? sharedMethodInfo.getName(): environment.getNamedMethodName();

Original file line number Diff line number Diff line change
@@ -365,7 +365,7 @@ public RubyNode visitZSuperNode(ZSuperParseNode node) {
while (methodArgumentsTranslator.isBlock) {
if (!(methodArgumentsTranslator.parent instanceof MethodTranslator)) {
return new ZSuperOutsideMethodNode(context, fullSourceSection, insideDefineMethod);
} else if (methodArgumentsTranslator.currentCallMethodName.equals("define_method")) {
} else if (methodArgumentsTranslator.currentCallMethodName != null && methodArgumentsTranslator.currentCallMethodName.equals("define_method")) {
insideDefineMethod = true;
}
methodArgumentsTranslator = (MethodTranslator) methodArgumentsTranslator.parent;
Original file line number Diff line number Diff line change
@@ -158,7 +158,17 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
parseEnvironment.resetLexicalScope(lexicalScope);

// TODO (10 Feb. 2015): name should be "<top (required)> for the require-d/load-ed files.
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, parseEnvironment.getLexicalScope(), Arity.NO_ARGUMENTS, "<main>", false, null, false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection,
parseEnvironment.getLexicalScope(),
Arity.NO_ARGUMENTS,
null,
"<main>",
null,
null,
false,
false,
false);

final TranslatorEnvironment environment = new TranslatorEnvironment(context, parentEnvironment,
parseEnvironment, parseEnvironment.allocateReturnID(), ownScopeForAssignments, false, sharedMethodInfo, sharedMethodInfo.getName(), 0, null);
@@ -247,7 +257,17 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
}

private TranslatorEnvironment environmentForFrameDescriptor(RubyContext context, FrameDescriptor frameDescriptor) {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(context.getCoreLibrary().getSourceSection(), context.getRootLexicalScope(), Arity.NO_ARGUMENTS, "(unknown)", false, null, false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),
context.getRootLexicalScope(),
Arity.NO_ARGUMENTS,
null,
null,
"external",
null,
false,
false,
false);
// TODO(CS): how do we know if the frame is a block or not?
return new TranslatorEnvironment(context, null, parseEnvironment,
parseEnvironment.allocateReturnID(), true, true, sharedMethodInfo, sharedMethodInfo.getName(), 0, null, frameDescriptor);
@@ -257,7 +277,17 @@ private TranslatorEnvironment environmentForFrame(RubyContext context, Materiali
if (frame == null) {
return null;
} else {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(context.getCoreLibrary().getSourceSection(), context.getRootLexicalScope(), Arity.NO_ARGUMENTS, "(unknown)", false, null, false, false, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),
context.getRootLexicalScope(),
Arity.NO_ARGUMENTS,
null,
null,
"external",
null,
false,
false,
false);
final MaterializedFrame parent = RubyArguments.getDeclarationFrame(frame);
// TODO(CS): how do we know if the frame is a block or not?
return new TranslatorEnvironment(context, environmentForFrame(context, parent), parseEnvironment,