Skip to content

Commit c21b1f7

Browse files
committed
Self review suggestions
- add back accidentally removed new lines - try to deref in patterns, rather than in expressions (maybe this was the reason of perf regression?...)
1 parent 8d3c90a commit c21b1f7

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

compiler/rustc_const_eval/src/interpret/step.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -151,50 +151,50 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
151151
// Also see https://github.com/rust-lang/rust/issues/68364.
152152

153153
use rustc_middle::mir::Rvalue::*;
154-
match rvalue {
154+
match *rvalue {
155155
ThreadLocalRef(did) => {
156-
let ptr = M::thread_local_static_base_pointer(self, *did)?;
156+
let ptr = M::thread_local_static_base_pointer(self, did)?;
157157
self.write_pointer(ptr, &dest)?;
158158
}
159159

160-
Use(operand) => {
160+
Use(ref operand) => {
161161
// Avoid recomputing the layout
162162
let op = self.eval_operand(operand, Some(dest.layout))?;
163163
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
164164
}
165165

166166
CopyForDeref(place) => {
167-
let op = self.eval_place_to_op(*place, Some(dest.layout))?;
167+
let op = self.eval_place_to_op(place, Some(dest.layout))?;
168168
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
169169
}
170170

171-
BinaryOp(bin_op, box (left, right)) => {
172-
let layout = binop_left_homogeneous(*bin_op).then_some(dest.layout);
171+
BinaryOp(bin_op, box (ref left, ref right)) => {
172+
let layout = binop_left_homogeneous(bin_op).then_some(dest.layout);
173173
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
174-
let layout = binop_right_homogeneous(*bin_op).then_some(left.layout);
174+
let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
175175
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
176-
self.binop_ignore_overflow(*bin_op, &left, &right, &dest)?;
176+
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
177177
}
178178

179-
CheckedBinaryOp(bin_op, box (left, right)) => {
179+
CheckedBinaryOp(bin_op, box (ref left, ref right)) => {
180180
// Due to the extra boolean in the result, we can never reuse the `dest.layout`.
181181
let left = self.read_immediate(&self.eval_operand(left, None)?)?;
182-
let layout = binop_right_homogeneous(*bin_op).then_some(left.layout);
182+
let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
183183
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
184184
self.binop_with_overflow(
185-
*bin_op, /*force_overflow_checks*/ false, &left, &right, &dest,
185+
bin_op, /*force_overflow_checks*/ false, &left, &right, &dest,
186186
)?;
187187
}
188188

189-
UnaryOp(un_op, operand) => {
189+
UnaryOp(un_op, ref operand) => {
190190
// The operand always has the same type as the result.
191191
let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
192-
let val = self.unary_op(*un_op, &val)?;
192+
let val = self.unary_op(un_op, &val)?;
193193
assert_eq!(val.layout, dest.layout, "layout mismatch for result of {:?}", un_op);
194194
self.write_immediate(*val, &dest)?;
195195
}
196196

197-
Aggregate(box kind, operands) => {
197+
Aggregate(box ref kind, ref operands) => {
198198
assert!(matches!(kind, mir::AggregateKind::Array(..)));
199199

200200
for (field_index, operand) in operands.iter().enumerate() {
@@ -204,7 +204,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
204204
}
205205
}
206206

207-
Repeat(operand, _) => {
207+
Repeat(ref operand, _) => {
208208
let src = self.eval_operand(operand, None)?;
209209
assert!(src.layout.is_sized());
210210
let dest = self.force_allocation(&dest)?;
@@ -241,14 +241,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
241241
}
242242

243243
Len(place) => {
244-
let src = self.eval_place(*place)?;
244+
let src = self.eval_place(place)?;
245245
let op = self.place_to_op(&src)?;
246246
let len = op.len(self)?;
247247
self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?;
248248
}
249249

250250
Ref(_, borrow_kind, place) => {
251-
let src = self.eval_place(*place)?;
251+
let src = self.eval_place(place)?;
252252
let place = self.force_allocation(&src)?;
253253
let val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
254254
// A fresh reference was created, make sure it gets retagged.
@@ -274,7 +274,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274274
false
275275
};
276276

277-
let src = self.eval_place(*place)?;
277+
let src = self.eval_place(place)?;
278278
let place = self.force_allocation(&src)?;
279279
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
280280
if !place_base_raw {
@@ -285,7 +285,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
285285
}
286286

287287
NullaryOp(null_op, ty) => {
288-
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(*ty)?;
288+
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
289289
let layout = self.layout_of(ty)?;
290290
if layout.is_unsized() {
291291
// FIXME: This should be a span_bug (#80742)
@@ -302,21 +302,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302302
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
303303
}
304304

305-
ShallowInitBox(operand, _) => {
305+
ShallowInitBox(ref operand, _) => {
306306
let src = self.eval_operand(operand, None)?;
307307
let v = self.read_immediate(&src)?;
308308
self.write_immediate(*v, &dest)?;
309309
}
310310

311-
Cast(cast_kind, operand, cast_ty) => {
311+
Cast(cast_kind, ref operand, cast_ty) => {
312312
let src = self.eval_operand(operand, None)?;
313313
let cast_ty =
314-
self.subst_from_current_frame_and_normalize_erasing_regions(*cast_ty)?;
315-
self.cast(&src, *cast_kind, cast_ty, &dest)?;
314+
self.subst_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
315+
self.cast(&src, cast_kind, cast_ty, &dest)?;
316316
}
317317

318318
Discriminant(place) => {
319-
let op = self.eval_place_to_op(*place, None)?;
319+
let op = self.eval_place_to_op(place, None)?;
320320
let discr_val = self.read_discriminant(&op)?.0;
321321
self.write_scalar(discr_val, &dest)?;
322322
}

compiler/rustc_const_eval/src/interpret/terminator.rs

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3535

3636
// Branch to the `otherwise` case by default, if no match is found.
3737
let mut target_block = targets.otherwise();
38+
3839
for (const_int, target) in targets.iter() {
3940
// Compare using MIR BinOp::Eq, to also support pointer values.
4041
// (Avoiding `self.binary_op` as that does some redundant layout computation.)
@@ -50,6 +51,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5051
break;
5152
}
5253
}
54+
5355
self.go_to_block(target_block);
5456
}
5557

@@ -66,11 +68,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6668
let old_loc = self.frame().loc;
6769
let func = self.eval_operand(func, None)?;
6870
let args = self.eval_operands(args)?;
71+
6972
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
7073
let fn_sig =
7174
self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder);
7275
let extra_args = &args[fn_sig.inputs().len()..];
7376
let extra_args = self.tcx.mk_type_list(extra_args.iter().map(|arg| arg.layout.ty));
77+
7478
let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
7579
ty::FnPtr(_sig) => {
7680
let fn_ptr = self.read_pointer(&func)?;
@@ -144,6 +148,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
144148
Abort => {
145149
M::abort(self, "the program aborted execution".to_owned())?;
146150
}
151+
147152
// When we encounter Resume, we've finished unwinding
148153
// cleanup for the current stack frame. We pop it in order
149154
// to continue unwinding the next frame
@@ -154,8 +159,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
154159
self.pop_stack_frame(/* unwinding */ true)?;
155160
return Ok(());
156161
}
162+
157163
// It is UB to ever encounter this.
158164
Unreachable => throw_ub!(Unreachable),
165+
159166
// These should never occur for MIR we actually run.
160167
DropAndReplace { .. }
161168
| FalseEdge { .. }

compiler/rustc_const_eval/src/interpret/visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ macro_rules! make_value_visitor {
483483
// Visit the fields of this value.
484484
match &v.layout().fields {
485485
FieldsShape::Primitive => {}
486-
FieldsShape::Union(fields) => {
487-
self.visit_union(v, *fields)?;
486+
&FieldsShape::Union(fields) => {
487+
self.visit_union(v, fields)?;
488488
}
489489
FieldsShape::Arbitrary { offsets, .. } => {
490490
// FIXME: We collect in a vec because otherwise there are lifetime

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2881,13 +2881,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28812881
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself));
28822882
self.res_to_ty(opt_self_ty, path, false)
28832883
}
2884-
hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
2885-
let opaque_ty = tcx.hir().item(*item_id);
2884+
&hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
2885+
let opaque_ty = tcx.hir().item(item_id);
28862886
let def_id = item_id.owner_id.to_def_id();
28872887

28882888
match opaque_ty.kind {
28892889
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
2890-
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, *in_trait)
2890+
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, in_trait)
28912891
}
28922892
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
28932893
}

0 commit comments

Comments
 (0)