From 7f456ede1a1a7dd91399d82eb24b851b757a52b1 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Mon, 6 Aug 2012 12:36:32 +0300 Subject: [PATCH 01/72] KT-2149 binary and text compilation in one pass --- .../jet/codegen/ClassBuilderFactories.java | 71 +++++++++++++++---- .../jetbrains/jet/codegen/ArrayGenTest.java | 2 +- .../jet/codegen/CodegenTestCase.java | 13 +++- .../jet/codegen/MultiFileGenTest.java | 2 +- .../jet/codegen/PrimitiveTypesTest.java | 2 +- 5 files changed, 72 insertions(+), 18 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBuilderFactories.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBuilderFactories.java index 679f1ecbcf4..9345f38177d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBuilderFactories.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBuilderFactories.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; +import org.jetbrains.asm4.ClassVisitor; import org.jetbrains.asm4.ClassWriter; import org.jetbrains.asm4.util.TraceClassVisitor; @@ -28,6 +29,34 @@ import java.io.StringWriter; */ public class ClassBuilderFactories { + public static ClassBuilderFactory TEST = new ClassBuilderFactory() { + @NotNull + @Override + public ClassBuilderMode getClassBuilderMode() { + return ClassBuilderMode.FULL; + } + + @Override + public ClassBuilder newClassBuilder() { + return new TraceBuilder(new BinaryClassWriter()); + } + + @Override + public String asText(ClassBuilder builder) { + TraceClassVisitor visitor = (TraceClassVisitor) builder.getVisitor(); + + StringWriter writer = new StringWriter(); + visitor.p.print(new PrintWriter(writer)); + + return writer.toString(); + } + + @Override + public byte[] asBytes(ClassBuilder builder) { + return ((TraceBuilder) builder).binary.toByteArray(); + } + }; + public static ClassBuilderFactory TEXT = new ClassBuilderFactory() { @NotNull @Override @@ -56,6 +85,9 @@ public class ClassBuilderFactories { } }; + private ClassBuilderFactories() { + } + public static ClassBuilderFactory binaries(final boolean stubs) { return new ClassBuilderFactory() { @NotNull @@ -66,18 +98,7 @@ public class ClassBuilderFactories { @Override public ClassBuilder newClassBuilder() { - return new ClassBuilder.Concrete(new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS){ - @Override - protected String getCommonSuperClass(String type1, String type2) { - try { - return super.getCommonSuperClass(type1, type2); - } - catch (Throwable t) { - // @todo we might need at some point do more sofisticated handling - return "java/lang/Object"; - } - } - }); + return new ClassBuilder.Concrete(new BinaryClassWriter()); } @Override @@ -92,4 +113,30 @@ public class ClassBuilderFactories { } }; } + + private static class BinaryClassWriter extends ClassWriter { + public BinaryClassWriter() { + super(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + } + + @Override + protected String getCommonSuperClass(String type1, String type2) { + try { + return super.getCommonSuperClass(type1, type2); + } + catch (Throwable t) { + // @todo we might need at some point do more sofisticated handling + return "java/lang/Object"; + } + } + } + + private static class TraceBuilder extends ClassBuilder.Concrete { + public final BinaryClassWriter binary; + + public TraceBuilder(BinaryClassWriter binary) { + super(new TraceClassVisitor(binary, new PrintWriter(new StringWriter()))); + this.binary = binary; + } + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java index 7a45b9573fe..0cb7b27e63a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java @@ -78,7 +78,7 @@ public class ArrayGenTest extends CodegenTestCase { public void testIntGenerics () throws Exception { loadText("class L(var a : T) {} fun foo() = L(5).a"); - System.out.println(generateToText()); + //System.out.println(generateToText()); Method foo = generateFunction(); Object invoke = foo.invoke(null); System.out.println(invoke.getClass()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index bfe7cf776c1..c88277058d1 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -59,6 +59,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { protected CodegenTestFiles myFiles; protected Object scriptInstance; + private GenerationState alreadyGenerated; protected void createEnvironmentWithMockJdkAndIdeaAnnotations() { if (myEnvironment != null) { @@ -102,6 +103,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { myFiles = null; myEnvironment = null; scriptInstance = null; + alreadyGenerated = null; super.tearDown(); } @@ -255,10 +257,15 @@ public abstract class CodegenTestCase extends UsefulTestCase { } protected String generateToText() { - return generateCommon(ClassBuilderFactories.TEXT).createText(); + if(alreadyGenerated == null) + alreadyGenerated = generateCommon(ClassBuilderFactories.TEST); + return alreadyGenerated.createText(); } private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) { + if(alreadyGenerated != null) + return alreadyGenerated; + final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors( myEnvironment.getProject(), myFiles.getPsiFiles(), @@ -269,6 +276,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext()); GenerationState state = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles()); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); + alreadyGenerated = state; return state; } @@ -313,8 +321,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { private GenerationState generateClassesInFileGetState() { GenerationState generationState; try { - ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false); - generationState = generateCommon(classBuilderFactory); + generationState = generateCommon(ClassBuilderFactories.TEST); if (DxChecker.RUN_DX_CHECKER) { DxChecker.check(generationState.getFactory()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/MultiFileGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/MultiFileGenTest.java index 23a9fd9c6c2..23400a5b171 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/MultiFileGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/MultiFileGenTest.java @@ -27,7 +27,7 @@ public class MultiFileGenTest extends CodegenTestCase { public void testSimple() { blackBoxMultiFile("/multi/simple/box.kt", "/multi/simple/ok.kt"); - System.out.println(generateToText()); + //System.out.println(generateToText()); } public void testInternalVisibility() { diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index f20d4e1406f..c4f451e8a9c 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -370,7 +370,7 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt756 () { blackBoxFile("regressions/kt756.jet"); - System.out.println(generateToText()); + //System.out.println(generateToText()); } public void testKt757 () { From 04b2477784f234e8bc8a6380d42b86322c42150e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 3 Aug 2012 22:55:29 +0400 Subject: [PATCH 02/72] KT-2270 VerifyError when default value of constructor parameter is previous parameter #KT-2270 Fixed --- .../jet/codegen/FunctionCodegen.java | 27 ++++++++++--------- .../codegen/functions/defaultargs6.kt | 7 +++++ .../codegen/functions/defaultargs7.kt | 5 ++++ .../testData/codegen/regressions/kt2270.kt | 6 +++++ .../jet/codegen/FunctionGenTest.java | 14 +++++++++- 5 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 compiler/testData/codegen/functions/defaultargs6.kt create mode 100644 compiler/testData/codegen/functions/defaultargs7.kt create mode 100644 compiler/testData/codegen/regressions/kt2270.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index cdfe31bb26a..0920d789efb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -444,6 +444,10 @@ public class FunctionCodegen { FrameMap frameMap = owner.prepareFrame(state.getInjector().getJetTypeMapper()); + if (kind instanceof OwnerKind.StaticDelegateKind) { + frameMap.leaveTemp(); + } + ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, jvmSignature.getReturnType(), owner, state); int var = 0; @@ -452,15 +456,13 @@ public class FunctionCodegen { } Type receiverType; - if (receiverParameter.exists()) { + if (hasReceiver) { receiverType = state.getInjector().getJetTypeMapper().mapType(receiverParameter.getType(), MapTypeMode.VALUE); + var += receiverType.getSize(); } else { receiverType = Type.DOUBLE_TYPE; } - if (hasReceiver) { - var += receiverType.getSize(); - } Type[] argTypes = jvmSignature.getArgumentTypes(); List paramDescrs = functionDescriptor.getValueParameters(); @@ -484,12 +486,15 @@ public class FunctionCodegen { int extra = hasReceiver ? 1 : 0; - Type[] argumentTypes = jvmSignature.getArgumentTypes(); for (int index = 0; index < paramDescrs.size(); index++) { ValueParameterDescriptor parameterDescriptor = paramDescrs.get(index); - Type t = argumentTypes[extra + index]; - Label endArg = null; + Type t = argTypes[extra + index]; + + if (frameMap.getIndex(parameterDescriptor) < 0) { + frameMap.enter(parameterDescriptor, t.getSize()); + } + if (parameterDescriptor.declaresDefaultValue()) { iv.load(maskIndex, Type.INT_TYPE); iv.iconst(1 << index); @@ -501,18 +506,14 @@ public class FunctionCodegen { assert jetParameter != null; codegen.gen(jetParameter.getDefaultValue(), t); - endArg = new Label(); - iv.goTo(endArg); + int ind = frameMap.getIndex(parameterDescriptor); + iv.store(ind, t); iv.mark(loadArg); } iv.load(var, t); var += t.getSize(); - - if (parameterDescriptor.declaresDefaultValue()) { - iv.mark(endArg); - } } if (!isStatic) { diff --git a/compiler/testData/codegen/functions/defaultargs6.kt b/compiler/testData/codegen/functions/defaultargs6.kt new file mode 100644 index 00000000000..21a9faeae3f --- /dev/null +++ b/compiler/testData/codegen/functions/defaultargs6.kt @@ -0,0 +1,7 @@ +trait A { + fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z +} + +class B : A {} + +fun box() = if (B().foo(1) == 42) "OK" else "Fail" diff --git a/compiler/testData/codegen/functions/defaultargs7.kt b/compiler/testData/codegen/functions/defaultargs7.kt new file mode 100644 index 00000000000..107929fad00 --- /dev/null +++ b/compiler/testData/codegen/functions/defaultargs7.kt @@ -0,0 +1,5 @@ +class A(val expected: Int) { + fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z == expected +} + +fun box() = if (A(42).foo(1)) "OK" else "Fail" diff --git a/compiler/testData/codegen/regressions/kt2270.kt b/compiler/testData/codegen/regressions/kt2270.kt new file mode 100644 index 00000000000..27d631e3d2f --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2270.kt @@ -0,0 +1,6 @@ +class A( + val i : Int, + val j : Int = i +) + +fun box() = if (A(1).j == 1) "OK" else "fail" diff --git a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java index 578dc674f0a..7b1abba69f2 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java @@ -68,6 +68,14 @@ public class FunctionGenTest extends CodegenTestCase { // System.out.println(generateToText()); } + public void testDefaultArgs6() { + blackBoxFile("functions/defaultargs6.kt"); + } + + public void testDefaultArgs7() { + blackBoxFile("functions/defaultargs7.kt"); + } + public void testNoThisNoClosure() throws Exception { blackBoxFile("functions/nothisnoclosure.jet"); // System.out.println(generateToText()); @@ -121,7 +129,7 @@ public class FunctionGenTest extends CodegenTestCase { blackBoxFile("functions/invoke.kt"); } - public void test2481() { + public void testKt2481() { blackBoxFile("regressions/kt2481.kt"); } @@ -137,6 +145,10 @@ public class FunctionGenTest extends CodegenTestCase { blackBoxFile("regressions/kt2271.kt"); } + public void testKt2270() { + blackBoxFile("regressions/kt2270.kt"); + } + public static class WithJavaFunctionGenTest extends CodegenTestCase { private void blackBoxFileWithJava(@NotNull String ktFile) throws Exception { File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes"); From 492d4da56d5aacbc7a8c9a7006151ec4b69ce725 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 3 Aug 2012 17:23:00 +0400 Subject: [PATCH 03/72] added variance handling to constraint system --- .../calls/inference/ConstraintSystemImpl.java | 101 +++++++++++++++++- .../calls/inference/TypeConstraintsImpl.java | 18 +--- .../tests/inference/dependantOnVariance.kt | 68 ++++++++++++ .../inference/dependantOnVarianceNullable.kt | 14 +++ .../checkers/JetDiagnosticsTestGenerated.java | 10 ++ 5 files changed, 189 insertions(+), 22 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt create mode 100644 compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index 5df320ed699..4a55b396da9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -30,6 +30,9 @@ import org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.Constr import java.util.*; +import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.ConstraintKind.*; +import static org.jetbrains.jet.lang.types.Variance.*; + /** * @author svtk */ @@ -137,12 +140,12 @@ public class ConstraintSystemImpl implements ConstraintSystem { @Override public void addSubtypingConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition) { - addConstraint(ConstraintKind.SUB_TYPE, subjectType, constrainingType, constraintPosition); + addConstraint(SUB_TYPE, subjectType, constrainingType, constraintPosition); } @Override public void addSupertypeConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition) { - addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition); + addConstraint(SUPER_TYPE, subjectType, constrainingType, constraintPosition); } private void addConstraint(@NotNull ConstraintKind constraintKind, @@ -210,12 +213,100 @@ public class ConstraintSystemImpl implements ConstraintSystem { List constrainingArguments = constrainingType.getArguments(); List parameters = typeConstructor.getParameters(); for (int i = 0; i < subjectArguments.size(); i++) { - //todo constrainingArguments.get(i).getType() -> type projections - addConstraint(ConstraintKind.fromVariance(parameters.get(i).getVariance()), subjectArguments.get(i).getType(), - constrainingArguments.get(i).getType(), constraintPosition); + Variance typeParameterVariance = parameters.get(i).getVariance(); + TypeProjection subjectArgument = subjectArguments.get(i); + TypeProjection constrainingArgument = constrainingArguments.get(i); + + ConstraintKind typeParameterConstraintKind = getTypeParameterConstraintKind(typeParameterVariance, + subjectArgument, constrainingArgument, constraintKind); + + addConstraint(typeParameterConstraintKind, subjectArgument.getType(), constrainingArgument.getType(), constraintPosition); } } + /** + * Determines what constraint (supertype, subtype or equal) should be generated for type parameter {@code T} in a constraint like (in this example subtype one):
+ * {@code MyClass <: MyClass}, where {@code MyClass} is declared.
+ * + * The parameters description is given according to the example above. + * @param typeParameterVariance declared variance of T + * @param subjectTypeProjection {@code in/out/- A} + * @param constrainingTypeProjection {@code in/out/- B} + * @param upperConstraintKind kind of the constraint {@code MyClass<...A> <: MyClass<...B>} (subtype in this example). + * @return kind of constraint to be generated: {@code A <: B} (subtype), {@code A >: B} (supertype) or {@code A = B} (equal). + */ + @NotNull + private static ConstraintKind getTypeParameterConstraintKind( + @NotNull Variance typeParameterVariance, + @NotNull TypeProjection subjectTypeProjection, + @NotNull TypeProjection constrainingTypeProjection, + @NotNull ConstraintKind upperConstraintKind + ) { + // If variance of type parameter is non-trivial, it should be taken into consideration to infer result constraint type. + // Otherwise when type parameter declared as INVARIANT, there might be non-trivial use-site variance of a supertype. + // + // Example: Let class MyClass is declared. + // + // If super type has 'out' projection: + // MyClass <: MyClass, + // then constraint A <: B can be generated. + // + // If super type has 'in' projection: + // MyClass <: MyClass, + // then constraint A >: B can be generated. + // + // Otherwise constraint A = B should be generated. + + Variance varianceForTypeParameter; + if (typeParameterVariance != INVARIANT) { + varianceForTypeParameter = typeParameterVariance; + } + else if (upperConstraintKind == SUB_TYPE) { + varianceForTypeParameter = constrainingTypeProjection.getProjectionKind(); + } + else if (upperConstraintKind == SUPER_TYPE) { + varianceForTypeParameter = subjectTypeProjection.getProjectionKind(); + } + else { + varianceForTypeParameter = INVARIANT; + } + + return getTypeParameterConstraintKind(varianceForTypeParameter, upperConstraintKind); + } + + /** + * Let class {@code MyClass} is declared.

+ * + * If upperConstraintKind is SUB_TYPE: + * {@code MyClass <: MyClass},
+ * then constraints {@code A = D, B <: E, C >: F} are generated.

+ * + * If upperConstraintKind is SUPER_TYPE: + * {@code MyClass >: MyClass},
+ * then constraints {@code A = D, B >: E, C <: F} are generated.

+ * + * If upperConstraintKind is EQUAL: + * {@code MyClass = MyClass},
+ * then equality constraints {@code A = D, B = E, C = F} are generated.

+ * + * Method getTypeParameterConstraintKind gets upperConstraintKind and variance of type parameter + * (INVARIANT for T, OUT_VARIANCE for R in example above) and returns kind of constraint for corresponding type parameter. + */ + @NotNull + private static ConstraintKind getTypeParameterConstraintKind( + @NotNull Variance typeParameterVariance, + @NotNull ConstraintKind upperConstraintKind + ) { + if (upperConstraintKind == EQUAL || typeParameterVariance == INVARIANT) { + return EQUAL; + } + if ((upperConstraintKind == SUPER_TYPE && typeParameterVariance == OUT_VARIANCE) || + (upperConstraintKind == SUB_TYPE && typeParameterVariance == IN_VARIANCE)) { + return SUPER_TYPE; + } + return SUB_TYPE; + } + @NotNull @Override public Set getTypeVariables() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java index ac4aeda95b4..4b0ad02b8cf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java @@ -93,22 +93,6 @@ public class TypeConstraintsImpl implements TypeConstraints { } public static enum ConstraintKind { - SUB_TYPE, SUPER_TYPE, EQUAL; - - @NotNull - static ConstraintKind fromVariance(@NotNull Variance variance) { - ConstraintKind constraintKind = null; - switch (variance) { - case INVARIANT: - constraintKind = EQUAL; - break; - case OUT_VARIANCE: - constraintKind = SUPER_TYPE; - break; - case IN_VARIANCE: - constraintKind = SUB_TYPE; - } - return constraintKind; - } + SUB_TYPE, SUPER_TYPE, EQUAL } } diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt new file mode 100644 index 00000000000..21db1a85465 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt @@ -0,0 +1,68 @@ +package a + +class MyList(t: T) {} + +fun getMyList(t: T) : MyList< T> = MyList(t) +fun getMyListToWriteTo(t: T) : MyList< in T> = MyList(t) +fun getMyListToReadFrom(t: T) : MyList = MyList(t) + +fun useMyList (l: MyList< T>, t: T) {} +fun writeToMyList (l: MyList< in T>, t: T) {} +fun readFromMyList(l: MyList, t: T) {} + +fun test1(int: Int, any: Any) { + val a0 : MyList = getMyList(int) + + val a1 : MyList = getMyList(any) + + val a2 : MyList = getMyList(int) + + val a3 : MyList = getMyListToReadFrom(int) + + val a4 : MyList = getMyList(any) + + val a5 : MyList = getMyListToWriteTo(any) + + + val a6 : MyList = getMyList(int) + val a7 : MyList = getMyList(int) + + val a8 : MyList = getMyListToReadFrom(int) + val a9 : MyList = getMyListToReadFrom(int) + + val a10 : MyList = getMyList(any) + val a11 : MyList = getMyList(any) + + val a12 : MyList = getMyListToWriteTo(any) + val a13 : MyList = getMyListToWriteTo(any) + + useMyList(getMyList(int), int) + useMyList(getMyList(any), int) + useMyList(getMyList(int), any) + + readFromMyList(getMyList(int), any) + readFromMyList(getMyList(any), int) + readFromMyList(getMyList(any), int) + + readFromMyList(getMyListToReadFrom(any), int) + readFromMyList(getMyListToReadFrom(any), int) + + readFromMyList(getMyListToReadFrom(int), any) + + + writeToMyList(getMyList(any), int) + writeToMyList(getMyList(int), any) + writeToMyList(getMyList(int), any) + writeToMyList(getMyList(int), any) + + writeToMyList(getMyListToWriteTo(any), int) + writeToMyList(getMyListToWriteTo(int), any) + + readFromMyList(getMyListToWriteTo(any), any) + + writeToMyList(getMyListToReadFrom(any), any) + + use(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) +} + +fun use(vararg a: Any) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt new file mode 100644 index 00000000000..cbdd402fc91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt @@ -0,0 +1,14 @@ +package b +//+JDK + +import java.util.* +import java.util.Collections.* + +fun foo(list: List) : String { + val w : String = max(list, comparator {o1, o2 -> 1 + })!! + return w +} + +//from library +fun comparator(fn: (T,T) -> Int): Comparator {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 6f8442680ff..279fa0fd393 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1269,6 +1269,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/dependOnExpectedType.kt"); } + @TestMetadata("dependantOnVariance.kt") + public void testDependantOnVariance() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt"); + } + + @TestMetadata("dependantOnVarianceNullable.kt") + public void testDependantOnVarianceNullable() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt"); + } + @TestMetadata("hasErrorInConstrainingTypes.kt") public void testHasErrorInConstrainingTypes() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.kt"); From 036ce3c2e13aaab397df0c4046f5f30ac3d71e43 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 3 Aug 2012 17:51:05 +0400 Subject: [PATCH 04/72] KT-2514 Type inference fails when using extension function literal (check for bounds when inference is not complete added) #KT-2514 fixed --- .../jet/lang/resolve/calls/CallResolver.java | 49 +++++++++++-------- .../lang/resolve/calls/ResolutionStatus.java | 2 +- .../tests/inference/regressions/kt2514.kt | 16 ++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 ++ 4 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index fa6e828d16f..ae22f2db0b3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -305,13 +305,13 @@ public class CallResolver { private OverloadResolutionResults completeTypeInferenceDependentOnExpectedType( @NotNull BasicResolutionContext context, - @NotNull OverloadResolutionResults results, + @NotNull OverloadResolutionResults resultsWithIncompleteTypeInference, @NotNull TracingStrategy tracing ) { - if (results.getResultCode() != OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) return results; + if (resultsWithIncompleteTypeInference.getResultCode() != OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) return resultsWithIncompleteTypeInference; Set> successful = Sets.newLinkedHashSet(); Set> failed = Sets.newLinkedHashSet(); - for (ResolvedCall call : results.getResultingCalls()) { + for (ResolvedCall call : resultsWithIncompleteTypeInference.getResultingCalls()) { if (!(call instanceof ResolvedCallImpl)) continue; ResolvedCallImpl resolvedCall = (ResolvedCallImpl) call; if (!resolvedCall.hasUnknownTypeParameters()) { @@ -325,16 +325,20 @@ public class CallResolver { } completeTypeInferenceDependentOnExpectedTypeForCall(resolvedCall, context, tracing, successful, failed); } - if (results.getResultingCalls().size() > 1) { + if (resultsWithIncompleteTypeInference.getResultingCalls().size() > 1) { for (ResolvedCallWithTrace call : successful) { if (call instanceof ResolvedCallImpl) { - ((ResolvedCallImpl)call).addStatus(ResolutionStatus.OTHER_ERROR); + ((ResolvedCallImpl)call).addStatus(ResolutionStatus.TYPE_INFERENCE_ERROR); failed.add(call); } } successful.clear(); } - return computeResultAndReportErrors(context.trace, tracing, successful, failed); + OverloadResolutionResultsImpl results = computeResultAndReportErrors(context.trace, tracing, successful, failed); + if (!results.isSingleResult()) { + checkTypesWithNoCallee(context); + } + return results; } private void completeTypeInferenceDependentOnExpectedTypeForCall(ResolvedCallImpl resolvedCall, @@ -381,9 +385,9 @@ public class CallResolver { if (constraintSystemWithoutExpectedTypeConstraint.isSuccessful()) { resolvedCall.setResultingSubstitutor(constraintSystemWithoutExpectedTypeConstraint.getResultingSubstitutor()); } - List argumentTypes = checkValueArgumentTypes(context, resolvedCall, context.trace).argumentTypes; + List argumentTypes = checkValueArgumentTypes(context, resolvedCall, resolvedCall.getTrace()).argumentTypes; JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null; - tracing.typeInferenceFailed(context.trace, + tracing.typeInferenceFailed(resolvedCall.getTrace(), InferenceErrorData .create(descriptor, constraintSystem, argumentTypes, receiverType, context.expectedType), constraintSystemWithoutExpectedTypeConstraint); @@ -394,9 +398,9 @@ public class CallResolver { resolvedCall.setResultingSubstitutor(constraintSystem.getResultingSubstitutor()); // Here we type check the arguments with inferred types expected - checkValueArgumentTypes(context, resolvedCall, context.trace); + checkValueArgumentTypes(context, resolvedCall, resolvedCall.getTrace()); - checkBounds(resolvedCall, constraintSystem, context.trace, tracing); + checkBounds(resolvedCall, constraintSystem, resolvedCall.getTrace(), tracing); resolvedCall.setHasUnknownTypeParameters(false); if (resolvedCall.getStatus().isSuccess() || resolvedCall.getStatus() == ResolutionStatus.UNKNOWN_STATUS) { resolvedCall.addStatus(ResolutionStatus.SUCCESS); @@ -768,20 +772,25 @@ public class CallResolver { // Solution - if (!constraintsSystem.hasContradiction()) { + boolean hasContradiction = constraintsSystem.hasContradiction(); + boolean boundsAreSatisfied = ConstraintsUtil.checkBoundsAreSatisfied(constraintsSystem); + if (!hasContradiction && boundsAreSatisfied) { candidateCall.setHasUnknownTypeParameters(true); return SUCCESS; } - else { - ValueArgumentsCheckingResult checkingResult = checkAllValueArguments(context); - ResolutionStatus argumentsStatus = checkingResult.status; - List argumentTypes = checkingResult.argumentTypes; - JetType receiverType = candidateCall.getReceiverArgument().exists() ? candidateCall.getReceiverArgument().getType() : null; - context.tracing.typeInferenceFailed(context.trace, - InferenceErrorData.create(candidate, constraintSystemWithRightTypeParameters, argumentTypes, receiverType, context.expectedType), - constraintSystemWithRightTypeParameters); - return TYPE_INFERENCE_ERROR.combine(argumentsStatus); + ValueArgumentsCheckingResult checkingResult = checkAllValueArguments(context); + ResolutionStatus argumentsStatus = checkingResult.status; + List argumentTypes = checkingResult.argumentTypes; + JetType receiverType = candidateCall.getReceiverArgument().exists() ? candidateCall.getReceiverArgument().getType() : null; + InferenceErrorData inferenceErrorData = InferenceErrorData + .create(candidate, constraintSystemWithRightTypeParameters, argumentTypes, receiverType, context.expectedType); + if (hasContradiction) { + context.tracing.typeInferenceFailed(candidateCall.getTrace(), inferenceErrorData, constraintSystemWithRightTypeParameters); } + else { + context.tracing.upperBoundViolated(candidateCall.getTrace(), inferenceErrorData); + } + return TYPE_INFERENCE_ERROR.combine(argumentsStatus); } private boolean addConstraintForValueArgument(ValueArgument valueArgument, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionStatus.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionStatus.java index 060299446ea..7def2ca8beb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionStatus.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolutionStatus.java @@ -32,8 +32,8 @@ public enum ResolutionStatus { @SuppressWarnings("unchecked") public static final EnumSet[] SEVERITY_LEVELS = new EnumSet[] { EnumSet.of(UNSAFE_CALL_ERROR), // weakest - EnumSet.of(OTHER_ERROR), EnumSet.of(TYPE_INFERENCE_ERROR), + EnumSet.of(OTHER_ERROR), EnumSet.of(STRONG_ERROR), // most severe }; diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt new file mode 100644 index 00000000000..09b136ad5e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt @@ -0,0 +1,16 @@ +//KT-2514 Type inference fails when using extension function literal +package kt2514 + +//+JDK +import java.io.Closeable + +fun Thread.use(block: Thread.() -> T): T = block() + +fun T.use(block: (T)-> R) : R = block(this) + +fun main(args: Array) { + Thread().use { } // compilation error: Type inference failed + Thread().use { 5 + 5 } // compilation error: Type inference failed + Thread().use { } // compiles okay + Thread().use { 5 + 5 } // compiles okay +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 279fa0fd393..ab021b6176a 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1375,6 +1375,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt"); } + @TestMetadata("kt2514.kt") + public void testKt2514() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt"); + } + @TestMetadata("kt702.kt") public void testKt702() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt"); From 792cc63197375b472a845adb6f676d6074caf8c6 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 3 Aug 2012 17:52:05 +0400 Subject: [PATCH 05/72] small refactoring --- .../rendering/TabledDescriptorRenderer.java | 37 ------------------- .../calls/inference/ConstraintsUtil.java | 26 +++++-------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/TabledDescriptorRenderer.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/TabledDescriptorRenderer.java index 65f82c9d199..44a0c395d78 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/TabledDescriptorRenderer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/TabledDescriptorRenderer.java @@ -141,43 +141,6 @@ public class TabledDescriptorRenderer { return new TableRenderer(); } - - //protected final List previousTables = Lists.newArrayList(); - //private TextRow currentFirstText; - //private List currentRows; - // - //public TabledDescriptorRenderer newElement() { - // previousTables.add(new TableRenderer(currentFirstText, currentRows)); - // currentFirstText = null; - // currentRows = Lists.newArrayList(); - // return this; - //} - // - //public TabledDescriptorRenderer text(String text) { - // if (currentRows.isEmpty()) { - // currentFirstText = new TextRow(text); - // return this; - // } - // currentRows.add(new TextRow(text)); - // return this; - //} - // - //public TabledDescriptorRenderer text(String text, Object... args) { - // return text(String.format(text, args)); - //} - - - - - //private TabledDescriptorRenderer(@Nullable TextRow firstText, @NotNull List rows) { - // this.currentFirstText = firstText; - // this.currentRows = rows; - //} - // - //protected TabledDescriptorRenderer() { - // this(null, Lists.newArrayList()); - //} - @Override public String toString() { StringBuilder result = new StringBuilder(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java index 3422aeda22e..3198f66a261 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java @@ -39,28 +39,28 @@ public class ConstraintsUtil { values.addAll(typeConstraints.getExactBounds()); if (!typeConstraints.getLowerBounds().isEmpty()) { JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertype(typeConstraints.getLowerBounds()); - if (values.isEmpty()) { - values.add(superTypeOfLowerBounds); - } for (JetType value : values) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(superTypeOfLowerBounds, value)) { values.add(superTypeOfLowerBounds); break; } } + if (values.isEmpty()) { + values.add(superTypeOfLowerBounds); + } } if (!typeConstraints.getUpperBounds().isEmpty()) { //todo subTypeOfUpperBounds JetType subTypeOfUpperBounds = typeConstraints.getUpperBounds().iterator().next(); //todo - if (values.isEmpty()) { - values.add(subTypeOfUpperBounds); - } for (JetType value : values) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(value, subTypeOfUpperBounds)) { values.add(subTypeOfUpperBounds); break; } } + if (values.isEmpty()) { + values.add(subTypeOfUpperBounds); + } } } return values; @@ -141,10 +141,10 @@ public class ConstraintsUtil { assert typeConstraints != null; JetType type = getValue(typeConstraints); JetType upperBound = typeParameter.getUpperBoundsAsType(); - JetType substitute = constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT); + JetType substitutedType = constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT); if (type != null) { - if (substitute == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitute)) { + if (substitutedType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitutedType)) { return false; } } @@ -153,14 +153,8 @@ public class ConstraintsUtil { public static boolean checkBoundsAreSatisfied(@NotNull ConstraintSystem constraintSystem) { for (TypeParameterDescriptor typeVariable : constraintSystem.getTypeVariables()) { - JetType type = getValue(constraintSystem.getTypeConstraints(typeVariable)); - JetType upperBound = typeVariable.getUpperBoundsAsType(); - JetType substitutedType = constraintSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT); - - if (type != null) { - if (substitutedType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitutedType)) { - return false; - } + if (!checkUpperBoundIsSatisfied(constraintSystem, typeVariable)) { + return false; } } return true; From b24509577cd457fb25c3c759dc0a9c906e68e278 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 3 Aug 2012 17:55:17 +0400 Subject: [PATCH 06/72] added issue names in tests --- .../testData/diagnostics/tests/inference/regressions/kt702.kt | 1 + .../testData/diagnostics/tests/inference/regressions/kt731.kt | 1 + .../testData/diagnostics/tests/inference/regressions/kt742.kt | 1 + .../testData/diagnostics/tests/inference/regressions/kt832.kt | 1 + .../testData/diagnostics/tests/inference/regressions/kt943.kt | 1 + .../testData/diagnostics/tests/inference/regressions/kt948.kt | 2 ++ 6 files changed, 7 insertions(+) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt index e166ac1f352..df7771256b8 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt @@ -1,3 +1,4 @@ +//KT-702 Type inference failed package a //+JDK diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt731.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt731.kt index a1eca3529c1..70e3b95199b 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt731.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt731.kt @@ -1,3 +1,4 @@ +//KT-731 Missing error from type inference package a class A(x: T) { diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt index a0bad3d1016..1e32ffc67a0 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt @@ -1,3 +1,4 @@ +//KT-742 Stack overflow in type inference package a class List(val head: T, val tail: List? = null) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt832.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt832.kt index 4e615b73d2e..ee684dd9d3b 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt832.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt832.kt @@ -1,3 +1,4 @@ +//KT-832 Provide better diagnostics when type inference fails for an expression that returns a function package a fun fooT2() : (t : T) -> T { diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt index 9508c0a686a..ed0987b815f 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt @@ -1,3 +1,4 @@ +//KT-943 Type inference failed package maze //+JDK diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt948.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt948.kt index a2ac18fb759..6cd13e611ca 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt948.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt948.kt @@ -1,3 +1,5 @@ +//KT-948 Make type inference work with sure()/!! + package a import java.util.* From 679a678e7c0b0d78ca1b693ab51eb8946046c1df Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 6 Aug 2012 16:37:48 +0400 Subject: [PATCH 07/72] choose the most specific candidate after type inference --- .../jet/lang/resolve/calls/CallResolver.java | 9 -------- .../inference/mostSpecificAfterInference.kt | 22 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index ae22f2db0b3..0142f4e1d9a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -325,15 +325,6 @@ public class CallResolver { } completeTypeInferenceDependentOnExpectedTypeForCall(resolvedCall, context, tracing, successful, failed); } - if (resultsWithIncompleteTypeInference.getResultingCalls().size() > 1) { - for (ResolvedCallWithTrace call : successful) { - if (call instanceof ResolvedCallImpl) { - ((ResolvedCallImpl)call).addStatus(ResolutionStatus.TYPE_INFERENCE_ERROR); - failed.add(call); - } - } - successful.clear(); - } OverloadResolutionResultsImpl results = computeResultAndReportErrors(context.trace, tracing, successful, failed); if (!results.isSingleResult()) { checkTypesWithNoCallee(context); diff --git a/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt b/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt new file mode 100644 index 00000000000..c1d36817722 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt @@ -0,0 +1,22 @@ +package i + +//+JDK +import java.util.* + +fun Collection.map1(f : (T) -> R) : List {} +fun java.lang.Iterable.map1(f : (T) -> R) : List {} + +fun test(list: List) { + val res = list.map1 { it } + //check res is not of error type + res : String +} + +fun Collection.foo() {} +fun java.lang.Iterable.foo() {} + +fun test1(list: List) { + val res = list.foo() + //check res is not of error type + res : String +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index ab021b6176a..bb5f7bc213d 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1309,6 +1309,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/mapFunction.kt"); } + @TestMetadata("mostSpecificAfterInference.kt") + public void testMostSpecificAfterInference() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt"); + } + @TestMetadata("NoInferenceFromDeclaredBounds.kt") public void testNoInferenceFromDeclaredBounds() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt"); From f730c1357c473e46c18eaa81b59fac44db0e3391 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 6 Aug 2012 18:08:26 +0400 Subject: [PATCH 08/72] KT-2484 Type inferred for function literal is (...) -> Int instead of (...) -> Unit, when function literal parameter is explicit #KT-2484 fixed --- .../ClosureExpressionsTypingVisitor.java | 3 +-- .../tests/inference/regressions/kt2484.kt | 23 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java index 2104323bb1c..42219f8a286 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java @@ -135,8 +135,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("") : returnType; functionDescriptor.setReturnType(safeReturnType); - boolean hasDeclaredValueParameters = functionLiteral.getValueParameterList() != null; - if (!hasDeclaredValueParameters && functionTypeExpected) { + if (!functionLiteral.hasDeclaredReturnType() && functionTypeExpected) { JetType expectedReturnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType); if (JetStandardClasses.isUnit(expectedReturnType)) { functionDescriptor.setReturnType(JetStandardClasses.getUnitType()); diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt new file mode 100644 index 00000000000..d5beed6abfb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt @@ -0,0 +1,23 @@ +//KT-2484 Type inferred for function literal is (...) -> Int instead of (...) -> Unit, when function literal parameter is explicit + +package a +//+JDK +import java.util.List + +fun Array.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element) + +fun bar(operation: (String) -> Unit) = operation("") + +fun main(args: Array) { + args.forEach { (a : String) : Unit -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { (a) : Unit -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { (a : String) -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { a -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { it.length } // This works! + + bar { (a: String) : Unit -> a.length } + bar { (a) : Unit -> a.length } + bar { (a: String) -> a.length } + bar { a -> a.length } + bar { it.length } +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index bb5f7bc213d..5725ef88af0 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1380,6 +1380,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt"); } + @TestMetadata("kt2484.kt") + public void testKt2484() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt"); + } + @TestMetadata("kt2514.kt") public void testKt2514() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt"); From 4b77e9b83ae799afab79a888798b7e3978efe6c6 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 6 Aug 2012 18:18:16 +0400 Subject: [PATCH 09/72] tests for obsolete tasks #KT-2445 fixed #KT-2459 fixed --- .../diagnostics/tests/inference/regressions/kt2445.kt | 10 ++++++++++ .../diagnostics/tests/inference/regressions/kt2459.kt | 10 ++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2445.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2459.kt diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2445.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2445.kt new file mode 100644 index 00000000000..0c282506c9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2445.kt @@ -0,0 +1,10 @@ +//KT-2445 Calling method with function with generic parameter causes compile-time exception +package a + +fun main(args: Array) { + test { + + } +} + +fun test(callback: (R) -> Unit):Unit = callback(null!!) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2459.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2459.kt new file mode 100644 index 00000000000..a61b5b804c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2459.kt @@ -0,0 +1,10 @@ +//KT-2459 Type inference error +package b + +import java.util.* + +class B(val x: List) +fun f(x: T): B = B(arrayList(x)) + +// from standard library +fun arrayList(vararg values: T) : ArrayList {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 5725ef88af0..e5f1d433c60 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1380,6 +1380,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt"); } + @TestMetadata("kt2445.kt") + public void testKt2445() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2445.kt"); + } + + @TestMetadata("kt2459.kt") + public void testKt2459() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2459.kt"); + } + @TestMetadata("kt2484.kt") public void testKt2484() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt"); From 8613db2724976f0aa0c8b0f1acfe573672da4849 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Mon, 6 Aug 2012 18:07:46 +0300 Subject: [PATCH 10/72] minor refactoring in JetParsing in order to reuse code --- .idea/codeStyleSettings.xml | 31 ------------------- .../jet/lang/parsing/JetParsing.java | 24 +++----------- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml index 0dd5af1923f..ceb1e02bb82 100644 --- a/.idea/codeStyleSettings.xml +++ b/.idea/codeStyleSettings.xml @@ -227,38 +227,7 @@ - diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index c4c1f75402f..82bf5429fed 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -97,7 +97,7 @@ public class JetParsing extends AbstractJetParsing { void parseFile() { PsiBuilder.Marker fileMarker = mark(); - parsePreamble(); + parsePreamble(true); parseToplevelDeclarations(false); @@ -107,22 +107,7 @@ public class JetParsing extends AbstractJetParsing { void parseScript() { PsiBuilder.Marker fileMarker = mark(); - PsiBuilder.Marker namespaceHeader = mark(); - PsiBuilder.Marker firstEntry = mark(); - parseModifierList(MODIFIER_LIST, true); - - if (at(PACKAGE_KEYWORD)) { - advance(); // PACKAGE_KEYWORD - - parseNamespaceName(); - - firstEntry.drop(); - consumeIf(SEMICOLON); - } - else { - firstEntry.rollbackTo(); - } - namespaceHeader.done(NAMESPACE_HEADER); + parsePreamble(false); PsiBuilder.Marker scriptMarker = mark(); parseImportDirectives(); @@ -155,7 +140,7 @@ public class JetParsing extends AbstractJetParsing { * : namespaceHeader? import* * ; */ - private void parsePreamble() { + private void parsePreamble(boolean imports) { /* * namespaceHeader * : modifiers "namespace" SimpleName{"."} SEMI? @@ -187,7 +172,8 @@ public class JetParsing extends AbstractJetParsing { } namespaceHeader.done(NAMESPACE_HEADER); - parseImportDirectives(); + if(imports) + parseImportDirectives(); } /* SimpleName{"."} */ From 0588d517004ec77c6ed6f4d7e61cf4d37ccd7da2 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Mon, 6 Aug 2012 18:18:17 +0300 Subject: [PATCH 11/72] getting rid of default imports for scripts --- .../jet/lang/parsing/JetScriptDefinition.java | 12 +--------- .../jet/lang/resolve/ImportsResolver.java | 3 +-- .../jet/lang/resolve/lazy/ScopeProvider.java | 24 +------------------ .../jetbrains/jet/codegen/ScriptGenTest.java | 18 -------------- 4 files changed, 3 insertions(+), 54 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetScriptDefinition.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetScriptDefinition.java index cfd97e990af..df784f85136 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetScriptDefinition.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetScriptDefinition.java @@ -28,12 +28,10 @@ import java.util.List; public class JetScriptDefinition { private final String extension; private final List parameters; - private final List imports; - public JetScriptDefinition(String extension, List scriptParameters, @Nullable List imports) { + public JetScriptDefinition(String extension, List scriptParameters) { this.extension = extension; parameters = scriptParameters == null ? Collections.emptyList() : scriptParameters; - this.imports = imports == null || imports.isEmpty() ? Collections.emptyList() : importPaths(imports); } private static List importPaths(List imports) { @@ -44,10 +42,6 @@ public class JetScriptDefinition { return paths; } - public JetScriptDefinition(String extension, List scriptParameters) { - this(extension, scriptParameters, null); - } - public JetScriptDefinition(String extension, AnalyzerScriptParameter... scriptParameters) { this(extension, Arrays.asList(scriptParameters)); } @@ -59,8 +53,4 @@ public class JetScriptDefinition { public String getExtension() { return extension; } - - public List getImports() { - return imports; - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java index 9784d7bf31f..aaa45193dd7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java @@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.ModuleConfiguration; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.lazy.ScopeProvider; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; @@ -80,7 +79,7 @@ public class ImportsResolver { private void processImports(boolean onlyClasses, @NotNull JetScope rootScope) { for (JetFile file : context.getNamespaceDescriptors().keySet()) { WritableScope namespaceScope = context.getNamespaceScopes().get(file); - processImportsInFile(onlyClasses, namespaceScope, ScopeProvider.getFileImports(file), rootScope); + processImportsInFile(onlyClasses, namespaceScope, Lists.newArrayList(file.getImportDirectives()), rootScope); } for (JetScript script : context.getScripts().keySet()) { WritableScope scriptScope = context.getScriptScopes().get(script); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java index 7968692d61a..85032807bcf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java @@ -21,11 +21,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; -import org.jetbrains.jet.lang.parsing.JetParserDefinition; -import org.jetbrains.jet.lang.parsing.JetScriptDefinition; -import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider; import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.ImportsResolver; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.scopes.JetScope; @@ -76,9 +72,7 @@ public class ScopeProvider { writableScope.importScope(rootPackageDescriptor.getMemberScope()); } - List importDirectives = getFileImports(file); - - ImportsResolver.processImportsInFile(true, writableScope, importDirectives, + ImportsResolver.processImportsInFile(true, writableScope, Lists.newArrayList(file.getImportDirectives()), rootPackageDescriptor.getMemberScope(), resolveSession.getModuleConfiguration(), resolveSession.getTrace(), resolveSession.getInjector().getQualifiedExpressionResolver()); @@ -90,22 +84,6 @@ public class ScopeProvider { return writableScope; } - public static List getFileImports(JetFile file) { - List fileImports = file.getImportDirectives(); - List importDirectives = Lists.newArrayList(); - if(file.isScript()) { - JetScriptDefinition definition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file); - List imports = definition.getImports(); - if(!imports.isEmpty()) { - for (ImportPath importPath : imports) { - importDirectives.add(JetPsiFactory.createImportDirective(file.getProject(), importPath)); - } - } - } - importDirectives.addAll(fileImports); - return importDirectives; - } - @NotNull public JetScope getResolutionScopeForDeclaration(@NotNull JetDeclaration jetDeclaration) { PsiElement immediateParent = jetDeclaration.getParent(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java index 576f9b52932..d1950cf12f7 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java @@ -39,9 +39,6 @@ public class ScriptGenTest extends CodegenTestCase { public static final JetScriptDefinition FIB_SCRIPT_DEFINITION = new JetScriptDefinition(".lang.kt", new AnalyzerScriptParameter("num", "jet.Int")); - public static final JetScriptDefinition DEFIMPORT_SCRIPT_DEFINITION = - new JetScriptDefinition(".def.kt", null, Arrays.asList("java.util.Collections")); - @Override protected void setUp() throws Exception { super.setUp(); @@ -150,21 +147,6 @@ public class ScriptGenTest extends CodegenTestCase { } } - public void testDefImports() { - JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(DEFIMPORT_SCRIPT_DEFINITION); - loadFile("script/withdefimports.def.kt"); - final Class aClass = loadClass("Withdefimports", generateClassesInFile()); - try { - Constructor constructor = aClass.getConstructor(); - Field rv = aClass.getField("rv"); - Object script = constructor.newInstance(); - assertEquals(Collections.emptyList(),rv.get(script)); - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - public void testScriptWhereMethodHasClosure() { JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION); loadFile("script/methodWithClosure.lang.kt"); From a98bc541f53e868012cd2e680375d4e9e8344e73 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 7 Aug 2012 16:44:14 +0400 Subject: [PATCH 12/72] Printer class moved from tests to util --- .../jet/compiler/android/CodegenTestsOnAndroidGenerator.java | 2 +- .../org/jetbrains/jet/test/generator/SimpleTestClassModel.java | 1 + .../org/jetbrains/jet/test/generator/SimpleTestMethodModel.java | 1 + .../tests/org/jetbrains/jet/test/generator/TestGenerator.java | 1 + .../tests/org/jetbrains/jet/test/generator/TestMethodModel.java | 1 + .../generator => util/src/org/jetbrains/jet/utils}/Printer.java | 2 +- 6 files changed, 6 insertions(+), 2 deletions(-) rename compiler/{tests/org/jetbrains/jet/test/generator => util/src/org/jetbrains/jet/utils}/Printer.java (97%) diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java index ef313cbbebd..8184c54aac5 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java @@ -32,7 +32,7 @@ import org.jetbrains.jet.codegen.GenerationUtils; import org.jetbrains.jet.compiler.PathManager; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetPsiFactory; -import org.jetbrains.jet.test.generator.Printer; +import org.jetbrains.jet.utils.Printer; import java.io.File; import java.io.IOException; diff --git a/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestClassModel.java b/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestClassModel.java index 62797a6b04e..fa12603fd73 100644 --- a/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestClassModel.java +++ b/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestClassModel.java @@ -20,6 +20,7 @@ import com.google.common.collect.Lists; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.utils.Printer; import java.io.File; import java.util.Collection; diff --git a/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestMethodModel.java b/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestMethodModel.java index 815cdb12e96..d0ec0f6ed89 100644 --- a/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestMethodModel.java +++ b/compiler/tests/org/jetbrains/jet/test/generator/SimpleTestMethodModel.java @@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.utils.Printer; import java.io.File; diff --git a/compiler/tests/org/jetbrains/jet/test/generator/TestGenerator.java b/compiler/tests/org/jetbrains/jet/test/generator/TestGenerator.java index 65795487f3c..ec888cb0a51 100644 --- a/compiler/tests/org/jetbrains/jet/test/generator/TestGenerator.java +++ b/compiler/tests/org/jetbrains/jet/test/generator/TestGenerator.java @@ -20,6 +20,7 @@ import com.google.common.collect.Lists; import com.intellij.openapi.util.io.FileUtil; import junit.framework.TestCase; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.utils.Printer; import java.io.File; import java.io.IOException; diff --git a/compiler/tests/org/jetbrains/jet/test/generator/TestMethodModel.java b/compiler/tests/org/jetbrains/jet/test/generator/TestMethodModel.java index 6c04c87835d..353c3ec12f6 100644 --- a/compiler/tests/org/jetbrains/jet/test/generator/TestMethodModel.java +++ b/compiler/tests/org/jetbrains/jet/test/generator/TestMethodModel.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.test.generator; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.utils.Printer; /** * @author abreslav diff --git a/compiler/tests/org/jetbrains/jet/test/generator/Printer.java b/compiler/util/src/org/jetbrains/jet/utils/Printer.java similarity index 97% rename from compiler/tests/org/jetbrains/jet/test/generator/Printer.java rename to compiler/util/src/org/jetbrains/jet/utils/Printer.java index fe7f24730a4..01545fe008a 100644 --- a/compiler/tests/org/jetbrains/jet/test/generator/Printer.java +++ b/compiler/util/src/org/jetbrains/jet/utils/Printer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.test.generator; +package org.jetbrains.jet.utils; import org.jetbrains.annotations.NotNull; From 9102622e021d4eece29926a6bb632505c60a9f2c Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 7 Aug 2012 15:43:54 +0400 Subject: [PATCH 13/72] more tests on type inference #KT-2200 fixed #KT-2283 fixed --- .../tests/inference/possibleCycleOnConstraints.kt | 13 +++++++++++++ .../tests/inference/regressions/kt2200.kt | 14 ++++++++++++++ .../tests/inference/regressions/kt2283.kt | 13 +++++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 10 ++++++++++ 4 files changed, 50 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2200.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt diff --git a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt new file mode 100644 index 00000000000..8e61222f43c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt @@ -0,0 +1,13 @@ +package a + +import java.util.* + +fun g (f: () -> List) : T {} + +fun test() { + //here possibly can be a cycle on constraints + val x = g { Collections.emptyList() } + + val y = g { Collections.emptyList()!! } + val z : List = g { Collections.emptyList()!! } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2200.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2200.kt new file mode 100644 index 00000000000..f5e0fc6d331 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2200.kt @@ -0,0 +1,14 @@ +//KT-2200 array(array()) breaks compiler +package n + +fun main(args: Array) { + val a = array(array()) + val a0 : Array> = array(array()) + val a1 = array(array()) + a1 : Array> + val a2 = array>(array()) + a2 : Array> +} + +//from library +fun array(vararg t : T) : Array = t \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt new file mode 100644 index 00000000000..edf1d078551 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt @@ -0,0 +1,13 @@ +//KT-2283 Bad diagnostics of failed type inference +package a + + +trait Foo
+ +fun Foo.map(f: (A) -> B): Foo = object : Foo {} + + +fun foo() { + val l: Foo = object : Foo {} + val m: Foo = l.map { ppp -> 1 } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index e5f1d433c60..59bfdeeda34 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1365,6 +1365,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt"); } + @TestMetadata("kt2200.kt") + public void testKt2200() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2200.kt"); + } + + @TestMetadata("kt2283.kt") + public void testKt2283() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt"); + } + @TestMetadata("kt2294.kt") public void testKt2294() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2294.kt"); From 70c5a5ba9e1da81e608c2f4f16656c2cc48aae4f Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 7 Aug 2012 18:08:52 +0400 Subject: [PATCH 14/72] KT-2505 Type mismatch: inferred type is T but T was expected #KT-2505 --- .../jet/lang/resolve/calls/CallResolver.java | 18 +-------- .../calls/OverloadResolutionResults.java | 2 + .../calls/OverloadResolutionResultsImpl.java | 37 ++++++++++++++----- .../BasicExpressionTypingVisitor.java | 9 +---- .../completeInferenceIfManyFailed.kt | 15 ++++++++ .../tests/inference/regressions/kt2505.kt | 20 ++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 15 ++++++++ 7 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2505.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 0142f4e1d9a..9afda1d11fd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -591,7 +591,7 @@ public class CallResolver { OverloadResolutionResultsImpl results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates); - if (!results.isSingleResult() && results.getResultCode() != OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) { + if (!results.isSingleResult() && !results.isIncomplete()) { checkTypesWithNoCallee(task.toBasic()); } return results; @@ -1033,7 +1033,7 @@ public class CallResolver { } if (!thisLevel.isEmpty()) { OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false); - if (results.isSuccess()) { + if (results.isSingleResult()) { results.getResultingCall().getTrace().commit(); return OverloadResolutionResultsImpl.singleFailedCandidate(results.getResultingCall()); } @@ -1058,9 +1058,6 @@ public class CallResolver { ResolvedCallWithTrace failed = failedCandidates.iterator().next(); failed.getTrace().commit(); - if (failed.getStatus() != ResolutionStatus.STRONG_ERROR && failed.hasUnknownTypeParameters()) { - return OverloadResolutionResultsImpl.incompleteTypeInference(failed); - } return OverloadResolutionResultsImpl.singleFailedCandidate(failed); } else { @@ -1078,13 +1075,9 @@ public class CallResolver { private OverloadResolutionResultsImpl chooseAndReportMaximallySpecific(Set> candidates, boolean discriminateGenerics) { if (candidates.size() != 1) { - boolean dirty = false; Set> cleanCandidates = Sets.newLinkedHashSet(candidates); for (Iterator> iterator = cleanCandidates.iterator(); iterator.hasNext(); ) { ResolvedCallWithTrace candidate = iterator.next(); - if (candidate.hasUnknownTypeParameters()) { - dirty = true; - } if (candidate.isDirty()) { iterator.remove(); } @@ -1107,10 +1100,6 @@ public class CallResolver { Set> noOverrides = OverridingUtil.filterOverrides(candidates, MAP_TO_RESULT); - if (dirty) { - return OverloadResolutionResultsImpl.incompleteTypeInference(candidates); - } - return OverloadResolutionResultsImpl.ambiguity(noOverrides); } else { @@ -1118,9 +1107,6 @@ public class CallResolver { TemporaryBindingTrace temporaryTrace = result.getTrace(); temporaryTrace.commit(); - if (result.hasUnknownTypeParameters()) { - return OverloadResolutionResultsImpl.incompleteTypeInference(result); - } return OverloadResolutionResultsImpl.success(result); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResults.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResults.java index d1c148858d8..07de185bf28 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResults.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResults.java @@ -63,4 +63,6 @@ public interface OverloadResolutionResults { boolean isNothing(); boolean isAmbiguity(); + + boolean isIncomplete(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java index db3fd1aa4e3..34dfc0c87d7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java @@ -28,8 +28,11 @@ import java.util.Collections; */ /*package*/ class OverloadResolutionResultsImpl implements OverloadResolutionResults { - public static OverloadResolutionResultsImpl success(@NotNull ResolvedCallWithTrace descriptor) { - return new OverloadResolutionResultsImpl(Code.SUCCESS, Collections.singleton(descriptor)); + public static OverloadResolutionResultsImpl success(@NotNull ResolvedCallWithTrace candidate) { + if (candidate.hasUnknownTypeParameters()) { + return incompleteTypeInference(candidate); + } + return new OverloadResolutionResultsImpl(Code.SUCCESS, Collections.singleton(candidate)); } public static OverloadResolutionResultsImpl nameNotFound() { @@ -37,22 +40,30 @@ import java.util.Collections; } public static OverloadResolutionResultsImpl singleFailedCandidate(ResolvedCallWithTrace candidate) { + if (candidate.getStatus() != ResolutionStatus.STRONG_ERROR && candidate.hasUnknownTypeParameters()) { + return incompleteTypeInference(candidate); + } return new OverloadResolutionResultsImpl(Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH, Collections.singleton(candidate)); } public static OverloadResolutionResultsImpl manyFailedCandidates(Collection> failedCandidates) { return new OverloadResolutionResultsImpl(Code.MANY_FAILED_CANDIDATES, failedCandidates); } - public static OverloadResolutionResultsImpl ambiguity(Collection> descriptors) { - return new OverloadResolutionResultsImpl(Code.AMBIGUITY, descriptors); + public static OverloadResolutionResultsImpl ambiguity(Collection> candidates) { + for (ResolvedCallWithTrace candidate : candidates) { + if (candidate.hasUnknownTypeParameters()) { + return incompleteTypeInference(candidates); + } + } + return new OverloadResolutionResultsImpl(Code.AMBIGUITY, candidates); } - public static OverloadResolutionResultsImpl incompleteTypeInference(Collection> descriptors) { - return new OverloadResolutionResultsImpl(Code.INCOMPLETE_TYPE_INFERENCE, descriptors); + private static OverloadResolutionResultsImpl incompleteTypeInference(Collection> candidates) { + return new OverloadResolutionResultsImpl(Code.INCOMPLETE_TYPE_INFERENCE, candidates); } - public static OverloadResolutionResultsImpl incompleteTypeInference(ResolvedCallWithTrace descriptor) { - return new OverloadResolutionResultsImpl(Code.INCOMPLETE_TYPE_INFERENCE, Collections.singleton(descriptor)); + private static OverloadResolutionResultsImpl incompleteTypeInference(ResolvedCallWithTrace candidate) { + return incompleteTypeInference(Collections.singleton(candidate)); } private final Collection> results; @@ -96,7 +107,7 @@ import java.util.Collections; @Override public boolean isSingleResult() { - return isSuccess() || resultCode == Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH; + return results.size() == 1; } @Override @@ -108,7 +119,13 @@ import java.util.Collections; public boolean isAmbiguity() { return resultCode == Code.AMBIGUITY; } -// + + @Override + public boolean isIncomplete() { + return resultCode == Code.INCOMPLETE_TYPE_INFERENCE; + } + + // // public OverloadResolutionResultsImpl newContents(@NotNull Collection functionDescriptors) { // return new OverloadResolutionResultsImpl(resultCode, functionDescriptors); // } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index b4c5a409669..34b4b035276 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -611,13 +611,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { if (!results.isNothing()) { checkSuper(receiver, results, context.trace, callExpression); result[0] = true; - if (results.isSingleResult()) { - ResolvedCall resultingCall = results.getResultingCall(); - if (resultingCall instanceof ResolvedCallWithTrace) { - if (((ResolvedCallWithTrace)resultingCall).getStatus() == ResolutionStatus.TYPE_INFERENCE_ERROR) { - return null; - } - } + if (results.isIncomplete()) { + return null; } return results.isSingleResult() ? results.getResultingDescriptor() : null; } diff --git a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt new file mode 100644 index 00000000000..a2b71f068af --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt @@ -0,0 +1,15 @@ +package d + +fun joinT(x: Int, vararg a: T): T? { + return null +} + +fun joinT(x: Any, y: T): T? { + return null +} + +fun test() { + val x2 = joinT(*1, "2") + x2 : String? +} + diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2505.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2505.kt new file mode 100644 index 00000000000..b3c9fdfe9b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2505.kt @@ -0,0 +1,20 @@ +//KT-2505 Type mismatch: inferred type is T but T was expected + +package a + +trait MyType {} +class MyClass : MyType {} + +public open class HttpResponse() { + public open fun parseAs(dataClass : MyClass) : T? { + return null + } + public open fun parseAs(dataType : MyType) : Any? { + return null + } +} + +fun test (httpResponse: HttpResponse, rtype: MyClass) { + val res = httpResponse.parseAs( rtype ) + res : R? //type mismatch: required R?, found T? +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 59bfdeeda34..c7a27aaba1f 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1259,6 +1259,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/arrayConstructor.kt"); } + @TestMetadata("completeInferenceIfManyFailed.kt") + public void testCompleteInferenceIfManyFailed() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt"); + } + @TestMetadata("conflictingSubstitutions.kt") public void testConflictingSubstitutions() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/conflictingSubstitutions.kt"); @@ -1324,6 +1329,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/noInformationForParameter.kt"); } + @TestMetadata("possibleCycleOnConstraints.kt") + public void testPossibleCycleOnConstraints() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt"); + } + @TestMetadata("typeConstructorMismatch.kt") public void testTypeConstructorMismatch() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/typeConstructorMismatch.kt"); @@ -1405,6 +1415,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2484.kt"); } + @TestMetadata("kt2505.kt") + public void testKt2505() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2505.kt"); + } + @TestMetadata("kt2514.kt") public void testKt2514() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2514.kt"); From 8a29b8562dbb787d2a4dbaed28b32ed7eaef4b46 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Tue, 7 Aug 2012 22:32:34 +0300 Subject: [PATCH 15/72] synthetic accessors for methods/properties are static methods in bytecode --- .../AccessorForFunctionDescriptor.java | 45 ++++++++++++ .../AccessorForPropertyDescriptor.java | 56 +++++++++++++++ .../jetbrains/jet/codegen/CallableMethod.java | 7 +- .../jetbrains/jet/codegen/CodegenContext.java | 68 +------------------ .../jet/codegen/CodegenContexts.java | 3 + .../codegen/ImplementationBodyCodegen.java | 14 ++-- .../jetbrains/jet/codegen/JetTypeMapper.java | 39 +++++++++-- .../jetbrains/jet/codegen/StubCodegen.java | 3 + .../jet/codegen/CodegenTestCase.java | 7 +- 9 files changed, 157 insertions(+), 85 deletions(-) create mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java create mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java new file mode 100644 index 00000000000..87735e64197 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen; + +import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; + +import java.util.Collections; + +/** + * @author alex.tkachman +*/ +public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl { + public AccessorForFunctionDescriptor(DeclarationDescriptor descriptor, DeclarationDescriptor containingDeclaration, int index) { + super(containingDeclaration, Collections.emptyList(), + Name.identifier(descriptor.getName() + "$b$" + index), + Kind.DECLARATION); + + FunctionDescriptor fd = (SimpleFunctionDescriptor) descriptor; + + initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null, + fd.getExpectedThisObject(), + Collections.emptyList(), + fd.getValueParameters(), + fd.getReturnType(), + Modality.FINAL, + Visibilities.INTERNAL, + /*isInline = */ false); + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java new file mode 100644 index 00000000000..fad288fc832 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen; + +import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.JetType; + +import java.util.Collections; + +/** + * @author alex.tkachman +*/ +public class AccessorForPropertyDescriptor extends PropertyDescriptor { + public AccessorForPropertyDescriptor(PropertyDescriptor pd, DeclarationDescriptor containingDeclaration, int index) { + super(containingDeclaration, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, + pd.isVar(), pd.isObjectDeclaration(), Name.identifier(pd.getName() + "$b$" + index), + Kind.DECLARATION); + + JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null; + setType(pd.getType(), Collections.emptyList(), pd.getExpectedThisObject(), receiverType); + initialize(new Getter(this), new Setter(this)); + } + + public static class Getter extends PropertyGetterDescriptor { + public Getter(AccessorForPropertyDescriptor property) { + super(property, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, + false, + false, Kind.DECLARATION); + initialize(property.getType()); + } + } + + public static class Setter extends PropertySetterDescriptor { + public Setter(AccessorForPropertyDescriptor property) { + super(property, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, + false, + false, Kind.DECLARATION); + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java index f49e5489faa..4137ddfd573 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java @@ -67,7 +67,7 @@ public class CallableMethod implements Callable { return owner; } - @NotNull + @Nullable public JvmClassName getDefaultImplParam() { return defaultImplParam; } @@ -96,6 +96,7 @@ public class CallableMethod implements Callable { v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor()); } + @Nullable public Type getGenerateCalleeType() { return generateCalleeType; } @@ -122,10 +123,6 @@ public class CallableMethod implements Callable { return thisClass != null && generateCalleeType == null; } - public boolean isNeedsReceiver() { - return receiverParameterType != null; - } - public Type getReturnType() { return signature.getAsmMethod().getReturnType(); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java index 4f76c0d8c39..382fa0221fe 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java @@ -20,9 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.JvmClassName; -import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; @@ -43,9 +41,6 @@ public abstract class CodegenContext { private final CodegenContext parentContext; public final ObjectOrClosureCodegen closure; - HashMap typeInfoConstants; - HashMap reverseTypeInfoConstants; - int typeInfoConstantsCount; HashMap accessors; protected StackValue outerExpression; @@ -183,50 +178,10 @@ public abstract class CodegenContext { if (accessor != null) { return accessor; } if (descriptor instanceof SimpleFunctionDescriptor) { - SimpleFunctionDescriptorImpl myAccessor = new SimpleFunctionDescriptorImpl(contextDescriptor, - Collections.emptyList(), - Name.identifier(descriptor.getName() + "$b$" + getHierarchyCount() + "$" + accessors.size()), - CallableMemberDescriptor.Kind.DECLARATION); - FunctionDescriptor fd = (SimpleFunctionDescriptor) descriptor; - myAccessor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null, - fd.getExpectedThisObject(), - fd.getTypeParameters(), - fd.getValueParameters(), - fd.getReturnType(), - Modality.FINAL, - Visibilities.PUBLIC, - /*isInline = */ false); - accessor = myAccessor; + accessor = new AccessorForFunctionDescriptor(descriptor, contextDescriptor, accessors.size()); } else if (descriptor instanceof PropertyDescriptor) { - PropertyDescriptor pd = (PropertyDescriptor) descriptor; - PropertyDescriptor myAccessor = new PropertyDescriptor(contextDescriptor, - Collections.emptyList(), - Modality.FINAL, - Visibilities.PUBLIC, - pd.isVar(), - pd.isObjectDeclaration(), - Name.identifier(pd.getName() + "$b$" + getHierarchyCount() + "$" + accessors.size()), - CallableMemberDescriptor.Kind.DECLARATION - ); - JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null; - myAccessor.setType(pd.getType(), Collections.emptyList(), pd.getExpectedThisObject(), receiverType); - - PropertyGetterDescriptor pgd = new PropertyGetterDescriptor( - myAccessor, Collections.emptyList(), - Modality.FINAL, - Visibilities.PUBLIC, - false, false, CallableMemberDescriptor.Kind.DECLARATION); - pgd.initialize(myAccessor.getType()); - - PropertySetterDescriptor psd = new PropertySetterDescriptor( - myAccessor, Collections.emptyList(), - Modality.FINAL, - Visibilities.PUBLIC, - false, false, CallableMemberDescriptor.Kind.DECLARATION); - - myAccessor.initialize(pgd, psd); - accessor = myAccessor; + accessor = new AccessorForPropertyDescriptor((PropertyDescriptor) descriptor, contextDescriptor,accessors.size()); } else { throw new UnsupportedOperationException(); @@ -235,25 +190,6 @@ public abstract class CodegenContext { return accessor; } - private int getHierarchyCount() { - ClassDescriptor descriptor = getThisDescriptor(); - int c = 0; - while(descriptor != null) { - Collection supertypes = descriptor.getDefaultType().getConstructor().getSupertypes(); - if (supertypes.isEmpty()) { - break; - } - c++; - for (JetType supertype : supertypes) { - descriptor = (ClassDescriptor) supertype.getConstructor().getDeclarationDescriptor(); - if (descriptor.getKind() == ClassKind.CLASS) { - break; - } - } - } - return c; - } - public StackValue getReceiverExpression(JetTypeMapper typeMapper) { assert getReceiverDescriptor() != null; Type asmType = typeMapper.mapType(getReceiverDescriptor().getReceiverParameter().getType(), MapTypeMode.VALUE); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContexts.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContexts.java index bcb43beb1c9..03aa14cadc5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContexts.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContexts.java @@ -40,6 +40,9 @@ import java.util.List; * @author Stepan Koltsov */ public class CodegenContexts { + private CodegenContexts() { + } + private static class FakeDescriptorForStaticContext implements DeclarationDescriptor { @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index e259def68f1..6ec6e1f811a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -312,7 +312,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Method originalMethod = typeMapper.mapSignature(original.getName(), original).getAsmMethod(); Type[] argTypes = method.getArgumentTypes(); - MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_FINAL, bridge.getName().getName(), method.getDescriptor(), null, null); + String owner = typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(); + MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, bridge.getName().getName(), + method.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { StubCodegen.generateStubCode(mv); } @@ -322,13 +324,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { InstructionAdapter iv = new InstructionAdapter(mv); iv.load(0, JetTypeMapper.TYPE_OBJECT); - for (int i = 0, reg = 1; i < argTypes.length; i++) { + for (int i = 1, reg = 1; i < argTypes.length; i++) { Type argType = argTypes[i]; iv.load(reg, argType); //noinspection AssignmentToForLoopParameter reg += argType.getSize(); } - iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor()); + iv.invokespecial(owner, originalMethod.getName(), originalMethod.getDescriptor()); iv.areturn(method.getReturnType()); FunctionCodegen.endVisit(iv, "accessor", null); @@ -342,7 +344,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION); Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod(); - MethodVisitor mv = v.newMethod(null, ACC_PUBLIC | ACC_BRIDGE | ACC_FINAL, method.getName(), method.getDescriptor(), null, null); + MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_STATIC, method.getName(), method.getDescriptor(), null, null); PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(), originalSignature.getJvmMethodSignature().getKotlinTypeParameter(), original, ((PropertyDescriptor) entry.getValue()).getGetter().getVisibility()); @@ -370,7 +372,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Method method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); JvmPropertyAccessorSignature originalSignature2 = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION); Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod(); - MethodVisitor mv = v.newMethod(null, ACC_PUBLIC | ACC_BRIDGE | ACC_FINAL, method.getName(), method.getDescriptor(), null, null); + MethodVisitor mv = v.newMethod(null, ACC_STATIC | ACC_BRIDGE | ACC_FINAL, method.getName(), method.getDescriptor(), null, null); PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(), originalSignature2.getJvmMethodSignature().getKotlinTypeParameter(), original, ((PropertyDescriptor) entry.getValue()).getSetter().getVisibility()); @@ -384,7 +386,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { iv.load(0, JetTypeMapper.TYPE_OBJECT); Type[] argTypes = method.getArgumentTypes(); - for (int i = 0, reg = 1; i < argTypes.length; i++) { + for (int i = 1, reg = 1; i < argTypes.length; i++) { Type argType = argTypes[i]; iv.load(reg, argType); //noinspection AssignmentToForLoopParameter diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index 11e8445e0e9..957c3bcbd6d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -38,7 +38,6 @@ import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames; import org.jetbrains.jet.lang.types.lang.PrimitiveType; import org.jetbrains.jet.lang.types.ref.ClassName; @@ -611,6 +610,8 @@ public class JetTypeMapper { boolean originalIsInterface = CodegenUtil.isInterface(declarationOwner); boolean currentIsInterface = CodegenUtil.isInterface(currentOwner); + boolean isAccessor = isAccessor(functionDescriptor); + ClassDescriptor receiver; if (currentIsInterface && !originalIsInterface) { receiver = declarationOwner; @@ -630,7 +631,7 @@ public class JetTypeMapper { invokeOpcode = isInterface ? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE) - : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL); + : (isAccessor ? Opcodes.INVOKESTATIC : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL)); if (isInterface && superCall) { descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL); owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); @@ -653,7 +654,11 @@ public class JetTypeMapper { owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode, thisClass, receiverParameterType, null); } - + + private static boolean isAccessor(FunctionDescriptor functionDescriptor) { + return functionDescriptor instanceof AccessorForFunctionDescriptor || functionDescriptor instanceof AccessorForPropertyDescriptor.Getter || functionDescriptor instanceof AccessorForPropertyDescriptor.Setter; + } + @NotNull private static FunctionDescriptor findAnyDeclaration(@NotNull FunctionDescriptor function) { //if (function.getKind() == CallableMemberDescriptor.Kind.DECLARATION) { @@ -682,6 +687,12 @@ public class JetTypeMapper { signatureVisitor.writeParametersStart(); + if(isAccessor(f)) { + signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS); + mapType(((ClassifierDescriptor)f.getContainingDeclaration()).getDefaultType(), signatureVisitor, MapTypeMode.VALUE); + signatureVisitor.writeParameterTypeEnd(); + } + if (kind == OwnerKind.TRAIT_IMPL) { ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration(); JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration); @@ -784,7 +795,13 @@ public class JetTypeMapper { writeFormalTypeParameters(f.getTypeParameters(), signatureWriter); signatureWriter.writeParametersStart(); - + + if(isAccessor(f)) { + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS); + mapType(((ClassifierDescriptor)f.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE); + signatureWriter.writeParameterTypeEnd(); + } + final List parameters = f.getValueParameters(); if (receiver.exists()) { signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); @@ -826,6 +843,13 @@ public class JetTypeMapper { mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.IMPL); signatureWriter.writeParameterTypeEnd(); } + else { + if(descriptor instanceof AccessorForPropertyDescriptor) { + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS); + mapType(((ClassifierDescriptor)descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE); + signatureWriter.writeParameterTypeEnd(); + } + } if (descriptor.getReceiverParameter().exists()) { signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); @@ -866,6 +890,13 @@ public class JetTypeMapper { mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.VALUE); signatureWriter.writeParameterTypeEnd(); } + else { + if(descriptor instanceof AccessorForPropertyDescriptor) { + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS); + mapType(((ClassifierDescriptor)descriptor.getContainingDeclaration()).getDefaultType(), signatureWriter, MapTypeMode.VALUE); + signatureWriter.writeParameterTypeEnd(); + } + } if (descriptor.getReceiverParameter().exists()) { signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java index 734786acf63..1b6fd156bb2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java @@ -24,6 +24,9 @@ import org.jetbrains.asm4.commons.InstructionAdapter; * @author Stepan Koltsov */ public class StubCodegen { + private StubCodegen() { + } + public static void generateStubThrow(MethodVisitor mv) { new InstructionAdapter(mv).anew(Type.getObjectType("java/lang/RuntimeException")); new InstructionAdapter(mv).dup(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index c88277058d1..321ce3a8eea 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -274,10 +274,9 @@ public abstract class CodegenTestCase extends UsefulTestCase { BuiltinsScopeExtensionMode.ALL); analyzeExhaust.throwIfError(); AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext()); - GenerationState state = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles()); - state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); - alreadyGenerated = state; - return state; + alreadyGenerated = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles()); + alreadyGenerated.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); + return alreadyGenerated; } protected Class generateNamespaceClass() { From 336ac45fc9905f96bbee624dc8690e5bffbab18a Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Tue, 7 Aug 2012 22:33:44 +0300 Subject: [PATCH 16/72] micro typo fixed --- .../org/jetbrains/jet/codegen/ImplementationBodyCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 6ec6e1f811a..c03ef9aee18 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -344,7 +344,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION); Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod(); - MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_STATIC, method.getName(), method.getDescriptor(), null, null); + MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, method.getName(), method.getDescriptor(), null, null); PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(), originalSignature.getJvmMethodSignature().getKotlinTypeParameter(), original, ((PropertyDescriptor) entry.getValue()).getGetter().getVisibility()); From 3dfb510a62962256425d7fc2c430c5803dd20dd0 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 7 Aug 2012 21:56:04 +0400 Subject: [PATCH 17/72] Regenerated JavaScript stubs. --- js/js.libraries/src/core/dom.kt | 78 +++++++++---------- js/js.libraries/src/core/domEvents.kt | 8 +- .../kotlin/tools/GenerateJavaScriptStubs.kt | 2 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/js/js.libraries/src/core/dom.kt b/js/js.libraries/src/core/dom.kt index c2c4b53bee6..bb9bca7cac1 100644 --- a/js/js.libraries/src/core/dom.kt +++ b/js/js.libraries/src/core/dom.kt @@ -4,7 +4,7 @@ package org.w3c.dom // -// NOTE THIS FILE IS AUTO-GENERATED by the GeneratedJavaScriptStubs.kt +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateJavaScriptStubs.kt // See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib // @@ -28,11 +28,11 @@ native public trait CDATASection: Text { native public trait CharacterData: Node { public var data: String public val length: Int + public fun appendData(arg1: String?): Unit = js.noImpl + public fun deleteData(arg1: Int, arg2: Int): Unit = js.noImpl + public fun insertData(arg1: Int, arg2: String?): Unit = js.noImpl public fun replaceData(arg1: Int, arg2: Int, arg3: String?): Unit = js.noImpl public fun substringData(arg1: Int, arg2: Int): String = js.noImpl - public fun appendData(arg1: String?): Unit = js.noImpl - public fun insertData(arg1: Int, arg2: String?): Unit = js.noImpl - public fun deleteData(arg1: Int, arg2: Int): Unit = js.noImpl } native public trait Comment: CharacterData { @@ -49,21 +49,21 @@ native public trait Document: Node { public val xmlEncoding: String public var xmlStandalone: Boolean public var xmlVersion: String - public fun createElement(arg1: String?): Element = js.noImpl + public fun adoptNode(arg1: Node): Node = js.noImpl + public fun createAttribute(arg1: String?): Attr = js.noImpl + public fun createAttributeNS(arg1: String?, arg2: String?): Attr = js.noImpl + public fun createCDATASection(arg1: String?): CDATASection = js.noImpl public fun createComment(arg1: String?): Comment = js.noImpl public fun createDocumentFragment(): DocumentFragment = js.noImpl - public fun createTextNode(arg1: String?): Text = js.noImpl - public fun createCDATASection(arg1: String?): CDATASection = js.noImpl - public fun createProcessingInstruction(arg1: String?, arg2: String?): ProcessingInstruction = js.noImpl - public fun createAttribute(arg1: String?): Attr = js.noImpl - public fun createEntityReference(arg1: String?): EntityReference = js.noImpl - public fun getElementsByTagName(arg1: String?): NodeList = js.noImpl - public fun importNode(arg1: Node, arg2: Boolean): Node = js.noImpl + public fun createElement(arg1: String?): Element = js.noImpl public fun createElementNS(arg1: String?, arg2: String?): Element = js.noImpl - public fun createAttributeNS(arg1: String?, arg2: String?): Attr = js.noImpl - public fun getElementsByTagNameNS(arg1: String?, arg2: String?): NodeList = js.noImpl + public fun createEntityReference(arg1: String?): EntityReference = js.noImpl + public fun createProcessingInstruction(arg1: String?, arg2: String?): ProcessingInstruction = js.noImpl + public fun createTextNode(arg1: String?): Text = js.noImpl public fun getElementById(arg1: String?): Element = js.noImpl - public fun adoptNode(arg1: Node): Node = js.noImpl + public fun getElementsByTagName(arg1: String?): NodeList = js.noImpl + public fun getElementsByTagNameNS(arg1: String?, arg2: String?): NodeList = js.noImpl + public fun importNode(arg1: Node, arg2: Boolean): Node = js.noImpl public fun normalizeDocument(): Unit = js.noImpl public fun renameNode(arg1: Node, arg2: String?, arg3: String?): Node = js.noImpl } @@ -82,9 +82,9 @@ native public trait DocumentType: Node { native public trait DOMConfiguration { public val parameterNames: DOMStringList - public fun setParameter(arg1: String?, arg2: Any): Unit = js.noImpl - public fun getParameter(arg1: String?): Any = js.noImpl public fun canSetParameter(arg1: String?, arg2: Any): Boolean = js.noImpl + public fun getParameter(arg1: String?): Any = js.noImpl + public fun setParameter(arg1: String?, arg2: Any): Unit = js.noImpl } native public trait DOMError { @@ -108,9 +108,9 @@ native public trait DOMErrorHandler { native public trait DOMImplementation { public fun getFeature(arg1: String?, arg2: String?): Any = js.noImpl - public fun hasFeature(arg1: String?, arg2: String?): Boolean = js.noImpl - public fun createDocumentType(arg1: String?, arg2: String?, arg3: String?): DocumentType = js.noImpl public fun createDocument(arg1: String?, arg2: String?, arg3: DocumentType?): Document = js.noImpl + public fun createDocumentType(arg1: String?, arg2: String?, arg3: String?): DocumentType = js.noImpl + public fun hasFeature(arg1: String?, arg2: String?): Boolean = js.noImpl } native public trait DOMImplementationList { @@ -137,18 +137,18 @@ native public trait Element: Node { public val schemaTypeInfo: TypeInfo public val tagName: String public fun getAttribute(arg1: String?): String = js.noImpl - public fun setAttribute(arg1: String?, arg2: String?): Unit = js.noImpl - public fun removeAttribute(arg1: String?): Unit = js.noImpl public fun getElementsByTagName(arg1: String?): NodeList = js.noImpl public fun getElementsByTagNameNS(arg1: String?, arg2: String?): NodeList = js.noImpl - public fun getAttributeNode(arg1: String?): Attr = js.noImpl - public fun removeAttributeNode(arg1: Attr): Attr = js.noImpl public fun getAttributeNS(arg1: String?, arg2: String?): String = js.noImpl - public fun setAttributeNS(arg1: String?, arg2: String?, arg3: String?): Unit = js.noImpl - public fun removeAttributeNS(arg1: String?, arg2: String?): Unit = js.noImpl + public fun getAttributeNode(arg1: String?): Attr = js.noImpl public fun getAttributeNodeNS(arg1: String?, arg2: String?): Attr = js.noImpl public fun hasAttribute(arg1: String?): Boolean = js.noImpl public fun hasAttributeNS(arg1: String?, arg2: String?): Boolean = js.noImpl + public fun removeAttribute(arg1: String?): Unit = js.noImpl + public fun removeAttributeNS(arg1: String?, arg2: String?): Unit = js.noImpl + public fun removeAttributeNode(arg1: Attr): Attr = js.noImpl + public fun setAttribute(arg1: String?, arg2: String?): Unit = js.noImpl + public fun setAttributeNS(arg1: String?, arg2: String?, arg3: String?): Unit = js.noImpl public fun setIdAttribute(arg1: String?, arg2: Boolean): Unit = js.noImpl public fun setIdAttributeNS(arg1: String?, arg2: String?, arg3: Boolean): Unit = js.noImpl public fun setIdAttributeNode(arg1: Attr, arg2: Boolean): Unit = js.noImpl @@ -180,8 +180,8 @@ native public trait NamedNodeMap { public val length: Int public fun item(arg1: Int): Node = js.noImpl public fun getNamedItem(arg1: String?): Node = js.noImpl - public fun removeNamedItem(arg1: String?): Node = js.noImpl public fun getNamedItemNS(arg1: String?, arg2: String?): Node = js.noImpl + public fun removeNamedItem(arg1: String?): Node = js.noImpl public fun removeNamedItemNS(arg1: String?, arg2: String?): Node = js.noImpl public fun setNamedItem(arg1: Node): Node = js.noImpl public fun setNamedItemNS(arg1: Node): Node = js.noImpl @@ -204,24 +204,24 @@ native public trait Node { public var prefix: String public val previousSibling: Node public var textContent: String - public fun normalize(): Unit = js.noImpl public fun isSupported(arg1: String?, arg2: String?): Boolean = js.noImpl - public fun getUserData(arg1: String?): Any = js.noImpl - public fun setUserData(arg1: String?, arg2: Any, arg3: UserDataHandler): Any = js.noImpl - public fun getFeature(arg1: String?, arg2: String?): Any = js.noImpl - public fun hasAttributes(): Boolean = js.noImpl - public fun removeChild(arg1: Node): Node = js.noImpl - public fun replaceChild(arg1: Node, arg2: Node): Node = js.noImpl - public fun insertBefore(arg1: Node, arg2: Node): Node = js.noImpl + public fun normalize(): Unit = js.noImpl public fun appendChild(arg1: Node): Node = js.noImpl - public fun hasChildNodes(): Boolean = js.noImpl public fun cloneNode(arg1: Boolean): Node = js.noImpl public fun compareDocumentPosition(arg1: Node): Short = js.noImpl - public fun isSameNode(arg1: Node): Boolean = js.noImpl - public fun lookupPrefix(arg1: String?): String = js.noImpl + public fun getFeature(arg1: String?, arg2: String?): Any = js.noImpl + public fun getUserData(arg1: String?): Any = js.noImpl + public fun hasAttributes(): Boolean = js.noImpl + public fun hasChildNodes(): Boolean = js.noImpl + public fun insertBefore(arg1: Node, arg2: Node): Node = js.noImpl public fun isDefaultNamespace(arg1: String?): Boolean = js.noImpl - public fun lookupNamespaceURI(arg1: String?): String = js.noImpl public fun isEqualNode(arg1: Node): Boolean = js.noImpl + public fun isSameNode(arg1: Node): Boolean = js.noImpl + public fun lookupNamespaceURI(arg1: String?): String = js.noImpl + public fun lookupPrefix(arg1: String?): String = js.noImpl + public fun removeChild(arg1: Node): Node = js.noImpl + public fun replaceChild(arg1: Node, arg2: Node): Node = js.noImpl + public fun setUserData(arg1: String?, arg2: Any, arg3: UserDataHandler): Any = js.noImpl public class object { public val ELEMENT_NODE: Short = 1 @@ -262,9 +262,9 @@ native public trait ProcessingInstruction: Node { native public trait Text: CharacterData { public val wholeText: String - public fun splitText(arg1: Int): Text = js.noImpl public fun isElementContentWhitespace(): Boolean = js.noImpl public fun replaceWholeText(arg1: String?): Text = js.noImpl + public fun splitText(arg1: Int): Text = js.noImpl } native public trait TypeInfo { diff --git a/js/js.libraries/src/core/domEvents.kt b/js/js.libraries/src/core/domEvents.kt index eade339ff46..c761b2ed15e 100644 --- a/js/js.libraries/src/core/domEvents.kt +++ b/js/js.libraries/src/core/domEvents.kt @@ -6,7 +6,7 @@ import org.w3c.dom.views.* // -// NOTE THIS FILE IS AUTO-GENERATED by the GeneratedJavaScriptStubs.kt +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateJavaScriptStubs.kt // See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib // @@ -27,9 +27,9 @@ native public trait Event { public val eventPhase: Short public val target: EventTarget public val timeStamp: Long - public fun stopPropagation(): Unit = js.noImpl - public fun preventDefault(): Unit = js.noImpl public fun initEvent(arg1: String?, arg2: Boolean, arg3: Boolean): Unit = js.noImpl + public fun preventDefault(): Unit = js.noImpl + public fun stopPropagation(): Unit = js.noImpl public class object { public val CAPTURING_PHASE: Short = 1 @@ -39,8 +39,8 @@ native public trait Event { } native public trait EventTarget { - public fun dispatchEvent(arg1: Event?): Boolean = js.noImpl public fun addEventListener(arg1: String?, arg2: EventListener, arg3: Boolean): Unit = js.noImpl + public fun dispatchEvent(arg1: Event?): Boolean = js.noImpl public fun removeEventListener(arg1: String?, arg2: EventListener, arg3: Boolean): Unit = js.noImpl } diff --git a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt index 693c12ad4c4..f0fe2e1586e 100644 --- a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt +++ b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateJavaScriptStubs.kt @@ -63,7 +63,7 @@ package $packageName $imports // -// NOTE THIS FILE IS AUTO-GENERATED by the GeneratedJavaScriptStubs.kt +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateJavaScriptStubs.kt // See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib // From e14a6126992c921ff6b201d53801ce78e1f80b7d Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 7 Aug 2012 22:06:43 +0400 Subject: [PATCH 18/72] Removed downto cases from JS backend tests (to be restored, see KT-2586) --- .../org/jetbrains/k2js/test/semantics/RangeTest.java | 6 +----- js/js.translator/testFiles/range/cases/intDownTo.kt | 11 ----------- ...pToDownToDoNotIterate.kt => upToDoesNotIterate.kt} | 3 --- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 js/js.translator/testFiles/range/cases/intDownTo.kt rename js/js.translator/testFiles/range/cases/{upToDownToDoNotIterate.kt => upToDoesNotIterate.kt} (71%) diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java index 6fab728891a..c02601c9eea 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java @@ -49,11 +49,7 @@ public final class RangeTest extends SingleFileTranslationTest { fooBoxTest(); } - public void testIntDownTo() throws Exception { - fooBoxTest(); - } - - public void testUpToDownToDoNotIterate() throws Exception { + public void testUpToDoesNotIterate() throws Exception { fooBoxTest(); } } diff --git a/js/js.translator/testFiles/range/cases/intDownTo.kt b/js/js.translator/testFiles/range/cases/intDownTo.kt deleted file mode 100644 index a99704dc664..00000000000 --- a/js/js.translator/testFiles/range/cases/intDownTo.kt +++ /dev/null @@ -1,11 +0,0 @@ -package foo - -import java.util.ArrayList - -fun box() : Boolean { - var elems = ArrayList() - for (i in 4 downto 0) { - elems.add(i) - } - return elems[0] == 4 && elems[1] == 3 && elems[2] == 2 && elems[3] == 1 && elems[4] == 0 -} \ No newline at end of file diff --git a/js/js.translator/testFiles/range/cases/upToDownToDoNotIterate.kt b/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt similarity index 71% rename from js/js.translator/testFiles/range/cases/upToDownToDoNotIterate.kt rename to js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt index 64cbce77d29..3fa15f6168f 100644 --- a/js/js.translator/testFiles/range/cases/upToDownToDoNotIterate.kt +++ b/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt @@ -6,8 +6,5 @@ fun box() : Boolean { for (i in 0 upto -1) { return false } - for (i in 0 downto 1) { - return false - } return true } \ No newline at end of file From 662fdca034eb3789f92cbaf087a77bb45ffca846 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 7 Aug 2012 21:59:54 +0400 Subject: [PATCH 19/72] Added generator and generated for downTo() extension functions for numbers. #KT-2519 in progress --- libraries/stdlib/src/generated/DownTo.kt | 203 ++++++++++++++++++ .../jetbrains/kotlin/tools/GenerateDownTos.kt | 59 +++++ .../kotlin/tools/GenerateStandardLib.kt | 12 +- 3 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 libraries/stdlib/src/generated/DownTo.kt create mode 100644 libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt diff --git a/libraries/stdlib/src/generated/DownTo.kt b/libraries/stdlib/src/generated/DownTo.kt new file mode 100644 index 00000000000..068cde743bd --- /dev/null +++ b/libraries/stdlib/src/generated/DownTo.kt @@ -0,0 +1,203 @@ +package kotlin + +// +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + + +public inline fun Byte.downTo(to: Byte): ByteRange { + return if (this >= to) ByteRange(this, to - this - 1) else ByteRange(0, 0) +} + +public inline fun Byte.downTo(to: Char): CharRange { + return if (this >= to) CharRange(this.toChar(), to - this - 1) else CharRange(0.toChar(), 0) +} + +public inline fun Byte.downTo(to: Short): ShortRange { + return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange(0, 0) +} + +public inline fun Byte.downTo(to: Int): IntRange { + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) +} + +public inline fun Byte.downTo(to: Long): LongRange { + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) +} + +public inline fun Byte.downTo(to: Float): FloatRange { + return FloatRange(this.toFloat(), to - this) +} + +public inline fun Byte.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Char.downTo(to: Byte): CharRange { + return if (this >= to) CharRange(this, to - this - 1) else CharRange(0.toChar(), 0) +} + +public inline fun Char.downTo(to: Char): CharRange { + return if (this >= to) CharRange(this, to - this - 1) else CharRange(0.toChar(), 0) +} + +public inline fun Char.downTo(to: Short): ShortRange { + return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange(0, 0) +} + +public inline fun Char.downTo(to: Int): IntRange { + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) +} + +public inline fun Char.downTo(to: Long): LongRange { + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) +} + +public inline fun Char.downTo(to: Float): FloatRange { + return FloatRange(this.toFloat(), to - this) +} + +public inline fun Char.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Short.downTo(to: Byte): ShortRange { + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) +} + +public inline fun Short.downTo(to: Char): ShortRange { + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) +} + +public inline fun Short.downTo(to: Short): ShortRange { + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) +} + +public inline fun Short.downTo(to: Int): IntRange { + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) +} + +public inline fun Short.downTo(to: Long): LongRange { + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) +} + +public inline fun Short.downTo(to: Float): FloatRange { + return FloatRange(this.toFloat(), to - this) +} + +public inline fun Short.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Int.downTo(to: Byte): IntRange { + return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) +} + +public inline fun Int.downTo(to: Char): IntRange { + return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) +} + +public inline fun Int.downTo(to: Short): IntRange { + return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) +} + +public inline fun Int.downTo(to: Int): IntRange { + return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) +} + +public inline fun Int.downTo(to: Long): LongRange { + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) +} + +public inline fun Int.downTo(to: Float): FloatRange { + return FloatRange(this.toFloat(), to - this) +} + +public inline fun Int.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Long.downTo(to: Byte): LongRange { + return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) +} + +public inline fun Long.downTo(to: Char): LongRange { + return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) +} + +public inline fun Long.downTo(to: Short): LongRange { + return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) +} + +public inline fun Long.downTo(to: Int): LongRange { + return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) +} + +public inline fun Long.downTo(to: Long): LongRange { + return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) +} + +public inline fun Long.downTo(to: Float): FloatRange { + return FloatRange(this.toFloat(), to - this) +} + +public inline fun Long.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Float.downTo(to: Byte): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Char): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Short): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Int): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Long): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Float): FloatRange { + return FloatRange(this, to - this) +} + +public inline fun Float.downTo(to: Double): DoubleRange { + return DoubleRange(this.toDouble(), to - this) +} + +public inline fun Double.downTo(to: Byte): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Char): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Short): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Int): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Long): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Float): DoubleRange { + return DoubleRange(this, to - this) +} + +public inline fun Double.downTo(to: Double): DoubleRange { + return DoubleRange(this, to - this) +} diff --git a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt new file mode 100644 index 00000000000..e719de5f4e8 --- /dev/null +++ b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt @@ -0,0 +1,59 @@ +package org.jetbrains.kotlin.tools + +import java.io.File +import java.io.FileWriter +import java.io.PrintWriter + +private fun generateDownTos(outputFile: File, header: String) { + + private fun getMaxType(fromType: String, toType: String): String { + return when { + fromType == "Double" || toType == "Double" -> "Double" + fromType == "Float" || toType == "Float" -> "Float" + fromType == "Long" || toType == "Long" -> "Long" + fromType == "Int" || toType == "Int" -> "Int" + fromType == "Short" || toType == "Short" -> "Short" + fromType == "Char" || toType == "Char" -> "Char" + else -> "Byte" + } + } + + private fun generateDownTo(writer: PrintWriter, fromType: String, toType: String) { + val elementType = getMaxType(fromType, toType) + val rangeType = elementType + "Range" + val fromExpr = "this${ if (elementType == fromType) "" else ".to$elementType()" }" + if (elementType == "Float" || elementType == "Double") { + writer.println(""" +public inline fun $fromType.downTo(to: $toType): $rangeType { + return $rangeType($fromExpr, to - this) +}""") + } else { + // TODO use empty range constant, which is not available yet (KT-2583) + writer.println(""" +public inline fun $fromType.downTo(to: $toType): $rangeType { + return if (this >= to) $rangeType($fromExpr, to - this - 1) else $rangeType(${if (elementType == "Char") "0.toChar()" else "0"}, 0) +}""") + } + } + + println("Writing $outputFile") + + outputFile.getParentFile()?.mkdirs() + val writer = PrintWriter(FileWriter(outputFile)) + try { + writer.println(header) + + writer.println(""" +$COMMON_AUTOGENERATED_WARNING +""") + + val types = array("Byte", "Char", "Short", "Int", "Long", "Float", "Double") + for (fromType in types) { + for (toType in types) { + generateDownTo(writer, fromType, toType) + } + } + } finally { + writer.close() + } +} \ No newline at end of file diff --git a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateStandardLib.kt b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateStandardLib.kt index e24f50ffff9..6361afe4956 100644 --- a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateStandardLib.kt +++ b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateStandardLib.kt @@ -3,6 +3,11 @@ package org.jetbrains.kotlin.tools import java.io.* import java.util.List +private val COMMON_AUTOGENERATED_WARNING: String = """// +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +//""" + fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> String) { generateFile(outFile, header, arrayList(inputFile), f) } @@ -19,10 +24,7 @@ fun generateFile(outFile: File, header: String, inputFiles: List, f: (Stri for (file in inputFiles) { writer.println(""" -// -// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt -// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib -// +$COMMON_AUTOGENERATED_WARNING // Generated from input file: $file // """) @@ -158,6 +160,8 @@ fun main(args: Array) { generateFile(File(outDir, "StandardFromJUtilCollectionsJVM.kt"), "package kotlin", File(srcDir, "JUtilCollectionsJVM.kt")) { it.replaceAll("java.util.Collection Date: Tue, 7 Aug 2012 22:07:14 +0400 Subject: [PATCH 20/72] Changed usages of upto/downto in test to rangeTo and downTo, respectively. #KT-2519 in progress --- .../testData/codegen/regressions/kt1076.kt | 2 +- .../testData/codegen/regressions/kt930.kt | 76 +++++++++---------- compiler/testData/codegen/uptoDownto.kt | 4 +- .../jet/codegen/ControlStructuresTest.java | 2 +- .../jet/codegen/PrimitiveTypesTest.java | 4 - .../org/jetbrains/jet/codegen/StdlibTest.java | 4 + js/js.libraries/src/core/javautilCode.kt | 2 +- js/js.libraries/src/stdlib/jutilCode.kt | 2 +- .../testFiles/range/cases/intUpTo.kt | 2 +- .../range/cases/upToDoesNotIterate.kt | 2 +- libraries/stdlib/test/language/RangeTest.kt | 4 +- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/compiler/testData/codegen/regressions/kt1076.kt b/compiler/testData/codegen/regressions/kt1076.kt index 9d99b164039..971acf266da 100644 --- a/compiler/testData/codegen/regressions/kt1076.kt +++ b/compiler/testData/codegen/regressions/kt1076.kt @@ -1,6 +1,6 @@ fun box() : String { var cnt = 0 - for (len in 4 downto 1) { + for (len in 4 downTo 1) { cnt++ } diff --git a/compiler/testData/codegen/regressions/kt930.kt b/compiler/testData/codegen/regressions/kt930.kt index 7a567156d83..45dc1afb7c6 100644 --- a/compiler/testData/codegen/regressions/kt930.kt +++ b/compiler/testData/codegen/regressions/kt930.kt @@ -1,82 +1,82 @@ fun testInt () : String { - val r1 = 1 upto 4 - if(r1.end != 4 || r1.isReversed || r1.size != 4) return "int upto fail" + val r1 = 1 rangeTo 4 + if(r1.end != 4 || r1.isReversed || r1.size != 4) return "int rangeTo fail" - val r2 = 4 upto 1 - if(r2.start != 0 || r2.size != 0) return "int negative upto fail" + val r2 = 4 rangeTo 1 + if(r2.start != 0 || r2.size != 0) return "int negative rangeTo fail" - val r3 = 5 downto 0 - if(r3.start != 5 || r3.end != 0 || !r3.isReversed || r3.size != 6) return "int downto fail" + val r3 = 5 downTo 0 + if(r3.start != 5 || r3.end != 0 || !r3.isReversed || r3.size != 6) return "int downTo fail" - val r4 = 5 downto 6 - if(r4.start != 0 || r4.end != 0 || !r3.isReversed || r4.size != 0) return "int negative downto fail" + val r4 = 5 downTo 6 + if(r4.start != 0 || r4.end != 0 || !r3.isReversed || r4.size != 0) return "int negative downTo fail" return "OK" } fun testByte () : String { - val r1 = 1.toByte() upto 4.toByte() - if(r1.end != 4.toByte() || r1.isReversed || r1.size != 4) return "byte upto fail" + val r1 = 1.toByte() rangeTo 4.toByte() + if(r1.end != 4.toByte() || r1.isReversed || r1.size != 4) return "byte rangeTo fail" - val r2 = 4.toByte() upto 1.toByte() - if(r2.start != 0.toByte() || r2.size != 0) return "byte negative upto fail" + val r2 = 4.toByte() rangeTo 1.toByte() + if(r2.start != 0.toByte() || r2.size != 0) return "byte negative rangeTo fail" - val r3 = 5.toByte() downto 0.toByte() - if(r3.start != 5.toByte() || r3.end != 0.toByte() || !r3.isReversed || r3.size != 6) return "byte downto fail" + val r3 = 5.toByte() downTo 0.toByte() + if(r3.start != 5.toByte() || r3.end != 0.toByte() || !r3.isReversed || r3.size != 6) return "byte downTo fail" - val r4 = 5.toByte() downto 6.toByte() - if(r4.start != 0.toByte() || r4.end != 0.toByte() || !r3.isReversed || r4.size != 0) return "byte negative downto fail" + val r4 = 5.toByte() downTo 6.toByte() + if(r4.start != 0.toByte() || r4.end != 0.toByte() || !r3.isReversed || r4.size != 0) return "byte negative downTo fail" return "OK" } fun testShort () : String { - val r1 = 1.toShort() upto 4.toShort() - if(r1.end != 4.toShort() || r1.isReversed || r1.size != 4) return "short upto fail" + val r1 = 1.toShort() rangeTo 4.toShort() + if(r1.end != 4.toShort() || r1.isReversed || r1.size != 4) return "short rangeTo fail" - val r2 = 4.toShort() upto 1.toShort() - if(r2.start != 0.toShort() || r2.size != 0) return "short negative upto fail" + val r2 = 4.toShort() rangeTo 1.toShort() + if(r2.start != 0.toShort() || r2.size != 0) return "short negative rangeTo fail" - val r3 = 5.toShort() downto 0.toShort() - if(r3.start != 5.toShort() || r3.end != 0.toShort() || !r3.isReversed || r3.size != 6) return "short downto fail" + val r3 = 5.toShort() downTo 0.toShort() + if(r3.start != 5.toShort() || r3.end != 0.toShort() || !r3.isReversed || r3.size != 6) return "short downTo fail" - val r4 = 5.toShort() downto 6.toShort() - if(r4.start != 0.toShort() || r4.end != 0.toShort() || !r3.isReversed || r4.size != 0) return "short negative downto fail" + val r4 = 5.toShort() downTo 6.toShort() + if(r4.start != 0.toShort() || r4.end != 0.toShort() || !r3.isReversed || r4.size != 0) return "short negative downTo fail" return "OK" } fun testLong () : String { - val r1 = 1.toLong() upto 4.toLong() - if(r1.end != 4.toLong() || r1.isReversed || r1.size != 4.toLong()) return "long upto fail" + val r1 = 1.toLong() rangeTo 4.toLong() + if(r1.end != 4.toLong() || r1.isReversed || r1.size != 4.toLong()) return "long rangeTo fail" - val r2 = 4.toLong() upto 1.toLong() + val r2 = 4.toLong() rangeTo 1.toLong() if(r2.start != 0.toLong() || r2.size != 0.toLong()) return "short negative long fail" - val r3 = 5.toLong() downto 0.toLong() - if(r3.start != 5.toLong() || r3.end != 0.toLong() || !r3.isReversed || r3.size != 6.toLong()) return "long downto fail" + val r3 = 5.toLong() downTo 0.toLong() + if(r3.start != 5.toLong() || r3.end != 0.toLong() || !r3.isReversed || r3.size != 6.toLong()) return "long downTo fail" - val r4 = 5.toLong() downto 6.toLong() - if(r4.start != 0.toLong() || r4.end != 0.toLong() || !r3.isReversed || r4.size != 0.toLong()) return "long negative downto fail" + val r4 = 5.toLong() downTo 6.toLong() + if(r4.start != 0.toLong() || r4.end != 0.toLong() || !r3.isReversed || r4.size != 0.toLong()) return "long negative downTo fail" return "OK" } fun testChar () : String { - val r1 = 'a' upto 'd' - if(r1.end != 'd' || r1.isReversed || r1.size != 4) return "char upto fail" + val r1 = 'a' rangeTo 'd' + if(r1.end != 'd' || r1.isReversed || r1.size != 4) return "char rangeTo fail" - val r2 = 'd' upto 'a' + val r2 = 'd' rangeTo 'a' if(r2.start != 0.toChar() || r2.size != 0) return "char negative long fail" - val r3 = 'd' downto 'a' - if(r3.start != 'd' || r3.end != 'a' || !r3.isReversed || r3.size != 4) return "char downto fail" + val r3 = 'd' downTo 'a' + if(r3.start != 'd' || r3.end != 'a' || !r3.isReversed || r3.size != 4) return "char downTo fail" - val r4 = 'a' downto 'd' - if(r4.start != 0.toChar() || r4.end != 0.toChar() || !r3.isReversed || r4.size != 0) return "char negative downto fail" + val r4 = 'a' downTo 'd' + if(r4.start != 0.toChar() || r4.end != 0.toChar() || !r3.isReversed || r4.size != 0) return "char negative downTo fail" return "OK" } diff --git a/compiler/testData/codegen/uptoDownto.kt b/compiler/testData/codegen/uptoDownto.kt index fed0339d1e9..a40f8e45f08 100644 --- a/compiler/testData/codegen/uptoDownto.kt +++ b/compiler/testData/codegen/uptoDownto.kt @@ -21,12 +21,12 @@ fun box(): String { } sb.append(";") - for (i in 0 downto 0) { + for (i in 0 downTo 0) { ap(i) } sb.append(";") - for (i in 1 downto 0) { + for (i in 1 downTo 0) { ap(i) } diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 690c4cc98d0..8b656289c87 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -313,7 +313,7 @@ public class ControlStructuresTest extends CodegenTestCase { } public void testKt1076() throws Exception { - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL); blackBoxFile("regressions/kt1076.kt"); } diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index c4f451e8a9c..e7e3bfdedef 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -401,10 +401,6 @@ public class PrimitiveTypesTest extends CodegenTestCase { blackBoxFile("regressions/kt765.kt"); } - public void testKt930 () { - blackBoxFile("regressions/kt930.kt"); - } - public void testKt944 () { blackBoxFile("regressions/kt944.kt"); } diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 484790b3bc4..ff22171e551 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -345,6 +345,10 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("uptoDownto.kt"); } + public void testKt930 () { + blackBoxFile("regressions/kt930.kt"); + } + public void test1733() { blackBoxFile("regressions/kt1733.kt"); } diff --git a/js/js.libraries/src/core/javautilCode.kt b/js/js.libraries/src/core/javautilCode.kt index e8ae545c521..07be7d97c19 100644 --- a/js/js.libraries/src/core/javautilCode.kt +++ b/js/js.libraries/src/core/javautilCode.kt @@ -29,7 +29,7 @@ public object Collections { public fun reverse(list: List): Unit { val size = list.size() - for (i in 0.upto(size / 2)) { + for (i in 0.rangeTo(size / 2)) { val i2 = size - i val tmp = list[i] list[i] = list[i2] diff --git a/js/js.libraries/src/stdlib/jutilCode.kt b/js/js.libraries/src/stdlib/jutilCode.kt index 235f5e8cdd0..90218dfadec 100644 --- a/js/js.libraries/src/stdlib/jutilCode.kt +++ b/js/js.libraries/src/stdlib/jutilCode.kt @@ -10,7 +10,7 @@ public inline fun java.util.List.equals(that: List): Boolean { val s1 = this.size() val s2 = that.size() if (s1 == s2) { - for (i in 0.upto(s1)) { + for (i in 0.rangeTo(s1)) { val elem1 = this.get(i) val elem2 = that.get(i) if (elem1 != elem2) { diff --git a/js/js.translator/testFiles/range/cases/intUpTo.kt b/js/js.translator/testFiles/range/cases/intUpTo.kt index ccab799f1f7..b59e1c04e54 100644 --- a/js/js.translator/testFiles/range/cases/intUpTo.kt +++ b/js/js.translator/testFiles/range/cases/intUpTo.kt @@ -4,7 +4,7 @@ import java.util.ArrayList fun box() : Boolean { var elems = ArrayList() - for (i in 0 upto 5) { + for (i in 0 rangeTo 5) { elems.add(i) } return elems[0] == 0 && elems[1] == 1 && elems[2] == 2 && elems[3] == 3 && elems[4] == 4 && elems[5] == 5 diff --git a/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt b/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt index 3fa15f6168f..3e45a494139 100644 --- a/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt +++ b/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt @@ -3,7 +3,7 @@ package foo import java.util.ArrayList fun box() : Boolean { - for (i in 0 upto -1) { + for (i in 0 upTo -1) { return false } return true diff --git a/libraries/stdlib/test/language/RangeTest.kt b/libraries/stdlib/test/language/RangeTest.kt index 1669b9b35cb..a31c1a08042 100644 --- a/libraries/stdlib/test/language/RangeTest.kt +++ b/libraries/stdlib/test/language/RangeTest.kt @@ -5,7 +5,7 @@ import kotlin.test.* class RangeTest { test fun upRange() { - val range = 0.upto(9) + val range = 0.rangeTo(9) println("Have created up range: $range") assertEquals(10, range.size) assertTrue(range.contains(0)) @@ -15,7 +15,7 @@ class RangeTest { } test fun downRange() { - val range = 9.downto(0) + val range = 9.downTo(0) println("Have created down range: $range") assertEquals(10, range.size) assertTrue(range.contains(0)) From b1fa44aa4db6ee24e210b19c705152d9c0b85f83 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 7 Aug 2012 22:05:36 +0400 Subject: [PATCH 21/72] Removed upto() and downto() member functions from number types #KT-2519 fixed --- .../codegen/intrinsics/IntrinsicMethods.java | 7 +- .../intrinsics/{UpTo.java => RangeTo.java} | 10 +- compiler/frontend/src/jet/Numbers.jet | 112 ----- compiler/testData/builtin-classes.txt | 98 ---- .../functions/FunctionIntrinsics.java | 1 - .../functions/factories/RangesFIF.java | 36 -- runtime/src/jet/runtime/Ranges.java | 440 +++--------------- 7 files changed, 60 insertions(+), 644 deletions(-) rename compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/{UpTo.java => RangeTo.java} (82%) delete mode 100644 js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index c3dad7f1755..e3e1d3807d1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -44,8 +44,7 @@ public class IntrinsicMethods { private static final IntrinsicMethod UNARY_PLUS = new UnaryPlus(); private static final IntrinsicMethod NUMBER_CAST = new NumberCast(); private static final IntrinsicMethod INV = new Inv(); - private static final IntrinsicMethod UP_TO = new UpTo(true); - private static final IntrinsicMethod DOWN_TO = new UpTo(false); + private static final IntrinsicMethod RANGE_TO = new RangeTo(); private static final IntrinsicMethod INC = new Increment(1); private static final IntrinsicMethod DEC = new Increment(-1); private static final IntrinsicMethod HASH_CODE = new HashCode(); @@ -93,9 +92,7 @@ public class IntrinsicMethods { declareIntrinsicFunction(type, Name.identifier("plus"), 0, UNARY_PLUS); declareIntrinsicFunction(type, Name.identifier("minus"), 0, UNARY_MINUS); declareIntrinsicFunction(type, Name.identifier("inv"), 0, INV); - declareIntrinsicFunction(type, Name.identifier("rangeTo"), 1, UP_TO); - declareIntrinsicFunction(type, Name.identifier("upto"), 1, UP_TO); - declareIntrinsicFunction(type, Name.identifier("downto"), 1, DOWN_TO); + declareIntrinsicFunction(type, Name.identifier("rangeTo"), 1, RANGE_TO); declareIntrinsicFunction(type, Name.identifier("inc"), 0, INC); declareIntrinsicFunction(type, Name.identifier("dec"), 0, DEC); declareIntrinsicFunction(type, Name.identifier("hashCode"), 0, HASH_CODE); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UpTo.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java similarity index 82% rename from compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UpTo.java rename to compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java index c83e22b7c43..f145a0a976f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UpTo.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java @@ -32,11 +32,9 @@ import java.util.List; * @author yole * @author alex.tkachman */ -public class UpTo implements IntrinsicMethod { - private boolean forward; +public class RangeTo implements IntrinsicMethod { - public UpTo(boolean forward) { - this.forward = forward; + public RangeTo() { } @Override @@ -46,7 +44,7 @@ public class UpTo implements IntrinsicMethod { final Type rightType = codegen.expressionType(arguments.get(0)); receiver.put(Type.INT_TYPE, v); codegen.gen(arguments.get(0), rightType); - v.invokestatic("jet/runtime/Ranges", forward ? "upTo" : "downTo", "(" + receiver.type.getDescriptor() + leftType.getDescriptor() + ")" + expectedType.getDescriptor()); + v.invokestatic("jet/runtime/Ranges", "rangeTo", "(" + receiver.type.getDescriptor() + leftType.getDescriptor() + ")" + expectedType.getDescriptor()); return StackValue.onStack(expectedType); } else { @@ -56,7 +54,7 @@ public class UpTo implements IntrinsicMethod { // if (JetTypeMapper.isIntPrimitive(leftType)) { codegen.gen(expression.getLeft(), leftType); codegen.gen(expression.getRight(), rightType); - v.invokestatic("jet/runtime/Ranges", forward ? "upTo" : "downTo", "(" + leftType.getDescriptor() + rightType.getDescriptor() + ")" + expectedType.getDescriptor()); + v.invokestatic("jet/runtime/Ranges", "rangeTo", "(" + leftType.getDescriptor() + rightType.getDescriptor() + ")" + expectedType.getDescriptor()); return StackValue.onStack(expectedType); // } // else { diff --git a/compiler/frontend/src/jet/Numbers.jet b/compiler/frontend/src/jet/Numbers.jet index 793b09f7ebd..190d036c0ff 100644 --- a/compiler/frontend/src/jet/Numbers.jet +++ b/compiler/frontend/src/jet/Numbers.jet @@ -73,22 +73,6 @@ public class Double : Number, Comparable { public fun rangeTo(other : Byte) : DoubleRange public fun rangeTo(other : Char) : DoubleRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : DoubleRange - public fun upto(other : Long) : DoubleRange - public fun upto(other : Int) : DoubleRange - public fun upto(other : Short) : DoubleRange - public fun upto(other : Byte) : DoubleRange - public fun upto(other : Char) : DoubleRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : DoubleRange - public fun downto(other : Long) : DoubleRange - public fun downto(other : Int) : DoubleRange - public fun downto(other : Short) : DoubleRange - public fun downto(other : Byte) : DoubleRange - public fun downto(other : Char) : DoubleRange - public fun inc() : Double public fun dec() : Double public fun plus() : Double @@ -163,22 +147,6 @@ public class Float : Number, Comparable { public fun rangeTo(other : Byte) : FloatRange public fun rangeTo(other : Char) : FloatRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : DoubleRange - public fun upto(other : Int) : FloatRange - public fun upto(other : Short) : FloatRange - public fun upto(other : Byte) : FloatRange - public fun upto(other : Char) : FloatRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : DoubleRange - public fun downto(other : Int) : FloatRange - public fun downto(other : Short) : FloatRange - public fun downto(other : Byte) : FloatRange - public fun downto(other : Char) : FloatRange - public fun inc() : Float public fun dec() : Float public fun plus() : Float @@ -253,22 +221,6 @@ public class Long : Number, Comparable { public fun rangeTo(other : Byte) : LongRange public fun rangeTo(other : Char) : LongRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : LongRange - public fun upto(other : Int) : LongRange - public fun upto(other : Short) : LongRange - public fun upto(other : Byte) : LongRange - public fun upto(other : Char) : LongRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : LongRange - public fun downto(other : Int) : LongRange - public fun downto(other : Short) : LongRange - public fun downto(other : Byte) : LongRange - public fun downto(other : Char) : LongRange - public fun inc() : Long public fun dec() : Long public fun plus() : Long @@ -351,22 +303,6 @@ public class Int : Number, Comparable { public fun rangeTo(other : Byte) : IntRange public fun rangeTo(other : Char) : IntRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : LongRange - public fun upto(other : Int) : IntRange - public fun upto(other : Short) : IntRange - public fun upto(other : Byte) : IntRange - public fun upto(other : Char) : IntRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : LongRange - public fun downto(other : Int) : IntRange - public fun downto(other : Short) : IntRange - public fun downto(other : Byte) : IntRange - public fun downto(other : Char) : IntRange - public fun inc() : Int public fun dec() : Int public fun plus() : Int @@ -449,22 +385,6 @@ public class Char : Number, Comparable { public fun rangeTo(other : Byte) : CharRange public fun rangeTo(other : Char) : CharRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : LongRange - public fun upto(other : Int) : IntRange - public fun upto(other : Short) : ShortRange - public fun upto(other : Byte) : CharRange - public fun upto(other : Char) : CharRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : LongRange - public fun downto(other : Int) : IntRange - public fun downto(other : Short) : ShortRange - public fun downto(other : Byte) : CharRange - public fun downto(other : Char) : CharRange - public fun inc() : Char public fun dec() : Char public fun plus() : Int @@ -539,22 +459,6 @@ public class Short : Number, Comparable { public fun rangeTo(other : Byte) : ShortRange public fun rangeTo(other : Char) : ShortRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : LongRange - public fun upto(other : Int) : IntRange - public fun upto(other : Short) : ShortRange - public fun upto(other : Byte) : ShortRange - public fun upto(other : Char) : ShortRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : LongRange - public fun downto(other : Int) : IntRange - public fun downto(other : Short) : ShortRange - public fun downto(other : Byte) : ShortRange - public fun downto(other : Char) : ShortRange - public fun inc() : Short public fun dec() : Short public fun plus() : Short @@ -629,22 +533,6 @@ public class Byte : Number, Comparable { public fun rangeTo(other : Byte) : ByteRange public fun rangeTo(other : Char) : CharRange - public fun upto(other : Double) : DoubleRange - public fun upto(other : Float) : FloatRange - public fun upto(other : Long) : LongRange - public fun upto(other : Int) : IntRange - public fun upto(other : Short) : ShortRange - public fun upto(other : Byte) : ByteRange - public fun upto(other : Char) : CharRange - - public fun downto(other : Double) : DoubleRange - public fun downto(other : Float) : FloatRange - public fun downto(other : Long) : LongRange - public fun downto(other : Int) : IntRange - public fun downto(other : Short) : ShortRange - public fun downto(other : Byte) : ByteRange - public fun downto(other : Char) : CharRange - public fun inc() : Byte public fun dec() : Byte public fun plus() : Byte diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 51fe717d7a5..c9f6c70f358 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -54,13 +54,6 @@ public final class jet.Byte : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Int public final fun div(/*0*/ other: jet.Long): jet.Long public final fun div(/*0*/ other: jet.Short): jet.Int - public final fun downto(/*0*/ other: jet.Byte): jet.ByteRange - public final fun downto(/*0*/ other: jet.Char): jet.CharRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.IntRange - public final fun downto(/*0*/ other: jet.Long): jet.LongRange - public final fun downto(/*0*/ other: jet.Short): jet.ShortRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Byte @@ -108,13 +101,6 @@ public final class jet.Byte : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.ByteRange - public final fun upto(/*0*/ other: jet.Char): jet.CharRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.IntRange - public final fun upto(/*0*/ other: jet.Long): jet.LongRange - public final fun upto(/*0*/ other: jet.Short): jet.ShortRange } public final class jet.ByteArray : jet.Any { public final /*constructor*/ fun (/*0*/ size: jet.Int): jet.ByteArray @@ -161,13 +147,6 @@ public final class jet.Char : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Int public final fun div(/*0*/ other: jet.Long): jet.Long public final fun div(/*0*/ other: jet.Short): jet.Int - public final fun downto(/*0*/ other: jet.Byte): jet.CharRange - public final fun downto(/*0*/ other: jet.Char): jet.CharRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.IntRange - public final fun downto(/*0*/ other: jet.Long): jet.LongRange - public final fun downto(/*0*/ other: jet.Short): jet.ShortRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Char @@ -212,13 +191,6 @@ public final class jet.Char : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.CharRange - public final fun upto(/*0*/ other: jet.Char): jet.CharRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.IntRange - public final fun upto(/*0*/ other: jet.Long): jet.LongRange - public final fun upto(/*0*/ other: jet.Short): jet.ShortRange } public final class jet.CharArray : jet.Any { public final /*constructor*/ fun (/*0*/ size: jet.Int): jet.CharArray @@ -274,13 +246,6 @@ public final class jet.Double : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Double public final fun div(/*0*/ other: jet.Long): jet.Double public final fun div(/*0*/ other: jet.Short): jet.Double - public final fun downto(/*0*/ other: jet.Byte): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Char): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Int): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Long): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Short): jet.DoubleRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Double @@ -327,13 +292,6 @@ public final class jet.Double : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Char): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Int): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Long): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Short): jet.DoubleRange } public final class jet.DoubleArray : jet.Any { public final /*constructor*/ fun (/*0*/ size: jet.Int): jet.DoubleArray @@ -471,13 +429,6 @@ public final class jet.Float : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Float public final fun div(/*0*/ other: jet.Long): jet.Float public final fun div(/*0*/ other: jet.Short): jet.Float - public final fun downto(/*0*/ other: jet.Byte): jet.FloatRange - public final fun downto(/*0*/ other: jet.Char): jet.FloatRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.FloatRange - public final fun downto(/*0*/ other: jet.Long): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Short): jet.FloatRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Float @@ -525,13 +476,6 @@ public final class jet.Float : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.FloatRange - public final fun upto(/*0*/ other: jet.Char): jet.FloatRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.FloatRange - public final fun upto(/*0*/ other: jet.Long): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Short): jet.FloatRange } public final class jet.FloatArray : jet.Any { public final /*constructor*/ fun (/*0*/ size: jet.Int): jet.FloatArray @@ -674,13 +618,6 @@ public final class jet.Int : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Int public final fun div(/*0*/ other: jet.Long): jet.Long public final fun div(/*0*/ other: jet.Short): jet.Int - public final fun downto(/*0*/ other: jet.Byte): jet.IntRange - public final fun downto(/*0*/ other: jet.Char): jet.IntRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.IntRange - public final fun downto(/*0*/ other: jet.Long): jet.LongRange - public final fun downto(/*0*/ other: jet.Short): jet.IntRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Int @@ -732,13 +669,6 @@ public final class jet.Int : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.IntRange - public final fun upto(/*0*/ other: jet.Char): jet.IntRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.IntRange - public final fun upto(/*0*/ other: jet.Long): jet.LongRange - public final fun upto(/*0*/ other: jet.Short): jet.IntRange public final fun ushr(/*0*/ bits: jet.Int): jet.Int public final fun xor(/*0*/ other: jet.Int): jet.Int } @@ -796,13 +726,6 @@ public final class jet.Long : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Long public final fun div(/*0*/ other: jet.Long): jet.Long public final fun div(/*0*/ other: jet.Short): jet.Long - public final fun downto(/*0*/ other: jet.Byte): jet.LongRange - public final fun downto(/*0*/ other: jet.Char): jet.LongRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.LongRange - public final fun downto(/*0*/ other: jet.Long): jet.LongRange - public final fun downto(/*0*/ other: jet.Short): jet.LongRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Long @@ -854,13 +777,6 @@ public final class jet.Long : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.LongRange - public final fun upto(/*0*/ other: jet.Char): jet.LongRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.LongRange - public final fun upto(/*0*/ other: jet.Long): jet.LongRange - public final fun upto(/*0*/ other: jet.Short): jet.LongRange public final fun ushr(/*0*/ bits: jet.Int): jet.Long public final fun xor(/*0*/ other: jet.Long): jet.Long } @@ -928,13 +844,6 @@ public final class jet.Short : jet.Number, jet.Comparable { public final fun div(/*0*/ other: jet.Int): jet.Int public final fun div(/*0*/ other: jet.Long): jet.Long public final fun div(/*0*/ other: jet.Short): jet.Int - public final fun downto(/*0*/ other: jet.Byte): jet.ShortRange - public final fun downto(/*0*/ other: jet.Char): jet.ShortRange - public final fun downto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun downto(/*0*/ other: jet.Float): jet.FloatRange - public final fun downto(/*0*/ other: jet.Int): jet.IntRange - public final fun downto(/*0*/ other: jet.Long): jet.LongRange - public final fun downto(/*0*/ other: jet.Short): jet.ShortRange public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean public open override /*1*/ fun hashCode(): jet.Int public final fun inc(): jet.Short @@ -982,13 +891,6 @@ public final class jet.Short : jet.Number, jet.Comparable { public open override /*1*/ fun toInt(): jet.Int public open override /*1*/ fun toLong(): jet.Long public open override /*1*/ fun toShort(): jet.Short - public final fun upto(/*0*/ other: jet.Byte): jet.ShortRange - public final fun upto(/*0*/ other: jet.Char): jet.ShortRange - public final fun upto(/*0*/ other: jet.Double): jet.DoubleRange - public final fun upto(/*0*/ other: jet.Float): jet.FloatRange - public final fun upto(/*0*/ other: jet.Int): jet.IntRange - public final fun upto(/*0*/ other: jet.Long): jet.LongRange - public final fun upto(/*0*/ other: jet.Short): jet.ShortRange } public final class jet.ShortArray : jet.Any { public final /*constructor*/ fun (/*0*/ size: jet.Int): jet.ShortArray diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java index 1b0cd2b301b..2aedb944daf 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java @@ -50,7 +50,6 @@ public final class FunctionIntrinsics { register(ArrayFIF.INSTANCE); register(TopLevelFIF.INSTANCE); register(NumberConversionFIF.INSTANCE); - register(RangesFIF.INSTANCE); } private void register(@NotNull FunctionIntrinsicFactory instance) { diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java deleted file mode 100644 index d6e787d72e7..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.translate.intrinsic.functions.factories; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic; - -import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern; - -/** - * @author Pavel Talanov - */ -public final class RangesFIF extends CompositeFIF { - - @NotNull - public static final FunctionIntrinsicFactory INSTANCE = new RangesFIF(); - - private RangesFIF() { - add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1)); - add(pattern("Int.downto"), new CallStandardMethodIntrinsic("Kotlin.intDownto", true, 1)); - } -} diff --git a/runtime/src/jet/runtime/Ranges.java b/runtime/src/jet/runtime/Ranges.java index 3a4823ac94e..537e4aae7fb 100644 --- a/runtime/src/jet/runtime/Ranges.java +++ b/runtime/src/jet/runtime/Ranges.java @@ -28,7 +28,7 @@ public class Ranges { private Ranges() { } - public static ByteRange upTo(byte from, byte to) { + public static ByteRange rangeTo(byte from, byte to) { if (from > to) { return ByteRange.empty; } @@ -37,16 +37,7 @@ public class Ranges { } } - public static ByteRange downTo(byte from, byte to) { - if (from >= to) { - return new ByteRange(from, to - from - 1); - } - else { - return ByteRange.empty; - } - } - - public static ShortRange upTo(byte from, short to) { + public static ShortRange rangeTo(byte from, short to) { if (from > to) { return ShortRange.empty; } @@ -55,16 +46,7 @@ public class Ranges { } } - public static ShortRange downTo(byte from, short to) { - if (from >= to) { - return new ShortRange(from, to - from - 1); - } - else { - return ShortRange.empty; - } - } - - public static IntRange upTo(byte from, int to) { + public static IntRange rangeTo(byte from, int to) { if (from > to) { return IntRange.empty; } @@ -73,16 +55,7 @@ public class Ranges { } } - public static IntRange downTo(byte from, int to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static LongRange upTo(byte from, long to) { + public static LongRange rangeTo(byte from, long to) { if (from > to) { return LongRange.empty; } @@ -91,32 +64,15 @@ public class Ranges { } } - public static LongRange downTo(byte from, long to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(byte from, float to) { + public static FloatRange rangeTo(byte from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(byte from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(byte from, double to) { + public static DoubleRange rangeTo(byte from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(byte from, double to) { - return new DoubleRange(from, to - from); - } - - public static CharRange upTo(byte from, char to) { + public static CharRange rangeTo(byte from, char to) { if (from > to) { return CharRange.empty; } @@ -125,16 +81,7 @@ public class Ranges { } } - public static CharRange downTo(byte from, char to) { - if (from >= to) { - return new CharRange((char) from, to - from - 1); - } - else { - return CharRange.empty; - } - } - - public static ShortRange upTo(short from, byte to) { + public static ShortRange rangeTo(short from, byte to) { if (from > to) { return ShortRange.empty; } @@ -143,16 +90,7 @@ public class Ranges { } } - public static ShortRange downTo(short from, byte to) { - if (from >= to) { - return new ShortRange(from, to - from - 1); - } - else { - return ShortRange.empty; - } - } - - public static ShortRange upTo(short from, short to) { + public static ShortRange rangeTo(short from, short to) { if (from > to) { return ShortRange.empty; } @@ -161,16 +99,7 @@ public class Ranges { } } - public static ShortRange downTo(short from, short to) { - if (from >= to) { - return new ShortRange(from, to - from - 1); - } - else { - return ShortRange.empty; - } - } - - public static IntRange upTo(short from, int to) { + public static IntRange rangeTo(short from, int to) { if (from > to) { return IntRange.empty; } @@ -179,16 +108,7 @@ public class Ranges { } } - public static IntRange downTo(short from, int to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static LongRange upTo(short from, long to) { + public static LongRange rangeTo(short from, long to) { if (from > to) { return LongRange.empty; } @@ -197,32 +117,15 @@ public class Ranges { } } - public static LongRange downTo(short from, long to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(short from, float to) { + public static FloatRange rangeTo(short from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(short from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(short from, double to) { + public static DoubleRange rangeTo(short from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(short from, double to) { - return new DoubleRange(from, to - from); - } - - public static ShortRange upTo(short from, char to) { + public static ShortRange rangeTo(short from, char to) { if (from > to) { return ShortRange.empty; } @@ -231,16 +134,7 @@ public class Ranges { } } - public static ShortRange downTo(short from, char to) { - if (from >= to) { - return new ShortRange(from, to - from - 1); - } - else { - return ShortRange.empty; - } - } - - public static IntRange upTo(int from, byte to) { + public static IntRange rangeTo(int from, byte to) { if (from > to) { return IntRange.empty; } @@ -249,16 +143,7 @@ public class Ranges { } } - public static IntRange downTo(int from, byte to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static IntRange upTo(int from, short to) { + public static IntRange rangeTo(int from, short to) { if (from > to) { return IntRange.empty; } @@ -267,16 +152,7 @@ public class Ranges { } } - public static IntRange downTo(int from, short to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static IntRange upTo(int from, int to) { + public static IntRange rangeTo(int from, int to) { if (from > to) { return IntRange.empty; } @@ -285,16 +161,7 @@ public class Ranges { } } - public static IntRange downTo(int from, int to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static LongRange upTo(int from, long to) { + public static LongRange rangeTo(int from, long to) { if (from > to) { return LongRange.empty; } @@ -303,32 +170,15 @@ public class Ranges { } } - public static LongRange downTo(int from, long to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(int from, float to) { + public static FloatRange rangeTo(int from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(int from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(int from, double to) { + public static DoubleRange rangeTo(int from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(int from, double to) { - return new DoubleRange(from, to - from); - } - - public static IntRange upTo(int from, char to) { + public static IntRange rangeTo(int from, char to) { if (from > to) { return IntRange.empty; } @@ -337,16 +187,7 @@ public class Ranges { } } - public static IntRange downTo(int from, char to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static LongRange upTo(long from, byte to) { + public static LongRange rangeTo(long from, byte to) { if (from > to) { return LongRange.empty; } @@ -355,16 +196,7 @@ public class Ranges { } } - public static LongRange downTo(long from, byte to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static LongRange upTo(long from, short to) { + public static LongRange rangeTo(long from, short to) { if (from > to) { return LongRange.empty; } @@ -373,16 +205,7 @@ public class Ranges { } } - public static LongRange downTo(long from, short to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static LongRange upTo(long from, int to) { + public static LongRange rangeTo(long from, int to) { if (from > to) { return LongRange.empty; } @@ -391,16 +214,7 @@ public class Ranges { } } - public static LongRange downTo(long from, int to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static LongRange upTo(long from, long to) { + public static LongRange rangeTo(long from, long to) { if (from > to) { return LongRange.empty; } @@ -409,32 +223,15 @@ public class Ranges { } } - public static LongRange downTo(long from, long to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(long from, float to) { + public static FloatRange rangeTo(long from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(long from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(long from, double to) { + public static DoubleRange rangeTo(long from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(long from, double to) { - return new DoubleRange(from, to - from); - } - - public static LongRange upTo(long from, char to) { + public static LongRange rangeTo(long from, char to) { if (from > to) { return LongRange.empty; } @@ -443,128 +240,63 @@ public class Ranges { } } - public static LongRange downTo(long from, char to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(float from, byte to) { + public static FloatRange rangeTo(float from, byte to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(float from, byte to) { + public static FloatRange rangeTo(float from, short to) { return new FloatRange(from, to - from); } - public static FloatRange upTo(float from, short to) { + public static FloatRange rangeTo(float from, int to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(float from, short to) { + public static FloatRange rangeTo(float from, long to) { return new FloatRange(from, to - from); } - public static FloatRange upTo(float from, int to) { + public static FloatRange rangeTo(float from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(float from, int to) { + public static DoubleRange rangeTo(float from, double to) { + return new DoubleRange(from, to - from); + } + + public static FloatRange rangeTo(float from, char to) { return new FloatRange(from, to - from); } - public static FloatRange upTo(float from, long to) { - return new FloatRange(from, to - from); - } - - public static FloatRange downTo(float from, long to) { - return new FloatRange(from, to - from); - } - - public static FloatRange upTo(float from, float to) { - return new FloatRange(from, to - from); - } - - public static FloatRange downTo(float from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(float from, double to) { + public static DoubleRange rangeTo(double from, byte to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(float from, double to) { + public static DoubleRange rangeTo(double from, short to) { return new DoubleRange(from, to - from); } - public static FloatRange upTo(float from, char to) { - return new FloatRange(from, to - from); - } - - public static FloatRange downTo(float from, char to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(double from, byte to) { + public static DoubleRange rangeTo(double from, int to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(double from, byte to) { + public static DoubleRange rangeTo(double from, long to) { return new DoubleRange(from, to - from); } - public static DoubleRange upTo(double from, short to) { + public static DoubleRange rangeTo(double from, float to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(double from, short to) { + public static DoubleRange rangeTo(double from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange upTo(double from, int to) { + public static DoubleRange rangeTo(double from, char to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(double from, int to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange upTo(double from, long to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange downTo(double from, long to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange upTo(double from, float to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange downTo(double from, float to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange upTo(double from, double to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange downTo(double from, double to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange upTo(double from, char to) { - return new DoubleRange(from, to - from); - } - - public static DoubleRange downTo(double from, char to) { - return new DoubleRange(from, to - from); - } - - public static CharRange upTo(char from, byte to) { + public static CharRange rangeTo(char from, byte to) { if (from > to) { return CharRange.empty; } @@ -573,16 +305,7 @@ public class Ranges { } } - public static CharRange downTo(char from, byte to) { - if (from >= to) { - return new CharRange(from, to - from - 1); - } - else { - return CharRange.empty; - } - } - - public static ShortRange upTo(char from, short to) { + public static ShortRange rangeTo(char from, short to) { if (from > to) { return ShortRange.empty; } @@ -591,16 +314,7 @@ public class Ranges { } } - public static ShortRange downTo(char from, short to) { - if (from >= to) { - return new ShortRange((short) from, to - from - 1); - } - else { - return ShortRange.empty; - } - } - - public static IntRange upTo(char from, int to) { + public static IntRange rangeTo(char from, int to) { if (from > to) { return IntRange.empty; } @@ -609,16 +323,7 @@ public class Ranges { } } - public static IntRange downTo(char from, int to) { - if (from >= to) { - return new IntRange(from, to - from - 1); - } - else { - return IntRange.empty; - } - } - - public static LongRange upTo(char from, long to) { + public static LongRange rangeTo(char from, long to) { if (from > to) { return LongRange.empty; } @@ -627,32 +332,15 @@ public class Ranges { } } - public static LongRange downTo(char from, long to) { - if (from >= to) { - return new LongRange(from, to - from - 1); - } - else { - return LongRange.empty; - } - } - - public static FloatRange upTo(char from, float to) { + public static FloatRange rangeTo(char from, float to) { return new FloatRange(from, to - from); } - public static FloatRange downTo(char from, float to) { - return new FloatRange(from, to - from); - } - - public static DoubleRange upTo(char from, double to) { + public static DoubleRange rangeTo(char from, double to) { return new DoubleRange(from, to - from); } - public static DoubleRange downTo(char from, double to) { - return new DoubleRange(from, to - from); - } - - public static CharRange upTo(char from, char to) { + public static CharRange rangeTo(char from, char to) { if (from > to) { return CharRange.empty; } @@ -661,15 +349,6 @@ public class Ranges { } } - public static CharRange downTo(char from, char to) { - if (from >= to) { - return new CharRange(from, to - from - 1); - } - else { - return CharRange.empty; - } - } - public static void main(String[] args) { List strings = Arrays.asList("byte", "short", "int", "long", "float", "double", "char"); for (String t1 : strings) { @@ -698,15 +377,12 @@ public class Ranges { } if (resType.equals("FloatRange") || resType.equals("DoubleRange")) { - System.out.println("\npublic static " + resType + " upTo(" + t1 + " from, " + t2 + " to) {\n" + - " return new " + resType + "(from, to-from);\n" + - "}"); - System.out.println("\npublic static " + resType + " downTo(" + t1 + " from, " + t2 + " to) {\n" + + System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {\n" + " return new " + resType + "(from, to-from);\n" + "}"); } else { - System.out.println("\npublic static " + resType + " upTo(" + t1 + " from, " + t2 + " to) {" + + System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {" + "\n if(from > to) {\n" + " return " + resType + ".empty;\n" + " }\n" + @@ -714,14 +390,6 @@ public class Ranges { " return new " + resType + "(from, to-from+1);\n" + " }\n" + "}"); - System.out.println("\npublic static " + resType + " downTo(" + t1 + " from, " + t2 + " to) {" + - "\n if(from >= to) {\n" + - " return new " + resType + "(from, to-from-1);\n" + - " }\n" + - " else {\n" + - " return " + resType + ".empty;\n" + - " }\n" + - "}"); } } } From 8d6b16eb23e48a5a823cfcea33dc44b7e956f9d4 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 7 Aug 2012 21:31:05 +0400 Subject: [PATCH 22/72] Equals for JetLightClass --- .../jetbrains/jet/asJava/JetLightClass.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java index cd9b022131f..2f432a6a288 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java @@ -46,7 +46,9 @@ import org.jetbrains.jet.lang.psi.JetClass; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFunction; import org.jetbrains.jet.lang.psi.JetPsiUtil; -import org.jetbrains.jet.lang.resolve.java.*; +import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; +import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; +import org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.plugin.JetLanguage; import org.jetbrains.jet.util.QualifiedNamesUtil; @@ -236,6 +238,30 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa } } + @Override + public int hashCode() { + int result = getManager().hashCode(); + result = 31 * result + file.hashCode(); + result = 31 * result + qualifiedName.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + JetLightClass lightClass = (JetLightClass) obj; + + if (getManager() != lightClass.getManager()) return false; + if (!file.equals(lightClass.file)) return false; + if (!qualifiedName.equals(lightClass.qualifiedName)) return false; + + return true; + } + public static JetLightClass wrapDelegate(JetClass jetClass) { return new JetLightClass(jetClass.getManager(), (JetFile) jetClass.getContainingFile(), JetPsiUtil.getFQName(jetClass)); } From 0faea1ed0b818068c07791695ac55f0966dae926 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 8 Aug 2012 15:22:27 +0400 Subject: [PATCH 23/72] Chain scope for merging in lazy package descriptor --- .../resolve/lazy/LazyPackageDescriptor.java | 13 +++++----- .../jet/lang/resolve/scopes/ChainedScope.java | 2 +- .../namespaceComparator/objectMembers.kt | 7 +++++ .../namespaceComparator/objectMembers.txt | 7 +++++ .../packageLevelObject.txt | 3 +++ ...esolveNamespaceComparingTestGenerated.java | 14 ++++++---- .../jet/test/util/NamespaceComparator.java | 26 ++++++++++++++++--- 7 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 compiler/testData/lazyResolve/namespaceComparator/objectMembers.kt create mode 100644 compiler/testData/lazyResolve/namespaceComparator/objectMembers.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyPackageDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyPackageDescriptor.java index af7f58d4c92..d8e44f28cd4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyPackageDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyPackageDescriptor.java @@ -24,10 +24,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; -import org.jetbrains.jet.lang.resolve.scopes.WritableScope; -import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; +import org.jetbrains.jet.lang.resolve.scopes.*; import java.util.Collections; @@ -44,12 +41,14 @@ public class LazyPackageDescriptor extends AbstractNamespaceDescriptorImpl imple @NotNull PackageMemberDeclarationProvider declarationProvider ) { super(containingDeclaration, Collections.emptyList(), name); + WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Package scope"); resolveSession.getModuleConfiguration().extendNamespaceScope(resolveSession.getTrace(), this, scope); - LazyPackageMemberScope lazyPackageMemberScope = new LazyPackageMemberScope(resolveSession, declarationProvider, this); - scope.importScope(lazyPackageMemberScope); scope.changeLockLevel(WritableScope.LockLevel.READING); - this.memberScope = scope; + + LazyPackageMemberScope lazyPackageMemberScope = new LazyPackageMemberScope(resolveSession, declarationProvider, this); + + this.memberScope = new ChainedScope(containingDeclaration, lazyPackageMemberScope, scope); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java index b34b69fb10b..5881ce61ec9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java @@ -118,7 +118,7 @@ public class ChainedScope implements JetScope { @NotNull @Override public ReceiverDescriptor getImplicitReceiver() { - throw new UnsupportedOperationException(); // TODO + return ReceiverDescriptor.NO_RECEIVER; } @Override diff --git a/compiler/testData/lazyResolve/namespaceComparator/objectMembers.kt b/compiler/testData/lazyResolve/namespaceComparator/objectMembers.kt new file mode 100644 index 00000000000..a05a78d2382 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/objectMembers.kt @@ -0,0 +1,7 @@ +package test + +object SomeObject { + fun test(a: Int) : Int { + return 0 + } +} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/objectMembers.txt b/compiler/testData/lazyResolve/namespaceComparator/objectMembers.txt new file mode 100644 index 00000000000..b40fc620291 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/objectMembers.txt @@ -0,0 +1,7 @@ +namespace test + +internal final object test.SomeObject : jet.Any { + internal final /*constructor*/ fun (): test.SomeObject + internal final fun test(/*0*/ a: jet.Int): jet.Int +} +internal final val SomeObject: test.SomeObject diff --git a/compiler/testData/lazyResolve/namespaceComparator/packageLevelObject.txt b/compiler/testData/lazyResolve/namespaceComparator/packageLevelObject.txt index bff1bb4b0d3..afc53292714 100644 --- a/compiler/testData/lazyResolve/namespaceComparator/packageLevelObject.txt +++ b/compiler/testData/lazyResolve/namespaceComparator/packageLevelObject.txt @@ -1,3 +1,6 @@ namespace test +internal final object test.Bar : jet.Any { + internal final /*constructor*/ fun (): test.Bar +} internal final val Bar: test.Bar diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 9be5d5928fd..92732d8f83f 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -15,15 +15,12 @@ */ package org.jetbrains.jet.lang.resolve.lazy; -import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestSuite; - -import java.io.File; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.test.TestMetadata; -import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest; +import java.io.File; /** This class is generated by {@link org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest}. DO NOT MODIFY MANUALLY */ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyResolveNamespaceComparingTest { @@ -1272,7 +1269,9 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso @TestMetadata("compiler/testData/lazyResolve/namespaceComparator") public static class NamespaceComparator extends AbstractLazyResolveNamespaceComparingTest { public void testAllFilesPresentInNamespaceComparator() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest", new File("compiler/testData/lazyResolve/namespaceComparator"), "kt", false); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), + "org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest", + new File("compiler/testData/lazyResolve/namespaceComparator"), "kt", false); } @TestMetadata("enum.kt") @@ -1295,6 +1294,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/innerObject.kt"); } + @TestMetadata("objectMembers.kt") + public void testObjectMembers() throws Exception { + doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/objectMembers.kt"); + } + @TestMetadata("OverrideWithErrors.kt") public void testOverrideWithErrors() throws Exception { doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/OverrideWithErrors.kt"); diff --git a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java index 6f4c235c41d..df905e87823 100644 --- a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java +++ b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java @@ -20,6 +20,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.codegen.PropertyCodegen; @@ -125,9 +126,10 @@ public class NamespaceComparator { //deferred.assertTrue("namespace " + nsa.getName() + " is empty", !nsa.getMemberScope().getAllDescriptors().isEmpty()); - Set classifierNames = new HashSet(); - Set propertyNames = new HashSet(); - Set functionNames = new HashSet(); + Set classifierNames = Sets.newHashSet(); + Set propertyNames = Sets.newHashSet(); + Set functionNames = Sets.newHashSet(); + Set objectNames = Sets.newHashSet(); for (DeclarationDescriptor ad : nsa.getMemberScope().getAllDescriptors()) { if (ad instanceof ClassifierDescriptor) { @@ -162,6 +164,10 @@ public class NamespaceComparator { } } + for (ClassDescriptor objectDescriptor : nsa.getMemberScope().getObjectDescriptors()) { + objectNames.add(objectDescriptor.getName()); + } + for (Name name : sorted(classifierNames)) { ClassifierDescriptor ca = nsa.getMemberScope().getClassifier(name); ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name); @@ -170,6 +176,14 @@ public class NamespaceComparator { compareClassifiers(ca, cb, sb); } + for (Name name : sorted(objectNames)) { + ClassifierDescriptor ca = nsa.getMemberScope().getObjectDescriptor(name); + ClassifierDescriptor cb = nsb.getMemberScope().getObjectDescriptor(name); + deferred.assertTrue("Object not found in " + nsa + ": " + name, ca != null); + deferred.assertTrue("Object not found in " + nsb + ": " + name, cb != null); + compareClassifiers(ca, cb, sb); + } + for (Name name : sorted(propertyNames)) { Collection pa = nsa.getMemberScope().getProperties(name); Collection pb = nsb.getMemberScope().getProperties(name); @@ -729,6 +743,12 @@ public class NamespaceComparator { memberStrings.add(memberSb.toString()); } + //for (DeclarationDescriptor object : memberScope.getObjectDescriptors()) { + // StringBuilder objectSb = new StringBuilder(); + // new FullContentSerialier(objectSb).serialize(object); + // memberStrings.add(objectSb.toString()); + //} + Collections.sort(memberStrings, new MemberComparator()); for (String memberString : memberStrings) { From e5119da97a67d304d96b25093ba8de617a2c0ba3 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 8 Aug 2012 15:09:19 +0400 Subject: [PATCH 24/72] Multiple fixes for try-catch-finally codegen #KT-2259 Fixed #KT-2577 Fixed --- .../jet/codegen/ExpressionCodegen.java | 42 ++++++++++++++++--- .../controlStructures/tryCatchFinallyChain.kt | 19 +++++++++ .../testData/codegen/regressions/kt2259.kt | 10 +++++ .../testData/codegen/regressions/kt2577.kt | 12 ++++++ .../jet/codegen/ControlStructuresTest.java | 15 +++++++ 5 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/codegen/controlStructures/tryCatchFinallyChain.kt create mode 100644 compiler/testData/codegen/regressions/kt2259.kt create mode 100644 compiler/testData/codegen/regressions/kt2577.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 5f30fb424cc..4e822fca3aa 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2717,25 +2717,38 @@ The "returned" value of try expression with no finally is either the last expres (or blocks). */ JetFinallySection finallyBlock = expression.getFinallyBlock(); + FinallyBlockStackElement finallyBlockStackElement = null; if (finallyBlock != null) { - blockStackElements.push(new FinallyBlockStackElement(expression)); + finallyBlockStackElement = new FinallyBlockStackElement(expression); + blockStackElements.push(finallyBlockStackElement); } JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); Type expectedAsmType = asmType(jetType); - + Label tryStart = new Label(); v.mark(tryStart); v.nop(); // prevent verify error on empty try + gen(expression.getTryBlock(), expectedAsmType); + + int savedValue = myFrameMap.enterTemp(expectedAsmType.getSize()); + v.store(savedValue, expectedAsmType); + Label tryEnd = new Label(); v.mark(tryEnd); if (finallyBlock != null) { + blockStackElements.pop(); gen(finallyBlock.getFinalExpression(), Type.VOID_TYPE); + blockStackElements.push(finallyBlockStackElement); } Label end = new Label(); - v.goTo(end); // TODO don't generate goto if there's no code following try/catch - for (JetCatchClause clause : expression.getCatchClauses()) { + v.goTo(end); + + List clauses = expression.getCatchClauses(); + for (int i = 0, size = clauses.size(); i < size; i++) { + JetCatchClause clause = clauses.get(i); + Label clauseStart = new Label(); v.mark(clauseStart); @@ -2748,28 +2761,45 @@ The "returned" value of try expression with no finally is either the last expres gen(clause.getCatchBody(), expectedAsmType); + v.store(savedValue, expectedAsmType); + myFrameMap.leave(descriptor); if (finallyBlock != null) { + blockStackElements.pop(); gen(finallyBlock.getFinalExpression(), Type.VOID_TYPE); + blockStackElements.push(finallyBlockStackElement); } - v.goTo(end); // TODO don't generate goto if there's no code following try/catch + if (i != size - 1 || finallyBlock != null) { + v.goTo(end); + } v.visitTryCatchBlock(tryStart, tryEnd, clauseStart, descriptorType.getInternalName()); } + if (finallyBlock != null) { Label finallyStart = new Label(); v.mark(finallyStart); + int savedException = myFrameMap.enterTemp(); + v.store(savedException, TYPE_THROWABLE); + + blockStackElements.pop(); gen(finallyBlock.getFinalExpression(), Type.VOID_TYPE); + blockStackElements.push(finallyBlockStackElement); + + v.load(savedException, TYPE_THROWABLE); + myFrameMap.leaveTemp(); v.athrow(); v.visitTryCatchBlock(tryStart, tryEnd, finallyStart, null); } v.mark(end); - v.nop(); + + v.load(savedValue, expectedAsmType); + myFrameMap.leaveTemp(expectedAsmType.getSize()); if (finallyBlock != null) { blockStackElements.pop(); diff --git a/compiler/testData/codegen/controlStructures/tryCatchFinallyChain.kt b/compiler/testData/codegen/controlStructures/tryCatchFinallyChain.kt new file mode 100644 index 00000000000..b0ee1f314dc --- /dev/null +++ b/compiler/testData/codegen/controlStructures/tryCatchFinallyChain.kt @@ -0,0 +1,19 @@ +fun box() : String { + try { + } finally { + try { + try { + } finally { + try { + } finally { + } + } + } catch (e: Exception) { + try { + } catch (f: Exception) { + } finally { + } + } + return "OK" + } +} diff --git a/compiler/testData/codegen/regressions/kt2259.kt b/compiler/testData/codegen/regressions/kt2259.kt new file mode 100644 index 00000000000..7b695efee06 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2259.kt @@ -0,0 +1,10 @@ +fun main(args: Array) { + try { + } finally { + try { + } catch (e: Throwable) { + } + } +} + +fun box() = "OK" diff --git a/compiler/testData/codegen/regressions/kt2577.kt b/compiler/testData/codegen/regressions/kt2577.kt new file mode 100644 index 00000000000..c11ba235411 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2577.kt @@ -0,0 +1,12 @@ +fun foo(): Int { + try { + } finally { + try { + return 1 + } catch (e: Throwable) { + return 2 + } + } +} + +fun box() = if (foo() == 1) "OK" else "Fail" diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 8b656289c87..51f30277962 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -376,4 +376,19 @@ public class ControlStructuresTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxFile("regressions/kt2291.kt"); } + + public void testKt2259() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2259.kt"); + } + + public void testKt2577() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2577.kt"); + } + + public void testTryCatchFinallyChain() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("controlStructures/tryCatchFinallyChain.kt"); + } } From 4f68b926fbd28d7729c06243941418500b721c22 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 15:37:39 +0400 Subject: [PATCH 25/72] Fixed RangeTest. --- .../test/org/jetbrains/k2js/test/semantics/RangeTest.java | 2 +- .../cases/{upToDoesNotIterate.kt => rangeToDoesNotIterate.kt} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename js/js.translator/testFiles/range/cases/{upToDoesNotIterate.kt => rangeToDoesNotIterate.kt} (77%) diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java index c02601c9eea..b95d568d197 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java @@ -49,7 +49,7 @@ public final class RangeTest extends SingleFileTranslationTest { fooBoxTest(); } - public void testUpToDoesNotIterate() throws Exception { + public void testRangeToDoesNotIterate() throws Exception { fooBoxTest(); } } diff --git a/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt b/js/js.translator/testFiles/range/cases/rangeToDoesNotIterate.kt similarity index 77% rename from js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt rename to js/js.translator/testFiles/range/cases/rangeToDoesNotIterate.kt index 3e45a494139..a319283e54d 100644 --- a/js/js.translator/testFiles/range/cases/upToDoesNotIterate.kt +++ b/js/js.translator/testFiles/range/cases/rangeToDoesNotIterate.kt @@ -3,7 +3,7 @@ package foo import java.util.ArrayList fun box() : Boolean { - for (i in 0 upTo -1) { + for (i in 0 rangeTo -1) { return false } return true From 16bcc7967e270aa6a33b11b833d550016e01ffee Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Wed, 8 Aug 2012 16:39:12 +0400 Subject: [PATCH 26/72] Fixed KT-2543 Constructor and function parameter annotations are ignored --- .../jet/codegen/AnnotationCodegen.java | 9 +++ .../jet/codegen/ClassBodyCodegen.java | 4 +- .../jet/codegen/FunctionCodegen.java | 3 +- .../codegen/ImplementationBodyCodegen.java | 1 + .../jet/codegen/AnnotationGenTest.java | 71 +++++++++++++++++++ 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java index fc649982437..ade7c42458c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java @@ -233,4 +233,13 @@ public abstract class AnnotationCodegen { } }; } + + public static AnnotationCodegen forParameter(final int parameter, final MethodVisitor mv, JetTypeMapper mapper) { + return new AnnotationCodegen(mapper) { + @Override + AnnotationVisitor visitAnnotation(String descr, boolean visible) { + return mv.visitParameterAnnotation(parameter, descr, visible); + } + }; + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java index 840c48b01fa..0c64361d3fc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java @@ -16,6 +16,7 @@ package org.jetbrains.jet.codegen; +import org.jetbrains.asm4.FieldVisitor; import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.Opcodes; import org.jetbrains.asm4.Type; @@ -117,7 +118,8 @@ public abstract class ClassBodyCodegen { modifiers |= Opcodes.ACC_VOLATILE; } Type type = state.getInjector().getJetTypeMapper().mapType(propertyDescriptor.getType(), MapTypeMode.VALUE); - v.newField(p, modifiers, p.getName(), type.getDescriptor(), null, null); + FieldVisitor fieldVisitor = v.newField(p, modifiers, p.getName(), type.getDescriptor(), null, null); + AnnotationCodegen.forField(fieldVisitor, state.getInjector().getJetTypeMapper()).genAnnotations(propertyDescriptor); } } else { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 0920d789efb..a745a601f41 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -170,8 +170,9 @@ public class FunctionCodegen { av.visitEnd(); } for(int i = 0; i != paramDescrs.size(); ++i) { - JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i + start); ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i); + AnnotationCodegen.forParameter(i, mv, state.getInjector().getJetTypeMapper()).genAnnotations(parameterDescriptor); + JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i + start); av.writeName(parameterDescriptor.getName().getName()); av.writeHasDefaultValue(parameterDescriptor.declaresDefaultValue()); av.writeNullable(parameterDescriptor.getType().isNullable()); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index c03ef9aee18..36e3b05e7d6 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -594,6 +594,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } for (ValueParameterDescriptor valueParameter : constructorDescriptor.getValueParameters()) { + AnnotationCodegen.forParameter(i, mv, state.getInjector().getJetTypeMapper()).genAnnotations(valueParameter); JetValueParameterAnnotationWriter jetValueParameterAnnotation = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i); jetValueParameterAnnotation.writeName(valueParameter.getName().getName()); jetValueParameterAnnotation.writeHasDefaultValue(valueParameter.declaresDefaultValue()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java index 26b983ab965..a571db0ef1b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java @@ -60,6 +60,77 @@ public class AnnotationGenTest extends CodegenTestCase { assertNull(aClass.getDeclaredField("x").getAnnotation(Deprecated.class)); } + public void testAnnotationForParamInGlobalFunction() throws NoSuchFieldException, NoSuchMethodException { + loadText("fun x([Deprecated] i: Int) {}"); + Class aClass = generateNamespaceClass(); + Method x = aClass.getMethod("x", int.class); + assertNotNull(x); + // Get annotations for first parameter + Annotation[] annotations = x.getParameterAnnotations()[0]; + assertNotNull(getDeprecatedAnnotationFromList(annotations)); + } + + public void testAnnotationForParamInLocalFunction() throws NoSuchFieldException, NoSuchMethodException { + loadText("class A() { fun x([Deprecated] i: Int) {}}"); + Class aClass = generateClass("A"); + Method x = aClass.getMethod("x", int.class); + assertNotNull(x); + // Get annotations for first parameter + Annotation[] annotations = x.getParameterAnnotations()[0]; + assertNotNull(getDeprecatedAnnotationFromList(annotations)); + } + + public void testParamInConstructor() throws NoSuchFieldException, NoSuchMethodException { + loadText("class A ([Deprecated] x: Int) {}"); + Class aClass = generateClass("A"); + Constructor constructor = aClass.getDeclaredConstructor(int.class); + assertNotNull(constructor); + // Get annotations for first parameter + Annotation[] annotations = constructor.getParameterAnnotations()[0]; + assertNotNull(getDeprecatedAnnotationFromList(annotations)); + } + + public void testPropFieldInConstructor() throws NoSuchFieldException, NoSuchMethodException { + loadText("class A ([Deprecated] var x: Int) {}"); + Class aClass = generateClass("A"); + Constructor constructor = aClass.getDeclaredConstructor(int.class); + assertNotNull(constructor); + // Get annotations for first parameter + Annotation[] annotations = constructor.getParameterAnnotations()[0]; + assertNotNull(getDeprecatedAnnotationFromList(annotations)); + assertNull(aClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class)); + assertNull(aClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class)); + assertNotNull(aClass.getDeclaredField("x").getAnnotation(Deprecated.class)); + } + + public void testAnnotationWithParamForParamInFunction() throws NoSuchFieldException, NoSuchMethodException { + loadText("import java.lang.annotation.*\n" + + "Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" + + "fun x(A(\"239\") i: Int) {}"); + Class aClass = generateNamespaceClass(); + Method x = aClass.getMethod("x", int.class); + assertNotNull(x); + // Get annotations for first parameter + Annotation[] annotations = x.getParameterAnnotations()[0]; + Annotation resultAnnotation = null; + for (Annotation annotation : annotations) { + if (annotation.annotationType().getCanonicalName().equals("A")) { + resultAnnotation = annotation; + break; + } + } + assertNotNull(resultAnnotation); + } + + private Deprecated getDeprecatedAnnotationFromList(Annotation[] annotations) { + for (Annotation annotation : annotations) { + if (annotation instanceof Deprecated) { + return (Deprecated) annotation; + } + } + return null; + } + public void testConstructor() throws NoSuchFieldException, NoSuchMethodException { loadText("class A [Deprecated] () {}"); Class aClass = generateClass("A"); From 8ad88498535aa44e8ca4405511c4bafa643b006e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 16:03:55 +0400 Subject: [PATCH 27/72] renamed myMethod -> method --- .../org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java index c8866f2229b..08ef6dbb284 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java @@ -32,16 +32,16 @@ import java.util.List; * @author alex.tkachman */ public class PsiMethodCall implements IntrinsicMethod { - private final SimpleFunctionDescriptor myMethod; + private final SimpleFunctionDescriptor method; public PsiMethodCall(SimpleFunctionDescriptor method) { - myMethod = method; + this.method = method; } @Override public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, PsiElement element, List arguments, StackValue receiver, @NotNull GenerationState state) { - final CallableMethod callableMethod = state.getInjector().getJetTypeMapper().mapToCallableMethod(myMethod, false, OwnerKind.IMPLEMENTATION); + final CallableMethod callableMethod = state.getInjector().getJetTypeMapper().mapToCallableMethod(method, false, OwnerKind.IMPLEMENTATION); codegen.invokeMethodWithArguments(callableMethod, (JetCallExpression) element, receiver); return StackValue.onStack(callableMethod.getSignature().getAsmMethod().getReturnType()); } From 39daa11e132ec73043653c5cf3d772ef0984de29 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 17:25:16 +0400 Subject: [PATCH 28/72] Fixed maven build. Renamed usages of upto to rangeTo. Excluded DownTo.kt from js lib compilation. --- .../kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt | 6 +++--- libraries/tools/kotlin-js-library/pom.xml | 1 + runtime/src/jet/IntRange.java | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt index fb8a343a180..17e6041964a 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt @@ -517,7 +517,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs // lets remove the /** ... * ... */ tokens val buffer = StringBuilder() val last = lines.size - 1 - for (i in 0.upto(last)) { + for (i in 0.rangeTo(last)) { var text = lines[i] ?: "" text = text.trim() if (i == 0) { @@ -630,7 +630,7 @@ $highlight""" break } var count = 1 - for (i in 0.upto(remaining.size - 1)) { + for (i in 0.rangeTo(remaining.size - 1)) { val ch = remaining[i] if (ch == '{') count ++ else if (ch == '}') { @@ -653,7 +653,7 @@ $highlight""" // lets try resolve the include name relative to this file val paths = relativeName.split("/") val size = paths.size - for (i in 0.upto(size - 2)) { + for (i in 0.rangeTo(size - 2)) { val path = paths[i] if (path == ".") continue else if (path == "..") dir = dir?.getParent() diff --git a/libraries/tools/kotlin-js-library/pom.xml b/libraries/tools/kotlin-js-library/pom.xml index 1fd4600c6d7..a4b54ec0dca 100644 --- a/libraries/tools/kotlin-js-library/pom.xml +++ b/libraries/tools/kotlin-js-library/pom.xml @@ -72,6 +72,7 @@ + - + + + + diff --git a/pluginPublisher/idea-version-tag.xsl b/pluginPublisher/idea-version-tag.xsl deleted file mode 100644 index dd588808ff7..00000000000 --- a/pluginPublisher/idea-version-tag.xsl +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 231dda60026ce4353c7fb07d1f4213596ea1d9ec Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Thu, 9 Aug 2012 14:07:39 +0300 Subject: [PATCH 35/72] test for obsolete KT-1528 --- compiler/testData/codegen/regressions/kt1528_1.kt | 1 + compiler/testData/codegen/regressions/kt1528_3.kt | 4 ++++ .../tests/org/jetbrains/jet/codegen/PropertyGenTest.java | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 compiler/testData/codegen/regressions/kt1528_1.kt create mode 100644 compiler/testData/codegen/regressions/kt1528_3.kt diff --git a/compiler/testData/codegen/regressions/kt1528_1.kt b/compiler/testData/codegen/regressions/kt1528_1.kt new file mode 100644 index 00000000000..3a79d6bfe14 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1528_1.kt @@ -0,0 +1 @@ +fun box() = foo() \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt1528_3.kt b/compiler/testData/codegen/regressions/kt1528_3.kt new file mode 100644 index 00000000000..cd91be22861 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1528_3.kt @@ -0,0 +1,4 @@ +private val a = "OK" +fun foo() : String { + return "${a}" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 3ec12e348eb..50337f22a69 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -280,6 +280,11 @@ public class PropertyGenTest extends CodegenTestCase { blackBoxFile("regressions/kt2509.kt"); } + public void testKt1528() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxMultiFile("regressions/kt1528_1.kt", "regressions/kt1528_3.kt"); + } + public void testKt2589() throws Exception { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); loadFile("regressions/kt2589.kt"); From 561e2e14d0e1f33ed28ab8e088909fa0f39758fa Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 19:27:48 +0400 Subject: [PATCH 36/72] Added PrimitiveType.NUMBER_TYPES constant. Used it in JVM and JS backends. --- .../codegen/intrinsics/IntrinsicMethods.java | 45 ++++++++++--------- .../jet/lang/types/lang/PrimitiveType.java | 3 ++ .../functions/patterns/NamePredicate.java | 11 ++++- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index e3e1d3807d1..9602583de9a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -20,20 +20,24 @@ import com.google.common.collect.ImmutableList; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.asm4.Opcodes; +import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.expressions.OperatorConventions; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.PrimitiveType; -import org.jetbrains.jet.lang.types.expressions.OperatorConventions; -import org.jetbrains.asm4.Opcodes; import javax.annotation.PostConstruct; import javax.inject.Inject; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author yole @@ -49,8 +53,6 @@ public class IntrinsicMethods { private static final IntrinsicMethod DEC = new Increment(-1); private static final IntrinsicMethod HASH_CODE = new HashCode(); - private static final List PRIMITIVE_TYPES = ImmutableList.of(Name.identifier("Boolean"), Name.identifier("Byte"), Name.identifier("Char"), Name.identifier("Short"), Name.identifier("Int"), Name.identifier("Float"), Name.identifier("Long"), Name.identifier("Double")); - private static final List PRIMITIVE_NUMBER_TYPES = ImmutableList.of(Name.identifier("Byte"), Name.identifier("Char"), Name.identifier("Short"), Name.identifier("Int"), Name.identifier("Float"), Name.identifier("Long"), Name.identifier("Double")); public static final IntrinsicMethod ARRAY_SIZE = new ArraySize(); public static final IntrinsicMethod ARRAY_INDICES = new ArrayIndices(); public static final Equals EQUALS = new Equals(); @@ -83,20 +85,21 @@ public class IntrinsicMethods { ImmutableList primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList(); for (Name method : primitiveCastMethods) { declareIntrinsicFunction(Name.identifier("Number"), method, 0, NUMBER_CAST); - for (Name type : PRIMITIVE_NUMBER_TYPES) { - declareIntrinsicFunction(type, method, 0, NUMBER_CAST); + for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { + declareIntrinsicFunction(type.getTypeName(), method, 0, NUMBER_CAST); } } - for (Name type : PRIMITIVE_NUMBER_TYPES) { - declareIntrinsicFunction(type, Name.identifier("plus"), 0, UNARY_PLUS); - declareIntrinsicFunction(type, Name.identifier("minus"), 0, UNARY_MINUS); - declareIntrinsicFunction(type, Name.identifier("inv"), 0, INV); - declareIntrinsicFunction(type, Name.identifier("rangeTo"), 1, RANGE_TO); - declareIntrinsicFunction(type, Name.identifier("inc"), 0, INC); - declareIntrinsicFunction(type, Name.identifier("dec"), 0, DEC); - declareIntrinsicFunction(type, Name.identifier("hashCode"), 0, HASH_CODE); - declareIntrinsicFunction(type, Name.identifier("equals"), 1, EQUALS); + for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { + Name typeName = type.getTypeName(); + declareIntrinsicFunction(typeName, Name.identifier("plus"), 0, UNARY_PLUS); + declareIntrinsicFunction(typeName, Name.identifier("minus"), 0, UNARY_MINUS); + declareIntrinsicFunction(typeName, Name.identifier("inv"), 0, INV); + declareIntrinsicFunction(typeName, Name.identifier("rangeTo"), 1, RANGE_TO); + declareIntrinsicFunction(typeName, Name.identifier("inc"), 0, INC); + declareIntrinsicFunction(typeName, Name.identifier("dec"), 0, DEC); + declareIntrinsicFunction(typeName, Name.identifier("hashCode"), 0, HASH_CODE); + declareIntrinsicFunction(typeName, Name.identifier("equals"), 1, EQUALS); } declareBinaryOp(Name.identifier("plus"), Opcodes.IADD); @@ -136,8 +139,8 @@ public class IntrinsicMethods { declareIntrinsicFunction(Name.identifier("FloatIterator"), Name.identifier("next"), 0, ITERATOR_NEXT); declareIntrinsicFunction(Name.identifier("DoubleIterator"), Name.identifier("next"), 0, ITERATOR_NEXT); - for (Name type : PRIMITIVE_TYPES) { - declareIntrinsicFunction(type, Name.identifier("compareTo"), 1, new CompareTo()); + for (PrimitiveType type : PrimitiveType.values()) { + declareIntrinsicFunction(type.getTypeName(), Name.identifier("compareTo"), 1, new CompareTo()); } // declareIntrinsicFunction("Any", "equals", 1, new Equals()); // @@ -175,8 +178,8 @@ public class IntrinsicMethods { private void declareBinaryOp(Name methodName, int opcode) { BinaryOp op = new BinaryOp(opcode); - for (Name type : PRIMITIVE_TYPES) { - declareIntrinsicFunction(type, methodName, 1, op); + for (PrimitiveType type : PrimitiveType.values()) { + declareIntrinsicFunction(type.getTypeName(), methodName, 1, op); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java index ac08c00fc00..db8c9bc7875 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java @@ -16,6 +16,7 @@ package org.jetbrains.jet.lang.types.lang; +import com.google.common.collect.ImmutableSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.ref.ClassName; @@ -34,6 +35,8 @@ public enum PrimitiveType { LONG("Long"), DOUBLE("Double"), ; + + public static final ImmutableSet NUMBER_TYPES = ImmutableSet.of(CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE); private final Name typeName; private final Name arrayTypeName; diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/patterns/NamePredicate.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/patterns/NamePredicate.java index 3b9aab055a9..ddca1cf9bd6 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/patterns/NamePredicate.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/patterns/NamePredicate.java @@ -18,9 +18,12 @@ package org.jetbrains.k2js.translate.intrinsic.functions.patterns; import closurecompiler.internal.com.google.common.collect.Lists; import com.google.common.base.Predicate; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.lang.PrimitiveType; import java.util.Arrays; import java.util.Collection; @@ -32,7 +35,13 @@ import java.util.List; public final class NamePredicate implements Predicate { @NotNull - public static final NamePredicate PRIMITIVE_NUMBERS = new NamePredicate("Int", "Double", "Float", "Long", "Short", "Byte"); + public static final NamePredicate PRIMITIVE_NUMBERS = new NamePredicate( + ContainerUtil.map(PrimitiveType.NUMBER_TYPES, new Function() { + @Override + public String fun(PrimitiveType type) { + return type.getTypeName().getName(); + } + })); @NotNull private final List validNames = Lists.newArrayList(); From 67304c64ffce03c6ea34c3194cce5fa90585b93f Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 19:36:19 +0400 Subject: [PATCH 37/72] Removed unused myProject field from IntrinsicMethods. Removed from injector parameters, etc. --- .../jetbrains/jet/codegen/GenerationState.java | 15 ++++++--------- .../jet/codegen/intrinsics/IntrinsicMethods.java | 6 ------ .../jetbrains/jet/di/InjectorForJvmCodegen.java | 6 ------ .../jvm/compiler/KotlinToJVMBytecodeCompiler.java | 2 +- .../jet/cli/jvm/repl/ReplInterpreter.java | 2 +- .../org/jetbrains/jet/asJava/JetLightClass.java | 2 +- .../jetbrains/jet/codegen/CodegenTestCase.java | 2 +- .../jetbrains/jet/codegen/GenerationUtils.java | 2 +- .../internal/codewindow/BytecodeToolwindow.java | 2 +- .../jetbrains/jet/di/AllInjectorsGenerator.java | 1 - 10 files changed, 12 insertions(+), 28 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java index f970e41208a..72e89ad3ac1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java @@ -19,10 +19,10 @@ */ package org.jetbrains.jet.codegen; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.asm4.commons.Method; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.di.InjectorForJvmCodegen; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; @@ -30,11 +30,10 @@ import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.ScriptNameUtil; +import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.utils.Progress; -import org.jetbrains.asm4.commons.Method; import java.util.Collection; import java.util.Collections; @@ -42,7 +41,6 @@ import java.util.List; import java.util.Map; public class GenerationState { - private final Project project; private final Progress progress; @NotNull private final AnalyzeExhaust analyzeExhaust; @@ -60,20 +58,19 @@ public class GenerationState { private Method scriptConstructorMethod; - public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List files) { - this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED); + public GenerationState(ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List files) { + this(builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED); } - public GenerationState(Project project, ClassBuilderFactory builderFactory, Progress progress, + public GenerationState(ClassBuilderFactory builderFactory, Progress progress, @NotNull AnalyzeExhaust exhaust, @NotNull List files, @NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping) { - this.project = project; this.progress = progress; this.analyzeExhaust = exhaust; this.files = files; this.classBuilderMode = builderFactory.getClassBuilderMode(); this.injector = new InjectorForJvmCodegen( analyzeExhaust.getBindingContext(), - this.files, project, builtinToJavaTypesMapping, builderFactory.getClassBuilderMode(), this, builderFactory); + this.files, builtinToJavaTypesMapping, builderFactory.getClassBuilderMode(), this, builderFactory); } private void markUsed() { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index 9602583de9a..4aad835fc8f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -65,17 +65,11 @@ public class IntrinsicMethods { public static final String KOTLIN_ARRAYS_ARRAY = "kotlin.arrays.array"; public static final String KOTLIN_JAVA_CLASS_PROPERTY = "kotlin.javaClass.property"; - private Project myProject; private final Map namedMethods = new HashMap(); private static final IntrinsicMethod ARRAY_ITERATOR = new ArrayIterator(); private final IntrinsicsMap intrinsicsMap = new IntrinsicsMap(); - @Inject - public void setMyProject(Project myProject) { - this.myProject = myProject; - } - @PostConstruct public void init() { namedMethods.put(KOTLIN_JAVA_CLASS_FUNCTION, new JavaClassFunction()); diff --git a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java index 2837110638b..1a4039db2b2 100644 --- a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java @@ -20,7 +20,6 @@ package org.jetbrains.jet.di; import org.jetbrains.jet.lang.resolve.BindingContext; import java.util.List; import org.jetbrains.jet.lang.psi.JetFile; -import com.intellij.openapi.project.Project; import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping; import org.jetbrains.jet.codegen.ClassBuilderMode; import org.jetbrains.jet.codegen.GenerationState; @@ -40,7 +39,6 @@ public class InjectorForJvmCodegen { private final BindingContext bindingContext; private final List listOfJetFile; - private final Project project; private final BuiltinToJavaTypesMapping builtinToJavaTypesMapping; private final ClassBuilderMode classBuilderMode; private final GenerationState generationState; @@ -56,7 +54,6 @@ public class InjectorForJvmCodegen { public InjectorForJvmCodegen( @NotNull BindingContext bindingContext, @NotNull List listOfJetFile, - @NotNull Project project, @NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping, @NotNull ClassBuilderMode classBuilderMode, @NotNull GenerationState generationState, @@ -64,7 +61,6 @@ public class InjectorForJvmCodegen { ) { this.bindingContext = bindingContext; this.listOfJetFile = listOfJetFile; - this.project = project; this.builtinToJavaTypesMapping = builtinToJavaTypesMapping; this.classBuilderMode = classBuilderMode; this.generationState = generationState; @@ -92,8 +88,6 @@ public class InjectorForJvmCodegen { this.scriptCodegen.setMemberCodegen(memberCodegen); this.scriptCodegen.setState(generationState); - this.intrinsics.setMyProject(project); - this.classFileFactory.setBuilderFactory(classBuilderFactory); this.classFileFactory.setState(generationState); diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index fcd5fb1139b..cfd3dbf3969 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -339,7 +339,7 @@ public class KotlinToJVMBytecodeCompiler { environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION); } }; - GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress, + GenerationState generationState = new GenerationState(ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(), environment.getConfiguration().get( JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java index 8c2da3446e4..04d00a1461d 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java @@ -236,7 +236,7 @@ public class ReplInterpreter { earierScripts.add(Pair.create(earlierLine.getScriptDescriptor(), earlierLine.getClassName())); } - GenerationState generationState = new GenerationState(jetCoreEnvironment.getProject(), ClassBuilderFactories.binaries(false), backendProgress, + GenerationState generationState = new GenerationState(ClassBuilderFactories.binaries(false), backendProgress, AnalyzeExhaust.success(trace.getBindingContext()), Collections.singletonList(psiFile), BuiltinToJavaTypesMapping.ENABLED); generationState.compileScript(psiFile.getScript(), scriptClassName, earierScripts, CompilationErrorHandler.THROW_EXCEPTION); diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java index 2f432a6a288..29418e20807 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java @@ -180,7 +180,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa throw new IllegalStateException("failed to analyze: " + context.getError(), context.getError()); } - final GenerationState state = new GenerationState(project, builderFactory, context, Collections.singletonList(file)) { + final GenerationState state = new GenerationState(builderFactory, context, Collections.singletonList(file)) { @Override protected void generateNamespace(FqName fqName, Collection namespaceFiles, CompilationErrorHandler errorHandler, Progress progress) { PsiManager manager = PsiManager.getInstance(project); diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index 321ce3a8eea..12b25272e29 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -274,7 +274,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { BuiltinsScopeExtensionMode.ALL); analyzeExhaust.throwIfError(); AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext()); - alreadyGenerated = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles()); + alreadyGenerated = new GenerationState(classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles()); alreadyGenerated.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); return alreadyGenerated; } diff --git a/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java b/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java index 50594685b8c..4e76fbc812a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java +++ b/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java @@ -41,7 +41,7 @@ public class GenerationUtils { final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors( psiFile, Collections.emptyList(), BuiltinsScopeExtensionMode.ALL); analyzeExhaust.throwIfError(); - GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, Collections.singletonList(psiFile)); + GenerationState state = new GenerationState(ClassBuilderFactories.binaries(false), analyzeExhaust, Collections.singletonList(psiFile)); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); return state; } diff --git a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java index 9ea5583e1b3..531214af3ee 100644 --- a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java +++ b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java @@ -209,7 +209,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable { if (binding.isError()) { return printStackTraceToString(binding.getError()); } - state = new GenerationState(myProject, ClassBuilderFactories.TEXT, binding, Collections.singletonList(file)); + state = new GenerationState(ClassBuilderFactories.TEXT, binding, Collections.singletonList(file)); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); } catch (Exception e) { diff --git a/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java b/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java index ca2442f9d50..f3f137cd08c 100644 --- a/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java +++ b/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java @@ -189,7 +189,6 @@ public class AllInjectorsGenerator { DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false); generator.addParameter(BindingContext.class); generator.addParameter(DiType.listOf(JetFile.class)); - generator.addParameter(Project.class); generator.addParameter(BuiltinToJavaTypesMapping.class); generator.addParameter(ClassBuilderMode.class); generator.addPublicParameter(GenerationState.class); From e771fd234d5f613ef3cc84d6c09e093901b9b24f Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 21:49:44 +0400 Subject: [PATCH 38/72] Enabled PrimitiveTypesTest.testKt882 (seems that it was disabled erroneously. --- .../tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index e7e3bfdedef..573207df0b0 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -382,7 +382,7 @@ public class PrimitiveTypesTest extends CodegenTestCase { } public void testKt882 () { -// blackBoxFile("regressions/kt882.jet"); + blackBoxFile("regressions/kt882.jet"); } public void testKt887 () { From 4a364f4c26be55bacb282c9fde71e65dce07ab0a Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 22:48:51 +0400 Subject: [PATCH 39/72] Added "empty" constant to DoubleRange and FloatRange for uniformity. --- runtime/src/jet/DoubleRange.java | 2 ++ runtime/src/jet/FloatRange.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/runtime/src/jet/DoubleRange.java b/runtime/src/jet/DoubleRange.java index ddb8513186a..654edc7b989 100644 --- a/runtime/src/jet/DoubleRange.java +++ b/runtime/src/jet/DoubleRange.java @@ -23,6 +23,8 @@ public final class DoubleRange implements Range { private final double start; private final double size; + public static final DoubleRange empty = new DoubleRange(0, 0); + public DoubleRange(double startValue, double size) { this.start = startValue; this.size = size; diff --git a/runtime/src/jet/FloatRange.java b/runtime/src/jet/FloatRange.java index 78011412db6..5197dc2c531 100644 --- a/runtime/src/jet/FloatRange.java +++ b/runtime/src/jet/FloatRange.java @@ -23,6 +23,8 @@ public final class FloatRange implements Range { private final float start; private final float size; + public static final FloatRange empty = new FloatRange(0, 0); + public FloatRange(float startValue, float size) { this.start = startValue; this.size = size; From d9f30f6763a103ebc798585a92b2ea1e4d63f6d3 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 22:49:19 +0400 Subject: [PATCH 40/72] Added getRangeType() to PrimitiveType enum. --- .../jet/lang/types/lang/PrimitiveType.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java index db8c9bc7875..5ebcbb73c54 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java @@ -40,14 +40,18 @@ public enum PrimitiveType { private final Name typeName; private final Name arrayTypeName; + private final Name rangeTypeName; private final ClassName className; private final ClassName arrayClassName; + private final ClassName rangeClassName; private PrimitiveType(String typeName) { this.typeName = Name.identifier(typeName); this.arrayTypeName = Name.identifier(typeName + "Array"); + this.rangeTypeName = Name.identifier(typeName + "Range"); this.className = new ClassName(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(this.typeName), 0); this.arrayClassName = new ClassName(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(this.arrayTypeName), 0); + this.rangeClassName = new ClassName(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(this.rangeTypeName), 0); } @NotNull @@ -60,6 +64,11 @@ public enum PrimitiveType { return arrayTypeName; } + @NotNull + public Name getRangeTypeName() { + return rangeTypeName; + } + @NotNull public ClassName getClassName() { return className; @@ -69,4 +78,9 @@ public enum PrimitiveType { public ClassName getArrayClassName() { return arrayClassName; } + + @NotNull + public ClassName getRangeClassName() { + return rangeClassName; + } } From 0124c7bb5a641db45a7d6e305efd8ad1bf7ac3d1 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 8 Aug 2012 22:50:29 +0400 Subject: [PATCH 41/72] KT-2583 Support *Range.EMPTY #KT-2583 fixed --- .../jet/codegen/ClosureAnnotator.java | 16 ++++++ .../jet/codegen/intrinsics/EmptyRange.java | 56 +++++++++++++++++++ .../codegen/intrinsics/IntrinsicMethods.java | 10 +++- .../jet/codegen/intrinsics/IntrinsicsMap.java | 9 ++- compiler/frontend/src/jet/Ranges.jet | 28 ++++++++++ compiler/testData/builtin-classes.txt | 28 ++++++++++ compiler/testData/codegen/emptyRanges.kt | 24 ++++++++ .../jet/codegen/PrimitiveTypesTest.java | 4 ++ 8 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java create mode 100644 compiler/testData/codegen/emptyRanges.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java index 83863901f75..aa76f53a2f4 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java @@ -30,6 +30,8 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; +import org.jetbrains.jet.lang.types.lang.PrimitiveType; import javax.inject.Inject; import java.util.*; @@ -65,6 +67,20 @@ public class ClosureAnnotator { public void init() { mapFilesToNamespaces(files); prepareAnonymousClasses(); + prepareClassObjectsForBuiltinRanges(); + } + + private void prepareClassObjectsForBuiltinRanges() { + // this is needed for range classes because they have class objects with + // intrinsic members + JetScope stdLibraryScope = JetStandardLibrary.getInstance().getLibraryScope(); + for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { + ClassDescriptor klass = (ClassDescriptor) stdLibraryScope.getClassifier(type.getRangeTypeName()); + String rangeInternalName = JvmClassName.byFqNameWithoutInnerClasses( + JetStandardClasses.STANDARD_CLASSES_FQNAME.child(type.getRangeTypeName())).getInternalName(); + JvmClassName classObjectInternalName = JvmClassName.byInternalName(rangeInternalName + JvmAbi.CLASS_OBJECT_SUFFIX); + classNamesForClassDescriptor.put(klass.getClassObjectDescriptor(), classObjectInternalName); + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java new file mode 100644 index 00000000000..0c1d8e86a74 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen.intrinsics; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.asm4.Type; +import org.jetbrains.asm4.commons.InstructionAdapter; +import org.jetbrains.jet.codegen.ExpressionCodegen; +import org.jetbrains.jet.codegen.GenerationState; +import org.jetbrains.jet.codegen.StackValue; +import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.resolve.java.JvmClassName; +import org.jetbrains.jet.lang.types.lang.PrimitiveType; + +import java.util.List; + +/** + * @author Evgeny Gerashchenko + * @since 08.08.12 + */ +public class EmptyRange implements IntrinsicMethod { + private final PrimitiveType elementType; + + public EmptyRange(PrimitiveType elementType) { + this.elementType = elementType; + } + + @Override + public StackValue generate(ExpressionCodegen codegen, + InstructionAdapter v, + @NotNull Type expectedType, + @Nullable PsiElement element, + @Nullable List arguments, + StackValue receiver, + @NotNull GenerationState state) { + JvmClassName name = JvmClassName.byFqNameWithoutInnerClasses(elementType.getRangeClassName().getFqName()); + v.getstatic(name.toString(), "empty", "L" + name + ";"); + return StackValue.onStack(expectedType); + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index 4aad835fc8f..9a0ca427588 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.codegen.intrinsics; import com.google.common.collect.ImmutableList; -import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Opcodes; @@ -25,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.psi.JetPsiUtil; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; @@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.PrimitiveType; import javax.annotation.PostConstruct; -import javax.inject.Inject; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -141,6 +140,12 @@ public class IntrinsicMethods { declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength()); declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength()); + for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { + intrinsicsMap.registerIntrinsic( + JetStandardClasses.STANDARD_CLASSES_FQNAME.child(type.getRangeTypeName()).toUnsafe().child(JetPsiUtil.NO_NAME_PROVIDED), + Name.identifier("EMPTY"), -1, new EmptyRange(type)); + } + declareArrayMethods(); } @@ -228,5 +233,4 @@ public class IntrinsicMethods { } return intrinsicMethod; } - } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java index c069a0dcee6..631ce95ebf8 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java @@ -82,11 +82,18 @@ class IntrinsicsMap { private Map intrinsicsMap = Maps.newHashMap(); + /** + * @param valueParameterCount -1 for property + */ + public void registerIntrinsic(@NotNull FqNameUnsafe owner, @NotNull Name name, int valueParameterCount, @NotNull IntrinsicMethod impl) { + intrinsicsMap.put(new Key(owner, name, valueParameterCount), impl); + } + /** * @param valueParameterCount -1 for property */ public void registerIntrinsic(@NotNull FqName owner, @NotNull Name name, int valueParameterCount, @NotNull IntrinsicMethod impl) { - intrinsicsMap.put(new Key(owner.toUnsafe(), name, valueParameterCount), impl); + registerIntrinsic(owner.toUnsafe(), name, valueParameterCount, impl); } diff --git a/compiler/frontend/src/jet/Ranges.jet b/compiler/frontend/src/jet/Ranges.jet index ff24d077f30..ee0635bf3a4 100644 --- a/compiler/frontend/src/jet/Ranges.jet +++ b/compiler/frontend/src/jet/Ranges.jet @@ -18,6 +18,10 @@ public class IntRange(public val start : Int, public val size : Int) : Range, LongIterable { @@ -34,6 +38,10 @@ public class LongRange(public val start : Long, public val size : Long) : Range< public fun step(step: Long) : LongIterator public val isReversed : Boolean + + public class object { + public val EMPTY: LongRange + } } public class ByteRange(public val start : Byte, public val size : Int) : Range, ByteIterable { @@ -50,6 +58,10 @@ public class ByteRange(public val start : Byte, public val size : Int) : Range, ShortIterable { @@ -66,6 +78,10 @@ public class ShortRange(public val start : Short, public val size : Int) : Range public fun step(step: Int) : ShortIterator public val isReversed : Boolean + + public class object { + public val EMPTY: ShortRange + } } public class CharRange(public val start : Char, public val size : Int) : Range, CharIterable { @@ -82,6 +98,10 @@ public class CharRange(public val start : Char, public val size : Int) : Range { @@ -94,6 +114,10 @@ public class FloatRange(public val start : Float, public val size : Float) : Ran public fun step(step: Float) : FloatIterator public val isReversed : Boolean + + public class object { + public val EMPTY: FloatRange + } } public class DoubleRange(public val start : Double, public val size : Double) : Range { @@ -106,4 +130,8 @@ public class DoubleRange(public val start : Double, public val size : Double) : public fun step(step: Double) : DoubleIterator public val isReversed : Boolean + + public class object { + public val EMPTY: DoubleRange + } } diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index c9f6c70f358..eb9f63cc1b8 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -130,6 +130,10 @@ public final class jet.ByteRange : jet.Range, jet.ByteIterable { public final val size: jet.Int public final val start: jet.Byte public final fun step(/*0*/ step: jet.Int): jet.ByteIterator + public final class object jet.ByteRange. : jet.Any { + internal final /*constructor*/ fun (): jet.ByteRange. + public final val EMPTY: jet.ByteRange + } } public final class jet.Char : jet.Number, jet.Comparable { public final /*constructor*/ fun (): jet.Char @@ -220,6 +224,10 @@ public final class jet.CharRange : jet.Range, jet.CharIterable { public final val size: jet.Int public final val start: jet.Char public final fun step(/*0*/ step: jet.Int): jet.CharIterator + public final class object jet.CharRange. : jet.Any { + internal final /*constructor*/ fun (): jet.CharRange. + public final val EMPTY: jet.CharRange + } } public abstract trait jet.CharSequence : jet.Any { public abstract fun get(/*0*/ index: jet.Int): jet.Char @@ -319,6 +327,10 @@ public final class jet.DoubleRange : jet.Range { public final val size: jet.Double public final val start: jet.Double public final fun step(/*0*/ step: jet.Double): jet.DoubleIterator + public final class object jet.DoubleRange. : jet.Any { + internal final /*constructor*/ fun (): jet.DoubleRange. + public final val EMPTY: jet.DoubleRange + } } public abstract class jet.ExtensionFunction0 : jet.Any { public final /*constructor*/ fun (): jet.ExtensionFunction0 @@ -503,6 +515,10 @@ public final class jet.FloatRange : jet.Range { public final val size: jet.Float public final val start: jet.Float public final fun step(/*0*/ step: jet.Float): jet.FloatIterator + public final class object jet.FloatRange. : jet.Any { + internal final /*constructor*/ fun (): jet.FloatRange. + public final val EMPTY: jet.FloatRange + } } public abstract class jet.Function0 : jet.Any { public final /*constructor*/ fun (): jet.Function0 @@ -700,6 +716,10 @@ public final class jet.IntRange : jet.Range, jet.IntIterable { public final val size: jet.Int public final val start: jet.Int public final fun step(/*0*/ step: jet.Int): jet.IntIterator + public final class object jet.IntRange. : jet.Any { + internal final /*constructor*/ fun (): jet.IntRange. + public final val EMPTY: jet.IntRange + } } public abstract trait jet.Iterable : jet.Any { public abstract fun iterator(): jet.Iterator @@ -808,6 +828,10 @@ public final class jet.LongRange : jet.Range, jet.LongIterable { public final val size: jet.Long public final val start: jet.Long public final fun step(/*0*/ step: jet.Long): jet.LongIterator + public final class object jet.LongRange. : jet.Any { + internal final /*constructor*/ fun (): jet.LongRange. + public final val EMPTY: jet.LongRange + } } public final class jet.Nothing { private final /*constructor*/ fun (): jet.Nothing @@ -920,6 +944,10 @@ public final class jet.ShortRange : jet.Range, jet.ShortIterable { public final val size: jet.Int public final val start: jet.Short public final fun step(/*0*/ step: jet.Int): jet.ShortIterator + public final class object jet.ShortRange. : jet.Any { + internal final /*constructor*/ fun (): jet.ShortRange. + public final val EMPTY: jet.ShortRange + } } public final class jet.String : jet.Comparable, jet.CharSequence { public final /*constructor*/ fun (): jet.String diff --git a/compiler/testData/codegen/emptyRanges.kt b/compiler/testData/codegen/emptyRanges.kt new file mode 100644 index 00000000000..ae1465da971 --- /dev/null +++ b/compiler/testData/codegen/emptyRanges.kt @@ -0,0 +1,24 @@ +fun box(): String { + if (IntRange(0, 0) != IntRange.EMPTY) { + return IntRange.EMPTY.toString() + } + if (CharRange(0.toChar(), 0) != CharRange.EMPTY) { + return CharRange.EMPTY.toString() + } + if (ByteRange(0, 0) != ByteRange.EMPTY) { + return ByteRange.EMPTY.toString() + } + if (ShortRange(0, 0) != ShortRange.EMPTY) { + return ShortRange.EMPTY.toString() + } + if (FloatRange(0.toFloat(), 0.toFloat()) != FloatRange.EMPTY) { + return FloatRange.EMPTY.toString() + } + if (LongRange(0, 0) != LongRange.EMPTY) { + return LongRange.EMPTY.toString() + } + if (DoubleRange(0.0, 0.0) != DoubleRange.EMPTY) { + return DoubleRange.EMPTY.toString() + } + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 573207df0b0..e27326900e4 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -444,4 +444,8 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt2275() { blackBoxFile("regressions/kt2275.kt"); } + + public void testEmptyRanges() throws Exception { + blackBoxFile("emptyRanges.kt"); + } } From 543ec16f4d25d9d303d82953453be95dd50c8180 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 13:35:25 +0400 Subject: [PATCH 42/72] Renamed 'empty' field in range classes to 'EMPTY'. --- .../jet/codegen/intrinsics/EmptyRange.java | 2 +- runtime/src/jet/ByteRange.java | 2 +- runtime/src/jet/CharRange.java | 2 +- runtime/src/jet/DoubleRange.java | 2 +- runtime/src/jet/FloatRange.java | 2 +- runtime/src/jet/IntRange.java | 2 +- runtime/src/jet/LongRange.java | 2 +- runtime/src/jet/ShortRange.java | 2 +- runtime/src/jet/runtime/Ranges.java | 52 +++++++++---------- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java index 0c1d8e86a74..67517bb264f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/EmptyRange.java @@ -50,7 +50,7 @@ public class EmptyRange implements IntrinsicMethod { StackValue receiver, @NotNull GenerationState state) { JvmClassName name = JvmClassName.byFqNameWithoutInnerClasses(elementType.getRangeClassName().getFqName()); - v.getstatic(name.toString(), "empty", "L" + name + ";"); + v.getstatic(name.toString(), "EMPTY", "L" + name + ";"); return StackValue.onStack(expectedType); } } diff --git a/runtime/src/jet/ByteRange.java b/runtime/src/jet/ByteRange.java index 881e62758f9..10d5c3005e3 100644 --- a/runtime/src/jet/ByteRange.java +++ b/runtime/src/jet/ByteRange.java @@ -23,7 +23,7 @@ public final class ByteRange implements Range, ByteIterable { private final byte start; private final int count; - public static final ByteRange empty = new ByteRange((byte) 0,0); + public static final ByteRange EMPTY = new ByteRange((byte) 0,0); public ByteRange(byte startValue, int count) { this.start = startValue; diff --git a/runtime/src/jet/CharRange.java b/runtime/src/jet/CharRange.java index 1f41d6fe26b..ae044bb5add 100644 --- a/runtime/src/jet/CharRange.java +++ b/runtime/src/jet/CharRange.java @@ -23,7 +23,7 @@ public final class CharRange implements Range, CharIterable { private final char start; private final int count; - public static final CharRange empty = new CharRange((char) 0,0); + public static final CharRange EMPTY = new CharRange((char) 0,0); public CharRange(char startValue, int count) { this.start = startValue; diff --git a/runtime/src/jet/DoubleRange.java b/runtime/src/jet/DoubleRange.java index 654edc7b989..01bb39f361f 100644 --- a/runtime/src/jet/DoubleRange.java +++ b/runtime/src/jet/DoubleRange.java @@ -23,7 +23,7 @@ public final class DoubleRange implements Range { private final double start; private final double size; - public static final DoubleRange empty = new DoubleRange(0, 0); + public static final DoubleRange EMPTY = new DoubleRange(0, 0); public DoubleRange(double startValue, double size) { this.start = startValue; diff --git a/runtime/src/jet/FloatRange.java b/runtime/src/jet/FloatRange.java index 5197dc2c531..8962310deea 100644 --- a/runtime/src/jet/FloatRange.java +++ b/runtime/src/jet/FloatRange.java @@ -23,7 +23,7 @@ public final class FloatRange implements Range { private final float start; private final float size; - public static final FloatRange empty = new FloatRange(0, 0); + public static final FloatRange EMPTY = new FloatRange(0, 0); public FloatRange(float startValue, float size) { this.start = startValue; diff --git a/runtime/src/jet/IntRange.java b/runtime/src/jet/IntRange.java index 693e21a6077..f73d7a8331a 100644 --- a/runtime/src/jet/IntRange.java +++ b/runtime/src/jet/IntRange.java @@ -23,7 +23,7 @@ public final class IntRange implements Range, IntIterable { private final int start; private final int count; - public static final IntRange empty = new IntRange(0,0); + public static final IntRange EMPTY = new IntRange(0,0); public IntRange(int startValue, int count) { this.start = startValue; diff --git a/runtime/src/jet/LongRange.java b/runtime/src/jet/LongRange.java index f091be8de81..114155d0123 100644 --- a/runtime/src/jet/LongRange.java +++ b/runtime/src/jet/LongRange.java @@ -23,7 +23,7 @@ public final class LongRange implements Range, LongIterable { private final long start; private final long count; - public static final LongRange empty = new LongRange(0L,0L); + public static final LongRange EMPTY = new LongRange(0L,0L); public LongRange(long startValue, long count) { this.start = startValue; diff --git a/runtime/src/jet/ShortRange.java b/runtime/src/jet/ShortRange.java index 6cddf3bba53..d94206c0894 100644 --- a/runtime/src/jet/ShortRange.java +++ b/runtime/src/jet/ShortRange.java @@ -23,7 +23,7 @@ public final class ShortRange implements Range, ShortIterable { private final short start; private final int count; - public static final ShortRange empty = new ShortRange((short) 0,0); + public static final ShortRange EMPTY = new ShortRange((short) 0,0); public ShortRange(short startValue, int count) { this.start = startValue; diff --git a/runtime/src/jet/runtime/Ranges.java b/runtime/src/jet/runtime/Ranges.java index 537e4aae7fb..93af2430afc 100644 --- a/runtime/src/jet/runtime/Ranges.java +++ b/runtime/src/jet/runtime/Ranges.java @@ -30,7 +30,7 @@ public class Ranges { public static ByteRange rangeTo(byte from, byte to) { if (from > to) { - return ByteRange.empty; + return ByteRange.EMPTY; } else { return new ByteRange(from, to - from + 1); @@ -39,7 +39,7 @@ public class Ranges { public static ShortRange rangeTo(byte from, short to) { if (from > to) { - return ShortRange.empty; + return ShortRange.EMPTY; } else { return new ShortRange(from, to - from + 1); @@ -48,7 +48,7 @@ public class Ranges { public static IntRange rangeTo(byte from, int to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -57,7 +57,7 @@ public class Ranges { public static LongRange rangeTo(byte from, long to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -74,7 +74,7 @@ public class Ranges { public static CharRange rangeTo(byte from, char to) { if (from > to) { - return CharRange.empty; + return CharRange.EMPTY; } else { return new CharRange((char) from, to - from + 1); @@ -83,7 +83,7 @@ public class Ranges { public static ShortRange rangeTo(short from, byte to) { if (from > to) { - return ShortRange.empty; + return ShortRange.EMPTY; } else { return new ShortRange(from, to - from + 1); @@ -92,7 +92,7 @@ public class Ranges { public static ShortRange rangeTo(short from, short to) { if (from > to) { - return ShortRange.empty; + return ShortRange.EMPTY; } else { return new ShortRange(from, to - from + 1); @@ -101,7 +101,7 @@ public class Ranges { public static IntRange rangeTo(short from, int to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -110,7 +110,7 @@ public class Ranges { public static LongRange rangeTo(short from, long to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -127,7 +127,7 @@ public class Ranges { public static ShortRange rangeTo(short from, char to) { if (from > to) { - return ShortRange.empty; + return ShortRange.EMPTY; } else { return new ShortRange(from, to - from + 1); @@ -136,7 +136,7 @@ public class Ranges { public static IntRange rangeTo(int from, byte to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -145,7 +145,7 @@ public class Ranges { public static IntRange rangeTo(int from, short to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -154,7 +154,7 @@ public class Ranges { public static IntRange rangeTo(int from, int to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -163,7 +163,7 @@ public class Ranges { public static LongRange rangeTo(int from, long to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -180,7 +180,7 @@ public class Ranges { public static IntRange rangeTo(int from, char to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -189,7 +189,7 @@ public class Ranges { public static LongRange rangeTo(long from, byte to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -198,7 +198,7 @@ public class Ranges { public static LongRange rangeTo(long from, short to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -207,7 +207,7 @@ public class Ranges { public static LongRange rangeTo(long from, int to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -216,7 +216,7 @@ public class Ranges { public static LongRange rangeTo(long from, long to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -233,7 +233,7 @@ public class Ranges { public static LongRange rangeTo(long from, char to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -298,7 +298,7 @@ public class Ranges { public static CharRange rangeTo(char from, byte to) { if (from > to) { - return CharRange.empty; + return CharRange.EMPTY; } else { return new CharRange(from, to - from + 1); @@ -307,7 +307,7 @@ public class Ranges { public static ShortRange rangeTo(char from, short to) { if (from > to) { - return ShortRange.empty; + return ShortRange.EMPTY; } else { return new ShortRange((short) from, to - from + 1); @@ -316,7 +316,7 @@ public class Ranges { public static IntRange rangeTo(char from, int to) { if (from > to) { - return IntRange.empty; + return IntRange.EMPTY; } else { return new IntRange(from, to - from + 1); @@ -325,7 +325,7 @@ public class Ranges { public static LongRange rangeTo(char from, long to) { if (from > to) { - return LongRange.empty; + return LongRange.EMPTY; } else { return new LongRange(from, to - from + 1); @@ -342,7 +342,7 @@ public class Ranges { public static CharRange rangeTo(char from, char to) { if (from > to) { - return CharRange.empty; + return CharRange.EMPTY; } else { return new CharRange(from, to - from + 1); @@ -384,7 +384,7 @@ public class Ranges { else { System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {" + "\n if(from > to) {\n" + - " return " + resType + ".empty;\n" + + " return " + resType + ".EMPTY;\n" + " }\n" + " else {\n" + " return new " + resType + "(from, to-from+1);\n" + From 8084876fed597b42864f44888ab3a314976f6586 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 13:56:56 +0400 Subject: [PATCH 43/72] Using empty ranges in downTo generator. --- libraries/stdlib/src/generated/DownTo.kt | 50 +++++++++---------- .../jetbrains/kotlin/tools/GenerateDownTos.kt | 3 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/libraries/stdlib/src/generated/DownTo.kt b/libraries/stdlib/src/generated/DownTo.kt index 068cde743bd..aee8b8c4906 100644 --- a/libraries/stdlib/src/generated/DownTo.kt +++ b/libraries/stdlib/src/generated/DownTo.kt @@ -7,23 +7,23 @@ package kotlin public inline fun Byte.downTo(to: Byte): ByteRange { - return if (this >= to) ByteRange(this, to - this - 1) else ByteRange(0, 0) + return if (this >= to) ByteRange(this, to - this - 1) else ByteRange.EMPTY } public inline fun Byte.downTo(to: Char): CharRange { - return if (this >= to) CharRange(this.toChar(), to - this - 1) else CharRange(0.toChar(), 0) + return if (this >= to) CharRange(this.toChar(), to - this - 1) else CharRange.EMPTY } public inline fun Byte.downTo(to: Short): ShortRange { - return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange(0, 0) + return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange.EMPTY } public inline fun Byte.downTo(to: Int): IntRange { - return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange.EMPTY } public inline fun Byte.downTo(to: Long): LongRange { - return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange.EMPTY } public inline fun Byte.downTo(to: Float): FloatRange { @@ -35,23 +35,23 @@ public inline fun Byte.downTo(to: Double): DoubleRange { } public inline fun Char.downTo(to: Byte): CharRange { - return if (this >= to) CharRange(this, to - this - 1) else CharRange(0.toChar(), 0) + return if (this >= to) CharRange(this, to - this - 1) else CharRange.EMPTY } public inline fun Char.downTo(to: Char): CharRange { - return if (this >= to) CharRange(this, to - this - 1) else CharRange(0.toChar(), 0) + return if (this >= to) CharRange(this, to - this - 1) else CharRange.EMPTY } public inline fun Char.downTo(to: Short): ShortRange { - return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange(0, 0) + return if (this >= to) ShortRange(this.toShort(), to - this - 1) else ShortRange.EMPTY } public inline fun Char.downTo(to: Int): IntRange { - return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange.EMPTY } public inline fun Char.downTo(to: Long): LongRange { - return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange.EMPTY } public inline fun Char.downTo(to: Float): FloatRange { @@ -63,23 +63,23 @@ public inline fun Char.downTo(to: Double): DoubleRange { } public inline fun Short.downTo(to: Byte): ShortRange { - return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange.EMPTY } public inline fun Short.downTo(to: Char): ShortRange { - return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange.EMPTY } public inline fun Short.downTo(to: Short): ShortRange { - return if (this >= to) ShortRange(this, to - this - 1) else ShortRange(0, 0) + return if (this >= to) ShortRange(this, to - this - 1) else ShortRange.EMPTY } public inline fun Short.downTo(to: Int): IntRange { - return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this.toInt(), to - this - 1) else IntRange.EMPTY } public inline fun Short.downTo(to: Long): LongRange { - return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange.EMPTY } public inline fun Short.downTo(to: Float): FloatRange { @@ -91,23 +91,23 @@ public inline fun Short.downTo(to: Double): DoubleRange { } public inline fun Int.downTo(to: Byte): IntRange { - return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this, to - this - 1) else IntRange.EMPTY } public inline fun Int.downTo(to: Char): IntRange { - return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this, to - this - 1) else IntRange.EMPTY } public inline fun Int.downTo(to: Short): IntRange { - return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this, to - this - 1) else IntRange.EMPTY } public inline fun Int.downTo(to: Int): IntRange { - return if (this >= to) IntRange(this, to - this - 1) else IntRange(0, 0) + return if (this >= to) IntRange(this, to - this - 1) else IntRange.EMPTY } public inline fun Int.downTo(to: Long): LongRange { - return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this.toLong(), to - this - 1) else LongRange.EMPTY } public inline fun Int.downTo(to: Float): FloatRange { @@ -119,23 +119,23 @@ public inline fun Int.downTo(to: Double): DoubleRange { } public inline fun Long.downTo(to: Byte): LongRange { - return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this, to - this - 1) else LongRange.EMPTY } public inline fun Long.downTo(to: Char): LongRange { - return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this, to - this - 1) else LongRange.EMPTY } public inline fun Long.downTo(to: Short): LongRange { - return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this, to - this - 1) else LongRange.EMPTY } public inline fun Long.downTo(to: Int): LongRange { - return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this, to - this - 1) else LongRange.EMPTY } public inline fun Long.downTo(to: Long): LongRange { - return if (this >= to) LongRange(this, to - this - 1) else LongRange(0, 0) + return if (this >= to) LongRange(this, to - this - 1) else LongRange.EMPTY } public inline fun Long.downTo(to: Float): FloatRange { diff --git a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt index e719de5f4e8..29bd1eddba9 100644 --- a/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt +++ b/libraries/stdlib/test/org/jetbrains/kotlin/tools/GenerateDownTos.kt @@ -28,10 +28,9 @@ public inline fun $fromType.downTo(to: $toType): $rangeType { return $rangeType($fromExpr, to - this) }""") } else { - // TODO use empty range constant, which is not available yet (KT-2583) writer.println(""" public inline fun $fromType.downTo(to: $toType): $rangeType { - return if (this >= to) $rangeType($fromExpr, to - this - 1) else $rangeType(${if (elementType == "Char") "0.toChar()" else "0"}, 0) + return if (this >= to) $rangeType($fromExpr, to - this - 1) else $rangeType.EMPTY }""") } } From 1656f38f6fd3843c7f17ae14c2432ba4b7ffc188 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 13:58:05 +0400 Subject: [PATCH 44/72] Minor: better formatting in code generator. --- runtime/src/jet/runtime/Ranges.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/src/jet/runtime/Ranges.java b/runtime/src/jet/runtime/Ranges.java index 93af2430afc..c169c4c5601 100644 --- a/runtime/src/jet/runtime/Ranges.java +++ b/runtime/src/jet/runtime/Ranges.java @@ -378,16 +378,16 @@ public class Ranges { if (resType.equals("FloatRange") || resType.equals("DoubleRange")) { System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {\n" + - " return new " + resType + "(from, to-from);\n" + + " return new " + resType + "(from, to - from);\n" + "}"); } else { System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {" + - "\n if(from > to) {\n" + + "\n if (from > to) {\n" + " return " + resType + ".EMPTY;\n" + " }\n" + " else {\n" + - " return new " + resType + "(from, to-from+1);\n" + + " return new " + resType + "(from, to - from + 1);\n" + " }\n" + "}"); } From 7f80deeb9a0eb846e0547a6cf90e00b506e55c46 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Thu, 9 Aug 2012 14:27:33 +0300 Subject: [PATCH 45/72] test for obsolete KT-2246 --- compiler/testData/codegen/regressions/kt2246.kt | 3 +++ compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 compiler/testData/codegen/regressions/kt2246.kt diff --git a/compiler/testData/codegen/regressions/kt2246.kt b/compiler/testData/codegen/regressions/kt2246.kt new file mode 100644 index 00000000000..3f68b9f770a --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2246.kt @@ -0,0 +1,3 @@ +fun main(args: Array) { + kotlin.assert(true) +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 0b721ee206c..a361663913d 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -369,4 +369,8 @@ public class StdlibTest extends CodegenTestCase { public void testKt2318() { blackBoxFile("regressions/kt2318.kt"); } + + public void testKt2246() { + blackBoxFile("regressions/kt2246.kt"); + } } From 150695518808ceac3b3992385cbbb075e5d965ce Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Thu, 9 Aug 2012 15:36:03 +0400 Subject: [PATCH 46/72] Android module: update excluded files --- .../tests/org/jetbrains/jet/compiler/android/SpecialFiles.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java index 20f1c33372a..501a2584916 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java @@ -95,6 +95,7 @@ public class SpecialFiles { excludedFiles.add("box.kt"); // MultiFileTest not supported yet excludedFiles.add("kt2060_1.kt"); // MultiFileTest not supported yet excludedFiles.add("kt2257_1.kt"); // MultiFileTest not supported yet + excludedFiles.add("kt1528_1.kt"); // MultiFileTest not supported yet excludedFiles.add("kt684.jet"); // StackOverflow with StringBuilder (escape()) From 2386757e7c59a070ef07c0259f1d1d4209911c21 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 8 Aug 2012 19:25:58 +0400 Subject: [PATCH 47/72] Serializing inner objects in NamespaceComparator + duplicating test removed --- .../lazyResolve/namespaceComparator/innerObject.kt | 5 ----- .../lazyResolve/namespaceComparator/innerObject.txt | 6 ------ .../lazyResolve/namespaceComparator/objectInClass.txt | 4 ++++ .../LazyResolveNamespaceComparingTestGenerated.java | 5 ----- .../jetbrains/jet/test/util/NamespaceComparator.java | 10 +++++----- 5 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 compiler/testData/lazyResolve/namespaceComparator/innerObject.kt delete mode 100644 compiler/testData/lazyResolve/namespaceComparator/innerObject.txt diff --git a/compiler/testData/lazyResolve/namespaceComparator/innerObject.kt b/compiler/testData/lazyResolve/namespaceComparator/innerObject.kt deleted file mode 100644 index 5c3a9cfce8d..00000000000 --- a/compiler/testData/lazyResolve/namespaceComparator/innerObject.kt +++ /dev/null @@ -1,5 +0,0 @@ -package test - -class B { - object Obj {} -} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/innerObject.txt b/compiler/testData/lazyResolve/namespaceComparator/innerObject.txt deleted file mode 100644 index 3d5137b41d0..00000000000 --- a/compiler/testData/lazyResolve/namespaceComparator/innerObject.txt +++ /dev/null @@ -1,6 +0,0 @@ -namespace test - -internal final class test.B : jet.Any { - public final /*constructor*/ fun (): test.B - internal final val Obj: test.B.Obj -} diff --git a/compiler/testData/lazyResolve/namespaceComparator/objectInClass.txt b/compiler/testData/lazyResolve/namespaceComparator/objectInClass.txt index 4e77eee6965..24ba83cf0be 100644 --- a/compiler/testData/lazyResolve/namespaceComparator/objectInClass.txt +++ b/compiler/testData/lazyResolve/namespaceComparator/objectInClass.txt @@ -3,4 +3,8 @@ namespace test internal final class test.A : jet.Any { public final /*constructor*/ fun (): test.A internal final val B: test.A.B + internal final object test.A.B : jet.Any { + internal final /*constructor*/ fun (): test.A.B + internal final fun foo(/*0*/ a: jet.Int): jet.String + } } diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 4d452133d30..905059c724f 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -1287,11 +1287,6 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/InnerClassNameClash.kt"); } - @TestMetadata("innerObject.kt") - public void testInnerObject() throws Exception { - doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/innerObject.kt"); - } - @TestMetadata("objectInClass.kt") public void testObjectInClass() throws Exception { doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/objectInClass.kt"); diff --git a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java index df905e87823..f562af15f7d 100644 --- a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java +++ b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java @@ -743,11 +743,11 @@ public class NamespaceComparator { memberStrings.add(memberSb.toString()); } - //for (DeclarationDescriptor object : memberScope.getObjectDescriptors()) { - // StringBuilder objectSb = new StringBuilder(); - // new FullContentSerialier(objectSb).serialize(object); - // memberStrings.add(objectSb.toString()); - //} + for (DeclarationDescriptor object : memberScope.getObjectDescriptors()) { + StringBuilder objectSb = new StringBuilder(); + new FullContentSerialier(objectSb).serialize(object); + memberStrings.add(objectSb.toString()); + } Collections.sort(memberStrings, new MemberComparator()); From 56414e90b3eb2f3765e9d4640162f3bc05042a4d Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 9 Aug 2012 15:19:56 +0400 Subject: [PATCH 48/72] Properly merging class scopes --- .../resolve/lazy/LazyClassDescriptor.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java index 5d5e1855fd6..54f566ac2d2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java @@ -86,6 +86,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes @NotNull JetClassLikeInfo classLikeInfo ) { this.resolveSession = resolveSession; + this.name = name; if (classLikeInfo.getCorrespondingClassOrObject() != null) { this.resolveSession.getTrace().record(BindingContext.CLASS, classLikeInfo.getCorrespondingClassOrObject(), this); @@ -95,7 +96,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes JetClassLikeInfo classLikeInfoForMembers = classLikeInfo.getClassKind() != ClassKind.ENUM_CLASS ? classLikeInfo : noEnumEntries(classLikeInfo); this.declarationProvider = resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfoForMembers); - this.name = name; this.containingDeclaration = containingDeclaration; this.unsubstitutedMemberScope = new LazyClassMemberScope(resolveSession, declarationProvider, this); this.unsubstitutedInnerClassesScope = new InnerClassesScopeWrapper(unsubstitutedMemberScope); @@ -130,12 +130,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes public JetScope getScopeForClassHeaderResolution() { if (scopeForClassHeaderResolution == null) { WritableScopeImpl scope = new WritableScopeImpl( - resolveSession.getResolutionScope(declarationProvider.getOwnerInfo().getScopeAnchor()), this, RedeclarationHandler.DO_NOTHING, "Class Header Resolution"); + JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Class Header Resolution"); for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) { scope.addClassifierDescriptor(typeParameterDescriptor); } scope.changeLockLevel(WritableScope.LockLevel.READING); - scopeForClassHeaderResolution = scope; + + scopeForClassHeaderResolution = new ChainedScope(this, scope, resolveSession.getResolutionScope(declarationProvider.getOwnerInfo().getScopeAnchor())); } return scopeForClassHeaderResolution; } @@ -143,12 +144,11 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes public JetScope getScopeForMemberDeclarationResolution() { if (scopeForMemberDeclarationResolution == null) { WritableScopeImpl scope = new WritableScopeImpl( - getScopeForMemberLookup(), this, RedeclarationHandler.DO_NOTHING, "Member Declaration Resolution"); + JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Member Declaration Resolution"); scope.addLabeledDeclaration(this); - scope.importScope(getScopeForClassHeaderResolution()); - scope.changeLockLevel(WritableScope.LockLevel.READING); - scopeForMemberDeclarationResolution = scope; + + scopeForMemberDeclarationResolution = new ChainedScope(this, scope, getScopeForMemberLookup(), getScopeForClassHeaderResolution()); } return scopeForMemberDeclarationResolution; } @@ -159,7 +159,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes if (scopeForPropertyInitializerResolution == null) { WritableScopeImpl scope = new WritableScopeImpl( - getScopeForMemberDeclarationResolution(), this, RedeclarationHandler.DO_NOTHING, "Property Initializer Resolution"); + JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Property Initializer Resolution"); List parameters = primaryConstructor.getValueParameters(); for (ValueParameterDescriptor valueParameterDescriptor : parameters) { @@ -167,7 +167,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes } scope.changeLockLevel(WritableScope.LockLevel.READING); - scopeForPropertyInitializerResolution = scope; + + scopeForPropertyInitializerResolution = new ChainedScope(this, scope, getScopeForMemberDeclarationResolution()); } return scopeForPropertyInitializerResolution; } From 8dd922541150507ccf2d5140663a8da7e4eb5f55 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 9 Aug 2012 15:44:18 +0400 Subject: [PATCH 49/72] Object descriptors for enum entries created properly --- .../resolve/lazy/AbstractLazyMemberScope.java | 23 +++++++++++---- .../resolve/lazy/LazyClassMemberScope.java | 25 +++++------------ .../jet/lang/resolve/lazy/ResolveSession.java | 28 ++----------------- .../lazyResolve/namespaceComparator/enum.txt | 9 ++++++ 4 files changed, 36 insertions(+), 49 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java index 2e72f35211c..379028a344b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java @@ -69,10 +69,11 @@ public abstract class AbstractLazyMemberScope fromSupertypes = Lists.newArrayList(); for (JetType supertype : thisDescriptor.getTypeConstructor().getSupertypes()) { @@ -264,9 +248,14 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope generateConstructorsFor = + EnumSet.of(ClassKind.CLASS, ClassKind.ANNOTATION_CLASS, ClassKind.OBJECT, ClassKind.ENUM_CLASS, ClassKind.ENUM_ENTRY); + if (generateConstructorsFor.contains(thisDescriptor.getKind())) { JetClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject(); - if (thisDescriptor.getKind() != ClassKind.OBJECT) { + if ( + thisDescriptor.getKind() != ClassKind.OBJECT // a fake class object of an enum class + && !declaresObjectOrEnumConstant(classOrObject) // normal objects and enum entries with no constructors + ) { JetClass jetClass = (JetClass) classOrObject; ConstructorDescriptorImpl constructor = resolveSession.getInjector().getDescriptorResolver() .resolvePrimaryConstructorDescriptor(thisDescriptor.getScopeForClassHeaderResolution(), diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java index bce8cf7619c..45ebff30efd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java @@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.lazy; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.Maps; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -32,7 +31,6 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTraceContext; -import org.jetbrains.jet.lang.resolve.lazy.data.JetClassInfoUtil; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.name.Name; @@ -40,7 +38,6 @@ import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import java.util.List; -import java.util.Map; /** * @author abreslav @@ -66,7 +63,6 @@ public class ResolveSession { private final InjectorForLazyResolve injector; private final ModuleConfiguration moduleConfiguration; - private final Map enumEntryClassDescriptorCache = Maps.newHashMap(); private final Function classifierAliases; public ResolveSession( @@ -136,10 +132,6 @@ public class ResolveSession { @NotNull public ClassDescriptor getClassDescriptor(@NotNull JetClassOrObject classOrObject) { - if (classOrObject instanceof JetEnumEntry) { - JetEnumEntry enumEntry = (JetEnumEntry) classOrObject; - return getEnumEntryClassDescriptor(enumEntry); - } if (classOrObject.getParent() instanceof JetClassObject) { return getClassObjectDescriptor((JetClassObject) classOrObject.getParent()); } @@ -147,29 +139,15 @@ public class ResolveSession { Name name = classOrObject.getNameAsName(); assert name != null : "Name is null for " + classOrObject + " " + classOrObject.getText(); ClassifierDescriptor classifier = resolutionScope.getClassifier(name); + if (classifier == null) { + classifier = resolutionScope.getObjectDescriptor(name); + } if (classifier == null) { throw new IllegalArgumentException("Could not find a classifier for " + classOrObject + " " + classOrObject.getText()); } return (ClassDescriptor) classifier; } - @NotNull - private ClassDescriptor getEnumEntryClassDescriptor(@NotNull JetEnumEntry jetEnumEntry) { - ClassDescriptor classDescriptor = enumEntryClassDescriptorCache.get(jetEnumEntry); - if (classDescriptor != null) { - return classDescriptor; - } - - DeclarationDescriptor containingDeclaration = getInjector().getScopeProvider().getResolutionScopeForDeclaration(jetEnumEntry) - .getContainingDeclaration(); - LazyClassDescriptor newClassDescriptor = new LazyClassDescriptor(this, - containingDeclaration, - jetEnumEntry.getNameAsName(), - JetClassInfoUtil.createClassLikeInfo(jetEnumEntry)); - enumEntryClassDescriptorCache.put(jetEnumEntry, newClassDescriptor); - return newClassDescriptor; - } - /*package*/ LazyClassDescriptor getClassObjectDescriptor(JetClassObject classObject) { LazyClassDescriptor classDescriptor = (LazyClassDescriptor) getClassDescriptor(PsiTreeUtil.getParentOfType(classObject, JetClass.class)); LazyClassDescriptor classObjectDescriptor = (LazyClassDescriptor) classDescriptor.getClassObjectDescriptor(); diff --git a/compiler/testData/lazyResolve/namespaceComparator/enum.txt b/compiler/testData/lazyResolve/namespaceComparator/enum.txt index 7ba892f5636..2bde4faa75c 100644 --- a/compiler/testData/lazyResolve/namespaceComparator/enum.txt +++ b/compiler/testData/lazyResolve/namespaceComparator/enum.txt @@ -6,5 +6,14 @@ internal final enum class test.Test : jet.Any { internal final /*constructor*/ fun (): test.Test. internal final val A: test.Test..A internal final val C: test.Test..C + internal final enum entry test.Test..A : test.Test { + internal final /*constructor*/ fun (): test.Test..A + } + internal final enum entry test.Test..B : test.Test { + public final /*constructor*/ fun (/*0*/ x: jet.Int): test.Test..B + } + internal final enum entry test.Test..C : test.Test { + internal final /*constructor*/ fun (): test.Test..C + } } } From e087d50a7f780817f05fdc450a8f8a82ae1416ec Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 9 Aug 2012 17:35:03 +0400 Subject: [PATCH 50/72] printlnWithNoIndent() added --- compiler/util/src/org/jetbrains/jet/utils/Printer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/util/src/org/jetbrains/jet/utils/Printer.java b/compiler/util/src/org/jetbrains/jet/utils/Printer.java index 01545fe008a..dacc2a294e5 100644 --- a/compiler/util/src/org/jetbrains/jet/utils/Printer.java +++ b/compiler/util/src/org/jetbrains/jet/utils/Printer.java @@ -46,6 +46,11 @@ public class Printer { } } + public void printlnWithNoIndent(Object... objects) { + printWithNoIndent(objects); + out.append("\n"); + } + public void pushIndent() { indent += INDENTATION_UNIT; } From 577d83605f2886176adacef1c0f600a6117b664c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 16:12:35 +0400 Subject: [PATCH 51/72] Made test for KT-821 actually testing creation of ranges using constructors, but not "minus" operator. --- .../testData/codegen/regressions/kt821.kt | 41 ++++++------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/compiler/testData/codegen/regressions/kt821.kt b/compiler/testData/codegen/regressions/kt821.kt index 46baa0f4c26..5edc90cd96f 100644 --- a/compiler/testData/codegen/regressions/kt821.kt +++ b/compiler/testData/codegen/regressions/kt821.kt @@ -2,38 +2,23 @@ fun box() : String { val r1 = IntRange(1, 4) if(r1.end != 4 || r1.isReversed || r1.size != 4) return "fail" - val r3 = -(0..5) - if(r3.start != 5 || r3.end != 0 || !r3.isReversed || r3.size != 6) return "fail" + val r2 = ByteRange(1, 4) + if(r2.end != 4.toByte() || r2.isReversed || r2.size != 4) return "fail" - val r4 = -r3 - if(r4.end != 5 || r4.isReversed || r4.size != 6) return "fail" + val r3 = ShortRange(1, 4) + if(r3.end != 4.toShort() || r3.isReversed || r3.size != 4) return "fail" - val r5 = ByteRange(1, 4) - if(r5.end != 4.toByte() || r5.isReversed || r5.size != 4) return "fail" + val r4 = CharRange('a', 4) + if(r4.end != 'd' || r4.isReversed || r4.size != 4) return "fail" - val r7 = -(0.toByte()..5.toByte()) - if(r7.start != 5.toByte() || r7.end != 0.toByte() || !r7.isReversed) return "fail" + val r5 = FloatRange(0.0.toFloat(), 1.0.toFloat()) + if(r5.end != 1.0.toFloat() || r5.isReversed || r5.size != 1.0.toFloat()) return "fail" - val r9 = -r7 - if(r9.end != 5.toByte() || r9.isReversed) return "fail" + val r6 = DoubleRange(0.0, 1.0) + if(r6.end != 1.0 || r6.isReversed || r6.size != 1.0) return "fail" - val r10 = ShortRange(1, 4) - if(r10.end != 4.toShort() || r10.isReversed || r10.size != 4) return "fail" - - val r12 = -(0.toShort()..5.toShort()) - if(r12.start != 5.toShort() || r12.end != 0.toShort() || !r12.isReversed) return "fail" - - val r13 = -r12 - if(r13.end != 5.toShort() || r13.isReversed) return "fail" - - val r14 = CharRange('a', 4) - if(r14.end != 'd' || r14.isReversed || r14.size != 4) return "fail" - - val r16 = -('a'..'e') - if(r16.start != 'e' || r16.end != 'a' || !r16.isReversed) return "fail" - - val r17 = -r16 - if(r17.end != 'e' || r17.isReversed) return "fail" + val r7 = LongRange(1, 4) + if(r7.end != 4.toLong() || r7.isReversed || r7.size != 4.toLong()) return "fail" return "OK" -} \ No newline at end of file +} From 1bc99ef19a1f19768f2c6b75e6f2b21bcdf4c752 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 16:14:00 +0400 Subject: [PATCH 52/72] KT-2579 Rename Range.minus() to reversed and make it extension #KT-2579 fixed --- compiler/frontend/src/jet/Ranges.jet | 14 ----------- compiler/testData/builtin-classes.txt | 7 ------ .../testData/codegen/regressions/kt1076.kt | 2 +- libraries/stdlib/src/kotlin/Ranges.kt | 23 +++++++++++++++++++ libraries/stdlib/test/language/RangeTest.kt | 19 +++++++++++++++ runtime/src/jet/ByteRange.java | 4 ---- runtime/src/jet/CharRange.java | 4 ---- runtime/src/jet/DoubleRange.java | 4 ---- runtime/src/jet/FloatRange.java | 4 ---- runtime/src/jet/IntRange.java | 4 ---- runtime/src/jet/LongRange.java | 4 ---- runtime/src/jet/ShortRange.java | 4 ---- 12 files changed, 43 insertions(+), 50 deletions(-) create mode 100644 libraries/stdlib/src/kotlin/Ranges.kt diff --git a/compiler/frontend/src/jet/Ranges.jet b/compiler/frontend/src/jet/Ranges.jet index ee0635bf3a4..e4e3a01c092 100644 --- a/compiler/frontend/src/jet/Ranges.jet +++ b/compiler/frontend/src/jet/Ranges.jet @@ -13,8 +13,6 @@ public class IntRange(public val start : Int, public val size : Int) : Range, jet.ByteIterable { public final val isReversed: jet.Boolean public open override /*1*/ fun iterator(): jet.ByteIterator public final val iteratorStart: jet.Byte - public final fun minus(): jet.ByteRange public final val size: jet.Int public final val start: jet.Byte public final fun step(/*0*/ step: jet.Int): jet.ByteIterator @@ -220,7 +219,6 @@ public final class jet.CharRange : jet.Range, jet.CharIterable { public final val isReversed: jet.Boolean public open override /*1*/ fun iterator(): jet.CharIterator public final val iteratorStart: jet.Char - public final fun minus(): jet.CharRange public final val size: jet.Int public final val start: jet.Char public final fun step(/*0*/ step: jet.Int): jet.CharIterator @@ -323,7 +321,6 @@ public final class jet.DoubleRange : jet.Range { public open override /*1*/ fun contains(/*0*/ elem: jet.Double): jet.Boolean public final val end: jet.Double public final val isReversed: jet.Boolean - public final fun minus(): jet.DoubleRange public final val size: jet.Double public final val start: jet.Double public final fun step(/*0*/ step: jet.Double): jet.DoubleIterator @@ -511,7 +508,6 @@ public final class jet.FloatRange : jet.Range { public open override /*1*/ fun contains(/*0*/ elem: jet.Float): jet.Boolean public final val end: jet.Float public final val isReversed: jet.Boolean - public final fun minus(): jet.FloatRange public final val size: jet.Float public final val start: jet.Float public final fun step(/*0*/ step: jet.Float): jet.FloatIterator @@ -712,7 +708,6 @@ public final class jet.IntRange : jet.Range, jet.IntIterable { public final val isReversed: jet.Boolean public open override /*1*/ fun iterator(): jet.IntIterator public final val iteratorStart: jet.Int - public final fun minus(): jet.IntRange public final val size: jet.Int public final val start: jet.Int public final fun step(/*0*/ step: jet.Int): jet.IntIterator @@ -824,7 +819,6 @@ public final class jet.LongRange : jet.Range, jet.LongIterable { public final val isReversed: jet.Boolean public open override /*1*/ fun iterator(): jet.LongIterator public final val iteratorStart: jet.Long - public final fun minus(): jet.LongRange public final val size: jet.Long public final val start: jet.Long public final fun step(/*0*/ step: jet.Long): jet.LongIterator @@ -940,7 +934,6 @@ public final class jet.ShortRange : jet.Range, jet.ShortIterable { public final val isReversed: jet.Boolean public open override /*1*/ fun iterator(): jet.ShortIterator public final val iteratorStart: jet.Short - public final fun minus(): jet.ShortRange public final val size: jet.Int public final val start: jet.Short public final fun step(/*0*/ step: jet.Int): jet.ShortIterator diff --git a/compiler/testData/codegen/regressions/kt1076.kt b/compiler/testData/codegen/regressions/kt1076.kt index 971acf266da..918713f681f 100644 --- a/compiler/testData/codegen/regressions/kt1076.kt +++ b/compiler/testData/codegen/regressions/kt1076.kt @@ -4,7 +4,7 @@ fun box() : String { cnt++ } - for (n in -(1..5)) + for (n in (1..5).reversed) cnt++ return if(cnt == 9) "OK" else cnt.toString() diff --git a/libraries/stdlib/src/kotlin/Ranges.kt b/libraries/stdlib/src/kotlin/Ranges.kt new file mode 100644 index 00000000000..953c29873b1 --- /dev/null +++ b/libraries/stdlib/src/kotlin/Ranges.kt @@ -0,0 +1,23 @@ +package kotlin + +public val CharRange.reversed: CharRange + get() = CharRange(end, if (start < end) -size else size) + +public val ByteRange.reversed: ByteRange + get() = ByteRange(end, if (start < end) -size else size) + +public val ShortRange.reversed: ShortRange + get() = ShortRange(end, if (start < end) -size else size) + +public val IntRange.reversed: IntRange + get() = IntRange(end, if (start < end) -size else size) + +public val FloatRange.reversed: FloatRange + get() = FloatRange(end, if (start < end) -size else size) + +public val LongRange.reversed: LongRange + get() = LongRange(end, if (start < end) -size else size) + +public val DoubleRange.reversed: DoubleRange + get() = DoubleRange(end, if (start < end) -size else size) + diff --git a/libraries/stdlib/test/language/RangeTest.kt b/libraries/stdlib/test/language/RangeTest.kt index a31c1a08042..239a402f5dc 100644 --- a/libraries/stdlib/test/language/RangeTest.kt +++ b/libraries/stdlib/test/language/RangeTest.kt @@ -23,4 +23,23 @@ class RangeTest { assertTrue(range.contains(9)) assertFalse(range.contains(10)) } + + test fun reversedRanges() { + val intRange = 0..9 + val reversedIntRange = intRange.reversed + assertEquals(10, reversedIntRange.size) + assertEquals(9, reversedIntRange.start) + assertEquals(0, reversedIntRange.end) + assertEquals(intRange, reversedIntRange.reversed) + + val doubleRange = 0.0..9.0 + val reversedDoubleRange = doubleRange.reversed + assertEquals(9.0, reversedDoubleRange.size) + assertEquals(9.0, reversedDoubleRange.start) + assertEquals(0.0, reversedDoubleRange.end) + assertEquals(doubleRange, reversedDoubleRange.reversed) + + assertEquals(IntRange.EMPTY, IntRange.EMPTY.reversed) + assertEquals(FloatRange.EMPTY, FloatRange.EMPTY.reversed) + } } \ No newline at end of file diff --git a/runtime/src/jet/ByteRange.java b/runtime/src/jet/ByteRange.java index 10d5c3005e3..7a51037fd00 100644 --- a/runtime/src/jet/ByteRange.java +++ b/runtime/src/jet/ByteRange.java @@ -93,10 +93,6 @@ public final class ByteRange implements Range, ByteIterable { return new MyIterator(start, count, step); } - public ByteRange minus() { - return new ByteRange(getEnd(), -count); - } - @Override public ByteIterator iterator() { return new MyIterator(start, count, 1); diff --git a/runtime/src/jet/CharRange.java b/runtime/src/jet/CharRange.java index ae044bb5add..2059ceb7ade 100644 --- a/runtime/src/jet/CharRange.java +++ b/runtime/src/jet/CharRange.java @@ -86,10 +86,6 @@ public final class CharRange implements Range, CharIterable { return count < 0 ? -count : count; } - public CharRange minus() { - return new CharRange(getEnd(), -count); - } - public CharIterator step(int step) { if (step < 0) return new MyIterator(getEnd(), -count, -step); diff --git a/runtime/src/jet/DoubleRange.java b/runtime/src/jet/DoubleRange.java index 01bb39f361f..d38d841faf4 100644 --- a/runtime/src/jet/DoubleRange.java +++ b/runtime/src/jet/DoubleRange.java @@ -87,10 +87,6 @@ public final class DoubleRange implements Range { return size < 0 ? -size : size; } - public DoubleRange minus() { - return new DoubleRange(getEnd(), -size); - } - public static DoubleRange count(int length) { return new DoubleRange(0, length); } diff --git a/runtime/src/jet/FloatRange.java b/runtime/src/jet/FloatRange.java index 8962310deea..fb3af3a68b1 100644 --- a/runtime/src/jet/FloatRange.java +++ b/runtime/src/jet/FloatRange.java @@ -83,10 +83,6 @@ public final class FloatRange implements Range { return size < 0 ? -size : size; } - public FloatRange minus() { - return new FloatRange(getEnd(), -size); - } - public static FloatRange count(int length) { return new FloatRange(0, length); } diff --git a/runtime/src/jet/IntRange.java b/runtime/src/jet/IntRange.java index f73d7a8331a..2d84304fcfd 100644 --- a/runtime/src/jet/IntRange.java +++ b/runtime/src/jet/IntRange.java @@ -102,10 +102,6 @@ public final class IntRange implements Range, IntIterable { return count < 0 ? -count : count; } - public IntRange minus() { - return new IntRange(getEnd(), -count); - } - @Override public IntIterator iterator() { return new MyIterator(start, count, 1); diff --git a/runtime/src/jet/LongRange.java b/runtime/src/jet/LongRange.java index 114155d0123..3e03d9f95d8 100644 --- a/runtime/src/jet/LongRange.java +++ b/runtime/src/jet/LongRange.java @@ -93,10 +93,6 @@ public final class LongRange implements Range, LongIterable { return count < 0 ? -count : count; } - public LongRange minus() { - return new LongRange(getEnd(), -count); - } - @Override public LongIterator iterator() { return new MyIterator(start, count, 1); diff --git a/runtime/src/jet/ShortRange.java b/runtime/src/jet/ShortRange.java index d94206c0894..0cc3d603065 100644 --- a/runtime/src/jet/ShortRange.java +++ b/runtime/src/jet/ShortRange.java @@ -93,10 +93,6 @@ public final class ShortRange implements Range, ShortIterable { return count < 0 ? -count : count; } - public ShortRange minus() { - return new ShortRange(getEnd(), -count); - } - @Override public ShortIterator iterator() { return new MyIterator(start, count, 1); From d7b8ea1817dea32ddb5cd8ef75536972bb1a34ba Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 16:19:10 +0400 Subject: [PATCH 53/72] Made IntRange.toString() aware of empty ranges. --- runtime/src/jet/IntRange.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/src/jet/IntRange.java b/runtime/src/jet/IntRange.java index 2d84304fcfd..e53f28bc95c 100644 --- a/runtime/src/jet/IntRange.java +++ b/runtime/src/jet/IntRange.java @@ -32,9 +32,13 @@ public final class IntRange implements Range, IntIterable { @Override public String toString() { - if (count >= 0) { + if (count == 0) { + return ""; + } + else if (count > 0) { return getStart() + ".rangeTo(" + getEnd() + ")"; - } else { + } + else { return getStart() + ".downTo(" + getEnd() + ")"; } } From 1b27d0db607601ebbc5b5ec05a872398e19b3d3c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 16:23:09 +0400 Subject: [PATCH 54/72] Added toString() method to all ranges. --- runtime/src/jet/ByteRange.java | 13 +++++++++++++ runtime/src/jet/CharRange.java | 13 +++++++++++++ runtime/src/jet/DoubleRange.java | 13 +++++++++++++ runtime/src/jet/FloatRange.java | 13 +++++++++++++ runtime/src/jet/LongRange.java | 14 ++++++++++++++ runtime/src/jet/ShortRange.java | 13 +++++++++++++ 6 files changed, 79 insertions(+) diff --git a/runtime/src/jet/ByteRange.java b/runtime/src/jet/ByteRange.java index 7a51037fd00..f24f74050c5 100644 --- a/runtime/src/jet/ByteRange.java +++ b/runtime/src/jet/ByteRange.java @@ -30,6 +30,19 @@ public final class ByteRange implements Range, ByteIterable { this.count = count; } + @Override + public String toString() { + if (count == 0) { + return ""; + } + else if (count > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + @Override public boolean contains(Byte item) { if (item == null) return false; diff --git a/runtime/src/jet/CharRange.java b/runtime/src/jet/CharRange.java index 2059ceb7ade..82900825914 100644 --- a/runtime/src/jet/CharRange.java +++ b/runtime/src/jet/CharRange.java @@ -30,6 +30,19 @@ public final class CharRange implements Range, CharIterable { this.count = count; } + @Override + public String toString() { + if (count == 0) { + return ""; + } + else if (count > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + @Override public boolean contains(Character item) { if (item == null) return false; diff --git a/runtime/src/jet/DoubleRange.java b/runtime/src/jet/DoubleRange.java index d38d841faf4..bdfa0e21a0b 100644 --- a/runtime/src/jet/DoubleRange.java +++ b/runtime/src/jet/DoubleRange.java @@ -30,6 +30,19 @@ public final class DoubleRange implements Range { this.size = size; } + @Override + public String toString() { + if (size == 0.0) { + return ""; + } + else if (size > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + @Override public boolean contains(Double item) { if (item == null) return false; diff --git a/runtime/src/jet/FloatRange.java b/runtime/src/jet/FloatRange.java index fb3af3a68b1..28b729db38f 100644 --- a/runtime/src/jet/FloatRange.java +++ b/runtime/src/jet/FloatRange.java @@ -30,6 +30,19 @@ public final class FloatRange implements Range { this.size = size; } + @Override + public String toString() { + if (size == 0.0) { + return ""; + } + else if (size > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + @Override public boolean contains(Float item) { if (item == null) return false; diff --git a/runtime/src/jet/LongRange.java b/runtime/src/jet/LongRange.java index 3e03d9f95d8..6f400419ca2 100644 --- a/runtime/src/jet/LongRange.java +++ b/runtime/src/jet/LongRange.java @@ -30,6 +30,20 @@ public final class LongRange implements Range, LongIterable { this.count = count; } + @Override + public String toString() { + if (count == 0) { + return ""; + } + else if (count > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + + public LongIterator step(long step) { if (step < 0) return new MyIterator(getEnd(), -count, -step); diff --git a/runtime/src/jet/ShortRange.java b/runtime/src/jet/ShortRange.java index 0cc3d603065..a82f7eb0451 100644 --- a/runtime/src/jet/ShortRange.java +++ b/runtime/src/jet/ShortRange.java @@ -30,6 +30,19 @@ public final class ShortRange implements Range, ShortIterable { this.count = count; } + @Override + public String toString() { + if (count == 0) { + return ""; + } + else if (count > 0) { + return getStart() + ".rangeTo(" + getEnd() + ")"; + } + else { + return getStart() + ".downTo(" + getEnd() + ")"; + } + } + public ShortIterator step(int step) { if (step < 0) return new MyIterator(getEnd(), -count, -step); From 5d8de8fbd22a8e3d757c180294ab12c1309eb7e7 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 17:21:25 +0400 Subject: [PATCH 55/72] KT-2596 Can't use iterator in for-loop #KT-2596 fixed --- compiler/testData/codegen/regressions/kt2596.kt | 7 +++++++ compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java | 4 ++++ libraries/stdlib/src/kotlin/Standard.kt | 5 ----- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt2596.kt diff --git a/compiler/testData/codegen/regressions/kt2596.kt b/compiler/testData/codegen/regressions/kt2596.kt new file mode 100644 index 00000000000..e5311df8a4e --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2596.kt @@ -0,0 +1,7 @@ +fun box(): String { + val iterator: Iterator = (0..0).iterator() + for (i in iterator) { + return "OK" + } + return "fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index a361663913d..7f26e004cf7 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -373,4 +373,8 @@ public class StdlibTest extends CodegenTestCase { public void testKt2246() { blackBoxFile("regressions/kt2246.kt"); } + + public void testKt2596() { + blackBoxFile("regressions/kt2596.kt"); + } } diff --git a/libraries/stdlib/src/kotlin/Standard.kt b/libraries/stdlib/src/kotlin/Standard.kt index dd388800575..b8e8a1c90bc 100644 --- a/libraries/stdlib/src/kotlin/Standard.kt +++ b/libraries/stdlib/src/kotlin/Standard.kt @@ -5,11 +5,6 @@ import java.util.Collection import java.util.HashSet import java.util.LinkedList -/** -Helper to make jet.Iterator usable in for -*/ -public inline fun Iterator.iterator() : Iterator = this - /** Helper to make java.util.Iterator usable in for */ From b359592fd188a201a2ec7939a32e9200c9f0cb68 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 17:34:10 +0400 Subject: [PATCH 56/72] Optimized imports --- .../jet/lang/descriptors/MutableClassDescriptorLite.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java index 29146968b7f..b45513ba267 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java @@ -17,11 +17,9 @@ package org.jetbrains.jet.lang.descriptors; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper; import org.jetbrains.jet.lang.resolve.scopes.JetScope; @@ -31,7 +29,10 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.resolve.DescriptorRenderer; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * @author Stepan Koltsov From 592f01ed74df407f61a8c09e7a5dec87d8807192 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 17:41:41 +0400 Subject: [PATCH 57/72] Made StandardLibraryReferenceResolver aware of class objects in built-ins. --- .../references/StandardLibraryReferenceResolver.java | 12 ++++++++++-- idea/testData/resolve/std/emptyRange.kt | 2 ++ .../StandardLibraryReferenceResolverTest.java | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 idea/testData/resolve/std/emptyRange.kt diff --git a/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java b/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java index a9b4fe8aeac..2be22f64391 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java +++ b/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java @@ -117,15 +117,23 @@ public class StandardLibraryReferenceResolver extends AbstractProjectComponent { @Nullable private DeclarationDescriptor findCurrentDescriptor(@NotNull DeclarationDescriptor originalDescriptor) { + DeclarationDescriptor parent = originalDescriptor.getContainingDeclaration(); if (originalDescriptor instanceof ClassDescriptor) { - return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); + if (((ClassDescriptor) originalDescriptor).getKind() == ClassKind.OBJECT) { + if (parent == null) return null; + parent = findCurrentDescriptor(parent); + if (parent == null) return null; + return ((ClassDescriptor) parent).getClassObjectDescriptor(); + } + else { + return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); + } } else if (originalDescriptor instanceof NamespaceDescriptor) { return bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); } else { - DeclarationDescriptor parent = originalDescriptor.getContainingDeclaration(); if (parent == null) return null; parent = findCurrentDescriptor(parent); JetScope memberScope; diff --git a/idea/testData/resolve/std/emptyRange.kt b/idea/testData/resolve/std/emptyRange.kt new file mode 100644 index 00000000000..438a50b3eda --- /dev/null +++ b/idea/testData/resolve/std/emptyRange.kt @@ -0,0 +1,2 @@ +val empty = IntRange.EMPTY +//jet/Ranges.jet:EMPTY \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java index 46905c4475a..7d61913697f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java @@ -67,6 +67,10 @@ public class StandardLibraryReferenceResolverTest extends ResolveTestCase { doTest(); } + public void testEmptyRange() throws Exception { + doTest(); + } + public void testAllReferencesResolved() { StandardLibraryReferenceResolver referenceResolver = getProject().getComponent(StandardLibraryReferenceResolver.class); for (DeclarationDescriptor descriptor : getAllStandardDescriptors(JetStandardClasses.STANDARD_CLASSES_NAMESPACE)) { From c8fc299f43de735648e2f051a6270f1222cea273 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Aug 2012 17:53:37 +0400 Subject: [PATCH 58/72] Extracted parts of StandardLibraryReferenceResolver.findCurrentDescriptor() into methods. --- .../StandardLibraryReferenceResolver.java | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java b/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java index 2be22f64391..1a384febea8 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java +++ b/idea/src/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolver.java @@ -115,46 +115,46 @@ public class StandardLibraryReferenceResolver extends AbstractProjectComponent { }); } + private DeclarationDescriptor findCurrentDescriptorForClass(@NotNull ClassDescriptor originalDescriptor) { + if (originalDescriptor.getKind() == ClassKind.OBJECT) { + DeclarationDescriptor currentParent = findCurrentDescriptor(originalDescriptor.getContainingDeclaration()); + if (currentParent == null) return null; + return ((ClassDescriptor) currentParent).getClassObjectDescriptor(); + } + else { + return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); + } + } + + private DeclarationDescriptor findCurrentDescriptorForMember(@NotNull MemberDescriptor originalDescriptor) { + JetScope memberScope = getMemberScope(findCurrentDescriptor(originalDescriptor.getContainingDeclaration())); + if (memberScope == null) return null; + + String renderedOriginal = DescriptorRenderer.TEXT.render(originalDescriptor); + for (DeclarationDescriptor member : memberScope.getAllDescriptors()) { + if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member).replace(TUPLE0_FQ_NAME.getFqName(), + JetStandardClasses.UNIT_ALIAS.getName()))) { + return member; + } + } + return null; + } + @Nullable private DeclarationDescriptor findCurrentDescriptor(@NotNull DeclarationDescriptor originalDescriptor) { - DeclarationDescriptor parent = originalDescriptor.getContainingDeclaration(); if (originalDescriptor instanceof ClassDescriptor) { - if (((ClassDescriptor) originalDescriptor).getKind() == ClassKind.OBJECT) { - if (parent == null) return null; - parent = findCurrentDescriptor(parent); - if (parent == null) return null; - return ((ClassDescriptor) parent).getClassObjectDescriptor(); - } - else { - return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); - } + return findCurrentDescriptorForClass((ClassDescriptor) originalDescriptor); } else if (originalDescriptor instanceof NamespaceDescriptor) { return bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, DescriptorUtils.getFQName(originalDescriptor).toSafe()); } - else { - if (parent == null) return null; - parent = findCurrentDescriptor(parent); - JetScope memberScope; - if (parent instanceof ClassDescriptor) { - memberScope = ((ClassDescriptor) parent).getDefaultType().getMemberScope(); - } - else if (parent instanceof NamespaceDescriptor) { - memberScope = ((NamespaceDescriptor)parent).getMemberScope(); - } - else { - return null; - } - String renderedOriginal = DescriptorRenderer.TEXT.render(originalDescriptor); - for (DeclarationDescriptor member : memberScope.getAllDescriptors()) { - if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member).replace(TUPLE0_FQ_NAME.getFqName(), - JetStandardClasses.UNIT_ALIAS.getName()))) { - return member; - } - } + else if (originalDescriptor instanceof MemberDescriptor) { + return findCurrentDescriptorForMember((MemberDescriptor) originalDescriptor); + } + else { + return null; } - return null; } @Nullable @@ -179,6 +179,19 @@ public class StandardLibraryReferenceResolver extends AbstractProjectComponent { return null; } + @Nullable + private static JetScope getMemberScope(@Nullable DeclarationDescriptor parent) { + if (parent instanceof ClassDescriptor) { + return ((ClassDescriptor) parent).getDefaultType().getMemberScope(); + } + else if (parent instanceof NamespaceDescriptor) { + return ((NamespaceDescriptor)parent).getMemberScope(); + } + else { + return null; + } + } + private static class FakeJetNamespaceDescriptor extends NamespaceDescriptorImpl { private WritableScope memberScope; From b497fcc16730b7de6200e08fd3b1961d526e91ad Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Fri, 10 Aug 2012 09:40:59 +0300 Subject: [PATCH 59/72] removing hack where ClosureAnnotator deals with range class objects --- .../jet/codegen/ClosureAnnotator.java | 30 ++++--------------- .../jetbrains/jet/codegen/JetTypeMapper.java | 3 ++ .../jet/lang/resolve/java/JvmAbi.java | 3 ++ 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java index aa76f53a2f4..5dfd501ff89 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java @@ -18,7 +18,6 @@ package org.jetbrains.jet.codegen; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.*; @@ -30,8 +29,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; -import org.jetbrains.jet.lang.types.lang.PrimitiveType; import javax.inject.Inject; import java.util.*; @@ -67,20 +64,6 @@ public class ClosureAnnotator { public void init() { mapFilesToNamespaces(files); prepareAnonymousClasses(); - prepareClassObjectsForBuiltinRanges(); - } - - private void prepareClassObjectsForBuiltinRanges() { - // this is needed for range classes because they have class objects with - // intrinsic members - JetScope stdLibraryScope = JetStandardLibrary.getInstance().getLibraryScope(); - for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { - ClassDescriptor klass = (ClassDescriptor) stdLibraryScope.getClassifier(type.getRangeTypeName()); - String rangeInternalName = JvmClassName.byFqNameWithoutInnerClasses( - JetStandardClasses.STANDARD_CLASSES_FQNAME.child(type.getRangeTypeName())).getInternalName(); - JvmClassName classObjectInternalName = JvmClassName.byInternalName(rangeInternalName + JvmAbi.CLASS_OBJECT_SUFFIX); - classNamesForClassDescriptor.put(klass.getClassObjectDescriptor(), classObjectInternalName); - } } @@ -238,8 +221,8 @@ public class ClosureAnnotator { } private class MyJetVisitorVoid extends JetVisitorVoid { - private LinkedList classStack = new LinkedList(); - private LinkedList nameStack = new LinkedList(); + private final LinkedList classStack = new LinkedList(); + private final LinkedList nameStack = new LinkedList(); private void recordEnclosing(ClassDescriptor classDescriptor) { if (classStack.size() > 0) { @@ -397,7 +380,9 @@ public class ClosureAnnotator { else if (containingDeclaration instanceof NamespaceDescriptor) { String peek = nameStack.peek(); if (peek.isEmpty()) { peek = "namespace"; } - else { peek = peek + "/namespace"; } + else { + peek += "/namespace"; + } nameStack.push(peek + '$' + function.getName()); super.visitNamedFunction(function); nameStack.pop(); @@ -426,9 +411,4 @@ public class ClosureAnnotator { public JvmClassName classNameForClassDescriptor(@NotNull ClassDescriptor classDescriptor) { return classNamesForClassDescriptor.get(classDescriptor); } - - @Nullable - public JvmClassName classNameForClassDescriptorIfDefined(@NotNull ClassDescriptor classDescriptor) { - return classNamesForClassDescriptor.get(classDescriptor); - } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index 2e801326afe..2eb6a38442b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -341,6 +341,9 @@ public class JetTypeMapper { if (containingKlass.getKind() == ClassKind.ENUM_CLASS) { return getFQName(containingKlass); } + else { + return getFQName(containingKlass) + JvmAbi.CLASS_OBJECT_SUFFIX; + } } } else if (klass.getKind() == ClassKind.ENUM_ENTRY) { diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java index 0c155960369..d130927080e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmAbi.java @@ -30,4 +30,7 @@ public class JvmAbi { public static final JvmClassName JETBRAINS_NOT_NULL_ANNOTATION = JvmClassName.byFqNameWithoutInnerClasses("org.jetbrains.annotations.NotNull"); + + private JvmAbi() { + } } From 4bc1b2636aa1037948c1d2c3037ffe3b960f3ace Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 10 Aug 2012 14:37:14 +0400 Subject: [PATCH 60/72] StackValue.pop() --- .../org/jetbrains/jet/codegen/StackValue.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 726fbc6518a..4dd772af0c2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -212,6 +212,13 @@ public abstract class StackValue { } } + protected static void pop(Type type, InstructionAdapter v) { + if (type.getSize() == 1) + v.pop(); + else + v.pop2(); + } + protected void coerce(Type toType, InstructionAdapter v) { coerce(this.type, toType, v); } @@ -220,10 +227,7 @@ public abstract class StackValue { if (toType.equals(fromType)) return; if (toType.getSort() == Type.VOID && fromType.getSort() != Type.VOID) { - if (fromType.getSize() == 1) - v.pop(); - else - v.pop2(); + pop(fromType, v); } else if (toType.getSort() != Type.VOID && fromType.getSort() == Type.VOID) { if (toType.getSort() == Type.OBJECT) { @@ -357,17 +361,7 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { - if (type == Type.VOID_TYPE && this.type != Type.VOID_TYPE) { - if (this.type.getSize() == 2) { - v.pop2(); - } - else { - v.pop(); - } - } - else { - coerce(type, v); - } + coerce(type, v); } @Override @@ -627,10 +621,7 @@ public abstract class StackValue { method.invoke(v); Type returnType = asmMethod.getReturnType(); if (returnType != Type.VOID_TYPE) { - if (returnType.getSize() == 2) - v.pop2(); - else - v.pop(); + pop(returnType, v); } } else From 9350369fab096703f06b22cd256265b061cc4ed9 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 10 Aug 2012 14:38:21 +0400 Subject: [PATCH 61/72] Fixed codegen for single-branch if #KT-2597 Fixed #KT-2598 Fixed --- .../jet/codegen/ExpressionCodegen.java | 20 +++++++++++++++---- .../org/jetbrains/jet/codegen/StackValue.java | 4 ++++ .../testData/codegen/regressions/kt2597.kt | 10 ++++++++++ .../testData/codegen/regressions/kt2598.kt | 9 +++++++++ .../jet/codegen/ControlStructuresTest.java | 10 ++++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt2597.kt create mode 100644 compiler/testData/codegen/regressions/kt2598.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 4e822fca3aa..55a746a5a64 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -687,14 +687,26 @@ public class ExpressionCodegen extends JetVisitor { } private StackValue generateSingleBranchIf(StackValue condition, JetExpression expression, boolean inverse) { + Type expressionType = expressionType(expression); + Type targetType = expressionType; + if (!expressionType.equals(TUPLE0_TYPE)) { + targetType = TYPE_OBJECT; + } + + Label elseLabel = new Label(); + condition.condJump(elseLabel, inverse, v); + + gen(expression, expressionType); + StackValue.coerce(expressionType, targetType, v); + Label end = new Label(); + v.goTo(end); - condition.condJump(end, inverse, v); - - gen(expression, Type.VOID_TYPE); + v.mark(elseLabel); + StackValue.putTuple0Instance(v); v.mark(end); - return StackValue.none(); + return StackValue.onStack(targetType); } @Override diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 4dd772af0c2..88937bf29af 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -242,6 +242,10 @@ public abstract class StackValue { else v.iconst(0); } + else if (toType.equals(JetTypeMapper.TUPLE0_TYPE) && !fromType.equals(JetTypeMapper.TUPLE0_TYPE)) { + pop(fromType, v); + putTuple0Instance(v); + } else if (toType.getSort() == Type.OBJECT && fromType.equals(JetTypeMapper.TYPE_OBJECT) || toType.getSort() == Type.ARRAY) { v.checkcast(toType); } diff --git a/compiler/testData/codegen/regressions/kt2597.kt b/compiler/testData/codegen/regressions/kt2597.kt new file mode 100644 index 00000000000..af5af144a86 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2597.kt @@ -0,0 +1,10 @@ +fun box(): String { + var i = 0 + { + if (1 == 1) { + i++ + } else { + } + }() + return "OK" +} diff --git a/compiler/testData/codegen/regressions/kt2598.kt b/compiler/testData/codegen/regressions/kt2598.kt new file mode 100644 index 00000000000..133f6f42cae --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2598.kt @@ -0,0 +1,9 @@ +fun foo(condition: Boolean): String { + val u = if (condition) { + "OK" + } else { + } + return u.toString() +} + +fun box() = foo(true) diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 51f30277962..7ee7ec91040 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -391,4 +391,14 @@ public class ControlStructuresTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxFile("controlStructures/tryCatchFinallyChain.kt"); } + + public void testKt2597() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2597.kt"); + } + + public void testKt2598() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2598.kt"); + } } From dcf2982288abcd68db4dbb785f1f24dade513425 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 10 Aug 2012 17:24:13 +0400 Subject: [PATCH 62/72] copy-paste bug fix in test --- .../jet/jvm/compiler/CompileKotlinAgainstKotlinTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTest.java index df22d408f9e..ecd3103cfe9 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTest.java @@ -104,7 +104,7 @@ public class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir { String text = FileUtil.loadFile(ktBFile); - LightVirtualFile virtualFile = new LightVirtualFile(ktAFile.getName(), JetLanguage.INSTANCE, text); + LightVirtualFile virtualFile = new LightVirtualFile(ktBFile.getName(), JetLanguage.INSTANCE, text); virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET); JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false); From f7321a40e0f364f69a2f79b777c54636e9a4a1bb Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 10 Aug 2012 20:05:43 +0400 Subject: [PATCH 63/72] Format method with multiline parameter list like this: int foo( Bar buzz ) { // ... } --- .idea/codeStyleSettings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml index ceb1e02bb82..0279b53f8eb 100644 --- a/.idea/codeStyleSettings.xml +++ b/.idea/codeStyleSettings.xml @@ -176,6 +176,8 @@