Skip to content

Commit 4de8954

Browse files
committed
Auto merge of rust-lang#16196 - mohe2015:rename-generator-to-coroutine, r=Veykril
Rename generator to coroutine Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html) This makes it much easier to test code with the nightly compiler.
2 parents b9fd12b + fe35447 commit 4de8954

29 files changed

+1047
-908
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ oorandom = "11.1.3"
2323
tracing.workspace = true
2424
rustc-hash.workspace = true
2525
scoped-tls = "1.0.0"
26-
chalk-solve = { version = "0.95.0", default-features = false }
27-
chalk-ir = "0.95.0"
28-
chalk-recursive = { version = "0.95.0", default-features = false }
29-
chalk-derive = "0.95.0"
26+
chalk-solve = { version = "0.96.0", default-features = false }
27+
chalk-ir = "0.96.0"
28+
chalk-recursive = { version = "0.96.0", default-features = false }
29+
chalk-derive = "0.96.0"
3030
la-arena.workspace = true
3131
once_cell = "1.17.0"
3232
triomphe.workspace = true

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: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,18 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
424424
fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId<Interner>) -> String {
425425
format!("fn_{}", fn_def_id.0)
426426
}
427-
fn generator_datum(
427+
fn coroutine_datum(
428428
&self,
429-
id: chalk_ir::GeneratorId<Interner>,
430-
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
431-
let (parent, expr) = self.db.lookup_intern_generator(id.into());
429+
id: chalk_ir::CoroutineId<Interner>,
430+
) -> Arc<chalk_solve::rust_ir::CoroutineDatum<Interner>> {
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

438-
let input_output = rust_ir::GeneratorInputOutputDatum {
438+
let input_output = rust_ir::CoroutineInputOutputDatum {
439439
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
440440
.intern(Interner),
441441
yield_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 1))
@@ -453,35 +453,35 @@ 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,
463463
Movability::Movable => rust_ir::Movability::Movable,
464464
};
465465

466-
Arc::new(rust_ir::GeneratorDatum { movability, input_output })
466+
Arc::new(rust_ir::CoroutineDatum { movability, input_output })
467467
}
468-
fn generator_witness_datum(
468+
fn coroutine_witness_datum(
469469
&self,
470-
id: chalk_ir::GeneratorId<Interner>,
471-
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<Interner>> {
470+
id: chalk_ir::CoroutineId<Interner>,
471+
) -> Arc<chalk_solve::rust_ir::CoroutineWitnessDatum<Interner>> {
472472
// FIXME: calculate inner types
473473
let inner_types =
474-
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
474+
rust_ir::CoroutineWitnessExistential { types: wrap_empty_binders(vec![]) };
475475

476-
let (parent, _) = self.db.lookup_intern_generator(id.into());
477-
// See the comment in `generator_datum()` for unknown types.
478-
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
476+
let (parent, _) = self.db.lookup_intern_coroutine(id.into());
477+
// See the comment in `coroutine_datum()` for unknown types.
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()));
482482
let inner_types = crate::make_type_and_const_binders(it, inner_types);
483483

484-
Arc::new(rust_ir::GeneratorWitnessDatum { inner_types })
484+
Arc::new(rust_ir::CoroutineWitnessDatum { inner_types })
485485
}
486486

487487
fn unification_database(&self) -> &dyn chalk_ir::UnificationDatabase<Interner> {
@@ -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::Coroutine,
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::Coroutine => 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: 7 additions & 7 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::Coroutine(_, _) => f.write_str("<coroutine>"),
663+
TyKind::CoroutineWitness(_, _) => 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
@@ -1205,10 +1205,10 @@ impl HirDisplay for Ty {
12051205
write!(f, "{{unknown}}")?;
12061206
}
12071207
TyKind::InferenceVar(..) => write!(f, "_")?,
1208-
TyKind::Generator(_, subst) => {
1208+
TyKind::Coroutine(_, 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::CoroutineWitness(..) => 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: 3 additions & 3 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,8 +50,8 @@ 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.
54-
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
53+
// Coroutines are not Fn* so return early.
54+
if matches!(closure_ty.kind(Interner), TyKind::Coroutine(..)) {
5555
return;
5656
}
5757

0 commit comments

Comments
 (0)