Propagate KotlinType through call generator, fix boxing on arguments
This commit is contained in:
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen;
|
package org.jetbrains.kotlin.codegen;
|
||||||
@@ -28,7 +17,7 @@ import org.jetbrains.org.objectweb.asm.Type;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.codegen.StackValue.*;
|
import static org.jetbrains.kotlin.codegen.StackValue.createDefaultValue;
|
||||||
|
|
||||||
public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
||||||
private final ExpressionCodegen codegen;
|
private final ExpressionCodegen codegen;
|
||||||
@@ -64,7 +53,12 @@ public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void generateDefault(int i, @NotNull DefaultValueArgument argument) {
|
protected void generateDefault(int i, @NotNull DefaultValueArgument argument) {
|
||||||
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), createDefaultValue(valueParameterTypes.get(i)), ValueKind.DEFAULT_PARAMETER, i);
|
callGenerator.putValueIfNeeded(
|
||||||
|
getJvmKotlinType(valueParameterTypes, valueParameters, i),
|
||||||
|
createDefaultValue(valueParameterTypes.get(i)),
|
||||||
|
ValueKind.DEFAULT_PARAMETER,
|
||||||
|
i
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,7 +67,7 @@ public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
|||||||
// Upper bound for type of vararg parameter should always have a form of 'Array<out T>',
|
// Upper bound for type of vararg parameter should always have a form of 'Array<out T>',
|
||||||
// while its lower bound may be Nothing-typed after approximation
|
// while its lower bound may be Nothing-typed after approximation
|
||||||
StackValue lazyVararg = codegen.genVarargs(argument, FlexibleTypesKt.upperIfFlexible(parameter.getType()));
|
StackValue lazyVararg = codegen.genVarargs(argument, FlexibleTypesKt.upperIfFlexible(parameter.getType()));
|
||||||
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), lazyVararg, ValueKind.GENERAL_VARARG, i);
|
callGenerator.putValueIfNeeded(getJvmKotlinType(valueParameterTypes, valueParameters, i), lazyVararg, ValueKind.GENERAL_VARARG, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,11 +78,19 @@ public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
|||||||
codegen.typeMapper
|
codegen.typeMapper
|
||||||
);
|
);
|
||||||
|
|
||||||
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), argumentValue);
|
callGenerator.putValueIfNeeded(getJvmKotlinType(valueParameterTypes, valueParameters, i), argumentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void reorderArgumentsIfNeeded(@NotNull List<ArgumentAndDeclIndex> actualArgsWithDeclIndex) {
|
protected void reorderArgumentsIfNeeded(@NotNull List<ArgumentAndDeclIndex> actualArgsWithDeclIndex) {
|
||||||
callGenerator.reorderArgumentsIfNeeded(actualArgsWithDeclIndex, valueParameterTypes);
|
callGenerator.reorderArgumentsIfNeeded(actualArgsWithDeclIndex, valueParameterTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static JvmKotlinType getJvmKotlinType(
|
||||||
|
@NotNull List<Type> valueParameterTypes,
|
||||||
|
@NotNull List<ValueParameterDescriptor> valueParameters, int i
|
||||||
|
) {
|
||||||
|
return new JvmKotlinType(valueParameterTypes.get(i), valueParameters.get(i).getOriginal().getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ interface CallGenerator {
|
|||||||
stackValue.put(stackValue.type, codegen.v)
|
stackValue.put(stackValue.type, codegen.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
override fun putValueIfNeeded(parameterType: JvmKotlinType, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
||||||
value.put(value.type, codegen.v)
|
value.put(value.type, value.kotlinType, codegen.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reorderArgumentsIfNeeded(actualArgsWithDeclIndex: List<ArgumentAndDeclIndex>, valueParameterTypes: List<Type>) {
|
override fun reorderArgumentsIfNeeded(actualArgsWithDeclIndex: List<ArgumentAndDeclIndex>, valueParameterTypes: List<Type>) {
|
||||||
@@ -104,13 +104,13 @@ interface CallGenerator {
|
|||||||
parameterIndex: Int)
|
parameterIndex: Int)
|
||||||
|
|
||||||
fun putValueIfNeeded(
|
fun putValueIfNeeded(
|
||||||
parameterType: Type,
|
parameterType: JvmKotlinType,
|
||||||
value: StackValue) {
|
value: StackValue) {
|
||||||
putValueIfNeeded(parameterType, value, ValueKind.GENERAL)
|
putValueIfNeeded(parameterType, value, ValueKind.GENERAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun putValueIfNeeded(
|
fun putValueIfNeeded(
|
||||||
parameterType: Type,
|
parameterType: JvmKotlinType,
|
||||||
value: StackValue,
|
value: StackValue,
|
||||||
kind: ValueKind = ValueKind.GENERAL,
|
kind: ValueKind = ValueKind.GENERAL,
|
||||||
parameterIndex: Int = -1)
|
parameterIndex: Int = -1)
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
@@ -55,11 +44,15 @@ class DefaultCallArgs(val size: Int) {
|
|||||||
val toInts = toInts()
|
val toInts = toInts()
|
||||||
if (!toInts.isEmpty()) {
|
if (!toInts.isEmpty()) {
|
||||||
for (mask in toInts) {
|
for (mask in toInts) {
|
||||||
callGenerator.putValueIfNeeded(Type.INT_TYPE, StackValue.constant(mask, Type.INT_TYPE), ValueKind.DEFAULT_MASK)
|
callGenerator.putValueIfNeeded(
|
||||||
|
JvmKotlinType(Type.INT_TYPE), StackValue.constant(mask, Type.INT_TYPE), ValueKind.DEFAULT_MASK
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val parameterType = if (isConstructor) AsmTypes.DEFAULT_CONSTRUCTOR_MARKER else AsmTypes.OBJECT_TYPE
|
val parameterType = if (isConstructor) AsmTypes.DEFAULT_CONSTRUCTOR_MARKER else AsmTypes.OBJECT_TYPE
|
||||||
callGenerator.putValueIfNeeded(parameterType, StackValue.constant(null, parameterType), ValueKind.METHOD_HANDLE_IN_DEFAULT)
|
callGenerator.putValueIfNeeded(
|
||||||
|
JvmKotlinType(parameterType), StackValue.constant(null, parameterType), ValueKind.METHOD_HANDLE_IN_DEFAULT
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return toInts.isNotEmpty()
|
return toInts.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2342,7 +2342,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
List<JvmMethodParameterSignature> callableParameters = ((CallableMethod) callableMethod).getValueParameters();
|
List<JvmMethodParameterSignature> callableParameters = ((CallableMethod) callableMethod).getValueParameters();
|
||||||
for (JvmMethodParameterSignature parameter: callableParameters) {
|
for (JvmMethodParameterSignature parameter: callableParameters) {
|
||||||
if (parameter.getKind() == JvmMethodParameterKind.CONSTRUCTOR_MARKER) {
|
if (parameter.getKind() == JvmMethodParameterKind.CONSTRUCTOR_MARKER) {
|
||||||
callGenerator.putValueIfNeeded(parameter.getAsmType(), StackValue.constant(null, parameter.getAsmType()));
|
callGenerator.putValueIfNeeded(
|
||||||
|
new JvmKotlinType(parameter.getAsmType(), null), StackValue.constant(null, parameter.getAsmType())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2584,10 +2586,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private StackValue generateExtensionReceiver(@NotNull CallableDescriptor descriptor) {
|
private StackValue generateExtensionReceiver(@NotNull CallableDescriptor descriptor) {
|
||||||
if (myFrameMap.getIndex(descriptor.getExtensionReceiverParameter()) != -1) {
|
ReceiverParameterDescriptor parameter = descriptor.getExtensionReceiverParameter();
|
||||||
|
if (myFrameMap.getIndex(parameter) != -1) {
|
||||||
|
KotlinType type = parameter.getReturnType();
|
||||||
return StackValue.local(
|
return StackValue.local(
|
||||||
myFrameMap.getIndex(descriptor.getExtensionReceiverParameter()),
|
myFrameMap.getIndex(parameter),
|
||||||
typeMapper.mapType(descriptor.getExtensionReceiverParameter())
|
typeMapper.mapType(type),
|
||||||
|
type
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1192,7 +1192,7 @@ public class FunctionCodegen {
|
|||||||
ValueParameterDescriptor parameterDescriptor = valueParameters.get(index);
|
ValueParameterDescriptor parameterDescriptor = valueParameters.get(index);
|
||||||
Type type = mappedParameters.get(capturedArgumentsCount + index).getAsmType();
|
Type type = mappedParameters.get(capturedArgumentsCount + index).getAsmType();
|
||||||
int parameterIndex = frameMap.getIndex(parameterDescriptor);
|
int parameterIndex = frameMap.getIndex(parameterDescriptor);
|
||||||
generator.putValueIfNeeded(type, StackValue.local(parameterIndex, type));
|
generator.putValueIfNeeded(new JvmKotlinType(type, null), StackValue.local(parameterIndex, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
CallableMethod method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false);
|
CallableMethod method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false);
|
||||||
@@ -1264,14 +1264,14 @@ public class FunctionCodegen {
|
|||||||
) {
|
) {
|
||||||
int var = 0;
|
int var = 0;
|
||||||
if (!isStatic) {
|
if (!isStatic) {
|
||||||
callGenerator.putValueIfNeeded(ownerType, StackValue.local(var, ownerType));
|
callGenerator.putValueIfNeeded(new JvmKotlinType(ownerType, null), StackValue.local(var, ownerType));
|
||||||
var += ownerType.getSize();
|
var += ownerType.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JvmMethodParameterSignature parameterSignature : signature.getValueParameters()) {
|
for (JvmMethodParameterSignature parameterSignature : signature.getValueParameters()) {
|
||||||
if (parameterSignature.getKind() != JvmMethodParameterKind.VALUE) {
|
if (parameterSignature.getKind() != JvmMethodParameterKind.VALUE) {
|
||||||
Type type = parameterSignature.getAsmType();
|
Type type = parameterSignature.getAsmType();
|
||||||
callGenerator.putValueIfNeeded(type, StackValue.local(var, type));
|
callGenerator.putValueIfNeeded(new JvmKotlinType(type, null), StackValue.local(var, type));
|
||||||
var += type.getSize();
|
var += type.getSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1294,7 +1294,10 @@ public abstract class StackValue {
|
|||||||
|
|
||||||
coerce(topOfStackType, topOfStackKotlinType, lastParameterType, lastParameterKotlinType, v);
|
coerce(topOfStackType, topOfStackKotlinType, lastParameterType, lastParameterKotlinType, v);
|
||||||
|
|
||||||
getCallGenerator().putValueIfNeeded(lastParameterType, StackValue.onStack(lastParameterType));
|
getCallGenerator().putValueIfNeeded(
|
||||||
|
new JvmKotlinType(lastParameterType, lastParameterKotlinType),
|
||||||
|
StackValue.onStack(lastParameterType, lastParameterKotlinType)
|
||||||
|
);
|
||||||
|
|
||||||
//Convention setter couldn't have default parameters, just getter can have it at last positions
|
//Convention setter couldn't have default parameters, just getter can have it at last positions
|
||||||
//We should remove default parameters of getter from stack*/
|
//We should remove default parameters of getter from stack*/
|
||||||
@@ -1481,7 +1484,7 @@ public abstract class StackValue {
|
|||||||
putReceiver(v, false);
|
putReceiver(v, false);
|
||||||
}
|
}
|
||||||
callGenerator.processAndPutHiddenParameters(true);
|
callGenerator.processAndPutHiddenParameters(true);
|
||||||
callGenerator.putValueIfNeeded(rightSide.type, rightSide);
|
callGenerator.putValueIfNeeded(new JvmKotlinType(rightSide.type, rightSide.kotlinType), rightSide);
|
||||||
callGenerator.putHiddenParamsIntoLocals();
|
callGenerator.putHiddenParamsIntoLocals();
|
||||||
callGenerator.genCall(setter, resolvedCall, false, codegen);
|
callGenerator.genCall(setter, resolvedCall, false, codegen);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ private fun CallableDescriptor.isJvmStaticIn(predicate: (DeclarationDescriptor)
|
|||||||
|
|
||||||
fun Collection<VariableDescriptor>.filterOutDescriptorsWithSpecialNames() = filterNot { it.name.isSpecial }
|
fun Collection<VariableDescriptor>.filterOutDescriptorsWithSpecialNames() = filterNot { it.name.isSpecial }
|
||||||
|
|
||||||
class JvmKotlinType(val type: Type, val kotlinType: KotlinType?)
|
class JvmKotlinType(val type: Type, val kotlinType: KotlinType? = null)
|
||||||
|
|
||||||
fun KotlinType.asmType(typeMapper: KotlinTypeMapper) = typeMapper.mapType(this)
|
fun KotlinType.asmType(typeMapper: KotlinTypeMapper) = typeMapper.mapType(this)
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.inline
|
package org.jetbrains.kotlin.codegen.inline
|
||||||
@@ -52,7 +41,6 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
|
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
|
||||||
import org.jetbrains.kotlin.types.expressions.LabelResolver
|
import org.jetbrains.kotlin.types.expressions.LabelResolver
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
@@ -326,20 +314,21 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun putArgumentOrCapturedToLocalVal(
|
protected fun putArgumentOrCapturedToLocalVal(
|
||||||
type: Type,
|
jvmKotlinType: JvmKotlinType,
|
||||||
stackValue: StackValue,
|
stackValue: StackValue,
|
||||||
capturedParamIndex: Int,
|
capturedParamIndex: Int,
|
||||||
parameterIndex: Int,
|
parameterIndex: Int,
|
||||||
kind: ValueKind
|
kind: ValueKind
|
||||||
) {
|
) {
|
||||||
val isDefaultParameter = kind === ValueKind.DEFAULT_PARAMETER
|
val isDefaultParameter = kind === ValueKind.DEFAULT_PARAMETER
|
||||||
if (!isDefaultParameter && shouldPutGeneralValue(type, stackValue)) {
|
val jvmType = jvmKotlinType.type
|
||||||
stackValue.put(type, codegen.v)
|
if (!isDefaultParameter && shouldPutGeneralValue(jvmType, stackValue)) {
|
||||||
|
stackValue.put(jvmType, jvmKotlinType.kotlinType, codegen.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asFunctionInline && Type.VOID_TYPE !== type) {
|
if (!asFunctionInline && Type.VOID_TYPE !== jvmType) {
|
||||||
//TODO remap only inlinable closure => otherwise we could get a lot of problem
|
//TODO remap only inlinable closure => otherwise we could get a lot of problem
|
||||||
val couldBeRemapped = !shouldPutGeneralValue(type, stackValue) && kind !== ValueKind.DEFAULT_PARAMETER
|
val couldBeRemapped = !shouldPutGeneralValue(jvmType, stackValue) && kind !== ValueKind.DEFAULT_PARAMETER
|
||||||
val remappedValue = if (couldBeRemapped) stackValue else null
|
val remappedValue = if (couldBeRemapped) stackValue else null
|
||||||
|
|
||||||
val info: ParameterInfo
|
val info: ParameterInfo
|
||||||
@@ -349,7 +338,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
info.setRemapValue(remappedValue)
|
info.setRemapValue(remappedValue)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info = invocationParamBuilder.addNextValueParameter(type, false, remappedValue, parameterIndex)
|
info = invocationParamBuilder.addNextValueParameter(jvmType, false, remappedValue, parameterIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
recordParameterValueInLocalVal(
|
recordParameterValueInLocalVal(
|
||||||
@@ -413,7 +402,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
protected fun rememberCapturedForDefaultLambda(defaultLambda: DefaultLambda) {
|
protected fun rememberCapturedForDefaultLambda(defaultLambda: DefaultLambda) {
|
||||||
for ((paramIndex, captured) in defaultLambda.capturedVars.withIndex()) {
|
for ((paramIndex, captured) in defaultLambda.capturedVars.withIndex()) {
|
||||||
putArgumentOrCapturedToLocalVal(
|
putArgumentOrCapturedToLocalVal(
|
||||||
captured.type,
|
JvmKotlinType(captured.type),
|
||||||
//HACK: actually parameter would be placed on stack in default function
|
//HACK: actually parameter would be placed on stack in default function
|
||||||
// also see ValueKind.DEFAULT_LAMBDA_CAPTURED_PARAMETER check
|
// also see ValueKind.DEFAULT_LAMBDA_CAPTURED_PARAMETER check
|
||||||
StackValue.onStack(captured.type),
|
StackValue.onStack(captured.type),
|
||||||
@@ -736,7 +725,12 @@ class PsiInlineCodegen(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val value = codegen.gen(argumentExpression)
|
val value = codegen.gen(argumentExpression)
|
||||||
putValueIfNeeded(parameterType, value, ValueKind.GENERAL, valueParameterDescriptor.index)
|
putValueIfNeeded(
|
||||||
|
JvmKotlinType(parameterType, valueParameterDescriptor.original.type),
|
||||||
|
value,
|
||||||
|
ValueKind.GENERAL,
|
||||||
|
valueParameterDescriptor.index
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,7 +747,7 @@ class PsiInlineCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
override fun putValueIfNeeded(parameterType: JvmKotlinType, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
||||||
if (processDefaultMaskOrMethodHandler(value, kind)) return
|
if (processDefaultMaskOrMethodHandler(value, kind)) return
|
||||||
|
|
||||||
assert(maskValues.isEmpty()) { "Additional default call arguments should be last ones, but " + value }
|
assert(maskValues.isEmpty()) { "Additional default call arguments should be last ones, but " + value }
|
||||||
@@ -762,7 +756,9 @@ class PsiInlineCodegen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun putCapturedValueOnStack(stackValue: StackValue, valueType: Type, paramIndex: Int) {
|
override fun putCapturedValueOnStack(stackValue: StackValue, valueType: Type, paramIndex: Int) {
|
||||||
putArgumentOrCapturedToLocalVal(stackValue.type, stackValue, paramIndex, paramIndex, ValueKind.CAPTURED)
|
putArgumentOrCapturedToLocalVal(
|
||||||
|
JvmKotlinType(stackValue.type, stackValue.kotlinType), stackValue, paramIndex, paramIndex, ValueKind.CAPTURED
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reorderArgumentsIfNeeded(actualArgsWithDeclIndex: List<ArgumentAndDeclIndex>, valueParameterTypes: List<Type>) = Unit
|
override fun reorderArgumentsIfNeeded(actualArgsWithDeclIndex: List<ArgumentAndDeclIndex>, valueParameterTypes: List<Type>) = Unit
|
||||||
|
|||||||
+3
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.inline
|
package org.jetbrains.kotlin.codegen.inline
|
||||||
@@ -92,7 +81,7 @@ class InlineCodegenForDefaultBody(
|
|||||||
throw UnsupportedOperationException("Shouldn't be called")
|
throw UnsupportedOperationException("Shouldn't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
override fun putValueIfNeeded(parameterType: JvmKotlinType, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
||||||
//original method would be inlined directly into default impl body without any inline magic
|
//original method would be inlined directly into default impl body without any inline magic
|
||||||
//so we no need to load variables on stack to further method call
|
//so we no need to load variables on stack to further method call
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-16
@@ -1,22 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.Callable
|
import org.jetbrains.kotlin.codegen.Callable
|
||||||
|
import org.jetbrains.kotlin.codegen.JvmKotlinType
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.codegen.ValueKind
|
import org.jetbrains.kotlin.codegen.ValueKind
|
||||||
import org.jetbrains.kotlin.codegen.inline.*
|
import org.jetbrains.kotlin.codegen.inline.*
|
||||||
@@ -62,17 +52,19 @@ class IrInlineCodegen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int, codegen: ExpressionCodegen) {
|
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int, codegen: ExpressionCodegen) {
|
||||||
putArgumentOrCapturedToLocalVal(value.type, value, -1, parameterIndex, ValueKind.CAPTURED)
|
putArgumentOrCapturedToLocalVal(JvmKotlinType(value.type, value.kotlinType), value, -1, parameterIndex, ValueKind.CAPTURED)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun putCapturedValueOnStack(argumentExpression: IrExpression, valueType: Type, capturedParamindex: Int) {
|
fun putCapturedValueOnStack(argumentExpression: IrExpression, valueType: Type, capturedParamindex: Int) {
|
||||||
val onStack = codegen.gen(argumentExpression, valueType, BlockInfo.create())
|
val onStack = codegen.gen(argumentExpression, valueType, BlockInfo.create())
|
||||||
putArgumentOrCapturedToLocalVal(onStack.type, onStack, capturedParamindex, capturedParamindex, ValueKind.CAPTURED)
|
putArgumentOrCapturedToLocalVal(
|
||||||
|
JvmKotlinType(onStack.type, onStack.kotlinType), onStack, capturedParamindex, capturedParamindex, ValueKind.CAPTURED
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun putValueOnStack(argumentExpression: IrExpression, valueType: Type, paramIndex: Int) {
|
fun putValueOnStack(argumentExpression: IrExpression, valueType: Type, paramIndex: Int) {
|
||||||
val onStack = codegen.gen(argumentExpression, valueType, BlockInfo.create())
|
val onStack = codegen.gen(argumentExpression, valueType, BlockInfo.create())
|
||||||
putArgumentOrCapturedToLocalVal(onStack.type, onStack, -1, paramIndex, ValueKind.CAPTURED)
|
putArgumentOrCapturedToLocalVal(JvmKotlinType(onStack.type, onStack.kotlinType), onStack, -1, paramIndex, ValueKind.CAPTURED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeValueParametersStart() {
|
override fun beforeValueParametersStart() {
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
inline class Foo(val value: Int)
|
||||||
|
|
||||||
|
fun <T> id(x: T): T = x
|
||||||
|
inline fun <T> inlinedId(x: T): T = x
|
||||||
|
|
||||||
|
fun <T> T.idExtension(): T = this
|
||||||
|
inline fun <T> T.inlinedIdExtension(): T = this
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
inlinedId(f) // box
|
||||||
|
inlinedId(f).idExtension() // box
|
||||||
|
|
||||||
|
f.inlinedIdExtension() // box
|
||||||
|
|
||||||
|
val a = inlinedId(f).idExtension() // box unbox
|
||||||
|
val b = inlinedId(f).inlinedIdExtension() // box unbox
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val f = Foo(11)
|
||||||
|
|
||||||
|
id(inlinedId(f))
|
||||||
|
inlinedId(id(f))
|
||||||
|
|
||||||
|
inlinedId(f) // box
|
||||||
|
inlinedId(f).idExtension() // box
|
||||||
|
|
||||||
|
f.inlinedIdExtension() // box
|
||||||
|
|
||||||
|
val a = inlinedId(f).idExtension() // box unbox
|
||||||
|
val b = inlinedId(f).inlinedIdExtension() // box unbox
|
||||||
|
|
||||||
|
if (a.value != 11) return "fail"
|
||||||
|
if (b.value != 11) return "fail"
|
||||||
|
|
||||||
|
if (inlinedId(Foo(10)).value != 10) return "fail"
|
||||||
|
if (Foo(20).inlinedIdExtension().value != 20) return "fail"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
inline class Foo(val a: Int)
|
||||||
|
|
||||||
|
fun <T> id(x: T): T = x
|
||||||
|
inline fun <T> inlinedId(x: T): T = x
|
||||||
|
|
||||||
|
fun <T> T.idExtension(): T = this
|
||||||
|
inline fun <T> T.inlinedIdExtension(): T = this
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
inlinedId(f) // box
|
||||||
|
inlinedId(f).idExtension() // box
|
||||||
|
|
||||||
|
f.inlinedIdExtension() // box
|
||||||
|
|
||||||
|
val a = inlinedId(f).idExtension() // box unbox
|
||||||
|
val b = inlinedId(f).inlinedIdExtension() // box unbox
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5 INVOKESTATIC Foo\$Erased.box
|
||||||
|
// 2 INVOKEVIRTUAL Foo.unbox
|
||||||
|
|
||||||
|
// 0 valueOf
|
||||||
|
// 0 intValue
|
||||||
Generated
+6
@@ -10407,6 +10407,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||||
|
|||||||
+6
@@ -10407,6 +10407,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||||
|
|||||||
@@ -1938,6 +1938,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("boxUnboxOnInlinedParameters.kt")
|
||||||
|
public void testBoxUnboxOnInlinedParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOnInlinedParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("callMemberMethodsInsideInlineClass.kt")
|
@TestMetadata("callMemberMethodsInsideInlineClass.kt")
|
||||||
public void testCallMemberMethodsInsideInlineClass() throws Exception {
|
public void testCallMemberMethodsInsideInlineClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/callMemberMethodsInsideInlineClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/callMemberMethodsInsideInlineClass.kt");
|
||||||
|
|||||||
+6
@@ -10407,6 +10407,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||||
|
|||||||
+6
@@ -11391,6 +11391,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
@TestMetadata("checkBoxingAfterAssertionOperator.kt")
|
||||||
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
public void testCheckBoxingAfterAssertionOperator() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/checkBoxingAfterAssertionOperator.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user