Skip to content

Commit 2c6f137

Browse files
committed
Add loop tests.
1 parent ae6f97c commit 2c6f137

6 files changed

+1585
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// MIR for `int_range` after PreCodegen
2+
3+
fn int_range(_1: usize, _2: usize) -> () {
4+
debug start => _1; // in scope 0 at $DIR/loops.rs:+0:18: +0:23
5+
debug end => _2; // in scope 0 at $DIR/loops.rs:+0:32: +0:35
6+
let mut _0: (); // return place in scope 0 at $DIR/loops.rs:+0:44: +0:44
7+
let mut _3: std::ops::Range<usize>; // in scope 0 at $DIR/loops.rs:+1:14: +1:24
8+
let mut _4: std::ops::Range<usize>; // in scope 0 at $DIR/loops.rs:+1:14: +1:24
9+
let mut _5: &mut std::ops::Range<usize>; // in scope 0 at $DIR/loops.rs:+1:14: +1:24
10+
let mut _6: std::option::Option<usize>; // in scope 0 at $DIR/loops.rs:+1:14: +1:24
11+
let mut _7: isize; // in scope 0 at $DIR/loops.rs:+1:5: +3:6
12+
let _9: (); // in scope 0 at $DIR/loops.rs:+1:14: +1:24
13+
scope 1 {
14+
debug iter => _4; // in scope 1 at $DIR/loops.rs:+1:14: +1:24
15+
let _8: usize; // in scope 1 at $DIR/loops.rs:+1:9: +1:10
16+
scope 2 {
17+
debug i => _8; // in scope 2 at $DIR/loops.rs:+1:9: +1:10
18+
}
19+
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) { // at $DIR/loops.rs:7:14: 7:24
20+
debug self => _5; // in scope 4 at $SRC_DIR/core/src/iter/range.rs:LL:COL
21+
}
22+
}
23+
scope 3 (inlined <std::ops::Range<usize> as IntoIterator>::into_iter) { // at $DIR/loops.rs:7:14: 7:24
24+
debug self => _3; // in scope 3 at $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
25+
}
26+
27+
bb0: {
28+
_3 = std::ops::Range::<usize> { start: _1, end: _2 }; // scope 0 at $DIR/loops.rs:+1:14: +1:24
29+
StorageLive(_4); // scope 0 at $DIR/loops.rs:+1:14: +1:24
30+
_4 = move _3; // scope 0 at $DIR/loops.rs:+1:14: +1:24
31+
goto -> bb1; // scope 1 at $DIR/loops.rs:+1:5: +3:6
32+
}
33+
34+
bb1: {
35+
StorageLive(_6); // scope 1 at $DIR/loops.rs:+1:14: +1:24
36+
_5 = &mut _4; // scope 1 at $DIR/loops.rs:+1:14: +1:24
37+
_6 = <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next(_5) -> bb2; // scope 4 at $SRC_DIR/core/src/iter/range.rs:LL:COL
38+
// mir::Constant
39+
// + span: $SRC_DIR/core/src/iter/range.rs:LL:COL
40+
// + literal: Const { ty: for<'a> fn(&'a mut std::ops::Range<usize>) -> Option<<std::ops::Range<usize> as iter::range::RangeIteratorImpl>::Item> {<std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next}, val: Value(<ZST>) }
41+
}
42+
43+
bb2: {
44+
_7 = discriminant(_6); // scope 1 at $DIR/loops.rs:+1:14: +1:24
45+
switchInt(move _7) -> [0: bb3, 1: bb4, otherwise: bb6]; // scope 1 at $DIR/loops.rs:+1:14: +1:24
46+
}
47+
48+
bb3: {
49+
StorageDead(_6); // scope 1 at $DIR/loops.rs:+3:5: +3:6
50+
StorageDead(_4); // scope 0 at $DIR/loops.rs:+3:5: +3:6
51+
return; // scope 0 at $DIR/loops.rs:+4:2: +4:2
52+
}
53+
54+
bb4: {
55+
_8 = ((_6 as Some).0: usize); // scope 1 at $DIR/loops.rs:+1:9: +1:10
56+
_9 = opaque::<usize>(_8) -> bb5; // scope 2 at $DIR/loops.rs:+2:9: +2:18
57+
// mir::Constant
58+
// + span: $DIR/loops.rs:8:9: 8:15
59+
// + literal: Const { ty: fn(usize) {opaque::<usize>}, val: Value(<ZST>) }
60+
}
61+
62+
bb5: {
63+
StorageDead(_6); // scope 1 at $DIR/loops.rs:+3:5: +3:6
64+
goto -> bb1; // scope 1 at $DIR/loops.rs:+1:5: +3:6
65+
}
66+
67+
bb6: {
68+
unreachable; // scope 1 at $DIR/loops.rs:+1:14: +1:24
69+
}
70+
}

tests/mir-opt/pre-codegen/loops.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// compile-flags: -O -Zmir-opt-level=2 -g
2+
// ignore-debug
3+
4+
#![crate_type = "lib"]
5+
6+
pub fn int_range(start: usize, end: usize) {
7+
for i in start..end {
8+
opaque(i)
9+
}
10+
}
11+
12+
pub fn vec_range(mut v: Vec<impl Sized>) {
13+
for i in 0..v.len() {
14+
let x = &mut v[i];
15+
opaque((i, x))
16+
}
17+
for i in 0..v.len() {
18+
let x = &v[i];
19+
opaque((i, x))
20+
}
21+
}
22+
23+
pub fn vec_iter(mut v: Vec<impl Sized>) {
24+
for x in v.iter_mut() {
25+
opaque(x)
26+
}
27+
for x in v.iter() {
28+
opaque(x)
29+
}
30+
}
31+
32+
pub fn vec_iter_enumerate(mut v: Vec<impl Sized>) {
33+
for (i, x) in v.iter_mut().enumerate() {
34+
opaque((i, x))
35+
}
36+
for (i, x) in v.iter().enumerate() {
37+
opaque((i, x))
38+
}
39+
}
40+
41+
pub fn vec_move(mut v: Vec<impl Sized>) {
42+
for x in v {
43+
opaque(x)
44+
}
45+
}
46+
47+
#[inline(never)]
48+
fn opaque(_: impl Sized) {}
49+
50+
// EMIT_MIR loops.int_range.PreCodegen.after.mir
51+
// EMIT_MIR loops.vec_range.PreCodegen.after.mir
52+
// EMIT_MIR loops.vec_iter.PreCodegen.after.mir
53+
// EMIT_MIR loops.vec_iter_enumerate.PreCodegen.after.mir
54+
// EMIT_MIR loops.vec_move.PreCodegen.after.mir

0 commit comments

Comments
 (0)