mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
IR: fix compiler warnings
This commit is contained in:
@@ -271,25 +271,25 @@ internal abstract class HeaderInfoBuilder(context: CommonBackendContext, private
|
||||
override fun visitElement(element: IrElement, data: IrCall?): HeaderInfo? = null
|
||||
|
||||
/** Builds a [HeaderInfo] for iterable expressions that are calls (e.g., `.reversed()`, `.indices`. */
|
||||
override fun visitCall(iterable: IrCall, iteratorCall: IrCall?): HeaderInfo? {
|
||||
override fun visitCall(expression: IrCall, data: IrCall?): HeaderInfo? {
|
||||
// Return the HeaderInfo from the first successful match.
|
||||
// First, try to match a `reversed()` or `withIndex()` call.
|
||||
val callHeaderInfo = callHandlers.firstNotNullResult { it.handle(iterable, iteratorCall, null, scopeOwnerSymbol()) }
|
||||
val callHeaderInfo = callHandlers.firstNotNullResult { it.handle(expression, data, null, scopeOwnerSymbol()) }
|
||||
if (callHeaderInfo != null)
|
||||
return callHeaderInfo
|
||||
|
||||
// Try to match a call to build a progression (e.g., `.indices`, `downTo`).
|
||||
val progressionType = ProgressionType.fromIrType(iterable.type, symbols)
|
||||
val progressionType = ProgressionType.fromIrType(expression.type, symbols)
|
||||
val progressionHeaderInfo =
|
||||
progressionType?.run { progressionHandlers.firstNotNullResult { it.handle(iterable, iteratorCall, this, scopeOwnerSymbol()) } }
|
||||
progressionType?.run { progressionHandlers.firstNotNullResult { it.handle(expression, data, this, scopeOwnerSymbol()) } }
|
||||
|
||||
return progressionHeaderInfo ?: super.visitCall(iterable, iteratorCall)
|
||||
return progressionHeaderInfo ?: super.visitCall(expression, data)
|
||||
}
|
||||
|
||||
/** Builds a [HeaderInfo] for iterable expressions not handled in [visitCall]. */
|
||||
override fun visitExpression(iterable: IrExpression, iteratorCall: IrCall?): HeaderInfo? {
|
||||
return expressionHandlers.firstNotNullResult { it.handle(iterable, iteratorCall, null, scopeOwnerSymbol()) }
|
||||
?: super.visitExpression(iterable, iteratorCall)
|
||||
override fun visitExpression(expression: IrExpression, data: IrCall?): HeaderInfo? {
|
||||
return expressionHandlers.firstNotNullResult { it.handle(expression, data, null, scopeOwnerSymbol()) }
|
||||
?: super.visitExpression(expression, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,4 +339,4 @@ internal class NestedHeaderInfoBuilderForWithIndex(context: CommonBackendContext
|
||||
DefaultIterableHandler(context),
|
||||
DefaultSequenceHandler(context),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ fun <Data, Context> makeVerifyAction(verifier: (Context, Data) -> Unit): Action<
|
||||
verifier(context, data)
|
||||
}
|
||||
|
||||
fun dumpIrElement(actionState: ActionState, data: IrElement, context: Any?): String {
|
||||
fun dumpIrElement(actionState: ActionState, data: IrElement, @Suppress("UNUSED_PARAMETER") context: Any?): String {
|
||||
val beforeOrAfterStr = actionState.beforeOrAfter.name.toLowerCaseAsciiOnly()
|
||||
|
||||
var dumpText: String = ""
|
||||
|
||||
@@ -161,7 +161,7 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis
|
||||
private var restricted: Boolean = false
|
||||
private var declarationListsRestricted = false
|
||||
|
||||
private inline fun <T> (() -> T).withRestrictions(
|
||||
private fun <T> (() -> T).withRestrictions(
|
||||
newRestrictedToDeclaration: IrDeclaration? = null,
|
||||
newBodiesEnabled: Boolean? = null,
|
||||
newRestricted: Boolean? = null,
|
||||
|
||||
@@ -140,7 +140,7 @@ class ExportModelGenerator(val context: JsIrBackendContext) {
|
||||
klass: IrClass
|
||||
): ExportedDeclaration? {
|
||||
when (val exportability = classExportability(klass)) {
|
||||
is Exportability.Prohibited -> return error(exportability.reason)
|
||||
is Exportability.Prohibited -> error(exportability.reason)
|
||||
is Exportability.NotNeeded -> return null
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
||||
fun build(): Pair<IrClass, IrConstructor> {
|
||||
val clazz = buildReferenceClass()
|
||||
val ctor = createConstructor(clazz)
|
||||
val invoke = createInvokeMethod(clazz)
|
||||
createInvokeMethod(clazz)
|
||||
createNameProperty(clazz)
|
||||
// TODO: create name property for KFunction*
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class EnumUsageLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
override fun visitGetEnumValue(expression: IrGetEnumValue): IrExpression {
|
||||
val enumEntry = expression.symbol.owner
|
||||
val klass = enumEntry.parent as IrClass
|
||||
return if (klass.isExternal) lowerExternalEnumEntry(enumEntry, klass) else lowerEnumEntry(enumEntry, klass)
|
||||
return if (klass.isExternal) lowerExternalEnumEntry(enumEntry, klass) else lowerEnumEntry(enumEntry)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class EnumUsageLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
}
|
||||
}
|
||||
|
||||
private fun lowerEnumEntry(enumEntry: IrEnumEntry, klass: IrClass) =
|
||||
private fun lowerEnumEntry(enumEntry: IrEnumEntry) =
|
||||
enumEntry.getInstanceFun!!.run { JsIrBuilder.buildCall(symbol) }
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ class EnumEntryInstancesBodyLowering(val context: JsIrBackendContext) : BodyLowe
|
||||
val index = (irBody as IrBlockBody).statements
|
||||
.indexOfFirst { it is IrTypeOperatorCall && it.argument is IrDelegatingConstructorCall } + 1
|
||||
|
||||
(irBody as IrBlockBody).statements.add(index, context.createIrBuilder(container.symbol).run {
|
||||
irBody.statements.add(index, context.createIrBuilder(container.symbol).run {
|
||||
irSetField(null, entry.correspondingField!!, irGet(entryClass.thisReceiver!!))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
||||
|
||||
protected abstract fun IrBlockBodyBuilder.generateCoroutineStart(invokeSuspendFunction: IrFunction, receiver: IrExpression)
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
protected fun initializeStateMachine(coroutineConstructors: List<IrConstructor>, coroutineClassThis: IrValueDeclaration) {
|
||||
// Do nothing by default
|
||||
// TODO find out if Kotlin/Native needs this method.
|
||||
|
||||
@@ -187,7 +187,7 @@ class JsIntrinsicTransformers(backendContext: JsIrBackendContext) {
|
||||
}
|
||||
|
||||
add(intrinsics.jsBoxIntrinsic) { call, context ->
|
||||
val arg = translateCallArguments(call as IrCall, context).single()
|
||||
val arg = translateCallArguments(call, context).single()
|
||||
val inlineClass = call.getTypeArgument(0)!!.getInlinedClass()!!
|
||||
val constructor = inlineClass.declarations.filterIsInstance<IrConstructor>().single { it.isPrimary }
|
||||
JsNew(context.getNameForConstructor(constructor).makeRef(), listOf(arg))
|
||||
|
||||
@@ -324,9 +324,6 @@ class NameTables(
|
||||
return sanitizeName(field.name.asString()) + "__error"
|
||||
}
|
||||
|
||||
require(name != null) {
|
||||
"Can't find name for member field ${field.render()}"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -340,10 +337,6 @@ class NameTables(
|
||||
return sanitizeName(function.name.asString()) + "__error" // TODO one case is a virtual method of an abstract class with no implementation
|
||||
}
|
||||
|
||||
// TODO report backend error
|
||||
require(name != null) {
|
||||
"Can't find name for member function ${function.render()}"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
@@ -631,6 +631,7 @@ class ExpressionCodegen(
|
||||
|
||||
private fun handlePlusMinus(expression: IrSetVariable, value: IrExpression?, isMinus: Boolean): Boolean {
|
||||
if (value is IrConst<*> && value.kind == IrConstKind.Int) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val delta = (value as IrConst<Int>).value
|
||||
val upperBound = Byte.MAX_VALUE.toInt() + (if (isMinus) 1 else 0)
|
||||
val lowerBound = Byte.MIN_VALUE.toInt() + (if (isMinus) 1 else 0)
|
||||
|
||||
@@ -249,7 +249,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
||||
return
|
||||
}
|
||||
|
||||
SamEqualsHashCodeMethodsGenerator(backendContext, functionReferenceClass, samSuperType) { receiver ->
|
||||
SamEqualsHashCodeMethodsGenerator(backendContext, functionReferenceClass, samSuperType) {
|
||||
val internalClass = when {
|
||||
isAdaptedReference -> backendContext.ir.symbols.adaptedFunctionReference
|
||||
else -> backendContext.ir.symbols.functionReferenceImpl
|
||||
|
||||
@@ -78,25 +78,25 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
|
||||
// in another class then the one it is nested under in the IR.
|
||||
// TODO: Loosen this up for local functions for lambdas passed as an inline lambda
|
||||
// argument to an inline function. In that case the code does end up in the current class.
|
||||
override fun visitFunction(declaration: IrFunction, currentClass: IrClass?): IrStatement {
|
||||
override fun visitFunction(declaration: IrFunction, data: IrClass?): IrStatement {
|
||||
val codeMightBeGeneratedInDifferentClass = declaration.isSuspend ||
|
||||
declaration.isInline ||
|
||||
declaration.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||
declaration.transformChildren(this, currentClass.takeUnless { codeMightBeGeneratedInDifferentClass })
|
||||
declaration.transformChildren(this, data.takeUnless { codeMightBeGeneratedInDifferentClass })
|
||||
return declaration
|
||||
}
|
||||
|
||||
override fun visitCall(expression: IrCall, currentClass: IrClass?): IrExpression {
|
||||
expression.transformChildren(this, currentClass)
|
||||
override fun visitCall(expression: IrCall, data: IrClass?): IrExpression {
|
||||
expression.transformChildren(this, data)
|
||||
|
||||
removeIntTypeSafeCastsForEquality(expression)
|
||||
|
||||
if (expression.symbol.owner.origin == IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR) {
|
||||
if (currentClass == null) return expression
|
||||
if (data == null) return expression
|
||||
val simpleFunction = (expression.symbol.owner as? IrSimpleFunction) ?: return expression
|
||||
val property = simpleFunction.correspondingPropertySymbol?.owner ?: return expression
|
||||
if (property.isLateinit) return expression
|
||||
return optimizePropertyAccess(expression, simpleFunction, property, currentClass)
|
||||
return optimizePropertyAccess(expression, simpleFunction, property, data)
|
||||
}
|
||||
|
||||
if (isNegation(expression, context) && isNegation(expression.dispatchReceiver!!, context)) {
|
||||
@@ -185,9 +185,9 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
|
||||
return expression
|
||||
}
|
||||
|
||||
override fun visitWhen(expression: IrWhen, currentClass: IrClass?): IrExpression {
|
||||
override fun visitWhen(expression: IrWhen, data: IrClass?): IrExpression {
|
||||
val isCompilerGenerated = expression.origin == null
|
||||
expression.transformChildren(this, currentClass)
|
||||
expression.transformChildren(this, data)
|
||||
// Remove all branches with constant false condition.
|
||||
expression.branches.removeIf {
|
||||
it.condition.isFalseConst() && isCompilerGenerated
|
||||
@@ -329,19 +329,19 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBlockBody(body: IrBlockBody, currentClass: IrClass?): IrBody {
|
||||
body.transformChildren(this, currentClass)
|
||||
override fun visitBlockBody(body: IrBlockBody, data: IrClass?): IrBody {
|
||||
body.transformChildren(this, data)
|
||||
removeUnnecessaryTemporaryVariables(body.statements)
|
||||
return body
|
||||
}
|
||||
|
||||
override fun visitContainerExpression(expression: IrContainerExpression, currentClass: IrClass?): IrExpression {
|
||||
expression.transformChildren(this, currentClass)
|
||||
override fun visitContainerExpression(expression: IrContainerExpression, data: IrClass?): IrExpression {
|
||||
expression.transformChildren(this, data)
|
||||
removeUnnecessaryTemporaryVariables(expression.statements)
|
||||
return expression
|
||||
}
|
||||
|
||||
override fun visitGetValue(expression: IrGetValue, currentClass: IrClass?): IrExpression {
|
||||
override fun visitGetValue(expression: IrGetValue, data: IrClass?): IrExpression {
|
||||
// Replace IrGetValue of an immutable temporary variable with a constant
|
||||
// initializer with the constant initializer.
|
||||
val variable = expression.symbol.owner
|
||||
|
||||
@@ -9,9 +9,7 @@ import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsSharedVariablesManager
|
||||
@@ -21,19 +19,17 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class WasmBackendContext(
|
||||
val module: ModuleDescriptor,
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
symbolTable: SymbolTable,
|
||||
irModuleFragment: IrModuleFragment,
|
||||
@Suppress("UNUSED_PARAMETER") symbolTable: SymbolTable,
|
||||
@Suppress("UNUSED_PARAMETER") irModuleFragment: IrModuleFragment,
|
||||
val additionalExportedDeclarations: Set<FqName>,
|
||||
override val configuration: CompilerConfiguration
|
||||
) : JsCommonBackendContext {
|
||||
@@ -81,4 +77,4 @@ class WasmBackendContext(
|
||||
/*TODO*/
|
||||
print(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ class ExpressionTransformer : BaseTransformer<WasmInstruction, WasmCodegenContex
|
||||
|
||||
override fun visitTypeOperator(expression: IrTypeOperatorCall, data: WasmCodegenContext): WasmInstruction {
|
||||
val wasmArgument = expressionToWasmInstruction(expression.argument, data)
|
||||
when (expression.operator) {
|
||||
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> return wasmArgument
|
||||
if (expression.operator == IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) {
|
||||
return wasmArgument
|
||||
}
|
||||
TODO("IrTypeOperatorCall:\n ${expression.dump()}")
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ private fun StatementGenerator.generateReceiverForCalleeImportedFromObject(
|
||||
private fun StatementGenerator.generateVarargExpressionUsing(
|
||||
varargArgument: VarargValueArgument,
|
||||
valueParameter: ValueParameterDescriptor,
|
||||
resolvedCall: ResolvedCall<*>, // TODO resolvedCall is required for suspend conversions, see KT-38604
|
||||
@Suppress("UNUSED_PARAMETER") resolvedCall: ResolvedCall<*>, // TODO resolvedCall is required for suspend conversions, see KT-38604
|
||||
generateArgumentExpression: (KtExpression) -> IrExpression?
|
||||
): IrExpression? {
|
||||
if (varargArgument.arguments.isEmpty()) {
|
||||
|
||||
@@ -74,6 +74,7 @@ interface PersistentIrElementBase<T : Carrier> : IrElement, Carrier {
|
||||
|
||||
fun ensureLowered()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun getCarrier(): T {
|
||||
stageController.currentStage.let { stage ->
|
||||
ensureLowered()
|
||||
@@ -104,6 +105,7 @@ interface PersistentIrElementBase<T : Carrier> : IrElement, Carrier {
|
||||
}
|
||||
|
||||
// TODO naming? e.g. `mutableCarrier`
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun setCarrier(): T {
|
||||
val stage = stageController.currentStage
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrClass.createMembers(isK: Boolean, isSuspend: Boolean, arity: Int, name: String, descriptorFactory: FunctionDescriptorFactory) {
|
||||
private fun IrClass.createMembers(isK: Boolean, isSuspend: Boolean, descriptorFactory: FunctionDescriptorFactory) {
|
||||
if (!isK) {
|
||||
val invokeSymbol = descriptorFactory.memberDescriptor("invoke") {
|
||||
val returnType = with(IrSimpleTypeBuilder()) {
|
||||
@@ -461,7 +461,7 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa
|
||||
klass.parent = packageFragment
|
||||
packageFragment.declarations += klass
|
||||
|
||||
klass.createMembers(isK, isSuspend, n, klass.name.identifier, descriptorFactory)
|
||||
klass.createMembers(isK, isSuspend, descriptorFactory)
|
||||
|
||||
return klass
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class DumpIrTreeVisitor(
|
||||
}
|
||||
|
||||
private fun IrMemberAccessExpression<*>.getTypeParameterNames(expectedCount: Int): List<String> =
|
||||
if (this is IrDeclarationReference && symbol.isBound)
|
||||
if (symbol.isBound)
|
||||
symbol.owner.getTypeParameterNames(expectedCount)
|
||||
else
|
||||
getPlaceholderParameterNames(expectedCount)
|
||||
|
||||
@@ -206,7 +206,9 @@ class SymbolTable(
|
||||
}
|
||||
} else {
|
||||
if (d.isBound()) {
|
||||
((d.owner as? IrSymbolDeclaration<*>)?.symbol ?: descriptorToSymbol[d]) as S?
|
||||
val result = (d.owner as? IrSymbolDeclaration<*>)?.symbol ?: descriptorToSymbol[d]
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
result as S?
|
||||
} else {
|
||||
descriptorToSymbol[d]
|
||||
}
|
||||
|
||||
@@ -11,13 +11,12 @@ dependencies {
|
||||
compile(project(":compiler:serialization"))
|
||||
compile(project(":kotlin-util-klib"))
|
||||
compile(project(":kotlin-util-klib-metadata"))
|
||||
|
||||
compile(project(":compiler:util"))
|
||||
compile(project(":compiler:ir.psi2ir"))
|
||||
compile(project(":compiler:ir.backend.common"))
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -29,7 +28,7 @@ tasks {
|
||||
val compileKotlin by existing(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += "-Xopt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI"
|
||||
freeCompilerArgs += "-Xinline-classes"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ class IrOverridingUtil(
|
||||
fun buildFakeOverridesForClass(clazz: IrClass) {
|
||||
val superTypes = allPublicApiSuperTypesOrAny(clazz)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val fromCurrent = clazz.declarations.filter { it is IrOverridableMember && it.symbol.isPublicApi } as List<IrOverridableMember>
|
||||
|
||||
val allFromSuper = superTypes.flatMap { superType ->
|
||||
@@ -190,10 +191,7 @@ class IrOverridingUtil(
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterVisibleFakeOverrides(
|
||||
current: IrClass,
|
||||
toFilter: Collection<IrOverridableMember>
|
||||
): Collection<IrOverridableMember> {
|
||||
private fun filterVisibleFakeOverrides(toFilter: Collection<IrOverridableMember>): Collection<IrOverridableMember> {
|
||||
return toFilter.filter { member: IrOverridableMember ->
|
||||
!Visibilities.isPrivate(member.visibility)
|
||||
}
|
||||
@@ -296,7 +294,7 @@ class IrOverridingUtil(
|
||||
overridables: Collection<IrOverridableMember>,
|
||||
current: IrClass
|
||||
) {
|
||||
val effectiveOverridden = filterVisibleFakeOverrides(current, overridables)
|
||||
val effectiveOverridden = filterVisibleFakeOverrides(overridables)
|
||||
|
||||
// The descriptor based algorithm goes further building invisible fakes here,
|
||||
// but we don't use invisible fakes in IR
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.common.overrides
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.parents
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithVisibility
|
||||
import org.jetbrains.kotlin.ir.declarations.IrOverridableMember
|
||||
import org.jetbrains.kotlin.ir.util.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
|
||||
// The contents of this file is from VisibilityUtil.kt adapted to IR.
|
||||
// TODO: The code would better be commonized for descriptors, ir and fir.
|
||||
|
||||
fun isVisibleForOverride(
|
||||
overriding: IrOverridableMember,
|
||||
@Suppress("UNUSED_PARAMETER") overriding: IrOverridableMember,
|
||||
fromSuper: IrOverridableMember
|
||||
): Boolean {
|
||||
return !Visibilities.isPrivate((fromSuper as IrDeclarationWithVisibility).visibility)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalUnsignedTypes::class)
|
||||
@file:Suppress("NAME_SHADOWING")
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ class ExpectActualTable(val expectDescriptorToSymbol: MutableMap<DeclarationDesc
|
||||
}
|
||||
|
||||
val expects: List<MemberDescriptor> = if (descriptor is ClassConstructorDescriptor && descriptor.isPrimary) {
|
||||
(descriptor.containingDeclaration.findExpects() as List<ClassDescriptor>).map {
|
||||
it.unsubstitutedPrimaryConstructor
|
||||
}.filterNotNull()
|
||||
descriptor.containingDeclaration.findExpects().mapNotNull {
|
||||
(it as ClassDescriptor).unsubstitutedPrimaryConstructor
|
||||
}
|
||||
} else {
|
||||
descriptor.findExpects()
|
||||
}
|
||||
|
||||
@@ -435,7 +435,6 @@ abstract class IrFileDeserializer(
|
||||
proto: ProtoEnumConstructorCall,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
): IrEnumConstructorCall {
|
||||
val symbol = deserializeIrSymbolAndRemap(proto.symbol) as IrConstructorSymbol
|
||||
val call = IrEnumConstructorCallImpl(
|
||||
@@ -587,7 +586,7 @@ abstract class IrFileDeserializer(
|
||||
return callable
|
||||
}
|
||||
|
||||
private fun deserializeReturn(proto: ProtoReturn, start: Int, end: Int, type: IrType): IrReturn {
|
||||
private fun deserializeReturn(proto: ProtoReturn, start: Int, end: Int): IrReturn {
|
||||
val symbol = deserializeIrSymbolAndRemap(proto.returnTarget) as IrReturnTargetSymbol
|
||||
val value = deserializeExpression(proto.value)
|
||||
return IrReturnImpl(start, end, builtIns.nothingType, symbol, value)
|
||||
@@ -631,7 +630,7 @@ abstract class IrFileDeserializer(
|
||||
return IrStringConcatenationImpl(start, end, type, arguments)
|
||||
}
|
||||
|
||||
private fun deserializeThrow(proto: ProtoThrow, start: Int, end: Int, type: IrType): IrThrowImpl {
|
||||
private fun deserializeThrow(proto: ProtoThrow, start: Int, end: Int): IrThrowImpl {
|
||||
return IrThrowImpl(start, end, builtIns.nothingType, deserializeExpression(proto.value))
|
||||
}
|
||||
|
||||
@@ -868,7 +867,7 @@ abstract class IrFileDeserializer(
|
||||
CONTINUE -> deserializeContinue(proto.`continue`, start, end, type)
|
||||
DELEGATING_CONSTRUCTOR_CALL -> deserializeDelegatingConstructorCall(proto.delegatingConstructorCall, start, end)
|
||||
DO_WHILE -> deserializeDoWhile(proto.doWhile, start, end, type)
|
||||
ENUM_CONSTRUCTOR_CALL -> deserializeEnumConstructorCall(proto.enumConstructorCall, start, end, type)
|
||||
ENUM_CONSTRUCTOR_CALL -> deserializeEnumConstructorCall(proto.enumConstructorCall, start, end)
|
||||
FUNCTION_REFERENCE -> deserializeFunctionReference(proto.functionReference, start, end, type)
|
||||
GET_ENUM_VALUE -> deserializeGetEnumValue(proto.getEnumValue, start, end, type)
|
||||
GET_CLASS -> deserializeGetClass(proto.getClass, start, end, type)
|
||||
@@ -878,11 +877,11 @@ abstract class IrFileDeserializer(
|
||||
LOCAL_DELEGATED_PROPERTY_REFERENCE -> deserializeIrLocalDelegatedPropertyReference(proto.localDelegatedPropertyReference, start, end, type)
|
||||
INSTANCE_INITIALIZER_CALL -> deserializeInstanceInitializerCall(proto.instanceInitializerCall, start, end)
|
||||
PROPERTY_REFERENCE -> deserializePropertyReference(proto.propertyReference, start, end, type)
|
||||
RETURN -> deserializeReturn(proto.`return`, start, end, type)
|
||||
RETURN -> deserializeReturn(proto.`return`, start, end)
|
||||
SET_FIELD -> deserializeSetField(proto.setField, start, end)
|
||||
SET_VARIABLE -> deserializeSetVariable(proto.setVariable, start, end)
|
||||
STRING_CONCAT -> deserializeStringConcat(proto.stringConcat, start, end, type)
|
||||
THROW -> deserializeThrow(proto.`throw`, start, end, type)
|
||||
THROW -> deserializeThrow(proto.`throw`, start, end)
|
||||
TRY -> deserializeTry(proto.`try`, start, end, type)
|
||||
TYPE_OP -> deserializeTypeOp(proto.typeOp, start, end, type)
|
||||
VARARG -> deserializeVararg(proto.vararg, start, end, type)
|
||||
|
||||
@@ -145,12 +145,12 @@ abstract class KlibMetadataSerializer(
|
||||
|
||||
protected fun serializeDescriptors(
|
||||
fqName: FqName,
|
||||
classifierDescriptors: List<DeclarationDescriptor>,
|
||||
topLevelDescriptors: List<DeclarationDescriptor>
|
||||
allClassifierDescriptors: List<DeclarationDescriptor>,
|
||||
allTopLevelDescriptors: List<DeclarationDescriptor>
|
||||
): List<ProtoBuf.PackageFragment> {
|
||||
|
||||
val classifierDescriptors = classifierDescriptors.filterOutExpects()
|
||||
val topLevelDescriptors = topLevelDescriptors.filterOutExpects()
|
||||
val classifierDescriptors = allClassifierDescriptors.filterOutExpects()
|
||||
val topLevelDescriptors = allTopLevelDescriptors.filterOutExpects()
|
||||
|
||||
if (TOP_LEVEL_CLASS_DECLARATION_COUNT_PER_FILE == null &&
|
||||
TOP_LEVEL_DECLARATION_COUNT_PER_FILE == null) {
|
||||
|
||||
@@ -158,7 +158,7 @@ fun generateKLib(
|
||||
deserializeFakeOverrides
|
||||
)
|
||||
|
||||
val deserializedModuleFragments = sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map {
|
||||
sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map {
|
||||
irLinker.deserializeOnlyHeaderModule(depsDescriptors.getModuleDescriptor(it), it)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ class IrLibraryLayoutImpl(klib: File, component: String) : KotlinLibraryLayoutIm
|
||||
FromZipIrLibraryImpl(this, zipFileSystem)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
open class BaseLibraryAccess<L : KotlinLibraryLayout>(val klib: File, component: String?) {
|
||||
open val layout = KotlinLibraryLayoutImpl(klib, component)
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.android.synthetic.res
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
@@ -145,7 +144,8 @@ abstract class AndroidLayoutXmlFileManager(val project: Project) {
|
||||
|
||||
companion object {
|
||||
fun getInstance(module: Module): AndroidLayoutXmlFileManager? {
|
||||
val service = ModuleServiceManager.getService(module, AndroidLayoutXmlFileManager::class.java)
|
||||
@Suppress("DEPRECATION")
|
||||
val service = com.intellij.openapi.module.ModuleServiceManager.getService(module, AndroidLayoutXmlFileManager::class.java)
|
||||
return service ?: module.getComponent(AndroidLayoutXmlFileManager::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ interface IrBuilderExtension {
|
||||
irInvoke(
|
||||
dispatchReceiver,
|
||||
callee,
|
||||
args = *valueArguments.toTypedArray(),
|
||||
args = valueArguments.toTypedArray(),
|
||||
typeHint = returnTypeHint
|
||||
).also { call -> typeArguments.forEachIndexed(call::putTypeArgument) }
|
||||
|
||||
@@ -500,11 +500,10 @@ interface IrBuilderExtension {
|
||||
property.type,
|
||||
genericIndex = property.genericIndex
|
||||
)
|
||||
?.let { expr -> wrapWithNullableSerializerIfNeeded(property.module, property.type, expr, nullableSerClass) }
|
||||
?.let { expr -> wrapWithNullableSerializerIfNeeded(property.type, expr, nullableSerClass) }
|
||||
}
|
||||
|
||||
private fun IrBuilderWithScope.wrapWithNullableSerializerIfNeeded(
|
||||
module: ModuleDescriptor,
|
||||
type: KotlinType,
|
||||
expression: IrExpression,
|
||||
nullableSerializerClass: IrClassSymbol
|
||||
@@ -582,7 +581,7 @@ interface IrBuilderExtension {
|
||||
type.genericIndex,
|
||||
genericGetter
|
||||
) ?: return null
|
||||
return wrapWithNullableSerializerIfNeeded(module, type, expr, nullableSerClass)
|
||||
return wrapWithNullableSerializerIfNeeded(type, expr, nullableSerClass)
|
||||
}
|
||||
|
||||
var serializerClass = serializerClassOriginal
|
||||
@@ -661,7 +660,7 @@ interface IrBuilderExtension {
|
||||
(genericType.constructor.declarationDescriptor as TypeParameterDescriptor).representativeUpperBound
|
||||
)!!
|
||||
}!!
|
||||
wrapWithNullableSerializerIfNeeded(module, type, expr, nullableSerClass)
|
||||
wrapWithNullableSerializerIfNeeded(type, expr, nullableSerClass)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.js.backend.ast.JsNameRef
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsReturn
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.declaration.DeclarationBodyVisitor
|
||||
import org.jetbrains.kotlin.psi.KtPureClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCompanionCodegen
|
||||
import org.jetbrains.kotlinx.serialization.compiler.backend.common.findTypeSerializer
|
||||
@@ -62,7 +61,7 @@ class SerializableCompanionJsTranslator(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun translate(declaration: KtPureClassOrObject, descriptor: ClassDescriptor, translator: DeclarationBodyVisitor, context: TranslationContext) {
|
||||
fun translate(descriptor: ClassDescriptor, translator: DeclarationBodyVisitor, context: TranslationContext) {
|
||||
val serializableClass = getSerializableClassDescriptorByCompanion(descriptor) ?: return
|
||||
if (serializableClass.shouldHaveGeneratedMethodsInCompanion)
|
||||
SerializableCompanionJsTranslator(descriptor, translator, context).generate()
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.declaration.DeclarationBodyVisitor
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||
@@ -160,7 +159,6 @@ class SerializableJsTranslator(
|
||||
fun translate(
|
||||
declaration: KtPureClassOrObject,
|
||||
serializableClass: ClassDescriptor,
|
||||
translator: DeclarationBodyVisitor,
|
||||
context: TranslationContext
|
||||
) {
|
||||
if (serializableClass.isInternalSerializable)
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtPureClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen
|
||||
import org.jetbrains.kotlinx.serialization.compiler.backend.common.getSerialTypeInfo
|
||||
import org.jetbrains.kotlinx.serialization.compiler.resolve.*
|
||||
@@ -362,7 +361,6 @@ open class SerializerJsTranslator(
|
||||
|
||||
companion object {
|
||||
fun translate(
|
||||
declaration: KtPureClassOrObject,
|
||||
descriptor: ClassDescriptor,
|
||||
translator: DeclarationBodyVisitor,
|
||||
context: TranslationContext
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.jetbrains.kotlinx.serialization.compiler.backend.js.SerializerJsTrans
|
||||
|
||||
open class SerializationJsExtension: JsSyntheticTranslateExtension {
|
||||
override fun generateClassSyntheticParts(declaration: KtPureClassOrObject, descriptor: ClassDescriptor, translator: DeclarationBodyVisitor, context: TranslationContext) {
|
||||
SerializerJsTranslator.translate(declaration, descriptor, translator, context)
|
||||
SerializableJsTranslator.translate(declaration, descriptor, translator, context)
|
||||
SerializableCompanionJsTranslator.translate(declaration, descriptor, translator, context)
|
||||
SerializerJsTranslator.translate(descriptor, translator, context)
|
||||
SerializableJsTranslator.translate(declaration, descriptor, context)
|
||||
SerializableCompanionJsTranslator.translate(descriptor, translator, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user