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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 13 additions & 16 deletions
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

Lines changed: 4 additions & 1 deletion
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),

0 commit comments

Comments
 (0)