Skip to content

Commit bfdeb2e

Browse files
committed
Retire MirSource.
1 parent cc58ae5 commit bfdeb2e

File tree

8 files changed

+22
-48
lines changed

8 files changed

+22
-48
lines changed

compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
905905
feeder.opt_local_def_id_to_hir_id(None);
906906

907907
let def_id = feeder.def_id();
908-
self.promoted.source = MirSource::item(def_id.to_def_id());
908+
self.promoted.source = ty::InstanceDef::Item(def_id.to_def_id());
909909
let parent_substs = tcx.erase_regions(InternalSubsts::identity_for_item(
910910
tcx,
911911
tcx.typeck_root_def_id(source_def_id.to_def_id()),

compiler/rustc_const_eval/src/transform/validate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
4242
// terribly important that they pass the validator. However, I think other passes might
4343
// still see them, in which case they might be surprised. It would probably be better if we
4444
// didn't put this through the MIR pipeline at all.
45-
if matches!(body.source.instance, InstanceDef::Intrinsic(..) | InstanceDef::Virtual(..)) {
45+
if matches!(body.source, InstanceDef::Intrinsic(..) | InstanceDef::Virtual(..)) {
4646
return;
4747
}
4848
let def_id = body.source.def_id();
@@ -74,7 +74,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
7474
checker.check_cleanup_control_flow();
7575

7676
if let MirPhase::Runtime(_) = body.phase {
77-
if let ty::InstanceDef::Item(_) = body.source.instance {
77+
if let ty::InstanceDef::Item(_) = body.source {
7878
if body.has_free_regions() {
7979
checker.fail(
8080
Location::START,
@@ -109,7 +109,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
109109
span,
110110
format!(
111111
"broken MIR in {:?} ({}) at {:?}:\n{}",
112-
self.body.source.instance,
112+
self.body.source,
113113
self.when,
114114
location,
115115
msg.as_ref()
@@ -1104,7 +1104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11041104
self.body.span,
11051105
format!(
11061106
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",
1107-
self.body.source.instance, self.when, scope,
1107+
self.body.source, self.when, scope,
11081108
),
11091109
);
11101110
}

compiler/rustc_middle/src/mir/mod.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,6 @@ impl RuntimePhase {
179179
}
180180
}
181181

182-
/// Where a specific `mir::Body` comes from.
183-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
184-
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
185-
pub struct MirSource<'tcx> {
186-
pub instance: InstanceDef<'tcx>,
187-
}
188-
189-
impl<'tcx> MirSource<'tcx> {
190-
pub fn item(def_id: DefId) -> Self {
191-
MirSource { instance: InstanceDef::Item(def_id) }
192-
}
193-
194-
pub fn from_instance(instance: InstanceDef<'tcx>) -> Self {
195-
MirSource { instance }
196-
}
197-
198-
#[inline]
199-
pub fn def_id(&self) -> DefId {
200-
self.instance.def_id()
201-
}
202-
}
203-
204182
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
205183
pub struct GeneratorInfo<'tcx> {
206184
/// The yield type of the function, if it is a generator.
@@ -234,7 +212,7 @@ pub struct Body<'tcx> {
234212
/// How many passses we have executed since starting the current phase. Used for debug output.
235213
pub pass_count: usize,
236214

237-
pub source: MirSource<'tcx>,
215+
pub source: InstanceDef<'tcx>,
238216

239217
/// A list of source scopes; these are referenced by statements
240218
/// and used for debuginfo. Indexed by a `SourceScope`.
@@ -305,7 +283,7 @@ pub struct Body<'tcx> {
305283

306284
impl<'tcx> Body<'tcx> {
307285
pub fn new(
308-
source: MirSource<'tcx>,
286+
source: InstanceDef<'tcx>,
309287
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
310288
source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
311289
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
@@ -362,7 +340,7 @@ impl<'tcx> Body<'tcx> {
362340
let mut body = Body {
363341
phase: MirPhase::Built,
364342
pass_count: 0,
365-
source: MirSource::item(CRATE_DEF_ID.to_def_id()),
343+
source: InstanceDef::Item(CRATE_DEF_ID.to_def_id()),
366344
basic_blocks: BasicBlocks::new(basic_blocks),
367345
source_scopes: IndexVec::new(),
368346
generator: None,

compiler/rustc_middle/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn dump_file_basename<'tcx>(
176176
let item_name = tcx.def_path(source.def_id()).to_filename_friendly_no_crate();
177177
// All drop shims have the same DefId, so we have to add the type
178178
// to get unique file names.
179-
let shim_disambiguator = match source.instance {
179+
let shim_disambiguator = match source {
180180
ty::InstanceDef::DropGlue(_, Some(ty)) => {
181181
// Unfortunately, pretty-printed typed are not very filename-friendly.
182182
// We dome some filtering.
@@ -976,7 +976,7 @@ fn write_allocation_bytes<'tcx, Prov: Provenance, Extra, Bytes: AllocBytes>(
976976
fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn Write) -> io::Result<()> {
977977
use rustc_hir::def::DefKind;
978978

979-
trace!("write_mir_sig: {:?}", body.source.instance);
979+
trace!("write_mir_sig: {:?}", body.source);
980980
let def_id = body.source.def_id();
981981
let kind = tcx.def_kind(def_id);
982982
let is_function = match kind {

compiler/rustc_mir_build/src/build/custom/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_index::{IndexSlice, IndexVec};
2525
use rustc_middle::{
2626
mir::*,
2727
thir::*,
28-
ty::{ParamEnv, Ty, TyCtxt},
28+
ty::{InstanceDef, ParamEnv, Ty, TyCtxt},
2929
};
3030
use rustc_span::Span;
3131

@@ -45,7 +45,7 @@ pub(super) fn build_custom_mir<'tcx>(
4545
) -> Body<'tcx> {
4646
let mut body = Body {
4747
basic_blocks: BasicBlocks::new(IndexVec::new()),
48-
source: MirSource::item(did),
48+
source: InstanceDef::Item(did),
4949
phase: MirPhase::Built,
5050
source_scopes: IndexVec::new(),
5151
generator: None,

compiler/rustc_mir_build/src/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ fn construct_error(tcx: TyCtxt<'_>, def: LocalDefId, err: ErrorGuaranteed) -> Bo
640640
cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
641641

642642
let mut body = Body::new(
643-
MirSource::item(def.to_def_id()),
643+
ty::InstanceDef::Item(def.to_def_id()),
644644
cfg.basic_blocks,
645645
source_scopes,
646646
local_decls,
@@ -730,7 +730,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
730730
}
731731

732732
Body::new(
733-
MirSource::item(self.def_id.to_def_id()),
733+
ty::InstanceDef::Item(self.def_id.to_def_id()),
734734
self.cfg.basic_blocks,
735735
self.source_scopes,
736736
self.local_decls,

compiler/rustc_mir_transform/src/check_packed_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
3939
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
4040
if context.is_borrow() {
4141
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
42-
let def_id = self.body.source.instance.def_id();
42+
let def_id = self.body.source.def_id();
4343
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
4444
&& self.tcx.is_builtin_derived(impl_def_id)
4545
{

compiler/rustc_mir_transform/src/shim.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
171171
block(&mut blocks, TerminatorKind::Goto { target: return_block });
172172
block(&mut blocks, TerminatorKind::Return);
173173

174-
let source = MirSource::from_instance(ty::InstanceDef::DropGlue(def_id, ty));
174+
let source = ty::InstanceDef::DropGlue(def_id, ty);
175175
let mut body =
176176
new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span);
177177

@@ -229,7 +229,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
229229
}
230230

231231
fn new_body<'tcx>(
232-
source: MirSource<'tcx>,
232+
source: ty::InstanceDef<'tcx>,
233233
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
234234
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
235235
arg_count: usize,
@@ -343,7 +343,7 @@ fn build_thread_local_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'t
343343
});
344344

345345
new_body(
346-
MirSource::from_instance(instance),
346+
instance,
347347
blocks,
348348
IndexVec::from_raw(vec![LocalDecl::new(tcx.thread_local_ptr_ty(def_id), span)]),
349349
0,
@@ -407,10 +407,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
407407
}
408408

409409
fn into_mir(self) -> Body<'tcx> {
410-
let source = MirSource::from_instance(ty::InstanceDef::CloneShim(
411-
self.def_id,
412-
self.sig.inputs_and_output[0],
413-
));
410+
let source = ty::InstanceDef::CloneShim(self.def_id, self.sig.inputs_and_output[0]);
414411
new_body(source, self.blocks, self.local_decls, self.sig.inputs().len(), self.span)
415412
}
416413

@@ -823,8 +820,7 @@ fn build_call_shim<'tcx>(
823820
block(&mut blocks, vec![], TerminatorKind::Resume, true);
824821
}
825822

826-
let mut body =
827-
new_body(MirSource::from_instance(instance), blocks, local_decls, sig.inputs().len(), span);
823+
let mut body = new_body(instance, blocks, local_decls, sig.inputs().len(), span);
828824

829825
if let Abi::RustCall = sig.abi {
830826
body.spread_arg = Some(Local::new(sig.inputs().len()));
@@ -890,7 +886,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
890886
is_cleanup: false,
891887
};
892888

893-
let source = MirSource::item(ctor_id);
889+
let source = ty::InstanceDef::Item(ctor_id);
894890
let body = new_body(
895891
source,
896892
IndexVec::from_elem_n(start_block, 1),
@@ -936,6 +932,6 @@ fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'t
936932
terminator: Some(Terminator { source_info, kind: TerminatorKind::Return }),
937933
is_cleanup: false,
938934
};
939-
let source = MirSource::from_instance(ty::InstanceDef::FnPtrAddrShim(def_id, self_ty));
935+
let source = ty::InstanceDef::FnPtrAddrShim(def_id, self_ty);
940936
new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span)
941937
}

0 commit comments

Comments
 (0)