Skip to content

Test: compiled TypedPython calls Kotlin in the embedded runtime (#45) - #102

Merged
b-re-w merged 1 commit into
developfrom
work/m2b-45
Oct 3, 2026
Merged

b-re-w merged 1 commit into
developfrom
work/m2b-45

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 3, 2026

Copy link
Copy Markdown
Member

Refs #45. This doesn't close it: the leak criterion is blocked by #98.

Test added

An embedded-runtime test in ksp-fixtures/app: compiled TypedPython code calls Kotlin through the binder.

  • The buildTypedPythonBridge task builds a # typedpython: compiled module with pipeline.compile_module against the embedded CPython 3.14 headers. It uses the cpythonIncludeDirectories provider and reads EXT_SUFFIX from the extracted tree's sysconfigdata.
  • The compiled code constructs a TpSample Kotlin proxy, calls its method, passes it back to Kotlin, passes a Python token to Kotlin, and loops with float math around the calls.

Results, all in the JVM:

  • pass — the build/ABI premise: interpreter version, suffix and flavour match, and the compiled functions are C functions;
  • pass — results identical to interpreted (float.hex), and Kotlin saw the same calls;
  • pass — a Kotlin exception reaches the compiled caller as the same Python exception;
  • skipped — the 10,000-call leak test, blocked by Binder: closing a PyObject argument inside an upcall crashes later (SIGSEGV in Py_XDECREF on the Cleaner thread) #98. When the cleaner releases the wrappers left by upcalls, the binder releases a reference twice and the JVM dies. The interpreted control crashes too. Re-enable it with -Dtypedpython.leakTest=true.

:ksp-fixtures:app:desktopTest: 74 tests, 0 failures, 1 skipped.

Defects found (filed, not fixed here: binder area)

The compile step needs a host Python with pyrefly 1.3.2, from -PtypedpythonPython or python-multiplatform-ksp/.venv. Without one the test reports itself as skipped. It runs on macOS only.

…edded runtime (#45)

ksp-fixtures/app builds a '# typedpython: compiled' module with the TypedPython
pipeline against the embedded CPython's headers (cpythonIncludeDirectories
provider; EXT_SUFFIX from the extracted tree's sysconfigdata) and loads it
next to the interpreted module in the desktopTest JVM. The compiled code
constructs a Kotlin proxy, calls its method, passes it back to Kotlin and
loops with float math around the calls.

Passing: build/ABI premise; identical results and Kotlin-side call counts;
a Kotlin exception reaches the compiled caller as the same Python exception.
Skipped: the 10,000-call leak test, blocked by #98 (the binder releases a
reference twice on the cleaner path; the interpreted control crashes too).
Found on the way: #94 (KSP function returns are untyped _PmObject).

:ksp-fixtures:app:desktopTest: 74 tests, 0 failures, 1 skipped.

Refs #45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant