Drop BothSignatureWriter.needGenerics
It's OK to always make JVM generic signature since it's already constructed at the end anyway
This commit is contained in:
@@ -292,7 +292,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
assert supertypes.size() == 1 : "Closure must have exactly one supertype: " + funDescriptor;
|
||||
JetType supertype = supertypes.iterator().next();
|
||||
|
||||
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true);
|
||||
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
|
||||
typeMapper.writeFormalTypeParameters(Collections.<TypeParameterDescriptor>emptyList(), sw);
|
||||
sw.writeSuperclass();
|
||||
typeMapper.mapSupertype(supertype, sw);
|
||||
|
||||
@@ -41,7 +41,10 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.Modality.ABSTRACT;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
@@ -84,7 +87,7 @@ public class CodegenUtil {
|
||||
}
|
||||
|
||||
public static JvmMethodSignature erasedInvokeSignature(FunctionDescriptor fd) {
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
boolean isExtensionFunction = fd.getReceiverParameter() != null;
|
||||
int paramCount = fd.getValueParameters().size();
|
||||
|
||||
@@ -77,7 +77,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
||||
"in " + function.getContainingFile().getVirtualFile();
|
||||
|
||||
OwnerKind kind = owner.getContextKind();
|
||||
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, true, kind);
|
||||
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind);
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL || function.getBodyExpression() != null) {
|
||||
generateMethod(function, method, functionDescriptor,
|
||||
|
||||
@@ -334,13 +334,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private JvmClassSignature signature() {
|
||||
List<String> superInterfaces;
|
||||
|
||||
LinkedHashSet<String> superInterfacesLinkedHashSet = new LinkedHashSet<String>();
|
||||
|
||||
// TODO: generics signature is not always needed
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true);
|
||||
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
|
||||
|
||||
{ // type parameters
|
||||
List<TypeParameterDescriptor> typeParameters = descriptor.getTypeConstructor().getParameters();
|
||||
@@ -360,7 +354,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
|
||||
List<String> superInterfaces;
|
||||
{ // superinterfaces
|
||||
LinkedHashSet<String> superInterfacesLinkedHashSet = new LinkedHashSet<String>();
|
||||
|
||||
superInterfacesLinkedHashSet.add(JvmAbi.JET_OBJECT.getInternalName());
|
||||
|
||||
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.asm4.signature.SignatureVisitor;
|
||||
import org.jetbrains.asm4.signature.SignatureWriter;
|
||||
import org.jetbrains.asm4.util.CheckSignatureAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
@@ -55,13 +54,9 @@ public class BothSignatureWriter {
|
||||
|
||||
private JvmMethodParameterKind currentParameterKind;
|
||||
|
||||
private final boolean needGenerics;
|
||||
|
||||
private boolean generic = false;
|
||||
|
||||
public BothSignatureWriter(Mode mode, boolean needGenerics) {
|
||||
this.needGenerics = needGenerics;
|
||||
|
||||
public BothSignatureWriter(@NotNull Mode mode) {
|
||||
this.signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter);
|
||||
}
|
||||
|
||||
@@ -99,17 +94,6 @@ public class BothSignatureWriter {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNothing() {
|
||||
signatureVisitor().visitBaseType('V');
|
||||
writeAsmType0(Type.VOID_TYPE);
|
||||
}
|
||||
|
||||
public void writeNullableNothing() {
|
||||
signatureVisitor().visitClassType("java/lang/Object");
|
||||
signatureVisitor().visitEnd();
|
||||
writeAsmType0(AsmTypeConstants.OBJECT_TYPE);
|
||||
}
|
||||
|
||||
private String makeArrayPrefix() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < jvmCurrentTypeArrayLevel; ++i) {
|
||||
@@ -268,11 +252,7 @@ public class BothSignatureWriter {
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature makeJvmMethodSignature(String name) {
|
||||
return new JvmMethodSignature(
|
||||
makeAsmMethod(name),
|
||||
needGenerics ? makeJavaGenericSignature() : null,
|
||||
kotlinParameterTypes
|
||||
);
|
||||
return new JvmMethodSignature(makeAsmMethod(name), makeJavaGenericSignature(), kotlinParameterTypes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JvmMethodSignature {
|
||||
|
||||
@NotNull
|
||||
private final Method asmMethod;
|
||||
/**
|
||||
* Null when we don't care about type parameters
|
||||
*/
|
||||
@Nullable
|
||||
private final String genericsSignature;
|
||||
@NotNull
|
||||
private final List<JvmMethodParameterSignature> kotlinParameterTypes;
|
||||
@@ -50,6 +47,7 @@ public class JvmMethodSignature {
|
||||
return asmMethod;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGenericsSignature() {
|
||||
return genericsSignature;
|
||||
}
|
||||
@@ -59,6 +57,7 @@ public class JvmMethodSignature {
|
||||
return kotlinParameterTypes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Type> getValueParameterTypes() {
|
||||
List<Type> r = new ArrayList<Type>(kotlinParameterTypes.size());
|
||||
for (JvmMethodParameterSignature p : kotlinParameterTypes) {
|
||||
|
||||
@@ -412,7 +412,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal());
|
||||
|
||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
|
||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), kind);
|
||||
Type owner;
|
||||
Type ownerForDefaultImpl;
|
||||
Type ownerForDefaultParam;
|
||||
@@ -433,7 +433,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
||||
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
||||
invokeOpcode = INVOKEVIRTUAL;
|
||||
descriptor = mapSignature("invoke", functionDescriptor, true, kind);
|
||||
descriptor = mapSignature("invoke", functionDescriptor, kind);
|
||||
calleeType = owner;
|
||||
}
|
||||
else if (functionParent instanceof PackageFragmentDescriptor) {
|
||||
@@ -498,7 +498,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
if (isInterface && superCall) {
|
||||
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
||||
descriptor = mapSignature(functionDescriptor, OwnerKind.TRAIT_IMPL);
|
||||
owner = Type.getObjectType(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
}
|
||||
thisClass = mapType(receiver.getDefaultType());
|
||||
@@ -564,32 +564,23 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, boolean needGenericSignature, @NotNull OwnerKind kind) {
|
||||
return mapSignature(mapFunctionName(f), f, needGenericSignature, kind);
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
return mapSignature(mapFunctionName(f), f, kind);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull Name functionName, @NotNull FunctionDescriptor f) {
|
||||
return mapSignature(functionName.asString(), f, false, OwnerKind.IMPLEMENTATION);
|
||||
return mapSignature(functionName.asString(), f, OwnerKind.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f) {
|
||||
return mapSignature(mapFunctionName(f), f, false, OwnerKind.IMPLEMENTATION);
|
||||
return mapSignature(mapFunctionName(f), f, OwnerKind.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JvmMethodSignature mapSignature(
|
||||
@NotNull String methodName,
|
||||
@NotNull FunctionDescriptor f,
|
||||
boolean needGenericSignature,
|
||||
@NotNull OwnerKind kind
|
||||
) {
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
needGenericSignature = false;
|
||||
}
|
||||
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, needGenericSignature);
|
||||
private JvmMethodSignature mapSignature(@NotNull String methodName, @NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor);
|
||||
|
||||
@@ -623,7 +614,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
@Nullable
|
||||
public String mapFieldSignature(@NotNull JetType backingFieldType) {
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE, true);
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE);
|
||||
mapType(backingFieldType, signatureVisitor, JetTypeMapperMode.VALUE);
|
||||
return signatureVisitor.makeJavaGenericSignature();
|
||||
}
|
||||
@@ -721,8 +712,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
// TODO: do not genClassOrObject generics if not needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
@@ -743,8 +733,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
public JvmMethodSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
assert descriptor.isVar();
|
||||
|
||||
// TODO: generics signature is not always needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
@@ -767,9 +756,9 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapConstructorSignature(@NotNull ConstructorDescriptor descriptor) {
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
// constructor type parmeters are fake
|
||||
// constructor type parameters are fake
|
||||
writeFormalTypeParameters(Collections.<TypeParameterDescriptor>emptyList(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
@@ -850,7 +839,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapScriptSignature(@NotNull ScriptDescriptor script, @NotNull List<ScriptDescriptor> importedScripts) {
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
writeFormalTypeParameters(Collections.<TypeParameterDescriptor>emptyList(), signatureWriter);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user