Freeze objects by default, stdlib improvements. (#1743)
This commit is contained in:
+1
-1
@@ -686,7 +686,7 @@ internal class FunctionGenerationContext(val function: LLVMValueRef,
|
||||
|
||||
positionAtEnd(bbInit)
|
||||
val typeInfo = codegen.typeInfoForAllocation(descriptor)
|
||||
val defaultConstructor = descriptor.constructors.first { it.valueParameters.size == 0 }
|
||||
val defaultConstructor = descriptor.constructors.single { it.valueParameters.size == 0 }
|
||||
val ctor = codegen.llvmFunction(defaultConstructor)
|
||||
val (initFunction, args) =
|
||||
if (shared) {
|
||||
|
||||
+8
-2
@@ -38,13 +38,19 @@ import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
|
||||
val IrClassSymbol.objectIsShared get() = owner.origin == DECLARATION_ORIGIN_ENUM
|
||||
private val threadLocalAnnotationFqName = FqName("konan.ThreadLocal")
|
||||
|
||||
val IrClassSymbol.objectIsShared get() =
|
||||
!owner.hasAnnotation(threadLocalAnnotationFqName)
|
||||
|
||||
internal fun emitLLVM(context: Context) {
|
||||
val irModule = context.irModule!!
|
||||
@@ -2662,4 +2668,4 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
||||
|
||||
internal data class LocationInfo(val scope:DIScopeOpaqueRef,
|
||||
val line:Int,
|
||||
val column:Int)
|
||||
val column:Int)
|
||||
|
||||
-1
@@ -562,7 +562,6 @@ internal class EnumClassLowering(val context: Context) : ClassLoweringPass {
|
||||
result.putValueArgument(1,
|
||||
IrGetValueImpl(startOffset, endOffset, ordinalParameter.type, ordinalParameter.symbol, origin)
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -155,7 +155,8 @@ internal class InitializersLowering(val context: CommonBackendContext) : ClassLo
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor): IrStatement {
|
||||
val blockBody = declaration.body as? IrBlockBody ?: throw AssertionError("Unexpected constructor body: ${declaration.body}")
|
||||
val blockBody = declaration.body as? IrBlockBody
|
||||
?: throw AssertionError("Unexpected constructor body: ${declaration.body}")
|
||||
|
||||
blockBody.statements.transformFlat {
|
||||
when {
|
||||
|
||||
@@ -671,6 +671,12 @@ task freeze2(type: RunKonanTest) {
|
||||
source = "runtime/workers/freeze2.kt"
|
||||
}
|
||||
|
||||
task freeze3(type: RunKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // No exceptions on WASM.
|
||||
goldValue = "OK\n"
|
||||
source = "runtime/workers/freeze3.kt"
|
||||
}
|
||||
|
||||
task atomic0(type: RunKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // Workers need pthreads.
|
||||
goldValue = "35\n" + "20\n" + "OK\n"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package runtime.workers.freeze3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import konan.worker.*
|
||||
|
||||
object Immutable {
|
||||
var x = 1
|
||||
}
|
||||
|
||||
@konan.ThreadLocal
|
||||
object Mutable {
|
||||
var x = 2
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals(1, Immutable.x)
|
||||
assertFailsWith<InvalidMutabilityException> {
|
||||
Immutable.x++
|
||||
}
|
||||
assertEquals(1, Immutable.x)
|
||||
Mutable.x++
|
||||
assertEquals(3, Mutable.x)
|
||||
println("OK")
|
||||
}
|
||||
Reference in New Issue
Block a user