Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f937673

Browse files
committed
fix: rename generator to coroutine
Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
1 parent a356172 commit f937673

File tree

22 files changed

+100
-100
lines changed

22 files changed

+100
-100
lines changed

crates/hir-def/src/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Body {
3737
pub pats: Arena<Pat>,
3838
pub bindings: Arena<Binding>,
3939
pub labels: Arena<Label>,
40-
/// Id of the closure/generator that owns the corresponding binding. If a binding is owned by the
40+
/// Id of the closure/coroutine that owns the corresponding binding. If a binding is owned by the
4141
/// top level expression, it will not be listed in here.
4242
pub binding_owners: FxHashMap<BindingId, ExprId>,
4343
/// The patterns for the function's parameters. While the parameter types are

crates/hir-def/src/body/lower.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(super) fn lower(
8181
expander,
8282
current_try_block_label: None,
8383
is_lowering_assignee_expr: false,
84-
is_lowering_generator: false,
84+
is_lowering_coroutine: false,
8585
label_ribs: Vec::new(),
8686
current_binding_owner: None,
8787
}
@@ -99,7 +99,7 @@ struct ExprCollector<'a> {
9999
source_map: BodySourceMap,
100100

101101
is_lowering_assignee_expr: bool,
102-
is_lowering_generator: bool,
102+
is_lowering_coroutine: bool,
103103

104104
current_try_block_label: Option<LabelId>,
105105
// points to the expression that a try expression will target (replaces current_try_block_label)
@@ -417,7 +417,7 @@ impl ExprCollector<'_> {
417417
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
418418
}
419419
ast::Expr::YieldExpr(e) => {
420-
self.is_lowering_generator = true;
420+
self.is_lowering_coroutine = true;
421421
let expr = e.expr().map(|e| self.collect_expr(e));
422422
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
423423
}
@@ -525,26 +525,26 @@ impl ExprCollector<'_> {
525525
.and_then(|r| r.ty())
526526
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
527527

528-
let prev_is_lowering_generator = mem::take(&mut this.is_lowering_generator);
528+
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
529529
let prev_try_block_label = this.current_try_block_label.take();
530530

531531
let body = this.collect_expr_opt(e.body());
532532

