1
Fork 0

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

@ -98,7 +98,7 @@ fn fn_sig_for_fn_abi<'tcx>(
)
}
ty::Coroutine(did, args, _) => {
let sig = args.as_generator().poly_sig();
let sig = args.as_coroutine().poly_sig();
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
@ -116,11 +116,11 @@ fn fn_sig_for_fn_abi<'tcx>(
let env_ty = Ty::new_adt(tcx, pin_adt_ref, pin_args);
let sig = sig.skip_binder();
// The `FnSig` and the `ret_ty` here is for a generators main
// The `FnSig` and the `ret_ty` here is for a coroutines main
// `Coroutine::resume(...) -> CoroutineState` function in case we
// have an ordinary generator, or the `Future::poll(...) -> Poll`
// function in case this is a special generator backing an async construct.
let (resume_ty, ret_ty) = if tcx.generator_is_async(did) {
// have an ordinary coroutine, or the `Future::poll(...) -> Poll`
// function in case this is a special coroutine backing an async construct.
let (resume_ty, ret_ty) = if tcx.coroutine_is_async(did) {
// The signature should be `Future::poll(_, &mut Context<'_>) -> Poll<Output>`
let poll_did = tcx.require_lang_item(LangItem::Poll, None);
let poll_adt_ref = tcx.adt_def(poll_did);

View file

@ -246,12 +246,12 @@ fn resolve_associated_item<'tcx>(
})
}
} else if Some(trait_ref.def_id) == lang_items.future_trait() {
let ty::Coroutine(generator_def_id, args, _) = *rcvr_args.type_at(0).kind() else {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else {
bug!()
};
if Some(trait_item_id) == tcx.lang_items().future_poll_fn() {
// `Future::poll` is generated by the compiler.
Some(Instance { def: ty::InstanceDef::Item(generator_def_id), args: args })
Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args: args })
} else {
// All other methods are default methods of the `Future` trait.
// (this assumes that `ImplSource::Builtin` is only used for methods on `Future`)
@ -259,7 +259,7 @@ fn resolve_associated_item<'tcx>(
Some(Instance::new(trait_item_id, rcvr_args))
}
} else if Some(trait_ref.def_id) == lang_items.gen_trait() {
let ty::Coroutine(generator_def_id, args, _) = *rcvr_args.type_at(0).kind() else {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else {
bug!()
};
if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::resume {
@ -268,12 +268,12 @@ fn resolve_associated_item<'tcx>(
// `InstanceDef::Item` pointing to a trait default method body if
// it is given a default implementation by the trait.
span_bug!(
tcx.def_span(generator_def_id),
"no definition for `{trait_ref}::{}` for built-in generator type",
tcx.def_span(coroutine_def_id),
"no definition for `{trait_ref}::{}` for built-in coroutine type",
tcx.item_name(trait_item_id)
)
}
Some(Instance { def: ty::InstanceDef::Item(generator_def_id), args })
Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args })
} else if tcx.fn_trait_kind_from_def_id(trait_ref.def_id).is_some() {
// FIXME: This doesn't check for malformed libcore that defines, e.g.,
// `trait Fn { fn call_once(&self) { .. } }`. This is mostly for extension

View file

@ -314,7 +314,7 @@ fn layout_of_uncached<'tcx>(
tcx.mk_layout(unit)
}
ty::Coroutine(def_id, args, _) => generator_layout(cx, ty, def_id, args)?,
ty::Coroutine(def_id, args, _) => coroutine_layout(cx, ty, def_id, args)?,
ty::Closure(_, ref args) => {
let tys = args.as_closure().upvar_tys();
@ -593,7 +593,7 @@ enum SavedLocalEligibility {
Ineligible(Option<FieldIdx>),
}
// When laying out generators, we divide our saved local fields into two
// When laying out coroutines, we divide our saved local fields into two
// categories: overlap-eligible and overlap-ineligible.
//
// Those fields which are ineligible for overlap go in a "prefix" at the
@ -613,7 +613,7 @@ enum SavedLocalEligibility {
// of any variant.
/// Compute the eligibility and assignment of each local.
fn generator_saved_local_eligibility(
fn coroutine_saved_local_eligibility(
info: &CoroutineLayout<'_>,
) -> (BitSet<CoroutineSavedLocal>, IndexVec<CoroutineSavedLocal, SavedLocalEligibility>) {
use SavedLocalEligibility::*;
@ -622,7 +622,7 @@ fn generator_saved_local_eligibility(
IndexVec::from_elem(Unassigned, &info.field_tys);
// The saved locals not eligible for overlap. These will get
// "promoted" to the prefix of our generator.
// "promoted" to the prefix of our coroutine.
let mut ineligible_locals = BitSet::new_empty(info.field_tys.len());
// Figure out which of our saved locals are fields in only
@ -660,7 +660,7 @@ fn generator_saved_local_eligibility(
for local_b in info.storage_conflicts.iter(local_a) {
// local_a and local_b are storage live at the same time, therefore they
// cannot overlap in the generator layout. The only way to guarantee
// cannot overlap in the coroutine layout. The only way to guarantee
// this is if they are in the same variant, or one is ineligible
// (which means it is stored in every variant).
if ineligible_locals.contains(local_b) || assignments[local_a] == assignments[local_b] {
@ -705,13 +705,13 @@ fn generator_saved_local_eligibility(
assignments[local] = Ineligible(Some(FieldIdx::from_usize(idx)));
}
}
debug!("generator saved local assignments: {:?}", assignments);
debug!("coroutine saved local assignments: {:?}", assignments);
(ineligible_locals, assignments)
}
/// Compute the full generator layout.
fn generator_layout<'tcx>(
/// Compute the full coroutine layout.
fn coroutine_layout<'tcx>(
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
ty: Ty<'tcx>,
def_id: hir::def_id::DefId,
@ -721,15 +721,15 @@ fn generator_layout<'tcx>(
let tcx = cx.tcx;
let subst_field = |ty: Ty<'tcx>| EarlyBinder::bind(ty).instantiate(tcx, args);
let Some(info) = tcx.generator_layout(def_id) else {
let Some(info) = tcx.coroutine_layout(def_id) else {
return Err(error(cx, LayoutError::Unknown(ty)));
};
let (ineligible_locals, assignments) = generator_saved_local_eligibility(&info);
let (ineligible_locals, assignments) = coroutine_saved_local_eligibility(&info);
// Build a prefix layout, including "promoting" all ineligible
// locals as part of the prefix. We compute the layout of all of
// these fields at once to get optimal packing.
let tag_index = args.as_generator().prefix_tys().len();
let tag_index = args.as_coroutine().prefix_tys().len();
// `info.variant_fields` already accounts for the reserved variants, so no need to add them.
let max_discr = (info.variant_fields.len() - 1) as u128;
@ -746,7 +746,7 @@ fn generator_layout<'tcx>(
.map(|ty| Ty::new_maybe_uninit(tcx, ty))
.map(|ty| Ok(cx.layout_of(ty)?.layout));
let prefix_layouts = args
.as_generator()
.as_coroutine()
.prefix_tys()
.iter()
.map(|ty| Ok(cx.layout_of(ty)?.layout))
@ -907,7 +907,7 @@ fn generator_layout<'tcx>(
max_repr_align: None,
unadjusted_abi_align: align.abi,
});
debug!("generator layout ({:?}): {:#?}", ty, layout);
debug!("coroutine layout ({:?}): {:#?}", ty, layout);
Ok(layout)
}
@ -957,10 +957,10 @@ fn record_layout_for_printing_outlined<'tcx>(
}
ty::Coroutine(def_id, args, _) => {
debug!("print-type-size t: `{:?}` record generator", layout.ty);
debug!("print-type-size t: `{:?}` record coroutine", layout.ty);
// Coroutines always have a begin/poisoned/end state with additional suspend points
let (variant_infos, opt_discr_size) =
variant_info_for_generator(cx, layout, def_id, args);
variant_info_for_coroutine(cx, layout, def_id, args);
record(DataTypeKind::Coroutine, false, opt_discr_size, variant_infos);
}
@ -1046,7 +1046,7 @@ fn variant_info_for_adt<'tcx>(
}
}
fn variant_info_for_generator<'tcx>(
fn variant_info_for_coroutine<'tcx>(
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
layout: TyAndLayout<'tcx>,
def_id: DefId,
@ -1056,12 +1056,12 @@ fn variant_info_for_generator<'tcx>(
return (vec![], None);
};
let generator = cx.tcx.optimized_mir(def_id).generator_layout().unwrap();
let coroutine = cx.tcx.optimized_mir(def_id).coroutine_layout().unwrap();
let upvar_names = cx.tcx.closure_saved_names_of_captured_variables(def_id);
let mut upvars_size = Size::ZERO;
let upvar_fields: Vec<_> = args
.as_generator()
.as_coroutine()
.upvar_tys()
.iter()
.zip(upvar_names)
@ -1080,7 +1080,7 @@ fn variant_info_for_generator<'tcx>(
})
.collect();
let mut variant_infos: Vec<_> = generator
let mut variant_infos: Vec<_> = coroutine
.variant_fields
.iter_enumerated()
.map(|(variant_idx, variant_def)| {
@ -1096,8 +1096,8 @@ fn variant_info_for_generator<'tcx>(
variant_size = variant_size.max(offset + field_layout.size);
FieldInfo {
kind: FieldKind::CoroutineLocal,
name: generator.field_names[*local].unwrap_or(Symbol::intern(&format!(
".generator_field{}",
name: coroutine.field_names[*local].unwrap_or(Symbol::intern(&format!(
".coroutine_field{}",
local.as_usize()
))),
offset: offset.bytes(),
@ -1115,8 +1115,8 @@ fn variant_info_for_generator<'tcx>(
// This `if` deserves some explanation.
//
// The layout code has a choice of where to place the discriminant of this generator.
// If the discriminant of the generator is placed early in the layout (before the
// The layout code has a choice of where to place the discriminant of this coroutine.
// If the discriminant of the coroutine is placed early in the layout (before the
// variant's own fields), then it'll implicitly be counted towards the size of the
// variant, since we use the maximum offset to calculate size.
// (side-note: I know this is a bit problematic given upvars placement, etc).
@ -1147,7 +1147,7 @@ fn variant_info_for_generator<'tcx>(
// The first three variants are hardcoded to be `UNRESUMED`, `RETURNED` and `POISONED`.
// We will move the `RETURNED` and `POISONED` elements to the end so we
// are left with a sorting order according to the generators yield points:
// are left with a sorting order according to the coroutines yield points:
// First `Unresumed`, then the `SuspendN` followed by `Returned` and `Panicked` (POISONED).
let end_states = variant_infos.drain(1..=2);
let end_states: Vec<_> = end_states.collect();

View file

@ -130,9 +130,9 @@ where
for component in components {
match *component.kind() {
// The information required to determine whether a generator has drop is
// The information required to determine whether a coroutine has drop is
// computed on MIR, while this very method is used to build MIR.
// To avoid cycles, we consider that generators always require drop.
// To avoid cycles, we consider that coroutines always require drop.
ty::Coroutine(..) => {
return Some(Err(AlwaysRequiresDrop));
}

View file

@ -322,7 +322,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Impl { .. } => {}
// Closures and generators are type checked with their parent, so there is no difference here.
// Closures and coroutines are type checked with their parent, so there is no difference here.
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => {
return tcx.opaque_types_defined_by(tcx.local_parent(item));
}