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

Commits on Jul 14, 2017

  1. identifier is dead. removing...

    enebo committed Jul 14, 2017
    Copy the full SHA
    605b814 View commit details
  2. Start of using symbols as identifiers. Only local variable names and …

    …only
    
    for static scope.  IRBuilder has not been changed to use them.
    
    The main desire for Symbols is we maintain a single pool of them.  When we
    were using String we would intern to get similar benefit.  Current parser is
    making lots and lots of ByteLists.  This will end up having a memory impact
    (one I have not actually measured) but by using Symbols we will be back to
    a String.intern amount.
    
    Symbols also conceptually is what all reflective APIs already want.
    enebo committed Jul 14, 2017
    Copy the full SHA
    aa68440 View commit details
Showing with 259 additions and 157 deletions.
  1. +1 −1 core/src/main/java/org/jruby/Ruby.java
  2. +10 −9 core/src/main/java/org/jruby/RubyBinding.java
  3. +4 −4 core/src/main/java/org/jruby/RubyKernel.java
  4. +1 −1 core/src/main/java/org/jruby/RubySymbol.java
  5. +11 −6 core/src/main/java/org/jruby/ast/DAsgnNode.java
  6. +11 −6 core/src/main/java/org/jruby/ast/DVarNode.java
  7. +11 −6 core/src/main/java/org/jruby/ast/LocalAsgnNode.java
  8. +11 −6 core/src/main/java/org/jruby/ast/LocalVarNode.java
  9. +29 −23 core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
  10. +27 −13 core/src/main/java/org/jruby/ext/ripper/RipperParserBase.java
  11. +8 −2 core/src/main/java/org/jruby/ir/IRBuilder.java
  12. +1 −1 core/src/main/java/org/jruby/ir/IRClosure.java
  13. +9 −1 core/src/main/java/org/jruby/ir/IRManager.java
  14. +2 −1 core/src/main/java/org/jruby/ir/IRScope.java
  15. +3 −7 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
  16. +1 −2 core/src/main/java/org/jruby/lexer/LexingCommon.java
  17. +4 −3 core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
  18. +37 −15 core/src/main/java/org/jruby/parser/ParserSupport.java
  19. +2 −2 core/src/main/java/org/jruby/parser/RubyParser.java
  20. +2 −2 core/src/main/java/org/jruby/parser/RubyParser.y
  21. +41 −35 core/src/main/java/org/jruby/parser/StaticScope.java
  22. +10 −9 core/src/main/java/org/jruby/parser/StaticScopeFactory.java
  23. +2 −1 core/src/main/java/org/jruby/runtime/DynamicScope.java
  24. +1 −1 core/src/main/java/org/jruby/runtime/Helpers.java
  25. +20 −0 core/src/main/java/org/jruby/util/StringSupport.java
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -1183,7 +1183,7 @@ private void init() {
initThreadStatuses();

// Create an IR manager and a top-level IR scope and bind it to the top-level static-scope object
irManager = new IRManager(getInstanceConfig());
irManager = new IRManager(this, getInstanceConfig());
// FIXME: This registers itself into static scope as a side-effect. Let's make this
// relationship handled either more directly or through a descriptice method
// FIXME: We need a failing test case for this since removing it did not regress tests
19 changes: 10 additions & 9 deletions core/src/main/java/org/jruby/RubyBinding.java
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.IdUtil;
import org.jruby.util.TypeConverter;

/**
* @author jpetersen
@@ -141,28 +142,28 @@ public IRubyObject eval(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "local_variable_defined?")
public IRubyObject local_variable_defined_p(ThreadContext context, IRubyObject symbol) {
return context.runtime.newBoolean(binding.getEvalScope(context.runtime).getStaticScope().isDefined(symbol.asJavaString()) != -1);
return context.runtime.newBoolean(binding.getEvalScope(context.runtime).getStaticScope().isDefined(TypeConverter.checkID(symbol)) != -1);
}

@JRubyMethod
public IRubyObject local_variable_get(ThreadContext context, IRubyObject symbol) {
String name = symbol.asJavaString().intern();
RubySymbol name = TypeConverter.checkID(symbol);
DynamicScope evalScope = binding.getEvalScope(context.runtime);
int slot = evalScope.getStaticScope().isDefined(name);

if (slot == -1) throw context.runtime.newNameError("local variable `" + name + "' not defined for " + inspect(), name);
if (slot == -1) throw context.runtime.newNameError("local variable `" + name + "' not defined for " + inspect(), name.asJavaString());

return evalScope.getValue(slot & 0xffff, slot >> 16);
}

@JRubyMethod
public IRubyObject local_variable_set(ThreadContext context, IRubyObject symbol, IRubyObject value) {
String name = symbol.asJavaString().intern();
RubySymbol name = TypeConverter.checkID(symbol);
DynamicScope evalScope = binding.getEvalScope(context.runtime);
int slot = evalScope.getStaticScope().isDefined(name);

if (slot == -1) { // Yay! New variable associated with this binding
slot = evalScope.getStaticScope().addVariable(name.intern());
slot = evalScope.getStaticScope().addVariable(name);
evalScope.growIfNeeded();
}

@@ -172,14 +173,14 @@ public IRubyObject local_variable_set(ThreadContext context, IRubyObject symbol,
@JRubyMethod
public IRubyObject local_variables(ThreadContext context) {
final Ruby runtime = context.runtime;
HashSet<String> encounteredLocalVariables = new HashSet<>();
HashSet<RubySymbol> encounteredLocalVariables = new HashSet<>();
RubyArray allLocalVariables = runtime.newArray();
DynamicScope currentScope = binding.getEvalScope(context.runtime);

while (currentScope != null) {
for (String name : currentScope.getStaticScope().getVariables()) {
if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) {
allLocalVariables.push(runtime.newSymbol(name));
for (RubySymbol name : currentScope.getStaticScope().getVariableSymbols()) {
if (IdUtil.isLocal(name.asJavaString()) && !encounteredLocalVariables.contains(name)) {
allLocalVariables.push(name);
encounteredLocalVariables.add(name);
}
}
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -759,14 +759,14 @@ public static RubyArray local_variables(ThreadContext context, IRubyObject recv)
@JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE)
public static RubyArray local_variables19(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
HashSet<String> encounteredLocalVariables = new HashSet<String>();
HashSet<RubySymbol> encounteredLocalVariables = new HashSet<>();
RubyArray allLocalVariables = runtime.newArray();
DynamicScope currentScope = context.getCurrentScope();

while (currentScope != null) {
for (String name : currentScope.getStaticScope().getVariables()) {
if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) {
allLocalVariables.push(runtime.newSymbol(name));
for (RubySymbol name : currentScope.getStaticScope().getVariableSymbols()) {
if (IdUtil.isLocal(name.asJavaString()) && !encounteredLocalVariables.contains(name)) {
allLocalVariables.push(name);
encounteredLocalVariables.add(name);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ public final String toString() {
return symbol;
}

final ByteList getBytes() {
public final ByteList getBytes() {
return symbolBytes;
}

17 changes: 11 additions & 6 deletions core/src/main/java/org/jruby/ast/DAsgnNode.java
Original file line number Diff line number Diff line change
@@ -33,32 +33,33 @@

import java.util.List;

import org.jruby.Ruby;
import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* An assignment to a dynamic variable (e.g. block scope local variable).
*/
public class DAsgnNode extends AssignableNode implements INameNode, IScopedNode {
// The name of the variable
private ByteList name;
private RubySymbol name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private int location;

public DAsgnNode(ISourcePosition position, ByteList name, int location, Node valueNode) {
public DAsgnNode(ISourcePosition position, RubySymbol name, int location, Node valueNode) {
super(position, valueNode, true);
this.name = name;
this.location = location;
}

@Deprecated
public DAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
this(position, StringSupport.stringAsByteList(name), location, valueNode);
this(position, Ruby.getThreadLocalRuntime().newSymbol(name), location, valueNode);
}

public NodeType getNodeType() {
@@ -78,10 +79,14 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public ByteList getByteName() {
return name.getBytes();
}

public RubySymbol getSymbolName() {
return name;
}

@@ -110,7 +115,7 @@ public List<Node> childNodes() {

@Deprecated
public void setName(String name) {
this.name = StringSupport.stringAsByteList(name);
this.name = Ruby.getThreadLocalRuntime().newSymbol(name);
}

@Override
17 changes: 11 additions & 6 deletions core/src/main/java/org/jruby/ast/DVarNode.java
Original file line number Diff line number Diff line change
@@ -33,32 +33,33 @@

import java.util.List;

import org.jruby.Ruby;
import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Access a dynamic variable (e.g. block scope local variable).
*/
public class DVarNode extends Node implements INameNode, IScopedNode, SideEffectFree {
// The name of the variable
private ByteList name;
private RubySymbol name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private int location;

public DVarNode(ISourcePosition position, int location, ByteList name) {
public DVarNode(ISourcePosition position, int location, RubySymbol name) {
super(position, false);
this.location = location;
this.name = name;
}

@Deprecated
public DVarNode(ISourcePosition position, int location, String name) {
this(position, location, StringSupport.stringAsByteList(name));
this(position, location, Ruby.getThreadLocalRuntime().newSymbol(name));
}

public NodeType getNodeType() {
@@ -97,10 +98,14 @@ public int getIndex() {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public ByteList getByteName() {
return name.getBytes();
}

public RubySymbol getSymbolName() {
return name;
}

@@ -110,7 +115,7 @@ public ByteList getByteName() {
*/
@Deprecated
public void setName(String name) {
this.name = StringSupport.stringAsByteList(name);
Ruby.getThreadLocalRuntime().newSymbol(name);
}

public List<Node> childNodes() {
17 changes: 11 additions & 6 deletions core/src/main/java/org/jruby/ast/LocalAsgnNode.java
Original file line number Diff line number Diff line change
@@ -34,32 +34,33 @@

import java.util.List;

import org.jruby.Ruby;
import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* An assignment to a local variable.
*/
public class LocalAsgnNode extends AssignableNode implements INameNode, IScopedNode {
// The name of the variable
private ByteList name;
private RubySymbol name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private final int location;

public LocalAsgnNode(ISourcePosition position, ByteList name, int location, Node valueNode) {
public LocalAsgnNode(ISourcePosition position, RubySymbol name, int location, Node valueNode) {
super(position, valueNode, true);
this.name = name;
this.location = location;
}

@Deprecated
public LocalAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
this(position, StringSupport.stringAsByteList(name), location, valueNode);
this(position, Ruby.getThreadLocalRuntime().newSymbol(name), location, valueNode);
}

public NodeType getNodeType() {
@@ -78,10 +79,14 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* Name of the local assignment.
**/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public ByteList getByteName() {
return name.getBytes();
}

public RubySymbol getSymbolName() {
return name;
}

@@ -91,7 +96,7 @@ public ByteList getByteName() {
*/
@Deprecated
public void setName(String name) {
this.name = StringSupport.stringAsByteList(name);
this.name = Ruby.getThreadLocalRuntime().newSymbol(name);
}

/**
17 changes: 11 additions & 6 deletions core/src/main/java/org/jruby/ast/LocalVarNode.java
Original file line number Diff line number Diff line change
@@ -33,32 +33,33 @@

import java.util.List;

import org.jruby.Ruby;
import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Access a local variable
*/
public class LocalVarNode extends Node implements INameNode, IScopedNode, SideEffectFree {
// The name of the variable
private ByteList name;
private RubySymbol name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private final int location;

public LocalVarNode(ISourcePosition position, int location, ByteList name) {
public LocalVarNode(ISourcePosition position, int location, RubySymbol name) {
super(position, false);
this.location = location;
this.name = name;
}

@Deprecated
public LocalVarNode(ISourcePosition position, int location, String name) {
this(position, location, StringSupport.stringAsByteList(name));
this(position, location, Ruby.getThreadLocalRuntime().newSymbol(name));
}

public NodeType getNodeType() {
@@ -98,10 +99,14 @@ public int getIndex() {
* @return the name of the variable
*/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public ByteList getByteName() {
return name.getBytes();
}

public RubySymbol getSymbolName() {
return name;
}

@@ -111,7 +116,7 @@ public ByteList getByteName() {
*/
@Deprecated
public void setName(String name) {
this.name = StringSupport.stringAsByteList(name);
this.name = Ruby.getThreadLocalRuntime().newSymbol(name);
}

public List<Node> childNodes() {
Loading