Skip to content

Commit 5f1c37a

Browse files
Rollup merge of #46071 - LooMaclin:fix-46001, r=estebank
Remove return_ty from Mir #46001
2 parents 1389b62 + 0b50884 commit 5f1c37a

File tree

10 files changed

+19
-32
lines changed

10 files changed

+19
-32
lines changed

src/librustc/mir/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ pub struct Mir<'tcx> {
8282
/// in scope, but a separate set of locals.
8383
pub promoted: IndexVec<Promoted, Mir<'tcx>>,
8484

85-
/// Return type of the function.
86-
pub return_ty: Ty<'tcx>,
87-
8885
/// Yield type of the function, if it is a generator.
8986
pub yield_ty: Option<Ty<'tcx>>,
9087

@@ -135,7 +132,6 @@ impl<'tcx> Mir<'tcx> {
135132
visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope,
136133
VisibilityScopeInfo>>,
137134
promoted: IndexVec<Promoted, Mir<'tcx>>,
138-
return_ty: Ty<'tcx>,
139135
yield_ty: Option<Ty<'tcx>>,
140136
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
141137
arg_count: usize,
@@ -145,14 +141,12 @@ impl<'tcx> Mir<'tcx> {
145141
// We need `arg_count` locals, and one for the return pointer
146142
assert!(local_decls.len() >= arg_count + 1,
147143
"expected at least {} locals, got {}", arg_count + 1, local_decls.len());
148-
assert_eq!(local_decls[RETURN_POINTER].ty, return_ty);
149144

150145
Mir {
151146
basic_blocks,
152147
visibility_scopes,
153148
visibility_scope_info,
154149
promoted,
155-
return_ty,
156150
yield_ty,
157151
generator_drop: None,
158152
generator_layout: None,
@@ -273,6 +267,11 @@ impl<'tcx> Mir<'tcx> {
273267
&block.terminator().source_info
274268
}
275269
}
270+
271+
/// Return the return type, it always return first element from `local_decls` array
272+
pub fn return_ty(&self) -> Ty<'tcx> {
273+
self.local_decls[RETURN_POINTER].ty
274+
}
276275
}
277276

278277
#[derive(Clone, Debug)]
@@ -299,7 +298,6 @@ impl_stable_hash_for!(struct Mir<'tcx> {
299298
visibility_scopes,
300299
visibility_scope_info,
301300
promoted,
302-
return_ty,
303301
yield_ty,
304302
generator_drop,
305303
generator_layout,
@@ -1744,7 +1742,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
17441742
visibility_scopes: self.visibility_scopes.clone(),
17451743
visibility_scope_info: self.visibility_scope_info.clone(),
17461744
promoted: self.promoted.fold_with(folder),
1747-
return_ty: self.return_ty.fold_with(folder),
17481745
yield_ty: self.yield_ty.fold_with(folder),
17491746
generator_drop: self.generator_drop.fold_with(folder),
17501747
generator_layout: self.generator_layout.fold_with(folder),
@@ -1763,7 +1760,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
17631760
self.generator_layout.visit_with(visitor) ||
17641761
self.yield_ty.visit_with(visitor) ||
17651762
self.promoted.visit_with(visitor) ||
1766-
self.return_ty.visit_with(visitor) ||
17671763
self.local_decls.visit_with(visitor)
17681764
}
17691765
}

src/librustc/mir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ macro_rules! make_mir_visitor {
292292
self.visit_visibility_scope_data(scope);
293293
}
294294

295-
self.visit_ty(&$($mutability)* mir.return_ty, TyContext::ReturnTy(SourceInfo {
295+
self.visit_ty(&$($mutability)* mir.return_ty(), TyContext::ReturnTy(SourceInfo {
296296
span: mir.span,
297297
scope: ARGUMENT_VISIBILITY_SCOPE,
298298
}));

src/librustc_mir/build/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
444444
}).collect()
445445
});
446446

447-
let mut mir = builder.finish(upvar_decls, return_ty, yield_ty);
447+
let mut mir = builder.finish(upvar_decls, yield_ty);
448448
mir.spread_arg = spread_arg;
449449
mir
450450
}
@@ -469,7 +469,7 @@ fn construct_const<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
469469
// Constants can't `return` so a return block should not be created.
470470
assert_eq!(builder.cached_return_block, None);
471471

472-
builder.finish(vec![], ty, None)
472+
builder.finish(vec![], None)
473473
}
474474

475475
fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
@@ -481,7 +481,7 @@ fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
481481
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty);
482482
let source_info = builder.source_info(span);
483483
builder.cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
484-
builder.finish(vec![], ty, None)
484+
builder.finish(vec![], None)
485485
}
486486

487487
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
@@ -524,7 +524,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
524524

525525
fn finish(self,
526526
upvar_decls: Vec<UpvarDecl>,
527-
return_ty: Ty<'tcx>,
528527
yield_ty: Option<Ty<'tcx>>)
529528
-> Mir<'tcx> {
530529
for (index, block) in self.cfg.basic_blocks.iter().enumerate() {
@@ -537,7 +536,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
537536
self.visibility_scopes,
538537
ClearOnDecode::Set(self.visibility_scope_info),
539538
IndexVec::new(),
540-
return_ty,
541539
yield_ty,
542540
self.local_decls,
543541
self.arg_count,

src/librustc_mir/shim.rs

-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
197197
),
198198
ClearOnDecode::Clear,
199199
IndexVec::new(),
200-
sig.output(),
201200
None,
202201
local_decls_for_sig(&sig, span),
203202
sig.inputs().len(),
@@ -345,7 +344,6 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
345344
),
346345
ClearOnDecode::Clear,
347346
IndexVec::new(),
348-
self.sig.output(),
349347
None,
350348
self.local_decls,
351349
self.sig.inputs().len(),
@@ -808,7 +806,6 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
808806
),
809807
ClearOnDecode::Clear,
810808
IndexVec::new(),
811-
sig.output(),
812809
None,
813810
local_decls,
814811
sig.inputs().len(),
@@ -881,7 +878,6 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
881878
),
882879
ClearOnDecode::Clear,
883880
IndexVec::new(),
884-
sig.output(),
885881
None,
886882
local_decls,
887883
sig.inputs().len(),

