Skip to content

Commit 6ee3e6b

Browse files
authored
Merge pull request #422 from thisisthepy/feat/klib-scanner-a3
Feat: bind klib constructors, object members, member properties, and cross-klib handles (SPEC B-2, #191)
2 parents 049fed7 + 667a757 commit 6ee3e6b

10 files changed

Lines changed: 1204 additions & 121 deletions

File tree

‎docs/SPEC.md‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -473,31 +473,40 @@ All in `PM/commonTest`, so they run wherever the interpreter loads.
473473
declined (#73). `Status: implemented`, `GP/artifact/TextStateBindingTest.kt`,
474474
`python-multiplatform-compose/fixtures/compose/.../TextFieldStateRenderTest.kt`.
475475
- **B-2** The walker on **klibs** (Kotlin/Native libraries). `Status: partial`. It reads
476-
top-level functions and, since #237, the **member functions** of the klib's classes; no class
477-
constructor or property yet. A member binds as #215's `METHOD` `Owner.name` (receiver in `args[0]`,
478-
`(args[0] as Owner).name(...)`, served on the proxy, never a module attribute) when its class can
479-
cross as a handle and is an interface, a final class or an enum class: the pinned compiler's klib
480-
ABI records modality but no visibility, so a member of an open, abstract or sealed class, which
481-
may be `protected`, is declined with that reason, and an `object`'s functions (statics on the jar
482-
side, #53) are declined too. Also declined, with reasons: members of a generic class, `suspend`,
483-
`@Deprecated`, `@PublishedApi`, `@Composable`, member extensions and context receivers, a member
476+
top-level functions, **member functions** (#237), **member properties** (`GETTER` and `SETTER`),
477+
**constructors** of final classes, and **`object` / `Companion` handles, constants (`STATIC_GETTER`)
478+
and functions (`FUNCTION`)** (#191 Phase B). A member function binds as #215's `METHOD` `Owner.name`
479+
(receiver in `args[0]`, `(args[0] as Owner).name(...)`, served on the proxy, never a module attribute)
480+
and a member property binds as #38's `GETTER` `Owner.prop` (and `SETTER` `Owner.prop=` when writable)
481+
when its class can cross as a handle and is an interface, a final class or an enum class: the pinned
482+
compiler's klib ABI records modality but no visibility, so a member or constructor of an open,
483+
abstract or sealed class, which may be `protected`, is declined with that reason. An `object`'s
484+
constants and functions bind under the object's qualified name (`Dispatchers.Default`,
485+
`NonDisposableHandle.dispose`), and a nested `Companion` object binds its singleton handle as
486+
`Owner.Companion` (`isCompanionHandle = true`) and its constants and factory functions under `Owner`
487+
(`SharingStarted.Eagerly`, `SharingStarted.WhileSubscribed`). Also declined, with reasons: members of
488+
a generic class, `suspend`, `@Deprecated`, `@PublishedApi` (including declarations inside an
489+
`@PublishedApi internal` class), `@Composable`, member extensions and context receivers, a member
484490
named like a property, data-class `copy`/`componentN`, and anything without a klib boundary type;
485491
`Any`'s members and an enum's static `valueOf`/`values`/`entries` are not bound. From
486-
`kotlinx-coroutines-core` this binds `CompletableJob.complete`, `Job.start`,
487-
`Semaphore.tryAcquire`/`release` and others; `GP/artifact/KlibMemberFunctionTest.kt`, and on the iOS
488-
simulator `WalkedKlibArtifactMemberFunctionTest`.
492+
`kotlinx-coroutines-core` this binds `CompletableJob.complete`, `Job.start`, `Job.isActive`,
493+
`CoroutineName`, `CoroutineName.name`, `Dispatchers.Default`, `SharingStarted.Eagerly`,
494+
`Semaphore.availablePermits`, `Semaphore.tryAcquire`/`release` and others;
495+
`GP/artifact/KlibMemberFunctionTest.kt`, `GP/artifact/KlibClassAndObjectBindingTest.kt`, and on the
496+
iOS simulator `WalkedKlibArtifactMemberFunctionTest`.
489497
Since #234 a **Kotlin object crosses as a handle**: a type whose class is a public, non-generic,
490-
non-value `class`, `interface`, `enum class` or `object` of the walked klib is an `OBJECT` slot
491-
or result, non-null or nullable, cast in generated source as the jar producer casts one, and a
492-
handle result carries its ancestry from the klib's supertypes. Handles are the common
493-
trampoline's and `HandleTable`'s, under the jar side's rules: passing one back into Kotlin takes
494-
no second slot, and dropping it releases it exactly once. Still declined, each with its reason:
495-
a type of another klib (`kotlin.coroutines.CoroutineContext`), a class of package `kotlin` other
496-
than the boundary's primitives, an extension (the pinned compiler's klib ABI has no receiver type),
497-
and any `@Deprecated` declaration (the ABI has no level, and a `HIDDEN` one, such as
498+
non-value `class`, `interface`, `enum class` or `object` of the walked klib (or of any `.klib` on its
499+
resolved `classpath`, #191 Phase B) is an `OBJECT` slot or result, non-null or nullable, cast in
500+
generated source as the jar producer casts one, and a handle result carries its ancestry from the
501+
klib classpath's supertypes. Handles are the common trampoline's and `HandleTable`'s, under the jar
502+
side's rules: passing one back into Kotlin takes no second slot, and dropping it releases it exactly
503+
once. Still declined, each with its reason: a type not on the klib `classpath`, a class of package
504+
`kotlin` other than the boundary's primitives, an extension (the pinned compiler's klib ABI has no
505+
receiver type), and any `@Deprecated` declaration (the ABI has no level, and a `HIDDEN` one, such as
498506
`kotlinx.coroutines.Job0`, cannot be called from source). From `kotlinx-coroutines-core` this binds
499507
`Job`, `SupervisorJob`, `MainScope`, `Mutex`, `Semaphore`, `newSingleThreadContext` and
500-
`newFixedThreadPoolContext`. `GP/artifact/KlibScannerTest.kt`, `GP/artifact/KlibObjectHandleTest.kt`;
508+
`newFixedThreadPoolContext`. `GP/artifact/KlibScannerTest.kt`, `GP/artifact/KlibObjectHandleTest.kt`,
509+
`GP/artifact/KlibClassAndObjectBindingTest.kt`;
501510
`python-multiplatform-gradle-plugin/fixtures/klib-artifact` builds `androidNativeArm64` and
502511
`iosSimulatorArm64` from one table in `nativeMain`, and its suite (`WalkedKlibArtifactHandleTest`,
503512
`WalkedKlibArtifactTableTest`, `WalkedKlibArtifactPythonImportTest`) runs through Gradle on the iOS

0 commit comments

Comments
 (0)