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
+23 -23
View File
@@ -2,28 +2,11 @@ import java.lang.System;
@kotlin.Metadata()
public final class User {
private final int age = 0;
@org.jetbrains.annotations.NotNull()
private final java.lang.String firstName = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.String secondName = null;
private final int age = 0;
public final void procedure() {
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getFirstName() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getSecondName() {
return null;
}
public final int getAge() {
return 0;
}
public User(@org.jetbrains.annotations.NotNull()
java.lang.String firstName, @org.jetbrains.annotations.NotNull()
@@ -52,9 +35,23 @@ public final class User {
return null;
}
@org.jetbrains.annotations.NotNull()
@java.lang.Override()
public java.lang.String toString() {
public boolean equals(@org.jetbrains.annotations.Nullable()
java.lang.Object p0) {
return false;
}
public final int getAge() {
return 0;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getFirstName() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getSecondName() {
return null;
}
@@ -63,9 +60,12 @@ public final class User {
return 0;
}
public final void procedure() {
}
@org.jetbrains.annotations.NotNull()
@java.lang.Override()
public boolean equals(@org.jetbrains.annotations.Nullable()
java.lang.Object p0) {
return false;
public java.lang.String toString() {
return null;
}
}