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(
|
data class KotlinpSettings(
|
||||||
val isVerbose: Boolean
|
val isVerbose: Boolean,
|
||||||
|
val sortDeclarations: Boolean
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ object Main {
|
|||||||
private fun run(args: Array<String>) {
|
private fun run(args: Array<String>) {
|
||||||
val paths = arrayListOf<String>()
|
val paths = arrayListOf<String>()
|
||||||
var verbose = false
|
var verbose = false
|
||||||
|
var sort = false
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -21,6 +22,8 @@ object Main {
|
|||||||
|
|
||||||
if (arg == "-help" || arg == "-h") {
|
if (arg == "-help" || arg == "-h") {
|
||||||
printUsageAndExit()
|
printUsageAndExit()
|
||||||
|
} else if (arg == "-sort") {
|
||||||
|
sort = true
|
||||||
} else if (arg == "-verbose") {
|
} else if (arg == "-verbose") {
|
||||||
verbose = true
|
verbose = true
|
||||||
} else if (arg == "-version") {
|
} 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) {
|
for (path in paths) {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
@@ -72,6 +75,7 @@ object Main {
|
|||||||
|
|
||||||
Usage: kotlinp <options> <classes>
|
Usage: kotlinp <options> <classes>
|
||||||
where possible options include:
|
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
|
-verbose Display information in more detail, minimizing ambiguities but worsening readability
|
||||||
-version Display Kotlin version
|
-version Display Kotlin version
|
||||||
-help (-h) Print a synopsis of options
|
-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
|
@ExperimentalContracts
|
||||||
private fun printContract(kmContract: KmContract): String = buildString {
|
private fun printContract(kmContract: KmContract): String = buildString {
|
||||||
appendLine("contract {")
|
appendLine("contract {")
|
||||||
@@ -546,7 +550,7 @@ class ClassPrinter(private val settings: KotlinpSettings) : AbstractPrinter<Kotl
|
|||||||
val jvmFlags: Flags = kclass.jvmFlags
|
val jvmFlags: Flags = kclass.jvmFlags
|
||||||
anonymousObjectOriginName = kclass.anonymousObjectOriginName
|
anonymousObjectOriginName = kclass.anonymousObjectOriginName
|
||||||
|
|
||||||
kclass.localDelegatedProperties.forEach { p ->
|
kclass.localDelegatedProperties.sortIfNeededBy(settings) { it.getterSignature?.toString() ?: it.name }.forEach { p ->
|
||||||
visitProperty(
|
visitProperty(
|
||||||
p, settings, StringBuilder().also { localDelegatedProperties.add(it) }
|
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)) }
|
kmClass.typeParameters.forEach { typeParams.add(printTypeParameter(it, settings)) }
|
||||||
supertypes.addAll(kmClass.supertypes.map { printType(it) })
|
supertypes.addAll(kmClass.supertypes.map { printType(it) })
|
||||||
|
|
||||||
kmClass.constructors.forEach { visitConstructor(it, sb) }
|
kmClass.constructors.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitConstructor(it, sb) }
|
||||||
kmClass.functions.forEach { visitFunction(it, settings, sb) }
|
kmClass.functions.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitFunction(it, settings, sb) }
|
||||||
kmClass.properties.forEach { visitProperty(it, settings, sb) }
|
kmClass.properties.sortIfNeededBy(settings) {
|
||||||
kmClass.typeAliases.forEach { visitTypeAlias(it, settings, sb) }
|
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.companionObject?.let { visitCompanionObject(it) }
|
||||||
kmClass.nestedClasses.forEach { visitNestedClass(it) }
|
kmClass.nestedClasses.forEach { visitNestedClass(it) }
|
||||||
kmClass.enumEntries.forEach { visitEnumEntry(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.inlineClassUnderlyingPropertyName?.let { visitInlineClassUnderlyingPropertyName(it) }
|
||||||
kmClass.inlineClassUnderlyingType?.let { visitInlineClassUnderlyingType(printType(it)) }
|
kmClass.inlineClassUnderlyingType?.let { visitInlineClassUnderlyingType(printType(it)) }
|
||||||
kmClass.contextReceiverTypes.forEach { contextReceiverTypes.add(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 localDelegatedProperties = mutableListOf<StringBuilder>()
|
||||||
val moduleName: String? = kmPackage.moduleName
|
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) })
|
visitProperty(p, settings, StringBuilder().also { localDelegatedProperties.add(it) })
|
||||||
}
|
}
|
||||||
sb.appendDeclarationContainerExtensions(settings, localDelegatedProperties, moduleName)
|
sb.appendDeclarationContainerExtensions(settings, localDelegatedProperties, moduleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun print(kmPackage: KmPackage) {
|
fun print(kmPackage: KmPackage) {
|
||||||
kmPackage.functions.forEach { visitFunction(it, settings, sb) }
|
kmPackage.functions.sortIfNeededBy(settings) { it.signature.toString() }.forEach { visitFunction(it, settings, sb) }
|
||||||
kmPackage.properties.forEach { visitProperty(it, settings, sb) }
|
kmPackage.properties.sortIfNeededBy(settings) {
|
||||||
kmPackage.typeAliases.forEach { visitTypeAlias(it, settings, sb) }
|
it.getterSignature?.toString() ?: it.name
|
||||||
|
}.forEach { visitProperty(it, settings, sb) }
|
||||||
|
kmPackage.typeAliases.sortIfNeededBy(settings) { it.name }.forEach { visitTypeAlias(it, settings, sb) }
|
||||||
visitExtensions(kmPackage)
|
visitExtensions(kmPackage)
|
||||||
sb.appendLine("}")
|
sb.appendLine("}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ fun compileAndPrintAllFiles(
|
|||||||
val afterVisitors = StringBuilder()
|
val afterVisitors = StringBuilder()
|
||||||
val afterNodes = StringBuilder()
|
val afterNodes = StringBuilder()
|
||||||
|
|
||||||
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true))
|
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true, sortDeclarations = true))
|
||||||
|
|
||||||
@OptIn(UnstableMetadataApi::class)
|
@OptIn(UnstableMetadataApi::class)
|
||||||
compile(file, disposable, tmpdir, useK2) { outputFile ->
|
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)
|
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
|
// signature: returnsNotNull(Z)V
|
||||||
public final fun returnsNotNull(condition: kotlin/Boolean): kotlin/Unit
|
public final fun returnsNotNull(condition: kotlin/Boolean): kotlin/Unit
|
||||||
contract {
|
contract {
|
||||||
@@ -58,12 +64,6 @@ package {
|
|||||||
returns(true) implies (p#1)
|
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
|
// module name: test-module
|
||||||
}
|
}
|
||||||
// META-INF/test-module.kotlin_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 val constructorParam: kotlin/String
|
||||||
public final get
|
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
|
// getter: getGetterOnlyVal()D
|
||||||
public final val getterOnlyVal: kotlin/Double
|
public final val getterOnlyVal: kotlin/Double
|
||||||
public final /* non-default */ get
|
public final /* non-default */ get
|
||||||
@@ -35,11 +40,6 @@ public final class C : kotlin/Any {
|
|||||||
public final /* delegated */ val withOptimizedDelegate: kotlin/Double
|
public final /* delegated */ val withOptimizedDelegate: kotlin/Double
|
||||||
public final /* non-default */ get
|
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
|
// module name: test-module
|
||||||
}
|
}
|
||||||
// META-INF/test-module.kotlin_module
|
// META-INF/test-module.kotlin_module
|
||||||
|
|||||||
+5
-5
@@ -2,19 +2,19 @@
|
|||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
public final class SimpleClass<in T#0 /* A */> : kotlin/Any {
|
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
|
// signature: <init>([Ljava/lang/String;)V
|
||||||
public /* secondary */ constructor(s: kotlin/Array<kotlin/String?>?)
|
public /* secondary */ constructor(s: kotlin/Array<kotlin/String?>?)
|
||||||
|
|
||||||
// signature: <init>(I)V
|
// signature: f$test_module(Ljava/lang/Object;[Ljava/util/Map;)Ljava/util/Set;
|
||||||
public constructor(p: kotlin/Int /* = ... */)
|
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)
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
// signature: g(Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
// 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
|
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
|
// field: p:I
|
||||||
// getter: getP()I
|
// getter: getP()I
|
||||||
public final val p: kotlin/Int
|
public final val p: kotlin/Int
|
||||||
|
|||||||
Reference in New Issue
Block a user