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

@ -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
@ -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
@ -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

View file

@ -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,
@ -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,

View file

@ -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:
///
@ -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,
@ -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);
@ -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 {
@ -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);
@ -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 });
@ -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 =

View file

@ -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(),
@ -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),
};
@ -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
}

View file

@ -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`