Skip to content

Commit 34d14e7

Browse files
authored
Auto merge of #34096 - eddyb:launch, r=nikomatsakis
Switch to MIR-based translation by default. This patch makes `-Z orbit` default to "on", which means that by default, functions will be translated from Rust to LLVM IR through the upcoming MIR backend, instead of the antiquated AST backend. This switch is made possible by the recently merged #33622, #33905 and smaller fixes. If you experience any issues, please file a report for each of them. You can switch to the old backend to work around problems by either setting `RUSTFLAGS="-Zorbit=off"` or by annotating specific functions with `#[rustc_no_mir]` (which requires `#![feature(rustc_attrs)]` at the crate-level). I would like this PR to get into nightly soon so that we can get early feedback in this release cycle and focus on correctness fixes and performance improvements, with the potential for removing the old backend implementation before beta branches off. cc @rust-lang/compiler
2 parents 19765f2 + b583711 commit 34d14e7

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
lines changed

configure

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ opt dist-host-only 0 "only install bins for the host architecture"
609609
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
610610
opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
611611
opt rustbuild 0 "use the rust and cargo based build system"
612-
opt orbit 0 "get MIR where it belongs - everywhere; most importantly, in orbit"
612+
opt orbit 1 "get MIR where it belongs - everywhere; most importantly, in orbit"
613613
opt codegen-tests 1 "run the src/test/codegen tests"
614614
opt option-checking 1 "complain about unrecognized options in this configure script"
615615
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
@@ -733,7 +733,7 @@ if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTION
733733
if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
734734
if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
735735

736-
if [ -n "$CFG_ENABLE_ORBIT" ]; then putvar CFG_ENABLE_ORBIT; fi
736+
if [ -n "$CFG_DISABLE_ORBIT" ]; then putvar CFG_DISABLE_ORBIT; fi
737737

738738
step_msg "looking for build programs"
739739

mk/main.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ ifdef CFG_ENABLE_DEBUGINFO
162162
CFG_RUSTC_FLAGS += -g
163163
endif
164164

165-
ifdef CFG_ENABLE_ORBIT
166-
$(info cfg: launching MIR (CFG_ENABLE_ORBIT))
167-
CFG_RUSTC_FLAGS += -Z orbit
165+
ifdef CFG_DISABLE_ORBIT
166+
$(info cfg: HOLD HOLD HOLD (CFG_DISABLE_ORBIT))
167+
CFG_RUSTC_FLAGS += -Z orbit=off
168168
endif
169169

170170
ifdef SAVE_TEMPS

src/doc/book/lang-items.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For example, `Box` pointers require two lang items, one for allocation
1515
and one for deallocation. A freestanding program that uses the `Box`
1616
sugar for dynamic allocations via `malloc` and `free`:
1717

18-
```rust
18+
```rust,ignore
1919
#![feature(lang_items, box_syntax, start, libc)]
2020
#![no_std]
2121

src/librustc/session/config.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ macro_rules! options {
463463
pub const parse_bool: Option<&'static str> = None;
464464
pub const parse_opt_bool: Option<&'static str> =
465465
Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
466+
pub const parse_all_bool: Option<&'static str> =
467+
Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
466468
pub const parse_string: Option<&'static str> = Some("a string");
467469
pub const parse_opt_string: Option<&'static str> = Some("a string");
468470
pub const parse_list: Option<&'static str> = Some("a space-separated list of strings");
@@ -512,6 +514,25 @@ macro_rules! options {
512514
}
513515
}
514516

517+
fn parse_all_bool(slot: &mut bool, v: Option<&str>) -> bool {
518+
match v {
519+
Some(s) => {
520+
match s {
521+
"n" | "no" | "off" => {
522+
*slot = false;
523+
}
524+
"y" | "yes" | "on" => {
525+
*slot = true;
526+
}
527+
_ => { return false; }
528+
}
529+
530+
true
531+
},
532+
None => { *slot = true; true }
533+
}
534+
}
535+
515536
fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
516537
match v {
517538
Some(s) => { *slot = Some(s.to_string()); true },
@@ -756,7 +777,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
756777
"dump MIR state at various points in translation"),
757778
dump_mir_dir: Option<String> = (None, parse_opt_string,
758779
"the directory the MIR is dumped into"),
759-
orbit: bool = (false, parse_bool,
780+
orbit: bool = (true, parse_all_bool,
760781
"get MIR where it belongs - everywhere; most importantly, in orbit"),
761782
}
762783

src/librustc_trans/mir/rvalue.rs

