s/generator/coroutine/

This commit is contained in:
Oli Scherer
2023-10-19 21:46:28 +00:00
parent 60956837cf
commit e96ce20b34
468 changed files with 2201 additions and 2197 deletions

View File

@@ -4,7 +4,7 @@ use rustc_hir::intravisit::nested_filter::NestedFilter;
/// that are inside of an item-like.
///
/// Notably, possible occurrences of bodies in non-item-like things
/// include: closures/generators, inline `const {}` blocks, and
/// include: closures/coroutines, inline `const {}` blocks, and
/// constant arguments of types, e.g. in `let _: [(); /* HERE */];`.
///
/// **This is the most common choice.** A very common pattern is

View File

@@ -32,11 +32,12 @@
#![feature(core_intrinsics)]
#![feature(discriminant_kind)]
#![feature(exhaustive_patterns)]
#![feature(generators)]
#![cfg_attr(bootstrap, feature(generators))]
#![cfg_attr(not(bootstrap), feature(coroutines))]
#![feature(get_mut_unchecked)]
#![feature(if_let_guard)]
#![feature(inline_const)]
#![feature(iter_from_generator)]
#![feature(iter_from_coroutine)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(extern_types)]

View File

@@ -308,7 +308,7 @@ pub struct ScopeTree {
/// The number of visit_expr and visit_pat calls done in the body.
/// Used to sanity check visit_expr/visit_pat call count when
/// calculating generator interiors.
/// calculating coroutine interiors.
pub body_expr_count: FxHashMap<hir::BodyId, usize>,
}
@@ -413,7 +413,7 @@ impl ScopeTree {
/// Gives the number of expressions visited in a body.
/// Used to sanity check visit_expr call count when
/// calculating generator interiors.
/// calculating coroutine interiors.
pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option<usize> {
self.body_expr_count.get(&body_id).copied()
}

View File

@@ -247,18 +247,18 @@ impl<'tcx> MirSource<'tcx> {
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
pub struct CoroutineInfo<'tcx> {
/// The yield type of the function, if it is a generator.
/// The yield type of the function, if it is a coroutine.
pub yield_ty: Option<Ty<'tcx>>,
/// Coroutine drop glue.
pub generator_drop: Option<Body<'tcx>>,
pub coroutine_drop: Option<Body<'tcx>>,
/// The layout of a generator. Produced by the state transformation.
pub generator_layout: Option<CoroutineLayout<'tcx>>,
/// The layout of a coroutine. Produced by the state transformation.
pub coroutine_layout: Option<CoroutineLayout<'tcx>>,
/// If this is a generator then record the type of source expression that caused this generator
/// If this is a coroutine then record the type of source expression that caused this coroutine
/// to be created.
pub generator_kind: CoroutineKind,
pub coroutine_kind: CoroutineKind,
}
/// The lowered representation of a single function.
@@ -284,7 +284,7 @@ pub struct Body<'tcx> {
/// and used for debuginfo. Indexed by a `SourceScope`.
pub source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
pub generator: Option<Box<CoroutineInfo<'tcx>>>,
pub coroutine: Option<Box<CoroutineInfo<'tcx>>>,
/// Declarations of locals.
///
@@ -365,7 +365,7 @@ impl<'tcx> Body<'tcx> {
arg_count: usize,
var_debug_info: Vec<VarDebugInfo<'tcx>>,
span: Span,
generator_kind: Option<CoroutineKind>,
coroutine_kind: Option<CoroutineKind>,
tainted_by_errors: Option<ErrorGuaranteed>,
) -> Self {
// We need `arg_count` locals, and one for the return place.
@@ -382,12 +382,12 @@ impl<'tcx> Body<'tcx> {
source,
basic_blocks: BasicBlocks::new(basic_blocks),
source_scopes,
generator: generator_kind.map(|generator_kind| {
coroutine: coroutine_kind.map(|coroutine_kind| {
Box::new(CoroutineInfo {
yield_ty: None,
generator_drop: None,
generator_layout: None,
generator_kind,
coroutine_drop: None,
coroutine_layout: None,
coroutine_kind,
})
}),
local_decls,
@@ -418,7 +418,7 @@ impl<'tcx> Body<'tcx> {
source: MirSource::item(CRATE_DEF_ID.to_def_id()),
basic_blocks: BasicBlocks::new(basic_blocks),
source_scopes: IndexVec::new(),
generator: None,
coroutine: None,
local_decls: IndexVec::new(),
user_type_annotations: IndexVec::new(),
arg_count: 0,
@@ -548,22 +548,22 @@ impl<'tcx> Body<'tcx> {
#[inline]
pub fn yield_ty(&self) -> Option<Ty<'tcx>> {
self.generator.as_ref().and_then(|generator| generator.yield_ty)
self.coroutine.as_ref().and_then(|coroutine| coroutine.yield_ty)
}
#[inline]
pub fn generator_layout(&self) -> Option<&CoroutineLayout<'tcx>> {
self.generator.as_ref().and_then(|generator| generator.generator_layout.as_ref())
pub fn coroutine_layout(&self) -> Option<&CoroutineLayout<'tcx>> {
self.coroutine.as_ref().and_then(|coroutine| coroutine.coroutine_layout.as_ref())
}
#[inline]
pub fn generator_drop(&self) -> Option<&Body<'tcx>> {
self.generator.as_ref().and_then(|generator| generator.generator_drop.as_ref())
pub fn coroutine_drop(&self) -> Option<&Body<'tcx>> {
self.coroutine.as_ref().and_then(|coroutine| coroutine.coroutine_drop.as_ref())
}
#[inline]
pub fn generator_kind(&self) -> Option<CoroutineKind> {
self.generator.as_ref().map(|generator| generator.generator_kind)
pub fn coroutine_kind(&self) -> Option<CoroutineKind> {
self.coroutine.as_ref().map(|coroutine| coroutine.coroutine_kind)
}
#[inline]

View File

@@ -130,8 +130,8 @@ fn dump_matched_mir_node<'tcx, F>(
Some(promoted) => write!(file, "::{promoted:?}`")?,
}
writeln!(file, " {disambiguator} {pass_name}")?;
if let Some(ref layout) = body.generator_layout() {
writeln!(file, "/* generator_layout = {layout:#?} */")?;
if let Some(ref layout) = body.coroutine_layout() {
writeln!(file, "/* coroutine_layout = {layout:#?} */")?;
}
writeln!(file)?;
extra_data(PassWhere::BeforeCFG, &mut file)?;
@@ -782,7 +782,7 @@ impl<'tcx> TerminatorKind<'tcx> {
Goto { .. } => write!(fmt, "goto"),
SwitchInt { discr, .. } => write!(fmt, "switchInt({discr:?})"),
Return => write!(fmt, "return"),
CoroutineDrop => write!(fmt, "generator_drop"),
CoroutineDrop => write!(fmt, "coroutine_drop"),
UnwindResume => write!(fmt, "resume"),
UnwindTerminate(reason) => {
write!(fmt, "abort({})", reason.as_short_str())
@@ -1047,7 +1047,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}),
AggregateKind::Coroutine(def_id, _, _) => ty::tls::with(|tcx| {
let name = format!("{{generator@{:?}}}", tcx.def_span(def_id));
let name = format!("{{coroutine@{:?}}}", tcx.def_span(def_id));
let mut struct_fmt = fmt.debug_struct(&name);
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
@@ -1302,7 +1302,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
}
AggregateKind::Coroutine(def_id, args, movability) => {
self.push("generator");
self.push("coroutine");
self.push(&format!("+ def_id: {def_id:?}"));
self.push(&format!("+ args: {args:#?}"));
self.push(&format!("+ movability: {movability:?}"));

View File

@@ -145,10 +145,10 @@ pub struct CoroutineSavedTy<'tcx> {
pub ignore_for_traits: bool,
}
/// The layout of generator state.
/// The layout of coroutine state.
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub struct CoroutineLayout<'tcx> {
/// The type of every local stored inside the generator.
/// The type of every local stored inside the coroutine.
pub field_tys: IndexVec<CoroutineSavedLocal, CoroutineSavedTy<'tcx>>,
/// The name for debuginfo.
@@ -185,7 +185,7 @@ impl Debug for CoroutineLayout<'_> {
}
}
/// Prints the generator variant name.
/// Prints the coroutine variant name.
struct GenVariantPrinter(VariantIdx);
impl From<VariantIdx> for GenVariantPrinter {
fn from(idx: VariantIdx) -> Self {
@@ -259,7 +259,7 @@ pub struct ConstQualifs {
///
/// The requirements are listed as being between various `RegionVid`. The 0th
/// region refers to `'static`; subsequent region vids refer to the free
/// regions that appear in the closure (or generator's) type, in order of
/// regions that appear in the closure (or coroutine's) type, in order of
/// appearance. (This numbering is actually defined by the `UniversalRegions`
/// struct in the NLL region checker. See for example
/// `UniversalRegions::closure_mapping`.) Note the free regions in the

View File

@@ -83,9 +83,9 @@ pub enum MirPhase {
/// don't document this here. Runtime MIR has most retags explicit (though implicit retags
/// can still occur at `Rvalue::{Ref,AddrOf}`).
/// - Coroutine bodies: In analysis MIR, locals may actually be behind a pointer that user code has
/// access to. This occurs in generator bodies. Such locals do not behave like other locals,
/// access to. This occurs in coroutine bodies. Such locals do not behave like other locals,
/// because they eg may be aliased in surprising ways. Runtime MIR has no such special locals -
/// all generator bodies are lowered and so all places that look like locals really are locals.
/// all coroutine bodies are lowered and so all places that look like locals really are locals.
///
/// Also note that the lint pass which reports eg `200_u8 + 200_u8` as an error is run as a part
/// of analysis to runtime MIR lowering. To ensure lints are reported reliably, this means that
@@ -292,7 +292,7 @@ pub enum StatementKind<'tcx> {
/// Write the discriminant for a variant to the enum Place.
///
/// This is permitted for both generators and ADTs. This does not necessarily write to the
/// This is permitted for both coroutines and ADTs. This does not necessarily write to the
/// entire place; instead, it writes to the minimum set of bytes as required by the layout for
/// the type.
SetDiscriminant { place: Box<Place<'tcx>>, variant_index: VariantIdx },
@@ -626,7 +626,7 @@ pub enum TerminatorKind<'tcx> {
/// `dest = move _0`. It might additionally do other things, like have side-effects in the
/// aliasing model.
///
/// If the body is a generator body, this has slightly different semantics; it instead causes a
/// If the body is a coroutine body, this has slightly different semantics; it instead causes a
/// `CoroutineState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
/// to the return place.
Return,
@@ -709,14 +709,14 @@ pub enum TerminatorKind<'tcx> {
/// Marks a suspend point.
///
/// Like `Return` terminators in generator bodies, this computes `value` and then a
/// Like `Return` terminators in coroutine bodies, this computes `value` and then a
/// `CoroutineState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
/// the return place of the function calling this one, and execution continues in the calling
/// function. When next invoked with the same first argument, execution of this function
/// continues at the `resume` basic block, with the second argument written to the `resume_arg`
/// place. If the generator is dropped before then, the `drop` basic block is invoked.
/// place. If the coroutine is dropped before then, the `drop` basic block is invoked.
///
/// Not permitted in bodies that are not generator bodies, or after generator lowering.
/// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering.
///
/// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`?
Yield {
@@ -726,16 +726,16 @@ pub enum TerminatorKind<'tcx> {
resume: BasicBlock,
/// The place to store the resume argument in.
resume_arg: Place<'tcx>,
/// Cleanup to be done if the generator is dropped at this suspend point.
/// Cleanup to be done if the coroutine is dropped at this suspend point.
drop: Option<BasicBlock>,
},
/// Indicates the end of dropping a generator.
/// Indicates the end of dropping a coroutine.
///
/// Semantically just a `return` (from the generators drop glue). Only permitted in the same situations
/// Semantically just a `return` (from the coroutines drop glue). Only permitted in the same situations
/// as `yield`.
///
/// **Needs clarification**: Is that even correct? The generator drop code is always confusing
/// **Needs clarification**: Is that even correct? The coroutine drop code is always confusing
/// to me, because it's not even really in the current body.
///
/// **Needs clarification**: Are there type system constraints on these terminators? Should
@@ -961,8 +961,8 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
/// was unsized and so had metadata associated with it, then the metadata is retained if the
/// field is unsized and thrown out if it is sized.
///
/// These projections are only legal for tuples, ADTs, closures, and generators. If the ADT or
/// generator has more than one variant, the parent place's variant index must be set, indicating
/// These projections are only legal for tuples, ADTs, closures, and coroutines. If the ADT or
/// coroutine has more than one variant, the parent place's variant index must be set, indicating
/// which variant is being used. If it has just one variant, the variant index may or may not be
/// included - the single possible variant is inferred if it is not included.
/// - [`OpaqueCast`](ProjectionElem::OpaqueCast): This projection changes the place's type to the
@@ -1068,7 +1068,7 @@ pub enum ProjectionElem<V, T> {
from_end: bool,
},
/// "Downcast" to a variant of an enum or a generator.
/// "Downcast" to a variant of an enum or a coroutine.
///
/// The included Symbol is the name of the variant, used for printing MIR.
Downcast(Option<Symbol>, VariantIdx),
@@ -1279,7 +1279,7 @@ pub enum Rvalue<'tcx> {
/// has a destructor.
///
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After
/// generator lowering, `Coroutine` aggregate kinds are disallowed too.
/// coroutine lowering, `Coroutine` aggregate kinds are disallowed too.
Aggregate(Box<AggregateKind<'tcx>>, IndexVec<FieldIdx, Operand<'tcx>>),
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.

View File

@@ -11,7 +11,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx};
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
pub struct PlaceTy<'tcx> {
pub ty: Ty<'tcx>,
/// Downcast to a particular variant of an enum or a generator, if included.
/// Downcast to a particular variant of an enum or a coroutine, if included.
pub variant_index: Option<VariantIdx>,
}
@@ -206,7 +206,7 @@ impl<'tcx> Rvalue<'tcx> {
AggregateKind::Adt(did, _, args, _, _) => tcx.type_of(did).instantiate(tcx, args),
AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args),
AggregateKind::Coroutine(did, args, movability) => {
Ty::new_generator(tcx, did, args, movability)
Ty::new_coroutine(tcx, did, args, movability)
}
},
Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty),

View File

@@ -139,9 +139,9 @@ impl<O> AssertKind<O> {
Overflow(op, _, _) => bug!("{:?} cannot overflow", op),
DivisionByZero(_) => "attempt to divide by zero",
RemainderByZero(_) => "attempt to calculate the remainder with a divisor of zero",
ResumedAfterReturn(CoroutineKind::Gen) => "generator resumed after completion",
ResumedAfterReturn(CoroutineKind::Gen) => "coroutine resumed after completion",
ResumedAfterReturn(CoroutineKind::Async(_)) => "`async fn` resumed after completion",
ResumedAfterPanic(CoroutineKind::Gen) => "generator resumed after panicking",
ResumedAfterPanic(CoroutineKind::Gen) => "coroutine resumed after panicking",
ResumedAfterPanic(CoroutineKind::Async(_)) => "`async fn` resumed after panicking",
BoundsCheck { .. } | MisalignedPointerDereference { .. } => {
bug!("Unexpected AssertKind")
@@ -229,9 +229,9 @@ impl<O> AssertKind<O> {
DivisionByZero(_) => middle_assert_divide_by_zero,
RemainderByZero(_) => middle_assert_remainder_by_zero,
ResumedAfterReturn(CoroutineKind::Async(_)) => middle_assert_async_resume_after_return,
ResumedAfterReturn(CoroutineKind::Gen) => middle_assert_generator_resume_after_return,
ResumedAfterReturn(CoroutineKind::Gen) => middle_assert_coroutine_resume_after_return,
ResumedAfterPanic(CoroutineKind::Async(_)) => middle_assert_async_resume_after_panic,
ResumedAfterPanic(CoroutineKind::Gen) => middle_assert_generator_resume_after_panic,
ResumedAfterPanic(CoroutineKind::Gen) => middle_assert_coroutine_resume_after_panic,
MisalignedPointerDereference { .. } => middle_assert_misaligned_ptr_deref,
}

View File

@@ -737,10 +737,10 @@ macro_rules! make_mir_visitor {
}
AggregateKind::Coroutine(
_,
generator_args,
coroutine_args,
_movability,
) => {
self.visit_args(generator_args, location);
self.visit_args(coroutine_args, location);
}
}
@@ -992,7 +992,7 @@ macro_rules! extra_body_methods {
macro_rules! super_body {
($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => {
let span = $body.span;
if let Some(gen) = &$($mutability)? $body.generator {
if let Some(gen) = &$($mutability)? $body.coroutine {
if let Some(yield_ty) = $(& $mutability)? gen.yield_ty {
$self.visit_ty(
yield_ty,

View File

@@ -541,28 +541,28 @@ rustc_queries! {
}
}
/// Returns names of captured upvars for closures and generators.
/// Returns names of captured upvars for closures and coroutines.
///
/// Here are some examples:
/// - `name__field1__field2` when the upvar is captured by value.
/// - `_ref__name__field` when the upvar is captured by reference.
///
/// For generators this only contains upvars that are shared by all states.
/// For coroutines this only contains upvars that are shared by all states.
query closure_saved_names_of_captured_variables(def_id: DefId) -> &'tcx IndexVec<abi::FieldIdx, Symbol> {
arena_cache
desc { |tcx| "computing debuginfo for closure `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
query mir_generator_witnesses(key: DefId) -> &'tcx Option<mir::CoroutineLayout<'tcx>> {
query mir_coroutine_witnesses(key: DefId) -> &'tcx Option<mir::CoroutineLayout<'tcx>> {
arena_cache
desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
separate_provide_extern
}
query check_generator_obligations(key: LocalDefId) {
desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key) }
query check_coroutine_obligations(key: LocalDefId) {
desc { |tcx| "verify auto trait bounds for coroutine interior type `{}`", tcx.def_path_str(key) }
}
/// MIR after our optimization passes have run. This is MIR that is ready
@@ -743,9 +743,9 @@ rustc_queries! {
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
}
/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
query generator_kind(def_id: DefId) -> Option<hir::CoroutineKind> {
desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
/// Returns `Some(coroutine_kind)` if the node pointed to by `def_id` is a coroutine.
query coroutine_kind(def_id: DefId) -> Option<hir::CoroutineKind> {
desc { |tcx| "looking up coroutine kind of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}

View File

@@ -382,9 +382,9 @@ pub enum ExprKind<'tcx> {
VarRef {
id: LocalVarId,
},
/// Used to represent upvars mentioned in a closure/generator
/// Used to represent upvars mentioned in a closure/coroutine
UpvarRef {
/// DefId of the closure/generator
/// DefId of the closure/coroutine
closure_def_id: DefId,
/// HirId of the root variable

View File

@@ -301,7 +301,7 @@ pub enum ObligationCauseCode<'tcx> {
InlineAsmSized,
/// Captured closure type must be `Sized`.
SizedClosureCapture(LocalDefId),
/// Types live across generator yields must be `Sized`.
/// Types live across coroutine yields must be `Sized`.
SizedCoroutineInterior(LocalDefId),
/// `[expr; N]` requires `type_of(expr): Copy`.
RepeatElementCopy {

View File

@@ -137,10 +137,10 @@ pub enum SelectionCandidate<'tcx> {
},
/// Implementation of a `Coroutine` trait by one of the anonymous types
/// generated for a generator.
/// generated for a coroutine.
CoroutineCandidate,
/// Implementation of a `Future` trait by one of the generator types
/// Implementation of a `Future` trait by one of the coroutine types
/// generated for an async construct.
FutureCandidate,

View File

@@ -761,9 +761,9 @@ impl<'tcx> TyCtxt<'tcx> {
self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did)
}
/// Returns `true` if the node pointed to by `def_id` is a generator for an async construct.
pub fn generator_is_async(self, def_id: DefId) -> bool {
matches!(self.generator_kind(def_id), Some(hir::CoroutineKind::Async(_)))
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct.
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_)))
}
pub fn stability(self) -> &'tcx stability::Index {
@@ -951,7 +951,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
let definitions = &self.untracked.definitions;
std::iter::from_generator(|| {
std::iter::from_coroutine(|| {
let mut i = 0;
// Recompute the number of definitions each time, because our caller may be creating

View File

@@ -241,8 +241,8 @@ impl<'tcx> Ty<'tcx> {
}
ty::Dynamic(..) => "trait object".into(),
ty::Closure(..) => "closure".into(),
ty::Coroutine(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(),
ty::CoroutineWitness(..) => "generator witness".into(),
ty::Coroutine(def_id, ..) => tcx.coroutine_kind(def_id).unwrap().descr().into(),
ty::CoroutineWitness(..) => "coroutine witness".into(),
ty::Infer(ty::TyVar(_)) => "inferred type".into(),
ty::Infer(ty::IntVar(_)) => "integer".into(),
ty::Infer(ty::FloatVar(_)) => "floating-point number".into(),
@@ -299,8 +299,8 @@ impl<'tcx> Ty<'tcx> {
ty::FnPtr(_) => "fn pointer".into(),
ty::Dynamic(..) => "trait object".into(),
ty::Closure(..) => "closure".into(),
ty::Coroutine(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(),
ty::CoroutineWitness(..) => "generator witness".into(),
ty::Coroutine(def_id, ..) => tcx.coroutine_kind(def_id).unwrap().descr().into(),
ty::CoroutineWitness(..) => "coroutine witness".into(),
ty::Tuple(..) => "tuple".into(),
ty::Placeholder(..) => "higher-ranked type".into(),
ty::Bound(..) => "bound type variable".into(),

View File

@@ -112,7 +112,7 @@ impl FlagComputation {
}
ty::Coroutine(_, args, _) => {
let args = args.as_generator();
let args = args.as_coroutine();
let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
self.add_args(args.parent_args());

View File

@@ -266,11 +266,11 @@ impl<'tcx> GenericArgs<'tcx> {
ClosureArgs { args: self }
}
/// Interpret these generic args as the args of a generator type.
/// Interpret these generic args as the args of a coroutine type.
/// Coroutine args have a particular structure controlled by the
/// compiler that encodes information like the signature and generator kind;
/// compiler that encodes information like the signature and coroutine kind;
/// see `ty::CoroutineArgs` struct for more comments.
pub fn as_generator(&'tcx self) -> CoroutineArgs<'tcx> {
pub fn as_coroutine(&'tcx self) -> CoroutineArgs<'tcx> {
CoroutineArgs { args: self }
}

View File

@@ -36,7 +36,7 @@ pub enum InstanceDef<'tcx> {
/// This includes:
/// - `fn` items
/// - closures
/// - generators
/// - coroutines
Item(DefId),
/// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI).
@@ -653,15 +653,15 @@ fn polymorphize<'tcx>(
let unused = tcx.unused_generic_params(instance);
debug!("polymorphize: unused={:?}", unused);
// If this is a closure or generator then we need to handle the case where another closure
// If this is a closure or coroutine then we need to handle the case where another closure
// from the function is captured as an upvar and hasn't been polymorphized. In this case,
// the unpolymorphized upvar closure would result in a polymorphized closure producing
// multiple mono items (and eventually symbol clashes).
let def_id = instance.def_id();
let upvars_ty = if tcx.is_closure(def_id) {
Some(args.as_closure().tupled_upvars_ty())
} else if tcx.type_of(def_id).skip_binder().is_generator() {
Some(args.as_generator().tupled_upvars_ty())
} else if tcx.type_of(def_id).skip_binder().is_coroutine() {
Some(args.as_coroutine().tupled_upvars_ty())
} else {
None
};
@@ -695,7 +695,7 @@ fn polymorphize<'tcx>(
if args == polymorphized_args {
ty
} else {
Ty::new_generator(self.tcx, def_id, polymorphized_args, movability)
Ty::new_coroutine(self.tcx, def_id, polymorphized_args, movability)
}
}
_ => ty.super_fold_with(self),
@@ -715,7 +715,7 @@ fn polymorphize<'tcx>(
upvars_ty == Some(args[param.index as usize].expect_ty()) => {
// ..then double-check that polymorphization marked it used..
debug_assert!(!is_unused);
// ..and polymorphize any closures/generators captured as upvars.
// ..and polymorphize any closures/coroutines captured as upvars.
let upvars_ty = upvars_ty.unwrap();
let polymorphized_upvars_ty = upvars_ty.fold_with(
&mut PolymorphizationFolder { tcx });

View File

@@ -898,7 +898,7 @@ where
ty::Array(element, _) | ty::Slice(element) => TyMaybeWithLayout::Ty(element),
ty::Str => TyMaybeWithLayout::Ty(tcx.types.u8),
// Tuples, generators and closures.
// Tuples, coroutines and closures.
ty::Closure(_, ref args) => field_ty_or_layout(
TyAndLayout { ty: args.as_closure().tupled_upvars_ty(), ..this },
cx,
@@ -907,7 +907,7 @@ where
ty::Coroutine(def_id, ref args, _) => match this.variants {
Variants::Single { index } => TyMaybeWithLayout::Ty(
args.as_generator()
args.as_coroutine()
.state_tys(def_id, tcx)
.nth(index.as_usize())
.unwrap()
@@ -918,7 +918,7 @@ where
if i == tag_field {
return TyMaybeWithLayout::TyAndLayout(tag_layout(tag));
}
TyMaybeWithLayout::Ty(args.as_generator().prefix_tys()[i])
TyMaybeWithLayout::Ty(args.as_coroutine().prefix_tys()[i])
}
},

View File

@@ -2421,10 +2421,10 @@ impl<'tcx> TyCtxt<'tcx> {
self.def_kind(trait_def_id) == DefKind::TraitAlias
}
/// Returns layout of a generator. Layout might be unavailable if the
/// generator is tainted by errors.
pub fn generator_layout(self, def_id: DefId) -> Option<&'tcx CoroutineLayout<'tcx>> {
self.optimized_mir(def_id).generator_layout()
/// Returns layout of a coroutine. Layout might be unavailable if the
/// coroutine is tainted by errors.
pub fn coroutine_layout(self, def_id: DefId) -> Option<&'tcx CoroutineLayout<'tcx>> {
self.optimized_mir(def_id).coroutine_layout()
}
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.

View File

@@ -154,12 +154,12 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
ty::Coroutine(def_id, args, movability) => {
let args = self.fold_closure_args(def_id, args);
Ty::new_generator(self.tcx, def_id, args, movability)
Ty::new_coroutine(self.tcx, def_id, args, movability)
}
ty::CoroutineWitness(def_id, args) => {
let args = self.fold_closure_args(def_id, args);
Ty::new_generator_witness(self.tcx, def_id, args)
Ty::new_coroutine_witness(self.tcx, def_id, args)
}
ty::Param(param) => {

View File

@@ -786,9 +786,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::Str => p!("str"),
ty::Coroutine(did, args, movability) => {
p!(write("{{"));
let generator_kind = self.tcx().generator_kind(did).unwrap();
let coroutine_kind = self.tcx().coroutine_kind(did).unwrap();
let should_print_movability =
self.should_print_verbose() || generator_kind == hir::CoroutineKind::Gen;
self.should_print_verbose() || coroutine_kind == hir::CoroutineKind::Gen;
if should_print_movability {
match movability {
@@ -798,7 +798,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
}
if !self.should_print_verbose() {
p!(write("{}", generator_kind));
p!(write("{}", coroutine_kind));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let span = self.tcx().def_span(did);
@@ -814,15 +814,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
} else {
p!(print_def_path(did, args));
p!(" upvar_tys=(");
if !args.as_generator().is_valid() {
if !args.as_coroutine().is_valid() {
p!("unavailable");
} else {
self = self.comma_sep(args.as_generator().upvar_tys().iter())?;
self = self.comma_sep(args.as_coroutine().upvar_tys().iter())?;
}
p!(")");
if args.as_generator().is_valid() {
p!(" ", print(args.as_generator().witness()));
if args.as_coroutine().is_valid() {
p!(" ", print(args.as_coroutine().witness()));
}
}
@@ -831,7 +831,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::CoroutineWitness(did, args) => {
p!(write("{{"));
if !self.tcx().sess.verbose() {
p!("generator witness");
p!("coroutine witness");
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let span = self.tcx().def_span(did);
@@ -1048,8 +1048,8 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
}
for (assoc_item_def_id, term) in assoc_items {
// Skip printing `<{generator@} as Coroutine<_>>::Return` from async blocks,
// unless we can find out what generator return type it comes from.
// Skip printing `<{coroutine@} as Coroutine<_>>::Return` from async blocks,
// unless we can find out what coroutine return type it comes from.
let term = if let Some(ty) = term.skip_binder().ty()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
@@ -1057,7 +1057,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
&& assoc.name == rustc_span::sym::Return
{
if let ty::Coroutine(_, args, _) = args.type_at(0).kind() {
let return_ty = args.as_generator().return_ty();
let return_ty = args.as_coroutine().return_ty();
if !return_ty.is_ty_var() {
return_ty.into()
} else {

View File

@@ -461,20 +461,20 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
if a_id == b_id =>
{
// All Coroutine types with the same id represent
// the (anonymous) type of the same generator expression. So
// the (anonymous) type of the same coroutine expression. So
// all of their regions should be equated.
let args = relate_args_invariantly(relation, a_args, b_args)?;
Ok(Ty::new_generator(tcx, a_id, args, movability))
Ok(Ty::new_coroutine(tcx, a_id, args, movability))
}
(&ty::CoroutineWitness(a_id, a_args), &ty::CoroutineWitness(b_id, b_args))
if a_id == b_id =>
{
// All CoroutineWitness types with the same id represent
// the (anonymous) type of the same generator expression. So
// the (anonymous) type of the same coroutine expression. So
// all of their regions should be equated.
let args = relate_args_invariantly(relation, a_args, b_args)?;
Ok(Ty::new_generator_witness(tcx, a_id, args))
Ok(Ty::new_coroutine_witness(tcx, a_id, args))
}
(&ty::Closure(a_id, a_args), &ty::Closure(b_id, b_args)) if a_id == b_id => {

View File

@@ -221,14 +221,14 @@ impl<'tcx> Article for TyKind<'tcx> {
/// type parameters is similar, but `CK` and `CS` are replaced by the
/// following type parameters:
///
/// * `GS`: The generator's "resume type", which is the type of the
/// * `GS`: The coroutine's "resume type", which is the type of the
/// argument passed to `resume`, and the type of `yield` expressions
/// inside the generator.
/// inside the coroutine.
/// * `GY`: The "yield type", which is the type of values passed to
/// `yield` inside the generator.
/// `yield` inside the coroutine.
/// * `GR`: The "return type", which is the type of value returned upon
/// completion of the generator.
/// * `GW`: The "generator witness".
/// completion of the coroutine.
/// * `GW`: The "coroutine witness".
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable, Lift)]
pub struct ClosureArgs<'tcx> {
/// Lifetime and type parameters from the enclosing function,
@@ -367,7 +367,7 @@ pub struct CoroutineArgsParts<'tcx, T> {
impl<'tcx> CoroutineArgs<'tcx> {
/// Construct `CoroutineArgs` from `CoroutineArgsParts`, containing `Args`
/// for the generator parent, alongside additional generator-specific components.
/// for the coroutine parent, alongside additional coroutine-specific components.
pub fn new(
tcx: TyCtxt<'tcx>,
parts: CoroutineArgsParts<'tcx, Ty<'tcx>>,
@@ -389,7 +389,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
}
}
/// Divides the generator args into their respective components.
/// Divides the coroutine args into their respective components.
/// The ordering assumed here must match that used by `CoroutineArgs::new` above.
fn split(self) -> CoroutineArgsParts<'tcx, GenericArg<'tcx>> {
match self.args[..] {
@@ -403,34 +403,34 @@ impl<'tcx> CoroutineArgs<'tcx> {
tupled_upvars_ty,
}
}
_ => bug!("generator args missing synthetics"),
_ => bug!("coroutine args missing synthetics"),
}
}
/// Returns `true` only if enough of the synthetic types are known to
/// allow using all of the methods on `CoroutineArgs` without panicking.
///
/// Used primarily by `ty::print::pretty` to be able to handle generator
/// Used primarily by `ty::print::pretty` to be able to handle coroutine
/// types that haven't had their synthetic types substituted in.
pub fn is_valid(self) -> bool {
self.args.len() >= 5 && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
}
/// Returns the substitutions of the generator's parent.
/// Returns the substitutions of the coroutine's parent.
pub fn parent_args(self) -> &'tcx [GenericArg<'tcx>] {
self.split().parent_args
}
/// This describes the types that can be contained in a generator.
/// This describes the types that can be contained in a coroutine.
/// It will be a type variable initially and unified in the last stages of typeck of a body.
/// It contains a tuple of all the types that could end up on a generator frame.
/// It contains a tuple of all the types that could end up on a coroutine frame.
/// The state transformation MIR pass may only produce layouts which mention types
/// in this tuple. Upvars are not counted here.
pub fn witness(self) -> Ty<'tcx> {
self.split().witness.expect_ty()
}
/// Returns an iterator over the list of types of captured paths by the generator.
/// Returns an iterator over the list of types of captured paths by the coroutine.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
@@ -443,28 +443,28 @@ impl<'tcx> CoroutineArgs<'tcx> {
}
}
/// Returns the tuple type representing the upvars for this generator.
/// Returns the tuple type representing the upvars for this coroutine.
#[inline]
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
self.split().tupled_upvars_ty.expect_ty()
}
/// Returns the type representing the resume type of the generator.
/// Returns the type representing the resume type of the coroutine.
pub fn resume_ty(self) -> Ty<'tcx> {
self.split().resume_ty.expect_ty()
}
/// Returns the type representing the yield type of the generator.
/// Returns the type representing the yield type of the coroutine.
pub fn yield_ty(self) -> Ty<'tcx> {
self.split().yield_ty.expect_ty()
}
/// Returns the type representing the return type of the generator.
/// Returns the type representing the return type of the coroutine.
pub fn return_ty(self) -> Ty<'tcx> {
self.split().return_ty.expect_ty()
}
/// Returns the "generator signature", which consists of its yield
/// Returns the "coroutine signature", which consists of its yield
/// and return types.
///
/// N.B., some bits of the code prefers to see this wrapped in a
@@ -474,7 +474,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
ty::Binder::dummy(self.sig())
}
/// Returns the "generator signature", which consists of its resume, yield
/// Returns the "coroutine signature", which consists of its resume, yield
/// and return types.
pub fn sig(self) -> GenSig<'tcx> {
ty::GenSig {
@@ -497,11 +497,11 @@ impl<'tcx> CoroutineArgs<'tcx> {
const RETURNED_NAME: &'static str = "Returned";
const POISONED_NAME: &'static str = "Panicked";
/// The valid variant indices of this generator.
/// The valid variant indices of this coroutine.
#[inline]
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
// FIXME requires optimized MIR
FIRST_VARIANT..tcx.generator_layout(def_id).unwrap().variant_fields.next_index()
FIRST_VARIANT..tcx.coroutine_layout(def_id).unwrap().variant_fields.next_index()
}
/// The discriminant for the given variant. Panics if the `variant_index` is
@@ -519,7 +519,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
Discr { val: variant_index.as_usize() as u128, ty: self.discr_ty(tcx) }
}
/// The set of all discriminants for the generator, enumerated with their
/// The set of all discriminants for the coroutine, enumerated with their
/// variant indices.
#[inline]
pub fn discriminants(
@@ -543,14 +543,14 @@ impl<'tcx> CoroutineArgs<'tcx> {
}
}
/// The type of the state discriminant used in the generator type.
/// The type of the state discriminant used in the coroutine type.
#[inline]
pub fn discr_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
tcx.types.u32
}
/// This returns the types of the MIR locals which had to be stored across suspension points.
/// It is calculated in rustc_mir_transform::generator::StateTransform.
/// It is calculated in rustc_mir_transform::coroutine::StateTransform.
/// All the types here must be in the tuple in CoroutineInterior.
///
/// The locals are grouped by their variant number. Note that some locals may
@@ -561,7 +561,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
let layout = tcx.generator_layout(def_id).unwrap();
let layout = tcx.coroutine_layout(def_id).unwrap();
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {
ty::EarlyBinder::bind(layout.field_tys[*field].ty).instantiate(tcx, self.args)
@@ -569,7 +569,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
})
}
/// This is the types of the fields of a generator which are not stored in a
/// This is the types of the fields of a coroutine which are not stored in a
/// variant.
#[inline]
pub fn prefix_tys(self) -> &'tcx List<Ty<'tcx>> {
@@ -584,14 +584,14 @@ pub enum UpvarArgs<'tcx> {
}
impl<'tcx> UpvarArgs<'tcx> {
/// Returns an iterator over the list of types of captured paths by the closure/generator.
/// Returns an iterator over the list of types of captured paths by the closure/coroutine.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
let tupled_tys = match self {
UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
UpvarArgs::Coroutine(args) => args.as_generator().tupled_upvars_ty(),
UpvarArgs::Coroutine(args) => args.as_coroutine().tupled_upvars_ty(),
};
match tupled_tys.kind() {
@@ -606,7 +606,7 @@ impl<'tcx> UpvarArgs<'tcx> {
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
match self {
UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
UpvarArgs::Coroutine(args) => args.as_generator().tupled_upvars_ty(),
UpvarArgs::Coroutine(args) => args.as_coroutine().tupled_upvars_ty(),
}
}
}
@@ -2165,22 +2165,22 @@ impl<'tcx> Ty<'tcx> {
}
#[inline]
pub fn new_generator(
pub fn new_coroutine(
tcx: TyCtxt<'tcx>,
def_id: DefId,
generator_args: GenericArgsRef<'tcx>,
coroutine_args: GenericArgsRef<'tcx>,
movability: hir::Movability,
) -> Ty<'tcx> {
debug_assert_eq!(
generator_args.len(),
coroutine_args.len(),
tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 5,
"generator constructed with incorrect number of substitutions"
"coroutine constructed with incorrect number of substitutions"
);
Ty::new(tcx, Coroutine(def_id, generator_args, movability))
Ty::new(tcx, Coroutine(def_id, coroutine_args, movability))
}
#[inline]
pub fn new_generator_witness(
pub fn new_coroutine_witness(
tcx: TyCtxt<'tcx>,
id: DefId,
args: GenericArgsRef<'tcx>,
@@ -2495,7 +2495,7 @@ impl<'tcx> Ty<'tcx> {
}
#[inline]
pub fn is_generator(self) -> bool {
pub fn is_coroutine(self) -> bool {
matches!(self.kind(), Coroutine(..))
}
@@ -2652,13 +2652,13 @@ impl<'tcx> Ty<'tcx> {
/// If the type contains variants, returns the valid range of variant indices.
//
// FIXME: This requires the optimized MIR in the case of generators.
// FIXME: This requires the optimized MIR in the case of coroutines.
#[inline]
pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
match self.kind() {
TyKind::Adt(adt, _) => Some(adt.variant_range()),
TyKind::Coroutine(def_id, args, _) => {
Some(args.as_generator().variant_range(*def_id, tcx))
Some(args.as_coroutine().variant_range(*def_id, tcx))
}
_ => None,
}
@@ -2667,7 +2667,7 @@ impl<'tcx> Ty<'tcx> {
/// If the type contains variants, returns the variant for `variant_index`.
/// Panics if `variant_index` is out of range.
//
// FIXME: This requires the optimized MIR in the case of generators.
// FIXME: This requires the optimized MIR in the case of coroutines.
#[inline]
pub fn discriminant_for_variant(
self,
@@ -2679,7 +2679,7 @@ impl<'tcx> Ty<'tcx> {
Some(adt.discriminant_for_variant(tcx, variant_index))
}
TyKind::Coroutine(def_id, args, _) => {
Some(args.as_generator().discriminant_for_variant(*def_id, tcx, variant_index))
Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index))
}
_ => None,
}
@@ -2689,7 +2689,7 @@ impl<'tcx> Ty<'tcx> {
pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self.kind() {
ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx),
ty::Coroutine(_, args, _) => args.as_generator().discr_ty(tcx),
ty::Coroutine(_, args, _) => args.as_coroutine().discr_ty(tcx),
ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => {
let assoc_items = tcx.associated_item_def_ids(

View File

@@ -189,9 +189,9 @@ pub struct TypeckResults<'tcx> {
/// Details may be find in `rustc_hir_analysis::check::rvalue_scopes`.
pub rvalue_scopes: RvalueScopes,
/// Stores the predicates that apply on generator witness types.
/// formatting modified file tests/ui/generator/retain-resume-ref.rs
pub generator_interior_predicates:
/// Stores the predicates that apply on coroutine witness types.
/// formatting modified file tests/ui/coroutine/retain-resume-ref.rs
pub coroutine_interior_predicates:
LocalDefIdMap<Vec<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>>,
/// We sometimes treat byte string literals (which are of type `&[u8; N]`)
@@ -231,7 +231,7 @@ impl<'tcx> TypeckResults<'tcx> {
closure_min_captures: Default::default(),
closure_fake_reads: Default::default(),
rvalue_scopes: Default::default(),
generator_interior_predicates: Default::default(),
coroutine_interior_predicates: Default::default(),
treat_byte_string_as_slice: Default::default(),
closure_size_eval: Default::default(),
offset_of_data: Default::default(),

View File

@@ -552,7 +552,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
/// Returns `true` if `def_id` refers to a definition that does not have its own
/// type-checking context, i.e. closure, generator or inline const.
/// type-checking context, i.e. closure, coroutine or inline const.
pub fn is_typeck_child(self, def_id: DefId) -> bool {
matches!(
self.def_kind(def_id),
@@ -686,13 +686,13 @@ impl<'tcx> TyCtxt<'tcx> {
}
/// Return the set of types that should be taken into account when checking
/// trait bounds on a generator's internal state.
pub fn generator_hidden_types(
/// trait bounds on a coroutine's internal state.
pub fn coroutine_hidden_types(
self,
def_id: DefId,
) -> impl Iterator<Item = ty::EarlyBinder<Ty<'tcx>>> {
let generator_layout = self.mir_generator_witnesses(def_id);
generator_layout
let coroutine_layout = self.mir_coroutine_witnesses(def_id);
coroutine_layout
.as_ref()
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
.filter(|decl| !decl.ignore_for_traits)
@@ -709,7 +709,7 @@ impl<'tcx> TyCtxt<'tcx> {
found_recursion: false,
found_any_recursion: false,
check_recursion: false,
expand_generators: false,
expand_coroutines: false,
tcx: self,
};
val.fold_with(&mut visitor)
@@ -729,7 +729,7 @@ impl<'tcx> TyCtxt<'tcx> {
found_recursion: false,
found_any_recursion: false,
check_recursion: true,
expand_generators: true,
expand_coroutines: true,
tcx: self,
};
@@ -746,9 +746,9 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str {
match def_kind {
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method",
DefKind::Coroutine => match self.generator_kind(def_id).unwrap() {
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
rustc_hir::CoroutineKind::Async(..) => "async closure",
rustc_hir::CoroutineKind::Gen => "generator",
rustc_hir::CoroutineKind::Gen => "coroutine",
},
_ => def_kind.descr(def_id),
}
@@ -763,7 +763,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str {
match def_kind {
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a",
DefKind::Coroutine => match self.generator_kind(def_id).unwrap() {
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
rustc_hir::CoroutineKind::Async(..) => "an",
rustc_hir::CoroutineKind::Gen => "a",
},
@@ -804,7 +804,7 @@ struct OpaqueTypeExpander<'tcx> {
primary_def_id: Option<DefId>,
found_recursion: bool,
found_any_recursion: bool,
expand_generators: bool,
expand_coroutines: bool,
/// Whether or not to check for recursive opaque types.
/// This is `true` when we're explicitly checking for opaque type
/// recursion, and 'false' otherwise to avoid unnecessary work.
@@ -842,7 +842,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
}
}
fn expand_generator(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option<Ty<'tcx>> {
fn expand_coroutine(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option<Ty<'tcx>> {
if self.found_any_recursion {
return None;
}
@@ -851,11 +851,11 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
let expanded_ty = match self.expanded_cache.get(&(def_id, args)) {
Some(expanded_ty) => *expanded_ty,
None => {
for bty in self.tcx.generator_hidden_types(def_id) {
for bty in self.tcx.coroutine_hidden_types(def_id) {
let hidden_ty = bty.instantiate(self.tcx, args);
self.fold_ty(hidden_ty);
}
let expanded_ty = Ty::new_generator_witness(self.tcx, def_id, args);
let expanded_ty = Ty::new_coroutine_witness(self.tcx, def_id, args);
self.expanded_cache.insert((def_id, args), expanded_ty);
expanded_ty
}
@@ -882,14 +882,14 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = *t.kind() {
self.expand_opaque_ty(def_id, args).unwrap_or(t)
} else if t.has_opaque_types() || t.has_generators() {
} else if t.has_opaque_types() || t.has_coroutines() {
t.super_fold_with(self)
} else {
t
};
if self.expand_generators {
if self.expand_coroutines {
if let ty::CoroutineWitness(def_id, args) = *t.kind() {
t = self.expand_generator(def_id, args).unwrap_or(t);
t = self.expand_coroutine(def_id, args).unwrap_or(t);
}
}
t
@@ -1419,7 +1419,7 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
found_recursion: false,
found_any_recursion: false,
check_recursion: false,
expand_generators: false,
expand_coroutines: false,
tcx,
};
val.fold_with(&mut visitor)

View File

@@ -47,7 +47,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
fn has_opaque_types(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
}
fn has_generators(&self) -> bool {
fn has_coroutines(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_GENERATOR)
}
fn references_error(&self) -> bool {