Movability doesn't need to be a query anymore

This commit is contained in:
Michael Goulet 2023-12-26 22:43:11 +00:00
parent 15ccf2e7bd
commit e24da8ea19
21 changed files with 29 additions and 56 deletions

View File

@ -275,7 +275,7 @@ fn do_mir_borrowck<'tcx>(
if let Some(local) = body.local_decls.raw.get(1)
// Get the interior types and args which typeck computed
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
&& tcx.movability(def_id) == hir::Movability::Movable
&& tcx.coroutine_movability(def_id) == hir::Movability::Movable
{
true
} else {

View File

@ -240,7 +240,6 @@ provide! { tcx, def_id, other, cdata,
mir_const_qualif => { table }
rendered_const => { table }
asyncness => { table_direct }
movability => { table_direct }
fn_arg_names => { table }
coroutine_kind => { table_direct }
trait_def => { table }

View File

@ -1444,8 +1444,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if def_kind == DefKind::Closure
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
{
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind));
self.tables.movability.set(def_id.index, Some(self.tcx.movability(def_id)));
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
}
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
self.encode_info_for_adt(local_id);

View File

@ -448,7 +448,6 @@ define_tables! {
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
rendered_const: Table<DefIndex, LazyValue<String>>,
asyncness: Table<DefIndex, ty::Asyncness>,
movability: Table<DefIndex, hir::Movability>,
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,

View File

@ -213,13 +213,6 @@ fixed_size_enum! {
}
}
fixed_size_enum! {
ty::Movability {
( Movable )
( Static )
}
}
fixed_size_enum! {
ty::AssocItemContainer {
( TraitContainer )

View File

@ -1308,7 +1308,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
self.push("coroutine");
self.push(&format!("+ def_id: {def_id:?}"));
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), _) => {

View File

@ -254,7 +254,6 @@ trivial! {
rustc_hir::IsAsync,
rustc_hir::ItemLocalId,
rustc_hir::LangItem,
rustc_hir::Movability,
rustc_hir::OwnerId,
rustc_hir::Upvar,
rustc_index::bit_set::FiniteBitSet<u32>,

View File

@ -721,11 +721,6 @@ rustc_queries! {
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
/// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
/// not have the feature gate active).

View File

@ -847,6 +847,12 @@ impl<'tcx> TyCtxt<'tcx> {
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.
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
matches!(

View File

@ -86,7 +86,6 @@ trivially_parameterized_over_tcx! {
rustc_hir::CoroutineKind,
rustc_hir::IsAsync,
rustc_hir::LangItem,
rustc_hir::Movability,
rustc_hir::def::DefKind,
rustc_hir::def::DocLinkResMap,
rustc_hir::def_id::DefId,

View File

@ -790,7 +790,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
if should_print_movability {
match self.tcx().movability(did) {
match coroutine_kind.movability() {
hir::Movability::Movable => {}
hir::Movability::Static => p!("static "),
}

View File

@ -553,7 +553,7 @@ impl<'tcx> Cx<'tcx> {
let (def_id, args, movability) = match *closure_ty.kind() {
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
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);

View File

@ -1565,7 +1565,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
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,
_ => 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
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
let (discr_ty, movable) = match *coroutine_ty.kind() {
ty::Coroutine(def_id, args) => {
ty::Coroutine(_, args) => {
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(
@ -1613,19 +1614,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
}
};
let is_async_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
);
let is_async_gen_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _))
);
let is_gen_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _))
);
let new_ret_ty = match body.coroutine_kind().unwrap() {
let is_async_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _));
let is_async_gen_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _));
let is_gen_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _));
let new_ret_ty = match coroutine_kind {
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
// Compute Poll<return_ty>
let poll_did = tcx.require_lang_item(LangItem::Poll, None);

View File

@ -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::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
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())
}
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),

View File

@ -535,7 +535,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
stable_mir::mir::AggregateKind::Coroutine(
tables.coroutine_def(*def_id),
generic_arg.stable(tables),
tables.tcx.movability(*def_id).stable(tables),
tables.tcx.coroutine_movability(*def_id).stable(tables),
)
}
}

View File

@ -389,7 +389,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
tables.coroutine_def(*def_id),
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::Tuple(fields) => {

View File

@ -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::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::Movable => {
if ecx.tcx().features().coroutine_clone {

View File

@ -930,7 +930,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
ty::Coroutine(def_id, _)
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::Movable => {
Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))

View File

@ -567,7 +567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Coroutine(coroutine_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 => {
// Immovable coroutines are never `Unpin`, so
// suppress the normal auto-impl candidate for it.

View File

@ -2185,7 +2185,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
}
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::Movable => {
if self.tcx().features().coroutine_clone {

View File

@ -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> {
let def = tcx.adt_def(def_id);
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) {
*providers = Providers {
asyncness,
movability,
adt_sized_constraint,
param_env,
param_env_reveal_all_normalized,