Skip to content

Commit

Permalink
[stdlib and samples][rename] konan -> kotlin.native
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko committed Aug 14, 2018
1 parent 5ad0012 commit 79755d8
Show file tree
Hide file tree
Showing 155 changed files with 294 additions and 282 deletions.
4 changes: 2 additions & 2 deletions Interop/JsRuntime/src/main/kotlin/jsinterop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

package kotlinx.wasm.jsinterop

import konan.internal.ExportForCppRuntime
import kotlin.native.*
import kotlin.native.internal.ExportForCppRuntime
import kotlinx.cinterop.*

typealias Arena = Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package kotlinx.cinterop

import konan.internal.Intrinsic
import konan.internal.ExportForCompiler
import kotlin.native.internal.Intrinsic
import kotlin.native.internal.ExportForCompiler

@Intrinsic external operator fun <R> CPointer<CFunction<() -> R>>.invoke(): R

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package kotlinx.cinterop

import konan.internal.Intrinsic
import kotlin.native.*
import kotlin.native.internal.Intrinsic

@PublishedApi
internal inline val pointerSize: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package kotlinx.cinterop
import kotlin.native.*

@SymbolName("Kotlin_Interop_createStablePointer")
internal external fun createStablePointer(any: Any): COpaquePointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package kotlinx.cinterop

import konan.internal.getNativeNullPtr
import konan.internal.Intrinsic
import konan.internal.reinterpret
import kotlin.native.internal.getNativeNullPtr
import kotlin.native.internal.Intrinsic
import kotlin.native.internal.reinterpret

typealias NativePtr = konan.internal.NativePtr
internal typealias NonNullNativePtr = konan.internal.NonNullNativePtr
typealias NativePtr = kotlin.native.internal.NativePtr
internal typealias NonNullNativePtr = kotlin.native.internal.NonNullNativePtr

@Suppress("NOTHING_TO_INLINE")
internal inline fun NativePtr.toNonNull() = this.reinterpret<NativePtr, NonNullNativePtr>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package kotlinx.cinterop

import konan.internal.Intrinsic
import kotlin.native.internal.Intrinsic

internal fun decodeFromUtf8(bytes: ByteArray): String = bytes.stringFromUtf8()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
@file:Suppress("NOTHING_TO_INLINE")

package kotlinx.cinterop
import kotlin.native.*

interface ObjCObject
interface ObjCClass : ObjCObject
interface ObjCClassOf<T : ObjCObject> : ObjCClass // TODO: T should be added to ObjCClass and all meta-classes instead.
typealias ObjCObjectMeta = ObjCClass

@ExportTypeInfo("theForeignObjCObjectTypeInfo")
internal open class ForeignObjCObject : konan.internal.ObjCObjectWrapper
internal open class ForeignObjCObject : kotlin.native.internal.ObjCObjectWrapper

abstract class ObjCObjectBase protected constructor() : ObjCObject {
@Target(AnnotationTarget.CONSTRUCTOR)
Expand All @@ -39,10 +40,10 @@ fun optional(): Nothing = throw RuntimeException("Do not call me!!!")
"Add @OverrideInit to constructor to make it override Objective-C initializer",
level = DeprecationLevel.WARNING
)
@konan.internal.Intrinsic
@kotlin.native.internal.Intrinsic
external fun <T : ObjCObjectBase> T.initBy(constructorCall: T): T

