Skip to content

Commit 016694c

Browse files
Movability doesn't need to be a query anymore
1 parent dfe369d commit 016694c

File tree

18 files changed

+27
-47
lines changed

18 files changed

+27
-47
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_movability(def_id) == 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/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@ impl<'tcx> TyCtxt<'tcx> {
847847
self.coroutine_kind(def_id).is_some()
848848
}
849849

850+
pub fn coroutine_movability(self, def_id: DefId) -> hir::Movability {
851+
self.coroutine_kind(def_id).expect("expected a coroutine").movability()
852+
}
853+
850854
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct.
851855
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
852856
matches!(

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl<'tcx> Cx<'tcx> {
553553
let (def_id, args, movability) = match *closure_ty.kind() {
554554
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
555555
ty::Coroutine(def_id, args) => {
556-
(def_id, UpvarArgs::Coroutine(args), Some(tcx.movability(def_id)))
556+
(def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id)))
557557
}
558558
_ => {
559559
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ 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, _) => tcx.coroutine_movability(def_id) == hir::Movability::Movable,
15691569
ty::Error(_) => return None,
15701570
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
15711571
};
@@ -1597,12 +1597,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
15971597

15981598
// The first argument is the coroutine type passed by value
15991599
let coroutine_ty = body.local_decls.raw[1].ty;
1600+
let coroutine_kind = body.coroutine_kind().unwrap();
16001601

16011602
// Get the discriminant type and args which typeck computed
16021603
let (discr_ty, movable) = match *coroutine_ty.kind() {
1603-
ty::Coroutine(def_id, args) => {
1604+
ty::Coroutine(_, args) => {
16041605
let args = args.as_coroutine();
1605-
(args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable)
1606+
(args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable)
16061607
}
16071608
_ => {
16081609
tcx.dcx().span_delayed_bug(
@@ -1613,19 +1614,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16131614
}
16141615
};
16151616

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() {
1617+
let is_async_kind =
1618+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _));
1619+
let is_async_gen_kind =
1620+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _));
1621+
let is_gen_kind =
1622+
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _));
1623+
let new_ret_ty = match coroutine_kind {
16291624
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
16301625
// Compute Poll<return_ty>
16311626
let poll_did = tcx.require_lang_item(LangItem::Poll, None);

0 commit comments

Comments
 (0)