Sort class members to ensure deterministic builds

Class methods and fields are currently sorted at serialization (see
DescriptorSerializer.sort) and at deserialization (see
DeserializedMemberScope.OptimizedImplementation#addMembers). Therefore,
the contents of the generated stub files are sorted in incremental
builds but not in clean builds.

The consequence is that the contents of the generated stub files may not
be consistent across a clean build and an incremental build, making the
build non-deterministic and dependent tasks run unnecessarily (see
KT-40882).

To work around that, this commit sorts class methods and fields when
outputting stub files.

Bug: KT-40882 (there are actually 2 issues in here; this commit fixes
     the first one)
Test: New DeterministicBuildIT + Updated existing test expectation files
This commit is contained in:
Hung Nguyen
2020-11-12 12:51:47 +00:00
committed by nataliya.valtman
parent 07a797cc3a
commit 4bf63a9539
70 changed files with 1380 additions and 1277 deletions
@@ -2,14 +2,13 @@ import java.lang.System;
@kotlin.Metadata()
public final class Boo {
@org.jetbrains.annotations.NotNull()
private static final java.lang.String z = null;
@org.jetbrains.annotations.NotNull()
public static final Boo INSTANCE = null;
@org.jetbrains.annotations.NotNull()
public final java.lang.String getZ() {
return null;
private static final java.lang.String z = null;
private Boo() {
super();
}
@org.jetbrains.annotations.NotNull()
@@ -17,8 +16,9 @@ public final class Boo {
return null;
}
private Boo() {
super();
@org.jetbrains.annotations.NotNull()
public final java.lang.String getZ() {
return null;
}
}
@@ -30,15 +30,17 @@ import java.lang.System;
@kotlin.Metadata()
public final class Foo {
@org.jetbrains.annotations.NotNull()
public static final java.lang.String aString = "foo";
public static final Foo INSTANCE = null;
public static final int aInt = 3;
@org.jetbrains.annotations.NotNull()
private static final java.lang.String bString = "bar";
public static final java.lang.String aString = "foo";
private static final int bInt = 5;
@org.jetbrains.annotations.NotNull()
private static java.lang.String cString = "baz";
private static final java.lang.String bString = "bar";
private static int cInt = 7;
@org.jetbrains.annotations.NotNull()
private static java.lang.String cString = "baz";
@org.jetbrains.annotations.NotNull()
private static final java.lang.String d = null;
private static final int e = 0;
private static final int f = 8;
@@ -50,12 +52,9 @@ public final class Foo {
private static final java.lang.String j = null;
@org.jetbrains.annotations.NotNull()
private static final java.lang.String k = null;
@org.jetbrains.annotations.NotNull()
public static final Foo INSTANCE = null;
@org.jetbrains.annotations.NotNull()
public final java.lang.String getBString() {
return null;
private Foo() {
super();
}
public final int getBInt() {
@@ -63,19 +62,17 @@ public final class Foo {
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getCString() {
public final java.lang.String getBString() {
return null;
}
public final void setCString(@org.jetbrains.annotations.NotNull()
java.lang.String p0) {
}
public final int getCInt() {
return 0;
}
public final void setCInt(int p0) {
@org.jetbrains.annotations.NotNull()
public final java.lang.String getCString() {
return null;
}
@org.jetbrains.annotations.NotNull()
@@ -114,8 +111,11 @@ public final class Foo {
return null;
}
private Foo() {
super();
public final void setCInt(int p0) {
}
public final void setCString(@org.jetbrains.annotations.NotNull()
java.lang.String p0) {
}
}
@@ -126,6 +126,18 @@ import java.lang.System;
@kotlin.Metadata()
public final class HavingState {
@org.jetbrains.annotations.NotNull()
private final kotlin.reflect.KClass<? extends java.lang.Object> anonymous = null;
@org.jetbrains.annotations.NotNull()
private final kotlin.reflect.KClass<State> clazz = null;
@org.jetbrains.annotations.NotNull()
private final float[] floatArray = {-1.0F};
@org.jetbrains.annotations.NotNull()
private final java.lang.Integer[] intArray = {1};
@org.jetbrains.annotations.NotNull()
private final java.util.List<java.lang.Integer> intList = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<State> javaClass = null;
@org.jetbrains.annotations.NotNull()
private final State state = State.START;
@org.jetbrains.annotations.NotNull()
@@ -134,23 +146,45 @@ public final class HavingState {
private final java.lang.String[] stringArray = {"foo"};
@org.jetbrains.annotations.NotNull()
private final java.util.List<java.lang.String> stringList = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Integer[] intArray = {1};
@org.jetbrains.annotations.NotNull()
private final float[] floatArray = {-1.0F};
@org.jetbrains.annotations.NotNull()
private final java.util.List<java.lang.Integer> intList = null;
private final int uint = 1;
@org.jetbrains.annotations.NotNull()
private final kotlin.UInt[] uintArray = {1};
@org.jetbrains.annotations.NotNull()
private final java.util.List<kotlin.UInt> uintList = null;
public HavingState() {
super();
}
@org.jetbrains.annotations.NotNull()
private final kotlin.reflect.KClass<State> clazz = null;
public final kotlin.reflect.KClass<? extends java.lang.Object> getAnonymous() {
return null;
}
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<State> javaClass = null;
public final kotlin.reflect.KClass<State> getClazz() {
return null;
}
@org.jetbrains.annotations.NotNull()
private final kotlin.reflect.KClass<? extends java.lang.Object> anonymous = null;
public final float[] getFloatArray() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Integer[] getIntArray() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.util.List<java.lang.Integer> getIntList() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<State> getJavaClass() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final State getState() {
@@ -172,21 +206,6 @@ public final class HavingState {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Integer[] getIntArray() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final float[] getFloatArray() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.util.List<java.lang.Integer> getIntList() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final kotlin.UInt[] getUintArray() {
return null;
@@ -196,25 +215,6 @@ public final class HavingState {
public final java.util.List<kotlin.UInt> getUintList() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final kotlin.reflect.KClass<State> getClazz() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<State> getJavaClass() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final kotlin.reflect.KClass<? extends java.lang.Object> getAnonymous() {
return null;
}
public HavingState() {
super();
}
}
////////////////////