Formatting changes
This commit is contained in:
+19
-17
@@ -267,8 +267,8 @@ private fun IrFunction.findBaseFunctionWithDefaultArguments(skipInlineMethods: B
|
||||
if (skipExternalMethods && isExternalOrInheritedFromExternal()) return null
|
||||
|
||||
if (this is IrSimpleFunction) {
|
||||
overriddenSymbols.forEach {
|
||||
val base = it.owner
|
||||
overriddenSymbols.forEach { overridden ->
|
||||
val base = overridden.owner
|
||||
if (base !in visited) base.dfsImpl()?.let { return it }
|
||||
}
|
||||
}
|
||||
@@ -485,12 +485,12 @@ class DefaultParameterPatchOverridenSymbolsLowering(
|
||||
}
|
||||
|
||||
private fun IrFunction.generateDefaultsFunction(
|
||||
context: CommonBackendContext,
|
||||
skipInlineMethods: Boolean,
|
||||
skipExternalMethods: Boolean,
|
||||
forceSetOverrideSymbols: Boolean,
|
||||
visibility: DescriptorVisibility,
|
||||
useConstructorMarker: Boolean
|
||||
context: CommonBackendContext,
|
||||
skipInlineMethods: Boolean,
|
||||
skipExternalMethods: Boolean,
|
||||
forceSetOverrideSymbols: Boolean,
|
||||
visibility: DescriptorVisibility,
|
||||
useConstructorMarker: Boolean
|
||||
): IrFunction? {
|
||||
if (skipInlineMethods && isInline) return null
|
||||
if (skipExternalMethods && isExternalOrInheritedFromExternal()) return null
|
||||
@@ -499,12 +499,14 @@ private fun IrFunction.generateDefaultsFunction(
|
||||
if (this is IrSimpleFunction) {
|
||||
// If this is an override of a function with default arguments, produce a fake override of a default stub.
|
||||
if (overriddenSymbols.any { it.owner.findBaseFunctionWithDefaultArguments(skipInlineMethods, skipExternalMethods) != null })
|
||||
return generateDefaultsFunctionImpl(context, IrDeclarationOrigin.FAKE_OVERRIDE, visibility, true, useConstructorMarker).also {
|
||||
context.mapping.defaultArgumentsDispatchFunction[this] = it
|
||||
context.mapping.defaultArgumentsOriginalFunction[it] = this
|
||||
return generateDefaultsFunctionImpl(
|
||||
context, IrDeclarationOrigin.FAKE_OVERRIDE, visibility, true, useConstructorMarker
|
||||
).also { defaultsFunction ->
|
||||
context.mapping.defaultArgumentsDispatchFunction[this] = defaultsFunction
|
||||
context.mapping.defaultArgumentsOriginalFunction[defaultsFunction] = this
|
||||
|
||||
if (forceSetOverrideSymbols) {
|
||||
(it as IrSimpleFunction).overriddenSymbols += overriddenSymbols.mapNotNull {
|
||||
(defaultsFunction as IrSimpleFunction).overriddenSymbols += overriddenSymbols.mapNotNull {
|
||||
it.owner.generateDefaultsFunction(
|
||||
context,
|
||||
skipInlineMethods,
|
||||
@@ -539,11 +541,11 @@ private fun IrFunction.generateDefaultsFunction(
|
||||
}
|
||||
|
||||
private fun IrFunction.generateDefaultsFunctionImpl(
|
||||
context: CommonBackendContext,
|
||||
newOrigin: IrDeclarationOrigin,
|
||||
newVisibility: DescriptorVisibility,
|
||||
isFakeOverride: Boolean,
|
||||
useConstructorMarker: Boolean
|
||||
context: CommonBackendContext,
|
||||
newOrigin: IrDeclarationOrigin,
|
||||
newVisibility: DescriptorVisibility,
|
||||
isFakeOverride: Boolean,
|
||||
useConstructorMarker: Boolean
|
||||
): IrFunction {
|
||||
val newFunction = when (this) {
|
||||
is IrConstructor ->
|
||||
|
||||
+11
-8
@@ -119,6 +119,7 @@ class LocalDeclarationsLowering(
|
||||
|
||||
private abstract class LocalContext {
|
||||
val capturedTypeParameterToTypeParameter: MutableMap<IrTypeParameter, IrTypeParameter> = mutableMapOf()
|
||||
|
||||
// By the time typeRemapper is used, the map will be already filled
|
||||
val typeRemapper = IrTypeParameterRemapper(capturedTypeParameterToTypeParameter)
|
||||
|
||||
@@ -698,7 +699,9 @@ class LocalDeclarationsLowering(
|
||||
throw AssertionError("Local class constructor can't have extension receiver: ${ir2string(oldDeclaration)}")
|
||||
}
|
||||
|
||||
newDeclaration.valueParameters += createTransformedValueParameters(capturedValues, localClassContext, oldDeclaration, newDeclaration)
|
||||
newDeclaration.valueParameters += createTransformedValueParameters(
|
||||
capturedValues, localClassContext, oldDeclaration, newDeclaration
|
||||
)
|
||||
newDeclaration.recordTransformedValueParameters(constructorContext)
|
||||
|
||||
newDeclaration.metadata = oldDeclaration.metadata
|
||||
@@ -708,13 +711,13 @@ class LocalDeclarationsLowering(
|
||||
}
|
||||
|
||||
private fun createFieldForCapturedValue(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
parent: IrClass,
|
||||
fieldType: IrType,
|
||||
isCrossinline: Boolean
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
parent: IrClass,
|
||||
fieldType: IrType,
|
||||
isCrossinline: Boolean
|
||||
): IrField =
|
||||
context.irFactory.buildField {
|
||||
this.startOffset = startOffset
|
||||
|
||||
+29
-15
@@ -81,7 +81,7 @@ class FunctionInlining(
|
||||
val inlineFunctionResolver: InlineFunctionResolver
|
||||
) : IrElementTransformerVoidWithContext(), BodyLoweringPass {
|
||||
|
||||
constructor(context: CommonBackendContext): this(context, DefaultInlineFunctionResolver(context))
|
||||
constructor(context: CommonBackendContext) : this(context, DefaultInlineFunctionResolver(context))
|
||||
|
||||
private var containerScope: ScopeWithIr? = null
|
||||
|
||||
@@ -263,7 +263,14 @@ class FunctionInlining(
|
||||
)
|
||||
}
|
||||
is IrSimpleFunction ->
|
||||
IrCallImpl(startOffset, endOffset, function.returnType, function.symbol, function.typeParameters.size, function.valueParameters.size)
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
function.returnType,
|
||||
function.symbol,
|
||||
function.typeParameters.size,
|
||||
function.valueParameters.size
|
||||
)
|
||||
else ->
|
||||
error("Unknown function kind : ${function.render()}")
|
||||
}
|
||||
@@ -308,7 +315,11 @@ class FunctionInlining(
|
||||
function.extensionReceiverParameter ->
|
||||
this.extensionReceiver = argument.implicitCastIfNeededTo(function.extensionReceiverParameter!!.type)
|
||||
|
||||
else -> putValueArgument(parameter.index, argument.implicitCastIfNeededTo(function.valueParameters[parameter.index].type))
|
||||
else ->
|
||||
putValueArgument(
|
||||
parameter.index,
|
||||
argument.implicitCastIfNeededTo(function.valueParameters[parameter.index].type)
|
||||
)
|
||||
}
|
||||
}
|
||||
assert(unboundIndex == valueParameters.size) { "Not all arguments of the callee are used" }
|
||||
@@ -367,8 +378,8 @@ class FunctionInlining(
|
||||
|| argumentExpression is IrFunctionExpression)
|
||||
|
||||
val isImmutableVariableLoad: Boolean
|
||||
get() = argumentExpression.let {
|
||||
it is IrGetValue && !it.symbol.owner.let { it is IrVariable && it.isVar }
|
||||
get() = argumentExpression.let { argument ->
|
||||
argument is IrGetValue && !argument.symbol.owner.let { it is IrVariable && it.isVar }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,28 +498,30 @@ class FunctionInlining(
|
||||
val arguments = buildParameterToArgument(callSite, callee)
|
||||
val evaluationStatements = mutableListOf<IrStatement>()
|
||||
val substitutor = ParameterSubstitutor()
|
||||
arguments.forEach {
|
||||
arguments.forEach { argument ->
|
||||
/*
|
||||
* We need to create temporary variable for each argument except inlinable lambda arguments.
|
||||
* For simplicity and to produce simpler IR we don't create temporaries for every immutable variable,
|
||||
* not only for those referring to inlinable lambdas.
|
||||
*/
|
||||
if (it.isInlinableLambdaArgument) {
|
||||
substituteMap[it.parameter] = it.argumentExpression
|
||||
(it.argumentExpression as? IrFunctionReference)?.let { evaluationStatements += evaluateArguments(it) }
|
||||
if (argument.isInlinableLambdaArgument) {
|
||||
substituteMap[argument.parameter] = argument.argumentExpression
|
||||
(argument.argumentExpression as? IrFunctionReference)?.let { evaluationStatements += evaluateArguments(it) }
|
||||
return@forEach
|
||||
}
|
||||
|
||||
if (it.isImmutableVariableLoad) {
|
||||
substituteMap[it.parameter] =
|
||||
it.argumentExpression.transform( // Arguments may reference the previous ones - substitute them.
|
||||
if (argument.isImmutableVariableLoad) {
|
||||
substituteMap[argument.parameter] =
|
||||
argument.argumentExpression.transform( // Arguments may reference the previous ones - substitute them.
|
||||
substitutor,
|
||||
data = null
|
||||
)
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val variableInitializer = it.argumentExpression.transform(substitutor, data = null) // Arguments may reference the previous ones - substitute them.
|
||||
// Arguments may reference the previous ones - substitute them.
|
||||
val variableInitializer = argument.argumentExpression.transform(substitutor, data = null)
|
||||
|
||||
val newVariable =
|
||||
currentScope.scope.createTemporaryVariableWithWrappedDescriptor(
|
||||
irExpression = IrBlockImpl(
|
||||
@@ -524,7 +537,7 @@ class FunctionInlining(
|
||||
)
|
||||
|
||||
evaluationStatements.add(newVariable)
|
||||
substituteMap[it.parameter] = IrGetValueWithoutLocation(newVariable.symbol)
|
||||
substituteMap[argument.parameter] = IrGetValueWithoutLocation(newVariable.symbol)
|
||||
}
|
||||
return evaluationStatements
|
||||
}
|
||||
@@ -556,7 +569,8 @@ class FunctionInlining(
|
||||
}
|
||||
|
||||
class InlinerExpressionLocationHint(val inlineAtSymbol: IrSymbol) : IrStatementOrigin {
|
||||
override fun toString(): String = "(${this.javaClass.simpleName} : $functionNameOrDefaultToString @${functionFileOrNull?.fileEntry?.name})"
|
||||
override fun toString(): String =
|
||||
"(${this.javaClass.simpleName} : $functionNameOrDefaultToString @${functionFileOrNull?.fileEntry?.name})"
|
||||
|
||||
private val functionFileOrNull: IrFile?
|
||||
get() = (inlineAtSymbol as? IrFunction)?.file
|
||||
|
||||
Reference in New Issue
Block a user