Skip to content

Commit

Permalink
Bootstrapping magic in IR persistent store loading. IRReaderStream ne…
Browse files Browse the repository at this point in the history
…eds a

currentScope to be able to make symbols but on first header in a persistent
store we have none.  So read scope name as bytelist and move up setting of
currentScope higher so variable reification has a valid value.
  • Loading branch information
enebo committed Apr 15, 2018
1 parent 7e8c848 commit a61f07e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/ir/persistence/IRReader.java
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.concurrent.Callable;

import org.jruby.util.ByteList;
import org.jruby.util.KeyValuePair;

/**
Expand Down Expand Up @@ -77,7 +78,9 @@ private static KeyValuePair<IRScope, Integer> decodeScopeHeader(IRManager manage
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("DECODING SCOPE HEADER");
IRScopeType type = decoder.decodeIRScopeType();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("IRScopeType = " + type);
RubySymbol name = decoder.decodeSymbol();
// Wackiness we decode as bytelist when we encoded as symbol because currentScope is not defined yet on first
// name of first scope. We will use manager in this method to finish the job in constructing our symbol.
ByteList name = decoder.decodeByteList();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("NAME = " + name);
int line = decoder.decodeInt();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("LINE = " + line);
Expand All @@ -97,18 +100,18 @@ private static KeyValuePair<IRScope, Integer> decodeScopeHeader(IRManager manage
// FIXME: It seems wrong we have static scope + local vars both being persisted. They must have the same values
// and offsets?
StaticScope staticScope = decodeStaticScope(decoder, parentScope);
IRScope scope = createScope(manager, type, name, line, parent, signature, staticScope);
IRScope scope = createScope(manager, type, manager.runtime.newSymbol(name), line, parent, signature, staticScope);

scope.setTemporaryVariableCount(tempVarsCount);
// FIXME: Replace since we are defining this...perhaps even make a persistence constructor
scope.setLabelIndices(indices);

decoder.addScope(scope);

// FIXME: This is odd, but ClosureLocalVariable wants it's defining closure...feels wrong.
// But because of this we have to push decoding lvars to the end of the scope info.
scope.setLocalVariables(decodeScopeLocalVariables(decoder, scope));

decoder.addScope(scope);

int instructionsOffset = decoder.decodeInt();

return new KeyValuePair<>(scope, instructionsOffset);
Expand Down
Expand Up @@ -152,6 +152,7 @@ public String decodeString() {
@Override
public void addScope(IRScope scope) {
scopes.add(scope);
currentScope = scope;
}

@Override
Expand Down Expand Up @@ -188,7 +189,6 @@ public Map<String, Operand> getVars() {

@Override
public List<Instr> decodeInstructionsAt(IRScope scope, int offset) {
currentScope = scope;
vars = new HashMap<>();
buf.position(offset);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/persistence/IRWriter.java
Expand Up @@ -78,7 +78,7 @@ private static void persistScopeHeader(IRWriterEncoder file, IRScope scope) {
file.startEncodingScopeHeader(scope);
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("IRScopeType = " + scope.getScopeType());
file.encode(scope.getScopeType()); // type is enum of kind of scope
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("NAME = " + scope.getId());
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("NAME = " + scope.getName());
file.encode(scope.getName());
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("Line # = " + scope.getLineNumber());
file.encode(scope.getLineNumber());
Expand Down

0 comments on commit a61f07e

Please sign in to comment.