fix erased parameters codegen and parsing
This commit is contained in:
@@ -232,11 +232,11 @@ public class BothSignatureWriter {
|
|||||||
writeAsmType0(asmType);
|
writeAsmType0(asmType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeFormalTypeParameter(final String name, Variance variance) {
|
public void writeFormalTypeParameter(final String name, Variance variance, boolean reified) {
|
||||||
checkTopLevel();
|
checkTopLevel();
|
||||||
|
|
||||||
signatureVisitor().visitFormalTypeParameter(name);
|
signatureVisitor().visitFormalTypeParameter(name);
|
||||||
jetSignatureWriter.visitFormalTypeParameter(name, JetSignatureUtils.translateVariance(variance));
|
jetSignatureWriter.visitFormalTypeParameter(name, JetSignatureUtils.translateVariance(variance), reified);
|
||||||
|
|
||||||
generic = true;
|
generic = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ public class FunctionCodegen {
|
|||||||
av.visitEnd();
|
av.visitEnd();
|
||||||
}
|
}
|
||||||
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||||
|
if (!typeParameterDescriptor.isReified()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true);
|
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true);
|
||||||
av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName());
|
av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName());
|
||||||
av.visitEnd();
|
av.visitEnd();
|
||||||
@@ -171,6 +174,9 @@ public class FunctionCodegen {
|
|||||||
add++;
|
add++;
|
||||||
|
|
||||||
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||||
|
if (!typeParameterDescriptor.isReified()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int slot = frameMap.enterTemp();
|
int slot = frameMap.enterTemp();
|
||||||
add++;
|
add++;
|
||||||
codegen.addTypeParameter(typeParameterDescriptor, StackValue.local(slot, JetTypeMapper.TYPE_TYPEINFO));
|
codegen.addTypeParameter(typeParameterDescriptor, StackValue.local(slot, JetTypeMapper.TYPE_TYPEINFO));
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeFormalTypeParameter(TypeParameterDescriptor typeParameterDescriptor, BothSignatureWriter signatureVisitor) {
|
private void writeFormalTypeParameter(TypeParameterDescriptor typeParameterDescriptor, BothSignatureWriter signatureVisitor) {
|
||||||
signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName(), typeParameterDescriptor.getVariance());
|
signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName(), typeParameterDescriptor.getVariance(), typeParameterDescriptor.isReified());
|
||||||
|
|
||||||
classBound:
|
classBound:
|
||||||
{
|
{
|
||||||
|
|||||||
+8
-6
@@ -375,12 +375,13 @@ public class JavaDescriptorResolver {
|
|||||||
private final DeclarationDescriptor containingDeclaration;
|
private final DeclarationDescriptor containingDeclaration;
|
||||||
private final PsiTypeParameterListOwner psiOwner;
|
private final PsiTypeParameterListOwner psiOwner;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final boolean reified;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final TypeInfoVariance variance;
|
private final TypeInfoVariance variance;
|
||||||
private final TypeVariableResolver typeVariableResolver;
|
private final TypeVariableResolver typeVariableResolver;
|
||||||
|
|
||||||
protected JetSignatureTypeParameterVisitor(DeclarationDescriptor containingDeclaration, PsiTypeParameterListOwner psiOwner,
|
protected JetSignatureTypeParameterVisitor(DeclarationDescriptor containingDeclaration, PsiTypeParameterListOwner psiOwner,
|
||||||
String name, int index, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver)
|
String name, boolean reified, int index, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver)
|
||||||
{
|
{
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@@ -389,6 +390,7 @@ public class JavaDescriptorResolver {
|
|||||||
this.containingDeclaration = containingDeclaration;
|
this.containingDeclaration = containingDeclaration;
|
||||||
this.psiOwner = psiOwner;
|
this.psiOwner = psiOwner;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.reified = reified;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.variance = variance;
|
this.variance = variance;
|
||||||
this.typeVariableResolver = typeVariableResolver;
|
this.typeVariableResolver = typeVariableResolver;
|
||||||
@@ -425,7 +427,7 @@ public class JavaDescriptorResolver {
|
|||||||
TypeParameterDescriptor typeParameter = TypeParameterDescriptor.createForFurtherModification(
|
TypeParameterDescriptor typeParameter = TypeParameterDescriptor.createForFurtherModification(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: wrong
|
Collections.<AnnotationDescriptor>emptyList(), // TODO: wrong
|
||||||
true, // TODO: wrong
|
reified,
|
||||||
JetSignatureUtils.translateVariance(variance),
|
JetSignatureUtils.translateVariance(variance),
|
||||||
name,
|
name,
|
||||||
index);
|
index);
|
||||||
@@ -462,8 +464,8 @@ public class JavaDescriptorResolver {
|
|||||||
private int formalTypeParameterIndex = 0;
|
private int formalTypeParameterIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance, boolean reified) {
|
||||||
return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, reified, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
||||||
@Override
|
@Override
|
||||||
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
r.add(typeParameterDescriptor);
|
r.add(typeParameterDescriptor);
|
||||||
@@ -1269,9 +1271,9 @@ public class JavaDescriptorResolver {
|
|||||||
private int formalTypeParameterIndex = 0;
|
private int formalTypeParameterIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance, boolean reified) {
|
||||||
|
|
||||||
return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, reified, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
||||||
@Override
|
@Override
|
||||||
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
r.add(typeParameterDescriptor);
|
r.add(typeParameterDescriptor);
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class OneTypeParameterErased<P, erased Q>(q: Q)
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
fun <erased P> funParamParam(a: Int, b: P) = 1
|
||||||
@@ -74,7 +74,7 @@ class TypeInfoParser {
|
|||||||
new JetSignatureReader(annotationValue).accept(new JetSignatureExceptionsAdapter() {
|
new JetSignatureReader(annotationValue).accept(new JetSignatureExceptionsAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance, boolean reified) {
|
||||||
|
|
||||||
// TODO: nullability
|
// TODO: nullability
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import jet.typeinfo.TypeInfoVariance;
|
|||||||
*/
|
*/
|
||||||
public class JetSignatureAdapter implements JetSignatureVisitor {
|
public class JetSignatureAdapter implements JetSignatureVisitor {
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import jet.typeinfo.TypeInfoVariance;
|
|||||||
*/
|
*/
|
||||||
public class JetSignatureExceptionsAdapter implements JetSignatureVisitor {
|
public class JetSignatureExceptionsAdapter implements JetSignatureVisitor {
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,12 @@ public class JetSignatureReader {
|
|||||||
pos = 1;
|
pos = 1;
|
||||||
do {
|
do {
|
||||||
TypeInfoVariance variance;
|
TypeInfoVariance variance;
|
||||||
|
boolean reified = true;
|
||||||
|
|
||||||
|
if (signature.substring(pos).startsWith("erased ")) {
|
||||||
|
reified = false;
|
||||||
|
pos += "erased ".length();
|
||||||
|
}
|
||||||
if (signature.substring(pos).startsWith("in ")) {
|
if (signature.substring(pos).startsWith("in ")) {
|
||||||
variance = TypeInfoVariance.IN;
|
variance = TypeInfoVariance.IN;
|
||||||
pos += "in ".length();
|
pos += "in ".length();
|
||||||
@@ -67,7 +73,7 @@ public class JetSignatureReader {
|
|||||||
if (typeParameterName.isEmpty()) {
|
if (typeParameterName.isEmpty()) {
|
||||||
throw new IllegalStateException("incorrect signature: " + signature);
|
throw new IllegalStateException("incorrect signature: " + signature);
|
||||||
}
|
}
|
||||||
JetSignatureVisitor parameterVisitor = v.visitFormalTypeParameter(typeParameterName, variance);
|
JetSignatureVisitor parameterVisitor = v.visitFormalTypeParameter(typeParameterName, variance, reified);
|
||||||
pos = end + 1;
|
pos = end + 1;
|
||||||
|
|
||||||
c = signature.charAt(pos);
|
c = signature.charAt(pos);
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ public interface JetSignatureVisitor {
|
|||||||
/**
|
/**
|
||||||
* Visits a formal type parameter.
|
* Visits a formal type parameter.
|
||||||
*
|
*
|
||||||
|
* TODO should not store reified flag in signature
|
||||||
|
*
|
||||||
* @param name the name of the formal parameter.
|
* @param name the name of the formal parameter.
|
||||||
*/
|
*/
|
||||||
JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance);
|
JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified);
|
||||||
|
|
||||||
void visitFormalTypeParameterEnd();
|
void visitFormalTypeParameterEnd();
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,14 @@ public class JetSignatureWriter implements JetSignatureVisitor {
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, TypeInfoVariance variance) {
|
public JetSignatureVisitor visitFormalTypeParameter(final String name, TypeInfoVariance variance, boolean reified) {
|
||||||
if (!hasFormals) {
|
if (!hasFormals) {
|
||||||
hasFormals = true;
|
hasFormals = true;
|
||||||
buf.append('<');
|
buf.append('<');
|
||||||
}
|
}
|
||||||
|
if (!reified) {
|
||||||
|
buf.append("erased ");
|
||||||
|
}
|
||||||
switch (variance) {
|
switch (variance) {
|
||||||
case OUT:
|
case OUT:
|
||||||
buf.append("out ");
|
buf.append("out ");
|
||||||
|
|||||||
Reference in New Issue
Block a user