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
@@ -16,10 +16,8 @@ public final class Bar {
@FieldAnno()
private final java.lang.String a = "";
@Anno()
@PropertyAnno()
@java.lang.Deprecated()
public static void getA$annotations() {
public Bar() {
super();
}
@org.jetbrains.annotations.NotNull()
@@ -27,8 +25,10 @@ public final class Bar {
return null;
}
public Bar() {
super();
@Anno()
@PropertyAnno()
@java.lang.Deprecated()
public static void getA$annotations() {
}
}
@@ -43,14 +43,14 @@ public final class Baz {
@FieldAnno()
public final java.lang.String a = "";
public Baz() {
super();
}
@Anno()
@java.lang.Deprecated()
public static void getA$annotations() {
}
public Baz() {
super();
}
}
////////////////////
@@ -76,9 +76,11 @@ public final class Foo {
@FieldAnno()
private final java.lang.String a = null;
@PropertyAnno()
@java.lang.Deprecated()
public static void getA$annotations() {
public Foo(@org.jetbrains.annotations.NotNull()
@Anno()
@ParameterAnno()
java.lang.String a) {
super();
}
@org.jetbrains.annotations.NotNull()
@@ -86,11 +88,9 @@ public final class Foo {
return null;
}
public Foo(@org.jetbrains.annotations.NotNull()
@Anno()
@ParameterAnno()
java.lang.String a) {
super();
@PropertyAnno()
@java.lang.Deprecated()
public static void getA$annotations() {
}
}