diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt index d7f24869c79..31072e641e5 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm @@ -46,7 +35,7 @@ class JvmBackendContext( ) : CommonBackendContext { override val builtIns = state.module.builtIns override val descriptorsFactory: JvmDescriptorsFactory = JvmDescriptorsFactory(psiSourceManager, builtIns) - override val sharedVariablesManager = JvmSharedVariablesManager(builtIns) + override val sharedVariablesManager = JvmSharedVariablesManager(builtIns, irBuiltIns) override val reflectionTypes: ReflectionTypes by lazy(LazyThreadSafetyMode.PUBLICATION) { ReflectionTypes(state.module, FqName("kotlin.reflect.jvm.internal")) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt index 39a6d82c1ed..63a7d6c1b12 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm @@ -44,7 +33,11 @@ object JvmBackendFacade { state, psi2irContext.sourceManager, psi2irContext.irBuiltIns, irModuleFragment, psi2irContext.symbolTable ) //TODO - ExternalDependenciesGenerator(psi2irContext.symbolTable, psi2irContext.irBuiltIns).generateUnboundSymbolsAsDependencies(irModuleFragment) + ExternalDependenciesGenerator( + irModuleFragment.descriptor, + psi2irContext.symbolTable, + psi2irContext.irBuiltIns + ).generateUnboundSymbolsAsDependencies(irModuleFragment) val jvmBackend = JvmBackend(jvmBackendContext) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 2b19455502b..e2c8d3d24c3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-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. */ @@ -26,6 +26,8 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.types.isArray +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.ir.visitors.IrElementVisitor @@ -176,7 +178,7 @@ class ExpressionCodegen( //coerceNotToUnit(r.type, Type.VOID_TYPE) exp.accept(this, data) } - return coerceNotToUnit(result.type, expression.type) + return coerceNotToUnit(result.type, expression.type.toKotlinType()) } override fun visitMemberAccess(expression: IrMemberAccessExpression, data: BlockInfo): StackValue { @@ -212,7 +214,7 @@ class ExpressionCodegen( if (args.size == 1) { val sizeExpression = expression.getValueArgument(0)!! gen(sizeExpression, Type.INT_TYPE, data) - newArrayInstruction(expression.type) + newArrayInstruction(expression.type.toKotlinType()) return expression.onStack } @@ -440,7 +442,7 @@ class ExpressionCodegen( val hasSpread = arguments.firstIsInstanceOrNull() != null if (hasSpread) { - val arrayOfReferences = KotlinBuiltIns.isArray(outType) + val arrayOfReferences = outType.isArray() if (size == 1) { // Arrays.copyOf(receiverValue, newLength) val argument = (arguments[0] as IrSpreadElement).expression @@ -488,7 +490,7 @@ class ExpressionCodegen( if (arrayOfReferences) { mv.dup() mv.invokevirtual(owner, "size", "()I", false) - newArrayInstruction(outType) + newArrayInstruction(outType.toKotlinType()) mv.invokevirtual(owner, "toArray", toArrayDescriptor, false) mv.checkcast(type) } else { @@ -497,8 +499,8 @@ class ExpressionCodegen( } } else { mv.iconst(size) - newArrayInstruction(expression.type) - val elementKotlinType = outType.constructor.builtIns.getArrayElementType(outType) + newArrayInstruction(expression.type.toKotlinType()) + val elementKotlinType = classCodegen.context.builtIns.getArrayElementType(outType.toKotlinType()!!) for ((i, element) in expression.elements.withIndex()) { mv.dup() StackValue.constant(i, Type.INT_TYPE).put(Type.INT_TYPE, mv) @@ -507,7 +509,7 @@ class ExpressionCodegen( .arrayElement( elementType, elementKotlinType, - StackValue.onStack(elementType, outType), + StackValue.onStack(elementType, outType.toKotlinType()), StackValue.onStack(Type.INT_TYPE) ) .store(rightSide, mv) @@ -547,7 +549,7 @@ class ExpressionCodegen( override fun visitWhen(expression: IrWhen, data: BlockInfo): StackValue = - genIfWithBranches(expression.branches[0], data, expression.type, expression.branches.drop(1)) + genIfWithBranches(expression.branches[0], data, expression.type.toKotlinType(), expression.branches.drop(1)) private fun genIfWithBranches(branch: IrBranch, data: BlockInfo, type: KotlinType, otherBranches: List): StackValue { @@ -582,7 +584,7 @@ class ExpressionCodegen( override fun visitTypeOperator(expression: IrTypeOperatorCall, data: BlockInfo): StackValue { - val asmType = expression.typeOperand.asmType + val asmType = expression.typeOperand.toKotlinType().asmType when (expression.operator) { IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> { val result = expression.argument.accept(this, data) @@ -601,14 +603,14 @@ class ExpressionCodegen( StackValue.putUnitInstance(mv) } val boxedType = boxType(asmType) - generateAsCast(mv, expression.typeOperand, boxedType, expression.operator == IrTypeOperator.SAFE_CAST) + generateAsCast(mv, expression.typeOperand.toKotlinType(), boxedType, expression.operator == IrTypeOperator.SAFE_CAST) return onStack(boxedType) } IrTypeOperator.INSTANCEOF, IrTypeOperator.NOT_INSTANCEOF -> { gen(expression.argument, OBJECT_TYPE, data) val type = boxType(asmType) - generateIsCheck(mv, expression.typeOperand, type) + generateIsCheck(mv, expression.typeOperand.toKotlinType(), type) if (IrTypeOperator.NOT_INSTANCEOF == expression.operator) { StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, mv) } @@ -627,7 +629,7 @@ class ExpressionCodegen( IrTypeOperator.IMPLICIT_INTEGER_COERCION -> { gen(expression.argument, Type.INT_TYPE, data) - StackValue.coerce(Type.INT_TYPE, typeMapper.mapType(expression.type), mv) + StackValue.coerce(Type.INT_TYPE, typeMapper.mapType(expression.type.toKotlinType()), mv) } } return expression.onStack @@ -937,7 +939,7 @@ class ExpressionCodegen( assert(classReference is IrGetClass) JavaClassProperty.generateImpl(mv, gen((classReference as IrGetClass).argument, data)) } else { - val type = classReference.classType + val type = classReference.classType.toKotlinType() if (TypeUtils.isTypeParameter(type)) { assert(TypeUtils.isReifiedTypeParameter(type)) { "Non-reified type parameter under ::class should be rejected by type checker: " + type } putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS, mv, this) @@ -962,7 +964,7 @@ class ExpressionCodegen( } val IrExpression.asmType: Type - get() = typeMapper.mapType(this.type) + get() = typeMapper.mapType(this.type.toKotlinType()) val IrExpression.onStack: StackValue get() = StackValue.onStack(this.asmType) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 212036b1705..d066dd7d95b 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.codegen @@ -25,6 +14,7 @@ import org.jetbrains.kotlin.codegen.FunctionCodegen import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.util.hasAnnotation import org.jetbrains.kotlin.ir.util.isAnnotationClass @@ -155,7 +145,7 @@ private fun createFrameMapWithReceivers( } for (parameter in irFunction.valueParameters) { - frameMap.enter(parameter, state.typeMapper.mapType(parameter.type)) + frameMap.enter(parameter, state.typeMapper.mapType(parameter.type.toKotlinType())) } return frameMap diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt index 142f13ee378..eb17f34a0ad 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-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. */ diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorsFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorsFactory.kt index 44141842df5..c1e43a6a3e7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorsFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorsFactory.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.descriptors @@ -31,6 +20,7 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.load.java.JavaVisibilities @@ -74,7 +64,7 @@ class JvmDescriptorsFactory( IrFieldSymbolImpl( JvmPropertyDescriptorImpl.createFinalField( - Name.identifier("this$0"), outerClass.defaultType, innerClass.descriptor, + Name.identifier("this$0"), outerClass.defaultType.toKotlinType(), innerClass.descriptor, Annotations.EMPTY, JavaVisibilities.PACKAGE_VISIBILITY, Opcodes.ACC_SYNTHETIC, SourceElement.NO_SOURCE ) ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt index 5a9a8ffa2e9..eb630b16eb2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.descriptors @@ -29,17 +18,22 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl +import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetValue import org.jetbrains.kotlin.ir.expressions.IrSetVariable import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol +import org.jetbrains.kotlin.ir.types.toIrType import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.* -class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesManager { +class JvmSharedVariablesManager( + val builtIns: KotlinBuiltIns, + val irBuiltIns: IrBuiltIns +) : SharedVariablesManager { private val kotlinJvmInternalPackage = KnownPackageFragmentDescriptor(builtIns.builtInsModule, FqName("kotlin.jvm.internal")) private val refNamespaceClass = KnownClassDescriptor.createClass(Name.identifier("Ref"), kotlinJvmInternalPackage, listOf(builtIns.anyType)) @@ -148,11 +142,12 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM val refConstructorCall = IrCallImpl( originalDeclaration.startOffset, originalDeclaration.endOffset, - refConstructor, refConstructorTypeArguments + refConstructor.constructedClass.defaultType.toIrType()!!, + refConstructor, refConstructorTypeArguments?.size ?: 0 ) return IrVariableImpl( originalDeclaration.startOffset, originalDeclaration.endOffset, originalDeclaration.origin, - sharedVariableDescriptor, refConstructorCall + sharedVariableDescriptor, sharedVariableDescriptor.type.toIrType()!!, refConstructorCall ) } @@ -172,11 +167,12 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM initializer.startOffset, initializer.endOffset, elementPropertyDescriptor, IrGetValueImpl(initializer.startOffset, initializer.endOffset, sharedVariableDeclaration.symbol), - initializer + initializer, + originalDeclaration.type ) return IrCompositeImpl( - originalDeclaration.startOffset, originalDeclaration.endOffset, builtIns.unitType, null, + originalDeclaration.startOffset, originalDeclaration.endOffset, irBuiltIns.unitType, null, listOf(sharedVariableDeclaration, sharedVariableInitialization) ) } @@ -196,6 +192,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM originalGet.endOffset, sharedVariableSymbol ), + originalGet.type, originalGet.origin ) @@ -209,6 +206,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM sharedVariableSymbol ), originalSet.value, + originalSet.type, originalSet.origin ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt index ca7c9adaa29..19e8992440c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.intrinsics @@ -24,6 +13,7 @@ import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE @@ -42,8 +32,9 @@ class Equals(val operator: IElementType) : IntrinsicMethod() { val receiverAndArgs = expression.receiverAndArgs().apply { assert(size == 2) { "Equals expects 2 arguments, but ${joinToString()}" } } - var leftType = context.state.typeMapper.mapType(receiverAndArgs.first().type) - var rightType = context.state.typeMapper.mapType(receiverAndArgs.last().type) + + var leftType = context.state.typeMapper.mapType(receiverAndArgs.first().type.toKotlinType()) + var rightType = context.state.typeMapper.mapType(receiverAndArgs.last().type.toKotlinType()) if (isPrimitive(leftType) != isPrimitive(rightType)) { leftType = boxType(leftType) @@ -90,10 +81,10 @@ class Ieee754Equals(val operandType: Type) : IntrinsicMethod() { } } - val arg0Type = expression.getValueArgument(0)!!.type + val arg0Type = expression.getValueArgument(0)!!.type.toKotlinType() if (!arg0Type.isPrimitiveNumberOrNullableType()) throw AssertionError("Should be primitive or nullable primitive type: $arg0Type") - val arg1Type = expression.getValueArgument(1)!!.type + val arg1Type = expression.getValueArgument(1)!!.type.toKotlinType() if (!arg1Type.isPrimitiveNumberOrNullableType()) throw AssertionError("Should be primitive or nullable primitive type: $arg1Type") val arg0isNullable = arg0Type.isMarkedNullable diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IntrinsicMethod.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IntrinsicMethod.kt index 6a6580a1e91..4ac2a247bec 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IntrinsicMethod.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IntrinsicMethod.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.intrinsics @@ -21,6 +10,7 @@ import org.jetbrains.kotlin.codegen.Callable import org.jetbrains.kotlin.codegen.CallableMethod import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.Method @@ -41,11 +31,11 @@ abstract class IntrinsicMethod { companion object { fun calcReceiverType(call: IrMemberAccessExpression, context: JvmBackendContext): Type { - return context.state.typeMapper.mapType(call.dispatchReceiver?.type ?: call.extensionReceiver!!.type) + return context.state.typeMapper.mapType((call.dispatchReceiver?.type ?: call.extensionReceiver!!.type).toKotlinType()) } fun expressionType(expression: IrExpression, context: JvmBackendContext): Type { - return context.state.typeMapper.mapType(expression.type) + return context.state.typeMapper.mapType(expression.type.toKotlinType()) } fun JvmMethodSignature.newReturnType(type: Type): JvmMethodSignature { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IrIntrinsicFunction.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IrIntrinsicFunction.kt index a281b3850a9..d9ffb9346f5 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IrIntrinsicFunction.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IrIntrinsicFunction.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-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. */ @@ -16,6 +16,8 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.toIrType +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.calls.components.isVararg @@ -87,13 +89,13 @@ open class IrIntrinsicFunction( val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) + expression.descriptor.valueParameters.mapIndexed { i, descriptor -> expression.getValueArgument(i) ?: if (descriptor.isVararg) - IrEmptyVarargExpression(descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET) + IrEmptyVarargExpression(descriptor.type.toIrType()!!, UNDEFINED_OFFSET, UNDEFINED_OFFSET) else error("Unknown parameter: $descriptor in $expression") } args.forEachIndexed { i, irExpression -> if (irExpression is IrEmptyVarargExpression) { - val parameterType = codegen.typeMapper.mapType(irExpression.type) + val parameterType = codegen.typeMapper.mapType(irExpression.type.toKotlinType()) StackValue.operation(parameterType) { it.aconst(0) it.newarray(AsmUtil.correctElementType(parameterType)) @@ -160,5 +162,5 @@ fun IrMemberAccessExpression.receiverAndArgs(): List { } fun List.asmTypes(context: JvmBackendContext): List { - return map { context.state.typeMapper.mapType(it.type) } + return map { context.state.typeMapper.mapType(it.type.toKotlinType()) } } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IsArrayOf.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IsArrayOf.kt index 396f068d33f..e52f235bb8d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IsArrayOf.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IsArrayOf.kt @@ -1,23 +1,13 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.intrinsics import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.types.Variance @@ -33,7 +23,7 @@ class IsArrayOf : IntrinsicMethod() { } /*TODO original?*/ val elementType = expression.getTypeArgument(descriptor.original.typeParameters.first().index)!! - val arrayKtType = builtIns.getArrayType(Variance.INVARIANT, elementType) + val arrayKtType = builtIns.getArrayType(Variance.INVARIANT, elementType.toKotlinType()) val arrayType = typeMapper.mapType(arrayKtType) return IrIntrinsicFunction.create(expression, signature, context) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/NewArray.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/NewArray.kt index 2c6e3ad83ee..1f7f246ba0d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/NewArray.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/NewArray.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.intrinsics @@ -21,6 +10,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter @@ -31,7 +21,7 @@ class NewArray : IntrinsicMethod() { return object : IrIntrinsicFunction(expression, signature, context) { override fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue { super.invoke(v, codegen, data) - codegen.newArrayInstruction(ktType) + codegen.newArrayInstruction(ktType.toKotlinType()) return StackValue.onStack(returnType) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index f160ef665f3..43b5f53d5c8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -23,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.bridges.findInterfaceImplementation import org.jetbrains.kotlin.backend.common.bridges.generateBridgesForFunctionDescriptor import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.lower.irBlockBody -import org.jetbrains.kotlin.backend.common.lower.irIfThen import org.jetbrains.kotlin.backend.common.lower.irNot import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin @@ -53,11 +41,12 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl +import org.jetbrains.kotlin.ir.expressions.typeParametersCount import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl +import org.jetbrains.kotlin.ir.types.toIrType import org.jetbrains.kotlin.ir.util.createParameterDeclarations import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature -import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.* import org.jetbrains.kotlin.load.java.getOverriddenBuiltinReflectingJvmDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.getSourceFromDescriptor @@ -226,8 +215,10 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { val implementation = if (isSpecialBridge) delegateTo.copyAsDeclaration() else delegateTo.descriptor val call = IrCallImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, + implementation.returnType!!.toIrType()!!, implementation, - null, JvmLoweredStatementOrigin.BRIDGE_DELEGATION, + implementation.typeParametersCount, + JvmLoweredStatementOrigin.BRIDGE_DELEGATION, if (isStubDeclarationWithDelegationToSuper) getSuperClassDescriptor( descriptor.containingDeclaration as ClassDescriptor ) else null @@ -257,7 +248,7 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { ) ) } - +IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunction.symbol, call) + +IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunction.returnType, irFunction.symbol, call) }.apply { irFunction.body = this } @@ -292,7 +283,7 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { if (delegateParameterTypes == null || OBJECT_TYPE == delegateParameterTypes[i]) { irNotEquals(checkValue, irNull()) } else { - irIs(checkValue, overrideDescriptor.valueParameters[i].type) + irIs(checkValue, overrideDescriptor.valueParameters[i].type.toIrType()!!) } } @@ -301,21 +292,25 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { context.andand(arg, result) } - +irIfThen(irNot(condition), irBlock { + +irIfThen(context.irBuiltIns.unitType, irNot(condition), irBlock { +irReturn( when (typeSafeBarrierDescription) { - MAP_GET_OR_DEFAULT -> irGet(IrVariableSymbolImpl(bridgeDescriptor.valueParameters[1])) - BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.NULL -> irNull() - INDEX -> IrConstImpl.int( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.builtIns.intType, typeSafeBarrierDescription.defaultValue as Int + BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.MAP_GET_OR_DEFAULT -> irGet( + bridgeDescriptor.valueParameters[1].type.toIrType()!!, + IrVariableSymbolImpl( + bridgeDescriptor.valueParameters[1] + ) ) - FALSE -> irFalse() + BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.NULL -> irNull() + BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.INDEX -> IrConstImpl.int( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.intType, typeSafeBarrierDescription.defaultValue as Int + ) + BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.FALSE -> irFalse() } ) } ) } - } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt index 027787a811e..13dbe37331b 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -69,6 +58,7 @@ class ConstAndJvmFieldPropertiesLowering : IrElementTransformerVoid(), FileLower descriptor.correspondingProperty, expression.dispatchReceiver, expression.getValueArgument(descriptor.valueParameters.lastIndex)!!, + expression.type, expression.origin, expression.superQualifier ) @@ -80,6 +70,7 @@ class ConstAndJvmFieldPropertiesLowering : IrElementTransformerVoid(), FileLower expression.endOffset, descriptor.correspondingProperty, expression.dispatchReceiver, + expression.type, expression.origin, expression.superQualifier ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index dc28e2d56d6..606704e7c4e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -33,6 +22,8 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.types.toIrType +import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid @@ -61,14 +52,20 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { val typeSubstitutor = TypeSubstitutor.create(mapOf(typeParameter0.typeConstructor to TypeProjectionImpl(arrayElementType))) val substitutedArrayOfFun = unsubstitutedArrayOfFun.substitute(typeSubstitutor)!! - val typeArguments = mapOf(typeParameter0 to arrayElementType) val valueParameter0 = substitutedArrayOfFun.valueParameters[0] val arg0VarargType = valueParameter0.type val arg0VarargElementType = valueParameter0.varargElementType!! - val arg0 = IrVarargImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, arg0VarargType, arg0VarargElementType, arrayElements) + val arg0 = + IrVarargImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, arg0VarargType.toIrType()!!, arg0VarargElementType.toIrType()!!, arrayElements) - return IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, substitutedArrayOfFun, typeArguments).apply { + return IrCallImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + substitutedArrayOfFun.returnType!!.toIrType()!!, + substitutedArrayOfFun, + substitutedArrayOfFun.typeParametersCount + ).apply { putValueArgument(0, arg0) } } @@ -193,7 +190,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { return IrFieldImpl( enumEntry.startOffset, enumEntry.endOffset, JvmLoweredDeclarationOrigin.FIELD_FOR_ENUM_ENTRY, - fieldSymbol + fieldSymbol, enumEntry.initializerExpression!!.type ).also { it.initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!) enumEntryFields.add(it) @@ -227,15 +224,16 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { return IrFieldImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.FIELD_FOR_ENUM_VALUES, createSyntheticValuesFieldDescriptor(valuesArrayType), + valuesArrayType.toIrType()!!, IrExpressionBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irValuesInitializer) ).also { valuesField = it } } private fun createSyntheticValuesFieldInitializerExpression(): IrExpression = createArrayOfExpression( - irClass.defaultType, + irClass.defaultType.toKotlinType(), enumEntryFields.map { irField -> - IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irField.symbol) + IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irField.symbol, irField.symbol.owner.type) }) private fun createSyntheticValuesFieldDescriptor(valuesArrayType: SimpleType): PropertyDescriptorImpl { @@ -263,6 +261,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { val result = IrDelegatingConstructorCallImpl( startOffset, endOffset, + enumConstructorCall.symbol.owner.returnType, enumConstructorCall.symbol, enumConstructorCall.descriptor, enumConstructorCall.typeArgumentsCount @@ -298,6 +297,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { val result = IrDelegatingConstructorCallImpl( startOffset, endOffset, + loweredDelegatedConstructor.symbol.owner.returnType, loweredDelegatedConstructor.symbol, loweredDelegatedConstructor.descriptor, loweredDelegatedConstructor.typeParameters.size @@ -330,8 +330,8 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { val result = createConstructorCall(startOffset, endOffset, loweredConstructor) - result.putValueArgument(0, IrConstImpl.string(startOffset, endOffset, context.builtIns.stringType, name)) - result.putValueArgument(1, IrConstImpl.int(startOffset, endOffset, context.builtIns.intType, ordinal)) + result.putValueArgument(0, IrConstImpl.string(startOffset, endOffset, context.irBuiltIns.stringType, name)) + result.putValueArgument(1, IrConstImpl.int(startOffset, endOffset, context.irBuiltIns.intType, ordinal)) descriptor.valueParameters.forEach { valueParameter -> val i = valueParameter.index @@ -357,6 +357,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { IrDelegatingConstructorCallImpl( startOffset, endOffset, + loweredConstructor.symbol.owner.returnType, loweredConstructor.symbol, loweredConstructor.descriptor, loweredConstructor.typeParameters.size @@ -368,6 +369,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { IrCallImpl( startOffset, endOffset, + loweredConstructor.symbol.owner.returnType, loweredConstructor.symbol ) } @@ -468,27 +470,49 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { val substitutedValueOf = unsubstitutedValueOf.substitute(typeSubstitutor)!! val irValueOfCall = - IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, substitutedValueOf, mapOf(typeParameterT to enumClassType)) + IrCallImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + substitutedValueOf.returnType!!.toIrType()!!, + substitutedValueOf, + substitutedValueOf.typeParametersCount + ) irValueOfCall.putValueArgument( 0, IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valueOfFunction.valueParameters[0].symbol) ) return IrBlockBodyImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, - listOf(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valueOfFunction.symbol, irValueOfCall)) + listOf( + IrReturnImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + valueOfFunction.returnType, + valueOfFunction.symbol, + irValueOfCall + ) + ) ) } private fun createEnumValuesBody(valuesField: IrField): IrBody { - val cloneFun = valuesField.type.memberScope.findSingleFunction(Name.identifier("clone")) + val cloneFun = valuesField.type.toKotlinType().memberScope.findSingleFunction(Name.identifier("clone")) - val irCloneValues = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cloneFun).apply { - dispatchReceiver = IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valuesField.symbol) + val irCloneValues = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cloneFun.returnType!!.toIrType()!!, cloneFun, 0).apply { + dispatchReceiver = IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valuesField.symbol, valuesField.symbol.owner.type) } return IrBlockBodyImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, - listOf(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valuesFunction.symbol, irCloneValues)) + listOf( + IrReturnImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + valuesFunction.symbol.owner.returnType, + valuesFunction.symbol, + irCloneValues + ) + ) ) } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt index 4151e4c23cb..925f064883f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -34,6 +23,8 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl +import org.jetbrains.kotlin.ir.expressions.typeParametersCount +import org.jetbrains.kotlin.ir.types.toIrType import org.jetbrains.kotlin.ir.util.createParameterDeclarations import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid @@ -82,8 +73,23 @@ class InterfaceDelegationLowering(val state: GenerationState) : IrElementTransfo InterfaceLowering.createDefaultImplFunDescriptor(defaultImpls, interfaceFun.original, interfaceDescriptor, state.typeMapper) val irCallImpl = - IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, defaultImplFun, null, JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION) - irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunction.symbol, irCallImpl)) + IrCallImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + defaultImplFun.returnType!!.toIrType()!!, + defaultImplFun, + defaultImplFun.typeParametersCount, + JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION + ) + irBody.statements.add( + IrReturnImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + irFunction.symbol.owner.returnType, + irFunction.symbol, + irCallImpl + ) + ) var offset = 0 irFunction.dispatchReceiverParameter?.let { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt index 3f787f123ce..83c7271d164 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ObjectClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ObjectClassLowering.kt index a8d6fefd3cd..35f12aa2acb 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ObjectClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ObjectClassLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -20,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin +import org.jetbrains.kotlin.codegen.JvmCodegenUtil.isCompanionObjectInInterfaceNotIntrinsic import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET @@ -32,9 +22,10 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl -import org.jetbrains.kotlin.codegen.JvmCodegenUtil.isCompanionObjectInInterfaceNotIntrinsic import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.ir.util.isObject class ObjectClassLowering(val context: JvmBackendContext) : IrElementTransformerVoidWithContext(), FileLoweringPass { @@ -72,38 +63,42 @@ class ObjectClassLowering(val context: JvmBackendContext) : IrElementTransformer false ) as PropertyDescriptor privateInstance.name - val field = createInstanceFieldWithInitializer(IrFieldSymbolImpl(privateInstance), constructor, irClass) + val field = createInstanceFieldWithInitializer(IrFieldSymbolImpl(privateInstance), constructor, irClass, irClass.defaultType) createFieldWithCustomInitializer( publicInstance, - IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, field.symbol), - publicInstanceOwner + IrGetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, field.symbol, irClass.defaultType), + publicInstanceOwner, + irClass.defaultType ) } else { - createInstanceFieldWithInitializer(publicInstance, constructor, publicInstanceOwner) + createInstanceFieldWithInitializer(publicInstance, constructor, publicInstanceOwner, irClass.defaultType) } } private fun createInstanceFieldWithInitializer( fieldSymbol: IrFieldSymbol, constructor: ClassConstructorDescriptor, - instanceOwner: IrDeclarationContainer + instanceOwner: IrDeclarationContainer, + objectType: IrType ): IrField = createFieldWithCustomInitializer( fieldSymbol, - IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, constructor), - instanceOwner + IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, objectType, constructor, 0), + instanceOwner, + objectType ) private fun createFieldWithCustomInitializer( fieldSymbol: IrFieldSymbol, instanceInitializer: IrExpression, - instanceOwner: IrDeclarationContainer + instanceOwner: IrDeclarationContainer, + objectType: IrType ): IrField = IrFieldImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE, - fieldSymbol, - IrExpressionBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, instanceInitializer) + fieldSymbol, objectType ).also { + it.initializer = IrExpressionBodyImpl(instanceInitializer) pendingTransformations.add { instanceOwner.declarations.add(it) } } } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SingletonReferencesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SingletonReferencesLowering.kt index 5f3c7cb2239..5b2a13b10d0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SingletonReferencesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SingletonReferencesLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -33,11 +22,11 @@ class SingletonReferencesLowering(val context: JvmBackendContext) : BodyLowering override fun visitGetEnumValue(expression: IrGetEnumValue): IrExpression { val entrySymbol = context.descriptorsFactory.getSymbolForEnumEntry(expression.symbol) - return IrGetFieldImpl(expression.startOffset, expression.endOffset, entrySymbol) + return IrGetFieldImpl(expression.startOffset, expression.endOffset, entrySymbol, expression.type) } override fun visitGetObjectValue(expression: IrGetObjectValue): IrExpression { val instanceField = context.descriptorsFactory.getSymbolForObjectInstance(expression.symbol) - return IrGetFieldImpl(expression.startOffset, expression.endOffset, instanceField) + return IrGetFieldImpl(expression.startOffset, expression.endOffset, instanceField, expression.type) } } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index 6fb356f2bf4..4e5462e5b6f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * 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. + * Copyright 2010-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. */ package org.jetbrains.kotlin.backend.jvm.lower @@ -44,7 +33,9 @@ import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol +import org.jetbrains.kotlin.ir.types.toIrType import org.jetbrains.kotlin.ir.util.createParameterDeclarations +import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.ir.util.usesDefaultArguments import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.name.Name @@ -182,13 +173,16 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : FileLoweringPa IrDelegatingConstructorCallImpl( expression.startOffset, expression.endOffset, - accessorForIr as ClassConstructorDescriptor + expression.type, + accessorForIr as ClassConstructorDescriptor, + 0 ) else IrCallImpl( expression.startOffset, expression.endOffset, + expression.type, accessorForIr, - emptyMap(), + 0, expression.origin/*TODO super*/ ) //copyAllArgsToValueParams(call, expression) @@ -202,7 +196,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : FileLoweringPa IrConstImpl.constNull( UNDEFINED_OFFSET, UNDEFINED_OFFSET, - context.ir.symbols.defaultConstructorMarker.descriptor.defaultType + context.ir.symbols.defaultConstructorMarker.owner.defaultType ) ) } @@ -251,18 +245,23 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : FileLoweringPa val calleeDescriptor = accessor.calleeDescriptor as FunctionDescriptor val delegationCall = if (!isConstructor) - IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, calleeDescriptor) - else IrDelegatingConstructorCallImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, - createFunctionSymbol(accessor.calleeDescriptor) as IrConstructorSymbol, - accessor.calleeDescriptor as ClassConstructorDescriptor - ) + IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, calleeDescriptor.returnType!!.toIrType()!!, calleeDescriptor, 0) + else { + val delegationConstructor = createFunctionSymbol(accessor.calleeDescriptor) + IrDelegatingConstructorCallImpl( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, + delegationConstructor.owner.returnType, + delegationConstructor as IrConstructorSymbol, + accessor.calleeDescriptor as ClassConstructorDescriptor + ) + } copyAllArgsToValueParams(delegationCall, syntheticFunction) body.statements.add( if (isConstructor) delegationCall else IrReturnImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, + syntheticFunction.returnType, syntheticFunction.symbol, delegationCall )