forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#109390 - cbeuw:aggregate-lit, r=oli-obk
Custom MIR: Support aggregate expressions Add support for tuple, array and ADT expressions in custom mir r? ```@oli-obk``` or ```@tmiasko``` or ```@JakobDegen```
- Loading branch information
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/mir-opt/building/custom/aggregate_exprs.adt.built.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// MIR for `adt` after built | ||
|
||
fn adt() -> Onion { | ||
let mut _0: Onion; // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:13: +0:18 | ||
let mut _1: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
let mut _2: Foo; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
let mut _3: Bar; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
|
||
bb0: { | ||
_1 = const 1_i32; // scope 0 at $DIR/aggregate_exprs.rs:+6:13: +6:20 | ||
_2 = Foo { a: const 1_i32, b: const 2_i32 }; // scope 0 at $DIR/aggregate_exprs.rs:+7:13: +10:14 | ||
_3 = Bar::Foo(move _2, _1); // scope 0 at $DIR/aggregate_exprs.rs:+11:13: +11:39 | ||
_0 = Onion { neon: ((_3 as variant#0).1: i32) }; // scope 0 at $DIR/aggregate_exprs.rs:+12:13: +12:58 | ||
return; // scope 0 at $DIR/aggregate_exprs.rs:+13:13: +13:21 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/mir-opt/building/custom/aggregate_exprs.array.built.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// MIR for `array` after built | ||
|
||
fn array() -> [i32; 2] { | ||
let mut _0: [i32; 2]; // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:15: +0:23 | ||
let mut _1: [i32; 2]; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
let mut _2: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
|
||
bb0: { | ||
_1 = [const 42_i32, const 43_i32]; // scope 0 at $DIR/aggregate_exprs.rs:+5:13: +5:25 | ||
_2 = const 1_i32; // scope 0 at $DIR/aggregate_exprs.rs:+6:13: +6:20 | ||
_1 = [_2, const 2_i32]; // scope 0 at $DIR/aggregate_exprs.rs:+7:13: +7:25 | ||
_0 = move _1; // scope 0 at $DIR/aggregate_exprs.rs:+8:13: +8:26 | ||
return; // scope 0 at $DIR/aggregate_exprs.rs:+9:13: +9:21 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#![feature(custom_mir, core_intrinsics)] | ||
|
||
extern crate core; | ||
use core::intrinsics::mir::*; | ||
|
||
// EMIT_MIR aggregate_exprs.tuple.built.after.mir | ||
#[custom_mir(dialect = "built")] | ||
fn tuple() -> (i32, bool) { | ||
mir!( | ||
{ | ||
RET = (1, true); | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
// EMIT_MIR aggregate_exprs.array.built.after.mir | ||
#[custom_mir(dialect = "built")] | ||
fn array() -> [i32; 2] { | ||
mir!( | ||
let x: [i32; 2]; | ||
let one: i32; | ||
{ | ||
x = [42, 43]; | ||
one = 1; | ||
x = [one, 2]; | ||
RET = Move(x); | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
struct Foo { | ||
a: i32, | ||
b: i32, | ||
} | ||
|
||
enum Bar { | ||
Foo(Foo, i32), | ||
} | ||
|
||
union Onion { | ||
neon: i32, | ||
noun: f32, | ||
} | ||
|
||
// EMIT_MIR aggregate_exprs.adt.built.after.mir | ||
#[custom_mir(dialect = "built")] | ||
fn adt() -> Onion { | ||
mir!( | ||
let one: i32; | ||
let x: Foo; | ||
let y: Bar; | ||
{ | ||
one = 1; | ||
x = Foo { | ||
a: 1, | ||
b: 2, | ||
}; | ||
y = Bar::Foo(Move(x), one); | ||
RET = Onion { neon: Field(Variant(y, 0), 1) }; | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
fn main() { | ||
assert_eq!(tuple(), (1, true)); | ||
assert_eq!(array(), [1, 2]); | ||
assert_eq!(unsafe { adt().neon }, 1); | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/mir-opt/building/custom/aggregate_exprs.tuple.built.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// MIR for `tuple` after built | ||
|
||
fn tuple() -> (i32, bool) { | ||
let mut _0: (i32, bool); // return place in scope 0 at $DIR/aggregate_exprs.rs:+0:15: +0:26 | ||
|
||
bb0: { | ||
_0 = (const 1_i32, const true); // scope 0 at $DIR/aggregate_exprs.rs:+3:13: +3:28 | ||
return; // scope 0 at $DIR/aggregate_exprs.rs:+4:13: +4:21 | ||
} | ||
} |