Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove return_ty from Mir #46071

Merged
merged 1 commit into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ pub struct Mir<'tcx> {
/// in scope, but a separate set of locals.
pub promoted: IndexVec<Promoted, Mir<'tcx>>,

/// Return type of the function.
pub return_ty: Ty<'tcx>,

/// Yield type of the function, if it is a generator.
pub yield_ty: Option<Ty<'tcx>>,

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

Mir {
basic_blocks,
visibility_scopes,
visibility_scope_info,
promoted,
return_ty,
yield_ty,
generator_drop: None,
generator_layout: None,
Expand Down Expand Up @@ -273,6 +267,11 @@ impl<'tcx> Mir<'tcx> {
&block.terminator().source_info
}
}

/// Return the return type, it always return first element from `local_decls` array
pub fn return_ty(&self) -> Ty<'tcx> {
self.local_decls[RETURN_POINTER].ty
}
}

#[derive(Clone, Debug)]
Expand All @@ -299,7 +298,6 @@ impl_stable_hash_for!(struct Mir<'tcx> {
visibility_scopes,
visibility_scope_info,
promoted,
return_ty,
yield_ty,
generator_drop,
generator_layout,
Expand Down Expand Up @@ -1744,7 +1742,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
visibility_scopes: self.visibility_scopes.clone(),
visibility_scope_info: self.visibility_scope_info.clone(),
promoted: self.promoted.fold_with(folder),
return_ty: self.return_ty.fold_with(folder),
yield_ty: self.yield_ty.fold_with(folder),
generator_drop: self.generator_drop.fold_with(folder),
generator_layout: self.generator_layout.fold_with(folder),
Expand All @@ -1763,7 +1760,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
self.generator_layout.visit_with(visitor) ||
self.yield_ty.visit_with(visitor) ||
self.promoted.visit_with(visitor) ||
self.return_ty.visit_with(visitor) ||
self.local_decls.visit_with(visitor)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ macro_rules! make_mir_visitor {
self.visit_visibility_scope_data(scope);
}

self.visit_ty(&$($mutability)* mir.return_ty, TyContext::ReturnTy(SourceInfo {
self.visit_ty(&$($mutability)* mir.return_ty(), TyContext::ReturnTy(SourceInfo {
span: mir.span,
scope: ARGUMENT_VISIBILITY_SCOPE,
}));
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
}).collect()
});

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

builder.finish(vec![], ty, None)
builder.finish(vec![], None)
}

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

impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
Expand Down Expand Up @@ -524,7 +524,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

fn finish(self,
upvar_decls: Vec<UpvarDecl>,
return_ty: Ty<'tcx>,
yield_ty: Option<Ty<'tcx>>)
-> Mir<'tcx> {
for (index, block) in self.cfg.basic_blocks.iter().enumerate() {
Expand All @@ -537,7 +536,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
self.visibility_scopes,
ClearOnDecode::Set(self.visibility_scope_info),
IndexVec::new(),
return_ty,
yield_ty,
self.local_decls,
self.arg_count,
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls_for_sig(&sig, span),
sig.inputs().len(),
Expand Down Expand Up @@ -345,7 +344,6 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
),
ClearOnDecode::Clear,
IndexVec::new(),
self.sig.output(),
None,
self.local_decls,
self.sig.inputs().len(),
Expand Down Expand Up @@ -808,7 +806,6 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls,
sig.inputs().len(),
Expand Down Expand Up @@ -881,7 +878,6 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls,
sig.inputs().len(),
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ fn create_generator_drop_shim<'a, 'tcx>(
}

// Replace the return variable
mir.return_ty = tcx.mk_nil();
mir.local_decls[RETURN_POINTER] = LocalDecl {
mutability: Mutability::Mut,
ty: tcx.mk_nil(),
Expand Down Expand Up @@ -777,7 +776,7 @@ impl MirPass for StateTransform {
let state_did = tcx.lang_items().gen_state().unwrap();
let state_adt_ref = tcx.adt_def(state_did);
let state_substs = tcx.mk_substs([Kind::from(yield_ty),
Kind::from(mir.return_ty)].iter());
Kind::from(mir.return_ty())].iter());
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);

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

// Update our MIR struct to reflect the changed we've made
mir.return_ty = ret_ty;
mir.yield_ty = None;
mir.arg_count = 1;
mir.spread_arg = None;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
let span = self.promoted.span;
let new_operand = Operand::Constant(box Constant {
span,
ty: self.promoted.return_ty,
ty: self.promoted.return_ty(),
literal: Literal::Promoted {
index: Promoted::new(self.source.promoted.len())
}
Expand Down Expand Up @@ -385,7 +385,6 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
mir.visibility_scopes.clone(),
mir.visibility_scope_info.clone(),
IndexVec::new(),
ty,
None,
initial_locals,
0,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
// conservative type qualification instead.
if self.qualif.intersects(Qualif::CONST_ERROR) {
self.qualif = Qualif::empty();
let return_ty = mir.return_ty;
let return_ty = mir.return_ty();
self.add_type(return_ty);
}

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

if mir.return_ty.references_error() {
if mir.return_ty().references_error() {
tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors");
return (Qualif::NOT_CONST.bits(), Rc::new(IdxSetBuf::new_empty(0)));
}
Expand All @@ -956,7 +956,7 @@ impl MirPass for QualifyAndPromoteConstants {
src: MirSource,
mir: &mut Mir<'tcx>) {
// There's not really any point in promoting errorful MIR.
if mir.return_ty.references_error() {
if mir.return_ty().references_error() {
tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: Mir had errors");
return;
}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ impl MirPass for QualifyAndPromoteConstants {
return;
}
}
let ty = mir.return_ty;
let ty = mir.return_ty();
tcx.infer_ctxt().enter(|infcx| {
let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
let cause = traits::ObligationCause::new(mir.span, id, traits::SharedStatic);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}

fn visit_mir(&mut self, mir: &Mir<'tcx>) {
self.sanitize_type(&"return type", mir.return_ty);
self.sanitize_type(&"return type", mir.return_ty());
for local_decl in &mir.local_decls {
self.sanitize_type(local_decl, local_decl.ty);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
write!(w, "{:?}: {}", Lvalue::Local(arg), escape(&mir.local_decls[arg].ty))?;
}

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

for local in mir.vars_and_temps_iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
write!(w, "{:?}: {}", Lvalue::Local(arg), mir.local_decls[arg].ty)?;
}

write!(w, ") -> {}", mir.return_ty)
write!(w, ") -> {}", mir.return_ty())
}
(hir::BodyOwnerKind::Const, _) |
(hir::BodyOwnerKind::Static(_), _) |
(_, Some(_)) => {
assert_eq!(mir.arg_count, 0);
write!(w, ": {} =", mir.return_ty)
write!(w, ": {} =", mir.return_ty())
}
}
}
Expand Down