Skip to content

Commit 1ac22a5

Browse files
committed
---
yaml --- r: 274685 b: refs/heads/stable c: fc1c118 h: refs/heads/master i: 274683: 43f1b9d
1 parent 6182ab5 commit 1ac22a5

File tree

22 files changed

+530
-363
lines changed

22 files changed

+530
-363
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: e22770beeb30f8ca04ab74ecd56ee56dcc2a234e
32+
refs/heads/stable: fc1c1183f32810a5b61ee9ee27a5683f14737994
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/libcollections/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
2727
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
2828

29-
#![allow(trivial_casts)]
3029
#![cfg_attr(test, allow(deprecated))] // rand
3130
#![cfg_attr(not(stage0), deny(warnings))]
3231

branches/stable/src/libcollections/string.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,15 @@ impl String {
479479
}
480480
}
481481

482-
/// Converts a slice of bytes to a `String`, including invalid characters.
482+
/// Converts a slice of bytes to a string, including invalid characters.
483483
///
484-
/// A string slice ([`&str`]) is made of bytes ([`u8`]), and a slice of
485-
/// bytes ([`&[u8]`][byteslice]) is made of bytes, so this function converts between
486-
/// the two. Not all byte slices are valid string slices, however: [`&str`]
487-
/// requires that it is valid UTF-8. During this conversion,
484+
/// Strings are made of bytes ([`u8`]), and a slice of bytes
485+
/// ([`&[u8]`][byteslice]) is made of bytes, so this function converts
486+
/// between the two. Not all byte slices are valid strings, however: strings
487+
/// are required to be valid UTF-8. During this conversion,
488488
/// `from_utf8_lossy()` will replace any invalid UTF-8 sequences with
489489
/// `U+FFFD REPLACEMENT CHARACTER`, which looks like this: �
490490
///
491-
/// [`&str`]: ../primitive.str.html
492491
/// [`u8`]: ../primitive.u8.html
493492
/// [byteslice]: ../primitive.slice.html
494493
///
@@ -499,10 +498,13 @@ impl String {
499498
///
500499
/// [`from_utf8_unchecked()`]: struct.String.html#method.from_utf8_unchecked
501500
///
502-
/// If you need a [`&str`] instead of a `String`, consider
503-
/// [`str::from_utf8()`].
501+
/// This function returns a [`Cow<'a, str>`]. If our byte slice is invalid
502+
/// UTF-8, then we need to insert the replacement characters, which will
503+
/// change the size of the string, and hence, require a `String`. But if
504+
/// it's already valid UTF-8, we don't need a new allocation. This return
505+
/// type allows us to handle both cases.
504506
///
505-
/// [`str::from_utf8()`]: ../str/fn.from_utf8.html
507+
/// [`Cow<'a, str>`]: ../borrow/enum.Cow.html
506508
///
507509
/// # Examples
508510
///
@@ -512,8 +514,7 @@ impl String {
512514
/// // some bytes, in a vector
513515
/// let sparkle_heart = vec![240, 159, 146, 150];
514516
///
515-
/// // We know these bytes are valid, so we'll use `unwrap()`.
516-
/// let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
517+
/// let sparkle_heart = String::from_utf8_lossy(&sparkle_heart);
517518
///
518519
/// assert_eq!("💖", sparkle_heart);
519520
/// ```

branches/stable/src/libcore/fmt/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,26 +1414,20 @@ impl<T> Pointer for *const T {
14141414
#[stable(feature = "rust1", since = "1.0.0")]
14151415
impl<T> Pointer for *mut T {
14161416
fn fmt(&self, f: &mut Formatter) -> Result {
1417-
// FIXME(#23542) Replace with type ascription.
1418-
#![allow(trivial_casts)]
14191417
Pointer::fmt(&(*self as *const T), f)
14201418
}
14211419
}
14221420

14231421
#[stable(feature = "rust1", since = "1.0.0")]
14241422
impl<'a, T> Pointer for &'a T {
14251423
fn fmt(&self, f: &mut Formatter) -> Result {
1426-
// FIXME(#23542) Replace with type ascription.
1427-
#![allow(trivial_casts)]
14281424
Pointer::fmt(&(*self as *const T), f)
14291425
}
14301426
}
14311427

14321428
#[stable(feature = "rust1", since = "1.0.0")]
14331429
impl<'a, T> Pointer for &'a mut T {
14341430
fn fmt(&self, f: &mut Formatter) -> Result {
1435-
// FIXME(#23542) Replace with type ascription.
1436-
#![allow(trivial_casts)]
14371431
Pointer::fmt(&(&**self as *const T), f)
14381432
}
14391433
}

branches/stable/src/libcore/mem.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,5 @@ pub const POST_DROP_USIZE: usize = POST_DROP_U64 as usize;
578578
#[inline]
579579
#[stable(feature = "rust1", since = "1.0.0")]
580580
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
581-
// FIXME(#23542) Replace with type ascription.
582-
#![allow(trivial_casts)]
583581
ptr::read(src as *const T as *const U)
584582
}

branches/stable/src/librustc/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
#![feature(time2)]
4444
#![cfg_attr(test, feature(test))]
4545

46-
#![allow(trivial_casts)]
47-
4846
extern crate arena;
4947
extern crate core;
5048
extern crate flate;

branches/stable/src/librustc_llvm/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![allow(non_camel_case_types)]
1313
#![allow(non_snake_case)]
1414
#![allow(dead_code)]
15-
#![allow(trivial_casts)]
1615

1716
#![crate_name = "rustc_llvm"]
1817
#![unstable(feature = "rustc_private", issue = "27812")]

branches/stable/src/librustc_trans/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#![feature(staged_api)]
3838
#![feature(unicode)]
3939

40-
#![allow(trivial_casts)]
41-
4240
extern crate arena;
4341
extern crate flate;
4442
extern crate getopts;

branches/stable/src/librustc_trans/trans/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ pub fn wants_msvc_seh(sess: &Session) -> bool {
988988
}
989989

990990
pub fn avoid_invoke(bcx: Block) -> bool {
991-
bcx.sess().no_landing_pads() || bcx.lpad.borrow().is_some()
991+
bcx.sess().no_landing_pads() || bcx.lpad().is_some()
992992
}
993993

994994
pub fn need_invoke(bcx: Block) -> bool {
@@ -1616,6 +1616,7 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
16161616
param_substs: param_substs,
16171617
span: sp,
16181618
block_arena: block_arena,
1619+
lpad_arena: TypedArena::new(),
16191620
ccx: ccx,
16201621
debug_context: debug_context,
16211622
scopes: RefCell::new(Vec::new()),
@@ -2003,7 +2004,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
20032004
let mut bcx = init_function(&fcx, false, output_type);
20042005

20052006
if attributes.iter().any(|item| item.check_name("rustc_mir")) {
2006-
mir::trans_mir(bcx);
2007+
mir::trans_mir(bcx.build());
20072008
fcx.cleanup();
20082009
return;
20092010
}

branches/stable/src/librustc_trans/trans/build.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ pub fn Invoke(cx: Block,
150150
cx.val_to_string(fn_),
151151
args.iter().map(|a| cx.val_to_string(*a)).collect::<Vec<String>>().join(", "));
152152
debug_loc.apply(cx.fcx);
153-
let lpad = cx.lpad.borrow();
154-
let bundle = lpad.as_ref().and_then(|b| b.bundle());
153+
let bundle = cx.lpad().and_then(|b| b.bundle());
155154
B(cx).invoke(fn_, args, then, catch, bundle, attributes)
156155
}
157156

@@ -916,8 +915,7 @@ pub fn Call(cx: Block,
916915
return _UndefReturn(cx, fn_);
917916
}
918917
debug_loc.apply(cx.fcx);
919-
let lpad = cx.lpad.borrow();
920-
let bundle = lpad.as_ref().and_then(|b| b.bundle());
918+
let bundle = cx.lpad.get().and_then(|b| b.bundle());
921919
B(cx).call(fn_, args, bundle, attributes)
922920
}
923921

@@ -932,8 +930,7 @@ pub fn CallWithConv(cx: Block,
932930
return _UndefReturn(cx, fn_);
933931
}
934932
debug_loc.apply(cx.fcx);
935-
let lpad = cx.lpad.borrow();
936-
let bundle = lpad.as_ref().and_then(|b| b.bundle());
933+
let bundle = cx.lpad.get().and_then(|b| b.bundle());
937934
B(cx).call_with_conv(fn_, args, conv, bundle, attributes)
938935
}
939936