+33-25
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,46 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
244244
}
245245
}
246246
}
247-
mir::CastKind::Misc if common::type_is_immediate(bcx.ccx(), operand.ty) => {
247+
mir::CastKind::Misc if common::type_is_fat_ptr(bcx.tcx(), operand.ty) => {
248+
let ll_cast_ty = type_of::immediate_type_of(bcx.ccx(), cast_ty);
249+
let ll_from_ty = type_of::immediate_type_of(bcx.ccx(), operand.ty);
250+
if let OperandValue::Pair(data_ptr, meta_ptr) = operand.val {
251+
if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
252+
let ll_cft = ll_cast_ty.field_types();
253+
let ll_fft = ll_from_ty.field_types();
254+
let data_cast = bcx.pointercast(data_ptr, ll_cft[0]);
255+
assert_eq!(ll_cft[1].kind(), ll_fft[1].kind());
256+
OperandValue::Pair(data_cast, meta_ptr)
257+
} else { // cast to thin-ptr
258+
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
259+
// pointer-cast of that pointer to desired pointer type.
260+
let llval = bcx.pointercast(data_ptr, ll_cast_ty);
261+
OperandValue::Immediate(llval)
262+
}
263+
} else {
264+
bug!("Unexpected non-Pair operand")
265+
}
266+
}
267+
mir::CastKind::Misc => {
248268
debug_assert!(common::type_is_immediate(bcx.ccx(), cast_ty));
249269
let r_t_in = CastTy::from_ty(operand.ty).expect("bad input type for cast");
250270
let r_t_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
251271
let ll_t_in = type_of::immediate_type_of(bcx.ccx(), operand.ty);
252272
let ll_t_out = type_of::immediate_type_of(bcx.ccx(), cast_ty);
253-
let llval = operand.immediate();
254-
let signed = if let CastTy::Int(IntTy::CEnum) = r_t_in {
273+
let (llval, signed) = if let CastTy::Int(IntTy::CEnum) = r_t_in {
255274
let repr = adt::represent_type(bcx.ccx(), operand.ty);
256-
adt::is_discr_signed(&repr)
275+
let discr = match operand.val {
276+
OperandValue::Immediate(llval) => llval,
277+
OperandValue::Ref(llptr) => {
278+
bcx.with_block(|bcx| {
279+
adt::trans_get_discr(bcx, &repr, llptr, None, true)
280+
})
281+
}
282+
OperandValue::Pair(..) => bug!("Unexpected Pair operand")
283+
};
284+
(discr, adt::is_discr_signed(&repr))
257285
} else {
258-
operand.ty.is_signed()
286+
(operand.immediate(), operand.ty.is_signed())
259287
};
260288

261289
let newval = match (r_t_in, r_t_out) {
@@ -304,26 +332,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
304332
};
305333
OperandValue::Immediate(newval)
306334
}
307-
mir::CastKind::Misc => { // Casts from a fat-ptr.
308-
let ll_cast_ty = type_of::immediate_type_of(bcx.ccx(), cast_ty);
309-
let ll_from_ty = type_of::immediate_type_of(bcx.ccx(), operand.ty);
310-
if let OperandValue::Pair(data_ptr, meta_ptr) = operand.val {
311-
if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
312-
let ll_cft = ll_cast_ty.field_types();
313-
let ll_fft = ll_from_ty.field_types();
314-
let data_cast = bcx.pointercast(data_ptr, ll_cft[0]);
315-
assert_eq!(ll_cft[1].kind(), ll_fft[1].kind());
316-
OperandValue::Pair(data_cast, meta_ptr)
317-
} else { // cast to thin-ptr
318-
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
319-
// pointer-cast of that pointer to desired pointer type.
320-
let llval = bcx.pointercast(data_ptr, ll_cast_ty);
321-
OperandValue::Immediate(llval)
322-
}
323-
} else {
324-
bug!("Unexpected non-Pair operand")
325-
}
326-
}
327335
};
328336
let operand = OperandRef {
329337
val: val,

src/test/run-pass/issue-14936.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ macro_rules! demo {
2828
unsafe {
2929
asm!("mov ($1), $0"
3030
: $output_constraint (*wrap(&mut x, "out", &mut history))
31-
: "r"(&wrap(y, "in", &mut history)));
31+
: "r"(&wrap(y, "in", &mut history))
32+
:: "volatile");
3233
}
3334
assert_eq!((x,y), (1,1));
3435
let b: &[_] = &["out", "in"];

src/test/run-pass/issue-28950.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z orbit=off
12+
// (blows the stack with MIR trans and no optimizations)
13+
1114
// Tests that the `vec!` macro does not overflow the stack when it is
1215
// given data larger than the stack.
1316

0 commit comments

Comments
 (0)