Don't pass useless closure parameter to JetTypeMapper

It should always be recorded in BindingContext
This commit is contained in:
Alexander Udalov
2013-12-23 20:44:56 +04:00
parent a84b984417
commit 8e753e6efd
3 changed files with 10 additions and 19 deletions
@@ -1328,7 +1328,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ConstructorDescriptor constructorDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, expression.getObjectDeclaration()); ConstructorDescriptor constructorDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, expression.getObjectDeclaration());
assert constructorDescriptor != null; assert constructorDescriptor != null;
CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor, closure); CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor);
Type type = bindingContext.get(ASM_TYPE, constructorDescriptor.getContainingDeclaration()); Type type = bindingContext.get(ASM_TYPE, constructorDescriptor.getContainingDeclaration());
assert type != null; assert type != null;
@@ -1137,7 +1137,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
assert constructorDescriptor != null; assert constructorDescriptor != null;
final JvmMethodSignature constructorSignature = typeMapper.mapConstructorSignature(constructorDescriptor, closure); final JvmMethodSignature constructorSignature = typeMapper.mapConstructorSignature(constructorDescriptor);
functionCodegen.generateMethod(null, constructorSignature, constructorDescriptor, constructorContext, functionCodegen.generateMethod(null, constructorSignature, constructorDescriptor, constructorContext,
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) { new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
@@ -1157,7 +1157,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
functionCodegen.generateDefaultIfNeeded(constructorContext, constructorSignature, constructorDescriptor, functionCodegen.generateDefaultIfNeeded(constructorContext, constructorSignature, constructorDescriptor,
OwnerKind.IMPLEMENTATION, DefaultParameterValueLoader.DEFAULT); OwnerKind.IMPLEMENTATION, DefaultParameterValueLoader.DEFAULT);
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, closure); CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v); FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v);
if (isClassObject(descriptor)) { if (isClassObject(descriptor)) {
@@ -1537,7 +1537,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
iv.load(2, Type.INT_TYPE); iv.load(2, Type.INT_TYPE);
} }
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor, context.closure); CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor);
ResolvedCall<? extends CallableDescriptor> resolvedCall = ResolvedCall<? extends CallableDescriptor> resolvedCall =
bindingContext.get(BindingContext.RESOLVED_CALL, ((JetCallElement) superCall).getCalleeExpression()); bindingContext.get(BindingContext.RESOLVED_CALL, ((JetCallElement) superCall).getCalleeExpression());
@@ -1546,12 +1546,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
//noinspection SuspiciousMethodCalls //noinspection SuspiciousMethodCalls
CalculatedClosure closureForSuper = bindingContext.get(CLOSURE, superConstructor.getContainingDeclaration()); CalculatedClosure closureForSuper = bindingContext.get(CLOSURE, superConstructor.getContainingDeclaration());
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor, closureForSuper);
if (closureForSuper != null && closureForSuper.getCaptureThis() != null) { if (closureForSuper != null && closureForSuper.getCaptureThis() != null) {
iv.load(((ConstructorFrameMap)codegen.myFrameMap).getOuterThisIndex(), OBJECT_TYPE); iv.load(((ConstructorFrameMap) codegen.myFrameMap).getOuterThisIndex(), OBJECT_TYPE);
} }
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor);
if (isAnonymousObject(descriptor) && superCall instanceof JetDelegatorToSuperCall) { if (isAnonymousObject(descriptor) && superCall instanceof JetDelegatorToSuperCall) {
int nextVar = findFirstSuperArgument(method); int nextVar = findFirstSuperArgument(method);
for (Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) { for (Type t : superCallable.getSignature().getAsmMethod().getArgumentTypes()) {
@@ -755,12 +755,6 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull @NotNull
public JvmMethodSignature mapConstructorSignature(@NotNull ConstructorDescriptor descriptor) { public JvmMethodSignature mapConstructorSignature(@NotNull ConstructorDescriptor descriptor) {
return mapConstructorSignature(descriptor, bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration()));
}
@NotNull
public JvmMethodSignature mapConstructorSignature(@NotNull ConstructorDescriptor descriptor, @Nullable CalculatedClosure closure) {
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true); BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
// constructor type parmeters are fake // constructor type parmeters are fake
@@ -768,6 +762,8 @@ public class JetTypeMapper extends BindingTraceAware {
signatureWriter.writeParametersStart(); signatureWriter.writeParametersStart();
CalculatedClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration(); ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure); ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure);
if (captureThis != null) { if (captureThis != null) {
@@ -867,12 +863,7 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull @NotNull
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor) { public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor) {
return mapToCallableMethod(descriptor, bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration())); JvmMethodSignature method = mapConstructorSignature(descriptor);
}
@NotNull
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor, @Nullable CalculatedClosure closure) {
JvmMethodSignature method = mapConstructorSignature(descriptor, closure);
ClassDescriptor container = descriptor.getContainingDeclaration(); ClassDescriptor container = descriptor.getContainingDeclaration();
Type owner = mapClass(container); Type owner = mapClass(container);
if (owner.getSort() != Type.OBJECT) { if (owner.getSort() != Type.OBJECT) {