Fix minor compile warnings

This commit is contained in:
Dmitry Gridin
2019-04-17 17:48:26 +07:00
parent 79793a4bda
commit 37c856290f
226 changed files with 618 additions and 479 deletions
@@ -121,7 +121,7 @@ abstract class IrElementVisitorVoidWithContext : IrElementVisitorVoid {
}
override final fun visitField(declaration: IrField) {
val isDelegated = declaration.descriptor.isDelegated
@Suppress("DEPRECATION") val isDelegated = declaration.descriptor.isDelegated
if (isDelegated) scopeStack.push(ScopeWithIr(Scope(declaration.symbol), declaration))
visitFieldNew(declaration)
if (isDelegated) scopeStack.pop()
@@ -19,7 +19,9 @@ package org.jetbrains.kotlin.backend.common.ir
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
import org.jetbrains.kotlin.backend.common.descriptors.*
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.Scope
@@ -43,7 +45,6 @@ import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import java.io.StringWriter
@@ -160,7 +161,6 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
shift: Int = 0,
origin: IrDeclarationOrigin = this.origin
): IrTypeParameter {
val source = parent as IrTypeParametersContainer
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
val symbol = IrTypeParameterSymbolImpl(descriptor)
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also { copied ->
@@ -240,7 +240,8 @@ fun IrFunction.copyValueParametersToStatic(
)
)
}
source.valueParameters.forEachIndexed { i, oldValueParameter ->
for (oldValueParameter in source.valueParameters) {
target.valueParameters.add(
oldValueParameter.copyTo(
target,
@@ -345,6 +346,7 @@ fun IrClass.createImplicitParameterDeclarationWithWrappedDescriptor() {
assert(descriptor.declaredTypeParameters.isEmpty())
}
@Suppress("UNCHECKED_CAST")
fun isElseBranch(branch: IrBranch) = branch is IrElseBranch || ((branch.condition as? IrConst<Boolean>)?.value == true)
fun IrSimpleFunction.isMethodOfAny() =
@@ -183,31 +183,35 @@ class InlineClassLowering(val context: BackendContext) {
override fun lower(irFile: IrFile) {
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
override fun visitCall(call: IrCall): IrExpression {
call.transformChildrenVoid(this)
val function = call.symbol.owner
override fun visitCall(expression: IrCall): IrExpression {
expression.transformChildrenVoid(this)
val function = expression.symbol.owner
if (function.parent !is IrClass ||
function.isStaticMethodOfClass ||
!function.parentAsClass.isInline ||
(function is IrSimpleFunction && !function.isReal) ||
(function is IrConstructor && function.isPrimary)
) {
return call
return expression
}
return irCall(call, getOrCreateStaticMethod(function), dispatchReceiverAsFirstArgument = (function is IrSimpleFunction))
return irCall(
expression,
getOrCreateStaticMethod(function),
dispatchReceiverAsFirstArgument = (function is IrSimpleFunction)
)
}
override fun visitDelegatingConstructorCall(call: IrDelegatingConstructorCall): IrExpression {
call.transformChildrenVoid(this)
val function = call.symbol.owner
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
expression.transformChildrenVoid(this)
val function = expression.symbol.owner
val klass = function.parentAsClass
return when {
!klass.isInline -> call
function.isPrimary -> irCall(call, function)
else -> irCall(call, getOrCreateStaticMethod(function)).apply {
(0 until call.valueArgumentsCount).forEach {
putValueArgument(it, call.getValueArgument(it)!!)
!klass.isInline -> expression
function.isPrimary -> irCall(expression, function)
else -> irCall(expression, getOrCreateStaticMethod(function)).apply {
(0 until expression.valueArgumentsCount).forEach {
putValueArgument(it, expression.getValueArgument(it)!!)
}
}
}
@@ -78,6 +78,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
if (this is SameTypeCompilerPhase<*, *> &&
this !in phaseConfig.enabled
) {
@Suppress("UNCHECKED_CAST")
return input as Output
}
@@ -121,7 +122,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
for (post in postconditions) post(output)
for (post in stickyPostconditions) post(output)
if (phaseConfig.checkStickyConditions && this is SameTypeCompilerPhase<*, *>) {
val phaserStateO = phaserState as PhaserState<Output>
@Suppress("UNCHECKED_CAST") val phaserStateO = phaserState as PhaserState<Output>
for (post in phaserStateO.stickyPostconditions) post(output)
}
}
@@ -17,7 +17,7 @@ private class CompositePhase<Context : CommonBackendContext, Input, Output>(
) : CompilerPhase<Context, Input, Output> {
override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, input: Input): Output {
var currentState = phaserState as PhaserState<Any?>
@Suppress("UNCHECKED_CAST") var currentState = phaserState as PhaserState<Any?>
var result = phases.first().invoke(phaseConfig, currentState, context, input)
for ((previous, next) in phases.zip(phases.drop(1))) {
if (next !is SameTypeCompilerPhase<*, *>) {
@@ -27,6 +27,7 @@ private class CompositePhase<Context : CommonBackendContext, Input, Output>(
currentState.stickyPostconditions.addAll(previous.stickyPostconditions)
result = next.invoke(phaseConfig, currentState, context, result)
}
@Suppress("UNCHECKED_CAST")
return result as Output
}
@@ -36,6 +37,7 @@ private class CompositePhase<Context : CommonBackendContext, Input, Output>(
override val stickyPostconditions get() = phases.last().stickyPostconditions
}
@Suppress("UNCHECKED_CAST")
infix fun <Context : CommonBackendContext, Input, Mid, Output> CompilerPhase<Context, Input, Mid>.then(
other: CompilerPhase<Context, Mid, Output>
): CompilerPhase<Context, Input, Output> {
@@ -176,8 +176,6 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
}
}
val sourceFile = callee.file
val transformer = ParameterSubstitutor()
statements.transform { it.transform(transformer, data = null) }
statements.addAll(0, evaluationStatements)
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.js.backend.ast.JsDeclarationScope
import org.jetbrains.kotlin.js.backend.ast.JsStatement
class IrFileToJsTransformer : BaseIrElementToJsNodeTransformer<JsStatement, JsGenerationContext> {
override fun visitFile(declaration: IrFile, context: JsGenerationContext): JsStatement {
val fileContext = context.newDeclaration(JsDeclarationScope(context.currentScope, "scope for file ${declaration.path}"))
override fun visitFile(declaration: IrFile, data: JsGenerationContext): JsStatement {
val fileContext = data.newDeclaration(JsDeclarationScope(data.currentScope, "scope for file ${declaration.path}"))
val block = fileContext.currentBlock
declaration.declarations.forEach {
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.backend.common.ir.isElseBranch
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
import org.jetbrains.kotlin.ir.backend.js.utils.Namer
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.ir.expressions.IrWhen
import org.jetbrains.kotlin.js.backend.ast.*
fun jsVar(name: JsName, initializer: IrExpression?, context: JsGenerationContext): JsVars {
@@ -18,12 +20,12 @@ fun jsVar(name: JsName, initializer: IrExpression?, context: JsGenerationContext
return JsVars(JsVars.JsVar(name, jsInitializer))
}
fun <T : JsNode, D : JsGenerationContext> IrWhen.toJsNode(
tr: BaseIrElementToJsNodeTransformer<T, D>,
data: D,
fun <T : JsNode> IrWhen.toJsNode(
tr: BaseIrElementToJsNodeTransformer<T, JsGenerationContext>,
data: JsGenerationContext,
node: (JsExpression, T, T?) -> T
): T? =
branches.foldRight<IrBranch, T?>(null) { br, n ->
branches.foldRight(null) { br, n ->
val body = br.result.accept(tr, data)
if (isElseBranch(br)) body
else {
@@ -118,9 +120,7 @@ object JsAstUtils {
thenStatement: JsStatement,
elseStatement: JsStatement? = null
): JsIf {
var elseStatement = elseStatement
elseStatement = if (elseStatement != null) deBlockIfPossible(elseStatement) else null
return JsIf(ifExpression, deBlockIfPossible(thenStatement), elseStatement)
return JsIf(ifExpression, deBlockIfPossible(thenStatement), elseStatement?.let { deBlockIfPossible(it) })
}
fun and(op1: JsExpression, op2: JsExpression): JsBinaryOperation {
@@ -21,6 +21,7 @@ object JsAnnotations {
val jsQualifierFqn = FqName("kotlin.js.JsQualifier")
}
@Suppress("UNCHECKED_CAST")
private fun IrCall.getSingleConstStringArgument() =
(getValueArgument(0) as IrConst<String>).value
@@ -31,7 +31,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
val psi2ir = Psi2IrTranslator(state.languageVersionSettings)
val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, extensions = JvmGeneratorExtensions)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection<KtFile>)
@Suppress("UNCHECKED_CAST") val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection<KtFile>)
JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext, phaseConfig)
}
@@ -96,7 +96,7 @@ class IrInlineCodegen(
private fun rememberClosure(irReference: IrFunctionReference, type: Type, parameter: ValueParameterDescriptor): LambdaInfo {
//assert(InlineUtil.isInlinableParameterExpression(ktLambda)) { "Couldn't find inline expression in ${expression.text}" }
val expression = irReference.symbol.owner as IrFunction
val expression = irReference.symbol.owner
return IrExpressionLambdaImpl(
irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/,
parameter.type.isExtensionFunctionType
@@ -177,7 +177,7 @@ class JvmSharedVariablesManager(
typeArgumentsCount = typeArgumentsCount,
origin = SHARED_VARIABLE_CONSTRUCTOR_CALL_ORIGIN
).apply {
refConstructor.parentAsClass.typeParameters.mapIndexed { i, param ->
List(refConstructor.parentAsClass.typeParameters.size) { i ->
putTypeArgument(i, valueType)
}
}
@@ -212,10 +212,10 @@ private class FieldReplacer(val replacementMap: Map<IrFieldSymbol, IrFieldSymbol
} ?: super.visitGetField(expression)
override fun visitSetField(expression: IrSetField): IrExpression =
replacementMap[expression.symbol]?.let { newSymbol ->
replacementMap[expression.symbol]?.let { _ ->
IrSetFieldImpl(
expression.startOffset, expression.endOffset,
replacementMap[expression.symbol]!!,
replacementMap.getValue(expression.symbol),
/* receiver = */ null,
visitExpression(expression.value),
expression.type,
@@ -106,7 +106,6 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta
// TODO relies on ControlFlowInformationProvider, get rid of it
val isUsedAsExpression = get(BindingContext.USED_AS_EXPRESSION, expression) ?: false
val isExhaustive = expression.isExhaustiveWhen()
val resultType = when {
isUsedAsExpression -> inferredType.toIrType()
@@ -172,7 +172,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
val irType = descriptor.type.toIrType()
return if (getMethodDescriptor == null) {
call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue ->
call.callReceiver.call { dispatchReceiverValue, _ ->
val fieldSymbol = context.symbolTable.referenceField(descriptor.original)
IrGetFieldImpl(
startOffset, endOffset,
@@ -156,6 +156,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
private fun getFieldForPropertyReference(originalProperty: PropertyDescriptor) =
// NB this is a hack, we really don't know if an arbitrary property has a backing field or not
when {
@Suppress("DEPRECATION")
originalProperty.isDelegated -> null
originalProperty.getter != null -> null
else -> context.symbolTable.referenceField(originalProperty)
@@ -85,6 +85,7 @@ class IrLocalDelegatedPropertyImpl(
descriptor.name, type, descriptor.isVar
)
@Suppress("DEPRECATION")
@Deprecated("Creates unbound symbol")
constructor(
startOffset: Int,
@@ -39,7 +39,7 @@ class IrPropertyImpl(
override val isVar: Boolean = symbol.descriptor.isVar,
override val isConst: Boolean = symbol.descriptor.isConst,
override val isLateinit: Boolean = symbol.descriptor.isLateInit,
override val isDelegated: Boolean = symbol.descriptor.isDelegated,
@Suppress("DEPRECATION") override val isDelegated: Boolean = symbol.descriptor.isDelegated,
override val isExternal: Boolean = symbol.descriptor.isEffectivelyExternal()
) : IrDeclarationBase(startOffset, endOffset, origin),
IrProperty {
@@ -69,6 +69,7 @@ class IrPropertyImpl(
isExternal = isExternal
)
@Suppress("DEPRECATION")
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING)
constructor(
startOffset: Int,
@@ -86,6 +87,7 @@ class IrPropertyImpl(
isExternal = descriptor.isEffectivelyExternal()
)
@Suppress("DEPRECATION")
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING)
constructor(
startOffset: Int,
@@ -94,6 +96,7 @@ class IrPropertyImpl(
descriptor: PropertyDescriptor
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
@Suppress("DEPRECATION")
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING)
constructor(
startOffset: Int,
@@ -106,6 +109,7 @@ class IrPropertyImpl(
this.backingField = backingField
}
@Suppress("DEPRECATION")
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING)
constructor(
startOffset: Int,
@@ -57,7 +57,7 @@ class IrLazyProperty(
isVar = symbol.descriptor.isVar,
isConst = symbol.descriptor.isConst,
isLateinit = symbol.descriptor.isLateInit,
isDelegated = symbol.descriptor.isDelegated,
isDelegated = @Suppress("DEPRECATION") symbol.descriptor.isDelegated,
isExternal = symbol.descriptor.isEffectivelyExternal(),
stubGenerator = stubGenerator,
typeTranslator = typeTranslator,
@@ -33,6 +33,6 @@ class LazyScopedTypeParametersResolver(private val symbolTable: ReferenceSymbolT
parent.typeParameters.firstOrNull {
it.descriptor == typeParameterDescriptor
}?.symbol
} ?: null
}
}
}
@@ -93,7 +93,7 @@ class DeclarationStubGenerator(
val origin = computeOrigin(descriptor)
return symbolTable.declareProperty(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original,
isDelegated = descriptor.isDelegated
isDelegated = @Suppress("DEPRECATION") descriptor.isDelegated
) {
deserializer?.findDeserializedDeclaration(descriptor)
?: IrLazyProperty(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator, bindingContext)
@@ -62,7 +62,7 @@ fun IrMemberAccessExpression.getArguments(): List<Pair<ParameterDescriptor, IrEx
*/
fun IrFunctionAccessExpression.getArgumentsWithSymbols(): List<Pair<IrValueParameterSymbol, IrExpression>> {
val res = mutableListOf<Pair<IrValueParameterSymbol, IrExpression>>()
val irFunction = symbol.owner as IrFunction
val irFunction = symbol.owner
dispatchReceiver?.let {
res += (irFunction.dispatchReceiverParameter!!.symbol to it)
@@ -347,6 +347,7 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean {
inline fun <reified T : IrDeclaration> IrDeclarationContainer.findDeclaration(predicate: (T) -> Boolean): T? =
declarations.find { it is T && predicate(it) } as? T
@Suppress("UNCHECKED_CAST")
inline fun <reified T : IrDeclaration> IrDeclarationContainer.filterDeclarations(predicate: (T) -> Boolean): List<T> =
declarations.filter { it is T && predicate(it) } as List<T>
@@ -334,7 +334,7 @@ open class SymbolTable : ReferenceSymbolTable {
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
isDelegated: Boolean = descriptor.isDelegated,
@Suppress("DEPRECATION") isDelegated: Boolean = descriptor.isDelegated,
propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol ->
IrPropertyImpl(startOffset, endOffset, origin, symbol, isDelegated = isDelegated).apply {
metadata = MetadataSource.Property(symbol.descriptor)
@@ -166,7 +166,7 @@ abstract class IrModuleDeserializer(
}
private fun deserializeSyntheticBody(proto: KotlinIr.IrSyntheticBody, start: Int, end: Int): IrSyntheticBody {
val kind = when (proto.kind) {
val kind = when (proto.kind!!) {
KotlinIr.IrSyntheticBodyKind.ENUM_VALUES -> IrSyntheticBodyKind.ENUM_VALUES
KotlinIr.IrSyntheticBodyKind.ENUM_VALUEOF -> IrSyntheticBodyKind.ENUM_VALUEOF
}
@@ -652,7 +652,7 @@ abstract class IrModuleDeserializer(
}
private fun deserializeConst(proto: KotlinIr.IrConst, start: Int, end: Int, type: IrType): IrExpression =
when (proto.valueCase) {
when (proto.valueCase!!) {
NULL
-> IrConstImpl.constNull(start, end, type)
BOOLEAN
@@ -678,7 +678,7 @@ abstract class IrModuleDeserializer(
}
private fun deserializeOperation(proto: KotlinIr.IrOperation, start: Int, end: Int, type: IrType): IrExpression =
when (proto.operationCase) {
when (proto.operationCase!!) {
BLOCK
-> deserializeBlock(proto.block, start, end, type)
BREAK
@@ -766,11 +766,12 @@ abstract class IrModuleDeserializer(
val name = deserializeName(proto.name)
val variance = deserializeIrTypeVariance(proto.variance)
val parameter = symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
symbol.descriptor, { symbol ->
IrTypeParameterImpl(start, end, origin, symbol, name, proto.index, proto.isReified, variance)
}
)
val parameter = symbolTable.declareGlobalTypeParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
symbol.descriptor
) {
IrTypeParameterImpl(start, end, origin, it, name, proto.index, proto.isReified, variance)
}
val superTypes = proto.superTypeList.map { deserializeIrType(it) }
parameter.superTypes.addAll(superTypes)
@@ -1162,7 +1163,7 @@ abstract class IrModuleDeserializer(
val declarator = proto.declarator
val declaration: IrDeclaration = when (declarator.declaratorCase) {
val declaration: IrDeclaration = when (declarator.declaratorCase!!) {
IR_ANONYMOUS_INIT
-> deserializeIrAnonymousInit(declarator.irAnonymousInit, start, end, origin)
IR_CONSTRUCTOR
@@ -967,7 +967,7 @@ open class IrModuleSerializer(
}
private fun serializeIrProperty(property: IrProperty): KotlinIr.IrProperty {
val index = declarationTable.uniqIdByDeclaration(property)
declarationTable.uniqIdByDeclaration(property)
val proto = KotlinIr.IrProperty.newBuilder()
.setIsDelegated(property.isDelegated)