Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quest/m1/ffi-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ Every generator on the C ABI:
- [C++ bindings on MSVC and Clang](/quest/m1/ffi-export/cpp.md) - the C++ header built and tested beyond GCC on Linux
- [Kotlin bindings: zero-copy payloads and the read path](/quest/m1/ffi-export/kotlin.md) - the Kotlin lends bytes without a copy, and reads at JNI's cost
- [Kotlin bindings on Android](/quest/m1/ffi-export/kotlin-android.md) - an R8 keep rule for JNI's lookups, and an emulator run in CI
- [Owned implementors for a parameter that must outlive the call](/quest/m1/ffi-export/implied-outlives.md) - `each` reads implied lifetime bounds, so the glue builds instead of borrowing past the call
28 changes: 28 additions & 0 deletions quest/m1/ffi-export/implied-outlives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# [S] Owned implementors for a parameter that must outlive the call

## Goal

A generic parameter whose bounds imply a lifetime, such as `impl Kept` with
`trait Kept: 'static`, takes an implementor by value, never a borrow of what C lends for
the call. Today [`each`](/ffi/src/collect.rs) reads only the item's direct outlives bounds,
so it picks `&Point` for `keep(kept: impl Kept)` when `Kept` is implemented for both `Point`
and `&'static Point`, and the generated glue fails to compile
(`E0597: a0 does not live long enough`): the whole export fails to build instead of
exporting `keep` at `Point`.

## Plan

Found by [#197](https://github.com/kixelated/rust2/pull/197) on 2026-10-29, which made
`choose` read lifetimes from the elaborated bounds and left `each` reading direct ones.

- It is not unsound: the glue borrows a handle or record through a guard local to the call
(`rt::Object::borrow`, then `&*local`), so rustc rejects any borrow that must outlive it.
The cost is a build failure in generated code, with no span in the user's crate, where
the rules say an unsupported construct fails loud at its source.
- Reproduced on 2026-10-29 by adding `Kept` (with a by-value method, so it is no callback,
and excluded as the fixture's `Payload` is) and `keep` to the api fixture.
- Read the outlives bound one way for both `choose` and `each`, from the elaborated
clauses, so the inference rules stay in one place.
- No consumer hits it yet: moq's bounds that imply `'static` reach `choose`, not `each`.

Public API: none, beyond exports that now build.
1 change: 1 addition & 0 deletions quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ generic std gap is planned here even when moq never calls it.
- [Debug and Display of Arc and ranges](/quest/m3/ts-fmt-wrappers.md) - `Arc<T>` formats as `T`, and ranges as std's `Debug`
- [Fold a match a bool decided](/quest/m3/ts-fold-bool.md) - `if matches!` and derived `==` drop a later match's dead arms
- [Rename one instance](/quest/m3/ffi-instance-rename.md) - `rename` by an instance's path, once a consumer's clash needs it
- [Into targets through a chain of From implementations](/quest/m3/ffi-from-chains.md) - `sources` follows more than one level, once a consumer's parameter needs it
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
23 changes: 23 additions & 0 deletions quest/m3/ffi-from-chains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# [S] Into targets through a chain of From implementations

## Goal

`impl Into<X>`, where `X` does not map, takes what converts into `X` through any number of
`From` implementations, not only one. Today [`sources`](/ffi/src/collect.rs) reads the
bounds of the `From` implementations into `X` and takes each `Into` or `AsRef` target
their source parameter implies. When that target does not map either, such as
`impl<B: Into<Inner>> From<B> for Outer` with an unmapped `Inner`, it stops there and the
parameter falls back to `String`, `Bytes`, or `Vec<u8>`, or is refused.

## Plan

Suggested by [#197](https://github.com/kixelated/rust2/pull/197) on 2026-10-29. No consumer
needs it yet: moq's `impl Into<Timed<Bytes>>` is one level. Start once a consumer's
parameter goes through two.

- Follow each target that does not map through its own `From` implementations, carrying
whether any level must outlive the call, as one level does now. Guard against cycles.
- A fallback that meets the bounds is the bug #197 fixed, so prove the chained case with a
payload that is not UTF-8, as #197's `timed_hex` does.

Public API: the C, C++, and Kotlin types of parameters that convert through a chain.