mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
fix: rename generator to coroutine
Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
This commit is contained in:
parent
a356172f92
commit
f937673ce2
22 changed files with 100 additions and 100 deletions
|
@ -37,7 +37,7 @@ pub struct Body {
|
||||||
pub pats: Arena<Pat>,
|
pub pats: Arena<Pat>,
|
||||||
pub bindings: Arena<Binding>,
|
pub bindings: Arena<Binding>,
|
||||||
pub labels: Arena<Label>,
|
pub labels: Arena<Label>,
|
||||||
/// Id of the closure/generator that owns the corresponding binding. If a binding is owned by the
|
/// Id of the closure/coroutine that owns the corresponding binding. If a binding is owned by the
|
||||||
/// top level expression, it will not be listed in here.
|
/// top level expression, it will not be listed in here.
|
||||||
pub binding_owners: FxHashMap<BindingId, ExprId>,
|
pub binding_owners: FxHashMap<BindingId, ExprId>,
|
||||||
/// The patterns for the function's parameters. While the parameter types are
|
/// The patterns for the function's parameters. While the parameter types are
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub(super) fn lower(
|
||||||
expander,
|
expander,
|
||||||
current_try_block_label: None,
|
current_try_block_label: None,
|
||||||
is_lowering_assignee_expr: false,
|
is_lowering_assignee_expr: false,
|
||||||
is_lowering_generator: false,
|
is_lowering_coroutine: false,
|
||||||
label_ribs: Vec::new(),
|
label_ribs: Vec::new(),
|
||||||
current_binding_owner: None,
|
current_binding_owner: None,
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ struct ExprCollector<'a> {
|
||||||
source_map: BodySourceMap,
|
source_map: BodySourceMap,
|
||||||
|
|
||||||
is_lowering_assignee_expr: bool,
|
is_lowering_assignee_expr: bool,
|
||||||
is_lowering_generator: bool,
|
is_lowering_coroutine: bool,
|
||||||
|
|
||||||
current_try_block_label: Option<LabelId>,
|
current_try_block_label: Option<LabelId>,
|
||||||
// points to the expression that a try expression will target (replaces current_try_block_label)
|
// points to the expression that a try expression will target (replaces current_try_block_label)
|
||||||
|
@ -417,7 +417,7 @@ impl ExprCollector<'_> {
|
||||||
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::Expr::YieldExpr(e) => {
|
ast::Expr::YieldExpr(e) => {
|
||||||
self.is_lowering_generator = true;
|
self.is_lowering_coroutine = true;
|
||||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||||
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
|
@ -525,18 +525,18 @@ impl ExprCollector<'_> {
|
||||||
.and_then(|r| r.ty())
|
.and_then(|r| r.ty())
|
||||||
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
|
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
|
||||||
|
|
||||||
let prev_is_lowering_generator = mem::take(&mut this.is_lowering_generator);
|
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
|
||||||
let prev_try_block_label = this.current_try_block_label.take();
|
let prev_try_block_label = this.current_try_block_label.take();
|
||||||
|
|
||||||
let body = this.collect_expr_opt(e.body());
|
let body = this.collect_expr_opt(e.body());
|
||||||
|
|
||||||
let closure_kind = if this.is_lowering_generator {
|
let closure_kind = if this.is_lowering_coroutine {
|
||||||
let movability = if e.static_token().is_some() {
|
let movability = if e.static_token().is_some() {
|
||||||
Movability::Static
|
Movability::Static
|
||||||
} else {
|
} else {
|
||||||
Movability::Movable
|
Movability::Movable
|
||||||
};
|
};
|
||||||
ClosureKind::Generator(movability)
|
ClosureKind::Coroutine(movability)
|
||||||
} else if e.async_token().is_some() {
|
} else if e.async_token().is_some() {
|
||||||
ClosureKind::Async
|
ClosureKind::Async
|
||||||
} else {
|
} else {
|
||||||
|
@ -544,7 +544,7 @@ impl ExprCollector<'_> {
|
||||||
};
|
};
|
||||||
let capture_by =
|
let capture_by =
|
||||||
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
|
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
|
||||||
this.is_lowering_generator = prev_is_lowering_generator;
|
this.is_lowering_coroutine = prev_is_lowering_coroutine;
|
||||||
this.current_binding_owner = prev_binding_owner;
|
this.current_binding_owner = prev_binding_owner;
|
||||||
this.current_try_block_label = prev_try_block_label;
|
this.current_try_block_label = prev_try_block_label;
|
||||||
this.body.exprs[result_expr_id] = Expr::Closure {
|
this.body.exprs[result_expr_id] = Expr::Closure {
|
||||||
|
|
|
@ -384,7 +384,7 @@ impl Printer<'_> {
|
||||||
}
|
}
|
||||||
Expr::Closure { args, arg_types, ret_type, body, closure_kind, capture_by } => {
|
Expr::Closure { args, arg_types, ret_type, body, closure_kind, capture_by } => {
|
||||||
match closure_kind {
|
match closure_kind {
|
||||||
ClosureKind::Generator(Movability::Static) => {
|
ClosureKind::Coroutine(Movability::Static) => {
|
||||||
w!(self, "static ");
|
w!(self, "static ");
|
||||||
}
|
}
|
||||||
ClosureKind::Async => {
|
ClosureKind::Async => {
|
||||||
|
|
|
@ -300,7 +300,7 @@ pub struct InlineAsm {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum ClosureKind {
|
pub enum ClosureKind {
|
||||||
Closure,
|
Closure,
|
||||||
Generator(Movability),
|
Coroutine(Movability),
|
||||||
Async,
|
Async,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,8 +334,8 @@ language_item_table! {
|
||||||
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
||||||
|
|
||||||
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
|
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
||||||
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
|
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||||
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
||||||
|
|
||||||
|
|
|
@ -227,21 +227,21 @@ impl TyBuilder<()> {
|
||||||
TyBuilder::new((), params, parent_subst)
|
TyBuilder::new((), params, parent_subst)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `TyBuilder` to build `Substitution` for a generator defined in `parent`.
|
/// Creates a `TyBuilder` to build `Substitution` for a coroutine defined in `parent`.
|
||||||
///
|
///
|
||||||
/// A generator's substitution consists of:
|
/// A coroutine's substitution consists of:
|
||||||
/// - resume type of generator
|
/// - resume type of coroutine
|
||||||
/// - yield type of generator ([`Generator::Yield`](std::ops::Generator::Yield))
|
/// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
|
||||||
/// - return type of generator ([`Generator::Return`](std::ops::Generator::Return))
|
/// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
|
||||||
/// - generic parameters in scope on `parent`
|
/// - generic parameters in scope on `parent`
|
||||||
/// in this order.
|
/// in this order.
|
||||||
///
|
///
|
||||||
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
||||||
/// should only push exactly 3 `GenericArg`s before building.
|
/// should only push exactly 3 `GenericArg`s before building.
|
||||||
pub fn subst_for_generator(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
|
pub fn subst_for_coroutine(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
|
||||||
let parent_subst =
|
let parent_subst =
|
||||||
parent.as_generic_def_id().map(|p| generics(db.upcast(), p).placeholder_subst(db));
|
parent.as_generic_def_id().map(|p| generics(db.upcast(), p).placeholder_subst(db));
|
||||||
// These represent resume type, yield type, and return type of generator.
|
// These represent resume type, yield type, and return type of coroutine.
|
||||||
let params = std::iter::repeat(ParamKind::Type).take(3).collect();
|
let params = std::iter::repeat(ParamKind::Type).take(3).collect();
|
||||||
TyBuilder::new((), params, parent_subst)
|
TyBuilder::new((), params, parent_subst)
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,12 +428,12 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
||||||
&self,
|
&self,
|
||||||
id: chalk_ir::GeneratorId<Interner>,
|
id: chalk_ir::GeneratorId<Interner>,
|
||||||
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
|
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
|
||||||
let (parent, expr) = self.db.lookup_intern_generator(id.into());
|
let (parent, expr) = self.db.lookup_intern_coroutine(id.into());
|
||||||
|
|
||||||
// We fill substitution with unknown type, because we only need to know whether the generic
|
// We fill substitution with unknown type, because we only need to know whether the generic
|
||||||
// params are types or consts to build `Binders` and those being filled up are for
|
// params are types or consts to build `Binders` and those being filled up are for
|
||||||
// `resume_type`, `yield_type`, and `return_type` of the generator in question.
|
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
|
||||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||||
|
|
||||||
let input_output = rust_ir::GeneratorInputOutputDatum {
|
let input_output = rust_ir::GeneratorInputOutputDatum {
|
||||||
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
|
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
|
||||||
|
@ -453,10 +453,10 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
||||||
|
|
||||||
let movability = match self.db.body(parent)[expr] {
|
let movability = match self.db.body(parent)[expr] {
|
||||||
hir_def::hir::Expr::Closure {
|
hir_def::hir::Expr::Closure {
|
||||||
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
|
closure_kind: hir_def::hir::ClosureKind::Coroutine(movability),
|
||||||
..
|
..
|
||||||
} => movability,
|
} => movability,
|
||||||
_ => unreachable!("non generator expression interned as generator"),
|
_ => unreachable!("non coroutine expression interned as coroutine"),
|
||||||
};
|
};
|
||||||
let movability = match movability {
|
let movability = match movability {
|
||||||
Movability::Static => rust_ir::Movability::Static,
|
Movability::Static => rust_ir::Movability::Static,
|
||||||
|
@ -473,9 +473,9 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
||||||
let inner_types =
|
let inner_types =
|
||||||
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
|
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
|
||||||
|
|
||||||
let (parent, _) = self.db.lookup_intern_generator(id.into());
|
let (parent, _) = self.db.lookup_intern_coroutine(id.into());
|
||||||
// See the comment in `generator_datum()` for unknown types.
|
// See the comment in `generator_datum()` for unknown types.
|
||||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||||
let it = subst
|
let it = subst
|
||||||
.iter(Interner)
|
.iter(Interner)
|
||||||
.map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
|
.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> {
|
||||||
LangItem::Fn => WellKnownTrait::Fn,
|
LangItem::Fn => WellKnownTrait::Fn,
|
||||||
LangItem::FnMut => WellKnownTrait::FnMut,
|
LangItem::FnMut => WellKnownTrait::FnMut,
|
||||||
LangItem::FnOnce => WellKnownTrait::FnOnce,
|
LangItem::FnOnce => WellKnownTrait::FnOnce,
|
||||||
LangItem::Generator => WellKnownTrait::Generator,
|
LangItem::Coroutine => WellKnownTrait::Generator,
|
||||||
LangItem::Sized => WellKnownTrait::Sized,
|
LangItem::Sized => WellKnownTrait::Sized,
|
||||||
LangItem::Unpin => WellKnownTrait::Unpin,
|
LangItem::Unpin => WellKnownTrait::Unpin,
|
||||||
LangItem::Unsize => WellKnownTrait::Unsize,
|
LangItem::Unsize => WellKnownTrait::Unsize,
|
||||||
|
@ -639,7 +639,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
|
||||||
WellKnownTrait::Fn => LangItem::Fn,
|
WellKnownTrait::Fn => LangItem::Fn,
|
||||||
WellKnownTrait::FnMut => LangItem::FnMut,
|
WellKnownTrait::FnMut => LangItem::FnMut,
|
||||||
WellKnownTrait::FnOnce => LangItem::FnOnce,
|
WellKnownTrait::FnOnce => LangItem::FnOnce,
|
||||||
WellKnownTrait::Generator => LangItem::Generator,
|
WellKnownTrait::Generator => LangItem::Coroutine,
|
||||||
WellKnownTrait::Sized => LangItem::Sized,
|
WellKnownTrait::Sized => LangItem::Sized,
|
||||||
WellKnownTrait::Tuple => LangItem::Tuple,
|
WellKnownTrait::Tuple => LangItem::Tuple,
|
||||||
WellKnownTrait::Unpin => LangItem::Unpin,
|
WellKnownTrait::Unpin => LangItem::Unpin,
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_generator(&self, id: (DefWithBodyId, ExprId)) -> InternedGeneratorId;
|
fn intern_coroutine(&self, id: (DefWithBodyId, ExprId)) -> InternedCoroutineId;
|
||||||
|
|
||||||
#[salsa::invoke(chalk_db::associated_ty_data_query)]
|
#[salsa::invoke(chalk_db::associated_ty_data_query)]
|
||||||
fn associated_ty_data(
|
fn associated_ty_data(
|
||||||
|
@ -335,8 +335,8 @@ pub struct InternedClosureId(salsa::InternId);
|
||||||
impl_intern_key!(InternedClosureId);
|
impl_intern_key!(InternedClosureId);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct InternedGeneratorId(salsa::InternId);
|
pub struct InternedCoroutineId(salsa::InternId);
|
||||||
impl_intern_key!(InternedGeneratorId);
|
impl_intern_key!(InternedCoroutineId);
|
||||||
|
|
||||||
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
||||||
/// we have different IDs for struct and enum variant constructors.
|
/// we have different IDs for struct and enum variant constructors.
|
||||||
|
|
|
@ -276,7 +276,7 @@ impl DisplayTarget {
|
||||||
pub enum DisplaySourceCodeError {
|
pub enum DisplaySourceCodeError {
|
||||||
PathNotFound,
|
PathNotFound,
|
||||||
UnknownType,
|
UnknownType,
|
||||||
Generator,
|
Coroutine,
|
||||||
OpaqueType,
|
OpaqueType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,8 +659,8 @@ fn render_const_scalar(
|
||||||
}
|
}
|
||||||
TyKind::Never => f.write_str("!"),
|
TyKind::Never => f.write_str("!"),
|
||||||
TyKind::Closure(_, _) => f.write_str("<closure>"),
|
TyKind::Closure(_, _) => f.write_str("<closure>"),
|
||||||
TyKind::Generator(_, _) => f.write_str("<generator>"),
|
TyKind::Generator(_, _) => f.write_str("<coroutine>"),
|
||||||
TyKind::GeneratorWitness(_, _) => f.write_str("<generator-witness>"),
|
TyKind::GeneratorWitness(_, _) => f.write_str("<coroutine-witness>"),
|
||||||
// The below arms are unreachable, since const eval will bail out before here.
|
// The below arms are unreachable, since const eval will bail out before here.
|
||||||
TyKind::Foreign(_) => f.write_str("<extern-type>"),
|
TyKind::Foreign(_) => f.write_str("<extern-type>"),
|
||||||
TyKind::Error
|
TyKind::Error
|
||||||
|
@ -1208,7 +1208,7 @@ impl HirDisplay for Ty {
|
||||||
TyKind::Generator(_, subst) => {
|
TyKind::Generator(_, subst) => {
|
||||||
if f.display_target.is_source_code() {
|
if f.display_target.is_source_code() {
|
||||||
return Err(HirDisplayError::DisplaySourceCodeError(
|
return Err(HirDisplayError::DisplaySourceCodeError(
|
||||||
DisplaySourceCodeError::Generator,
|
DisplaySourceCodeError::Coroutine,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let subst = subst.as_slice(Interner);
|
let subst = subst.as_slice(Interner);
|
||||||
|
@ -1229,10 +1229,10 @@ impl HirDisplay for Ty {
|
||||||
ret_ty.hir_fmt(f)?;
|
ret_ty.hir_fmt(f)?;
|
||||||
} else {
|
} else {
|
||||||
// This *should* be unreachable, but fallback just in case.
|
// This *should* be unreachable, but fallback just in case.
|
||||||
write!(f, "{{generator}}")?;
|
write!(f, "{{coroutine}}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::GeneratorWitness(..) => write!(f, "{{generator witness}}")?,
|
TyKind::GeneratorWitness(..) => write!(f, "{{coroutine witness}}")?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,7 +534,7 @@ pub(crate) struct InferenceContext<'a> {
|
||||||
/// expressions. If `None`, this is in a context where return is
|
/// expressions. If `None`, this is in a context where return is
|
||||||
/// inappropriate, such as a const expression.
|
/// inappropriate, such as a const expression.
|
||||||
return_coercion: Option<CoerceMany>,
|
return_coercion: Option<CoerceMany>,
|
||||||
/// The resume type and the yield type, respectively, of the generator being inferred.
|
/// The resume type and the yield type, respectively, of the coroutine being inferred.
|
||||||
resume_yield_tys: Option<(Ty, Ty)>,
|
resume_yield_tys: Option<(Ty, Ty)>,
|
||||||
diverges: Diverges,
|
diverges: Diverges,
|
||||||
breakables: Vec<BreakableContext>,
|
breakables: Vec<BreakableContext>,
|
||||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
||||||
use super::{Expectation, InferenceContext};
|
use super::{Expectation, InferenceContext};
|
||||||
|
|
||||||
impl InferenceContext<'_> {
|
impl InferenceContext<'_> {
|
||||||
// This function handles both closures and generators.
|
// This function handles both closures and coroutines.
|
||||||
pub(super) fn deduce_closure_type_from_expectations(
|
pub(super) fn deduce_closure_type_from_expectations(
|
||||||
&mut self,
|
&mut self,
|
||||||
closure_expr: ExprId,
|
closure_expr: ExprId,
|
||||||
|
@ -50,7 +50,7 @@ impl InferenceContext<'_> {
|
||||||
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
|
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
|
||||||
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
|
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
|
||||||
|
|
||||||
// Generators are not Fn* so return early.
|
// Coroutines are not Fn* so return early.
|
||||||
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
|
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ impl InferenceContext<'_> {
|
||||||
.intern(Interner);
|
.intern(Interner);
|
||||||
|
|
||||||
let (id, ty, resume_yield_tys) = match closure_kind {
|
let (id, ty, resume_yield_tys) = match closure_kind {
|
||||||
ClosureKind::Generator(_) => {
|
ClosureKind::Coroutine(_) => {
|
||||||
// FIXME: report error when there are more than 1 parameter.
|
// FIXME: report error when there are more than 1 parameter.
|
||||||
let resume_ty = match sig_tys.first() {
|
let resume_ty = match sig_tys.first() {
|
||||||
// When `sig_tys.len() == 1` the first type is the return type, not the
|
// When `sig_tys.len() == 1` the first type is the return type, not the
|
||||||
|
@ -243,16 +243,16 @@ impl InferenceContext<'_> {
|
||||||
};
|
};
|
||||||
let yield_ty = self.table.new_type_var();
|
let yield_ty = self.table.new_type_var();
|
||||||
|
|
||||||
let subst = TyBuilder::subst_for_generator(self.db, self.owner)
|
let subst = TyBuilder::subst_for_coroutine(self.db, self.owner)
|
||||||
.push(resume_ty.clone())
|
.push(resume_ty.clone())
|
||||||
.push(yield_ty.clone())
|
.push(yield_ty.clone())
|
||||||
.push(ret_ty.clone())
|
.push(ret_ty.clone())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let generator_id = self.db.intern_generator((self.owner, tgt_expr)).into();
|
let coroutine_id = self.db.intern_coroutine((self.owner, tgt_expr)).into();
|
||||||
let generator_ty = TyKind::Generator(generator_id, subst).intern(Interner);
|
let coroutine_ty = TyKind::Generator(coroutine_id, subst).intern(Interner);
|
||||||
|
|
||||||
(None, generator_ty, Some((resume_ty, yield_ty)))
|
(None, coroutine_ty, Some((resume_ty, yield_ty)))
|
||||||
}
|
}
|
||||||
ClosureKind::Closure | ClosureKind::Async => {
|
ClosureKind::Closure | ClosureKind::Async => {
|
||||||
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
||||||
|
@ -503,7 +503,7 @@ impl InferenceContext<'_> {
|
||||||
}
|
}
|
||||||
resume_ty
|
resume_ty
|
||||||
} else {
|
} else {
|
||||||
// FIXME: report error (yield expr in non-generator)
|
// FIXME: report error (yield expr in non-coroutine)
|
||||||
self.result.standard_types.unknown.clone()
|
self.result.standard_types.unknown.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,14 +103,14 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedGeneratorId {
|
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedCoroutineId {
|
||||||
fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
|
fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
|
||||||
Self::from_intern_id(id.0)
|
Self::from_intern_id(id.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<crate::db::InternedGeneratorId> for chalk_ir::GeneratorId<Interner> {
|
impl From<crate::db::InternedCoroutineId> for chalk_ir::GeneratorId<Interner> {
|
||||||
fn from(id: crate::db::InternedGeneratorId) -> Self {
|
fn from(id: crate::db::InternedCoroutineId) -> Self {
|
||||||
chalk_ir::GeneratorId(id.as_intern_id())
|
chalk_ir::GeneratorId(id.as_intern_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,7 @@ pub enum AggregateKind {
|
||||||
Adt(VariantId, Substitution),
|
Adt(VariantId, Substitution),
|
||||||
Union(UnionId, FieldId),
|
Union(UnionId, FieldId),
|
||||||
Closure(Ty),
|
Closure(Ty),
|
||||||
//Generator(LocalDefId, SubstsRef, Movability),
|
//Coroutine(LocalDefId, SubstsRef, Movability),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||||
|
@ -453,8 +453,8 @@ pub enum TerminatorKind {
|
||||||
/// `dest = move _0`. It might additionally do other things, like have side-effects in the
|
/// `dest = move _0`. It might additionally do other things, like have side-effects in the
|
||||||
/// aliasing model.
|
/// aliasing model.
|
||||||
///
|
///
|
||||||
/// If the body is a generator body, this has slightly different semantics; it instead causes a
|
/// If the body is a coroutine body, this has slightly different semantics; it instead causes a
|
||||||
/// `GeneratorState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
/// `CoroutineState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
||||||
/// to the return place.
|
/// to the return place.
|
||||||
Return,
|
Return,
|
||||||
|
|
||||||
|
@ -566,14 +566,14 @@ pub enum TerminatorKind {
|
||||||
|
|
||||||
/// Marks a suspend point.
|
/// Marks a suspend point.
|
||||||
///
|
///
|
||||||
/// Like `Return` terminators in generator bodies, this computes `value` and then a
|
/// Like `Return` terminators in coroutine bodies, this computes `value` and then a
|
||||||
/// `GeneratorState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
|
/// `CoroutineState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
|
||||||
/// the return place of the function calling this one, and execution continues in the calling
|
/// the return place of the function calling this one, and execution continues in the calling
|
||||||
/// function. When next invoked with the same first argument, execution of this function
|
/// function. When next invoked with the same first argument, execution of this function
|
||||||
/// continues at the `resume` basic block, with the second argument written to the `resume_arg`
|
/// continues at the `resume` basic block, with the second argument written to the `resume_arg`
|
||||||
/// place. If the generator is dropped before then, the `drop` basic block is invoked.
|
/// place. If the coroutine is dropped before then, the `drop` basic block is invoked.
|
||||||
///
|
///
|
||||||
/// Not permitted in bodies that are not generator bodies, or after generator lowering.
|
/// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering.
|
||||||
///
|
///
|
||||||
/// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`?
|
/// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`?
|
||||||
Yield {
|
Yield {
|
||||||
|
@ -583,21 +583,21 @@ pub enum TerminatorKind {
|
||||||
resume: BasicBlockId,
|
resume: BasicBlockId,
|
||||||
/// The place to store the resume argument in.
|
/// The place to store the resume argument in.
|
||||||
resume_arg: Place,
|
resume_arg: Place,
|
||||||
/// Cleanup to be done if the generator is dropped at this suspend point.
|
/// Cleanup to be done if the coroutine is dropped at this suspend point.
|
||||||
drop: Option<BasicBlockId>,
|
drop: Option<BasicBlockId>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Indicates the end of dropping a generator.
|
/// Indicates the end of dropping a coroutine.
|
||||||
///
|
///
|
||||||
/// Semantically just a `return` (from the generators drop glue). Only permitted in the same situations
|
/// Semantically just a `return` (from the coroutines drop glue). Only permitted in the same situations
|
||||||
/// as `yield`.
|
/// as `yield`.
|
||||||
///
|
///
|
||||||
/// **Needs clarification**: Is that even correct? The generator drop code is always confusing
|
/// **Needs clarification**: Is that even correct? The coroutine drop code is always confusing
|
||||||
/// to me, because it's not even really in the current body.
|
/// to me, because it's not even really in the current body.
|
||||||
///
|
///
|
||||||
/// **Needs clarification**: Are there type system constraints on these terminators? Should
|
/// **Needs clarification**: Are there type system constraints on these terminators? Should
|
||||||
/// there be a "block type" like `cleanup` blocks for them?
|
/// there be a "block type" like `cleanup` blocks for them?
|
||||||
GeneratorDrop,
|
CoroutineDrop,
|
||||||
|
|
||||||
/// A block where control flow only ever takes one real path, but borrowck needs to be more
|
/// A block where control flow only ever takes one real path, but borrowck needs to be more
|
||||||
/// conservative.
|
/// conservative.
|
||||||
|
@ -989,8 +989,8 @@ pub enum Rvalue {
|
||||||
/// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
|
/// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
|
||||||
/// has a destructor.
|
/// has a destructor.
|
||||||
///
|
///
|
||||||
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After
|
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After
|
||||||
/// generator lowering, `Generator` aggregate kinds are disallowed too.
|
/// coroutine lowering, `Coroutine` aggregate kinds are disallowed too.
|
||||||
Aggregate(AggregateKind, Box<[Operand]>),
|
Aggregate(AggregateKind, Box<[Operand]>),
|
||||||
|
|
||||||
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
|
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
|
||||||
|
@ -1140,7 +1140,7 @@ impl MirBody {
|
||||||
| TerminatorKind::FalseUnwind { .. }
|
| TerminatorKind::FalseUnwind { .. }
|
||||||
| TerminatorKind::Goto { .. }
|
| TerminatorKind::Goto { .. }
|
||||||
| TerminatorKind::UnwindResume
|
| TerminatorKind::UnwindResume
|
||||||
| TerminatorKind::GeneratorDrop
|
| TerminatorKind::CoroutineDrop
|
||||||
| TerminatorKind::Abort
|
| TerminatorKind::Abort
|
||||||
| TerminatorKind::Return
|
| TerminatorKind::Return
|
||||||
| TerminatorKind::Unreachable => (),
|
| TerminatorKind::Unreachable => (),
|
||||||
|
|
|
@ -159,7 +159,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
|
||||||
| TerminatorKind::FalseUnwind { .. }
|
| TerminatorKind::FalseUnwind { .. }
|
||||||
| TerminatorKind::Goto { .. }
|
| TerminatorKind::Goto { .. }
|
||||||
| TerminatorKind::UnwindResume
|
| TerminatorKind::UnwindResume
|
||||||
| TerminatorKind::GeneratorDrop
|
| TerminatorKind::CoroutineDrop
|
||||||
| TerminatorKind::Abort
|
| TerminatorKind::Abort
|
||||||
| TerminatorKind::Return
|
| TerminatorKind::Return
|
||||||
| TerminatorKind::Unreachable
|
| TerminatorKind::Unreachable
|
||||||
|
@ -314,7 +314,7 @@ fn ever_initialized_map(
|
||||||
TerminatorKind::DropAndReplace { .. }
|
TerminatorKind::DropAndReplace { .. }
|
||||||
| TerminatorKind::Assert { .. }
|
| TerminatorKind::Assert { .. }
|
||||||
| TerminatorKind::Yield { .. }
|
| TerminatorKind::Yield { .. }
|
||||||
| TerminatorKind::GeneratorDrop
|
| TerminatorKind::CoroutineDrop
|
||||||
| TerminatorKind::FalseEdge { .. }
|
| TerminatorKind::FalseEdge { .. }
|
||||||
| TerminatorKind::FalseUnwind { .. } => {
|
| TerminatorKind::FalseUnwind { .. } => {
|
||||||
never!("We don't emit these MIR terminators yet");
|
never!("We don't emit these MIR terminators yet");
|
||||||
|
@ -439,7 +439,7 @@ fn mutability_of_locals(
|
||||||
| TerminatorKind::Unreachable
|
| TerminatorKind::Unreachable
|
||||||
| TerminatorKind::FalseEdge { .. }
|
| TerminatorKind::FalseEdge { .. }
|
||||||
| TerminatorKind::FalseUnwind { .. }
|
| TerminatorKind::FalseUnwind { .. }
|
||||||
| TerminatorKind::GeneratorDrop
|
| TerminatorKind::CoroutineDrop
|
||||||
| TerminatorKind::Drop { .. }
|
| TerminatorKind::Drop { .. }
|
||||||
| TerminatorKind::DropAndReplace { .. }
|
| TerminatorKind::DropAndReplace { .. }
|
||||||
| TerminatorKind::Assert { .. }
|
| TerminatorKind::Assert { .. }
|
||||||
|
|
|
@ -275,7 +275,7 @@ impl Filler<'_> {
|
||||||
| TerminatorKind::DropAndReplace { .. }
|
| TerminatorKind::DropAndReplace { .. }
|
||||||
| TerminatorKind::Assert { .. }
|
| TerminatorKind::Assert { .. }
|
||||||
| TerminatorKind::Yield { .. }
|
| TerminatorKind::Yield { .. }
|
||||||
| TerminatorKind::GeneratorDrop
|
| TerminatorKind::CoroutineDrop
|
||||||
| TerminatorKind::FalseEdge { .. }
|
| TerminatorKind::FalseEdge { .. }
|
||||||
| TerminatorKind::FalseUnwind { .. } => (),
|
| TerminatorKind::FalseUnwind { .. } => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,7 +328,7 @@ fn foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generator_yield_return_coerce() {
|
fn coroutine_yield_return_coerce() {
|
||||||
check_no_mismatches(
|
check_no_mismatches(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
|
|
|
@ -1949,11 +1949,11 @@ fn closure_return_inferred() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generator_types_inferred() {
|
fn coroutine_types_inferred() {
|
||||||
check_infer(
|
check_infer(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: generator, deref
|
//- minicore: coroutine, deref
|
||||||
use core::ops::{Generator, GeneratorState};
|
use core::ops::{Coroutine, CoroutineState};
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
|
|
||||||
fn f(v: i64) {}
|
fn f(v: i64) {}
|
||||||
|
@ -1966,8 +1966,8 @@ fn test() {
|
||||||
};
|
};
|
||||||
|
|
||||||
match Pin::new(&mut g).resume(0usize) {
|
match Pin::new(&mut g).resume(0usize) {
|
||||||
GeneratorState::Yielded(y) => { f(y); }
|
CoroutineState::Yielded(y) => { f(y); }
|
||||||
GeneratorState::Complete(r) => {}
|
CoroutineState::Complete(r) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -1992,17 +1992,17 @@ fn test() {
|
||||||
225..360 'match ... }': ()
|
225..360 'match ... }': ()
|
||||||
231..239 'Pin::new': fn new<&mut |usize| yields i64 -> &str>(&mut |usize| yields i64 -> &str) -> Pin<&mut |usize| yields i64 -> &str>
|
231..239 'Pin::new': fn new<&mut |usize| yields i64 -> &str>(&mut |usize| yields i64 -> &str) -> Pin<&mut |usize| yields i64 -> &str>
|
||||||
231..247 'Pin::n...mut g)': Pin<&mut |usize| yields i64 -> &str>
|
231..247 'Pin::n...mut g)': Pin<&mut |usize| yields i64 -> &str>
|
||||||
231..262 'Pin::n...usize)': GeneratorState<i64, &str>
|
231..262 'Pin::n...usize)': CoroutineState<i64, &str>
|
||||||
240..246 '&mut g': &mut |usize| yields i64 -> &str
|
240..246 '&mut g': &mut |usize| yields i64 -> &str
|
||||||
245..246 'g': |usize| yields i64 -> &str
|
245..246 'g': |usize| yields i64 -> &str
|
||||||
255..261 '0usize': usize
|
255..261 '0usize': usize
|
||||||
273..299 'Genera...ded(y)': GeneratorState<i64, &str>
|
273..299 'Corout...ded(y)': CoroutineState<i64, &str>
|
||||||
297..298 'y': i64
|
297..298 'y': i64
|
||||||
303..312 '{ f(y); }': ()
|
303..312 '{ f(y); }': ()
|
||||||
305..306 'f': fn f(i64)
|
305..306 'f': fn f(i64)
|
||||||
305..309 'f(y)': ()
|
305..309 'f(y)': ()
|
||||||
307..308 'y': i64
|
307..308 'y': i64
|
||||||
321..348 'Genera...ete(r)': GeneratorState<i64, &str>
|
321..348 'Corout...ete(r)': CoroutineState<i64, &str>
|
||||||
346..347 'r': &str
|
346..347 'r': &str
|
||||||
352..354 '{}': ()
|
352..354 '{}': ()
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -2010,11 +2010,11 @@ fn test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generator_resume_yield_return_unit() {
|
fn coroutine_resume_yield_return_unit() {
|
||||||
check_no_mismatches(
|
check_no_mismatches(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: generator, deref
|
//- minicore: coroutine, deref
|
||||||
use core::ops::{Generator, GeneratorState};
|
use core::ops::{Coroutine, CoroutineState};
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
fn test() {
|
fn test() {
|
||||||
let mut g = || {
|
let mut g = || {
|
||||||
|
@ -2022,8 +2022,8 @@ fn test() {
|
||||||
};
|
};
|
||||||
|
|
||||||
match Pin::new(&mut g).resume(()) {
|
match Pin::new(&mut g).resume(()) {
|
||||||
GeneratorState::Yielded(()) => {}
|
CoroutineState::Yielded(()) => {}
|
||||||
GeneratorState::Complete(()) => {}
|
CoroutineState::Complete(()) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
|
@ -285,21 +285,21 @@ impl Variant {
|
||||||
check_assist(
|
check_assist(
|
||||||
generate_enum_is_method,
|
generate_enum_is_method,
|
||||||
r#"
|
r#"
|
||||||
enum GeneratorState {
|
enum CoroutineState {
|
||||||
Yielded,
|
Yielded,
|
||||||
Complete$0,
|
Complete$0,
|
||||||
Major,
|
Major,
|
||||||
}"#,
|
}"#,
|
||||||
r#"enum GeneratorState {
|
r#"enum CoroutineState {
|
||||||
Yielded,
|
Yielded,
|
||||||
Complete,
|
Complete,
|
||||||
Major,
|
Major,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GeneratorState {
|
impl CoroutineState {
|
||||||
/// Returns `true` if the generator state is [`Complete`].
|
/// Returns `true` if the coroutine state is [`Complete`].
|
||||||
///
|
///
|
||||||
/// [`Complete`]: GeneratorState::Complete
|
/// [`Complete`]: CoroutineState::Complete
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn is_complete(&self) -> bool {
|
fn is_complete(&self) -> bool {
|
||||||
matches!(self, Self::Complete)
|
matches!(self, Self::Complete)
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl RootDatabase {
|
||||||
hir::db::InternImplTraitIdQuery
|
hir::db::InternImplTraitIdQuery
|
||||||
hir::db::InternTypeOrConstParamIdQuery
|
hir::db::InternTypeOrConstParamIdQuery
|
||||||
hir::db::InternClosureQuery
|
hir::db::InternClosureQuery
|
||||||
hir::db::InternGeneratorQuery
|
hir::db::InternCoroutineQuery
|
||||||
hir::db::AssociatedTyDataQuery
|
hir::db::AssociatedTyDataQuery
|
||||||
hir::db::TraitDatumQuery
|
hir::db::TraitDatumQuery
|
||||||
hir::db::StructDatumQuery
|
hir::db::StructDatumQuery
|
||||||
|
|
|
@ -283,7 +283,7 @@ impl RootDatabase {
|
||||||
// hir_db::InternImplTraitIdQuery
|
// hir_db::InternImplTraitIdQuery
|
||||||
// hir_db::InternTypeOrConstParamIdQuery
|
// hir_db::InternTypeOrConstParamIdQuery
|
||||||
// hir_db::InternClosureQuery
|
// hir_db::InternClosureQuery
|
||||||
// hir_db::InternGeneratorQuery
|
// hir_db::InternCoroutineQuery
|
||||||
hir_db::AssociatedTyDataQuery
|
hir_db::AssociatedTyDataQuery
|
||||||
hir_db::TraitDatumQuery
|
hir_db::TraitDatumQuery
|
||||||
hir_db::StructDatumQuery
|
hir_db::StructDatumQuery
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
//! fn:
|
//! fn:
|
||||||
//! from: sized
|
//! from: sized
|
||||||
//! future: pin
|
//! future: pin
|
||||||
//! generator: pin
|
//! coroutine: pin
|
||||||
//! hash:
|
//! hash:
|
||||||
//! include:
|
//! include:
|
||||||
//! index: sized
|
//! index: sized
|
||||||
|
@ -798,26 +798,26 @@ pub mod ops {
|
||||||
// endregion:builtin_impls
|
// endregion:builtin_impls
|
||||||
// endregion:add
|
// endregion:add
|
||||||
|
|
||||||
// region:generator
|
// region:coroutine
|
||||||
mod generator {
|
mod coroutine {
|
||||||
use crate::pin::Pin;
|
use crate::pin::Pin;
|
||||||
|
|
||||||
#[lang = "generator"]
|
#[lang = "coroutine"]
|
||||||
pub trait Generator<R = ()> {
|
pub trait Coroutine<R = ()> {
|
||||||
type Yield;
|
type Yield;
|
||||||
#[lang = "generator_return"]
|
#[lang = "coroutine_return"]
|
||||||
type Return;
|
type Return;
|
||||||
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
|
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "generator_state"]
|
#[lang = "coroutine_state"]
|
||||||
pub enum GeneratorState<Y, R> {
|
pub enum CoroutineState<Y, R> {
|
||||||
Yielded(Y),
|
Yielded(Y),
|
||||||
Complete(R),
|
Complete(R),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub use self::generator::{Generator, GeneratorState};
|
pub use self::coroutine::{Coroutine, CoroutineState};
|
||||||
// endregion:generator
|
// endregion:coroutine
|
||||||
}
|
}
|
||||||
|
|
||||||
// region:eq
|
// region:eq
|
||||||
|
|
Loading…
Reference in a new issue