Skip to content

Commit

Permalink
Remove box syntax from rustc_mir
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Aug 18, 2021
1 parent dcdadc4 commit 99db8fa
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 101 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Expand Up @@ -464,12 +464,12 @@ fn do_mir_borrowck<'a, 'tcx>(

let body_with_facts = if return_body_with_facts {
let output_facts = mbcx.polonius_output.expect("Polonius output was not computed");
Some(box BodyWithBorrowckFacts {
Some(Box::new(BodyWithBorrowckFacts {
body: body_owned,
input_facts: *polonius_input.expect("Polonius input facts were not generated"),
output_facts,
location_table: location_table_owned,
})
}))
} else {
None
};
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir/src/lib.rs
Expand Up @@ -11,7 +11,6 @@ Rust MIR: a lowered representation of Rust.
#![cfg_attr(bootstrap, feature(bindings_after_at))]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(exact_size_is_empty)]
Expand Down
60 changes: 30 additions & 30 deletions compiler/rustc_mir/src/shim.rs
Expand Up @@ -174,7 +174,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
0,
Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Raw, box (dropee_ptr)),
kind: StatementKind::Retag(RetagKind::Raw, Box::new(dropee_ptr)),
},
);
}
Expand Down Expand Up @@ -388,10 +388,10 @@ impl CloneShimBuilder<'tcx> {

fn copy_shim(&mut self) {
let rcvr = self.tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
let ret_statement = self.make_statement(StatementKind::Assign(box (
let ret_statement = self.make_statement(StatementKind::Assign(Box::new((
Place::return_place(),
Rvalue::Use(Operand::Copy(rcvr)),
)));
))));
self.block(vec![ret_statement], TerminatorKind::Return, false);
}

Expand All @@ -418,22 +418,22 @@ impl CloneShimBuilder<'tcx> {

// `func == Clone::clone(&ty) -> ty`
let func_ty = tcx.mk_fn_def(self.def_id, substs);
let func = Operand::Constant(box Constant {
let func = Operand::Constant(Box::new(Constant {
span: self.span,
user_ty: None,
literal: ty::Const::zero_sized(tcx, func_ty).into(),
});
}));

let ref_loc = self.make_place(
Mutability::Not,
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }),
);

// `let ref_loc: &ty = &src;`
let statement = self.make_statement(StatementKind::Assign(box (
let statement = self.make_statement(StatementKind::Assign(Box::new((
ref_loc,
Rvalue::Ref(tcx.lifetimes.re_erased, BorrowKind::Shared, src),
)));
))));

// `let loc = Clone::clone(ref_loc);`
self.block(
Expand Down Expand Up @@ -461,10 +461,10 @@ impl CloneShimBuilder<'tcx> {
let tcx = self.tcx;

let cond = self.make_place(Mutability::Mut, tcx.types.bool);
let compute_cond = self.make_statement(StatementKind::Assign(box (
let compute_cond = self.make_statement(StatementKind::Assign(Box::new((
cond,
Rvalue::BinaryOp(BinOp::Ne, box (Operand::Copy(end), Operand::Copy(beg))),
)));
Rvalue::BinaryOp(BinOp::Ne, Box::new((Operand::Copy(end), Operand::Copy(beg)))),
))));

// `if end != beg { goto loop_body; } else { goto loop_end; }`
self.block(
Expand All @@ -475,11 +475,11 @@ impl CloneShimBuilder<'tcx> {
}

fn make_usize(&self, value: u64) -> Box<Constant<'tcx>> {
box Constant {
Box::new(Constant {
span: self.span,
user_ty: None,
literal: ty::Const::from_usize(self.tcx, value).into(),
}
})
}

fn array_shim(
Expand All @@ -500,18 +500,18 @@ impl CloneShimBuilder<'tcx> {
// `let end = len;`
// `goto #1;`
let inits = vec![
self.make_statement(StatementKind::Assign(box (
self.make_statement(StatementKind::Assign(Box::new((
Place::from(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0))),
))),
self.make_statement(StatementKind::Assign(box (
)))),
self.make_statement(StatementKind::Assign(Box::new((
end,
Rvalue::Use(Operand::Constant(box Constant {
Rvalue::Use(Operand::Constant(Box::new(Constant {
span: self.span,
user_ty: None,
literal: len.into(),
})),
))),
}))),
)))),
];
self.block(inits, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);

