-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #30890 - nagisa:mir-tuple-adts, r=nikomatsakis
This PR changes translation of tuple-like ADTs from being calls to being proper aggregates. This change is done in hope to make code generation better. Namely, now we can avoid: 1. Call overhead; 2. Generating landingpads in presence of cleanups (we know for sure constructing ADTs can’t panic); 3. And probably much more, gaining better MIR introspectablilty. Along with that a few serious deficiencies with translation of ADTs and switches have been fixed as well (commits 2 and 3). r? @nikomatsakis cc @tsion
- Loading branch information
Showing
5 changed files
with
152 additions
and
22 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[repr(C, u32)] | ||
enum CEnum { | ||
Hello = 30, | ||
World = 60 | ||
} | ||
|
||
#[rustc_mir] | ||
fn test1(c: CEnum) -> i32 { | ||
let c2 = CEnum::Hello; | ||
match (c, c2) { | ||
(CEnum::Hello, CEnum::Hello) => 42, | ||
(CEnum::World, CEnum::Hello) => 0, | ||
_ => 1 | ||
} | ||
} | ||
|
||
#[repr(packed)] | ||
#[derive(PartialEq, Debug)] | ||
struct Pakd { | ||
a: u64, | ||
b: u32, | ||
c: u16, | ||
d: u8, | ||
e: () | ||
} | ||
|
||
impl Drop for Pakd { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
#[rustc_mir] | ||
fn test2() -> Pakd { | ||
Pakd { a: 42, b: 42, c: 42, d: 42, e: () } | ||
} | ||
|
||
#[derive(PartialEq, Debug)] | ||
struct TupleLike(u64, u32); | ||
|
||
#[rustc_mir] | ||
fn test3() -> TupleLike { | ||
TupleLike(42, 42) | ||
} | ||
|
||
#[rustc_mir] | ||
fn test4(x: fn(u64, u32) -> TupleLike) -> (TupleLike, TupleLike) { | ||
let y = TupleLike; | ||
(x(42, 84), y(42, 84)) | ||
} | ||
|
||
#[rustc_mir] | ||
fn test5(x: fn(u32) -> Option<u32>) -> (Option<u32>, Option<u32>) { | ||
let y = Some; | ||
(x(42), y(42)) | ||
} | ||
|
||
fn main() { | ||
assert_eq!(test1(CEnum::Hello), 42); | ||
assert_eq!(test1(CEnum::World), 0); | ||
assert_eq!(test2(), Pakd { a: 42, b: 42, c: 42, d: 42, e: () }); | ||
assert_eq!(test3(), TupleLike(42, 42)); | ||
let t4 = test4(TupleLike); | ||
assert_eq!(t4.0, t4.1); | ||
let t5 = test5(Some); | ||
assert_eq!(t5.0, t5.1); | ||
} |
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