Skip to content

Commit 3a9ec21

Browse files
Movability doesn't need to be a query anymore
1 parent a4b2953 commit 3a9ec21

File tree

17 files changed

+33
-49
lines changed

17 files changed

+33
-49
lines changed

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn do_mir_borrowck<'tcx>(
275275
if let Some(local) = body.local_decls.raw.get(1)
276276
// Get the interior types and args which typeck computed
277277
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
278-
&& tcx.movability(def_id) == hir::Movability::Movable
278+
&& tcx.coroutine_kind(def_id).unwrap().movability() == hir::Movability::Movable
279279
{
280280
true
281281
} else {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ provide! { tcx, def_id, other, cdata,
240240
mir_const_qualif => { table }
241241
rendered_const => { table }
242242
asyncness => { table_direct }
243-
movability => { table_direct }
244243
fn_arg_names => { table }
245244
coroutine_kind => { table_direct }
246245
trait_def => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14321432
if def_kind == DefKind::Closure
14331433
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
14341434
{
1435-
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind));
1436-
self.tables.movability.set(def_id.index, Some(self.tcx.movability(def_id)));
1435+
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
14371436
}
14381437
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
14391438
self.encode_info_for_adt(local_id);

compiler/rustc_metadata/src/rmeta/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ define_tables! {
447447
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
448448
rendered_const: Table<DefIndex, LazyValue<String>>,
449449
asyncness: Table<DefIndex, ty::Asyncness>,
450-
movability: Table<DefIndex, hir::Movability>,
451450
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
452451
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
453452
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
13081308
self.push("coroutine");
13091309
self.push(&format!("+ def_id: {def_id:?}"));
13101310
self.push(&format!("+ args: {args:#?}"));
1311-
self.push(&format!("+ movability: {:?}", self.tcx.movability(def_id)));
1311+
self.push(&format!("+ kind: {:?}", self.tcx.coroutine_kind(def_id)));
13121312
}
13131313

