[Commonizer] Implement two phased re-approximation
^KT-48288
This commit is contained in:
committed by
Space
parent
b68f14960a
commit
cf0f061db5
@@ -65,14 +65,11 @@ internal fun commonizeTarget(
|
|||||||
|
|
||||||
InlineTypeAliasCirNodeTransformer(parameters.storageManager, classifiers).invoke(mergedTree)
|
InlineTypeAliasCirNodeTransformer(parameters.storageManager, classifiers).invoke(mergedTree)
|
||||||
|
|
||||||
/*
|
|
||||||
ReApproximationCirNodeTransformer(
|
ReApproximationCirNodeTransformer(
|
||||||
parameters.storageManager, classifiers,
|
parameters.storageManager, classifiers,
|
||||||
SignatureBuildingContextProvider(classifiers, typeAliasInvariant = true, skipArguments = false)
|
SignatureBuildingContextProvider(classifiers, typeAliasInvariant = true, skipArguments = false)
|
||||||
).invoke(mergedTree)
|
).invoke(mergedTree)
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
ReApproximationCirNodeTransformer(
|
ReApproximationCirNodeTransformer(
|
||||||
parameters.storageManager, classifiers,
|
parameters.storageManager, classifiers,
|
||||||
SignatureBuildingContextProvider(classifiers, typeAliasInvariant = true, skipArguments = true)
|
SignatureBuildingContextProvider(classifiers, typeAliasInvariant = true, skipArguments = true)
|
||||||
|
|||||||
+15
-3
@@ -68,7 +68,11 @@ internal class ReApproximationCirNodeTransformer(
|
|||||||
buildFunctionNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
buildFunctionNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode.targetDeclarations.setIfAbsent(index, functionAtIndex)
|
// Move declaration
|
||||||
|
if (newNode.targetDeclarations[index] == null) {
|
||||||
|
function.targetDeclarations[index] = null
|
||||||
|
newNode.targetDeclarations[index] = functionAtIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private operator fun invoke(parent: CirNodeWithMembers<*, *>, property: CirPropertyNode, index: Int, context: CirMemberContext) {
|
private operator fun invoke(parent: CirNodeWithMembers<*, *>, property: CirPropertyNode, index: Int, context: CirMemberContext) {
|
||||||
@@ -81,7 +85,11 @@ internal class ReApproximationCirNodeTransformer(
|
|||||||
buildPropertyNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
buildPropertyNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode.targetDeclarations.setIfAbsent(index, propertyAtIndex)
|
// Move declaration
|
||||||
|
if (newNode.targetDeclarations[index] == null) {
|
||||||
|
property.targetDeclarations[index] = null
|
||||||
|
newNode.targetDeclarations[index] = propertyAtIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private operator fun invoke(
|
private operator fun invoke(
|
||||||
@@ -98,6 +106,10 @@ internal class ReApproximationCirNodeTransformer(
|
|||||||
buildClassConstructorNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
buildClassConstructorNode(storageManager, parent.targetDeclarations.size, classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode.targetDeclarations.setIfAbsent(index, constructorAtIndex)
|
// Move declaration
|
||||||
|
if (newNode.targetDeclarations[index] == null) {
|
||||||
|
constructor.targetDeclarations[index] = null
|
||||||
|
newNode.targetDeclarations[index] = constructorAtIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ internal fun CirNodeWithMembers<*, *>.buildFunction(
|
|||||||
buildFunctionNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
buildFunctionNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
/* Multiple type substitutions could in result in the same commonization result */
|
/* Multiple type substitutions could in result in the same commonization result */
|
||||||
functionNode.targetDeclarations.setIfAbsent(context.targetIndex, function)
|
functionNode.targetDeclarations.set(context.targetIndex, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirNodeWithMembers<*, *>.buildProperty(
|
internal fun CirNodeWithMembers<*, *>.buildProperty(
|
||||||
@@ -99,7 +99,7 @@ internal fun CirNodeWithMembers<*, *>.buildProperty(
|
|||||||
buildPropertyNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
buildPropertyNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
/* Multiple type substitutions could in result in the same commonization result */
|
/* Multiple type substitutions could in result in the same commonization result */
|
||||||
propertyNode.targetDeclarations.setIfAbsent(context.targetIndex, property)
|
propertyNode.targetDeclarations.set(context.targetIndex, property)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirClassNode.buildConstructor(
|
internal fun CirClassNode.buildConstructor(
|
||||||
@@ -111,7 +111,7 @@ internal fun CirClassNode.buildConstructor(
|
|||||||
buildClassConstructorNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
buildClassConstructorNode(context.storageManager, context.targets, context.classifiers, ParentNode(parent))
|
||||||
}
|
}
|
||||||
/* Multiple type substitutions could in result in the same commonization result */
|
/* Multiple type substitutions could in result in the same commonization result */
|
||||||
constructorNode.targetDeclarations.setIfAbsent(context.targetIndex, constructor)
|
constructorNode.targetDeclarations.set(context.targetIndex, constructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirPackageNode.buildTypeAlias(context: TargetBuildingContext, treeTypeAlias: CirTreeTypeAlias) {
|
internal fun CirPackageNode.buildTypeAlias(context: TargetBuildingContext, treeTypeAlias: CirTreeTypeAlias) {
|
||||||
|
|||||||
@@ -31,8 +31,4 @@ class CommonizedGroup<T : Any>(
|
|||||||
|
|
||||||
elements[index] = value
|
elements[index] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setIfAbsent(index: Int, value: T?) {
|
|
||||||
if (this[index] == null) set(index, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user