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
14 changes: 5 additions & 9 deletions quest/m2/ts-async.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ std's future helpers translate: `Poll`'s methods, `Poll<Poll<T>>`, `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<dyn FnMut>` 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<dyn FnMut>`, 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.
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/reject/census.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 18 additions & 0 deletions ts/fixtures/reject/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,21 @@ pub fn bound_ranges(v: &mut Vec<u8>, map: &std::collections::BTreeMap<u8, u8>) -
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<F: Fn() -> u8, O: std::future::Future<Output = u8>>(f: F, o: O) -> u8 {
f() + awaited(o).await
}

async fn awaited<O: std::future::Future<Output = u8>>(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::future::Future>(
o: std::pin::Pin<&mut O>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<O::Output> {
o.poll(cx)
}
11 changes: 1 addition & 10 deletions ts/src/lower/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

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<T: ty::TypeFoldable<ty::TyCtxt<'tcx>>>(&self, value: T) -> T {
self.t.subst(self.args, value)
}

pub fn err(&mut self, span: Span, msg: impl Into<String>) -> Expr {
self.t.err(span, msg);
Expr::undefined()
Expand Down Expand Up @@ -83,7 +76,6 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> {
out: &mut Vec<Stmt>,
) -> 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) {
Expand Down Expand Up @@ -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<String> = (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
Expand Down
2 changes: 1 addition & 1 deletion ts/src/lower/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Param> = sig.inputs()[1..]
.iter()
.map(|input| Param {
Expand Down
1 change: 0 additions & 1 deletion ts/src/lower/mir/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> {
span: Span,
) -> Option<Expr> {
let tcx = self.tcx;
let gargs = self.b.subst(gargs);
let call = library::Call {
def_id,
args: gargs,
Expand Down
4 changes: 2 additions & 2 deletions ts/src/lower/mir/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion ts/src/lower/mir/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ts/src/lower/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)))
Expand Down