Skip to content

Commit cbb3e19

Browse files
committed
slow and stready
1 parent 7e7d1eb commit cbb3e19

File tree

2 files changed

+13
-70
lines changed

2 files changed

+13
-70
lines changed

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6161
if self.is_constant_pattern_subslice(prefix) && opt_slice.is_none() && suffix.len() == 0 {
6262
let elem_ty = prefix[0].ty;
6363
let prefix_valtree = self.simplify_const_pattern_slice_into_valtree(prefix);
64-
tracing::warn!("reduced prefix ({:?}) to ({:?})", prefix, prefix_valtree);
64+
//tracing::warn!("reduced prefix ({:?}) to ({:?})", prefix, prefix_valtree);
6565

6666
let match_pair = self.valtree_to_match_pair(
6767
src_path.ty,

compiler/rustc_mir_build/src/builder/matches/test.rs

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::cmp::Ordering;
1010
use rustc_data_structures::fx::FxIndexMap;
1111
use rustc_hir::{LangItem, RangeEnd};
1212
use rustc_middle::mir::*;
13-
use rustc_middle::ty::adjustment::PointerCoercion;
1413
use rustc_middle::ty::util::IntTypeExt;
1514
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt};
1615
use rustc_middle::{bug, span_bug};
@@ -375,14 +374,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
375374
mut val: Place<'tcx>,
376375
mut ty: Ty<'tcx>,
377376
) {
378-
//let mut expect_op = self.literal_operand(source_info.span, value);
379-
//let expect = self.temp(value, source_info.span);
380-
//self.cfg.push_assign(
381-
// block,
382-
// source_info,
383-
// expect,
384-
// Rvalue::Use(expect_op),
385-
//);
377+
let expect_ty = value.ty();
378+
let expect_op = self.literal_operand(source_info.span, value);
379+
let mut expect = self.temp(value.ty(), source_info.span);
380+
self.cfg.push_assign(
381+
block,
382+
source_info,
383+
expect,
384+
Rvalue::Use(expect_op),
385+
);
386386

387387
match ty.kind() {
388388
ty::Ref(_, inner_ty, _) if inner_ty.is_slice() => {
@@ -435,6 +435,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
435435
temp,
436436
Rvalue::Use(Operand::Copy(val)),
437437
);
438+
tracing::warn!("from {:?} to {:?}", val, temp);
438439
val = temp;
439440
}
440441
_=> break,
@@ -445,65 +446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
445446
};
446447

447448
(ty, val) = normalize_depth(ty, val);
448-
449-
// If we're using `b"..."` as a pattern, we need to insert an
450-
// unsizing coercion, as the byte string has the type `&[u8; N]`.
451-
//
452-
// We want to do this even when the scrutinee is a reference to an
453-
// array, so we can call `<[u8]>::eq` rather than having to find an
454-
// `<[u8; N]>::eq`.
455-
let unsize = |ty: Ty<'tcx>| match ty.kind() {
456-
ty::Ref(region, rty, _) => match rty.kind() {
457-
ty::Array(inner_ty, n) => Some((region, inner_ty, n)),
458-
_ => None,
459-
},
460-
_ => None,
461-
};
462-
let opt_ref_ty = unsize(ty);
463-
let opt_ref_test_ty = unsize(value.ty());
464-
match (opt_ref_ty, opt_ref_test_ty) {
465-
// nothing to do, neither is an array
466-
(None, None) => {}
467-
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
468-
let tcx = self.tcx;
469-
// make both a slice
470-
ty = Ty::new_imm_ref(tcx, *region, Ty::new_slice(tcx, *elem_ty));
471-
if opt_ref_ty.is_some() {
472-
let temp = self.temp(ty, source_info.span);
473-
self.cfg.push_assign(
474-
block,
475-
source_info,
476-
temp,
477-
Rvalue::Cast(
478-
CastKind::PointerCoercion(
479-
PointerCoercion::Unsize,
480-
CoercionSource::Implicit,
481-
),
482-
Operand::Copy(val),
483-
ty,
484-
),
485-
);
486-
val = temp;
487-
}
488-
if opt_ref_test_ty.is_some() {
489-
let slice = self.temp(ty, source_info.span);
490-
self.cfg.push_assign(
491-
block,
492-
source_info,
493-
slice,
494-
Rvalue::Cast(
495-
CastKind::PointerCoercion(
496-
PointerCoercion::Unsize,
497-
CoercionSource::Implicit,
498-
),
499-
expect,
500-
ty,
501-
),
502-
);
503-
expect = Operand::Move(slice);
504-
}
505-
}
506-
}
449+
(_, expect) = normalize_depth(expect_ty, expect);
507450

508451
// Figure out the type on which we are calling `PartialEq`. This involves an extra wrapping
509452
// reference: we can only compare two `&T`, and then compare_ty will be `T`.
@@ -540,7 +483,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
540483
const_: method,
541484
})),
542485
args: [Spanned { node: Operand::Copy(val), span: DUMMY_SP }, Spanned {
543-
node: expect,
486+
node: Operand::Copy(expect),
544487
span: DUMMY_SP,
545488
}]
546489
.into(),

0 commit comments

Comments
 (0)