Avoid GenFuture shim when compiling async constructs

Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
This commit is contained in:
Arpad Borsos 2022-11-18 22:56:22 +01:00
parent fd815a5091
commit 9f36f988ad
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
41 changed files with 459 additions and 211 deletions

View file

@ -202,6 +202,12 @@ fn resolve_associated_item<'tcx>(
)),
substs: generator_data.substs,
}),
traits::ImplSource::Future(future_data) => Some(Instance {
def: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
future_data.generator_def_id,
)),
substs: future_data.substs,
}),
traits::ImplSource::Closure(closure_data) => {
let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap();
Instance::resolve_closure(