@konan.internal.ExportForCompiler
@kotlin.native.internal.ExportForCompiler
private fun ObjCObjectBase.superInitCheck(superInitCallResult: ObjCObject?) {
if (superInitCallResult == null)
throw RuntimeException("Super initialization failed")
Expand Down Expand Up @@ -88,7 +89,7 @@ var <T : Any?> ObjCNotImplementedVar<T>.value: T
typealias ObjCStringVarOf<T> = ObjCNotImplementedVar<T>
typealias ObjCBlockVar<T> = ObjCNotImplementedVar<T>

@konan.internal.Intrinsic external fun getReceiverOrSuper(receiver: NativePtr, superClass: NativePtr): COpaquePointer?
@kotlin.native.internal.Intrinsic external fun getReceiverOrSuper(receiver: NativePtr, superClass: NativePtr): COpaquePointer?

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
Expand Down Expand Up @@ -118,7 +119,7 @@ annotation class InteropStubs()
@Retention(AnnotationRetention.SOURCE)
private annotation class ObjCMethodImp(val selector: String, val encoding: String)

@konan.internal.ExportForCppRuntime("Kotlin_Interop_getObjCClass")
@kotlin.native.internal.ExportForCppRuntime("Kotlin_Interop_getObjCClass")
private fun getObjCClassByName(name: NativePtr): NativePtr {
val result = objc_lookUpClass(name)
if (result == nativeNullPtr) {
Expand All @@ -131,7 +132,7 @@ private fun getObjCClassByName(name: NativePtr): NativePtr {
return result
}

@konan.internal.ExportForCompiler
@kotlin.native.internal.ExportForCompiler
private fun allocObjCObject(clazz: NativePtr): NativePtr {
val rawResult = objc_allocWithZone(clazz)
if (rawResult == nativeNullPtr) {
Expand All @@ -143,22 +144,23 @@ private fun allocObjCObject(clazz: NativePtr): NativePtr {
return rawResult
}

@konan.internal.Intrinsic
@konan.internal.ExportForCompiler
@kotlin.native.internal.Intrinsic
@kotlin.native.internal.ExportForCompiler
private external fun <T : ObjCObject> getObjCClass(): NativePtr

@konan.internal.Intrinsic external fun getMessenger(superClass: NativePtr): COpaquePointer?
@konan.internal.Intrinsic external fun getMessengerStret(superClass: NativePtr): COpaquePointer?
@kotlin.native.internal.Intrinsic external fun getMessenger(superClass: NativePtr): COpaquePointer?
@kotlin.native.internal.Intrinsic external fun getMessengerStret(superClass: NativePtr): COpaquePointer?

internal class ObjCWeakReferenceImpl : konan.ref.WeakReferenceImpl() {

internal class ObjCWeakReferenceImpl : kotlin.native.ref.WeakReferenceImpl() {
@SymbolName("Konan_ObjCInterop_getWeakReference")
external override fun get(): Any?
}

@SymbolName("Konan_ObjCInterop_initWeakReference")
private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr)

@konan.internal.ExportForCppRuntime internal fun makeObjCWeakReferenceImpl(objcPtr: NativePtr): ObjCWeakReferenceImpl {
@kotlin.native.internal.ExportForCppRuntime internal fun makeObjCWeakReferenceImpl(objcPtr: NativePtr): ObjCWeakReferenceImpl {
val result = ObjCWeakReferenceImpl()
result.init(objcPtr)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package kotlinx.cinterop
import kotlin.native.*

data class Pinned<out T : Any> internal constructor(private val stablePtr: COpaquePointer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package kotlinx.cinterop
import kotlin.native.*

private const val MAX_ARGUMENT_SIZE = 8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ObjCMethodStub(private val stubGenerator: StubGenerator,
}

context.addTopLevelDeclaration(
listOf("@konan.internal.ExportForCompiler",
listOf("@kotlin.native.internal.ExportForCompiler",
"@ObjCBridge".applyToStrings(method.selector, method.encoding, implementationTemplate))
+ block(bridgeHeader, bodyLines)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SimpleBridgeGeneratorImpl(
val cReturnType = returnType.nativeType

val symbolName = pkgName.replace(INVALID_CLANG_IDENTIFIER_REGEX, "_") + "_$kotlinFunctionName"
kotlinLines.add("@konan.internal.ExportForCppRuntime(${symbolName.quoteAsKotlinLiteral()})")
kotlinLines.add("@kotlin.native.internal.ExportForCppRuntime(${symbolName.quoteAsKotlinLiteral()})")
val cFunctionHeader = "$cReturnType $symbolName($joinedCParameters)"

nativeLines.add("$cFunctionHeader;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ class StubGenerator(
out("")
}
if (platform == KotlinPlatform.NATIVE) {
out("import konan.SymbolName")
out("import kotlin.native.SymbolName")
}
out("import kotlinx.cinterop.*")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private val cKeywords = setOf(
"xor_eq"
)

private val cnameAnnotation = FqName("konan.internal.CName")
private val cnameAnnotation = FqName("kotlin.native.internal.CName")

private fun org.jetbrains.kotlin.types.KotlinType.isGeneric() =
constructor.declarationDescriptor is TypeParameterDescriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
moduleDescriptor.builtIns as KonanBuiltIns
}

private val packageScope by lazy { builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope }
private val packageScope by lazy { builtIns.builtInsModule.getPackage(KonanFqNames.internalPackageName).memberScope }

val nativePtr by lazy { packageScope.getContributedClassifier(NATIVE_PTR_NAME) as ClassDescriptor }
val nativePtrPlusLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("plus").single() }
val nativePtrToLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("toLong").single() }
val getNativeNullPtr by lazy { packageScope.getContributedFunctions("getNativeNullPtr").single() }
val immutableBinaryBlobOf by lazy {
builtIns.builtInsModule.getPackage(FqName("konan")).memberScope.getContributedFunctions("immutableBinaryBlobOf").single()
builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope.getContributedFunctions("immutableBinaryBlobOf").single()
}

val specialDeclarationsFactory = SpecialDeclarationsFactory(this)
Expand All @@ -319,7 +319,7 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
@Suppress("UNCHECKED_CAST") (lazyValues.getOrPut(member, { member.initializer(this) }) as T)

override val reflectionTypes: ReflectionTypes by lazy(PUBLICATION) {
ReflectionTypes(moduleDescriptor, FqName("konan.internal"))
ReflectionTypes(moduleDescriptor, KonanFqNames.internalPackageName)
}
private val vtableBuilders = mutableMapOf<IrClass, ClassVtablesBuilder>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ private val implicitInlineClasses =

private enum class ValueClass(val fqName: FqNameUnsafe, val binaryType: BinaryType.Primitive) {

BOOLEAN("konan.internal.BooleanValue", PrimitiveBinaryType.BOOLEAN),
BYTE("konan.internal.ByteValue", PrimitiveBinaryType.BYTE),
SHORT("konan.internal.ShortValue", PrimitiveBinaryType.SHORT),
INT("konan.internal.IntValue", PrimitiveBinaryType.INT),
LONG("konan.internal.LongValue", PrimitiveBinaryType.LONG),
FLOAT("konan.internal.FloatValue", PrimitiveBinaryType.FLOAT),
DOUBLE("konan.internal.DoubleValue", PrimitiveBinaryType.DOUBLE),
NON_NULL_POINTER("konan.internal.NotNullPointerValue", PrimitiveBinaryType.POINTER)
BOOLEAN("kotlin.native.internal.BooleanValue", PrimitiveBinaryType.BOOLEAN),
BYTE("kotlin.native.internal.ByteValue", PrimitiveBinaryType.BYTE),
SHORT("kotlin.native.internal.ShortValue", PrimitiveBinaryType.SHORT),
INT("kotlin.native.internal.IntValue", PrimitiveBinaryType.INT),
LONG("kotlin.native.internal.LongValue", PrimitiveBinaryType.LONG),
FLOAT("kotlin.native.internal.FloatValue", PrimitiveBinaryType.FLOAT),
DOUBLE("kotlin.native.internal.DoubleValue", PrimitiveBinaryType.DOUBLE),
NON_NULL_POINTER("kotlin.native.internal.NotNullPointerValue", PrimitiveBinaryType.POINTER)

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns, vararg konanPrimitives:

val staticCFunction = packageScope.getContributedFunctions("staticCFunction").toSet()

val workerPackageScope = builtIns.builtInsModule.getPackage(FqName("konan.worker")).memberScope
val workerPackageScope = builtIns.builtInsModule.getPackage(FqName("kotlin.native.worker")).memberScope

val scheduleFunction = workerPackageScope.getContributedClass("Worker")
.unsubstitutedMemberScope.getContributedFunctions("schedule").single()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.backend.konan

import org.jetbrains.kotlin.backend.common.CommonBackendContext
import org.jetbrains.kotlin.backend.konan.descriptors.KonanSharedVariablesManager
import org.jetbrains.kotlin.backend.konan.descriptors.konanInternal
import org.jetbrains.kotlin.backend.konan.descriptors.kotlinNativeInternal
import org.jetbrains.kotlin.backend.konan.ir.KonanIr
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
Expand All @@ -44,10 +44,10 @@ abstract internal class KonanBackendContext(val config: KonanConfig) : CommonBac
}

override fun getInternalClass(name: String): ClassDescriptor =
builtIns.konanInternal.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
builtIns.kotlinNativeInternal.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND) as ClassDescriptor

override fun getInternalFunctions(name: String): List<FunctionDescriptor> =
builtIns.konanInternal.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).toList()
builtIns.kotlinNativeInternal.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).toList()

val messageCollector: MessageCollector
get() = config.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ internal const val NATIVE_PTR_NAME = "NativePtr"

object KonanFqNames {

val packageName = FqName("konan.internal")
val nativePtr = packageName.child(Name.identifier(NATIVE_PTR_NAME)).toUnsafe()
val nonNullNativePtr = FqNameUnsafe("konan.internal.NonNullNativePtr")
val throws = FqName("konan.Throws")
val packageName = FqName("kotlin.native")
val internalPackageName = FqName("kotlin.native.internal")
val nativePtr = internalPackageName.child(Name.identifier(NATIVE_PTR_NAME)).toUnsafe()
val nonNullNativePtr = FqNameUnsafe("kotlin.native.internal.NonNullNativePtr")
val throws = FqName("kotlin.native.Throws")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ internal fun IrSimpleFunction.resolveFakeOverride(): IrSimpleFunction {
return realSupers.first { it.modality != Modality.ABSTRACT }
}

private val intrinsicAnnotation = FqName("konan.internal.Intrinsic")
private val frozenAnnotation = FqName("konan.internal.Frozen")
private val intrinsicAnnotation = FqName("kotlin.native.internal.Intrinsic")
private val frozenAnnotation = FqName("kotlin.native.internal.Frozen")

// TODO: don't forget to remove descriptor access here.
internal val FunctionDescriptor.isIntrinsic: Boolean
Expand All @@ -108,7 +108,7 @@ internal val arrayTypes = setOf(
"kotlin.FloatArray",
"kotlin.DoubleArray",
"kotlin.BooleanArray",
"konan.ImmutableBinaryBlob"
"kotlin.native.ImmutableBinaryBlob"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ internal val ClassDescriptor.isArray: Boolean
internal val ClassDescriptor.isInterface: Boolean
get() = (this.kind == ClassKind.INTERFACE)

private val konanInternalPackageName = FqName.fromSegments(listOf("konan", "internal"))
private val kotlinNativeInternalPackageName = FqName.fromSegments(listOf("kotlin", "native", "internal"))

/**
* @return `konan.internal` member scope
*/
internal val KonanBuiltIns.konanInternal: MemberScope
get() = this.builtInsModule.getPackage(konanInternalPackageName).memberScope
internal val KonanBuiltIns.kotlinNativeInternal: MemberScope
get() = this.builtInsModule.getPackage(kotlinNativeInternalPackageName).memberScope

internal val KotlinType.isKFunctionType: Boolean
get() {
Expand Down Expand Up @@ -137,7 +137,7 @@ internal fun DeclarationDescriptor.allContainingDeclarations(): List<Declaration
// since externals don't have IR bodies.
// Enforce inlining of constructors annotated with @InlineConstructor.

private val inlineConstructor = FqName("konan.internal.InlineConstructor")
private val inlineConstructor = FqName("kotlin.native.internal.InlineConstructor")

internal val FunctionDescriptor.needsInlining: Boolean
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.backend.common.COROUTINE_SUSPENDED_NAME
import org.jetbrains.kotlin.backend.common.ir.Ir
import org.jetbrains.kotlin.backend.common.ir.Symbols
import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.descriptors.konanInternal
import org.jetbrains.kotlin.backend.konan.descriptors.kotlinNativeInternal
import org.jetbrains.kotlin.backend.konan.llvm.findMainEntryPoint
import org.jetbrains.kotlin.backend.konan.lower.TestProcessor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
Expand Down Expand Up @@ -173,7 +173,7 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
symbolTable.referenceSimpleFunction(context.interopBuiltIns.CreateNSStringFromKString)

val objCExportTrapOnUndeclaredException =
symbolTable.referenceSimpleFunction(context.builtIns.konanInternal.getContributedFunctions(
symbolTable.referenceSimpleFunction(context.builtIns.kotlinNativeInternal.getContributedFunctions(
Name.identifier("trapOnUndeclaredException"),
NoLookupLocation.FROM_BACKEND
).single())
Expand All @@ -191,7 +191,7 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
}

val immutableBinaryBlob = symbolTable.referenceClass(
builtInsPackage("konan").getContributedClassifier(
builtInsPackage("kotlin", "native").getContributedClassifier(
Name.identifier("ImmutableBinaryBlob"), NoLookupLocation.FROM_BACKEND
) as ClassDescriptor
)
Expand Down Expand Up @@ -301,7 +301,7 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
context.getInternalFunctions("initInstance").single())

val freeze = symbolTable.referenceSimpleFunction(
builtInsPackage("konan", "worker").getContributedFunctions(Name.identifier("freeze"), NoLookupLocation.FROM_BACKEND).single())
builtInsPackage("kotlin", "native", "worker").getContributedFunctions(Name.identifier("freeze"), NoLookupLocation.FROM_BACKEND).single())

val println = symbolTable.referenceSimpleFunction(
builtInsPackage("kotlin", "io").getContributedFunctions(Name.identifier("println"), NoLookupLocation.FROM_BACKEND)
Expand Down Expand Up @@ -363,7 +363,7 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
symbolTable.referenceClass(context.getInternalClass(name))

private fun getKonanTestClass(className: String) = symbolTable.referenceClass(
builtInsPackage("konan", "test").getContributedClassifier(
builtInsPackage("kotlin", "native", "test").getContributedClassifier(
Name.identifier(className), NoLookupLocation.FROM_BACKEND
) as ClassDescriptor)

Expand Down
Loading

0 comments on commit 79755d8

Please sign in to comment.