diff --git a/quest/m1/ffi-export/README.md b/quest/m1/ffi-export/README.md index bc5856d34..0d755e6ea 100644 --- a/quest/m1/ffi-export/README.md +++ b/quest/m1/ffi-export/README.md @@ -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 diff --git a/quest/m1/ffi-export/implied-outlives.md b/quest/m1/ffi-export/implied-outlives.md new file mode 100644 index 000000000..0e4e31a7a --- /dev/null +++ b/quest/m1/ffi-export/implied-outlives.md @@ -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. diff --git a/quest/m3/README.md b/quest/m3/README.md index 206557ec4..a01788784 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -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` 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 diff --git a/quest/m3/ffi-from-chains.md b/quest/m3/ffi-from-chains.md new file mode 100644 index 000000000..38ff760e3 --- /dev/null +++ b/quest/m3/ffi-from-chains.md @@ -0,0 +1,23 @@ +# [S] Into targets through a chain of From implementations + +## Goal + +`impl Into`, 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> From for Outer` with an unmapped `Inner`, it stops there and the +parameter falls back to `String`, `Bytes`, or `Vec`, 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>` 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.