Sort kotlinp output in tests to reduce diff between K1 and K2.
This commit is contained in:
@@ -45,5 +45,6 @@ class Kotlinp(private val settings: KotlinpSettings) {
|
||||
}
|
||||
|
||||
data class KotlinpSettings(
|
||||
val isVerbose: Boolean
|
||||
val isVerbose: Boolean,
|
||||
val sortDeclarations: Boolean
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@ object Main {
|
||||
private fun run(args: Array<String>) {
|
||||
val paths = arrayListOf<String>()
|
||||
var verbose = false
|
||||
var sort = false
|
||||
|
||||
var i = 0
|
||||
while (true) {
|
||||
@@ -21,6 +22,8 @@ object Main {
|
||||
|
||||
if (arg == "-help" || arg == "-h") {
|
||||
printUsageAndExit()
|
||||
} else if (arg == "-sort") {
|
||||
sort = true
|
||||
} else if (arg == "-verbose") {
|
||||
verbose = true
|
||||
} else if (arg == "-version") {
|
||||
@@ -32,7 +35,7 @@ object Main {
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinp = Kotlinp(KotlinpSettings(verbose))
|
||||
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = verbose, sortDeclarations = sort))
|
||||
|
||||
for (path in paths) {
|
||||
val file = File(path)
|
||||
@@ -72,6 +75,7 @@ object Main {
|
||||
|
||||
Usage: kotlinp <options> <classes>
|
||||
where possible options include:
|
||||
-sort Sort declarations in the output by signature and/or name
|
||||
-verbose Display information in more detail, minimizing ambiguities but worsening readability
|
||||
-version Display Kotlin version
|
||||
-help (-h) Print a synopsis of options
|
||||
|
||||
@@ -371,6 +371,10 @@ private fun StringBuilder.appendDeclarationContainerExtensions(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T, R : Comparable<R>> Iterable<T>.sortIfNeededBy(settings: KotlinpSettings, selector: (T) -> R?): Iterable<T> {
|
||||
return if (settings.sortDeclarations) sortedBy(selector) else this
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
private fun printContract(kmContract: KmContract): String = buildString {
|
||||
appendLine("contract {")
|
||||
@@ -546,7 +550,7 @@ class ClassPrinter(private val settings: KotlinpSettings) : AbstractPrinter<Kotl
|
||||
val jvmFlags: Flags = kclass.jvmFlags
|
||||
anonymousObjectOriginName = kclass.anonymousObjectOriginName
|
||||
|
||||
kclass.localDelegatedProperties.forEach { p ->
|
||||
kclass.localDelegatedProperties.sortIfNeededBy(settings) { it.getterSignature?.toString() ?: it.name }.forEach { p ->
|
||||
visitProperty(
|
||||
p, settings, StringBuilder().also { localDelegatedProperties.add(it) }
|
||||
)
|
||||
@@ -572,14 +576,16 @@ class ClassPrinter(private val settings: KotlinpSettings) : AbstractPrinter<Kotl
|
||||
kmClass.typeParameters.forEach { typeParams.add(printTypeParameter(it, settings)) }
|
||||
supertypes.addAll(kmClass.supertypes.map { printType(it) })
|
||||
|
||||
kmClass.constructors.forEach { visitConstructor(it, sb) }
|
||||
kmClass.functions.forEach { visitFunction(it, settings, sb) }
|
||||
kmClass.properties.forEach { visitProperty(it, settings, sb) }
|
||||
kmClass.typeAliases.forEach { visitTypeAlias(it, settings, sb) }
|
||||
kmClass.constructors.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitConstructor(it, sb) }
|
||||
kmClass.functions.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitFunction(it, settings, sb) }
|
||||
kmClass.properties.sortIfNeededBy(settings) {
|
||||
it.getterSignature?.toString() ?: it.name
|
||||
}.forEach { visitProperty(it, settings, sb) }
|
||||
kmClass.typeAliases.sortIfNeededBy(settings) { it.name }.forEach { visitTypeAlias(it, settings, sb) }
|
||||
kmClass.companionObject?.let { visitCompanionObject(it) }
|
||||
kmClass.nestedClasses.forEach { visitNestedClass(it) }
|
||||
kmClass.enumEntries.forEach { visitEnumEntry(it) }
|
||||
kmClass.sealedSubclasses.forEach { visitSealedSubclass(it) }
|
||||
kmClass.sealedSubclasses.sortIfNeededBy(settings) { it }.forEach { visitSealedSubclass(it) }
|
||||
kmClass.inlineClassUnderlyingPropertyName?.let { visitInlineClassUnderlyingPropertyName(it) }
|
||||
kmClass.inlineClassUnderlyingType?.let { visitInlineClassUnderlyingType(printType(it)) }
|
||||
kmClass.contextReceiverTypes.forEach { contextReceiverTypes.add(printType(it)) }
|
||||
@@ -600,16 +606,18 @@ abstract class PackagePrinter(private val settings: KotlinpSettings) {
|
||||
val localDelegatedProperties = mutableListOf<StringBuilder>()
|
||||
val moduleName: String? = kmPackage.moduleName
|
||||
|
||||
kmPackage.localDelegatedProperties.forEach { p ->
|
||||
kmPackage.localDelegatedProperties.sortIfNeededBy(settings) { it.getterSignature?.toString() ?: it.name }.forEach { p ->
|
||||
visitProperty(p, settings, StringBuilder().also { localDelegatedProperties.add(it) })
|
||||
}
|
||||
sb.appendDeclarationContainerExtensions(settings, localDelegatedProperties, moduleName)
|
||||
}
|
||||
|
||||
fun print(kmPackage: KmPackage) {
|
||||
kmPackage.functions.forEach { visitFunction(it, settings, sb) }
|
||||
kmPackage.properties.forEach { visitProperty(it, settings, sb) }
|
||||
kmPackage.typeAliases.forEach { visitTypeAlias(it, settings, sb) }
|
||||
kmPackage.functions.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitFunction(it, settings, sb) }
|
||||
kmPackage.properties.sortIfNeededBy(settings) {
|
||||
it.getterSignature?.toString() ?: it.name
|
||||
}.forEach { visitProperty(it, settings, sb) }
|
||||
kmPackage.typeAliases.sortIfNeededBy(settings) { it.name }.forEach { visitTypeAlias(it, settings, sb) }
|
||||
visitExtensions(kmPackage)
|
||||
sb.appendLine("}")
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ fun compileAndPrintAllFiles(
|
||||
val afterVisitors = StringBuilder()
|
||||
val afterNodes = StringBuilder()
|
||||
|
||||
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true))
|
||||
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true, sortDeclarations = true))
|
||||
|
||||
@OptIn(UnstableMetadataApi::class)
|
||||
compile(file, disposable, tmpdir, useK2) { outputFile ->
|
||||
|
||||
+6
-6
@@ -40,6 +40,12 @@ package {
|
||||
returns() implies (p#1 !is kotlin/collections/List<*> && p#2 && p#3 == null)
|
||||
}
|
||||
|
||||
// signature: receiverIsNotNull(Ljava/lang/Object;)Z
|
||||
public final fun kotlin/Any?.receiverIsNotNull(): kotlin/Boolean
|
||||
contract {
|
||||
returns(true) implies (p#0 != null)
|
||||
}
|
||||
|
||||
// signature: returnsNotNull(Z)V
|
||||
public final fun returnsNotNull(condition: kotlin/Boolean): kotlin/Unit
|
||||
contract {
|
||||
@@ -58,12 +64,6 @@ package {
|
||||
returns(true) implies (p#1)
|
||||
}
|
||||
|
||||
// signature: receiverIsNotNull(Ljava/lang/Object;)Z
|
||||
public final fun kotlin/Any?.receiverIsNotNull(): kotlin/Boolean
|
||||
contract {
|
||||
returns(true) implies (p#0 != null)
|
||||
}
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
|
||||
+5
-5
@@ -19,6 +19,11 @@ public final class C : kotlin/Any {
|
||||
public final val constructorParam: kotlin/String
|
||||
public final get
|
||||
|
||||
// getter: getDelegated(Ljava/lang/Number;)Ljava/util/List;
|
||||
// synthetic method for delegate: getDelegated$delegate(LC;Ljava/lang/Number;)Ljava/lang/Object;
|
||||
public final /* delegated */ val <T#0 /* T */ : kotlin/Number> T#0.delegated: kotlin/collections/List<kotlin/Nothing>
|
||||
public final /* non-default */ get
|
||||
|
||||
// getter: getGetterOnlyVal()D
|
||||
public final val getterOnlyVal: kotlin/Double
|
||||
public final /* non-default */ get
|
||||
@@ -35,11 +40,6 @@ public final class C : kotlin/Any {
|
||||
public final /* delegated */ val withOptimizedDelegate: kotlin/Double
|
||||
public final /* non-default */ get
|
||||
|
||||
// getter: getDelegated(Ljava/lang/Number;)Ljava/util/List;
|
||||
// synthetic method for delegate: getDelegated$delegate(LC;Ljava/lang/Number;)Ljava/lang/Object;
|
||||
public final /* delegated */ val <T#0 /* T */ : kotlin/Number> T#0.delegated: kotlin/collections/List<kotlin/Nothing>
|
||||
public final /* non-default */ get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
|
||||
+5
-5
@@ -2,19 +2,19 @@
|
||||
// ------------------------------------------
|
||||
public final class SimpleClass<in T#0 /* A */> : kotlin/Any {
|
||||
|
||||
// signature: <init>(I)V
|
||||
public constructor(p: kotlin/Int /* = ... */)
|
||||
|
||||
// signature: <init>([Ljava/lang/String;)V
|
||||
public /* secondary */ constructor(s: kotlin/Array<kotlin/String?>?)
|
||||
|
||||
// signature: <init>(I)V
|
||||
public constructor(p: kotlin/Int /* = ... */)
|
||||
// signature: f$test_module(Ljava/lang/Object;[Ljava/util/Map;)Ljava/util/Set;
|
||||
internal final fun <T#1 /* U */ : T#3, T#2 /* V */ : T#3, T#3 /* A */> T#3.f(vararg z: kotlin/collections/Map<T#2, T#1?> /* kotlin/Array<out kotlin/collections/Map<T#2, T#1?>> */): kotlin/collections/Set<*>
|
||||
|
||||
// requires language version 1.3.0 (level=ERROR)
|
||||
// signature: g(Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
protected final inline suspend fun <reified T#1 /* T */> g(crossinline a: kotlin/Function0<T#0>, noinline b: suspend kotlin/Function1<kotlin/coroutines/Continuation<T#1>, kotlin/Any?>): kotlin/Unit
|
||||
|
||||
// signature: f$test_module(Ljava/lang/Object;[Ljava/util/Map;)Ljava/util/Set;
|
||||
internal final fun <T#1 /* U */ : T#3, T#2 /* V */ : T#3, T#3 /* A */> T#3.f(vararg z: kotlin/collections/Map<T#2, T#1?> /* kotlin/Array<out kotlin/collections/Map<T#2, T#1?>> */): kotlin/collections/Set<*>
|
||||
|
||||
// field: p:I
|
||||
// getter: getP()I
|
||||
public final val p: kotlin/Int
|
||||
|
||||
Reference in New Issue
Block a user