You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Relates to #58027, but this is the case where an async fn is re-exported by another crate. The docs for the original function shows async fn but the re-export shows fn -> impl Future.
I'm going to mark this as "blocking" although it isn't really. It does seem like a good "polish" item to try and nail down before async-await hits beta, though it's ultimately a "nice to have".
There seems to be a reset of the asyncness when the function gets duplicated. Unfortunately I don't know from where I can get the asyncness information for hir::FnHeader there. There does not seem to be any information on that in sty::PolyFnSig.
Thanks, @hirschenberger, for the tip, I think that's exactly the right spot in the code. We basically want to copy the pathways in the code that we use for tracking (e.g.) whether a function is a const fn.
For that case, you can see in the code that we invoke the tcx query is_min_const_fn to check:
so we're going to want something similar, like let asyncness = tcx.fn_asyncness(...). Here I changed the query to return a hir::Asyncness type instead of a bool, but it's easy enough either way.
But first we need to add that is_async_fn query. We can look at is_min_const_fn as a model, although it has a few complications. In particular, is_min_const_fnturns out to be a regular tcx method that invokes the is_const_fn_raw helper (and then does some other stuff). We're more interested in the is_const_fn_raw model, since we don't need that other stuff.
is_const_fn_raw is defined in the query/mod.rs file:
The tricky part comes when the function is loaded from metadata from another crate. That requires us to edit the librustc_metadata modules. The first step would be to extend the schema:
Here we would just read it from the HIR. Finally, we have to modify the decoder and "crate store impl" files so that when you invoke the fn_asyncness query on an external crate, it gets routed the right way. For that we would add a function like is_const_fn_raw to decoder.rs:
Activity
nikomatsakis commentedon Aug 27, 2019
Check-in from the triage meeting:
I'm going to mark this as "blocking" although it isn't really. It does seem like a good "polish" item to try and nail down before async-await hits beta, though it's ultimately a "nice to have".
estebank commentedon Aug 28, 2019
Should we also consider always documenting
Fn() -> impl Future<Output=_>asasync Fn() -> _?hirschenberger commentedon Sep 13, 2019
After some codereview I found that code.
There seems to be a reset of the asyncness when the function gets duplicated. Unfortunately I don't know from where I can get the asyncness information for
hir::FnHeaderthere. There does not seem to be any information on that insty::PolyFnSig.csmoe commentedon Sep 17, 2019
@rustbot claim
nikomatsakis commentedon Sep 18, 2019
Mentoring instructions
Thanks, @hirschenberger, for the tip, I think that's exactly the right spot in the code. We basically want to copy the pathways in the code that we use for tracking (e.g.) whether a function is a
const fn.For that case, you can see in the code that we invoke the tcx query
is_min_const_fnto check:rust/src/librustdoc/clean/inline.rs
Lines 215 to 219 in 3287a65
so we're going to want something similar, like
let asyncness = tcx.fn_asyncness(...). Here I changed the query to return ahir::Asyncnesstype instead of a bool, but it's easy enough either way.But first we need to add that
is_async_fnquery. We can look atis_min_const_fnas a model, although it has a few complications. In particular,is_min_const_fnturns out to be a regular tcx method that invokes theis_const_fn_rawhelper (and then does some other stuff). We're more interested in theis_const_fn_rawmodel, since we don't need that other stuff.is_const_fn_rawis defined in the query/mod.rs file:rust/src/librustc/query/mod.rs
Lines 237 to 245 in 3287a65
The "provider" (function that gets called) for local functions is given in
ty/constness.rs:rust/src/librustc/ty/constness.rs
Lines 71 to 84 in 3287a65
and installed into the provider struct down below:
rust/src/librustc/ty/constness.rs
Lines 110 to 115 in 3287a65
The tricky part comes when the function is loaded from metadata from another crate. That requires us to edit the
librustc_metadatamodules. The first step would be to extend the schema:rust/src/librustc_metadata/schema.rs
Lines 296 to 301 in 3287a65
Here, we would add a field like
asyncness: hir::Asyncness. Then we'll have to modify the encoder to provide a value for that field, e.g. here:rust/src/librustc_metadata/encoder.rs
Lines 887 to 891 in 3287a65
Here we would just read it from the HIR. Finally, we have to modify the decoder and "crate store impl" files so that when you invoke the
fn_asyncnessquery on an external crate, it gets routed the right way. For that we would add a function likeis_const_fn_rawtodecoder.rs:rust/src/librustc_metadata/decoder.rs
Lines 1201 to 1209 in 3287a65
and then add an entry to the macro which invokes this function when the query is called, kind of like this:
rust/src/librustc_metadata/cstore_impl.rs
Line 135 in 3287a65
This macro basically says "when this tcx query is called on something from a foreign crate, invoke this method on the
cdatavariable ('crate data')".hirschenberger commentedon Sep 19, 2019
Oh, seems I was too late 😞
@nikomatsakis But thanks for the tried mentoring
Rollup merge of rust-lang#64599 - csmoe:doc_async_reexport, r=nikomat…