Skip to content

Commit

Permalink
Stop using the unpack! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jul 8, 2024
1 parent 5066e6c commit 8357e4e
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 178 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
});
matching.and(failure)
});
let failure = unpack!(block = failure_and_block);
let failure = failure_and_block.unpack(&mut block);
this.cfg.goto(failure, source_info, failure_entry);

if let Some(source_scope) = visibility_scope {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/as_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(Operand::Constant(Box::new(constant)))
}
Category::Constant | Category::Place | Category::Rvalue(..) => {
let operand = unpack!(block = this.as_temp(block, scope, expr_id, Mutability::Mut));
let operand =
this.as_temp(block, scope, expr_id, Mutability::Mut).unpack(&mut block);
// Overwrite temp local info if we have something more interesting to record.
if !matches!(local_info, LocalInfo::Boring) {
let decl_info =
Expand Down Expand Up @@ -174,7 +175,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// type, and that value is coming from the deref of a box.
if let ExprKind::Deref { arg } = expr.kind {
// Generate let tmp0 = arg0
let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut));
let operand =
this.as_temp(block, scope, arg, Mutability::Mut).unpack(&mut block);

// Return the operand *tmp0 to be used as the call argument
let place = Place {
Expand Down
32 changes: 17 additions & 15 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
mut block: BasicBlock,
expr_id: ExprId,
) -> BlockAnd<Place<'tcx>> {
let place_builder = unpack!(block = self.as_place_builder(block, expr_id));
let place_builder = self.as_place_builder(block, expr_id).unpack(&mut block);
block.and(place_builder.to_place(self))
}

Expand All @@ -393,7 +393,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
mut block: BasicBlock,
expr_id: ExprId,
) -> BlockAnd<Place<'tcx>> {
let place_builder = unpack!(block = self.as_read_only_place_builder(block, expr_id));
let place_builder = self.as_read_only_place_builder(block, expr_id).unpack(&mut block);
block.and(place_builder.to_place(self))
}

