Minor. Reformat

This commit is contained in:
Mikhael Bogdanov
2018-06-14 11:04:22 +02:00
parent 3dff3d61f5
commit 7c615eb7ab
9 changed files with 201 additions and 175 deletions
@@ -37,14 +37,14 @@ interface InnerClassConsumer {
if (defaultImpls) {
if (DescriptorUtils.isLocal(descriptor)) return null
val classDescriptorImpl = ClassDescriptorImpl(
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
Modality.FINAL, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE,
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS)
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
Modality.FINAL, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE,
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS
)
classDescriptorImpl.initialize(MemberScope.Empty, emptySet(), null)
return classDescriptorImpl
}
else {
} else {
return if (DescriptorUtils.isTopLevelDeclaration(descriptor)) null else descriptor
}
}
@@ -19,19 +19,19 @@ import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.tree.MethodNode
class InlineCodegenForDefaultBody(
function: FunctionDescriptor,
codegen: ExpressionCodegen,
val state: GenerationState,
private val sourceCompilerForInline: SourceCompilerForInline
function: FunctionDescriptor,
codegen: ExpressionCodegen,
val state: GenerationState,
private val sourceCompilerForInline: SourceCompilerForInline
) : CallGenerator {
private val sourceMapper: SourceMapper = codegen.parentCodegen.orCreateSourceMapper
private val functionDescriptor =
if (InlineUtil.isArrayConstructorWithLambda(function))
FictitiousArrayConstructor.create(function as ConstructorDescriptor)
else
function.original
if (InlineUtil.isArrayConstructorWithLambda(function))
FictitiousArrayConstructor.create(function as ConstructorDescriptor)
else
function.original
init {
@@ -45,7 +45,7 @@ class InlineCodegenForDefaultBody(
init {
assert(InlineUtil.isInline(function)) {
"InlineCodegen can inline only inline functions and array constructors: " + function
"InlineCodegen can inline only inline functions and array constructors: $function"
}
sourceCompilerForInline.initializeInlineFunctionContext(functionDescriptor)
jvmSignature = state.typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompilerForInline.contextKind)
@@ -55,18 +55,21 @@ class InlineCodegenForDefaultBody(
}
override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) {
val nodeAndSmap = InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, null, state, sourceCompilerForInline)
val nodeAndSmap =
InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, null, state, sourceCompilerForInline)
val childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper)
val node = nodeAndSmap.node
val transformedMethod = MethodNode(
node.access,
node.name,
node.desc,
node.signature,
node.exceptions.toTypedArray())
node.access,
node.name,
node.desc,
node.signature,
node.exceptions.toTypedArray()
)
val argsSize = (Type.getArgumentsAndReturnSizes(jvmSignature.asmMethod.descriptor) ushr 2) - if (callableMethod.isStaticCall()) 1 else 0
val argsSize =
(Type.getArgumentsAndReturnSizes(jvmSignature.asmMethod.descriptor) ushr 2) - if (callableMethod.isStaticCall()) 1 else 0
node.accept(object : InlineAdapter(transformedMethod, 0, childSourceMapper) {
override fun visitLocalVariable(name: String, desc: String, signature: String?, start: Label, end: Label, index: Int) {
val startLabel = if (index < argsSize) methodStartLabel else start
@@ -77,7 +80,12 @@ class InlineCodegenForDefaultBody(
transformedMethod.accept(MethodBodyVisitor(codegen.visitor))
}
override fun genValueAndPut(valueParameterDescriptor: ValueParameterDescriptor, argumentExpression: KtExpression, parameterType: Type, parameterIndex: Int) {
override fun genValueAndPut(
valueParameterDescriptor: ValueParameterDescriptor,
argumentExpression: KtExpression,
parameterType: Type,
parameterIndex: Int
) {
throw UnsupportedOperationException("Shouldn't be called")
}
@@ -52,8 +52,8 @@ abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : LabelOwner {
val builder = ParametersBuilder.initializeBuilderFrom(AsmTypes.OBJECT_TYPE, invokeMethod.descriptor, this)
for (info in capturedVars) {
val field = remapper.findField(FieldInsnNode(0, info.containingLambdaName, info.fieldName, "")) ?:
error("Captured field not found: " + info.containingLambdaName + "." + info.fieldName)
val field = remapper.findField(FieldInsnNode(0, info.containingLambdaName, info.fieldName, ""))
?: error("Captured field not found: " + info.containingLambdaName + "." + info.fieldName)
builder.addCapturedParam(field, info.fieldName)
}
@@ -74,11 +74,11 @@ abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : LabelOwner {
class DefaultLambda(
override val lambdaClassType: Type,
private val capturedArgs: Array<Type>,
val parameterDescriptor: ValueParameterDescriptor,
val offset: Int,
val needReification: Boolean
override val lambdaClassType: Type,
private val capturedArgs: Array<Type>,
val parameterDescriptor: ValueParameterDescriptor,
val offset: Int,
val needReification: Boolean
) : LambdaInfo(parameterDescriptor.isCrossinline) {
override var isBoundCallableReference by Delegates.notNull<Boolean>()
@@ -103,8 +103,15 @@ class DefaultLambda(
val classReader = buildClassReaderByInternalName(sourceCompiler.state, lambdaClassType.internalName)
var isPropertyReference = false
var isFunctionReference = false
classReader.accept(object: ClassVisitor(API){
override fun visit(version: Int, access: Int, name: String, signature: String?, superName: String?, interfaces: Array<out String>?) {
classReader.accept(object : ClassVisitor(API) {
override fun visit(
version: Int,
access: Int,
name: String,
signature: String?,
superName: String?,
interfaces: Array<out String>?
) {
isPropertyReference = superName?.startsWith("kotlin/jvm/internal/PropertyReference") ?: false
isFunctionReference = "kotlin/jvm/internal/FunctionReference" == superName
@@ -114,19 +121,20 @@ class DefaultLambda(
invokeMethodDescriptor =
parameterDescriptor.type.memberScope
.getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND)
.single()
.let {
//property reference generates erased 'get' method
if (isPropertyReference) it.original else it
}
.getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND)
.single()
.let {
//property reference generates erased 'get' method
if (isPropertyReference) it.original else it
}
val descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, *capturedArgs)
val constructor = getMethodNode(
classReader.b,
"<init>",
descriptor,
lambdaClassType)?.node
classReader.b,
"<init>",
descriptor,
lambdaClassType
)?.node
assert(constructor != null || capturedArgs.isEmpty()) {
"Can't find non-default constructor <init>$descriptor for default lambda $lambdaClassType"
@@ -139,23 +147,23 @@ class DefaultLambda(
listOf(capturedParamDesc(AsmUtil.RECEIVER_NAME, it.boxReceiverForBoundReference()))
} ?: emptyList()
else
constructor?.findCapturedFieldAssignmentInstructions()?.map {
fieldNode ->
constructor?.findCapturedFieldAssignmentInstructions()?.map { fieldNode ->
capturedParamDesc(fieldNode.name, Type.getType(fieldNode.desc))
}?.toList() ?: emptyList()
isBoundCallableReference = (isFunctionReference || isPropertyReference) && capturedVars.isNotEmpty()
invokeMethod = Method(
(if (isPropertyReference) OperatorNameConventions.GET else OperatorNameConventions.INVOKE).asString(),
sourceCompiler.state.typeMapper.mapSignatureSkipGeneric(invokeMethodDescriptor).asmMethod.descriptor
(if (isPropertyReference) OperatorNameConventions.GET else OperatorNameConventions.INVOKE).asString(),
sourceCompiler.state.typeMapper.mapSignatureSkipGeneric(invokeMethodDescriptor).asmMethod.descriptor
)
node = getMethodNode(
classReader.b,
invokeMethod.name,
invokeMethod.descriptor,
lambdaClassType) ?: error("Can't find method '${invokeMethod.name}${invokeMethod.descriptor}' in '${classReader.className}'")
classReader.b,
invokeMethod.name,
invokeMethod.descriptor,
lambdaClassType
) ?: error("Can't find method '${invokeMethod.name}${invokeMethod.descriptor}' in '${classReader.className}'")
if (needReification) {
//nested classes could also require reification
@@ -166,19 +174,19 @@ class DefaultLambda(
fun Type.boxReceiverForBoundReference() = AsmUtil.boxType(this)
abstract class ExpressionLambda(protected val typeMapper: KotlinTypeMapper, isCrossInline: Boolean): LambdaInfo(isCrossInline) {
abstract class ExpressionLambda(protected val typeMapper: KotlinTypeMapper, isCrossInline: Boolean) : LambdaInfo(isCrossInline) {
override fun generateLambdaBody(sourceCompiler: SourceCompilerForInline, reifiedTypeInliner: ReifiedTypeInliner) {
val jvmMethodSignature = typeMapper.mapSignatureSkipGeneric(invokeMethodDescriptor)
val asmMethod = jvmMethodSignature.asmMethod
val methodNode = MethodNode(
API, AsmUtil.getMethodAsmFlags(invokeMethodDescriptor, OwnerKind.IMPLEMENTATION, sourceCompiler.state),
asmMethod.name, asmMethod.descriptor, null, null
API, AsmUtil.getMethodAsmFlags(invokeMethodDescriptor, OwnerKind.IMPLEMENTATION, sourceCompiler.state),
asmMethod.name, asmMethod.descriptor, null, null
)
node = wrapWithMaxLocalCalc(methodNode).let { adapter ->
val smap = sourceCompiler.generateLambdaBody(
adapter, jvmMethodSignature, this
adapter, jvmMethodSignature, this
)
adapter.visitMaxs(-1, -1)
SMAPAndMethodNode(methodNode, smap)
@@ -187,10 +195,10 @@ abstract class ExpressionLambda(protected val typeMapper: KotlinTypeMapper, isCr
}
class PsiExpressionLambda(
expression: KtExpression,
typeMapper: KotlinTypeMapper,
isCrossInline: Boolean,
override val isBoundCallableReference: Boolean
expression: KtExpression,
typeMapper: KotlinTypeMapper,
isCrossInline: Boolean,
override val isBoundCallableReference: Boolean
) : ExpressionLambda(typeMapper, isCrossInline) {
override val lambdaClassType: Type
@@ -211,21 +219,21 @@ class PsiExpressionLambda(
init {
val bindingContext = typeMapper.bindingContext
val function = bindingContext.get<PsiElement, SimpleFunctionDescriptor>(BindingContext.FUNCTION, functionWithBodyOrCallableReference)
val function =
bindingContext.get<PsiElement, SimpleFunctionDescriptor>(BindingContext.FUNCTION, functionWithBodyOrCallableReference)
if (function == null && expression is KtCallableReferenceExpression) {
val variableDescriptor =
bindingContext.get(BindingContext.VARIABLE, functionWithBodyOrCallableReference) as? VariableDescriptorWithAccessors ?:
throw AssertionError("""Reference expression not resolved to variable descriptor with accessors: ${expression.getText()}""")
bindingContext.get(BindingContext.VARIABLE, functionWithBodyOrCallableReference) as? VariableDescriptorWithAccessors
?: throw AssertionError("""Reference expression not resolved to variable descriptor with accessors: ${expression.getText()}""")
classDescriptor = CodegenBinding.anonymousClassForCallable(bindingContext, variableDescriptor)
lambdaClassType = typeMapper.mapClass(classDescriptor)
val getFunction = PropertyReferenceCodegen.findGetFunction(variableDescriptor)
invokeMethodDescriptor = PropertyReferenceCodegen.createFakeOpenDescriptor(getFunction, classDescriptor)
val resolvedCall = expression.callableReference.getResolvedCallWithAssert(bindingContext)
propertyReferenceInfo = PropertyReferenceInfo(
resolvedCall.resultingDescriptor as VariableDescriptor, getFunction
resolvedCall.resultingDescriptor as VariableDescriptor, getFunction
)
}
else {
} else {
propertyReferenceInfo = null
invokeMethodDescriptor = function ?: throw AssertionError("Function is not resolved to descriptor: " + expression.text)
classDescriptor = anonymousClassForCallable(bindingContext, invokeMethodDescriptor)
@@ -246,9 +254,9 @@ class PsiExpressionLambda(
if (closure.captureThis != null) {
val type = typeMapper.mapType(closure.captureThis!!)
val descriptor = EnclosedValueDescriptor(
AsmUtil.CAPTURED_THIS_FIELD, null,
StackValue.field(type, lambdaClassType, AsmUtil.CAPTURED_THIS_FIELD, false, StackValue.LOCAL_0),
type
AsmUtil.CAPTURED_THIS_FIELD, null,
StackValue.field(type, lambdaClassType, AsmUtil.CAPTURED_THIS_FIELD, false, StackValue.LOCAL_0),
type
)
add(getCapturedParamInfo(descriptor))
}
@@ -258,15 +266,14 @@ class PsiExpressionLambda(
if (isBoundCallableReference) it.boxReceiverForBoundReference() else it
}
val descriptor = EnclosedValueDescriptor(
AsmUtil.CAPTURED_RECEIVER_FIELD, null,
StackValue.field(type, lambdaClassType, AsmUtil.CAPTURED_RECEIVER_FIELD, false, StackValue.LOCAL_0),
type
AsmUtil.CAPTURED_RECEIVER_FIELD, null,
StackValue.field(type, lambdaClassType, AsmUtil.CAPTURED_RECEIVER_FIELD, false, StackValue.LOCAL_0),
type
)
add(getCapturedParamInfo(descriptor))
}
closure.captureVariables.values.forEach {
descriptor ->
closure.captureVariables.values.forEach { descriptor ->
add(getCapturedParamInfo(descriptor))
}
}
@@ -35,14 +35,14 @@ abstract class ObjectTransformer<out T : TransformationInfo>(@JvmField val trans
protected fun createRemappingClassBuilderViaFactory(inliningContext: InliningContext): ClassBuilder {
val classBuilder = state.factory.newVisitor(
JvmDeclarationOrigin.NO_ORIGIN,
Type.getObjectType(transformationInfo.newClassName),
inliningContext.root.sourceCompilerForInline.callsiteFile!!
JvmDeclarationOrigin.NO_ORIGIN,
Type.getObjectType(transformationInfo.newClassName),
inliningContext.root.sourceCompilerForInline.callsiteFile!!
)
return RemappingClassBuilder(
classBuilder,
AsmTypeRemapper(inliningContext.typeRemapper, transformationResult)
classBuilder,
AsmTypeRemapper(inliningContext.typeRemapper, transformationResult)
)
}
@@ -52,8 +52,8 @@ abstract class ObjectTransformer<out T : TransformationInfo>(@JvmField val trans
}
class WhenMappingTransformer(
whenObjectRegenerationInfo: WhenMappingTransformationInfo,
private val inliningContext: InliningContext
whenObjectRegenerationInfo: WhenMappingTransformationInfo,
private val inliningContext: InliningContext
) : ObjectTransformer<WhenMappingTransformationInfo>(whenObjectRegenerationInfo, inliningContext.state) {
override fun doTransform(parentRemapper: FieldRemapper): InlineResult {
@@ -72,14 +72,13 @@ class WhenMappingTransformer(
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
return if (name == fieldNode.name) {
classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, access, name, desc, signature, value)
}
else {
} else {
null
}
}
override fun visitMethod(
access: Int, name: String, desc: String, signature: String?, exceptions: Array<out String>?
access: Int, name: String, desc: String, signature: String?, exceptions: Array<out String>?
): MethodVisitor? {
return MethodNode(access, name, desc, signature, exceptions).apply {
methodNodes.add(this)
@@ -91,12 +90,12 @@ class WhenMappingTransformer(
"When mapping ${fieldNode.owner} class should contain only one method but: " + methodNodes.joinToString { it.name }
}
val clinit = methodNodes.first()
assert(clinit.name == "<clinit>", { "When mapping should contains only <clinit> method, but contains '${clinit.name}'" })
assert(clinit.name == "<clinit>") { "When mapping should contains only <clinit> method, but contains '${clinit.name}'" }
val transformedClinit = cutOtherMappings(clinit)
val result = classBuilder.newMethod(
JvmDeclarationOrigin.NO_ORIGIN, transformedClinit.access, transformedClinit.name, transformedClinit.desc,
transformedClinit.signature, transformedClinit.exceptions.toTypedArray()
JvmDeclarationOrigin.NO_ORIGIN, transformedClinit.access, transformedClinit.name, transformedClinit.desc,
transformedClinit.signature, transformedClinit.exceptions.toTypedArray()
)
transformedClinit.accept(result)
classBuilder.done()
@@ -106,7 +105,7 @@ class WhenMappingTransformer(
private fun cutOtherMappings(node: MethodNode): MethodNode {
val myArrayAccess = InsnSequence(node.instructions).first {
it is FieldInsnNode && it.name.equals(transformationInfo.fieldNode.name)
it is FieldInsnNode && it.name == transformationInfo.fieldNode.name
}
val myValuesAccess = generateSequence(myArrayAccess) { it.previous }.first {
@@ -125,8 +124,8 @@ class WhenMappingTransformer(
}
private fun isValues(node: AbstractInsnNode) =
node is MethodInsnNode &&
node.opcode == Opcodes.INVOKESTATIC &&
node.name == "values" &&
node.desc == "()[" + Type.getObjectType(node.owner).descriptor
node is MethodInsnNode &&
node.opcode == Opcodes.INVOKESTATIC &&
node.name == "values" &&
node.desc == "()[" + Type.getObjectType(node.owner).descriptor
}
@@ -26,9 +26,9 @@ val KOTLIN_DEBUG_STRATA_NAME = "KotlinDebug"
//TODO join parameter
class SMAPBuilder(
val source: String,
val path: String,
private val fileMappings: List<FileMapping>
val source: String,
val path: String,
private val fileMappings: List<FileMapping>
) {
private val header = "SMAP\n$source\nKotlin"
@@ -58,9 +58,11 @@ class SMAPBuilder(
val combinedMapping = FileMapping(source, path)
realMappings.forEach { fileMapping ->
fileMapping.lineMappings.filter { it.callSiteMarker != null }.forEach { (_, dest, range, callSiteMarker) ->
combinedMapping.addRangeMapping(RangeMapping(
combinedMapping.addRangeMapping(
RangeMapping(
callSiteMarker!!.lineNumber, dest, range
))
)
)
}
}
@@ -88,7 +90,7 @@ class SMAPBuilder(
}
open class NestedSourceMapper(
override val parent: SourceMapper, val ranges: List<RangeMapping>, sourceInfo: SourceInfo
override val parent: SourceMapper, val ranges: List<RangeMapping>, sourceInfo: SourceInfo
) : DefaultSourceMapper(sourceInfo) {
private val visitedLines = TIntIntHashMap()
@@ -100,11 +102,10 @@ open class NestedSourceMapper(
return if (mappedLineNumber > 0) {
mappedLineNumber
}
else {
} else {
val rangeForMapping =
(if (lastVisitedRange?.contains(lineNumber) ?: false) lastVisitedRange!! else findMappingIfExists(lineNumber))
?: error("Can't find range to map line $lineNumber in ${sourceInfo.source}: ${sourceInfo.pathOrCleanFQN}")
(if (lastVisitedRange?.contains(lineNumber) ?: false) lastVisitedRange!! else findMappingIfExists(lineNumber))
?: error("Can't find range to map line $lineNumber in ${sourceInfo.source}: ${sourceInfo.pathOrCleanFQN}")
val sourceLineNumber = rangeForMapping.mapDestToSource(lineNumber)
val newLineNumber = parent.mapLineNumber(sourceLineNumber, rangeForMapping.parent!!.name, rangeForMapping.parent!!.path)
if (newLineNumber > 0) {
@@ -116,8 +117,7 @@ open class NestedSourceMapper(
}
private fun findMappingIfExists(lineNumber: Int): RangeMapping? {
val index = ranges.binarySearch(RangeMapping(lineNumber, lineNumber, 1), Comparator {
value, key ->
val index = ranges.binarySearch(RangeMapping(lineNumber, lineNumber, 1), Comparator { value, key ->
if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key)
})
return if (index < 0) null else ranges[index]
@@ -125,7 +125,7 @@ open class NestedSourceMapper(
}
open class InlineLambdaSourceMapper(
parent: SourceMapper, smap: SMAPAndMethodNode
parent: SourceMapper, smap: SMAPAndMethodNode
) : NestedSourceMapper(parent, smap.sortedRanges, smap.classSMAP.sourceInfo) {
init {
@@ -208,14 +208,14 @@ open class DefaultSourceMapper(val sourceInfo: SourceInfo) : SourceMapper {
constructor(sourceInfo: SourceInfo, fileMappings: List<FileMapping>) : this(sourceInfo) {
fileMappings.asSequence().drop(1)
//default one mapped through sourceInfo
.forEach { fileMapping ->
val newFileMapping = getOrRegisterNewSource(fileMapping.name, fileMapping.path)
fileMapping.lineMappings.forEach {
newFileMapping.mapNewInterval(it.source, it.dest, it.range)
maxUsedValue = Math.max(it.maxDest, maxUsedValue)
}
//default one mapped through sourceInfo
.forEach { fileMapping ->
val newFileMapping = getOrRegisterNewSource(fileMapping.name, fileMapping.path)
fileMapping.lineMappings.forEach {
newFileMapping.mapNewInterval(it.source, it.dest, it.range)
maxUsedValue = Math.max(it.maxDest, maxUsedValue)
}
}
}
private fun createKey(name: String, path: String) = "$name#$path"
@@ -282,11 +282,11 @@ class RawFileMapping(val name: String, val path: String) {
private var lastMappedWithNewIndex = -1000
fun toFileMapping() =
FileMapping(name, path).apply {
for (range in rangeMappings) {
addRangeMapping(range)
}
FileMapping(name, path).apply {
for (range in rangeMappings) {
addRangeMapping(range)
}
}
fun initRange(start: Int, end: Int) {
assert(rangeMappings.isEmpty()) { "initRange should only be called for empty mapping" }
@@ -301,8 +301,7 @@ class RawFileMapping(val name: String, val path: String) {
rangeMapping = rangeMappings.last()
rangeMapping.range += source - lastMappedWithNewIndex
dest = rangeMapping.mapSourceToDest(source)
}
else {
} else {
dest = currentIndex + 1
rangeMapping = RangeMapping(source, dest, callSiteMarker = callSiteMarker)
rangeMappings.add(rangeMapping)
@@ -93,7 +93,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
override val lookupLocation = KotlinLookupLocation(callElement)
override val callElementText by lazy {
override val callElementText: String by lazy {
callElement.text
}
@@ -203,7 +203,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
mappings: List<FileMapping>
): SMAP {
val containingFile = declaration.containingFile
CodegenUtil.getLineNumberForElement(containingFile, true) ?: error("Couldn't extract line count in " + containingFile)
CodegenUtil.getLineNumberForElement(containingFile, true) ?: error("Couldn't extract line count in $containingFile")
return SMAP(mappings)
}
@@ -261,7 +261,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
val element = DescriptorToSourceUtils.descriptorToDeclaration(callableDescriptor)
if (!(element is KtNamedFunction || element is KtPropertyAccessor)) {
throw IllegalStateException("Couldn't find declaration for function " + callableDescriptor)
throw IllegalStateException("Couldn't find declaration for function $callableDescriptor")
}
val inliningFunction = element as KtDeclarationWithBody?
@@ -274,7 +274,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
//for maxLocals calculation
val maxCalcAdapter = wrapWithMaxLocalCalc(node)
val parentContext = context.parentContext ?: error("Context has no parent: " + context)
val parentContext = context.parentContext ?: error("Context has no parent: $context")
val methodContext = parentContext.intoFunction(callableDescriptor)
val smap = if (callDefault) {
@@ -286,7 +286,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
false
)
if (element !is KtNamedFunction) {
throw IllegalStateException("Property accessors with default parameters not supported " + callableDescriptor)
throw IllegalStateException("Property accessors with default parameters not supported $callableDescriptor")
}
FunctionCodegen.generateDefaultImplBody(
methodContext, callableDescriptor, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
@@ -416,7 +416,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
return PackageContext(descriptor, state.rootContext, null, sourceFile)
}
val container = descriptor.containingDeclaration ?: error("No container for descriptor: " + descriptor)
val container = descriptor.containingDeclaration ?: error("No container for descriptor: $descriptor")
val parent = getContext(
container,
descriptor,
@@ -454,7 +454,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
parent.intoFunction(descriptor)
}
else -> {
throw IllegalStateException("Couldn't build context for " + descriptor)
throw IllegalStateException("Couldn't build context for $descriptor")
}
}
@@ -23,11 +23,10 @@ import org.jetbrains.kotlin.codegen.state.GenerationState
//This method was moved to separate class cause of LightClass generation problem: KT-18419
//Move it back to inlineCodegenUtil after fix
fun initDefaultSourceMappingIfNeeded(
context: CodegenContext<*>, codegen: MemberCodegen<*>, state: GenerationState
context: CodegenContext<*>, codegen: MemberCodegen<*>, state: GenerationState
) {
if (state.isInlineDisabled) return
var parentContext: CodegenContext<*>? = context.parentContext
while (parentContext != null) {
if (parentContext.isInlineMethodContext) {
@@ -35,52 +35,62 @@ enum class JvmDeclarationOriginKind {
}
class JvmDeclarationOrigin(
val originKind: JvmDeclarationOriginKind,
val element: PsiElement?,
val descriptor: DeclarationDescriptor?
val originKind: JvmDeclarationOriginKind,
val element: PsiElement?,
val descriptor: DeclarationDescriptor?
) {
companion object {
@JvmField val NO_ORIGIN: JvmDeclarationOrigin = JvmDeclarationOrigin(OTHER, null, null)
@JvmField
val NO_ORIGIN: JvmDeclarationOrigin = JvmDeclarationOrigin(OTHER, null, null)
}
}
@JvmOverloads
fun OtherOrigin(element: PsiElement?, descriptor: DeclarationDescriptor? = null) =
if (element == null && descriptor == null)
JvmDeclarationOrigin.NO_ORIGIN
else
JvmDeclarationOrigin(OTHER, element, descriptor)
if (element == null && descriptor == null)
JvmDeclarationOrigin.NO_ORIGIN
else
JvmDeclarationOrigin(OTHER, element, descriptor)
@JvmOverloads
fun OtherOriginFromPure(element: KtPureElement?, descriptor: DeclarationDescriptor? = null) =
OtherOrigin(element?.psiOrParent, descriptor)
OtherOrigin(element?.psiOrParent, descriptor)
fun OtherOrigin(descriptor: DeclarationDescriptor) = JvmDeclarationOrigin(OTHER, null, descriptor)
fun Bridge(descriptor: DeclarationDescriptor, element: PsiElement? = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)): JvmDeclarationOrigin =
JvmDeclarationOrigin(BRIDGE, element, descriptor)
fun Bridge(
descriptor: DeclarationDescriptor,
element: PsiElement? = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
): JvmDeclarationOrigin =
JvmDeclarationOrigin(BRIDGE, element, descriptor)
fun PackagePart(file: KtFile, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(PACKAGE_PART, file, descriptor)
fun PackagePart(file: KtFile, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(PACKAGE_PART, file, descriptor)
/**
* @param representativeFile one of the files representing this multifile class (will be used for diagnostics)
*/
fun MultifileClass(representativeFile: KtFile?, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(MULTIFILE_CLASS, representativeFile, descriptor)
JvmDeclarationOrigin(MULTIFILE_CLASS, representativeFile, descriptor)
fun MultifileClassPart(file: KtFile, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(MULTIFILE_CLASS_PART, file, descriptor)
JvmDeclarationOrigin(MULTIFILE_CLASS_PART, file, descriptor)
fun DefaultImpls(element: PsiElement?, descriptor: ClassDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(INTERFACE_DEFAULT_IMPL, element, descriptor)
fun DefaultImpls(element: PsiElement?, descriptor: ClassDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(INTERFACE_DEFAULT_IMPL, element, descriptor)
fun Delegation(element: PsiElement?, descriptor: FunctionDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(DELEGATION, element, descriptor)
fun Delegation(element: PsiElement?, descriptor: FunctionDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(DELEGATION, element, descriptor)
fun SamDelegation(descriptor: FunctionDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(SAM_DELEGATION, null, descriptor)
fun Synthetic(element: PsiElement?, descriptor: CallableMemberDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(SYNTHETIC, element, descriptor)
fun Synthetic(element: PsiElement?, descriptor: CallableMemberDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(SYNTHETIC, element, descriptor)
val CollectionStub = JvmDeclarationOrigin(COLLECTION_STUB, null, null)
fun AugmentedBuiltInApi(descriptor: CallableDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(AUGMENTED_BUILTIN_API, null, descriptor)
fun AugmentedBuiltInApi(descriptor: CallableDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(AUGMENTED_BUILTIN_API, null, descriptor)
fun ErasedInlineClassOrigin(element: PsiElement?, descriptor: ClassDescriptor): JvmDeclarationOrigin =
JvmDeclarationOrigin(ERASED_INLINE_CLASS, element, descriptor)
@@ -25,9 +25,9 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import java.util.*
private class IrEmptyVarargExpression(
override val type: KotlinType,
override val startOffset: Int,
override val endOffset: Int
override val type: KotlinType,
override val startOffset: Int,
override val endOffset: Int
) : IrExpression {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
TODO("not implemented")
@@ -43,10 +43,10 @@ private class IrEmptyVarargExpression(
}
open class IrIntrinsicFunction(
val expression: IrMemberAccessExpression,
val signature: JvmMethodSignature,
val context: JvmBackendContext,
val argsTypes: List<Type> = expression.argTypes(context)
val expression: IrMemberAccessExpression,
val signature: JvmMethodSignature,
val context: JvmBackendContext,
val argsTypes: List<Type> = expression.argTypes(context)
) : Callable {
override val owner: Type
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
@@ -84,12 +84,11 @@ open class IrIntrinsicFunction(
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue {
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)
else error("Unknown parameter: $descriptor in $expression")
}
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
expression.getValueArgument(i) ?: if (descriptor.isVararg)
IrEmptyVarargExpression(descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET)
else error("Unknown parameter: $descriptor in $expression")
}
args.forEachIndexed { i, irExpression ->
if (irExpression is IrEmptyVarargExpression) {
@@ -98,8 +97,7 @@ open class IrIntrinsicFunction(
it.aconst(0)
it.newarray(AsmUtil.correctElementType(parameterType))
}.put(parameterType, codegen.mv)
}
else {
} else {
genArg(irExpression, codegen, i, data)
}
}
@@ -111,33 +109,39 @@ open class IrIntrinsicFunction(
}
companion object {
fun create(expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
argsTypes: List<Type> = expression.argTypes(context),
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
fun create(
expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
argsTypes: List<Type> = expression.argTypes(context),
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
): IrIntrinsicFunction {
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
override fun genInvokeInstruction(v: InstructionAdapter) = invokeInstuction(v)
override fun genInvokeInstruction(v: InstructionAdapter) = invokeInstruction(v)
}
}
fun createWithResult(expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
argsTypes: List<Type> = expression.argTypes(context),
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Type): IrIntrinsicFunction {
fun createWithResult(
expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
argsTypes: List<Type> = expression.argTypes(context),
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Type
): IrIntrinsicFunction {
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
override fun genInvokeInstructionWithResult(v: InstructionAdapter) = invokeInstuction(v)
override fun genInvokeInstructionWithResult(v: InstructionAdapter) = invokeInstruction(v)
}
}
fun create(expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
type: Type,
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
fun create(
expression: IrMemberAccessExpression,
signature: JvmMethodSignature,
context: JvmBackendContext,
type: Type,
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
): IrIntrinsicFunction {
return create(expression, signature, context, listOf(type), invokeInstruction)
}
}
@@ -153,7 +157,7 @@ fun IrMemberAccessExpression.argTypes(context: JvmBackendContext): ArrayList<Typ
fun IrMemberAccessExpression.receiverAndArgs(): List<IrExpression> {
return (arrayListOf(this.dispatchReceiver, this.extensionReceiver) +
descriptor.valueParameters.mapIndexed { i, _ ->getValueArgument(i)}).filterNotNull()
descriptor.valueParameters.mapIndexed { i, _ -> getValueArgument(i) }).filterNotNull()
}
fun List<IrExpression>.asmTypes(context: JvmBackendContext): List<Type> {