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

Commits on Apr 18, 2015

  1. Make setIRScope and setScopeType simpler. This change makes me wonder…

    … how safe we are since not all
    
    constructed IRScope paths setIRScope.  In the case of evals it appears we only set IRScopeType.
    enebo committed Apr 18, 2015
    Copy the full SHA
    905afa0 View commit details
  2. IRPersistence via AOT was not properly recording nested scopes. To dr…

    …ive Ruby code to generate AOT
    
    code we need to create a separate IRManager and put it in dry run mode so it sets up lexical
    containment info.
    enebo committed Apr 18, 2015
    Copy the full SHA
    79ed302 View commit details
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ir/IRMethod.java
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ public IRMethod(IRManager manager, IRScope lexicalParent, MethodDefNode defn, St

if (!getManager().isDryRun() && staticScope != null) {
staticScope.setIRScope(this);
staticScope.setScopeType(this.getScopeType());
}
}

5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/ir/IRModuleBody.java
Original file line number Diff line number Diff line change
@@ -15,10 +15,7 @@ public IRModuleBody(IRManager manager, IRScope lexicalParent, String name,

if (!getManager().isDryRun()) {
updateVersion();
if (staticScope != null) {
staticScope.setIRScope(this);
staticScope.setScopeType(this.getScopeType());
}
if (staticScope != null) staticScope.setIRScope(this);
}
}

1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScriptBody.java
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScop
this.toplevelScope = null;
if (!getManager().isDryRun() && staticScope != null) {
staticScope.setIRScope(this);
staticScope.setScopeType(this.getScopeType());
}
}

42 changes: 3 additions & 39 deletions core/src/main/java/org/jruby/parser/StaticScope.java
Original file line number Diff line number Diff line change
@@ -86,9 +86,8 @@ public class StaticScope implements Serializable {

private Type type;
private boolean isBlockOrEval;
private boolean isArgumentScope; // Is this block and argument scope of a define_method (for the purposes of zsuper).
private boolean isArgumentScope; // Is this block and argument scope of a define_method.

private int scopeId;
private IRScope irScope; // Method/Closure that this static scope corresponds to

public enum Type {
@@ -134,10 +133,6 @@ public IRScope getIRScope() {
return irScope;
}

public int getScopeId() {
return scopeId;
}

public IRScopeType getScopeType() {
return scopeType;
}
@@ -146,16 +141,9 @@ public void setScopeType(IRScopeType scopeType) {
this.scopeType = scopeType;
}

public void setIRScope(IRScope irScope, boolean isForLoopBody) {
if (!isForLoopBody) {
this.irScope = irScope;
}
this.scopeId = irScope.getScopeId();
this.scopeType = irScope.getScopeType();
}

public void setIRScope(IRScope irScope) {
setIRScope(irScope, false);
this.irScope = irScope;
this.scopeType = irScope.getScopeType();
}

/**
@@ -233,18 +221,6 @@ public void setVariables(String[] names) {
System.arraycopy(names, 0, variableNames, 0, names.length);
}

/* Note: Only used by compiler until it can use getConstant again or use some other refactoring */
public IRubyObject getConstantWithConstMissing(String internedName) {
IRubyObject result = getConstantInner(internedName);

// If we could not find the constant from cref..then try getting from inheritence hierarchy
return result == null ? cref.getConstant(internedName) : result;
}

public boolean isConstantDefined(String internedName) {
return getConstant(internedName) != null;
}

public IRubyObject getConstant(String internedName) {
IRubyObject result = getConstantInner(internedName);

@@ -268,18 +244,6 @@ private IRubyObject getConstantInnerNoObject(String internedName) {
return getConstantInner(internedName);
}

public IRubyObject setConstant(String internedName, IRubyObject result) {
RubyModule module;

if ((module = getModule()) != null) {
module.setConstant(internedName, result);
return result;
}

// TODO: wire into new exception handling mechanism
throw result.getRuntime().newTypeError("no class/module to define constant");
}

/**
* Next outer most scope in list of scopes. An enclosing scope may have no direct scoping
* relationship to its child. If I am in a localScope and then I enter something which
12 changes: 1 addition & 11 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -656,12 +656,6 @@ public static IRubyObject fetchClassVariable(Ruby runtime, StaticScope scope,
return rubyClass.getClassVar(name);
}

public static IRubyObject getConstant(ThreadContext context, String internedName) {
Ruby runtime = context.runtime;

return context.getCurrentScope().getStaticScope().getConstantWithConstMissing(internedName);
}

public static IRubyObject nullToNil(IRubyObject value, ThreadContext context) {
return value != null ? value : context.nil;
}
@@ -1195,15 +1189,11 @@ public static IRubyObject setConstantInModule(ThreadContext context, String name
if (!(module instanceof RubyModule)) {
throw context.runtime.newTypeError(module.toString() + " is not a class/module");
}
((RubyModule)module).setConstant(name, value);
((RubyModule) module).setConstant(name, value);

return value;
}

public static IRubyObject setConstantInCurrent(IRubyObject value, ThreadContext context, String name) {
return context.getCurrentStaticScope().setConstant(name, value);
}

public static final int MAX_SPECIFIC_ARITY_OBJECT_ARRAY = 10;

public static IRubyObject[] anewarrayIRubyObjects(int size) {
4 changes: 3 additions & 1 deletion core/src/main/ruby/jruby/jruby.rb
Original file line number Diff line number Diff line change
@@ -64,13 +64,15 @@ def parse(content = nil, filename = (default_filename = true; '-'), extra_positi

def compile_ir(content = nil, filename = (default_filename = true; '-'), extra_position_info = false, &block)
runtime = JRuby.runtime
manager = org.jruby.ir.IRManager.new(runtime.instance_config)
manager.dry_run = true
node = if default_filename
parse(content, &block)
else
parse(content, filename, extra_position_info, &block)
end

scope = org.jruby.ir.IRBuilder.build_root(runtime.getIRManager(), node).scope
scope = org.jruby.ir.IRBuilder.build_root(manager, node).scope
scope.top_level_binding_scope = node.scope

scope