Expand All @@ -532,13 +532,13 @@ impl CloneShimBuilder<'tcx> {
// BB #3
// `beg = beg + 1;`
// `goto #1`;
let statements = vec![self.make_statement(StatementKind::Assign(box (
let statements = vec![self.make_statement(StatementKind::Assign(Box::new((
Place::from(beg),
Rvalue::BinaryOp(
BinOp::Add,
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
Box::new((Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)))),
),
)))];
))))];
self.block(statements, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);

// BB #4
Expand All @@ -551,10 +551,10 @@ impl CloneShimBuilder<'tcx> {
// goto #6;
let end = beg;
let beg = self.local_decls.push(LocalDecl::new(tcx.types.usize, span));
let init = self.make_statement(StatementKind::Assign(box (
let init = self.make_statement(StatementKind::Assign(Box::new((
Place::from(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0))),
)));
))));
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);

// BB #6 (cleanup): loop {
Expand Down Expand Up @@ -585,13 +585,13 @@ impl CloneShimBuilder<'tcx> {
// BB #8 (cleanup)
// `beg = beg + 1;`
// `goto #6;`
let statement = self.make_statement(StatementKind::Assign(box (
let statement = self.make_statement(StatementKind::Assign(Box::new((
Place::from(beg),
Rvalue::BinaryOp(
BinOp::Add,
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
Box::new((Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)))),
),
)));
))));
self.block(vec![statement], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);

// BB #9 (resume)
Expand Down Expand Up @@ -748,10 +748,10 @@ fn build_call_shim<'tcx>(
let borrow_kind = BorrowKind::Mut { allow_two_phase_borrow: false };
statements.push(Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
Place::from(ref_rcvr),
Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()),
)),
))),
});
Operand::Move(Place::from(ref_rcvr))
}
Expand All @@ -765,11 +765,11 @@ fn build_call_shim<'tcx>(
CallKind::Direct(def_id) => {
let ty = tcx.type_of(def_id);
(
Operand::Constant(box Constant {
Operand::Constant(Box::new(Constant {
span,
user_ty: None,
literal: ty::Const::zero_sized(tcx, ty).into(),
}),
})),
rcvr.into_iter().collect::<Vec<_>>(),
)
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_mir/src/transform/add_retag.rs
Expand Up @@ -105,7 +105,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
0..0,
places.map(|place| Statement {
source_info,
kind: StatementKind::Retag(RetagKind::FnEntry, box (place)),
kind: StatementKind::Retag(RetagKind::FnEntry, Box::new(place)),
}),
);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
0,
Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Default, box (dest_place)),
kind: StatementKind::Retag(RetagKind::Default, Box::new(dest_place)),
},
);
}
Expand Down Expand Up @@ -175,7 +175,10 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
let source_info = block_data.statements[i].source_info;
block_data.statements.insert(
i + 1,
Statement { source_info, kind: StatementKind::Retag(retag_kind, box (place)) },
Statement {
source_info,
kind: StatementKind::Retag(retag_kind, Box::new(place)),
},
);
}
}
Expand Down
22 changes: 13 additions & 9 deletions compiler/rustc_mir/src/transform/coverage/graph.rs
Expand Up @@ -491,15 +491,19 @@ fn bcb_filtered_successors<'a, 'tcx>(
term_kind: &'tcx TerminatorKind<'tcx>,
) -> Box<dyn Iterator<Item = &'a BasicBlock> + 'a> {
let mut successors = term_kind.successors();
box match &term_kind {
// SwitchInt successors are never unwind, and all of them should be traversed.
TerminatorKind::SwitchInt { .. } => successors,
// For all other kinds, return only the first successor, if any, and ignore unwinds.
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
// `next().into_iter()`) into the `mir::Successors` aliased type.
_ => successors.next().into_iter().chain(&[]),
}
.filter(move |&&successor| body[successor].terminator().kind != TerminatorKind::Unreachable)
Box::new(
match &term_kind {
// SwitchInt successors are never unwind, and all of them should be traversed.
TerminatorKind::SwitchInt { .. } => successors,
// For all other kinds, return only the first successor, if any, and ignore unwinds.
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
// `next().into_iter()`) into the `mir::Successors` aliased type.
_ => successors.next().into_iter().chain(&[]),
}
.filter(move |&&successor| {
body[successor].terminator().kind != TerminatorKind::Unreachable
}),
)
}