branches/stable/src/librustc_trans/trans/cleanup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,11 @@ impl EarlyExitLabel {
10541054
match *self {
10551055
UnwindExit(UnwindKind::CleanupPad(..)) => {
10561056
let pad = build::CleanupPad(bcx, None, &[]);
1057-
*bcx.lpad.borrow_mut() = Some(LandingPad::msvc(pad));
1057+
bcx.lpad.set(Some(bcx.fcx.lpad_arena.alloc(LandingPad::msvc(pad))));
10581058
UnwindExit(UnwindKind::CleanupPad(pad))
10591059
}
10601060
UnwindExit(UnwindKind::LandingPad) => {
1061-
*bcx.lpad.borrow_mut() = Some(LandingPad::gnu());
1061+
bcx.lpad.set(Some(bcx.fcx.lpad_arena.alloc(LandingPad::gnu())));
10621062
*self
10631063
}
10641064
label => label,

branches/stable/src/librustc_trans/trans/common.rs

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use middle::lang_items::LangItem;
2626
use middle::subst::{self, Substs};
2727
use trans::base;
2828
use trans::build;
29+
use trans::builder::Builder;
2930
use trans::callee;
3031
use trans::cleanup;
3132
use trans::consts;
@@ -45,6 +46,7 @@ use util::nodemap::{FnvHashMap, NodeMap};
4546

4647
use arena::TypedArena;
4748
use libc::{c_uint, c_char};
49+
use std::ops::Deref;
4850
use std::ffi::CString;
4951
use std::cell::{Cell, RefCell};
5052
use std::vec::Vec;
@@ -365,6 +367,9 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
365367
// The arena that blocks are allocated from.
366368
pub block_arena: &'a TypedArena<BlockS<'a, 'tcx>>,
367369

370+
// The arena that landing pads are allocated from.
371+
pub lpad_arena: TypedArena<LandingPad>,
372+
368373
// This function's enclosing crate context.
369374
pub ccx: &'a CrateContext<'a, 'tcx>,
370375

@@ -582,7 +587,7 @@ pub struct BlockS<'blk, 'tcx: 'blk> {
582587

583588
// If this block part of a landing pad, then this is `Some` indicating what
584589
// kind of landing pad its in, otherwise this is none.
585-
pub lpad: RefCell<Option<LandingPad>>,
590+
pub lpad: Cell<Option<&'blk LandingPad>>,
586591

587592
// AST node-id associated with this block, if any. Used for
588593
// debugging purposes only.
@@ -604,7 +609,7 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
604609
llbb: llbb,
605610
terminated: Cell::new(false),
606611
unreachable: Cell::new(false),
607-
lpad: RefCell::new(None),
612+
lpad: Cell::new(None),
608613
opt_node_id: opt_node_id,
609614
fcx: fcx
610615
})
@@ -613,11 +618,18 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
613618
pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> {
614619
self.fcx.ccx
615620
}
621+
pub fn fcx(&self) -> &'blk FunctionContext<'blk, 'tcx> {
622+
self.fcx
623+
}
616624
pub fn tcx(&self) -> &'blk ty::ctxt<'tcx> {
617625
self.fcx.ccx.tcx()
618626
}
619627
pub fn sess(&self) -> &'blk Session { self.fcx.ccx.sess() }
620628

