[warnings] g/c some warnings and idea inspections

This commit is contained in:
Vasily Levchenko
2018-02-08 16:14:01 +03:00
committed by Vasily Levchenko
parent 066bff2004
commit 4b12f1c54c
15 changed files with 330 additions and 330 deletions
@@ -67,6 +67,7 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme
// Translate AST to high level IR.
val translator = Psi2IrTranslator(Psi2IrConfiguration(false))
val generatorContext = translator.createGeneratorContext(context.moduleDescriptor, bindingContext)
@Suppress("DEPRECATION")
context.psi2IrGeneratorContext = generatorContext
val symbols = KonanSymbols(context, generatorContext.symbolTable)
@@ -40,7 +40,7 @@ internal class KonanLower(val context: Context) {
}
}
fun lowerModule(irModule: IrModuleFragment) {
private fun lowerModule(irModule: IrModuleFragment) {
val phaser = PhaseManager(context)
phaser.phase(KonanPhase.REMOVE_EXPECT_DECLARATIONS) {
@@ -72,11 +72,12 @@ internal class KonanLower(val context: Context) {
irModule.files.forEach(InteropLoweringPart1(context)::lower)
}
@Suppress("DEPRECATION")
irModule.replaceUnboundSymbols(context)
validateIrModule(context, irModule)
}
fun lowerFile(irFile: IrFile) {
private fun lowerFile(irFile: IrFile) {
val phaser = PhaseManager(context)
phaser.phase(KonanPhase.LOWER_STRING_CONCAT) {
@@ -1401,6 +1401,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
private fun evaluateConst(value: IrConst<*>): LLVMValueRef {
context.log{"evaluateConst : ${ir2string(value)}"}
/* This suppression against IrConst<String> */
@Suppress("UNCHECKED_CAST")
when (value.kind) {
IrConstKind.Null -> return codegen.kNullObjHeaderPtr
IrConstKind.Boolean -> when (value.value) {
@@ -1412,7 +1414,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
IrConstKind.Short -> return LLVMConstInt(LLVMInt16Type(), (value.value as Short).toLong(), 1)!!
IrConstKind.Int -> return LLVMConstInt(LLVMInt32Type(), (value.value as Int).toLong(), 1)!!
IrConstKind.Long -> return LLVMConstInt(LLVMInt64Type(), value.value as Long, 1)!!
IrConstKind.String -> return evaluateStringConst(@Suppress("UNCHECKED_CAST") value as IrConst<String>)
IrConstKind.String -> return evaluateStringConst(value as IrConst<String>)
IrConstKind.Float -> return LLVMConstRealOfString(LLVMFloatType(), (value.value as Float).toString())!!
IrConstKind.Double -> return LLVMConstRealOfString(LLVMDoubleType(), (value.value as Double).toString())!!
}
@@ -146,7 +146,10 @@ private fun Context.getDeclaredFields(classDescriptor: ClassDescriptor): List<Pr
}
private fun ContextUtils.createClassBodyType(name: String, fields: List<PropertyDescriptor>): LLVMTypeRef {
val fieldTypes = fields.map { getLLVMType(if (it.isDelegated) context.builtIns.nullableAnyType else it.type) }
val fieldTypes = fields.map {
@Suppress("DEPRECATION")
getLLVMType(if (it.isDelegated) context.builtIns.nullableAnyType else it.type)
}
val classType = LLVMStructCreateNamed(LLVMGetModuleContext(context.llvmModule), name)!!
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptorImpl
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull
import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol
import org.jetbrains.kotlin.ir.util.DeepCopyIrTree
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.name.Name
@@ -41,7 +43,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable
class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor,
val parentDescriptor: DeclarationDescriptor,
context: CommonBackendContext) {
val context: CommonBackendContext) {
private val descriptorSubstituteMap: MutableMap<DeclarationDescriptor, DeclarationDescriptor> = mutableMapOf()
private var typeSubstitutor: TypeSubstitutor? = null
@@ -274,6 +276,7 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor,
val oldContainingDeclaration = oldDescriptor.containingDeclaration
val newContainingDeclaration = descriptorSubstituteMap.getOrDefault(oldContainingDeclaration, oldContainingDeclaration) as ClassDescriptor
@Suppress("DEPRECATION")
return PropertyDescriptorImpl.create(
/* containingDeclaration = */ newContainingDeclaration,
/* annotations = */ oldDescriptor.annotations,
@@ -286,7 +289,7 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor,
/* lateInit = */ oldDescriptor.isLateInit,
/* isConst = */ oldDescriptor.isConst,
/* isExpect = */ oldDescriptor.isExpect,
/* isActual = */ oldDescriptor.isActual,
/* isActual = */ oldDescriptor.isActual,
/* isExternal = */ oldDescriptor.isExternal,
/* isDelegated = */ oldDescriptor.isDelegated
).apply {
@@ -378,6 +381,7 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor,
//-----------------------------------------------------------------------------//
@Suppress("DEPRECATION")
inner class InlineCopyIr : DeepCopyIrTree() {
override fun mapClassDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor
@@ -596,8 +600,6 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor,
}
}
val context = context
}
class SubstitutedDescriptor(val inlinedFunction: FunctionDescriptor, val descriptor: DeclarationDescriptor)
@@ -633,10 +635,11 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap<
startOffset = oldExpression.startOffset,
endOffset = oldExpression.endOffset,
type = oldExpression.type,
calleeDescriptor = newDescriptor,
symbol = createFunctionSymbol(newDescriptor),
descriptor = newDescriptor,
typeArguments = oldExpression.typeArguments,
origin = oldExpression.origin,
superQualifierDescriptor = oldExpression.superQualifier
superQualifierSymbol = createClassSymbolOrNull(oldExpression.superQualifier)
).apply {
oldExpression.descriptor.valueParameters.forEach {
val valueArgument = oldExpression.getValueArgument(it)
@@ -659,7 +662,7 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap<
if (newDescriptor == oldDescriptor)
return oldExpression
return oldExpression.shallowCopy(oldExpression.origin, newDescriptor, oldExpression.superQualifier)
return oldExpression.shallowCopy(oldExpression.origin, createFunctionSymbol(newDescriptor), oldExpression.superQualifierSymbol)
}
}
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrMemberAccessExpressionBase
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -347,7 +348,7 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
val getVal = IrGetValueImpl( // Create new expression, representing access the new variable.
startOffset = currentScope.irElement.startOffset,
endOffset = currentScope.irElement.endOffset,
descriptor = newVariable.descriptor
symbol = createValueSymbol(newVariable.descriptor)
)
substituteMap[parameterDescriptor] = getVal // Parameter will be replaced with the new variable.
}
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.FqName
@@ -100,7 +102,7 @@ internal class InlineConstructorsTransformation(val context: Context): IrElement
val newThisGetValue = IrGetValueImpl( // Create new expression, representing access the new variable.
startOffset = 0,
endOffset = 0,
descriptor = thisVariable.descriptor
symbol = createValueSymbol(thisVariable.descriptor)
)
val classDescriptor = delegatingCall.descriptor.constructedClass
@@ -119,7 +121,7 @@ internal class InlineConstructorsTransformation(val context: Context): IrElement
statements = newStatements
)
val returnThis = IrReturnImpl(0, 0, functionDescriptor, block)
val returnThis = IrReturnImpl(0, 0, createFunctionSymbol(functionDescriptor), block)
statements.clear()
statements += returnThis
@@ -127,12 +129,13 @@ internal class InlineConstructorsTransformation(val context: Context): IrElement
//-------------------------------------------------------------------------//
fun generateIrCall(expression: IrDelegatingConstructorCallImpl): IrVariable {
private fun generateIrCall(expression: IrDelegatingConstructorCallImpl): IrVariable {
val newExpression = IrCallImpl(
expression.startOffset,
expression.endOffset,
expression.descriptor.returnType,
expression.symbol,
expression.descriptor,
expression.typeArguments,
expression.origin
@@ -143,12 +146,10 @@ internal class InlineConstructorsTransformation(val context: Context): IrElement
}
}
val newVariable = currentScope!!.scope.createTemporaryVariable( // Create new variable and init it with constructor call.
return currentScope!!.scope.createTemporaryVariable( // Create new variable and init it with constructor call.
irExpression = newExpression,
nameHint = newExpression.descriptor.fqNameSafe.toString() + ".this",
isMutable = false)
return newVariable
}
//-------------------------------------------------------------------------//
@@ -93,7 +93,6 @@ internal class ObjCExport(val context: Context) {
}
val file = directory.child("Info.plist")
val bundleExecutable = name
val pkg = context.moduleDescriptor.guessMainPackage() // TODO: consider showing warning if it is root.
val bundleId = pkg.child(Name.identifier(name)).asString()
@@ -104,7 +103,7 @@ internal class ObjCExport(val context: Context) {
else -> error(target)
}
val properties = context.config.platform.configurables as AppleConfigurables
val minimumOsVersion = properties.osVersionMin!!
val minimumOsVersion = properties.osVersionMin
val contents = StringBuilder()
contents.append("""
@@ -113,7 +112,7 @@ internal class ObjCExport(val context: Context) {
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$bundleExecutable</string>
<string>$name</string>
<key>CFBundleIdentifier</key>
<string>$bundleId</string>
<key>CFBundleInfoDictionaryVersion</key>
@@ -42,6 +42,8 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol
import org.jetbrains.kotlin.ir.util.getArguments
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
@@ -195,7 +197,7 @@ private class ExpressionValuesExtractor(val returnableBlockValues: Map<IrReturna
else -> {
if ((expression.type.isUnit() || expression.type.isNothing())) {
block(IrGetObjectValueImpl(expression.startOffset, expression.endOffset,
expression.type, (expression.type.constructor.declarationDescriptor as ClassDescriptor)))
expression.type, IrClassSymbolImpl(expression.type.constructor.declarationDescriptor as ClassDescriptor)))
}
else TODO(ir2stringWhole(expression))
}
@@ -560,7 +562,7 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
is IrDelegatingConstructorCall -> {
val thiz = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET,
(descriptor as ConstructorDescriptor).constructedClass.thisAsReceiverParameter)
createValueSymbol((descriptor as ConstructorDescriptor).constructedClass.thisAsReceiverParameter))
val arguments = listOf(thiz) + value.getArguments().map { it.second }
DataFlowIR.Node.StaticCall(
symbolTable.mapFunction(value.descriptor),
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.backend.konan.optimizations
import org.jetbrains.kotlin.backend.konan.DirectedGraphCondensationBuilder
import org.jetbrains.kotlin.backend.konan.DirectedGraphMultiNode
import org.jetbrains.kotlin.backend.konan.llvm.Lifetime
import org.jetbrains.kotlin.backend.konan.optimizations.*
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
import org.jetbrains.kotlin.ir.IrElement
@@ -162,6 +161,7 @@ internal object EscapeAnalysis {
assignRole(value.node, Role.FIELD_WRITTEN, RoleInfoEntry(node))
}
}
else -> TODO()
}
}
FunctionAnalysisResult(function, nodesRoles)
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirementTable
import org.jetbrains.kotlin.types.KotlinType
// This class knows how to construct contexts for
// MemberDeserializer to deserialize descriptors declared in IR.
@@ -101,12 +100,7 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) {
contextStack.pop()
}
fun deserializeInlineType(type: ProtoBuf.Type): KotlinType {
val result = typeDeserializer.type(type)
return result
}
fun deserializeInlineType(type: ProtoBuf.Type) = typeDeserializer.type(type)
fun deserializeClass(irProto: KonanIr.KotlinDescriptor): ClassDescriptor {
return DeserializedClassDescriptor(parentContext, irProto.irLocalDeclaration.descriptor.clazz, nameResolver, SourceElement.NO_SOURCE)
@@ -121,9 +115,8 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) {
val proto = irProto.irLocalDeclaration.descriptor.constructor
val isPrimary = !Flags.IS_SECONDARY.get(proto.flags)
val constructor = memberDeserializer.loadConstructor(proto, isPrimary)
return constructor
return memberDeserializer.loadConstructor(proto, isPrimary)
}
fun deserializeProperty(irProto: KonanIr.KotlinDescriptor): VariableDescriptor {
@@ -138,18 +131,17 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) {
}
}
fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor {
val variable = LocalVariableDescriptor(
private fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor {
// TODO: Should we transform the getter and the setter too?
@Suppress("DEPRECATION")
return LocalVariableDescriptor(
property.containingDeclaration,
property.annotations,
property.name,
property.type,
property.isVar,
property.isVar,
property.isDelegated,
SourceElement.NO_SOURCE)
// TODO: Should we transform the getter and the setter too?
return variable
}
}
@@ -97,8 +97,9 @@ internal class LocalDeclarationSerializer(val context: Context, val rootFunction
// serialization to serialize variables for now.
// Need to introduce an extension protobuf message
// and serialize variables directly.
fun variableAsProperty(variable: VariableDescriptor): PropertyDescriptor {
private fun variableAsProperty(variable: VariableDescriptor): PropertyDescriptor {
@Suppress("DEPRECATION")
val isDelegated = when (variable) {
is LocalVariableDescriptor -> variable.isDelegated
is IrTemporaryVariableDescriptor -> false
@@ -55,6 +55,7 @@ internal fun IrModuleFragment.replaceUnboundSymbols(context: Context) {
// Generate missing external stubs:
// TODO: ModuleGenerator::generateUnboundSymbolsAsDependencies(IRModuleFragment) is private function :/
@Suppress("DEPRECATION")
ExternalDependenciesGenerator(symbolTable = context.psi2IrGeneratorContext.symbolTable, irBuiltIns = context.irBuiltIns).generateUnboundSymbolsAsDependencies(this)
// Merge duplicated module and package declarations:
@@ -28,7 +28,8 @@ open class KlibInstall: Exec() {
override fun configure(config: Closure<*>): Task {
val result = super.configure(config)
val konanHome = project.rootProject.file(project.findProperty("konan.home") ?: "dist")
val konanHomePath = project.findProperty("konan.home") ?: "dist" // Makes kotlin analyzer happy.
val konanHome = project.rootProject.file(konanHomePath)
val suffix = if (TargetManager.host == KonanTarget.MINGW) ".bat" else ""
val klibProgram = "$konanHome/bin/klib$suffix"