Skip to content

Commit 26fe550

Browse files
committed
normalization change and rebase
1 parent 8a811a1 commit 26fe550

File tree

49 files changed

+290
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+290
-344
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ dependencies = [
311311

312312
[[package]]
313313
name = "cargo"
314-
version = "0.61.0"
314+
version = "0.62.0"
315315
dependencies = [
316316
"anyhow",
317317
"atty",

compiler/rustc_const_eval/src/interpret/eval_context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub enum StackPopCleanup {
164164
}
165165

166166
/// State of a local variable including a memoized layout
167-
#[derive(Clone, PartialEq, Eq, HashStable)]
167+
#[derive(Clone, Debug, PartialEq, Eq, HashStable)]
168168
pub struct LocalState<'tcx, Tag: Provenance = AllocId> {
169169
pub value: LocalValue<Tag>,
170170
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
@@ -714,13 +714,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
714714
self.size_and_align_of(&mplace.meta, &mplace.layout)
715715
}
716716

717+
#[instrument(skip(self, body, return_place, return_to_block), level = "debug")]
717718
pub fn push_stack_frame(
718719
&mut self,
719720
instance: ty::Instance<'tcx>,
720721
body: &'mir mir::Body<'tcx>,
721722
return_place: Option<&PlaceTy<'tcx, M::PointerTag>>,
722723
return_to_block: StackPopCleanup,
723724
) -> InterpResult<'tcx> {
725+
debug!("body: {:#?}", body);
724726
// first push a stack frame so we have access to the local substs
725727
let pre_frame = Frame {
726728
body,
@@ -824,6 +826,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
824826
/// `Drop` impls for any locals that have been initialized at this point.
825827
/// The cleanup block ends with a special `Resume` terminator, which will
826828
/// cause us to continue unwinding.
829+
#[instrument(skip(self), level = "debug")]
827830
pub(super) fn pop_stack_frame(&mut self, unwinding: bool) -> InterpResult<'tcx> {
828831
info!(
829832
"popping stack frame ({})",
@@ -876,6 +879,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
876879
return Ok(());
877880
}
878881

882+
debug!("locals: {:#?}", frame.locals);
883+
879884
// Cleanup: deallocate all locals that are backed by an allocation.
880885
for local in &frame.locals {
881886
self.deallocate_local(local.value)?;
@@ -935,6 +940,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
935940
Ok(())
936941
}
937942

943+
#[instrument(skip(self), level = "debug")]
938944
fn deallocate_local(&mut self, local: LocalValue<M::PointerTag>) -> InterpResult<'tcx> {
939945
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
940946
// All locals have a backing allocation, even if the allocation is empty

compiler/rustc_const_eval/src/interpret/intern.rs

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ pub fn intern_const_alloc_recursive<
359359
// pointers, ... So we can't intern them according to their type rules
360360

361361
let mut todo: Vec<_> = leftover_allocations.iter().cloned().collect();
362+
debug!(?todo);
363+
debug!("dead_alloc_map: {:#?}", ecx.memory.dead_alloc_map);
362364
while let Some(alloc_id) = todo.pop() {
363365
if let Some((_, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) {
364366
// We can't call the `intern_shallow` method here, as its logic is tailored to safe

compiler/rustc_const_eval/src/interpret/memory.rs

+3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
275275
Ok(new_ptr)
276276
}
277277

278+
#[instrument(skip(self), level = "debug")]
278279
pub fn deallocate(
279280
&mut self,
280281
ptr: Pointer<Option<M::PointerTag>>,
@@ -305,6 +306,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
305306
.into());
306307
};
307308

309+
debug!(?alloc);
310+
308311
if alloc.mutability == Mutability::Not {
309312
throw_ub_format!("deallocating immutable allocation {}", alloc_id);
310313
}

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
336336
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
337337
let constant_kind = match constant {
338338
mir::ConstantKind::Ty(c) => {
339-
let const_folded = c.try_super_fold_with(self)?;
339+
let const_folded = c.try_fold_with(self)?;
340340
match const_folded.val() {
341341
ty::ConstKind::Value(cv) => {
342342
// FIXME With Valtrees we need to convert `cv: ValTree`

src/test/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir

+16-16
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,44 @@ fn main() -> () {
2121
}
2222

2323
alloc1 (static: FOO, size: 16, align: 8) {
24-
╾───────alloc22───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
24+
╾───────alloc28───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
2525
}
2626

27-
alloc22 (size: 72, align: 8) {
28-
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc9────────╼ │ ....░░░░╾──────╼
27+
alloc28 (size: 72, align: 8) {
28+
0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc13───────╼ │ ....░░░░╾──────╼
2929
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
30-
0x20 │ ╾───────alloc14───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
31-
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc20───────╼ │ ....*...╾──────╼
30+
0x20 │ ╾───────alloc18───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
31+
0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc26───────╼ │ ....*...╾──────╼
3232
0x40 │ 03 00 00 00 00 00 00 00 │ ........
3333
}
3434

35-
alloc9 (size: 0, align: 8) {}
35+
alloc13 (size: 0, align: 8) {}
3636

37-
alloc14 (size: 16, align: 8) {
38-
╾───────alloc12───────╼ ╾───────alloc13───────╼ │ ╾──────╼╾──────╼
37+
alloc18 (size: 16, align: 8) {
38+
╾───────alloc16───────╼ ╾───────alloc17───────╼ │ ╾──────╼╾──────╼
3939
}
4040

41-
alloc12 (size: 1, align: 1) {
41+
alloc16 (size: 1, align: 1) {
4242
05 │ .
4343
}
4444

45-
alloc13 (size: 1, align: 1) {
45+
alloc17 (size: 1, align: 1) {
4646
06 │ .
4747
}
4848

49-
alloc20 (size: 24, align: 8) {
50-
0x00 │ ╾─────alloc17+0x3─────╼ ╾───────alloc18───────╼ │ ╾──────╼╾──────╼
51-
0x10 │ ╾─────alloc19+0x2─────╼ │ ╾──────╼
49+
alloc26 (size: 24, align: 8) {
50+
0x00 │ ╾─────alloc22+0x3─────╼ ╾───────alloc23───────╼ │ ╾──────╼╾──────╼
51+
0x10 │ ╾─────alloc25+0x2─────╼ │ ╾──────╼
5252
}
5353

54-
alloc17 (size: 4, align: 1) {
54+
alloc22 (size: 4, align: 1) {
5555
2a 45 15 6f │ *E.o
5656
}
5757

58-
alloc18 (size: 1, align: 1) {
58+
alloc23 (size: 1, align: 1) {
5959
2a │ *
6060
}
6161

62-
alloc19 (size: 4, align: 1) {
62+
alloc25 (size: 4, align: 1) {
6363
2a 45 15 6f │ *E.o
6464
}

src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- _2 = transmute::<&str, &[u8]>(move _8) -> bb14; // scope 2 at $SRC_DIR/core/src/str/mod.rs:LL:COL
2727
+ _2 = transmute::<&str, &[u8]>(move _8) -> bb12; // scope 2 at $SRC_DIR/core/src/str/mod.rs:LL:COL
2828
// mir::Constant
29-
// + span: $DIR/deduplicate_blocks.rs:3:11: 3:23
29+
// + span: $SRC_DIR/core/src/str/mod.rs:LL:COL
3030
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&str) -> &[u8] {transmute::<&str, &[u8]>}, val: Value(Scalar(<ZST>)) }
3131
}
3232

src/test/mir-opt/inline/inline_diverging.g.Inline.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// mir::Constant
4040
- // + span: $DIR/inline-diverging.rs:16:9: 16:14
4141
- // + literal: Const { ty: fn() -> ! {panic}, val: Value(Scalar(<ZST>)) }
42-
+ // + span: $DIR/inline-diverging.rs:16:9: 16:16
42+
+ // + span: $SRC_DIR/std/src/panic.rs:LL:COL
4343
+ // + literal: Const { ty: fn(&str) -> ! {begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
4444
+ // mir::Constant
4545
+ // + span: $SRC_DIR/std/src/panic.rs:LL:COL

src/test/mir-opt/inline/inline_generator.main.Inline.diff

-8
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@
5050
- // mir::Constant
5151
- // + span: $DIR/inline-generator.rs:9:14: 9:22
5252
- // + user_ty: UserType(0)
53-
<<<<<<< HEAD
54-
- // + literal: Const { ty: fn(&mut impl Generator<bool>) -> Pin<&mut impl Generator<bool>> {Pin::<&mut impl Generator<bool>>::new}, val: Value(Scalar(<ZST>)) }
55-
=======
5653
- // + literal: Const { ty: fn(&mut [generator@$DIR/inline-generator.rs:15:5: 15:41]) -> Pin<&mut [generator@$DIR/inline-generator.rs:15:5: 15:41]> {Pin::<&mut [generator@$DIR/inline-generator.rs:15:5: 15:41]>::new}, val: Value(Scalar(<ZST>)) }
57-
>>>>>>> a4feb9af018 (bless tests)
5854
- }
5955
-
6056
- bb2: {
@@ -69,11 +65,7 @@
6965
- _1 = <[generator@$DIR/inline-generator.rs:15:5: 15:41] as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
7066
- // mir::Constant
7167
- // + span: $DIR/inline-generator.rs:9:33: 9:39
72-
<<<<<<< HEAD
73-
- // + literal: Const { ty: for<'r> fn(Pin<&'r mut impl Generator<bool>>, bool) -> GeneratorState<<impl Generator<bool> as Generator<bool>>::Yield, <impl Generator<bool> as Generator<bool>>::Return> {<impl Generator<bool> as Generator<bool>>::resume}, val: Value(Scalar(<ZST>)) }
74-
=======
7568
- // + literal: Const { ty: for<'r> fn(Pin<&'r mut [generator@$DIR/inline-generator.rs:15:5: 15:41]>, bool) -> GeneratorState<<[generator@$DIR/inline-generator.rs:15:5: 15:41] as Generator<bool>>::Yield, <[generator@$DIR/inline-generator.rs:15:5: 15:41] as Generator<bool>>::Return> {<[generator@$DIR/inline-generator.rs:15:5: 15:41] as Generator<bool>>::resume}, val: Value(Scalar(<ZST>)) }
76-
>>>>>>> a4feb9af018 (bless tests)
7769
+ StorageLive(_7); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
7870
+ _7 = const false; // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
7971
+ StorageLive(_10); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46

src/test/mir-opt/inline/inline_into_box_place.main.Inline.64bit.diff

-12
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@
3434
- (*_5) = Vec::<u32>::new() -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43
3535
+ StorageLive(_7); // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43
3636
+ _7 = &mut (*_5); // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43
37-
<<<<<<< HEAD
3837
+ ((*_7).0: alloc::raw_vec::RawVec<u32>) = const alloc::raw_vec::RawVec::<u32> { ptr: Unique::<u32> { pointer: {0x4 as *const u32}, _marker: PhantomData::<u32> }, cap: 0_usize, alloc: std::alloc::Global }; // scope 3 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
39-
=======
40-
+ ((*_7).0: alloc::raw_vec::RawVec<u32>) = const alloc::raw_vec::RawVec::<u32>::NEW; // scope 3 at $DIR/inline-into-box-place.rs:8:33: 8:43
41-
+ // ty::Const
42-
+ // + ty: alloc::raw_vec::RawVec<u32>
43-
+ // + val: Unevaluated(alloc::raw_vec::RawVec::<T>::NEW, [u32], None)
44-
>>>>>>> a4feb9af018 (bless tests)
4538
// mir::Constant
4639
- // + span: $DIR/inline-into-box-place.rs:8:33: 8:41
4740
- // + user_ty: UserType(1)
@@ -51,13 +44,8 @@
5144
- bb2: {
5245
+ // + span: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
5346
+ // + user_ty: UserType(0)
54-
<<<<<<< HEAD
5547
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [65535], len: Size { raw: 16 } }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
5648
+ ((*_7).1: usize) = const 0_usize; // scope 3 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
57-
=======
58-
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(5:77 ~ alloc[bd09]::raw_vec::{impl#0}::NEW), const_param_did: None }, substs: [u32], promoted: None }) }
59-
+ ((*_7).1: usize) = const 0_usize; // scope 3 at $DIR/inline-into-box-place.rs:8:33: 8:43
60-
>>>>>>> a4feb9af018 (bless tests)
6149
+ StorageDead(_7); // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43
6250
_1 = move _5; // scope 0 at $DIR/inline-into-box-place.rs:8:29: 8:43
6351
StorageDead(_5); // scope 0 at $DIR/inline-into-box-place.rs:8:42: 8:43

src/test/mir-opt/inline/issue_78442.bar.Inline.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
- // mir::Constant
3030
- // + span: $DIR/issue-78442.rs:11:5: 11:15
3131
- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(Scalar(<ZST>)) }
32-
+ _2 = move (*_3)() -> [return: bb5, unwind: bb3]; // scope 1 at $DIR/issue-78442.rs:11:5: 11:17
32+
+ _2 = move (*_3)() -> [return: bb5, unwind: bb3]; // scope 1 at $SRC_DIR/core/src/ops/function.rs:LL:COL
3333
}
3434

3535
bb2: {

src/test/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn num_to_digit(_1: char) -> u32 {
3838
_8 = _2; // scope 1 at $SRC_DIR/core/src/char/methods.rs:LL:COL
3939
_7 = char::methods::<impl char>::to_digit(move _8, const 8_u32) -> bb5; // scope 1 at $SRC_DIR/core/src/char/methods.rs:LL:COL
4040
// mir::Constant
41-
// + span: $DIR/issue-59352.rs:14:8: 14:23
41+
// + span: $SRC_DIR/core/src/char/methods.rs:LL:COL
4242
// + literal: Const { ty: fn(char, u32) -> Option<u32> {char::methods::<impl char>::to_digit}, val: Value(Scalar(<ZST>)) }
4343
}
4444

src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
_14 = &mut (*_8); // scope 5 at $SRC_DIR/core/src/iter/range.rs:LL:COL
5959
_7 = <std::ops::Range<i32> as iter::range::RangeIteratorImpl>::spec_next(move _14) -> bb4; // scope 5 at $SRC_DIR/core/src/iter/range.rs:LL:COL
6060
// mir::Constant
61-
// + span: $DIR/remove_storage_markers.rs:8:14: 8:19
61+
// + span: $SRC_DIR/core/src/iter/range.rs:LL:COL
6262
// + literal: Const { ty: for<'r> fn(&'r mut std::ops::Range<i32>) -> Option<<std::ops::Range<i32> as iter::range::RangeIteratorImpl>::Item> {<std::ops::Range<i32> as iter::range::RangeIteratorImpl>::spec_next}, val: Value(Scalar(<ZST>)) }
6363
}
6464

src/test/ui/associated-consts/defaults-cyclic-fail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// build-fail
2+
//~^ cycle detected when normalizing `<() as Tr>::A` [E0391]
23

34
// Cyclic assoc. const defaults don't error unless *used*
45
trait Tr {
56
const A: u8 = Self::B;
6-
//~^ ERROR cycle detected when const-evaluating + checking `Tr::A`
77

88
const B: u8 = Self::A;
99
}

src/test/ui/associated-consts/defaults-cyclic-fail.stderr

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
error[E0391]: cycle detected when const-evaluating + checking `Tr::A`
2-
--> $DIR/defaults-cyclic-fail.rs:5:5
1+
error[E0391]: cycle detected when normalizing `<() as Tr>::A`
2+
|
3+
note: ...which requires simplifying constant for the type system `Tr::A`...
4+
--> $DIR/defaults-cyclic-fail.rs:6:5
5+
|
6+
LL | const A: u8 = Self::B;
7+
| ^^^^^^^^^^^^^^^^^^^^^^
8+
note: ...which requires simplifying constant for the type system `Tr::A`...
9+
--> $DIR/defaults-cyclic-fail.rs:6:5
10+
|
11+
LL | const A: u8 = Self::B;
12+
| ^^^^^^^^^^^^^^^^^^^^^^
13+
note: ...which requires const-evaluating + checking `Tr::A`...
14+
--> $DIR/defaults-cyclic-fail.rs:6:5
315
|
416
LL | const A: u8 = Self::B;
517
| ^^^^^^^^^^^^^^^^^^^^^^
18+
= note: ...which requires normalizing `<() as Tr>::B`...
19+
note: ...which requires simplifying constant for the type system `Tr::B`...
20+
--> $DIR/defaults-cyclic-fail.rs:8:5
621
|
22+
LL | const B: u8 = Self::A;
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
note: ...which requires simplifying constant for the type system `Tr::B`...
25+
--> $DIR/defaults-cyclic-fail.rs:8:5
26+
|
27+
LL | const B: u8 = Self::A;
28+
| ^^^^^^^^^^^^^^^^^^^^^^
729
note: ...which requires const-evaluating + checking `Tr::B`...
830
--> $DIR/defaults-cyclic-fail.rs:8:5
931
|
1032
LL | const B: u8 = Self::A;
1133
| ^^^^^^^^^^^^^^^^^^^^^^
12-
= note: ...which again requires const-evaluating + checking `Tr::A`, completing the cycle
34+
= note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle
1335
note: cycle used when const-evaluating + checking `main::promoted[1]`
1436
--> $DIR/defaults-cyclic-fail.rs:14:1
1537
|

0 commit comments

Comments
 (0)