Skip to content

Commit 7e7d1eb

Browse files
committed
progress
1 parent 68cb418 commit 7e7d1eb

File tree

3 files changed

+99
-27
lines changed

3 files changed

+99
-27
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,8 @@ codegen-units = 1
9393
# FIXME: LTO cannot be enabled for binaries in a workspace
9494
# <https://github.com/rust-lang/cargo/issues/9330>
9595
# lto = true
96+
97+
[profile.release.package.rustc_mir_build]
98+
opt-level = 1
99+
[profile.release.package.rustc_driver]
100+
opt-level = 1

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,19 @@ 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);
6465

65-
if let Some(match_pair) = self.valtree_to_match_pair(
66+
let match_pair = self.valtree_to_match_pair(
6667
src_path.ty,
6768
src_path.span,
6869
prefix.len() as u64,
6970
prefix_valtree,
7071
place.clone(),
7172
elem_ty,
72-
) {
73-
match_pairs.push(match_pair);
74-
prefix_opt = true;
75-
}
73+
);
74+
75+
match_pairs.push(match_pair);
76+
prefix_opt = true;
7677
}
7778

7879
if !prefix_opt {
@@ -155,20 +156,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
155156
valtree: ty::ValTree<'tcx>,
156157
place: PlaceBuilder<'tcx>,
157158
elem_ty: Ty<'tcx>,
158-
) -> Option<MatchPairTree<'pat, 'tcx>> {
159+
) -> MatchPairTree<'pat, 'tcx> {
159160
let tcx = self.tcx;
160-
let (const_ty, pat_ty) = if src_pat_ty.is_slice() {
161-
(
162-
Ty::new_imm_ref(
161+
tracing::warn!("valtree_to_match_pair: {:?} {:?}", subslice_len, src_pat_ty);
162+
163+
let (const_ty, pat_ty) = match src_pat_ty.kind() {
164+
ty::Slice(_) => {
165+
(Ty::new_imm_ref(
163166
tcx,
164167
tcx.lifetimes.re_erased,
165168
Ty::new_array(tcx, elem_ty, subslice_len),
166169
),
167-
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, Ty::new_slice(tcx, elem_ty)),
168-
)
169-
} else {
170-
let arr_ty = Ty::new_array(tcx, elem_ty, subslice_len);
171-
(arr_ty, arr_ty)
170+
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, Ty::new_slice(tcx, elem_ty)),)
171+
}
172+
ty::Array(_, _) => {
173+
(Ty::new_imm_ref(
174+
tcx,
175+
tcx.lifetimes.re_erased,
176+
Ty::new_array(tcx, elem_ty, subslice_len),
177+
),
178+
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, Ty::new_array(tcx, elem_ty, subslice_len)),)
179+
}
180+
_ => todo!()
172181
};
173182

174183
let r#const = ty::Const::new(tcx, ty::ConstKind::Value(const_ty, valtree));
@@ -182,12 +191,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
182191

183192
let test_case = TestCase::Constant { value: r#const2 };
184193

185-
Some(MatchPairTree {
194+
MatchPairTree {
186195
place: Some(place.to_place(self)),
187196
test_case,
188197
subpairs: Vec::new(),
189198
pattern,
190-
})
199+
}
191200
}
192201
}
193202

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

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,76 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
375375
mut val: Place<'tcx>,
376376
mut ty: Ty<'tcx>,
377377
) {
378-
let mut expect = self.literal_operand(source_info.span, value);
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+
//);
386+
387+
match ty.kind() {
388+
ty::Ref(_, inner_ty, _) if inner_ty.is_slice() => {
389+
let ref_ty = Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, ty);
390+
let temp = self.temp(ty, source_info.span);
391+
self.cfg.push_assign(
392+
block,
393+
source_info,
394+
temp,
395+
Rvalue::Ref(self.tcx.lifetimes.re_erased, BorrowKind::Shared, val),
396+
);
397+
ty = ref_ty;
398+
val = temp;
399+
tracing::warn!("slice ty sig: {:?}", ty);
400+
}
401+
ty::Ref(_, inner_ty, _) if inner_ty.is_array() => {
402+
let ref_ty = Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, ty);
403+
let temp = self.temp(ref_ty, source_info.span);
404+
self.cfg.push_assign(
405+
block,
406+
source_info,
407+
temp,
408+
Rvalue::Ref(self.tcx.lifetimes.re_erased, BorrowKind::Shared, val),
409+
);
379410

380-
let ref_ty = Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, ty);
381-
let temp = self.temp(ty, source_info.span);
382-
self.cfg.push_assign(
383-
block,
384-
source_info,
385-
temp,
386-
Rvalue::Ref(self.tcx.lifetimes.re_erased, BorrowKind::Shared, val),
387-
);
388-
ty = ref_ty;
389-
val = temp;
411+
ty = ref_ty;
412+
val = temp;
413+
tracing::warn!("arr ty sig: {:?}", ty);
414+
}
415+
ty::Ref(_, inner_ty, _) if inner_ty.is_str() => {
416+
// nothing yet
417+
}
418+
_ => todo!("not yet, ty: {:?}", ty),
419+
}
420+
421+
let mut normalize_depth = |mut ty: Ty<'tcx>, mut val: Place<'tcx>| {
422+
if !ty.is_ref() {
423+
panic!("not a reference?");
424+
}
425+
426+
loop {
427+
match ty.kind() {
428+
ty::Ref(_, inner_ty @ _, _) if inner_ty.is_ref() => {
429+
tracing::warn!("descending from {:?} to {:?}", ty.kind(), inner_ty.kind());
430+
ty = *inner_ty;
431+
let temp = self.temp(ty, source_info.span);
432+
self.cfg.push_assign(
433+
block,
434+
source_info,
435+
temp,
436+
Rvalue::Use(Operand::Copy(val)),
437+
);
438+
val = temp;
439+
}
440+
_=> break,
441+
}
442+
}
443+
444+
(ty, val)
445+
};
446+
447+
(ty, val) = normalize_depth(ty, val);
390448

391449
// If we're using `b"..."` as a pattern, we need to insert an
392450
// unsizing coercion, as the byte string has the type `&[u8; N]`.

0 commit comments

Comments
 (0)