/// Maintains separate worklists for each loop in the BasicCoverageBlock CFG, plus one for the
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/transform/coverage/mod.rs
Expand Up @@ -478,10 +478,10 @@ fn inject_statement(
let source_info = data.terminator().source_info;
let statement = Statement {
source_info,
kind: StatementKind::Coverage(box Coverage {
kind: StatementKind::Coverage(Box::new(Coverage {
kind: counter_kind,
code_region: some_code_region,
}),
})),
};
data.statements.insert(0, statement);
}
Expand All @@ -495,7 +495,7 @@ fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: Co
let source_info = data.terminator().source_info;
let statement = Statement {
source_info,
kind: StatementKind::Coverage(box Coverage { kind: expression, code_region: None }),
kind: StatementKind::Coverage(Box::new(Coverage { kind: expression, code_region: None })),
};
data.statements.push(statement);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/coverage/tests.rs
Expand Up @@ -44,11 +44,11 @@ const TEMP_BLOCK: BasicBlock = BasicBlock::MAX;

fn dummy_ty() -> &'static TyS<'static> {
thread_local! {
static DUMMY_TYS: &'static TyS<'static> = Box::leak(box TyS::make_for_test(
static DUMMY_TYS: &'static TyS<'static> = Box::leak(Box::new(TyS::make_for_test(
ty::Bool,
TypeFlags::empty(),
DebruijnIndex::from_usize(0),
));
)));
}

&DUMMY_TYS.with(|tys| *tys)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Expand Up @@ -96,14 +96,14 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
opt_to_apply.infos[0].first_switch_info.discr_used_in_switch;
let not_equal_rvalue = Rvalue::BinaryOp(
not_equal,
box (
Box::new((
Operand::Copy(Place::from(second_discriminant_temp)),
Operand::Copy(first_descriminant_place),
),
)),
);
patch.add_statement(
end_of_block_location,
StatementKind::Assign(box (Place::from(not_equal_temp), not_equal_rvalue)),
StatementKind::Assign(Box::new((Place::from(not_equal_temp), not_equal_rvalue))),
);

let new_targets = opt_to_apply
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/elaborate_drops.rs
Expand Up @@ -409,7 +409,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");

let assign = Statement {
kind: StatementKind::Assign(box (place, Rvalue::Use(value.clone()))),
kind: StatementKind::Assign(Box::new((place, Rvalue::Use(value.clone())))),
source_info: terminator.source_info,
};

Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_mir/src/transform/generator.rs
Expand Up @@ -274,7 +274,7 @@ impl TransformVisitor<'tcx> {
Statement {
source_info,
kind: StatementKind::SetDiscriminant {
place: box self_place,
place: Box::new(self_place),
variant_index: state_disc,
},
}
Expand All @@ -289,7 +289,7 @@ impl TransformVisitor<'tcx> {
let self_place = Place::from(SELF_ARG);
let assign = Statement {
source_info: SourceInfo::outermost(body.span),
kind: StatementKind::Assign(box (temp, Rvalue::Discriminant(self_place))),
kind: StatementKind::Assign(Box::new((temp, Rvalue::Discriminant(self_place)))),
};
(assign, temp)
}
Expand Down Expand Up @@ -954,7 +954,7 @@ fn create_generator_drop_shim<'tcx>(
0,
Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Raw, box Place::from(SELF_ARG)),
kind: StatementKind::Retag(RetagKind::Raw, Box::new(Place::from(SELF_ARG))),
},
)
}
Expand Down Expand Up @@ -984,11 +984,11 @@ fn insert_panic_block<'tcx>(
) -> BasicBlock {
let assert_block = BasicBlock::new(body.basic_blocks().len());
let term = TerminatorKind::Assert {
cond: Operand::Constant(box Constant {
cond: Operand::Constant(Box::new(Constant {
span: body.span,
user_ty: None,
literal: ty::Const::from_bool(tcx, false).into(),
}),
})),
expected: true,
msg: message,
target: assert_block,
Expand Down Expand Up @@ -1207,10 +1207,10 @@ fn create_cases<'tcx>(
let resume_arg = Local::new(2); // 0 = return, 1 = self
statements.push(Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
point.resume_arg,
Rvalue::Use(Operand::Move(resume_arg.into())),
)),
))),
});
}

Expand Down Expand Up @@ -1287,10 +1287,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
0,
Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
new_resume_local.into(),
Rvalue::Use(Operand::Move(resume_local.into())),
)),
))),
},
);

Expand Down

0 comments on commit 99db8fa

Please sign in to comment.