Minor. Reformat
This commit is contained in:
@@ -39,12 +39,12 @@ interface InnerClassConsumer {
|
|||||||
val classDescriptorImpl = ClassDescriptorImpl(
|
val classDescriptorImpl = ClassDescriptorImpl(
|
||||||
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
|
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
|
||||||
Modality.FINAL, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE,
|
Modality.FINAL, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE,
|
||||||
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS)
|
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS
|
||||||
|
)
|
||||||
|
|
||||||
classDescriptorImpl.initialize(MemberScope.Empty, emptySet(), null)
|
classDescriptorImpl.initialize(MemberScope.Empty, emptySet(), null)
|
||||||
return classDescriptorImpl
|
return classDescriptorImpl
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return if (DescriptorUtils.isTopLevelDeclaration(descriptor)) null else descriptor
|
return if (DescriptorUtils.isTopLevelDeclaration(descriptor)) null else descriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-5
@@ -45,7 +45,7 @@ class InlineCodegenForDefaultBody(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
assert(InlineUtil.isInline(function)) {
|
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)
|
sourceCompilerForInline.initializeInlineFunctionContext(functionDescriptor)
|
||||||
jvmSignature = state.typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompilerForInline.contextKind)
|
jvmSignature = state.typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompilerForInline.contextKind)
|
||||||
@@ -55,7 +55,8 @@ class InlineCodegenForDefaultBody(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) {
|
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 childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper)
|
||||||
|
|
||||||
val node = nodeAndSmap.node
|
val node = nodeAndSmap.node
|
||||||
@@ -64,9 +65,11 @@ class InlineCodegenForDefaultBody(
|
|||||||
node.name,
|
node.name,
|
||||||
node.desc,
|
node.desc,
|
||||||
node.signature,
|
node.signature,
|
||||||
node.exceptions.toTypedArray())
|
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) {
|
node.accept(object : InlineAdapter(transformedMethod, 0, childSourceMapper) {
|
||||||
override fun visitLocalVariable(name: String, desc: String, signature: String?, start: Label, end: Label, index: Int) {
|
override fun visitLocalVariable(name: String, desc: String, signature: String?, start: Label, end: Label, index: Int) {
|
||||||
val startLabel = if (index < argsSize) methodStartLabel else start
|
val startLabel = if (index < argsSize) methodStartLabel else start
|
||||||
@@ -77,7 +80,12 @@ class InlineCodegenForDefaultBody(
|
|||||||
transformedMethod.accept(MethodBodyVisitor(codegen.visitor))
|
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")
|
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)
|
val builder = ParametersBuilder.initializeBuilderFrom(AsmTypes.OBJECT_TYPE, invokeMethod.descriptor, this)
|
||||||
|
|
||||||
for (info in capturedVars) {
|
for (info in capturedVars) {
|
||||||
val field = remapper.findField(FieldInsnNode(0, info.containingLambdaName, info.fieldName, "")) ?:
|
val field = remapper.findField(FieldInsnNode(0, info.containingLambdaName, info.fieldName, ""))
|
||||||
error("Captured field not found: " + info.containingLambdaName + "." + info.fieldName)
|
?: error("Captured field not found: " + info.containingLambdaName + "." + info.fieldName)
|
||||||
builder.addCapturedParam(field, info.fieldName)
|
builder.addCapturedParam(field, info.fieldName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +103,15 @@ class DefaultLambda(
|
|||||||
val classReader = buildClassReaderByInternalName(sourceCompiler.state, lambdaClassType.internalName)
|
val classReader = buildClassReaderByInternalName(sourceCompiler.state, lambdaClassType.internalName)
|
||||||
var isPropertyReference = false
|
var isPropertyReference = false
|
||||||
var isFunctionReference = false
|
var isFunctionReference = false
|
||||||
classReader.accept(object: ClassVisitor(API){
|
classReader.accept(object : ClassVisitor(API) {
|
||||||
override fun visit(version: Int, access: Int, name: String, signature: String?, superName: String?, interfaces: Array<out String>?) {
|
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
|
isPropertyReference = superName?.startsWith("kotlin/jvm/internal/PropertyReference") ?: false
|
||||||
isFunctionReference = "kotlin/jvm/internal/FunctionReference" == superName
|
isFunctionReference = "kotlin/jvm/internal/FunctionReference" == superName
|
||||||
|
|
||||||
@@ -126,7 +133,8 @@ class DefaultLambda(
|
|||||||
classReader.b,
|
classReader.b,
|
||||||
"<init>",
|
"<init>",
|
||||||
descriptor,
|
descriptor,
|
||||||
lambdaClassType)?.node
|
lambdaClassType
|
||||||
|
)?.node
|
||||||
|
|
||||||
assert(constructor != null || capturedArgs.isEmpty()) {
|
assert(constructor != null || capturedArgs.isEmpty()) {
|
||||||
"Can't find non-default constructor <init>$descriptor for default lambda $lambdaClassType"
|
"Can't find non-default constructor <init>$descriptor for default lambda $lambdaClassType"
|
||||||
@@ -139,8 +147,7 @@ class DefaultLambda(
|
|||||||
listOf(capturedParamDesc(AsmUtil.RECEIVER_NAME, it.boxReceiverForBoundReference()))
|
listOf(capturedParamDesc(AsmUtil.RECEIVER_NAME, it.boxReceiverForBoundReference()))
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
else
|
else
|
||||||
constructor?.findCapturedFieldAssignmentInstructions()?.map {
|
constructor?.findCapturedFieldAssignmentInstructions()?.map { fieldNode ->
|
||||||
fieldNode ->
|
|
||||||
capturedParamDesc(fieldNode.name, Type.getType(fieldNode.desc))
|
capturedParamDesc(fieldNode.name, Type.getType(fieldNode.desc))
|
||||||
}?.toList() ?: emptyList()
|
}?.toList() ?: emptyList()
|
||||||
|
|
||||||
@@ -155,7 +162,8 @@ class DefaultLambda(
|
|||||||
classReader.b,
|
classReader.b,
|
||||||
invokeMethod.name,
|
invokeMethod.name,
|
||||||
invokeMethod.descriptor,
|
invokeMethod.descriptor,
|
||||||
lambdaClassType) ?: error("Can't find method '${invokeMethod.name}${invokeMethod.descriptor}' in '${classReader.className}'")
|
lambdaClassType
|
||||||
|
) ?: error("Can't find method '${invokeMethod.name}${invokeMethod.descriptor}' in '${classReader.className}'")
|
||||||
|
|
||||||
if (needReification) {
|
if (needReification) {
|
||||||
//nested classes could also require reification
|
//nested classes could also require reification
|
||||||
@@ -166,7 +174,7 @@ class DefaultLambda(
|
|||||||
|
|
||||||
fun Type.boxReceiverForBoundReference() = AsmUtil.boxType(this)
|
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) {
|
override fun generateLambdaBody(sourceCompiler: SourceCompilerForInline, reifiedTypeInliner: ReifiedTypeInliner) {
|
||||||
val jvmMethodSignature = typeMapper.mapSignatureSkipGeneric(invokeMethodDescriptor)
|
val jvmMethodSignature = typeMapper.mapSignatureSkipGeneric(invokeMethodDescriptor)
|
||||||
@@ -211,11 +219,12 @@ class PsiExpressionLambda(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val bindingContext = typeMapper.bindingContext
|
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) {
|
if (function == null && expression is KtCallableReferenceExpression) {
|
||||||
val variableDescriptor =
|
val variableDescriptor =
|
||||||
bindingContext.get(BindingContext.VARIABLE, functionWithBodyOrCallableReference) as? VariableDescriptorWithAccessors ?:
|
bindingContext.get(BindingContext.VARIABLE, functionWithBodyOrCallableReference) as? VariableDescriptorWithAccessors
|
||||||
throw AssertionError("""Reference expression not resolved to variable descriptor with accessors: ${expression.getText()}""")
|
?: throw AssertionError("""Reference expression not resolved to variable descriptor with accessors: ${expression.getText()}""")
|
||||||
classDescriptor = CodegenBinding.anonymousClassForCallable(bindingContext, variableDescriptor)
|
classDescriptor = CodegenBinding.anonymousClassForCallable(bindingContext, variableDescriptor)
|
||||||
lambdaClassType = typeMapper.mapClass(classDescriptor)
|
lambdaClassType = typeMapper.mapClass(classDescriptor)
|
||||||
val getFunction = PropertyReferenceCodegen.findGetFunction(variableDescriptor)
|
val getFunction = PropertyReferenceCodegen.findGetFunction(variableDescriptor)
|
||||||
@@ -224,8 +233,7 @@ class PsiExpressionLambda(
|
|||||||
propertyReferenceInfo = PropertyReferenceInfo(
|
propertyReferenceInfo = PropertyReferenceInfo(
|
||||||
resolvedCall.resultingDescriptor as VariableDescriptor, getFunction
|
resolvedCall.resultingDescriptor as VariableDescriptor, getFunction
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
propertyReferenceInfo = null
|
propertyReferenceInfo = null
|
||||||
invokeMethodDescriptor = function ?: throw AssertionError("Function is not resolved to descriptor: " + expression.text)
|
invokeMethodDescriptor = function ?: throw AssertionError("Function is not resolved to descriptor: " + expression.text)
|
||||||
classDescriptor = anonymousClassForCallable(bindingContext, invokeMethodDescriptor)
|
classDescriptor = anonymousClassForCallable(bindingContext, invokeMethodDescriptor)
|
||||||
@@ -265,8 +273,7 @@ class PsiExpressionLambda(
|
|||||||
add(getCapturedParamInfo(descriptor))
|
add(getCapturedParamInfo(descriptor))
|
||||||
}
|
}
|
||||||
|
|
||||||
closure.captureVariables.values.forEach {
|
closure.captureVariables.values.forEach { descriptor ->
|
||||||
descriptor ->
|
|
||||||
add(getCapturedParamInfo(descriptor))
|
add(getCapturedParamInfo(descriptor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ class WhenMappingTransformer(
|
|||||||
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
||||||
return if (name == fieldNode.name) {
|
return if (name == fieldNode.name) {
|
||||||
classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, access, name, desc, signature, value)
|
classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, access, name, desc, signature, value)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +90,7 @@ class WhenMappingTransformer(
|
|||||||
"When mapping ${fieldNode.owner} class should contain only one method but: " + methodNodes.joinToString { it.name }
|
"When mapping ${fieldNode.owner} class should contain only one method but: " + methodNodes.joinToString { it.name }
|
||||||
}
|
}
|
||||||
val clinit = methodNodes.first()
|
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 transformedClinit = cutOtherMappings(clinit)
|
||||||
val result = classBuilder.newMethod(
|
val result = classBuilder.newMethod(
|
||||||
@@ -106,7 +105,7 @@ class WhenMappingTransformer(
|
|||||||
|
|
||||||
private fun cutOtherMappings(node: MethodNode): MethodNode {
|
private fun cutOtherMappings(node: MethodNode): MethodNode {
|
||||||
val myArrayAccess = InsnSequence(node.instructions).first {
|
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 {
|
val myValuesAccess = generateSequence(myArrayAccess) { it.previous }.first {
|
||||||
|
|||||||
@@ -58,9 +58,11 @@ class SMAPBuilder(
|
|||||||
val combinedMapping = FileMapping(source, path)
|
val combinedMapping = FileMapping(source, path)
|
||||||
realMappings.forEach { fileMapping ->
|
realMappings.forEach { fileMapping ->
|
||||||
fileMapping.lineMappings.filter { it.callSiteMarker != null }.forEach { (_, dest, range, callSiteMarker) ->
|
fileMapping.lineMappings.filter { it.callSiteMarker != null }.forEach { (_, dest, range, callSiteMarker) ->
|
||||||
combinedMapping.addRangeMapping(RangeMapping(
|
combinedMapping.addRangeMapping(
|
||||||
|
RangeMapping(
|
||||||
callSiteMarker!!.lineNumber, dest, range
|
callSiteMarker!!.lineNumber, dest, range
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +102,7 @@ open class NestedSourceMapper(
|
|||||||
|
|
||||||
return if (mappedLineNumber > 0) {
|
return if (mappedLineNumber > 0) {
|
||||||
mappedLineNumber
|
mappedLineNumber
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val rangeForMapping =
|
val rangeForMapping =
|
||||||
(if (lastVisitedRange?.contains(lineNumber) ?: false) lastVisitedRange!! else findMappingIfExists(lineNumber))
|
(if (lastVisitedRange?.contains(lineNumber) ?: false) lastVisitedRange!! else findMappingIfExists(lineNumber))
|
||||||
?: error("Can't find range to map line $lineNumber in ${sourceInfo.source}: ${sourceInfo.pathOrCleanFQN}")
|
?: error("Can't find range to map line $lineNumber in ${sourceInfo.source}: ${sourceInfo.pathOrCleanFQN}")
|
||||||
@@ -116,8 +117,7 @@ open class NestedSourceMapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun findMappingIfExists(lineNumber: Int): RangeMapping? {
|
private fun findMappingIfExists(lineNumber: Int): RangeMapping? {
|
||||||
val index = ranges.binarySearch(RangeMapping(lineNumber, lineNumber, 1), Comparator {
|
val index = ranges.binarySearch(RangeMapping(lineNumber, lineNumber, 1), Comparator { value, key ->
|
||||||
value, key ->
|
|
||||||
if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key)
|
if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key)
|
||||||
})
|
})
|
||||||
return if (index < 0) null else ranges[index]
|
return if (index < 0) null else ranges[index]
|
||||||
@@ -301,8 +301,7 @@ class RawFileMapping(val name: String, val path: String) {
|
|||||||
rangeMapping = rangeMappings.last()
|
rangeMapping = rangeMappings.last()
|
||||||
rangeMapping.range += source - lastMappedWithNewIndex
|
rangeMapping.range += source - lastMappedWithNewIndex
|
||||||
dest = rangeMapping.mapSourceToDest(source)
|
dest = rangeMapping.mapSourceToDest(source)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dest = currentIndex + 1
|
dest = currentIndex + 1
|
||||||
rangeMapping = RangeMapping(source, dest, callSiteMarker = callSiteMarker)
|
rangeMapping = RangeMapping(source, dest, callSiteMarker = callSiteMarker)
|
||||||
rangeMappings.add(rangeMapping)
|
rangeMappings.add(rangeMapping)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
override val lookupLocation = KotlinLookupLocation(callElement)
|
override val lookupLocation = KotlinLookupLocation(callElement)
|
||||||
|
|
||||||
|
|
||||||
override val callElementText by lazy {
|
override val callElementText: String by lazy {
|
||||||
callElement.text
|
callElement.text
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
mappings: List<FileMapping>
|
mappings: List<FileMapping>
|
||||||
): SMAP {
|
): SMAP {
|
||||||
val containingFile = declaration.containingFile
|
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)
|
return SMAP(mappings)
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
val element = DescriptorToSourceUtils.descriptorToDeclaration(callableDescriptor)
|
val element = DescriptorToSourceUtils.descriptorToDeclaration(callableDescriptor)
|
||||||
|
|
||||||
if (!(element is KtNamedFunction || element is KtPropertyAccessor)) {
|
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?
|
val inliningFunction = element as KtDeclarationWithBody?
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
|
|
||||||
//for maxLocals calculation
|
//for maxLocals calculation
|
||||||
val maxCalcAdapter = wrapWithMaxLocalCalc(node)
|
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 methodContext = parentContext.intoFunction(callableDescriptor)
|
||||||
|
|
||||||
val smap = if (callDefault) {
|
val smap = if (callDefault) {
|
||||||
@@ -286,7 +286,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
if (element !is KtNamedFunction) {
|
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(
|
FunctionCodegen.generateDefaultImplBody(
|
||||||
methodContext, callableDescriptor, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
|
methodContext, callableDescriptor, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
|
||||||
@@ -416,7 +416,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
return PackageContext(descriptor, state.rootContext, null, sourceFile)
|
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(
|
val parent = getContext(
|
||||||
container,
|
container,
|
||||||
descriptor,
|
descriptor,
|
||||||
@@ -454,7 +454,7 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
|
|||||||
parent.intoFunction(descriptor)
|
parent.intoFunction(descriptor)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
throw IllegalStateException("Couldn't build context for " + descriptor)
|
throw IllegalStateException("Couldn't build context for $descriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ fun initDefaultSourceMappingIfNeeded(
|
|||||||
) {
|
) {
|
||||||
if (state.isInlineDisabled) return
|
if (state.isInlineDisabled) return
|
||||||
|
|
||||||
|
|
||||||
var parentContext: CodegenContext<*>? = context.parentContext
|
var parentContext: CodegenContext<*>? = context.parentContext
|
||||||
while (parentContext != null) {
|
while (parentContext != null) {
|
||||||
if (parentContext.isInlineMethodContext) {
|
if (parentContext.isInlineMethodContext) {
|
||||||
|
|||||||
+17
-7
@@ -40,7 +40,8 @@ class JvmDeclarationOrigin(
|
|||||||
val descriptor: DeclarationDescriptor?
|
val descriptor: DeclarationDescriptor?
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val NO_ORIGIN: JvmDeclarationOrigin = JvmDeclarationOrigin(OTHER, null, null)
|
@JvmField
|
||||||
|
val NO_ORIGIN: JvmDeclarationOrigin = JvmDeclarationOrigin(OTHER, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,30 +58,39 @@ fun OtherOriginFromPure(element: KtPureElement?, descriptor: DeclarationDescript
|
|||||||
|
|
||||||
fun OtherOrigin(descriptor: DeclarationDescriptor) = JvmDeclarationOrigin(OTHER, null, descriptor)
|
fun OtherOrigin(descriptor: DeclarationDescriptor) = JvmDeclarationOrigin(OTHER, null, descriptor)
|
||||||
|
|
||||||
fun Bridge(descriptor: DeclarationDescriptor, element: PsiElement? = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)): JvmDeclarationOrigin =
|
fun Bridge(
|
||||||
|
descriptor: DeclarationDescriptor,
|
||||||
|
element: PsiElement? = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
|
||||||
|
): JvmDeclarationOrigin =
|
||||||
JvmDeclarationOrigin(BRIDGE, element, descriptor)
|
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)
|
* @param representativeFile one of the files representing this multifile class (will be used for diagnostics)
|
||||||
*/
|
*/
|
||||||
fun MultifileClass(representativeFile: KtFile?, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
|
fun MultifileClass(representativeFile: KtFile?, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
|
||||||
JvmDeclarationOrigin(MULTIFILE_CLASS, representativeFile, descriptor)
|
JvmDeclarationOrigin(MULTIFILE_CLASS, representativeFile, descriptor)
|
||||||
|
|
||||||
fun MultifileClassPart(file: KtFile, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin =
|
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 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)
|
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 =
|
fun ErasedInlineClassOrigin(element: PsiElement?, descriptor: ClassDescriptor): JvmDeclarationOrigin =
|
||||||
JvmDeclarationOrigin(ERASED_INLINE_CLASS, element, descriptor)
|
JvmDeclarationOrigin(ERASED_INLINE_CLASS, element, descriptor)
|
||||||
|
|||||||
+17
-13
@@ -85,8 +85,7 @@ open class IrIntrinsicFunction(
|
|||||||
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue {
|
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue {
|
||||||
val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) +
|
val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) +
|
||||||
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
|
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
|
||||||
expression.getValueArgument(i) ?:
|
expression.getValueArgument(i) ?: if (descriptor.isVararg)
|
||||||
if (descriptor.isVararg)
|
|
||||||
IrEmptyVarargExpression(descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
IrEmptyVarargExpression(descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||||
else error("Unknown parameter: $descriptor in $expression")
|
else error("Unknown parameter: $descriptor in $expression")
|
||||||
}
|
}
|
||||||
@@ -98,8 +97,7 @@ open class IrIntrinsicFunction(
|
|||||||
it.aconst(0)
|
it.aconst(0)
|
||||||
it.newarray(AsmUtil.correctElementType(parameterType))
|
it.newarray(AsmUtil.correctElementType(parameterType))
|
||||||
}.put(parameterType, codegen.mv)
|
}.put(parameterType, codegen.mv)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
genArg(irExpression, codegen, i, data)
|
genArg(irExpression, codegen, i, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,33 +109,39 @@ open class IrIntrinsicFunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun create(expression: IrMemberAccessExpression,
|
fun create(
|
||||||
|
expression: IrMemberAccessExpression,
|
||||||
signature: JvmMethodSignature,
|
signature: JvmMethodSignature,
|
||||||
context: JvmBackendContext,
|
context: JvmBackendContext,
|
||||||
argsTypes: List<Type> = expression.argTypes(context),
|
argsTypes: List<Type> = expression.argTypes(context),
|
||||||
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
|
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
|
||||||
|
): IrIntrinsicFunction {
|
||||||
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
|
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,
|
fun createWithResult(
|
||||||
|
expression: IrMemberAccessExpression,
|
||||||
signature: JvmMethodSignature,
|
signature: JvmMethodSignature,
|
||||||
context: JvmBackendContext,
|
context: JvmBackendContext,
|
||||||
argsTypes: List<Type> = expression.argTypes(context),
|
argsTypes: List<Type> = expression.argTypes(context),
|
||||||
invokeInstuction: IrIntrinsicFunction.(InstructionAdapter) -> Type): IrIntrinsicFunction {
|
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Type
|
||||||
|
): IrIntrinsicFunction {
|
||||||
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
|
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,
|
fun create(
|
||||||
|
expression: IrMemberAccessExpression,
|
||||||
signature: JvmMethodSignature,
|
signature: JvmMethodSignature,
|
||||||
context: JvmBackendContext,
|
context: JvmBackendContext,
|
||||||
type: Type,
|
type: Type,
|
||||||
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit): IrIntrinsicFunction {
|
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
|
||||||
|
): IrIntrinsicFunction {
|
||||||
return create(expression, signature, context, listOf(type), invokeInstruction)
|
return create(expression, signature, context, listOf(type), invokeInstruction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +157,7 @@ fun IrMemberAccessExpression.argTypes(context: JvmBackendContext): ArrayList<Typ
|
|||||||
|
|
||||||
fun IrMemberAccessExpression.receiverAndArgs(): List<IrExpression> {
|
fun IrMemberAccessExpression.receiverAndArgs(): List<IrExpression> {
|
||||||
return (arrayListOf(this.dispatchReceiver, this.extensionReceiver) +
|
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> {
|
fun List<IrExpression>.asmTypes(context: JvmBackendContext): List<Type> {
|
||||||
|
|||||||
Reference in New Issue
Block a user