Skip to content

Commit 8003602

Browse files
committed
Eliminate with_tables helper
1 parent 078eb11 commit 8003602

File tree

2 files changed

+18
-78
lines changed

2 files changed

+18
-78
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,14 @@ use std::ops::{ControlFlow, Index};
88

99
use crate::rustc_internal;
1010
use crate::stable_mir::CompilerError;
11-
use crate::{
12-
rustc_smir::Tables,
13-
stable_mir::{self, with},
14-
};
11+
use crate::{rustc_smir::Tables, stable_mir};
1512
use rustc_driver::{Callbacks, Compilation, RunCompiler};
1613
use rustc_interface::{interface, Queries};
1714
use rustc_middle::mir::interpret::AllocId;
1815
use rustc_middle::ty::TyCtxt;
1916
pub use rustc_span::def_id::{CrateNum, DefId};
2017
use rustc_span::Span;
2118

22-
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
23-
let mut ret = None;
24-
with(|tables| tables.rustc_tables(&mut |t| ret = Some(f(t))));
25-
ret.unwrap()
26-
}
27-
28-
pub fn item_def_id(item: &stable_mir::CrateItem) -> DefId {
29-
with_tables(|t| t[item.0])
30-
}
31-
32-
pub fn crate_item(did: DefId) -> stable_mir::CrateItem {
33-
with_tables(|t| t.crate_item(did))
34-
}
35-
36-
pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
37-
with_tables(|t| t.adt_def(did))
38-
}
39-
40-
pub fn foreign_def(did: DefId) -> stable_mir::ty::ForeignDef {
41-
with_tables(|t| t.foreign_def(did))
42-
}
43-
44-
pub fn fn_def(did: DefId) -> stable_mir::ty::FnDef {
45-
with_tables(|t| t.fn_def(did))
46-
}
47-
48-
pub fn closure_def(did: DefId) -> stable_mir::ty::ClosureDef {
49-
with_tables(|t| t.closure_def(did))
50-
}
51-
52-
pub fn generator_def(did: DefId) -> stable_mir::ty::GeneratorDef {
53-
with_tables(|t| t.generator_def(did))
54-
}
55-
56-
pub fn alias_def(did: DefId) -> stable_mir::ty::AliasDef {
57-
with_tables(|t| t.alias_def(did))
58-
}
59-
60-
pub fn param_def(did: DefId) -> stable_mir::ty::ParamDef {
61-
with_tables(|t| t.param_def(did))
62-
}
63-
64-
pub fn br_named_def(did: DefId) -> stable_mir::ty::BrNamedDef {
65-
with_tables(|t| t.br_named_def(did))
66-
}
67-
68-
pub fn trait_def(did: DefId) -> stable_mir::ty::TraitDef {
69-
with_tables(|t| t.trait_def(did))
70-
}
71-
72-
pub fn impl_def(did: DefId) -> stable_mir::ty::ImplDef {
73-
with_tables(|t| t.impl_def(did))
74-
}
75-
7619
impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
7720
type Output = DefId;
7821

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use crate::rustc_internal::{self, opaque};
10+
use crate::rustc_internal::opaque;
1111
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
1212
use crate::stable_mir::ty::{
1313
FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
@@ -276,7 +276,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
276276
place.stable(tables),
277277
),
278278
ThreadLocalRef(def_id) => {
279-
stable_mir::mir::Rvalue::ThreadLocalRef(rustc_internal::crate_item(*def_id))
279+
stable_mir::mir::Rvalue::ThreadLocalRef(tables.crate_item(*def_id))
280280
}
281281
AddressOf(mutability, place) => {
282282
stable_mir::mir::Rvalue::AddressOf(mutability.stable(tables), place.stable(tables))
@@ -739,7 +739,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
739739
mir::AggregateKind::Tuple => stable_mir::mir::AggregateKind::Tuple,
740740
mir::AggregateKind::Adt(def_id, var_idx, generic_arg, user_ty_index, field_idx) => {
741741
stable_mir::mir::AggregateKind::Adt(
742-
rustc_internal::adt_def(*def_id),
742+
tables.adt_def(*def_id),
743743
var_idx.index(),
744744
generic_arg.stable(tables),
745745
user_ty_index.map(|idx| idx.index()),
@@ -748,13 +748,13 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
748748
}
749749
mir::AggregateKind::Closure(def_id, generic_arg) => {
750750
stable_mir::mir::AggregateKind::Closure(
751-
rustc_internal::closure_def(*def_id),
751+
tables.closure_def(*def_id),
752752
generic_arg.stable(tables),
753753
)
754754
}
755755
mir::AggregateKind::Generator(def_id, generic_arg, movability) => {
756756
stable_mir::mir::AggregateKind::Generator(
757-
rustc_internal::generator_def(*def_id),
757+
tables.generator_def(*def_id),
758758
generic_arg.stable(tables),
759759
movability.stable(tables),
760760
)
@@ -964,13 +964,13 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
964964
impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
965965
type T = stable_mir::ty::BoundTyKind;
966966

967-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
967+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
968968
use stable_mir::ty::BoundTyKind;
969969

970970
match self {
971971
ty::BoundTyKind::Anon => BoundTyKind::Anon,
972972
ty::BoundTyKind::Param(def_id, symbol) => {
973-
BoundTyKind::Param(rustc_internal::param_def(*def_id), symbol.to_string())
973+
BoundTyKind::Param(tables.param_def(*def_id), symbol.to_string())
974974
}
975975
}
976976
}
@@ -987,7 +987,7 @@ impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
987987
BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
988988
}
989989
ty::BoundRegionKind::BrNamed(def_id, symbol) => {
990-
BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
990+
BoundRegionKind::BrNamed(tables.br_named_def(*def_id), symbol.to_string())
991991
}
992992
ty::BoundRegionKind::BrEnv => BoundRegionKind::BrEnv,
993993
}
@@ -1074,12 +1074,10 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10741074
ty::Uint(uint_ty) => TyKind::RigidTy(RigidTy::Uint(uint_ty.stable(tables))),
10751075
ty::Float(float_ty) => TyKind::RigidTy(RigidTy::Float(float_ty.stable(tables))),
10761076
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
1077-
rustc_internal::adt_def(adt_def.did()),
1077+
tables.adt_def(adt_def.did()),
10781078
generic_args.stable(tables),
10791079
)),
1080-
ty::Foreign(def_id) => {
1081-
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
1082-
}
1080+
ty::Foreign(def_id) => TyKind::RigidTy(RigidTy::Foreign(tables.foreign_def(*def_id))),
10831081
ty::Str => TyKind::RigidTy(RigidTy::Str),
10841082
ty::Array(ty, constant) => {
10851083
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), constant.stable(tables)))
@@ -1093,10 +1091,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10931091
tables.intern_ty(*ty),
10941092
mutbl.stable(tables),
10951093
)),
1096-
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
1097-
rustc_internal::fn_def(*def_id),
1098-
generic_args.stable(tables),
1099-
)),
1094+
ty::FnDef(def_id, generic_args) => {
1095+
TyKind::RigidTy(RigidTy::FnDef(tables.fn_def(*def_id), generic_args.stable(tables)))
1096+
}
11001097
ty::FnPtr(poly_fn_sig) => TyKind::RigidTy(RigidTy::FnPtr(poly_fn_sig.stable(tables))),
11011098
ty::Dynamic(existential_predicates, region, dyn_kind) => {
11021099
TyKind::RigidTy(RigidTy::Dynamic(
@@ -1109,11 +1106,11 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
11091106
))
11101107
}
11111108
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
1112-
rustc_internal::closure_def(*def_id),
1109+
tables.closure_def(*def_id),
11131110
generic_args.stable(tables),
11141111
)),
11151112
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
1116-
rustc_internal::generator_def(*def_id),
1113+
tables.generator_def(*def_id),
11171114
generic_args.stable(tables),
11181115
movability.stable(tables),
11191116
)),
@@ -1229,7 +1226,7 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef {
12291226
use stable_mir::ty::TraitDecl;
12301227

12311228
TraitDecl {
1232-
def_id: rustc_internal::trait_def(self.def_id),
1229+
def_id: tables.trait_def(self.def_id),
12331230
unsafety: self.unsafety.stable(tables),
12341231
paren_sugar: self.paren_sugar,
12351232
has_auto_impl: self.has_auto_impl,
@@ -1278,7 +1275,7 @@ impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
12781275
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
12791276
use stable_mir::ty::TraitRef;
12801277

1281-
TraitRef { def_id: rustc_internal::trait_def(self.def_id), args: self.args.stable(tables) }
1278+
TraitRef { def_id: tables.trait_def(self.def_id), args: self.args.stable(tables) }
12821279
}
12831280
}
12841281

0 commit comments

Comments
 (0)