From cccbd1ff590e6a96581e817c85fffa5ea42bcf8e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 01:19:09 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m2/ts-async.md Quest-Claim: ed8b36641efe40d2 From 700aa3654baf1caae0e71e52fcad35311ec78a49 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 01:41:39 -0700 Subject: [PATCH 2/2] fix(ts): substitute a census's type parameters into a body once Each MIR body is instantiated with its instance's arguments already, but Body substituted a call's generic arguments again. In a census lowered over type parameters, a parameter of the root then took the argument at its index in the body's own instance: a coroutine's kind, `()`. Drop Body's arguments. Co-Authored-By: Claude Opus 5.5 --- quest/m2/ts-async.md | 15 ++++++--------- ts/fixtures/reject/census.md | 4 ++-- ts/fixtures/reject/src/lib.rs | 18 ++++++++++++++++++ ts/src/lower/body.rs | 11 +---------- ts/src/lower/dynamic.rs | 2 +- ts/src/lower/mir/call.rs | 1 - ts/src/lower/mir/coroutine.rs | 4 ++-- ts/src/lower/mir/glue.rs | 2 +- ts/src/lower/mir/mod.rs | 4 ++-- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/quest/m2/ts-async.md b/quest/m2/ts-async.md index 7176802f8..e9ff3ceaf 100644 --- a/quest/m2/ts-async.md +++ b/quest/m2/ts-async.md @@ -23,16 +23,13 @@ std's future helpers translate: `Poll`'s methods, `Poll>`, `pin!`, `poll moq-net still needs, by its census from MIR at the pinned revision: - Async closures, which only moq-net's tests write today. -- kio's `Tasks`, whose `RawWaker` vtable and `Box` tasks are - [bindings](/ts/README.md#bindings). The rest of kio's API translates from source - across crates; what it still refuses is std's. +- kio's `Tasks`, which the model's census binds. Translated, it refuses a waker's + identity: `Polling` keeps `(Waker::data, Waker::vtable)` in a thread-local and compares + it as an `Option` of that pair (`rs/kio/src/task.rs`), 10 of kio's refusals. `rt.Waker` + has no identity a raw pointer can stand for, and a caller's own waker would have to give + one, so the runtime's waker shape is the maintainer's to decide. Its `Vec::drain` is left + to [the slice gaps](/quest/m3/ts-slice-gaps.md). - The edge: `rt.spawn`'s shape for callers, and cancelling a spawned task. -- `kio::Waiter::poll_future::<()>` does not normalize in moq-net's census, since `()` is - no `Future`. It is reached from `util.rs`'s `future_task` closure, itself refused as a - `Box`, and the same call translates in the fixture - ([#141](https://github.com/moq-dev/rust2/pull/141), - [#183](https://github.com/moq-dev/rust2/pull/183)). Find where polymorphic lowering - makes the `()`. An async block that captures part of a variable, which THIR refused 47 times, is a capture like any other in MIR. diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 06ea2c92c..ad1defdd9 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,8 +1,8 @@ # Census of `reject-fixture` - Refusals: 102 -- Function instances: 116 -- Generic functions no instance reached, lowered over their type parameters: 7 +- Function instances: 119 +- Generic functions no instance reached, lowered over their type parameters: 10 ## By construct diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 06aba4314..8d52a7ebe 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -746,3 +746,21 @@ pub fn pointer_statics(p: *mut u32) -> u32 { let _ = SLOT.compare_exchange(p, std::ptr::null_mut(), Relaxed, Relaxed); *NAMED } + +/// A census lowers this over `F` and `O`, and `awaited`'s body with it, whose closure names +/// `O` as this function's second type parameter: that refuses nothing. +pub async fn generic_awaited u8, O: std::future::Future>(f: F, o: O) -> u8 { + f() + awaited(o).await +} + +async fn awaited>(o: O) -> u8 { + let mut o = std::pin::pin!(o); + std::future::poll_fn(|cx| poll_pinned(o.as_mut(), cx)).await +} + +fn poll_pinned( + o: std::pin::Pin<&mut O>, + cx: &mut std::task::Context<'_>, +) -> std::task::Poll { + o.poll(cx) +} diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 2af61a30e..1cb62b46b 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -11,25 +11,18 @@ use crate::ts::{Expr, Key, Param, Stmt, StmtKind}; pub struct Body<'b, 'a, 'tcx> { pub t: &'b mut Translator<'a, 'tcx>, - /// The instance's generic arguments. - pub args: GenericArgsRef<'tcx>, /// Every name in the function, so none shadows another. names: FxHashSet, } impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { - pub fn new(t: &'b mut Translator<'a, 'tcx>, args: GenericArgsRef<'tcx>) -> Self { + pub fn new(t: &'b mut Translator<'a, 'tcx>) -> Self { Body { t, - args, names: FxHashSet::default(), } } - pub fn subst>>(&self, value: T) -> T { - self.t.subst(self.args, value) - } - pub fn err(&mut self, span: Span, msg: impl Into) -> Expr { self.t.err(span, msg); Expr::undefined() @@ -83,7 +76,6 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { out: &mut Vec, ) -> Expr { let tcx = self.t.tcx; - let gargs = self.subst(gargs); // A tuple struct or variant's constructor, called or passed as a value. if let rustc_hir::def::DefKind::Ctor(..) = tcx.def_kind(def_id) { @@ -233,7 +225,6 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { /// A function item as a value. pub fn fn_value(&mut self, def_id: rustc_hir::def_id::DefId, gargs: GenericArgsRef<'tcx>, span: Span) -> Expr { let tcx = self.t.tcx; - let gargs = self.subst(gargs); let sig = self.t.sig(def_id, gargs); let names: Vec = (0..sig.inputs().len()).map(|i| self.fresh(&format!("a{i}"))).collect(); // std's mappings take a `&mut` they declare that is an `rt.Place` as what it points diff --git a/ts/src/lower/dynamic.rs b/ts/src/lower/dynamic.rs index b4ca756cb..d04f7ed78 100644 --- a/ts/src/lower/dynamic.rs +++ b/ts/src/lower/dynamic.rs @@ -258,7 +258,7 @@ impl<'tcx> Translator<'_, 'tcx> { continue; } }; - let mut b = Body::new(self, args); + let mut b = Body::new(self); let params: Vec = sig.inputs()[1..] .iter() .map(|input| Param { diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index bcf596ba4..9caddfc51 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -358,7 +358,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { span: Span, ) -> Option { let tcx = self.tcx; - let gargs = self.b.subst(gargs); let call = library::Call { def_id, args: gargs, diff --git a/ts/src/lower/mir/coroutine.rs b/ts/src/lower/mir/coroutine.rs index aaedbc137..5c4d806c1 100644 --- a/ts/src/lower/mir/coroutine.rs +++ b/ts/src/lower/mir/coroutine.rs @@ -182,7 +182,7 @@ pub fn info<'tcx>(t: &mut Translator<'_, 'tcx>, def_id: DefId, args: GenericArgs }); if let Some(mir) = resume { let ret = mir.return_ty(); - let mut b = Body::new(t, args); + let mut b = Body::new(t); let mut fx = Fx::new(&mut b, &mir, Env::Coroutine, span); let params = fx.params(); let body = fx.lower(); @@ -217,7 +217,7 @@ pub fn info<'tcx>(t: &mut Translator<'_, 'tcx>, def_id: DefId, args: GenericArgs t.typing_env_pub(), EarlyBinder::bind(tcx, drop), ); - let mut b = Body::new(t, args); + let mut b = Body::new(t); let mut fx = Fx::new(&mut b, &mir, Env::Coroutine, span); fx.lower() } diff --git a/ts/src/lower/mir/glue.rs b/ts/src/lower/mir/glue.rs index ebffca868..2a1ab52d6 100644 --- a/ts/src/lower/mir/glue.rs +++ b/ts/src/lower/mir/glue.rs @@ -52,7 +52,7 @@ pub fn shim<'tcx>(t: &mut Translator<'_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Opt t.typing_env_pub(), EarlyBinder::bind(tcx, body), ); - let mut b = Body::new(t, instance.args); + let mut b = Body::new(t); let mut fx = Fx::new(&mut b, &mir, Env::Shim, span); let params = fx.params(); let body = fx.lower(); diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 2b7581d1e..aa8a3979e 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -48,7 +48,7 @@ pub fn function<'a, 'tcx>(t: &mut Translator<'a, 'tcx>, instance: Instance<'tcx> super::iter::check_impl(t, def_id); } let ret_ty = mir.return_ty(); - let mut b = Body::new(t, instance.args); + let mut b = Body::new(t); let mut fx = Fx::new(&mut b, &mir, Env::Plain, span); let params = fx.params(); let body = fx.lower(); @@ -976,7 +976,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } let tcx = self.tcx; let pointees = |func: &Operand<'tcx>, i: usize| match *func.ty(&self.mir.local_decls, tcx).kind() { - ty::FnDef(def_id, gargs) if self.b.t.mapped(def_id, self.b.subst(gargs.skip_binder())) => { + ty::FnDef(def_id, gargs) if self.b.t.mapped(def_id, gargs.skip_binder()) => { let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(); let input = tcx.instantiate_bound_regions_with_erased(sig).inputs().get(i).copied(); input.is_some_and(|t| matches!(t.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut)))