mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
Auto merge of #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.
This commit is contained in:
commit
4de8954c45
29 changed files with 970 additions and 831 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -160,9 +160,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "chalk-derive"
|
||||
version = "0.95.0"
|
||||
version = "0.96.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "329427f28cd2bddaacd47c4dcd3d7082d315c61fb164394c690fe98c1b6ee9d3"
|
||||
checksum = "5676cea088c32290fe65c82895be9d06dd21e0fa49bb97ca840529e9417ab71a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -172,9 +172,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "chalk-ir"
|
||||
version = "0.95.0"
|
||||
version = "0.96.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1e1659238bd598d0f7dbc5034cf1ff46010a3d6827704c9ed443c8359cb484"
|
||||
checksum = "ff550c2cdd63ff74394214dce03d06386928a641c0f08837535f04af573a966d"
|
||||
dependencies = [
|
||||
"bitflags 2.4.1",
|
||||
"chalk-derive",
|
||||
|
@ -183,9 +183,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "chalk-recursive"
|
||||
version = "0.95.0"
|
||||
version = "0.96.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3e0bff0ba1bed11407384fcec0353aeb6888901e63cb47d04505ec47adad847"
|
||||
checksum = "4c4559e5c9b200240453b07d893f9c3c74413b53b0d33cbe272c68b0b77aa1c3"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
|
@ -196,9 +196,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "chalk-solve"
|
||||
version = "0.95.0"
|
||||
version = "0.96.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9c46d501cf83732a91056c0c846ae7a16d6b3c67a6a6bb5e9cc0a2e91563b6"
|
||||
checksum = "0882e68ce9eb5a0a2413806538494d19df6ee520ab17d1faf489e952f32e98b8"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
|
|
|
@ -37,7 +37,7 @@ pub struct Body {
|
|||
pub pats: Arena<Pat>,
|
||||
pub bindings: Arena<Binding>,
|
||||
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.
|
||||
pub binding_owners: FxHashMap<BindingId, ExprId>,
|
||||
/// The patterns for the function's parameters. While the parameter types are
|
||||
|
|
|
@ -81,7 +81,7 @@ pub(super) fn lower(
|
|||
expander,
|
||||
current_try_block_label: None,
|
||||
is_lowering_assignee_expr: false,
|
||||
is_lowering_generator: false,
|
||||
is_lowering_coroutine: false,
|
||||
label_ribs: Vec::new(),
|
||||
current_binding_owner: None,
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ struct ExprCollector<'a> {
|
|||
source_map: BodySourceMap,
|
||||
|
||||
is_lowering_assignee_expr: bool,
|
||||
is_lowering_generator: bool,
|
||||
is_lowering_coroutine: bool,
|
||||
|
||||
current_try_block_label: Option<LabelId>,
|
||||
// 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)
|
||||
}
|
||||
ast::Expr::YieldExpr(e) => {
|
||||
self.is_lowering_generator = true;
|
||||
self.is_lowering_coroutine = true;
|
||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
|
||||
}
|
||||
|
@ -525,18 +525,18 @@ impl ExprCollector<'_> {
|
|||
.and_then(|r| r.ty())
|
||||
.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 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() {
|
||||
Movability::Static
|
||||
} else {
|
||||
Movability::Movable
|
||||
};
|
||||
ClosureKind::Generator(movability)
|
||||
ClosureKind::Coroutine(movability)
|
||||
} else if e.async_token().is_some() {
|
||||
ClosureKind::Async
|
||||
} else {
|
||||
|
@ -544,7 +544,7 @@ impl ExprCollector<'_> {
|
|||
};
|
||||
let capture_by =
|
||||
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_try_block_label = prev_try_block_label;
|
||||
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 } => {
|
||||
match closure_kind {
|
||||
ClosureKind::Generator(Movability::Static) => {
|
||||
ClosureKind::Coroutine(Movability::Static) => {
|
||||
w!(self, "static ");
|
||||
}
|
||||
ClosureKind::Async => {
|
||||
|
|
|
@ -300,7 +300,7 @@ pub struct InlineAsm {
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ClosureKind {
|
||||
Closure,
|
||||
Generator(Movability),
|
||||
Coroutine(Movability),
|
||||
Async,
|
||||
}
|
||||
|
||||
|
|
|
@ -334,8 +334,8 @@ language_item_table! {
|
|||
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
||||
|
||||
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
|
||||
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
||||
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
||||
|
||||
|
|
|
@ -23,10 +23,10 @@ oorandom = "11.1.3"
|
|||
tracing.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
scoped-tls = "1.0.0"
|
||||
chalk-solve = { version = "0.95.0", default-features = false }
|
||||
chalk-ir = "0.95.0"
|
||||
chalk-recursive = { version = "0.95.0", default-features = false }
|
||||
chalk-derive = "0.95.0"
|
||||
chalk-solve = { version = "0.96.0", default-features = false }
|
||||
chalk-ir = "0.96.0"
|
||||
chalk-recursive = { version = "0.96.0", default-features = false }
|
||||
chalk-derive = "0.96.0"
|
||||
la-arena.workspace = true
|
||||
once_cell = "1.17.0"
|
||||
triomphe.workspace = true
|
||||
|
|
|
@ -227,21 +227,21 @@ impl TyBuilder<()> {
|
|||
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:
|
||||
/// - resume type of generator
|
||||
/// - yield type of generator ([`Generator::Yield`](std::ops::Generator::Yield))
|
||||
/// - return type of generator ([`Generator::Return`](std::ops::Generator::Return))
|
||||
/// A coroutine's substitution consists of:
|
||||
/// - resume type of coroutine
|
||||
/// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
|
||||
/// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
|
||||
/// - generic parameters in scope on `parent`
|
||||
/// in this order.
|
||||
///
|
||||
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
||||
/// 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 =
|
||||
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();
|
||||
TyBuilder::new((), params, parent_subst)
|
||||
}
|
||||
|
|
|
@ -424,18 +424,18 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId<Interner>) -> String {
|
||||
format!("fn_{}", fn_def_id.0)
|
||||
}
|
||||
fn generator_datum(
|
||||
fn coroutine_datum(
|
||||
&self,
|
||||
id: chalk_ir::GeneratorId<Interner>,
|
||||
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
|
||||
let (parent, expr) = self.db.lookup_intern_generator(id.into());
|
||||
id: chalk_ir::CoroutineId<Interner>,
|
||||
) -> Arc<chalk_solve::rust_ir::CoroutineDatum<Interner>> {
|
||||
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
|
||||
// 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.
|
||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
||||
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||
|
||||
let input_output = rust_ir::GeneratorInputOutputDatum {
|
||||
let input_output = rust_ir::CoroutineInputOutputDatum {
|
||||
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
|
||||
.intern(Interner),
|
||||
yield_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 1))
|
||||
|
@ -453,35 +453,35 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
|
||||
let movability = match self.db.body(parent)[expr] {
|
||||
hir_def::hir::Expr::Closure {
|
||||
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
|
||||
closure_kind: hir_def::hir::ClosureKind::Coroutine(movability),
|
||||
..
|
||||
} => movability,
|
||||
_ => unreachable!("non generator expression interned as generator"),
|
||||
_ => unreachable!("non coroutine expression interned as coroutine"),
|
||||
};
|
||||
let movability = match movability {
|
||||
Movability::Static => rust_ir::Movability::Static,
|
||||
Movability::Movable => rust_ir::Movability::Movable,
|
||||
};
|
||||
|
||||
Arc::new(rust_ir::GeneratorDatum { movability, input_output })
|
||||
Arc::new(rust_ir::CoroutineDatum { movability, input_output })
|
||||
}
|
||||
fn generator_witness_datum(
|
||||
fn coroutine_witness_datum(
|
||||
&self,
|
||||
id: chalk_ir::GeneratorId<Interner>,
|
||||
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<Interner>> {
|
||||
id: chalk_ir::CoroutineId<Interner>,
|
||||
) -> Arc<chalk_solve::rust_ir::CoroutineWitnessDatum<Interner>> {
|
||||
// FIXME: calculate inner types
|
||||
let inner_types =
|
||||
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
|
||||
rust_ir::CoroutineWitnessExistential { types: wrap_empty_binders(vec![]) };
|
||||
|
||||
let (parent, _) = self.db.lookup_intern_generator(id.into());
|
||||
// See the comment in `generator_datum()` for unknown types.
|
||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
||||
let (parent, _) = self.db.lookup_intern_coroutine(id.into());
|
||||
// See the comment in `coroutine_datum()` for unknown types.
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||
let it = subst
|
||||
.iter(Interner)
|
||||
.map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
|
||||
let inner_types = crate::make_type_and_const_binders(it, inner_types);
|
||||
|
||||
Arc::new(rust_ir::GeneratorWitnessDatum { inner_types })
|
||||
Arc::new(rust_ir::CoroutineWitnessDatum { inner_types })
|
||||
}
|
||||
|
||||
fn unification_database(&self) -> &dyn chalk_ir::UnificationDatabase<Interner> {
|
||||
|
@ -617,7 +617,7 @@ fn well_known_trait_from_lang_item(item: LangItem) -> Option<WellKnownTrait> {
|
|||
LangItem::Fn => WellKnownTrait::Fn,
|
||||
LangItem::FnMut => WellKnownTrait::FnMut,
|
||||
LangItem::FnOnce => WellKnownTrait::FnOnce,
|
||||
LangItem::Generator => WellKnownTrait::Generator,
|
||||
LangItem::Coroutine => WellKnownTrait::Coroutine,
|
||||
LangItem::Sized => WellKnownTrait::Sized,
|
||||
LangItem::Unpin => WellKnownTrait::Unpin,
|
||||
LangItem::Unsize => WellKnownTrait::Unsize,
|
||||
|
@ -639,7 +639,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
|
|||
WellKnownTrait::Fn => LangItem::Fn,
|
||||
WellKnownTrait::FnMut => LangItem::FnMut,
|
||||
WellKnownTrait::FnOnce => LangItem::FnOnce,
|
||||
WellKnownTrait::Generator => LangItem::Generator,
|
||||
WellKnownTrait::Coroutine => LangItem::Coroutine,
|
||||
WellKnownTrait::Sized => LangItem::Sized,
|
||||
WellKnownTrait::Tuple => LangItem::Tuple,
|
||||
WellKnownTrait::Unpin => LangItem::Unpin,
|
||||
|
|
|
@ -199,7 +199,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||
#[salsa::interned]
|
||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||
#[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)]
|
||||
fn associated_ty_data(
|
||||
|
@ -335,8 +335,8 @@ pub struct InternedClosureId(salsa::InternId);
|
|||
impl_intern_key!(InternedClosureId);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct InternedGeneratorId(salsa::InternId);
|
||||
impl_intern_key!(InternedGeneratorId);
|
||||
pub struct InternedCoroutineId(salsa::InternId);
|
||||
impl_intern_key!(InternedCoroutineId);
|
||||
|
||||
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
||||
/// we have different IDs for struct and enum variant constructors.
|
||||
|
|
|
@ -276,7 +276,7 @@ impl DisplayTarget {
|
|||
pub enum DisplaySourceCodeError {
|
||||
PathNotFound,
|
||||
UnknownType,
|
||||
Generator,
|
||||
Coroutine,
|
||||
OpaqueType,
|
||||
}
|
||||
|
||||
|
@ -659,8 +659,8 @@ fn render_const_scalar(
|
|||
}
|
||||
TyKind::Never => f.write_str("!"),
|
||||
TyKind::Closure(_, _) => f.write_str("<closure>"),
|
||||
TyKind::Generator(_, _) => f.write_str("<generator>"),
|
||||
TyKind::GeneratorWitness(_, _) => f.write_str("<generator-witness>"),
|
||||
TyKind::Coroutine(_, _) => f.write_str("<coroutine>"),
|
||||
TyKind::CoroutineWitness(_, _) => f.write_str("<coroutine-witness>"),
|
||||
// The below arms are unreachable, since const eval will bail out before here.
|
||||
TyKind::Foreign(_) => f.write_str("<extern-type>"),
|
||||
TyKind::Error
|
||||
|
@ -1205,10 +1205,10 @@ impl HirDisplay for Ty {
|
|||
write!(f, "{{unknown}}")?;
|
||||
}
|
||||
TyKind::InferenceVar(..) => write!(f, "_")?,
|
||||
TyKind::Generator(_, subst) => {
|
||||
TyKind::Coroutine(_, subst) => {
|
||||
if f.display_target.is_source_code() {
|
||||
return Err(HirDisplayError::DisplaySourceCodeError(
|
||||
DisplaySourceCodeError::Generator,
|
||||
DisplaySourceCodeError::Coroutine,
|
||||
));
|
||||
}
|
||||
let subst = subst.as_slice(Interner);
|
||||
|
@ -1229,10 +1229,10 @@ impl HirDisplay for Ty {
|
|||
ret_ty.hir_fmt(f)?;
|
||||
} else {
|
||||
// This *should* be unreachable, but fallback just in case.
|
||||
write!(f, "{{generator}}")?;
|
||||
write!(f, "{{coroutine}}")?;
|
||||
}
|
||||
}
|
||||
TyKind::GeneratorWitness(..) => write!(f, "{{generator witness}}")?,
|
||||
TyKind::CoroutineWitness(..) => write!(f, "{{coroutine witness}}")?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -534,7 +534,7 @@ pub(crate) struct InferenceContext<'a> {
|
|||
/// expressions. If `None`, this is in a context where return is
|
||||
/// inappropriate, such as a const expression.
|
||||
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)>,
|
||||
diverges: Diverges,
|
||||
breakables: Vec<BreakableContext>,
|
||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
|||
use super::{Expectation, 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(
|
||||
&mut self,
|
||||
closure_expr: ExprId,
|
||||
|
@ -50,8 +50,8 @@ impl InferenceContext<'_> {
|
|||
// 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);
|
||||
|
||||
// Generators are not Fn* so return early.
|
||||
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
|
||||
// Coroutines are not Fn* so return early.
|
||||
if matches!(closure_ty.kind(Interner), TyKind::Coroutine(..)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ impl InferenceContext<'_> {
|
|||
.intern(Interner);
|
||||
|
||||
let (id, ty, resume_yield_tys) = match closure_kind {
|
||||
ClosureKind::Generator(_) => {
|
||||
ClosureKind::Coroutine(_) => {
|
||||
// FIXME: report error when there are more than 1 parameter.
|
||||
let resume_ty = match sig_tys.first() {
|
||||
// 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 subst = TyBuilder::subst_for_generator(self.db, self.owner)
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, self.owner)
|
||||
.push(resume_ty.clone())
|
||||
.push(yield_ty.clone())
|
||||
.push(ret_ty.clone())
|
||||
.build();
|
||||
|
||||
let generator_id = self.db.intern_generator((self.owner, tgt_expr)).into();
|
||||
let generator_ty = TyKind::Generator(generator_id, subst).intern(Interner);
|
||||
let coroutine_id = self.db.intern_coroutine((self.owner, tgt_expr)).into();
|
||||
let coroutine_ty = TyKind::Coroutine(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 => {
|
||||
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
||||
|
@ -503,7 +503,7 @@ impl InferenceContext<'_> {
|
|||
}
|
||||
resume_ty
|
||||
} else {
|
||||
// FIXME: report error (yield expr in non-generator)
|
||||
// FIXME: report error (yield expr in non-coroutine)
|
||||
self.result.standard_types.unknown.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ pub fn layout_of_ty_query(
|
|||
cx.univariant(dl, &fields, &ReprOptions::default(), StructKind::AlwaysSized)
|
||||
.ok_or(LayoutError::Unknown)?
|
||||
}
|
||||
TyKind::Generator(_, _) | TyKind::GeneratorWitness(_, _) => {
|
||||
TyKind::Coroutine(_, _) | TyKind::CoroutineWitness(_, _) => {
|
||||
return Err(LayoutError::NotImplemented)
|
||||
}
|
||||
TyKind::Error => return Err(LayoutError::HasErrorType),
|
||||
|
|
|
@ -103,15 +103,15 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedGeneratorId {
|
||||
fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
|
||||
impl From<chalk_ir::CoroutineId<Interner>> for crate::db::InternedCoroutineId {
|
||||
fn from(id: chalk_ir::CoroutineId<Interner>) -> Self {
|
||||
Self::from_intern_id(id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::db::InternedGeneratorId> for chalk_ir::GeneratorId<Interner> {
|
||||
fn from(id: crate::db::InternedGeneratorId) -> Self {
|
||||
chalk_ir::GeneratorId(id.as_intern_id())
|
||||
impl From<crate::db::InternedCoroutineId> for chalk_ir::CoroutineId<Interner> {
|
||||
fn from(id: crate::db::InternedCoroutineId) -> Self {
|
||||
chalk_ir::CoroutineId(id.as_intern_id())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,8 @@ impl TyFingerprint {
|
|||
| TyKind::OpaqueType(_, _)
|
||||
| TyKind::FnDef(_, _)
|
||||
| TyKind::Closure(_, _)
|
||||
| TyKind::Generator(..)
|
||||
| TyKind::GeneratorWitness(..) => TyFingerprint::Unnameable,
|
||||
| TyKind::Coroutine(..)
|
||||
| TyKind::CoroutineWitness(..) => TyFingerprint::Unnameable,
|
||||
TyKind::Function(fn_ptr) => {
|
||||
TyFingerprint::Function(fn_ptr.substitution.0.len(Interner) as u32)
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ pub enum AggregateKind {
|
|||
Adt(VariantId, Substitution),
|
||||
Union(UnionId, FieldId),
|
||||
Closure(Ty),
|
||||
//Generator(LocalDefId, SubstsRef, Movability),
|
||||
//Coroutine(LocalDefId, SubstsRef, Movability),
|
||||
}
|
||||
|
||||
#[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
|
||||
/// aliasing model.
|
||||
///
|
||||
/// If the body is a generator body, this has slightly different semantics; it instead causes a
|
||||
/// `GeneratorState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
||||
/// If the body is a coroutine body, this has slightly different semantics; it instead causes a
|
||||
/// `CoroutineState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
||||
/// to the return place.
|
||||
Return,
|
||||
|
||||
|
@ -566,14 +566,14 @@ pub enum TerminatorKind {
|
|||
|
||||
/// Marks a suspend point.
|
||||
///
|
||||
/// Like `Return` terminators in generator bodies, this computes `value` and then a
|
||||
/// `GeneratorState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
|
||||
/// Like `Return` terminators in coroutine bodies, this computes `value` and then a
|
||||
/// `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
|
||||
/// 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`
|
||||
/// 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`?
|
||||
Yield {
|
||||
|
@ -583,21 +583,21 @@ pub enum TerminatorKind {
|
|||
resume: BasicBlockId,
|
||||
/// The place to store the resume argument in.
|
||||
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>,
|
||||
},
|
||||
|
||||
/// 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`.
|
||||
///
|
||||
/// **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.
|
||||
///
|
||||
/// **Needs clarification**: Are there type system constraints on these terminators? Should
|
||||
/// 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
|
||||
/// conservative.
|
||||
|
@ -989,8 +989,8 @@ pub enum Rvalue {
|
|||
/// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
|
||||
/// has a destructor.
|
||||
///
|
||||
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After
|
||||
/// generator lowering, `Generator` aggregate kinds are disallowed too.
|
||||
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After
|
||||
/// coroutine lowering, `Coroutine` aggregate kinds are disallowed too.
|
||||
Aggregate(AggregateKind, Box<[Operand]>),
|
||||
|
||||
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
|
||||
|
@ -1140,7 +1140,7 @@ impl MirBody {
|
|||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::Goto { .. }
|
||||
| TerminatorKind::UnwindResume
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Abort
|
||||
| TerminatorKind::Return
|
||||
| TerminatorKind::Unreachable => (),
|
||||
|
|
|
@ -159,7 +159,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
|
|||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::Goto { .. }
|
||||
| TerminatorKind::UnwindResume
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Abort
|
||||
| TerminatorKind::Return
|
||||
| TerminatorKind::Unreachable
|
||||
|
@ -314,7 +314,7 @@ fn ever_initialized_map(
|
|||
TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
| TerminatorKind::Yield { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. } => {
|
||||
never!("We don't emit these MIR terminators yet");
|
||||
|
@ -439,7 +439,7 @@ fn mutability_of_locals(
|
|||
| TerminatorKind::Unreachable
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Drop { .. }
|
||||
| TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
|
|
|
@ -2147,8 +2147,8 @@ impl Evaluator<'_> {
|
|||
| TyKind::Str
|
||||
| TyKind::Never
|
||||
| TyKind::Closure(_, _)
|
||||
| TyKind::Generator(_, _)
|
||||
| TyKind::GeneratorWitness(_, _)
|
||||
| TyKind::Coroutine(_, _)
|
||||
| TyKind::CoroutineWitness(_, _)
|
||||
| TyKind::Foreign(_)
|
||||
| TyKind::Error
|
||||
| TyKind::Placeholder(_)
|
||||
|
@ -2635,8 +2635,8 @@ impl Evaluator<'_> {
|
|||
| TyKind::Str
|
||||
| TyKind::Never
|
||||
| TyKind::Closure(_, _)
|
||||
| TyKind::Generator(_, _)
|
||||
| TyKind::GeneratorWitness(_, _)
|
||||
| TyKind::Coroutine(_, _)
|
||||
| TyKind::CoroutineWitness(_, _)
|
||||
| TyKind::Foreign(_)
|
||||
| TyKind::Error
|
||||
| TyKind::Placeholder(_)
|
||||
|
|
|
@ -275,7 +275,7 @@ impl Filler<'_> {
|
|||
| TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
| TerminatorKind::Yield { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. } => (),
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ fn foo() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_yield_return_coerce() {
|
||||
fn coroutine_yield_return_coerce() {
|
||||
check_no_mismatches(
|
||||
r#"
|
||||
fn test() {
|
||||
|
|
|
@ -1949,11 +1949,11 @@ fn closure_return_inferred() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_types_inferred() {
|
||||
fn coroutine_types_inferred() {
|
||||
check_infer(
|
||||
r#"
|
||||
//- minicore: generator, deref
|
||||
use core::ops::{Generator, GeneratorState};
|
||||
//- minicore: coroutine, deref
|
||||
use core::ops::{Coroutine, CoroutineState};
|
||||
use core::pin::Pin;
|
||||
|
||||
fn f(v: i64) {}
|
||||
|
@ -1966,8 +1966,8 @@ fn test() {
|
|||
};
|
||||
|
||||
match Pin::new(&mut g).resume(0usize) {
|
||||
GeneratorState::Yielded(y) => { f(y); }
|
||||
GeneratorState::Complete(r) => {}
|
||||
CoroutineState::Yielded(y) => { f(y); }
|
||||
CoroutineState::Complete(r) => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
@ -1992,17 +1992,17 @@ fn test() {
|
|||
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..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
|
||||
245..246 'g': |usize| yields i64 -> &str
|
||||
255..261 '0usize': usize
|
||||
273..299 'Genera...ded(y)': GeneratorState<i64, &str>
|
||||
273..299 'Corout...ded(y)': CoroutineState<i64, &str>
|
||||
297..298 'y': i64
|
||||
303..312 '{ f(y); }': ()
|
||||
305..306 'f': fn f(i64)
|
||||
305..309 'f(y)': ()
|
||||
307..308 'y': i64
|
||||
321..348 'Genera...ete(r)': GeneratorState<i64, &str>
|
||||
321..348 'Corout...ete(r)': CoroutineState<i64, &str>
|
||||
346..347 'r': &str
|
||||
352..354 '{}': ()
|
||||
"#]],
|
||||
|
@ -2010,11 +2010,11 @@ fn test() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_resume_yield_return_unit() {
|
||||
fn coroutine_resume_yield_return_unit() {
|
||||
check_no_mismatches(
|
||||
r#"
|
||||
//- minicore: generator, deref
|
||||
use core::ops::{Generator, GeneratorState};
|
||||
//- minicore: coroutine, deref
|
||||
use core::ops::{Coroutine, CoroutineState};
|
||||
use core::pin::Pin;
|
||||
fn test() {
|
||||
let mut g = || {
|
||||
|
@ -2022,8 +2022,8 @@ fn test() {
|
|||
};
|
||||
|
||||
match Pin::new(&mut g).resume(()) {
|
||||
GeneratorState::Yielded(()) => {}
|
||||
GeneratorState::Complete(()) => {}
|
||||
CoroutineState::Yielded(()) => {}
|
||||
CoroutineState::Complete(()) => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
|
|
@ -4103,8 +4103,8 @@ impl Type {
|
|||
| TyKind::Function(_)
|
||||
| TyKind::Alias(_)
|
||||
| TyKind::Foreign(_)
|
||||
| TyKind::Generator(..)
|
||||
| TyKind::GeneratorWitness(..) => false,
|
||||
| TyKind::Coroutine(..)
|
||||
| TyKind::CoroutineWitness(..) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,21 +285,21 @@ impl Variant {
|
|||
check_assist(
|
||||
generate_enum_is_method,
|
||||
r#"
|
||||
enum GeneratorState {
|
||||
enum CoroutineState {
|
||||
Yielded,
|
||||
Complete$0,
|
||||
Major,
|
||||
}"#,
|
||||
r#"enum GeneratorState {
|
||||
r#"enum CoroutineState {
|
||||
Yielded,
|
||||
Complete,
|
||||
Major,
|
||||
}
|
||||
|
||||
impl GeneratorState {
|
||||
/// Returns `true` if the generator state is [`Complete`].
|
||||
impl CoroutineState {
|
||||
/// Returns `true` if the coroutine state is [`Complete`].
|
||||
///
|
||||
/// [`Complete`]: GeneratorState::Complete
|
||||
/// [`Complete`]: CoroutineState::Complete
|
||||
#[must_use]
|
||||
fn is_complete(&self) -> bool {
|
||||
matches!(self, Self::Complete)
|
||||
|
|
|
@ -120,7 +120,7 @@ impl RootDatabase {
|
|||
hir::db::InternImplTraitIdQuery
|
||||
hir::db::InternTypeOrConstParamIdQuery
|
||||
hir::db::InternClosureQuery
|
||||
hir::db::InternGeneratorQuery
|
||||
hir::db::InternCoroutineQuery
|
||||
hir::db::AssociatedTyDataQuery
|
||||
hir::db::TraitDatumQuery
|
||||
hir::db::StructDatumQuery
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -283,7 +283,7 @@ impl RootDatabase {
|
|||
// hir_db::InternImplTraitIdQuery
|
||||
// hir_db::InternTypeOrConstParamIdQuery
|
||||
// hir_db::InternClosureQuery
|
||||
// hir_db::InternGeneratorQuery
|
||||
// hir_db::InternCoroutineQuery
|
||||
hir_db::AssociatedTyDataQuery
|
||||
hir_db::TraitDatumQuery
|
||||
hir_db::StructDatumQuery
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
//! fn:
|
||||
//! from: sized
|
||||
//! future: pin
|
||||
//! generator: pin
|
||||
//! coroutine: pin
|
||||
//! hash:
|
||||
//! include:
|
||||
//! index: sized
|
||||
|
@ -798,26 +798,26 @@ pub mod ops {
|
|||
// endregion:builtin_impls
|
||||
// endregion:add
|
||||
|
||||
// region:generator
|
||||
mod generator {
|
||||
// region:coroutine
|
||||
mod coroutine {
|
||||
use crate::pin::Pin;
|
||||
|
||||
#[lang = "generator"]
|
||||
pub trait Generator<R = ()> {
|
||||
#[lang = "coroutine"]
|
||||
pub trait Coroutine<R = ()> {
|
||||
type Yield;
|
||||
#[lang = "generator_return"]
|
||||
#[lang = "coroutine_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"]
|
||||
pub enum GeneratorState<Y, R> {
|
||||
#[lang = "coroutine_state"]
|
||||
pub enum CoroutineState<Y, R> {
|
||||
Yielded(Y),
|
||||
Complete(R),
|
||||
}
|
||||
}
|
||||
pub use self::generator::{Generator, GeneratorState};
|
||||
// endregion:generator
|
||||
pub use self::coroutine::{Coroutine, CoroutineState};
|
||||
// endregion:coroutine
|
||||
}
|
||||
|
||||
// region:eq
|
||||
|
|
Loading…
Reference in a new issue