Skip to content

Commit

Permalink
auto merge of rust-lang#11058 : pcwalton/rust/demuting, r=pcwalton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Dec 27, 2013
2 parents f74b8f0 + ad16014 commit 00d87e0
Show file tree
Hide file tree
Showing 109 changed files with 5,230 additions and 3,596 deletions.
84 changes: 44 additions & 40 deletions src/libextra/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,22 +593,13 @@ pub mod writer {
use std::io::extensions::u64_to_be_bytes;

// ebml writing
pub struct Encoder {
pub struct Encoder<'a> {
// FIXME(#5665): this should take a trait object
writer: @mut MemWriter,
writer: &'a mut MemWriter,
priv size_positions: ~[uint],
}

impl Clone for Encoder {
fn clone(&self) -> Encoder {
Encoder {
writer: self.writer,
size_positions: self.size_positions.clone(),
}
}
}

fn write_sized_vuint(w: @mut MemWriter, n: uint, size: uint) {
fn write_sized_vuint(w: &mut MemWriter, n: uint, size: uint) {
match size {
1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
Expand All @@ -620,15 +611,15 @@ pub mod writer {
};
}

fn write_vuint(w: @mut MemWriter, n: uint) {
fn write_vuint(w: &mut MemWriter, n: uint) {
if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; }
if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; }
if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; }
if n < 0x10000000_u { write_sized_vuint(w, n, 4u); return; }
fail!("vint to write too big: {}", n);
}

pub fn Encoder(w: @mut MemWriter) -> Encoder {
pub fn Encoder<'a>(w: &'a mut MemWriter) -> Encoder<'a> {
let size_positions: ~[uint] = ~[];
Encoder {
writer: w,
Expand All @@ -637,7 +628,15 @@ pub mod writer {
}

// FIXME (#2741): Provide a function to write the standard ebml header.
impl Encoder {
impl<'a> Encoder<'a> {
/// XXX(pcwalton): Workaround for badness in trans. DO NOT USE ME.
pub unsafe fn unsafe_clone(&self) -> Encoder<'a> {
Encoder {
writer: cast::transmute_copy(&self.writer),
size_positions: self.size_positions.clone(),
}
}

pub fn start_tag(&mut self, tag_id: uint) {
debug!("Start tag {}", tag_id);

Expand Down Expand Up @@ -739,7 +738,7 @@ pub mod writer {
// Totally lame approach.
static DEBUG: bool = true;

impl Encoder {
impl<'a> Encoder<'a> {
// used internally to emit things like the vector length and so on
fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) {
assert!(v <= 0xFFFF_FFFF_u);
Expand All @@ -755,17 +754,15 @@ pub mod writer {
// try and check failures more quickly.
if DEBUG { self.wr_tagged_str(EsLabel as uint, label) }
}
}

impl Encoder {
pub fn emit_opaque(&mut self, f: |&mut Encoder|) {
self.start_tag(EsOpaque as uint);
f(self);
self.end_tag();
}
}

impl ::serialize::Encoder for Encoder {
impl<'a> ::serialize::Encoder for Encoder<'a> {
fn emit_nil(&mut self) {}

fn emit_uint(&mut self, v: uint) {
Expand Down Expand Up @@ -820,7 +817,7 @@ pub mod writer {
self.wr_tagged_str(EsStr as uint, v)
}

fn emit_enum(&mut self, name: &str, f: |&mut Encoder|) {
fn emit_enum(&mut self, name: &str, f: |&mut Encoder<'a>|) {
self._emit_label(name);
self.start_tag(EsEnum as uint);
f(self);
Expand All @@ -831,98 +828,103 @@ pub mod writer {
_: &str,
v_id: uint,
_: uint,
f: |&mut Encoder|) {
f: |&mut Encoder<'a>|) {
self._emit_tagged_uint(EsEnumVid, v_id);
self.start_tag(EsEnumBody as uint);
f(self);
self.end_tag();
}

fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder|) {
fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder<'a>|) {
f(self)
}

fn emit_enum_struct_variant(&mut self,
v_name: &str,
v_id: uint,
cnt: uint,
f: |&mut Encoder|) {
f: |&mut Encoder<'a>|) {
self.emit_enum_variant(v_name, v_id, cnt, f)
}

fn emit_enum_struct_variant_field(&mut self,
_: &str,
idx: uint,
f: |&mut Encoder|) {
f: |&mut Encoder<'a>|) {
self.emit_enum_variant_arg(idx, f)
}

fn emit_struct(&mut self, _: &str, _len: uint, f: |&mut Encoder|) {
fn emit_struct(&mut self,
_: &str,
_len: uint,
f: |&mut Encoder<'a>|) {
f(self)
}

fn emit_struct_field(&mut self,
name: &str,
_: uint,
f: |&mut Encoder|) {
f: |&mut Encoder<'a>|) {
self._emit_label(name);
f(self)
}

fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) {
fn emit_tuple(&mut self, len: uint, f: |&mut Encoder<'a>|) {
self.emit_seq(len, f)
}
fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) {
fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
self.emit_seq_elt(idx, f)
}

fn emit_tuple_struct(&mut self,
_: &str,
len: uint,
f: |&mut Encoder|) {
f: |&mut Encoder<'a>|) {
self.emit_seq(len, f)
}
fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) {
fn emit_tuple_struct_arg(&mut self,
idx: uint,
f: |&mut Encoder<'a>|) {
self.emit_seq_elt(idx, f)
}

fn emit_option(&mut self, f: |&mut Encoder|) {
fn emit_option(&mut self, f: |&mut Encoder<'a>|) {
self.emit_enum("Option", f);
}
fn emit_option_none(&mut self) {
self.emit_enum_variant("None", 0, 0, |_| ())
}
fn emit_option_some(&mut self, f: |&mut Encoder|) {
fn emit_option_some(&mut self, f: |&mut Encoder<'a>|) {
self.emit_enum_variant("Some", 1, 1, f)
}

fn emit_seq(&mut self, len: uint, f: |&mut Encoder|) {
fn emit_seq(&mut self, len: uint, f: |&mut Encoder<'a>|) {
self.start_tag(EsVec as uint);
self._emit_tagged_uint(EsVecLen, len);
f(self);
self.end_tag();
}

fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder|) {
fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
self.start_tag(EsVecElt as uint);
f(self);
self.end_tag();
}

fn emit_map(&mut self, len: uint, f: |&mut Encoder|) {
fn emit_map(&mut self, len: uint, f: |&mut Encoder<'a>|) {
self.start_tag(EsMap as uint);
self._emit_tagged_uint(EsMapLen, len);
f(self);
self.end_tag();
}

fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder|) {
fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
self.start_tag(EsMapKey as uint);
f(self);
self.end_tag();
}

fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) {
fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
self.start_tag(EsMapVal as uint);
f(self);
self.end_tag();
Expand All @@ -948,9 +950,11 @@ mod tests {
fn test_option_int() {
fn test_v(v: Option<int>) {
debug!("v == {:?}", v);
let wr = @mut MemWriter::new();
let mut ebml_w = writer::Encoder(wr);
v.encode(&mut ebml_w);
let mut wr = MemWriter::new();
{
let mut ebml_w = writer::Encoder(&mut wr);
v.encode(&mut ebml_w);
}
let ebml_doc = reader::Doc(*wr.inner_ref());
let mut deser = reader::Decoder(ebml_doc);
let v1 = serialize::Decodable::decode(&mut deser);
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ impl Archive {

let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch.get_target_lib_path());
let path = self.sess.opts.addl_lib_search_paths.iter();
let addl_lib_search_paths = self.sess
.opts
.addl_lib_search_paths
.borrow();
let path = addl_lib_search_paths.get().iter();
for path in path.chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
let test = path.join(oslibname.as_slice());
Expand Down
52 changes: 33 additions & 19 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ pub mod write {
// Emit the bytecode if we're either saving our temporaries or
// emitting an rlib. Whenever an rlib is create, the bytecode is
// inserted into the archive in order to allow LTO against it.
let outputs = sess.outputs.borrow();
if sess.opts.save_temps ||
sess.outputs.iter().any(|&o| o == session::OutputRlib) {
outputs.get().iter().any(|&o| o == session::OutputRlib) {
output.with_extension("bc").with_c_str(|buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
})
Expand Down Expand Up @@ -520,15 +521,20 @@ pub fn symbol_hash(tcx: ty::ctxt,
hash.to_managed()
}

pub fn get_symbol_hash(ccx: &mut CrateContext, t: ty::t) -> @str {
match ccx.type_hashcodes.find(&t) {
Some(&h) => h,
None => {
let hash = symbol_hash(ccx.tcx, &mut ccx.symbol_hasher, t, &ccx.link_meta);
ccx.type_hashcodes.insert(t, hash);
hash
}
pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> @str {
{
let type_hashcodes = ccx.type_hashcodes.borrow();
match type_hashcodes.get().find(&t) {
Some(&h) => return h,
None => {}
}
}

let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
type_hashcodes.get().insert(t, hash);
hash
}


Expand Down Expand Up @@ -657,7 +663,7 @@ pub fn exported_name(sess: Session,
mangle(sess, path, Some(hash), Some(vers.as_slice()))
}

pub fn mangle_exported_name(ccx: &mut CrateContext,
pub fn mangle_exported_name(ccx: &CrateContext,
path: path,
t: ty::t) -> ~str {
let hash = get_symbol_hash(ccx, t);
Expand All @@ -666,7 +672,7 @@ pub fn mangle_exported_name(ccx: &mut CrateContext,
ccx.link_meta.pkgid.version_or_default());
}

pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_short_str(ccx.tcx, t);
Expand All @@ -678,7 +684,7 @@ pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
None);
}

pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_str(ccx.tcx, t);
Expand All @@ -690,15 +696,15 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
None);
}

pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
pub fn mangle_internal_name_by_path_and_seq(ccx: &CrateContext,
mut path: path,
flav: &str) -> ~str {
let (_, name) = gensym_name(flav);
path.push(name);
mangle(ccx.sess, path, None, None)
}

pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
pub fn mangle_internal_name_by_path(ccx: &CrateContext, path: path) -> ~str {
mangle(ccx.sess, path, None, None)
}

Expand Down Expand Up @@ -740,7 +746,8 @@ pub fn link_binary(sess: Session,
out_filename: &Path,
lm: &LinkMeta) -> ~[Path] {
let mut out_filenames = ~[];
for &output in sess.outputs.iter() {
let outputs = sess.outputs.borrow();
for &output in outputs.get().iter() {
let out_file = link_binary_output(sess, trans, output, obj_filename,
out_filename, lm);
out_filenames.push(out_file);
Expand Down Expand Up @@ -848,7 +855,9 @@ fn link_rlib(sess: Session,
out_filename: &Path) -> Archive {
let mut a = Archive::create(sess, out_filename, obj_filename);

for &(ref l, kind) in sess.cstore.get_used_libraries().iter() {
let used_libraries = sess.cstore.get_used_libraries();
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
match kind {
cstore::NativeStatic => {
a.add_native_library(l.as_slice());
Expand Down Expand Up @@ -1082,7 +1091,9 @@ fn link_args(sess: Session,
// Finally add all the linker arguments provided on the command line along
// with any #[link_args] attributes found inside the crate
args.push_all(sess.opts.linker_args);
for arg in sess.cstore.get_used_link_args().iter() {
let used_link_args = sess.cstore.get_used_link_args();
let used_link_args = used_link_args.borrow();
for arg in used_link_args.get().iter() {
args.push(arg.clone());
}
return args;
Expand All @@ -1100,7 +1111,8 @@ fn link_args(sess: Session,
// in the current crate. Upstream crates with native library dependencies
// may have their native library pulled in above.
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
for path in sess.opts.addl_lib_search_paths.iter() {
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
for path in addl_lib_search_paths.get().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned());
}
Expand All @@ -1111,7 +1123,9 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
args.push("-L" + path.as_str().unwrap().to_owned());
}

for &(ref l, kind) in sess.cstore.get_used_libraries().iter() {
let used_libraries = sess.cstore.get_used_libraries();
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
match kind {
cstore::NativeUnknown | cstore::NativeStatic => {
args.push("-l" + *l);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::libc;
pub fn run(sess: session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[~str]) {
// Make sure we actually can run LTO
for output in sess.outputs.iter() {
let outputs = sess.outputs.borrow();
for output in outputs.get().iter() {
match *output {
session::OutputExecutable | session::OutputStaticlib => {}
_ => {
Expand Down
Loading

0 comments on commit 00d87e0

Please sign in to comment.