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:
@@ -660,6 +660,9 @@ pub enum ImplSource<'tcx, N> {
|
||||
/// ImplSource automatically generated for a generator.
|
||||
Generator(ImplSourceGeneratorData<'tcx, N>),
|
||||
|
||||
/// ImplSource automatically generated for a generator backing an async future.
|
||||
Future(ImplSourceFutureData<'tcx, N>),
|
||||
|
||||
/// ImplSource for a trait alias.
|
||||
TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
|
||||
|
||||
@@ -676,6 +679,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
ImplSource::AutoImpl(d) => d.nested,
|
||||
ImplSource::Closure(c) => c.nested,
|
||||
ImplSource::Generator(c) => c.nested,
|
||||
ImplSource::Future(c) => c.nested,
|
||||
ImplSource::Object(d) => d.nested,
|
||||
ImplSource::FnPointer(d) => d.nested,
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData)
|
||||
@@ -694,6 +698,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
ImplSource::AutoImpl(d) => &d.nested,
|
||||
ImplSource::Closure(c) => &c.nested,
|
||||
ImplSource::Generator(c) => &c.nested,
|
||||
ImplSource::Future(c) => &c.nested,
|
||||
ImplSource::Object(d) => &d.nested,
|
||||
ImplSource::FnPointer(d) => &d.nested,
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData)
|
||||
@@ -737,6 +742,11 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
substs: c.substs,
|
||||
nested: c.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSource::Future(c) => ImplSource::Future(ImplSourceFutureData {
|
||||
generator_def_id: c.generator_def_id,
|
||||
substs: c.substs,
|
||||
nested: c.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSource::FnPointer(p) => ImplSource::FnPointer(ImplSourceFnPointerData {
|
||||
fn_ty: p.fn_ty,
|
||||
nested: p.nested.into_iter().map(f).collect(),
|
||||
@@ -796,6 +806,16 @@ pub struct ImplSourceGeneratorData<'tcx, N> {
|
||||
pub nested: Vec<N>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct ImplSourceFutureData<'tcx, N> {
|
||||
pub generator_def_id: DefId,
|
||||
pub substs: SubstsRef<'tcx>,
|
||||
/// Nested obligations. This can be non-empty if the generator
|
||||
/// signature contains associated types.
|
||||
pub nested: Vec<N>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct ImplSourceClosureData<'tcx, N> {
|
||||
|
||||
Reference in New Issue
Block a user