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
+13 -13
View File
@@ -14,15 +14,15 @@ public abstract interface FooComponent {
@kotlin.Metadata()
public static final class Companion {
private Companion() {
super();
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String create(@org.jetbrains.annotations.NotNull()
java.lang.String context) {
return null;
}
private Companion() {
super();
}
}
}
@@ -33,13 +33,13 @@ import java.lang.System;
@kotlin.Metadata()
public final class JvmStaticTest {
public final byte three = (byte)3;
public final char d = 'D';
private static final int one = 1;
public static final int two = 2;
public static final char c = 'C';
@org.jetbrains.annotations.NotNull()
public static final JvmStaticTest.Companion Companion = null;
public static final char c = 'C';
public final char d = 'D';
private static final int one = 1;
public final byte three = (byte)3;
public static final int two = 2;
public JvmStaticTest() {
super();
@@ -52,16 +52,16 @@ public final class JvmStaticTest {
@kotlin.Metadata()
public static final class Companion {
@java.lang.Deprecated()
public static void getOne$annotations() {
private Companion() {
super();
}
public final int getOne() {
return 0;
}
private Companion() {
super();
@java.lang.Deprecated()
public static void getOne$annotations() {
}
}
}