Expand Down Expand Up @@ -432,8 +432,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
ExprKind::Field { lhs, variant_index, name } => {
let lhs_expr = &this.thir[lhs];
let mut place_builder =
unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,));
let mut place_builder = this
.expr_as_place(block, lhs, mutability, fake_borrow_temps)
.unpack(&mut block);
if let ty::Adt(adt_def, _) = lhs_expr.ty.kind() {
if adt_def.is_enum() {
place_builder = place_builder.downcast(*adt_def, variant_index);
Expand All @@ -442,8 +443,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(place_builder.field(name, expr.ty))
}
ExprKind::Deref { arg } => {
let place_builder =
unpack!(block = this.expr_as_place(block, arg, mutability, fake_borrow_temps,));
let place_builder = this
.expr_as_place(block, arg, mutability, fake_borrow_temps)
.unpack(&mut block);
block.and(place_builder.deref())
}
ExprKind::Index { lhs, index } => this.lower_index_expression(
Expand Down Expand Up @@ -472,9 +474,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

ExprKind::PlaceTypeAscription { source, ref user_ty } => {
let place_builder = unpack!(
block = this.expr_as_place(block, source, mutability, fake_borrow_temps,)
);
let place_builder = this
.expr_as_place(block, source, mutability, fake_borrow_temps)
.unpack(&mut block);
if let Some(user_ty) = user_ty {
let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
Expand Down Expand Up @@ -502,9 +504,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
ExprKind::ValueTypeAscription { source, ref user_ty } => {
let source_expr = &this.thir[source];
let temp = unpack!(
block = this.as_temp(block, source_expr.temp_lifetime, source, mutability)
);
let temp = this
.as_temp(block, source_expr.temp_lifetime, source, mutability)
.unpack(&mut block);
if let Some(user_ty) = user_ty {
let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
Expand Down Expand Up @@ -570,7 +572,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// these are not places, so we need to make a temporary.
debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place)));
let temp =
unpack!(block = this.as_temp(block, expr.temp_lifetime, expr_id, mutability));
this.as_temp(block, expr.temp_lifetime, expr_id, mutability).unpack(&mut block);
block.and(PlaceBuilder::from(temp))
}
}
Expand Down Expand Up @@ -612,12 +614,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fake_borrow_temps = fake_borrow_temps.unwrap_or(base_fake_borrow_temps);

let base_place =
unpack!(block = self.expr_as_place(block, base, mutability, Some(fake_borrow_temps),));
self.expr_as_place(block, base, mutability, Some(fake_borrow_temps)).unpack(&mut block);

// Making this a *fresh* temporary means we do not have to worry about
// the index changing later: Nothing will ever change this temporary.
// The "retagging" transformation (for Stacked Borrows) relies on this.
let idx = unpack!(block = self.as_temp(block, temp_lifetime, index, Mutability::Not));
let idx = self.as_temp(block, temp_lifetime, index, Mutability::Not).unpack(&mut block);

block = self.bounds_check(block, &base_place, idx, expr_span, source_info);

Expand Down
136 changes: 45 additions & 91 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if Some(0) == count.try_eval_target_usize(this.tcx, this.param_env) {
this.build_zero_repeat(block, value, scope, source_info)
} else {
let value_operand = unpack!(
block = this.as_operand(
block,
scope,
value,
LocalInfo::Boring,
NeedsTemporary::No
)
);
let value_operand = this
.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
block.and(Rvalue::Repeat(value_operand, count))
}
}
ExprKind::Binary { op, lhs, rhs } => {
let lhs = unpack!(
block = this.as_operand(
block,
scope,
lhs,
LocalInfo::Boring,
NeedsTemporary::Maybe
)
);
let rhs = unpack!(
block =
this.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No)
);
let lhs = this
.as_operand(block, scope, lhs, LocalInfo::Boring, NeedsTemporary::Maybe)
.unpack(&mut block);
let rhs = this
.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
}
ExprKind::Unary { op, arg } => {
let arg = unpack!(
block =
this.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No)
);
let arg = this
.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
// Check for -MIN on signed integers
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
let bool_ty = this.tcx.types.bool;
Expand Down Expand Up @@ -200,7 +186,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&& adt_def.is_enum()
{
let discr_ty = adt_def.repr().discr_type().to_ty(this.tcx);
let temp = unpack!(block = this.as_temp(block, scope, source, Mutability::Not));
let temp =
this.as_temp(block, scope, source, Mutability::Not).unpack(&mut block);
let layout = this.tcx.layout_of(this.param_env.and(source_expr.ty));
let discr = this.temp(discr_ty, source_expr.span);
this.cfg.push_assign(
Expand Down Expand Up @@ -282,15 +269,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
(op, ty)
} else {
let ty = source_expr.ty;
let source = unpack!(
block = this.as_operand(
block,
scope,
source,
LocalInfo::Boring,
NeedsTemporary::No
)
);
let source = this
.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
(source, ty)
};
let from_ty = CastTy::from_ty(ty);
Expand All @@ -300,15 +281,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(Rvalue::Cast(cast_kind, source, expr.ty))
}
ExprKind::PointerCoercion { cast, source } => {
let source = unpack!(
block = this.as_operand(
block,
scope,
source,
LocalInfo::Boring,
NeedsTemporary::No
)
);
let source = this
.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
block.and(Rvalue::Cast(CastKind::PointerCoercion(cast), source, expr.ty))
}
ExprKind::Array { ref fields } => {
Expand Down Expand Up @@ -344,15 +319,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.into_iter()
.copied()
.map(|f| {
unpack!(
block = this.as_operand(
block,
scope,
f,
LocalInfo::Boring,
NeedsTemporary::Maybe
)
)
this.as_operand(block, scope, f, LocalInfo::Boring, NeedsTemporary::Maybe)
.unpack(&mut block)
})
.collect();

Expand All @@ -365,15 +333,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.into_iter()
.copied()
.map(|f| {
unpack!(
block = this.as_operand(
block,
scope,
f,
LocalInfo::Boring,
NeedsTemporary::Maybe
)
)
this.as_operand(block, scope, f, LocalInfo::Boring, NeedsTemporary::Maybe)
.unpack(&mut block)
})
.collect();

Expand Down Expand Up @@ -401,7 +362,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// ```
//
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
let place_builder = unpack!(block = this.as_place_builder(block, *thir_place));
let place_builder =
this.as_place_builder(block, *thir_place).unpack(&mut block);

if let Some(mir_place) = place_builder.try_to_place(this) {
this.cfg.push_fake_read(
Expand Down Expand Up @@ -429,7 +391,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// This occurs when capturing by copy/move, while
// by reference captures use as_operand
Some(Category::Place) => {
let place = unpack!(block = this.as_place(block, upvar));
let place = this.as_place(block, upvar).unpack(&mut block);
this.consume_by_copy_or_move(place)
}
_ => {
Expand All @@ -442,26 +404,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
borrow_kind:
BorrowKind::Mut { kind: MutBorrowKind::Default },
arg,
} => unpack!(
block = this.limit_capture_mutability(
} => this
.limit_capture_mutability(
upvar_expr.span,
upvar_expr.ty,
scope,
block,
arg,
)
),
_ => {
unpack!(
block = this.as_operand(
block,
scope,
upvar,
LocalInfo::Boring,
NeedsTemporary::Maybe
)
.unpack(&mut block),
_ => this
.as_operand(
block,
scope,
upvar,
LocalInfo::Boring,
NeedsTemporary::Maybe,
)
}
.unpack(&mut block),
}
}
}
Expand Down Expand Up @@ -536,15 +496,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Category::of(&expr.kind),
Some(Category::Rvalue(RvalueFunc::AsRvalue) | Category::Constant)
));
let operand = unpack!(
block = this.as_operand(
block,
scope,
expr_id,
LocalInfo::Boring,
NeedsTemporary::No,
)
);
let operand = this
.as_operand(block, scope, expr_id, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
block.and(Rvalue::Use(operand))
}
}
Expand Down Expand Up @@ -716,9 +670,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Repeating a const does nothing
} else {
// For a non-const, we may need to generate an appropriate `Drop`
let value_operand = unpack!(
block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
);
let value_operand = this
.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
.unpack(&mut block);
if let Operand::Move(to_drop) = value_operand {
let success = this.cfg.start_new_block();
this.cfg.terminate(
Expand Down Expand Up @@ -754,7 +708,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

this.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });

let arg_place_builder = unpack!(block = this.as_place_builder(block, arg));
let arg_place_builder = this.as_place_builder(block, arg).unpack(&mut block);

let mutability = match arg_place_builder.base() {
// We are capturing a path that starts off a local variable in the parent.
Expand Down
Loading

0 comments on commit 8357e4e

Please sign in to comment.