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
@@ -7,6 +7,15 @@ public final class State {
@org.jetbrains.annotations.NotNull()
private final java.lang.String someString = null;
public State(int someInt, long someLong) {
super();
}
public State(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
super();
}
public final int getSomeInt() {
return 0;
}
@@ -19,15 +28,6 @@ public final class State {
public final java.lang.String getSomeString() {
return null;
}
public State(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
super();
}
public State(int someInt, long someLong) {
super();
}
}
////////////////////
@@ -42,28 +42,7 @@ public final class State2 {
@org.jetbrains.annotations.NotNull()
public final java.lang.String someString = null;
public final int test(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
return 0;
}
public final int test(int someInt, long someLong) {
return 0;
}
public final int test(int someInt) {
return 0;
}
public final void someMethod(@org.jetbrains.annotations.NotNull()
java.lang.String str) {
}
public final void methodWithoutArgs() {
}
public State2(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
public State2(int someInt) {
super();
}
@@ -71,7 +50,28 @@ public final class State2 {
super();
}
public State2(int someInt) {
public State2(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
super();
}
public final void methodWithoutArgs() {
}
public final void someMethod(@org.jetbrains.annotations.NotNull()
java.lang.String str) {
}
public final int test(int someInt) {
return 0;
}
public final int test(int someInt, long someLong) {
return 0;
}
public final int test(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
return 0;
}
}