Movability doesn't need to be a query anymore
This commit is contained in:
parent
15ccf2e7bd
commit
e24da8ea19
@ -275,7 +275,7 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
if let Some(local) = body.local_decls.raw.get(1)
|
if let Some(local) = body.local_decls.raw.get(1)
|
||||||
// Get the interior types and args which typeck computed
|
// Get the interior types and args which typeck computed
|
||||||
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
|
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
|
||||||
&& tcx.movability(def_id) == hir::Movability::Movable
|
&& tcx.coroutine_movability(def_id) == hir::Movability::Movable
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -240,7 +240,6 @@ provide! { tcx, def_id, other, cdata,
|
|||||||
mir_const_qualif => { table }
|
mir_const_qualif => { table }
|
||||||
rendered_const => { table }
|
rendered_const => { table }
|
||||||
asyncness => { table_direct }
|
asyncness => { table_direct }
|
||||||
movability => { table_direct }
|
|
||||||
fn_arg_names => { table }
|
fn_arg_names => { table }
|
||||||
coroutine_kind => { table_direct }
|
coroutine_kind => { table_direct }
|
||||||
trait_def => { table }
|
trait_def => { table }
|
||||||
|
@ -1444,8 +1444,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
if def_kind == DefKind::Closure
|
if def_kind == DefKind::Closure
|
||||||
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
|
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
|
||||||
{
|
{
|
||||||
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind));
|
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
|
||||||
self.tables.movability.set(def_id.index, Some(self.tcx.movability(def_id)));
|
|
||||||
}
|
}
|
||||||
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
|
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
|
||||||
self.encode_info_for_adt(local_id);
|
self.encode_info_for_adt(local_id);
|
||||||
|
@ -448,7 +448,6 @@ define_tables! {
|
|||||||
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
|
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
|
||||||
rendered_const: Table<DefIndex, LazyValue<String>>,
|
rendered_const: Table<DefIndex, LazyValue<String>>,
|
||||||
asyncness: Table<DefIndex, ty::Asyncness>,
|
asyncness: Table<DefIndex, ty::Asyncness>,
|
||||||
movability: Table<DefIndex, hir::Movability>,
|
|
||||||
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
|
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
|
||||||
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
|
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
|
||||||
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
||||||
|
@ -213,13 +213,6 @@ fixed_size_enum! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed_size_enum! {
|
|
||||||
ty::Movability {
|
|
||||||
( Movable )
|
|
||||||
( Static )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixed_size_enum! {
|
fixed_size_enum! {
|
||||||
ty::AssocItemContainer {
|
ty::AssocItemContainer {
|
||||||
( TraitContainer )
|
( TraitContainer )
|
||||||
|
@ -1308,7 +1308,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
|
|||||||
self.push("coroutine");
|
self.push("coroutine");
|
||||||
self.push(&format!("+ def_id: {def_id:?}"));
|
self.push(&format!("+ def_id: {def_id:?}"));
|
||||||
self.push(&format!("+ args: {args:#?}"));
|
self.push(&format!("+ args: {args:#?}"));
|
||||||
self.push(&format!("+ movability: {:?}", self.tcx.movability(def_id)));
|
self.push(&format!("+ kind: {:?}", self.tcx.coroutine_kind(def_id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AggregateKind::Adt(_, _, _, Some(user_ty), _) => {
|
AggregateKind::Adt(_, _, _, Some(user_ty), _) => {
|
||||||
|
@ -254,7 +254,6 @@ trivial! {
|
|||||||
rustc_hir::IsAsync,
|
rustc_hir::IsAsync,
|
||||||
rustc_hir::ItemLocalId,
|
rustc_hir::ItemLocalId,
|
||||||
rustc_hir::LangItem,
|
rustc_hir::LangItem,
|
||||||
rustc_hir::Movability,
|
|
||||||
rustc_hir::OwnerId,
|
rustc_hir::OwnerId,
|
||||||
rustc_hir::Upvar,
|
rustc_hir::Upvar,
|
||||||
rustc_index::bit_set::FiniteBitSet<u32>,
|
rustc_index::bit_set::FiniteBitSet<u32>,
|
||||||
|
@ -721,11 +721,6 @@ rustc_queries! {
|
|||||||
desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
query movability(key: DefId) -> hir::Movability {
|
|
||||||
desc { |tcx| "checking if coroutine is movable: `{}`", tcx.def_path_str(key) }
|
|
||||||
separate_provide_extern
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
|
/// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
|
||||||
/// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
|
/// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
|
||||||
/// not have the feature gate active).
|
/// not have the feature gate active).
|
||||||
|
@ -847,6 +847,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
self.coroutine_kind(def_id).is_some()
|
self.coroutine_kind(def_id).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the movability of the coroutine of `def_id`, or panics
|
||||||
|
/// if given a `def_id` that is not a coroutine.
|
||||||
|
pub fn coroutine_movability(self, def_id: DefId) -> hir::Movability {
|
||||||
|
self.coroutine_kind(def_id).expect("expected a coroutine").movability()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct.
|
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct.
|
||||||
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
|
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
|
@ -86,7 +86,6 @@ trivially_parameterized_over_tcx! {
|
|||||||
rustc_hir::CoroutineKind,
|
rustc_hir::CoroutineKind,
|
||||||
rustc_hir::IsAsync,
|
rustc_hir::IsAsync,
|
||||||
rustc_hir::LangItem,
|
rustc_hir::LangItem,
|
||||||
rustc_hir::Movability,
|
|
||||||
rustc_hir::def::DefKind,
|
rustc_hir::def::DefKind,
|
||||||
rustc_hir::def::DocLinkResMap,
|
rustc_hir::def::DocLinkResMap,
|
||||||
rustc_hir::def_id::DefId,
|
rustc_hir::def_id::DefId,
|
||||||
|
@ -790,7 +790,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
|||||||
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
|
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
|
||||||
|
|
||||||
if should_print_movability {
|
if should_print_movability {
|
||||||
match self.tcx().movability(did) {
|
match coroutine_kind.movability() {
|
||||||
hir::Movability::Movable => {}
|
hir::Movability::Movable => {}
|
||||||
hir::Movability::Static => p!("static "),
|
hir::Movability::Static => p!("static "),
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ impl<'tcx> Cx<'tcx> {
|
|||||||
let (def_id, args, movability) = match *closure_ty.kind() {
|
let (def_id, args, movability) = match *closure_ty.kind() {
|
||||||
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
|
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
|
||||||
ty::Coroutine(def_id, args) => {
|
ty::Coroutine(def_id, args) => {
|
||||||
(def_id, UpvarArgs::Coroutine(args), Some(tcx.movability(def_id)))
|
(def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id)))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
|
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
|
||||||
|
@ -1565,7 +1565,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
|
|||||||
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
|
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
|
||||||
|
|
||||||
let movable = match *coroutine_ty.kind() {
|
let movable = match *coroutine_ty.kind() {
|
||||||
ty::Coroutine(def_id, _) => tcx.movability(def_id) == hir::Movability::Movable,
|
ty::Coroutine(def_id, _) => tcx.coroutine_movability(def_id) == hir::Movability::Movable,
|
||||||
ty::Error(_) => return None,
|
ty::Error(_) => return None,
|
||||||
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
|
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
|
||||||
};
|
};
|
||||||
@ -1597,12 +1597,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||||||
|
|
||||||
// The first argument is the coroutine type passed by value
|
// The first argument is the coroutine type passed by value
|
||||||
let coroutine_ty = body.local_decls.raw[1].ty;
|
let coroutine_ty = body.local_decls.raw[1].ty;
|
||||||
|
let coroutine_kind = body.coroutine_kind().unwrap();
|
||||||
|
|
||||||
// Get the discriminant type and args which typeck computed
|
// Get the discriminant type and args which typeck computed
|
||||||
let (discr_ty, movable) = match *coroutine_ty.kind() {
|
let (discr_ty, movable) = match *coroutine_ty.kind() {
|
||||||
ty::Coroutine(def_id, args) => {
|
ty::Coroutine(_, args) => {
|
||||||
let args = args.as_coroutine();
|
let args = args.as_coroutine();
|
||||||
(args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable)
|
(args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
tcx.dcx().span_delayed_bug(
|
tcx.dcx().span_delayed_bug(
|
||||||
@ -1613,19 +1614,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_async_kind = matches!(
|
let is_async_kind =
|
||||||
body.coroutine_kind(),
|
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _));
|
||||||
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
|
let is_async_gen_kind =
|
||||||
);
|
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _));
|
||||||
let is_async_gen_kind = matches!(
|
let is_gen_kind =
|
||||||
body.coroutine_kind(),
|
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _));
|
||||||
Some(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _))
|
let new_ret_ty = match coroutine_kind {
|
||||||
);
|
|
||||||
let is_gen_kind = matches!(
|
|
||||||
body.coroutine_kind(),
|
|
||||||
Some(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _))
|
|
||||||
);
|
|
||||||
let new_ret_ty = match body.coroutine_kind().unwrap() {
|
|
||||||
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
|
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
|
||||||
// Compute Poll<return_ty>
|
// Compute Poll<return_ty>
|
||||||
let poll_did = tcx.require_lang_item(LangItem::Poll, None);
|
let poll_did = tcx.require_lang_item(LangItem::Poll, None);
|
||||||
|
@ -395,7 +395,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
|
|||||||
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
|
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
|
||||||
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
|
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
|
||||||
ty::Coroutine(coroutine_def_id, args) => {
|
ty::Coroutine(coroutine_def_id, args) => {
|
||||||
assert_eq!(tcx.movability(coroutine_def_id), hir::Movability::Movable);
|
assert_eq!(tcx.coroutine_movability(*coroutine_def_id), hir::Movability::Movable);
|
||||||
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
|
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
|
||||||
}
|
}
|
||||||
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),
|
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),
|
||||||
|
@ -535,7 +535,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
|
|||||||
stable_mir::mir::AggregateKind::Coroutine(
|
stable_mir::mir::AggregateKind::Coroutine(
|
||||||
tables.coroutine_def(*def_id),
|
tables.coroutine_def(*def_id),
|
||||||
generic_arg.stable(tables),
|
generic_arg.stable(tables),
|
||||||
tables.tcx.movability(*def_id).stable(tables),
|
tables.tcx.coroutine_movability(*def_id).stable(tables),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
|
|||||||
ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
|
ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
|
||||||
tables.coroutine_def(*def_id),
|
tables.coroutine_def(*def_id),
|
||||||
generic_args.stable(tables),
|
generic_args.stable(tables),
|
||||||
tables.tcx.movability(*def_id).stable(tables),
|
tables.tcx.coroutine_movability(*def_id).stable(tables),
|
||||||
)),
|
)),
|
||||||
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
||||||
ty::Tuple(fields) => {
|
ty::Tuple(fields) => {
|
||||||
|
@ -193,7 +193,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
|
|||||||
|
|
||||||
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
|
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
|
||||||
|
|
||||||
ty::Coroutine(def_id, args) => match ecx.tcx().movability(def_id) {
|
ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_movability(def_id) {
|
||||||
Movability::Static => Err(NoSolution),
|
Movability::Static => Err(NoSolution),
|
||||||
Movability::Movable => {
|
Movability::Movable => {
|
||||||
if ecx.tcx().features().coroutine_clone {
|
if ecx.tcx().features().coroutine_clone {
|
||||||
|
@ -930,7 +930,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||||||
ty::Coroutine(def_id, _)
|
ty::Coroutine(def_id, _)
|
||||||
if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() =>
|
if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() =>
|
||||||
{
|
{
|
||||||
match self.tcx().movability(def_id) {
|
match self.tcx().coroutine_movability(def_id) {
|
||||||
Movability::Static => Some(Err(NoSolution)),
|
Movability::Static => Some(Err(NoSolution)),
|
||||||
Movability::Movable => {
|
Movability::Movable => {
|
||||||
Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))
|
Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))
|
||||||
|
@ -567,7 +567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
ty::Coroutine(coroutine_def_id, _)
|
ty::Coroutine(coroutine_def_id, _)
|
||||||
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
|
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
|
||||||
{
|
{
|
||||||
match self.tcx().movability(coroutine_def_id) {
|
match self.tcx().coroutine_movability(coroutine_def_id) {
|
||||||
hir::Movability::Static => {
|
hir::Movability::Static => {
|
||||||
// Immovable coroutines are never `Unpin`, so
|
// Immovable coroutines are never `Unpin`, so
|
||||||
// suppress the normal auto-impl candidate for it.
|
// suppress the normal auto-impl candidate for it.
|
||||||
|
@ -2185,7 +2185,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ty::Coroutine(coroutine_def_id, args) => {
|
ty::Coroutine(coroutine_def_id, args) => {
|
||||||
match self.tcx().movability(coroutine_def_id) {
|
match self.tcx().coroutine_movability(coroutine_def_id) {
|
||||||
hir::Movability::Static => None,
|
hir::Movability::Static => None,
|
||||||
hir::Movability::Movable => {
|
hir::Movability::Movable => {
|
||||||
if self.tcx().features().coroutine_clone {
|
if self.tcx().features().coroutine_clone {
|
||||||
|
@ -307,16 +307,6 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Asyncness {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn movability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Movability {
|
|
||||||
let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) =
|
|
||||||
tcx.hir_node_by_def_id(def_id)
|
|
||||||
else {
|
|
||||||
bug!("expected query `movability` only called on coroutine def id");
|
|
||||||
};
|
|
||||||
|
|
||||||
closure.movability.expect("expected coroutine to have movability")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
|
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
|
||||||
let def = tcx.adt_def(def_id);
|
let def = tcx.adt_def(def_id);
|
||||||
let num_params = tcx.generics_of(def_id).count();
|
let num_params = tcx.generics_of(def_id).count();
|
||||||
@ -364,7 +354,6 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
|
|||||||
pub(crate) fn provide(providers: &mut Providers) {
|
pub(crate) fn provide(providers: &mut Providers) {
|
||||||
*providers = Providers {
|
*providers = Providers {
|
||||||
asyncness,
|
asyncness,
|
||||||
movability,
|
|
||||||
adt_sized_constraint,
|
adt_sized_constraint,
|
||||||
param_env,
|
param_env,
|
||||||
param_env_reveal_all_normalized,
|
param_env_reveal_all_normalized,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user