Fixed bugs with contracts DSL
This commit is contained in:
+2
@@ -70,6 +70,8 @@ internal class KonanLower(val context: Context) {
|
|||||||
|
|
||||||
phaser.phase(KonanPhase.LOWER_AFTER_INLINE) {
|
phaser.phase(KonanPhase.LOWER_AFTER_INLINE) {
|
||||||
irModule.files.forEach(PostInlineLowering(context)::lower)
|
irModule.files.forEach(PostInlineLowering(context)::lower)
|
||||||
|
// TODO: Seems like this should be deleted in PsiToIR.
|
||||||
|
irModule.files.forEach(ContractsDslRemover(context)::lower)
|
||||||
}
|
}
|
||||||
|
|
||||||
phaser.phase(KonanPhase.LOWER_INTEROP_PART1) {
|
phaser.phase(KonanPhase.LOWER_INTEROP_PART1) {
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.konan.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||||
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
|
import org.jetbrains.kotlin.contracts.parsing.ContractsDslNames
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer
|
||||||
|
import org.jetbrains.kotlin.ir.util.transformFlat
|
||||||
|
|
||||||
|
internal class ContractsDslRemover(val context: Context) : DeclarationContainerLoweringPass {
|
||||||
|
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||||
|
irDeclarationContainer.declarations.transformFlat {
|
||||||
|
if (it is IrClass && it.descriptor.annotations.hasAnnotation(ContractsDslNames.CONTRACTS_DSL_ANNOTATION_FQN))
|
||||||
|
null
|
||||||
|
else
|
||||||
|
listOf(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.backend.konan.llvm.localHash
|
import org.jetbrains.kotlin.backend.konan.llvm.localHash
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.contracts.parsing.ContractsDslNames
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -107,6 +108,11 @@ val IrBuiltIns.irBuiltInDescriptors
|
|||||||
internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||||
assert(!this.isExpectMember) { this }
|
assert(!this.isExpectMember) { this }
|
||||||
|
|
||||||
|
if (this.annotations.findAnnotation(ContractsDslNames.CONTRACTS_DSL_ANNOTATION_FQN) != null) {
|
||||||
|
// TODO: Seems like this should be deleted in PsiToIR.
|
||||||
|
// Treat any `@ContractsDsl` declaration as exported.
|
||||||
|
return true
|
||||||
|
}
|
||||||
if (this.annotations.findAnnotation(symbolNameAnnotation) != null) {
|
if (this.annotations.findAnnotation(symbolNameAnnotation) != null) {
|
||||||
// Treat any `@SymbolName` declaration as exported.
|
// Treat any `@SymbolName` declaration as exported.
|
||||||
return true
|
return true
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
descriptorIndex[index]!!
|
descriptorIndex[index]!!
|
||||||
CLASS, CONSTRUCTOR, FUNCTION, ACCESSOR ->
|
CLASS, CONSTRUCTOR, FUNCTION, ACCESSOR ->
|
||||||
descriptorIndex[index] ?:
|
descriptorIndex[index] ?:
|
||||||
findInTheDescriptorTree(proto)!! // Note: can be null when using `@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")`
|
findInTheDescriptorTree(proto) ?: error("${proto.name} is not found") // Note: can be null when using `@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")`
|
||||||
else -> TODO("Unexpected descriptor kind: $kind")
|
else -> TODO("Unexpected descriptor kind: $kind")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user