629+
pub fn lpad(&self) -> Option<&'blk LandingPad> {
630+
self.lpad.get()
631+
}
632+
621633
pub fn mir(&self) -> &'blk Mir<'tcx> {
622634
self.fcx.mir()
623635
}
@@ -659,6 +671,109 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
659671
self.fcx.param_substs,
660672
value)
661673
}
674+
675+
pub fn build(&'blk self) -> BlockAndBuilder<'blk, 'tcx> {
676+
BlockAndBuilder::new(self, OwnedBuilder::new_with_ccx(self.ccx()))
677+
}
678+
}
679+
680+
pub struct OwnedBuilder<'blk, 'tcx: 'blk> {
681+
builder: Builder<'blk, 'tcx>
682+
}
683+
684+
impl<'blk, 'tcx> OwnedBuilder<'blk, 'tcx> {
685+
pub fn new_with_ccx(ccx: &'blk CrateContext<'blk, 'tcx>) -> Self {
686+
// Create a fresh builder from the crate context.
687+
let llbuilder = unsafe {
688+
llvm::LLVMCreateBuilderInContext(ccx.llcx())
689+
};
690+
OwnedBuilder {
691+
builder: Builder {
692+
llbuilder: llbuilder,
693+
ccx: ccx,
694+
}
695+
}
696+
}
697+
}
698+
699+
impl<'blk, 'tcx> Drop for OwnedBuilder<'blk, 'tcx> {
700+
fn drop(&mut self) {
701+
unsafe {
702+
llvm::LLVMDisposeBuilder(self.builder.llbuilder);
703+
}
704+
}
705+
}
706+
707+
pub struct BlockAndBuilder<'blk, 'tcx: 'blk> {
708+
bcx: Block<'blk, 'tcx>,
709+
owned_builder: OwnedBuilder<'blk, 'tcx>,
710+
}
711+
712+
impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
713+
pub fn new(bcx: Block<'blk, 'tcx>, owned_builder: OwnedBuilder<'blk, 'tcx>) -> Self {
714+
// Set the builder's position to this block's end.
715+
owned_builder.builder.position_at_end(bcx.llbb);
716+
BlockAndBuilder {
717+
bcx: bcx,
718+
owned_builder: owned_builder,
719+
}
720+
}
721+
722+
pub fn with_block<F, R>(&self, f: F) -> R
723+
where F: FnOnce(Block<'blk, 'tcx>) -> R
724+
{
725+
let result = f(self.bcx);
726+
self.position_at_end(self.bcx.llbb);
727+
result
728+
}
729+
730+
pub fn map_block<F>(self, f: F) -> Self
731+
where F: FnOnce(Block<'blk, 'tcx>) -> Block<'blk, 'tcx>
732+
{
733+
let BlockAndBuilder { bcx, owned_builder } = self;
734+
let bcx = f(bcx);
735+
BlockAndBuilder::new(bcx, owned_builder)
736+
}
737+
738+
// Methods delegated to bcx
739+
740+
pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> {
741+
self.bcx.ccx()
742+
}
743+
pub fn fcx(&self) -> &'blk FunctionContext<'blk, 'tcx> {
744+
self.bcx.fcx()
745+
}
746+
pub fn tcx(&self) -> &'blk ty::ctxt<'tcx> {
747+
self.bcx.tcx()
748+
}
749+
pub fn sess(&self) -> &'blk Session {
750+
self.bcx.sess()
751+
}
752+
753+
pub fn llbb(&self) -> BasicBlockRef {
754+
self.bcx.llbb
755+
}
756+
757+
pub fn mir(&self) -> &'blk Mir<'tcx> {
758+
self.bcx.mir()
759+
}
760+
761+
pub fn val_to_string(&self, val: ValueRef) -> String {
762+
self.bcx.val_to_string(val)
763+
}
764+
765+
pub fn monomorphize<T>(&self, value: &T) -> T
766+
where T: TypeFoldable<'tcx>
767+
{
768+
self.bcx.monomorphize(value)
769+
}
770+
}
771+
772+
impl<'blk, 'tcx> Deref for BlockAndBuilder<'blk, 'tcx> {
773+
type Target = Builder<'blk, 'tcx>;
774+
fn deref(&self) -> &Self::Target {
775+
&self.owned_builder.builder
776+
}
662777
}
663778

664779
/// A structure representing an active landing pad for the duration of a basic

0 commit comments

Comments
 (0)