diff --git a/quest/m2/ts-async.md b/quest/m2/ts-async.md index 7176802f8..5d4f84fbe 100644 --- a/quest/m2/ts-async.md +++ b/quest/m2/ts-async.md @@ -23,16 +23,12 @@ 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. - 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 e17c00e14..b5bbaf292 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,8 +1,8 @@ # Census of `reject-fixture` - Refusals: 105 -- Function instances: 117 -- Generic functions no instance reached, lowered over their type parameters: 7 +- Function instances: 120 +- 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 83ca394ed..05fe85f47 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -752,3 +752,21 @@ pub fn bound_ranges(v: &mut Vec, map: &std::collections::BTreeMap) - use std::ops::Bound::{Excluded, Included}; v.drain((Excluded(0), Included(2))).count() + map.range((Excluded(0), Included(2))).count() } + +/// 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 d0044ac5b..c58d646e2 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -360,7 +360,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)))