Consider all real functions, not only declarations in bridge codegen

There should be bridges to all of the functions present in bytecode
This commit is contained in:
Alexander Udalov
2014-04-04 16:12:04 +04:00
parent 04c237cc22
commit 478766815d
7 changed files with 34 additions and 11 deletions
@@ -26,13 +26,6 @@ import kotlin.Function1;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor;
import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.MethodContext;
@@ -53,12 +46,18 @@ import org.jetbrains.jet.lang.resolve.constants.JavaClassValue;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.utils.DFS;
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
import static org.jetbrains.jet.codegen.AsmUtil.*;
import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
@@ -69,6 +68,7 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.OLD_JET_VALUE_PARAMETER_ANNOTATION;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
public class FunctionCodegen extends ParentCodegenAwareImpl {
private final CodegenContext owner;
@@ -485,7 +485,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
new DFS.NodeHandlerWithListResult<FunctionDescriptor, Method>() {
@Override
public void afterChildren(FunctionDescriptor current) {
if (current.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
if (current.getKind().isReal()) {
result.add(typeMapper.mapSignature(current).getAsmMethod());
}
}
@@ -504,7 +504,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
throw new IllegalArgumentException("Only non-abstract functions have implementations: " + descriptor);
}
if (descriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
if (descriptor.getKind().isReal()) {
return descriptor;
}
@@ -0,0 +1,14 @@
open data class A(val value: String)
trait B {
fun component1(): Any
}
class C(value: String) : A(value), B
fun box(): String {
val c = C("OK")
if ((c : B).component1() != "OK") return "Fail 1"
if ((c : A).component1() != "OK") return "Fail 2"
return c.component1()
}
@@ -320,6 +320,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/bridges/fakeOverrideWithSeveralSuperDeclarations.kt");
}
@TestMetadata("fakeOverrideWithSynthesizedImplementation.kt")
public void testFakeOverrideWithSynthesizedImplementation() throws Exception {
doTest("compiler/testData/codegen/box/bridges/fakeOverrideWithSynthesizedImplementation.kt");
}
@TestMetadata("kt1939.kt")
public void testKt1939() throws Exception {
doTest("compiler/testData/codegen/box/bridges/kt1939.kt");
@@ -41,13 +41,14 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
;
public boolean isReal() {
return this == DECLARATION || this == DELEGATION || this == SYNTHESIZED;
return this != FAKE_OVERRIDE;
}
}
/**
* Is this a real function or function projection.
*/
@NotNull
Kind getKind();
@NotNull
@@ -170,6 +170,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
return original == this ? this : original.getOriginal();
}
@NotNull
@Override
public Kind getKind() {
return kind;
@@ -66,6 +66,7 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript
return isDefault;
}
@NotNull
@Override
public Kind getKind() {
return kind;
@@ -316,6 +316,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
return original == this ? this : original.getOriginal();
}
@NotNull
@Override
public Kind getKind() {
return kind;