src/librustc_mir/transform/generator.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ fn create_generator_drop_shim<'a, 'tcx>(
557557
}
558558

559559
// Replace the return variable
560-
mir.return_ty = tcx.mk_nil();
561560
mir.local_decls[RETURN_POINTER] = LocalDecl {
562561
mutability: Mutability::Mut,
563562
ty: tcx.mk_nil(),
@@ -777,7 +776,7 @@ impl MirPass for StateTransform {
777776
let state_did = tcx.lang_items().gen_state().unwrap();
778777
let state_adt_ref = tcx.adt_def(state_did);
779778
let state_substs = tcx.mk_substs([Kind::from(yield_ty),
780-
Kind::from(mir.return_ty)].iter());
779+
Kind::from(mir.return_ty())].iter());
781780
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
782781

783782
// We rename RETURN_POINTER which has type mir.return_ty to new_ret_local
@@ -808,7 +807,6 @@ impl MirPass for StateTransform {
808807
transform.visit_mir(mir);
809808

810809
// Update our MIR struct to reflect the changed we've made
811-
mir.return_ty = ret_ty;
812810
mir.yield_ty = None;
813811
mir.arg_count = 1;
814812
mir.spread_arg = None;

src/librustc_mir/transform/promote_consts.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
287287
let span = self.promoted.span;
288288
let new_operand = Operand::Constant(box Constant {
289289
span,
290-
ty: self.promoted.return_ty,
290+
ty: self.promoted.return_ty(),
291291
literal: Literal::Promoted {
292292
index: Promoted::new(self.source.promoted.len())
293293
}
@@ -385,7 +385,6 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
385385
mir.visibility_scopes.clone(),
386386
mir.visibility_scope_info.clone(),
387387
IndexVec::new(),
388-
ty,
389388
None,
390389
initial_locals,
391390
0,

src/librustc_mir/transform/qualify_consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
380380
// conservative type qualification instead.
381381
if self.qualif.intersects(Qualif::CONST_ERROR) {
382382
self.qualif = Qualif::empty();
383-
let return_ty = mir.return_ty;
383+
let return_ty = mir.return_ty();
384384
self.add_type(return_ty);
385385
}
386386

@@ -938,7 +938,7 @@ fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
938938
// performing the steal.
939939
let mir = &tcx.mir_const(def_id).borrow();
940940

941-
if mir.return_ty.references_error() {
941+
if mir.return_ty().references_error() {
942942
tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors");
943943
return (Qualif::NOT_CONST.bits(), Rc::new(IdxSetBuf::new_empty(0)));
944944
}
@@ -956,7 +956,7 @@ impl MirPass for QualifyAndPromoteConstants {
956956
src: MirSource,
957957
mir: &mut Mir<'tcx>) {
958958
// There's not really any point in promoting errorful MIR.
959-
if mir.return_ty.references_error() {
959+
if mir.return_ty().references_error() {
960960
tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: Mir had errors");
961961
return;
962962
}
@@ -1045,7 +1045,7 @@ impl MirPass for QualifyAndPromoteConstants {
10451045
return;
10461046
}
10471047
}
1048-
let ty = mir.return_ty;
1048+
let ty = mir.return_ty();
10491049
tcx.infer_ctxt().enter(|infcx| {
10501050
let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
10511051
let cause = traits::ObligationCause::new(mir.span, id, traits::SharedStatic);

src/librustc_mir/transform/type_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
130130
}
131131

132132
fn visit_mir(&mut self, mir: &Mir<'tcx>) {
133-
self.sanitize_type(&"return type", mir.return_ty);
133+
self.sanitize_type(&"return type", mir.return_ty());
134134
for local_decl in &mir.local_decls {
135135
self.sanitize_type(local_decl, local_decl.ty);
136136
}

src/librustc_mir/util/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
150150
write!(w, "{:?}: {}", Lvalue::Local(arg), escape(&mir.local_decls[arg].ty))?;
151151
}
152152

153-
write!(w, ") -&gt; {}", escape(mir.return_ty))?;
153+
write!(w, ") -&gt; {}", escape(mir.return_ty()))?;
154154
write!(w, r#"<br align="left"/>"#)?;
155155

156156
for local in mir.vars_and_temps_iter() {

src/librustc_mir/util/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,13 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
392392
write!(w, "{:?}: {}", Lvalue::Local(arg), mir.local_decls[arg].ty)?;
393393
}
394394

395-
write!(w, ") -> {}", mir.return_ty)
395+
write!(w, ") -> {}", mir.return_ty())
396396
}
397397
(hir::BodyOwnerKind::Const, _) |
398398
(hir::BodyOwnerKind::Static(_), _) |
399399
(_, Some(_)) => {
400400
assert_eq!(mir.arg_count, 0);
401-
write!(w, ": {} =", mir.return_ty)
401+
write!(w, ": {} =", mir.return_ty())
402402
}
403403
}
404404
}

0 commit comments

Comments
 (0)