Skip to content

Commit

Permalink
Remove unused CompilerContext variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Apr 8, 2015
1 parent ffe9f32 commit 44ff930
Show file tree
Hide file tree
Showing 30 changed files with 273 additions and 284 deletions.
69 changes: 0 additions & 69 deletions presto-main/src/main/java/com/facebook/presto/byteCode/Block.java
Expand Up @@ -762,12 +762,6 @@ public Block putStaticField(ParameterizedType target, String fieldName, Paramete
// Load constants
//

public Block pushThis()
{
getVariable("this");
return this;
}

public Block pushNull()
{
nodes.add(OpCode.ACONST_NULL);
Expand Down Expand Up @@ -830,20 +824,6 @@ public Block pushJavaDefault(Class<?> type)
return pushNull();
}

public Block getVariable(String name)
{
checkArgument(context != null, "Variable %s not defined", name);
append(loadVariable(context.getVariable(name)));
return this;
}

public Block getVariable(String name, ParameterizedType type)
{
getVariable(name);
checkCast(type);
return this;
}

public Block initializeVariable(Variable variable)
{
ParameterizedType type = variable.getType();
Expand Down Expand Up @@ -884,55 +864,6 @@ public Block getVariable(Variable variable)
return this;
}

public Block putVariable(String name)
{
checkArgument(context != null, "Variable %s not defined", name);
putVariable(context.getVariable(name));
return this;
}

public Block putVariable(String name, Class<?> type)
{
nodes.add(loadClass(type));
putVariable(name);
return this;
}

public Block putVariable(String name, ParameterizedType type)
{
nodes.add(loadClass(type));
putVariable(name);
return this;
}

public Block putVariable(String name, String value)
{
nodes.add(Constant.loadString(value));
putVariable(name);
return this;
}

public Block putVariable(String name, Number value)
{
nodes.add(loadNumber(value));
putVariable(name);
return this;
}

public Block putVariable(String name, int value)
{
nodes.add(loadInt(value));
putVariable(name);
return this;
}

public Block putVariable(String name, boolean value)
{
nodes.add(loadBoolean(value));
putVariable(name);
return this;
}

public Block putVariable(Variable variable)
{
nodes.add(storeVariable(variable));
Expand Down
Expand Up @@ -238,9 +238,10 @@ public MethodDefinition declareConstructor(

public ClassDefinition declareDefaultConstructor(EnumSet<Access> access)
{
declareConstructor(new CompilerContext(), access)
MethodDefinition constructor = declareConstructor(access);
constructor
.getBody()
.pushThis()
.append(constructor.getThis())
.invokeConstructor(superClass)
.ret();
return this;
Expand Down
Expand Up @@ -48,6 +48,11 @@ public Variable createTempVariable(Class<?> type)
return variable;
}

public Variable getThis()
{
return getVariable("this");
}

public Variable getVariable(String name)
{
Variable variable = variables.get(name);
Expand Down
Expand Up @@ -170,6 +170,11 @@ public CompilerContext getCompilerContext()
return compilerContext;
}

public Variable getThis()
{
return compilerContext.getThis();
}

public String getMethodDescriptor()
{
return methodDescription(returnType, parameterTypes);
Expand Down
Expand Up @@ -166,7 +166,7 @@ private static MethodDefinition generateGetIntermediateType(ClassDefinition defi
MethodDefinition methodDefinition = definition.declareMethod(a(PUBLIC), "getIntermediateType", type(Type.class));

methodDefinition.getBody()
.append(constantType(new CompilerContext(), callSiteBinder, type))
.append(constantType(callSiteBinder, type))
.retObject();

return methodDefinition;
Expand All @@ -177,7 +177,7 @@ private static MethodDefinition generateGetFinalType(ClassDefinition definition,
MethodDefinition methodDefinition = definition.declareMethod(a(PUBLIC), "getFinalType", type(Type.class));

methodDefinition.getBody()
.append(constantType(new CompilerContext(), callSiteBinder, type))
.append(constantType(callSiteBinder, type))
.retObject();

return methodDefinition;
Expand All @@ -186,8 +186,7 @@ private static MethodDefinition generateGetFinalType(ClassDefinition definition,
private static void generateGetEstimatedSize(ClassDefinition definition, FieldDefinition stateField)
{
MethodDefinition method = definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class));
CompilerContext compilerContext = method.getCompilerContext();
ByteCodeExpression state = compilerContext.getVariable("this").getField(stateField);
ByteCodeExpression state = method.getThis().getField(stateField);
method.getBody()
.append(state.invoke("getEstimatedSize", long.class).ret());
}
Expand All @@ -211,7 +210,7 @@ private static void generateAddInput(

MethodDefinition method = definition.declareMethod(a(PUBLIC), "addInput", type(void.class), parameters.build());
CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = context.getThis();
Variable page = context.getVariable("page");
Block body = method.getBody();

Expand Down Expand Up @@ -392,7 +391,7 @@ private static Block generateInvokeInputFunction(
ParameterMetadata parameterMetadata = parameterMetadatas.get(i);
switch (parameterMetadata.getParameterType()) {
case STATE:
block.append(context.getVariable("this").getField(stateField));
block.append(context.getThis().getField(stateField));
break;
case BLOCK_INDEX:
block.getVariable(position);
Expand All @@ -416,7 +415,7 @@ private static Block generateInvokeInputFunction(
}
}

block.append(invoke(context, callSiteBinder.bind(inputFunction), "input"));
block.append(invoke(callSiteBinder.bind(inputFunction), "input"));
return block;
}

Expand All @@ -429,28 +428,28 @@ private static void pushStackType(CompilerContext context, Block block, Type sql
}
else if (parameter == long.class) {
block.comment("%s.getLong(block, position)", sqlType.getTypeSignature())
.append(constantType(new CompilerContext(), callSiteBinder, sqlType))
.append(constantType(callSiteBinder, sqlType))
.append(getBlockByteCode)
.append(position)
.invokeInterface(Type.class, "getLong", long.class, com.facebook.presto.spi.block.Block.class, int.class);
}
else if (parameter == double.class) {
block.comment("%s.getDouble(block, position)", sqlType.getTypeSignature())
.append(constantType(new CompilerContext(), callSiteBinder, sqlType))
.append(constantType(callSiteBinder, sqlType))
.append(getBlockByteCode)
.append(position)
.invokeInterface(Type.class, "getDouble", double.class, com.facebook.presto.spi.block.Block.class, int.class);
}
else if (parameter == boolean.class) {
block.comment("%s.getBoolean(block, position)", sqlType.getTypeSignature())
.append(constantType(new CompilerContext(), callSiteBinder, sqlType))
.append(constantType(callSiteBinder, sqlType))
.append(getBlockByteCode)
.append(position)
.invokeInterface(Type.class, "getBoolean", boolean.class, com.facebook.presto.spi.block.Block.class, int.class);
}
else if (parameter == Slice.class) {
block.comment("%s.getBoolean(block, position)", sqlType.getTypeSignature())
.append(constantType(new CompilerContext(), callSiteBinder, sqlType))
.append(constantType(callSiteBinder, sqlType))
.append(getBlockByteCode)
.append(position)
.invokeInterface(Type.class, "getSlice", Slice.class, com.facebook.presto.spi.block.Block.class, int.class);
Expand Down Expand Up @@ -479,7 +478,7 @@ private static void generateAddIntermediateAsCombine(
Variable position = context.declareVariable(int.class, "position");

body.comment("scratchState = stateFactory.createSingleState();")
.append(context.getVariable("this").getField(stateFactoryField))
.append(context.getThis().getField(stateFactoryField))
.invokeInterface(AccumulatorStateFactory.class, "createSingleState", Object.class)
.checkCast(scratchState.getType())
.putVariable(scratchState);
Expand All @@ -492,15 +491,15 @@ private static void generateAddIntermediateAsCombine(

if (grouped) {
Variable groupIdsBlock = context.getVariable("groupIdsBlock");
loopBody.append(context.getVariable("this").getField(stateField).invoke("setGroupId", void.class, groupIdsBlock.invoke("getGroupId", long.class, position)));
loopBody.append(context.getThis().getField(stateField).invoke("setGroupId", void.class, groupIdsBlock.invoke("getGroupId", long.class, position)));
}

loopBody.append(context.getVariable("this").getField(stateSerializerField).invoke("deserialize", void.class, block, position, scratchState.cast(Object.class)));
loopBody.append(context.getThis().getField(stateSerializerField).invoke("deserialize", void.class, block, position, scratchState.cast(Object.class)));

loopBody.comment("combine(state, scratchState)")
.append(context.getVariable("this").getField(stateField))
.append(context.getThis().getField(stateField))
.append(scratchState)
.append(invoke(context, callSiteBinder.bind(combineFunction), "combine"));
.append(invoke(callSiteBinder.bind(combineFunction), "combine"));

body.append(generateBlockNonNullPositionForLoop(context, position, loopBody))
.ret();
Expand All @@ -510,14 +509,14 @@ private static void generateSetGroupIdFromGroupIdsBlock(CompilerContext context,
{
Variable groupIdsBlock = context.getVariable("groupIdsBlock");
Variable position = context.getVariable("position");
ByteCodeExpression state = context.getVariable("this").getField(stateField);
ByteCodeExpression state = context.getThis().getField(stateField);
block.append(state.invoke("setGroupId", void.class, groupIdsBlock.invoke("getGroupId", long.class, position)));
}

private static void generateEnsureCapacity(CompilerContext context, FieldDefinition stateField, Block block)
{
Variable groupIdsBlock = context.getVariable("groupIdsBlock");
ByteCodeExpression state = context.getVariable("this").getField(stateField);
ByteCodeExpression state = context.getThis().getField(stateField);
block.append(state.invoke("ensureCapacity", void.class, groupIdsBlock.invoke("getGroupCount", long.class)));
}

Expand Down Expand Up @@ -603,7 +602,7 @@ private static void generateGroupedEvaluateIntermediate(ClassDefinition definiti
arg("out", BlockBuilder.class));

CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = method.getThis();
Variable groupId = context.getVariable("groupId");
Variable out = context.getVariable("out");

Expand All @@ -625,7 +624,7 @@ private static void generateEvaluateIntermediate(ClassDefinition definition, Fie
arg("out", BlockBuilder.class));

CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = method.getThis();
Variable out = context.getVariable("out");
ByteCodeExpression stateSerializer = thisVariable.getField(stateSerializerField);
ByteCodeExpression state = thisVariable.getField(stateField);
Expand Down Expand Up @@ -653,7 +652,7 @@ private static void generateGroupedEvaluateFinal(

Block body = method.getBody();
CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = method.getThis();
Variable groupId = context.getVariable("groupId");
Variable out = context.getVariable("out");

Expand All @@ -669,7 +668,7 @@ private static void generateGroupedEvaluateFinal(
body.append(thisVariable.getField(confidenceField));
}
body.append(out);
body.append(invoke(context, callSiteBinder.bind(outputFunction), "output"));
body.append(invoke(callSiteBinder.bind(outputFunction), "output"));
}
else {
checkArgument(!approximate, "Approximate aggregations must specify an output function");
Expand Down Expand Up @@ -697,7 +696,7 @@ private static void generateEvaluateFinal(

Block body = method.getBody();
CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = method.getThis();
Variable out = context.getVariable("out");

ByteCodeExpression state = thisVariable.getField(stateField);
Expand All @@ -710,7 +709,7 @@ private static void generateEvaluateFinal(
body.append(thisVariable.getField(confidenceField));
}
body.append(out);
body.append(invoke(context, callSiteBinder.bind(outputFunction), "output"));
body.append(invoke(callSiteBinder.bind(outputFunction), "output"));
}
else {
checkArgument(!approximate, "Approximate aggregations must specify an output function");
Expand Down Expand Up @@ -742,7 +741,7 @@ private static void generateConstructor(

Block body = method.getBody();
CompilerContext context = method.getCompilerContext();
Variable thisVariable = context.getVariable("this");
Variable thisVariable = method.getThis();
Variable stateSerializer = context.getVariable("stateSerializer");
Variable stateFactory = context.getVariable("stateFactory");
Variable inputChannels = context.getVariable("inputChannels");
Expand Down

0 comments on commit 44ff930

Please sign in to comment.