533-
let closure_kind = if this.is_lowering_generator {
533+
let closure_kind = if this.is_lowering_coroutine {
534534
let movability = if e.static_token().is_some() {
535535
Movability::Static
536536
} else {
537537
Movability::Movable
538538
};
539-
ClosureKind::Generator(movability)
539+
ClosureKind::Coroutine(movability)
540540
} else if e.async_token().is_some() {
541541
ClosureKind::Async
542542
} else {
543543
ClosureKind::Closure
544544
};
545545
let capture_by =
546546
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
547-
this.is_lowering_generator = prev_is_lowering_generator;
547+
this.is_lowering_coroutine = prev_is_lowering_coroutine;
548548
this.current_binding_owner = prev_binding_owner;
549549
this.current_try_block_label = prev_try_block_label;
550550
this.body.exprs[result_expr_id] = Expr::Closure {

crates/hir-def/src/body/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl Printer<'_> {
384384
}
385385
Expr::Closure { args, arg_types, ret_type, body, closure_kind, capture_by } => {
386386
match closure_kind {
387-
ClosureKind::Generator(Movability::Static) => {
387+
ClosureKind::Coroutine(Movability::Static) => {
388388
w!(self, "static ");
389389
}
390390
ClosureKind::Async => {

crates/hir-def/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub struct InlineAsm {
300300
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
301301
pub enum ClosureKind {
302302
Closure,
303-
Generator(Movability),
303+
Coroutine(Movability),
304304
Async,
305305
}
306306

crates/hir-def/src/lang_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ language_item_table! {
334334
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
335335

336336
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
337-
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
338-
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
337+
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
338+
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
339339
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
340340
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
341341

crates/hir-ty/src/builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,21 @@ impl TyBuilder<()> {
227227
TyBuilder::new((), params, parent_subst)
228228
}
229229

230-
/// Creates a `TyBuilder` to build `Substitution` for a generator defined in `parent`.
230+
/// Creates a `TyBuilder` to build `Substitution` for a coroutine defined in `parent`.
231231
///
232-
/// A generator's substitution consists of:
233-
/// - resume type of generator
234-
/// - yield type of generator ([`Generator::Yield`](std::ops::Generator::Yield))
235-
/// - return type of generator ([`Generator::Return`](std::ops::Generator::Return))
232+
/// A coroutine's substitution consists of:
233+
/// - resume type of coroutine
234+
/// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
235+
/// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
236236
/// - generic parameters in scope on `parent`
237237
/// in this order.
238238
///
239239
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
240240
/// should only push exactly 3 `GenericArg`s before building.
241-
pub fn subst_for_generator(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
241+
pub fn subst_for_coroutine(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
242242
let parent_subst =
243243
parent.as_generic_def_id().map(|p| generics(db.upcast(), p).placeholder_subst(db));
244-
// These represent resume type, yield type, and return type of generator.
244+
// These represent resume type, yield type, and return type of coroutine.
245245
let params = std::iter::repeat(ParamKind::Type).take(3).collect();
246246
TyBuilder::new((), params, parent_subst)
247247
}

crates/hir-ty/src/chalk_db.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,12 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
428428
&self,
429429
id: chalk_ir::GeneratorId<Interner>,
430430
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
431-
let (parent, expr) = self.db.lookup_intern_generator(id.into());
431+
let (parent, expr) = self.db.lookup_intern_coroutine(id.into());
432432

433433
// We fill substitution with unknown type, because we only need to know whether the generic
434434
// params are types or consts to build `Binders` and those being filled up are for
435-
// `resume_type`, `yield_type`, and `return_type` of the generator in question.
436-
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
435+
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
436+
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
437437

438438
let input_output = rust_ir::GeneratorInputOutputDatum {
439439
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
@@ -453,10 +453,10 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
453453

454454
let movability = match self.db.body(parent)[expr] {
455455
hir_def::hir::Expr::Closure {
456-
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
456+
closure_kind: hir_def::hir::ClosureKind::Coroutine(movability),
457457
..
458458
} => movability,
459-
_ => unreachable!("non generator expression interned as generator"),
459+
_ => unreachable!("non coroutine expression interned as coroutine"),
460460
};
461461
let movability = match movability {
462462
Movability::Static => rust_ir::Movability::Static,
@@ -473,9 +473,9 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
473473
let inner_types =
474474
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
475475

476-
let (parent, _) = self.db.lookup_intern_generator(id.into());
476+
let (parent, _) = self.db.lookup_intern_coroutine(id.into());
477477
// See the comment in `generator_datum()` for unknown types.
478-
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
478+
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
479479
let it = subst
480480
.iter(Interner)
481481
.map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
@@ -617,7 +617,7 @@ fn well_known_trait_from_lang_item(item: LangItem) -> Option<WellKnownTrait> {
617617
LangItem::Fn => WellKnownTrait::Fn,
618618
LangItem::FnMut => WellKnownTrait::FnMut,
619619
LangItem::FnOnce => WellKnownTrait::FnOnce,
620-
LangItem::Generator => WellKnownTrait::Generator,
620+
LangItem::Coroutine => WellKnownTrait::Generator,
621621
LangItem::Sized => WellKnownTrait::Sized,
622622
LangItem::Unpin => WellKnownTrait::Unpin,
623623
LangItem::Unsize => WellKnownTrait::Unsize,
@@ -639,7 +639,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
639639
WellKnownTrait::Fn => LangItem::Fn,
640640
WellKnownTrait::FnMut => LangItem::FnMut,
641641
WellKnownTrait::FnOnce => LangItem::FnOnce,
642-
WellKnownTrait::Generator => LangItem::Generator,
642+
WellKnownTrait::Generator => LangItem::Coroutine,
643643
WellKnownTrait::Sized => LangItem::Sized,
644644
WellKnownTrait::Tuple => LangItem::Tuple,
645645
WellKnownTrait::Unpin => LangItem::Unpin,

crates/hir-ty/src/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
199199
#[salsa::interned]
200200
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
201201
#[salsa::interned]
202-
fn intern_generator(&self, id: (DefWithBodyId, ExprId)) -> InternedGeneratorId;
202+
fn intern_coroutine(&self, id: (DefWithBodyId, ExprId)) -> InternedCoroutineId;
203203

204204
#[salsa::invoke(chalk_db::associated_ty_data_query)]
205205
fn associated_ty_data(
@@ -335,8 +335,8 @@ pub struct InternedClosureId(salsa::InternId);
335335
impl_intern_key!(InternedClosureId);
336336

337337
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
338-
pub struct InternedGeneratorId(salsa::InternId);
339-
impl_intern_key!(InternedGeneratorId);
338+
pub struct InternedCoroutineId(salsa::InternId);
339+
impl_intern_key!(InternedCoroutineId);
340340

341341
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
342342
/// we have different IDs for struct and enum variant constructors.

crates/hir-ty/src/display.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl DisplayTarget {
276276
pub enum DisplaySourceCodeError {
277277
PathNotFound,
278278
UnknownType,
279-
Generator,
279+
Coroutine,
280280
OpaqueType,
281281
}
282282

@@ -659,8 +659,8 @@ fn render_const_scalar(
659659
}
660660
TyKind::Never => f.write_str("!"),
661661
TyKind::Closure(_, _) => f.write_str("<closure>"),
662-
TyKind::Generator(_, _) => f.write_str("<generator>"),
663-
TyKind::GeneratorWitness(_, _) => f.write_str("<generator-witness>"),
662+
TyKind::Generator(_, _) => f.write_str("<coroutine>"),
663+
TyKind::GeneratorWitness(_, _) => f.write_str("<coroutine-witness>"),
664664
// The below arms are unreachable, since const eval will bail out before here.
665665
TyKind::Foreign(_) => f.write_str("<extern-type>"),
666666
TyKind::Error
@@ -1208,7 +1208,7 @@ impl HirDisplay for Ty {
12081208
TyKind::Generator(_, subst) => {
12091209
if f.display_target.is_source_code() {
12101210
return Err(HirDisplayError::DisplaySourceCodeError(
1211-
DisplaySourceCodeError::Generator,
1211+
DisplaySourceCodeError::Coroutine,
12121212
));
12131213
}
12141214
let subst = subst.as_slice(Interner);
@@ -1229,10 +1229,10 @@ impl HirDisplay for Ty {
12291229
ret_ty.hir_fmt(f)?;
12301230
} else {
12311231
// This *should* be unreachable, but fallback just in case.
1232-
write!(f, "{{generator}}")?;
1232+
write!(f, "{{coroutine}}")?;
12331233
}
12341234
}
1235-
TyKind::GeneratorWitness(..) => write!(f, "{{generator witness}}")?,
1235+
TyKind::GeneratorWitness(..) => write!(f, "{{coroutine witness}}")?,
12361236
}
12371237
Ok(())
12381238
}

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ pub(crate) struct InferenceContext<'a> {
534534
/// expressions. If `None`, this is in a context where return is
535535
/// inappropriate, such as a const expression.
536536
return_coercion: Option<CoerceMany>,
537-
/// The resume type and the yield type, respectively, of the generator being inferred.
537+
/// The resume type and the yield type, respectively, of the coroutine being inferred.
538538
resume_yield_tys: Option<(Ty, Ty)>,
539539
diverges: Diverges,
540540
breakables: Vec<BreakableContext>,

crates/hir-ty/src/infer/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
use super::{Expectation, InferenceContext};
3535

3636
impl InferenceContext<'_> {
37-
// This function handles both closures and generators.
37+
// This function handles both closures and coroutines.
3838
pub(super) fn deduce_closure_type_from_expectations(
3939
&mut self,
4040
closure_expr: ExprId,
@@ -50,7 +50,7 @@ impl InferenceContext<'_> {
5050
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
5151
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
5252

53-
// Generators are not Fn* so return early.
53+
// Coroutines are not Fn* so return early.
5454
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
5555
return;
5656
}

crates/hir-ty/src/infer/expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl InferenceContext<'_> {
233233
.intern(Interner);
234234

235235
let (id, ty, resume_yield_tys) = match closure_kind {
236-
ClosureKind::Generator(_) => {
236+
ClosureKind::Coroutine(_) => {
237237
// FIXME: report error when there are more than 1 parameter.
238238
let resume_ty = match sig_tys.first() {
239239
// When `sig_tys.len() == 1` the first type is the return type, not the
@@ -243,16 +243,16 @@ impl InferenceContext<'_> {
243243
};
244244
let yield_ty = self.table.new_type_var();
245245

246-
let subst = TyBuilder::subst_for_generator(self.db, self.owner)
246+
let subst = TyBuilder::subst_for_coroutine(self.db, self.owner)
247247
.push(resume_ty.clone())
248248
.push(yield_ty.clone())
249249
.push(ret_ty.clone())
250250
.build();
251251

252-
let generator_id = self.db.intern_generator((self.owner, tgt_expr)).into();
253-
let generator_ty = TyKind::Generator(generator_id, subst).intern(Interner);
252+
let coroutine_id = self.db.intern_coroutine((self.owner, tgt_expr)).into();
253+
let coroutine_ty = TyKind::Generator(coroutine_id, subst).intern(Interner);
254254

255-
(None, generator_ty, Some((resume_ty, yield_ty)))
255+
(None, coroutine_ty, Some((resume_ty, yield_ty)))
256256
}
257257
ClosureKind::Closure | ClosureKind::Async => {
258258
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
@@ -503,7 +503,7 @@ impl InferenceContext<'_> {
503503
}
504504
resume_ty
505505
} else {
506-
// FIXME: report error (yield expr in non-generator)
506+
// FIXME: report error (yield expr in non-coroutine)
507507
self.result.standard_types.unknown.clone()
508508
}
509509
}

crates/hir-ty/src/mapping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
103103
}
104104
}
105105

106-
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedGeneratorId {
106+
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedCoroutineId {
107107
fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
108108
Self::from_intern_id(id.0)
109109
}
110110
}
111111

112-
impl From<crate::db::InternedGeneratorId> for chalk_ir::GeneratorId<Interner> {
113-
fn from(id: crate::db::InternedGeneratorId) -> Self {
112+
impl From<crate::db::InternedCoroutineId> for chalk_ir::GeneratorId<Interner> {
113+
fn from(id: crate::db::InternedCoroutineId) -> Self {
114114
chalk_ir::GeneratorId(id.as_intern_id())
115115
}
116116
}

0 commit comments

Comments
 (0)