Skip to content

Commit

Permalink
s/generator/coroutine/
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 19, 2023
1 parent 851e0e5 commit e4f1277
Show file tree
Hide file tree
Showing 467 changed files with 2,195 additions and 2,191 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ pub struct LayoutS<FieldIdx: Idx, VariantIdx: Idx> {
/// Encodes information about multi-variant layouts.
/// Even with `Multiple` variants, a layout still has its own fields! Those are then
/// shared between all variants. One of them will be the discriminant,
/// but e.g. generators can have more.
/// but e.g. coroutines can have more.
///
/// To access all fields of this layout, both `fields` and the fields of the active variant
/// must be taken into account.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,8 @@ pub enum CaptureBy {
Ref,
}

/// The movability of a generator / closure literal:
/// whether a generator contains self-references, causing it to be `!Unpin`.
/// The movability of a coroutine / closure literal:
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, Debug, Copy)]
#[derive(HashStable_Generic)]
pub enum Movability {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ast_lowering_argument = argument
ast_lowering_assoc_ty_parentheses =
parenthesized generic arguments cannot be used in associated type constraints
ast_lowering_async_generators_not_supported =
`async` generators are not yet supported
ast_lowering_async_coroutines_not_supported =
`async` coroutines are not yet supported
ast_lowering_async_non_move_closure_not_supported =
`async` non-`move` closures with parameters are not currently supported
Expand Down Expand Up @@ -42,6 +42,9 @@ ast_lowering_clobber_abi_not_supported =
ast_lowering_closure_cannot_be_static = closures cannot be static
ast_lowering_coroutine_too_many_parameters =
too many parameters for a coroutine (expected 0 or 1 parameters)
ast_lowering_does_not_support_modifiers =
the `{$class_name}` register class does not support template modifiers
Expand All @@ -53,9 +56,6 @@ ast_lowering_functional_record_update_destructuring_assignment =
functional record updates are not allowed in destructuring assignments
.suggestion = consider removing the trailing pattern
ast_lowering_generator_too_many_parameters =
too many parameters for a generator (expected 0 or 1 parameters)
ast_lowering_generic_type_with_parentheses =
parenthesized type parameters may only be used with a `Fn` trait
.label = only `Fn` traits may use parentheses
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_generator_too_many_parameters, code = "E0628")]
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
pub struct CoroutineTooManyParameters {
#[primary_span]
pub fn_decl_span: Span,
Expand Down Expand Up @@ -161,7 +161,7 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_async_generators_not_supported, code = "E0727")]
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
pub struct AsyncCoroutinesNotSupported {
#[primary_span]
pub span: Span,
Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

/// Lower an `async` construct to a generator that implements `Future`.
/// Lower an `async` construct to a coroutine that implements `Future`.
///
/// This results in:
///
Expand Down Expand Up @@ -613,7 +613,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: unstable_span,
};

// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
// The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
let fn_decl = self.arena.alloc(hir::FnDecl {
inputs: arena_vec![self; input_ty],
output,
Expand All @@ -637,7 +637,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let params = arena_vec![self; param];

let body = self.lower_body(move |this| {
this.generator_kind = Some(hir::CoroutineKind::Async(async_gen_kind));
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_gen_kind));

let old_ctx = this.task_context;
this.task_context = Some(task_context_hid);
Expand Down Expand Up @@ -710,7 +710,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// ```
fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
let full_span = expr.span.to(await_kw_span);
match self.generator_kind {
match self.coroutine_kind {
Some(hir::CoroutineKind::Async(_)) => {}
Some(hir::CoroutineKind::Gen) | None => {
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
Expand Down Expand Up @@ -887,19 +887,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::ExprKind<'hir> {
let (binder_clause, generic_params) = self.lower_closure_binder(binder);

let (body_id, generator_option) = self.with_new_scopes(move |this| {
let (body_id, coroutine_option) = self.with_new_scopes(move |this| {
let prev = this.current_item;
this.current_item = Some(fn_decl_span);
let mut generator_kind = None;
let mut coroutine_kind = None;
let body_id = this.lower_fn_body(decl, |this| {
let e = this.lower_expr_mut(body);
generator_kind = this.generator_kind;
coroutine_kind = this.coroutine_kind;
e
});
let generator_option =
this.generator_movability_for_fn(&decl, fn_decl_span, generator_kind, movability);
let coroutine_option =
this.coroutine_movability_for_fn(&decl, fn_decl_span, coroutine_kind, movability);
this.current_item = prev;
(body_id, generator_option)
(body_id, coroutine_option)
});

let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
Expand All @@ -915,21 +915,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: body_id,
fn_decl_span: self.lower_span(fn_decl_span),
fn_arg_span: Some(self.lower_span(fn_arg_span)),
movability: generator_option,
movability: coroutine_option,
constness: self.lower_constness(constness),
});

hir::ExprKind::Closure(c)
}

fn generator_movability_for_fn(
fn coroutine_movability_for_fn(
&mut self,
decl: &FnDecl,
fn_decl_span: Span,
generator_kind: Option<hir::CoroutineKind>,
coroutine_kind: Option<hir::CoroutineKind>,
movability: Movability,
) -> Option<hir::Movability> {
match generator_kind {
match coroutine_kind {
Some(hir::CoroutineKind::Gen) => {
if decl.inputs.len() > 1 {
self.tcx.sess.emit_err(CoroutineTooManyParameters { fn_decl_span });
Expand Down Expand Up @@ -1444,12 +1444,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
match self.generator_kind {
match self.coroutine_kind {
Some(hir::CoroutineKind::Gen) => {}
Some(hir::CoroutineKind::Async(_)) => {
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
}
None => self.generator_kind = Some(hir::CoroutineKind::Gen),
None => self.coroutine_kind = Some(hir::CoroutineKind::Gen),
}

let expr =
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
is_in_loop_condition: false,
is_in_trait_impl: false,
is_in_dyn_type: false,
generator_kind: None,
coroutine_kind: None,
task_context: None,
current_item: None,
impl_trait_defs: Vec::new(),
Expand Down Expand Up @@ -974,7 +974,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
value: hir::Expr<'hir>,
) -> hir::BodyId {
let body = hir::Body {
generator_kind: self.generator_kind,
coroutine_kind: self.coroutine_kind,
params,
value: self.arena.alloc(value),
};
Expand All @@ -988,12 +988,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self,
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
) -> hir::BodyId {
let prev_gen_kind = self.generator_kind.take();
let prev_gen_kind = self.coroutine_kind.take();
let task_context = self.task_context.take();
let (parameters, result) = f(self);
let body_id = self.record_body(parameters, result);
self.task_context = task_context;
self.generator_kind = prev_gen_kind;
self.coroutine_kind = prev_gen_kind;
body_id
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ struct LoweringContext<'a, 'hir> {
/// Collect items that were created by lowering the current owner.
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,

generator_kind: Option<hir::CoroutineKind>,
coroutine_kind: Option<hir::CoroutineKind>,

/// When inside an `async` context, this is the `HirId` of the
/// `task_context` local bound to the resume argument of the generator.
/// `task_context` local bound to the resume argument of the coroutine.
task_context: Option<hir::HirId>,

/// Used to get the current `fn`'s def span to point to when using `await`
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
"consider removing `for<...>`"
);
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
gate_all!(generators, "yield syntax is experimental");
gate_all!(coroutines, "yield syntax is experimental");
gate_all!(raw_ref_op, "raw address of syntax is experimental");
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_borrowck/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
borrowck_assign_due_to_use_closure =
assignment occurs due to use in closure
borrowck_assign_due_to_use_generator =
assign occurs due to use in generator
borrowck_assign_due_to_use_coroutine =
assign occurs due to use in coroutine
borrowck_assign_part_due_to_use_closure =
assignment to part occurs due to use in closure
borrowck_assign_part_due_to_use_generator =
assign to part occurs due to use in generator
borrowck_assign_part_due_to_use_coroutine =
assign to part occurs due to use in coroutine
borrowck_borrow_due_to_use_closure =
borrow occurs due to use in closure
borrowck_borrow_due_to_use_generator =
borrow occurs due to use in generator
borrowck_borrow_due_to_use_coroutine =
borrow occurs due to use in coroutine
borrowck_calling_operator_moves_lhs =
calling this operator moves the left-hand side
Expand Down Expand Up @@ -142,11 +142,11 @@ borrowck_partial_var_move_by_use_in_closure =
*[false] moved
} due to use in closure
borrowck_partial_var_move_by_use_in_generator =
borrowck_partial_var_move_by_use_in_coroutine =
variable {$is_partial ->
[true] partially moved
*[false] moved
} due to use in generator
} due to use in coroutine
borrowck_returned_async_block_escaped =
returns an `async` block that contains a reference to a captured variable, which then escapes the closure body
Expand Down Expand Up @@ -180,15 +180,15 @@ borrowck_ty_no_impl_copy =
borrowck_use_due_to_use_closure =
use occurs due to use in closure
borrowck_use_due_to_use_generator =
use occurs due to use in generator
borrowck_use_due_to_use_coroutine =
use occurs due to use in coroutine
borrowck_used_impl_require_static =
the used `impl` has a `'static` requirement
borrowck_value_capture_here =
value captured {$is_within ->
[true] here by generator
[true] here by coroutine
*[false] here
}
Expand All @@ -207,20 +207,20 @@ borrowck_value_moved_here =
borrowck_var_borrow_by_use_in_closure =
borrow occurs due to use in closure
borrowck_var_borrow_by_use_in_generator =
borrow occurs due to use in generator
borrowck_var_borrow_by_use_in_coroutine =
borrow occurs due to use in coroutine
borrowck_var_borrow_by_use_place_in_closure =
{$is_single_var ->
*[true] borrow occurs
[false] borrows occur
} due to use of {$place} in closure
borrowck_var_borrow_by_use_place_in_generator =
borrowck_var_borrow_by_use_place_in_coroutine =
{$is_single_var ->
*[true] borrow occurs
[false] borrows occur
} due to use of {$place} in generator
} due to use of {$place} in coroutine
borrowck_var_cannot_escape_closure =
captured variable cannot escape `FnMut` closure body
Expand All @@ -234,8 +234,8 @@ borrowck_var_does_not_need_mut =
borrowck_var_first_borrow_by_use_place_in_closure =
first borrow occurs due to use of {$place} in closure
borrowck_var_first_borrow_by_use_place_in_generator =
first borrow occurs due to use of {$place} in generator
borrowck_var_first_borrow_by_use_place_in_coroutine =
first borrow occurs due to use of {$place} in coroutine
borrowck_var_here_captured = variable captured here
Expand All @@ -244,14 +244,14 @@ borrowck_var_here_defined = variable defined here
borrowck_var_move_by_use_in_closure =
move occurs due to use in closure
borrowck_var_move_by_use_in_generator =
move occurs due to use in generator
borrowck_var_move_by_use_in_coroutine =
move occurs due to use in coroutine
borrowck_var_mutable_borrow_by_use_place_in_closure =
mutable borrow occurs due to use of {$place} in closure
borrowck_var_second_borrow_by_use_place_in_closure =
second borrow occurs due to use of {$place} in closure
borrowck_var_second_borrow_by_use_place_in_generator =
second borrow occurs due to use of {$place} in generator
borrowck_var_second_borrow_by_use_place_in_coroutine =
second borrow occurs due to use of {$place} in coroutine
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
err
}

pub(crate) fn cannot_borrow_across_generator_yield(
pub(crate) fn cannot_borrow_across_coroutine_yield(
&self,
span: Span,
yield_span: Span,
Expand All @@ -377,7 +377,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
self,
span,
E0626,
"borrow may still be in use when generator yields",
"borrow may still be in use when coroutine yields",
);
err.span_label(yield_span, "possible yield occurs here");
err
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
PlaceContext::MutatingUse(MutatingUseContext::Projection) |

// Borrows only consider their local used at the point of the borrow.
// This won't affect the results since we use this analysis for generators
// This won't affect the results since we use this analysis for coroutines
// and we only care about the result at suspension points. Borrows cannot
// cross suspension points so this behavior is unproblematic.
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
Expand Down
Loading

0 comments on commit e4f1277

Please sign in to comment.