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,116 +16,36 @@ import java.lang.System;
@kotlin.Metadata()
public final class Foo {
private final boolean z = false;
private final byte b = 0;
private final char c = '\u0000';
private final char c2 = '\u0000';
private final short sh = 0;
private final int i = 0;
private final long l = 0L;
private final float f = 0.0F;
private final double d = 0.0;
@org.jetbrains.annotations.NotNull()
private final java.lang.String s = null;
@org.jetbrains.annotations.NotNull()
private final int[] iarr = null;
@org.jetbrains.annotations.NotNull()
private final long[] larr = null;
@org.jetbrains.annotations.NotNull()
private final double[] darr = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.String[] sarr = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?> cl = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?>[] clarr = null;
private final double d = 0.0;
@org.jetbrains.annotations.NotNull()
private final double[] darr = null;
@org.jetbrains.annotations.NotNull()
private final Em em = null;
@org.jetbrains.annotations.NotNull()
private final Em[] emarr = null;
public final void foo(int a) {
}
public final boolean getZ() {
return false;
}
public final byte getB() {
return 0;
}
public final char getC() {
return '\u0000';
}
public final char getC2() {
return '\u0000';
}
public final short getSh() {
return 0;
}
public final int getI() {
return 0;
}
public final long getL() {
return 0L;
}
public final float getF() {
return 0.0F;
}
public final double getD() {
return 0.0;
}
private final float f = 0.0F;
private final int i = 0;
@org.jetbrains.annotations.NotNull()
public final java.lang.String getS() {
return null;
}
private final int[] iarr = null;
private final long l = 0L;
@org.jetbrains.annotations.NotNull()
public final int[] getIarr() {
return null;
}
private final long[] larr = null;
@org.jetbrains.annotations.NotNull()
public final long[] getLarr() {
return null;
}
private final java.lang.String s = null;
@org.jetbrains.annotations.NotNull()
public final double[] getDarr() {
return null;
}
private final java.lang.String[] sarr = null;
private final short sh = 0;
private final boolean z = false;
@org.jetbrains.annotations.NotNull()
public final java.lang.String[] getSarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?> getCl() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?>[] getClarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em getEm() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em[] getEmarr() {
return null;
public Foo() {
super();
}
public Foo(boolean z, byte b, char c, char c2, short sh, int i, long l, float f, double d, @org.jetbrains.annotations.NotNull()
@@ -141,7 +61,87 @@ public final class Foo {
super();
}
public Foo() {
super();
public final void foo(int a) {
}
public final byte getB() {
return 0;
}
public final char getC() {
return '\u0000';
}
public final char getC2() {
return '\u0000';
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?> getCl() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?>[] getClarr() {
return null;
}
public final double getD() {
return 0.0;
}
@org.jetbrains.annotations.NotNull()
public final double[] getDarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em getEm() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em[] getEmarr() {
return null;
}
public final float getF() {
return 0.0F;
}
public final int getI() {
return 0;
}
@org.jetbrains.annotations.NotNull()
public final int[] getIarr() {
return null;
}
public final long getL() {
return 0L;
}
@org.jetbrains.annotations.NotNull()
public final long[] getLarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getS() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String[] getSarr() {
return null;
}
public final short getSh() {
return 0;
}
public final boolean getZ() {
return false;
}
}