13141314
AggregateKind::Adt(_, _, _, Some(user_ty), _) => {

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,6 @@ rustc_queries! {
721721
desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
722722
}
723723

724-
query movability(key: DefId) -> hir::Movability {
725-
desc { |tcx| "checking if coroutine is movable: `{}`", tcx.def_path_str(key) }
726-
separate_provide_extern
727-
}
728-
729724
/// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
730725
/// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
731726
/// not have the feature gate active).

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
790790
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
791791

792792
if should_print_movability {
793-
match self.tcx().movability(did) {
793+
match coroutine_kind.movability() {
794794
hir::Movability::Movable => {}
795795
hir::Movability::Static => p!("static "),
796796
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,11 @@ impl<'tcx> Cx<'tcx> {
552552
let closure_ty = self.typeck_results().expr_ty(expr);
553553
let (def_id, args, movability) = match *closure_ty.kind() {
554554
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
555-
ty::Coroutine(def_id, args) => {
556-
(def_id, UpvarArgs::Coroutine(args), Some(tcx.movability(def_id)))
557-
}
555+
ty::Coroutine(def_id, args) => (
556+
def_id,
557+
UpvarArgs::Coroutine(args),
558+
Some(tcx.coroutine_kind(def_id).unwrap().movability()),
559+
),
558560
_ => {
559561
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
560562
}

compiler/rustc_mir_transform/src/coroutine.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,9 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
15651565
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
15661566

15671567
let movable = match *coroutine_ty.kind() {
1568-
ty::Coroutine(def_id, _) => tcx.movability(def_id) == hir::Movability::Movable,
1568+
ty::Coroutine(def_id, _) => {
1569+
tcx.coroutine_kind(def_id).unwrap().movability() == hir::Movability::Movable
1570+
}
15691571
ty::Error(_) => return None,
15701572
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
15711573
};
@@ -1597,12 +1599,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
15971599

15981600
// The first argument is the coroutine type passed by value
15991601
let coroutine_ty = body.local_decls.raw[1].ty;
1602+
let coroutine_kind = body.coroutine_kind().unwrap();
16001603

16011604
// Get the discriminant type and args which typeck computed
16021605
let (discr_ty, movable) = match *coroutine_ty.kind() {
1603-
ty::Coroutine(def_id, args) => {
1606+
ty::Coroutine(_, args) => {
16041607
let args = args.as_coroutine();
1605-
(args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable)
1608+
(args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable)
16061609
}
16071610
_ => {
16081611
tcx.dcx().span_delayed_bug(
@@ -1613,19 +1616,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16131616
}
16141617
};
16151618

1616-
let is_async_kind = matches!(
1617-
body.coroutine_kind(),
1618-
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
1619-
);
1620-
let is_async_gen_kind = matches!(
1621-
body.coroutine_kind(),
1622-
Some(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _))
1623-
);
1624-
let is_gen_kind = matches!(
1625-
body.coroutine_kind(),
1626-
Some(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _))
1627-
);
1628-
let new_ret_ty = match body.coroutine_kind().unwrap() {
1619+
let is_async_kind =
1620+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _));
1621+
let is_async_gen_kind =
1622+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _));
1623+
let is_gen_kind =
1624+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _));
1625+
let new_ret_ty = match coroutine_kind {
16291626
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
16301627
// Compute Poll<return_ty>
16311628
let poll_did = tcx.require_lang_item(LangItem::Poll, None);

compiler/rustc_mir_transform/src/shim.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
395395
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
396396
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
397397
ty::Coroutine(coroutine_def_id, args) => {
398-
assert_eq!(tcx.movability(coroutine_def_id), hir::Movability::Movable);
398+
assert_eq!(
399+
tcx.coroutine_kind(coroutine_def_id).unwrap().movability(),
400+
hir::Movability::Movable
401+
);
399402
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
400403
}
401404
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
535535
stable_mir::mir::AggregateKind::Coroutine(
536536
tables.coroutine_def(*def_id),
537537
generic_arg.stable(tables),
538-
tables.tcx.movability(*def_id).stable(tables),
538+
tables.tcx.coroutine_kind(*def_id).unwrap().movability().stable(tables),
539539
)
540540
}
541541
}

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
389389
ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
390390
tables.coroutine_def(*def_id),
391391
generic_args.stable(tables),
392-
tables.tcx.movability(*def_id).stable(tables),
392+
tables.tcx.coroutine_kind(*def_id).unwrap().movability().stable(tables),
393393
)),
394394
ty::Never => TyKind::RigidTy(RigidTy::Never),
395395
ty::Tuple(fields) => {

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
193193

194194
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
195195

196-
ty::Coroutine(def_id, args) => match ecx.tcx().movability(def_id) {
196+
ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_kind(def_id).unwrap().movability()
197+
{
197198
Movability::Static => Err(NoSolution),
198199
Movability::Movable => {
199200
if ecx.tcx().features().coroutine_clone {

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
930930
ty::Coroutine(def_id, _)
931931
if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() =>
932932
{
933-
match self.tcx().movability(def_id) {
933+
match self.tcx().coroutine_kind(def_id).unwrap().movability() {
934934
Movability::Static => Some(Err(NoSolution)),
935935
Movability::Movable => {
936936
Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
567567
ty::Coroutine(coroutine_def_id, _)
568568
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
569569
{
570-
match self.tcx().movability(coroutine_def_id) {
570+
match self.tcx().coroutine_kind(coroutine_def_id).unwrap().movability() {
571571
hir::Movability::Static => {
572572
// Immovable coroutines are never `Unpin`, so
573573
// suppress the normal auto-impl candidate for it.

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21852185
}
21862186

21872187
ty::Coroutine(coroutine_def_id, args) => {
2188-
match self.tcx().movability(coroutine_def_id) {
2188+
match self.tcx().coroutine_kind(coroutine_def_id).unwrap().movability() {
21892189
hir::Movability::Static => None,
21902190
hir::Movability::Movable => {
21912191
if self.tcx().features().coroutine_clone {

compiler/rustc_ty_utils/src/ty.rs

-11
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,6 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Asyncness {
307307
})
308308
}
309309

310-
fn movability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Movability {
311-
let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) =
312-
tcx.hir_node_by_def_id(def_id)
313-
else {
314-
bug!("expected query `movability` only called on coroutine def id");
315-
};
316-
317-
closure.movability.expect("expected coroutine to have movability")
318-
}
319-
320310
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
321311
let def = tcx.adt_def(def_id);
322312
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
364354
pub(crate) fn provide(providers: &mut Providers) {
365355
*providers = Providers {
366356
asyncness,
367-
movability,
368357
adt_sized_constraint,
369358
param_env,
370359
param_env_reveal_all_normalized,

0 commit comments

Comments
 (0)