Skip to content

Commit 00d87e0

Browse files
committed
auto merge of #11058 : pcwalton/rust/demuting, r=pcwalton
r? @alexcrichton
2 parents f74b8f0 + ad16014 commit 00d87e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+5230
-3596
lines changed

src/libextra/ebml.rs

+44-40
Original file line numberDiff line numberDiff line change
@@ -593,22 +593,13 @@ pub mod writer {
593593
use std::io::extensions::u64_to_be_bytes;
594594

595595
// ebml writing
596-
pub struct Encoder {
596+
pub struct Encoder<'a> {
597597
// FIXME(#5665): this should take a trait object
598-
writer: @mut MemWriter,
598+
writer: &'a mut MemWriter,
599599
priv size_positions: ~[uint],
600600
}
601601

602-
impl Clone for Encoder {
603-
fn clone(&self) -> Encoder {
604-
Encoder {
605-
writer: self.writer,
606-
size_positions: self.size_positions.clone(),
607-
}
608-
}
609-
}
610-
611-
fn write_sized_vuint(w: @mut MemWriter, n: uint, size: uint) {
602+
fn write_sized_vuint(w: &mut MemWriter, n: uint, size: uint) {
612603
match size {
613604
1u => w.write(&[0x80u8 | (n as u8)]),
614605
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
@@ -620,15 +611,15 @@ pub mod writer {
620611
};
621612
}
622613

623-
fn write_vuint(w: @mut MemWriter, n: uint) {
614+
fn write_vuint(w: &mut MemWriter, n: uint) {
624615
if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; }
625616
if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; }
626617
if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; }
627618
if n < 0x10000000_u { write_sized_vuint(w, n, 4u); return; }
628619
fail!("vint to write too big: {}", n);
629620
}
630621

631-
pub fn Encoder(w: @mut MemWriter) -> Encoder {
622+
pub fn Encoder<'a>(w: &'a mut MemWriter) -> Encoder<'a> {
632623
let size_positions: ~[uint] = ~[];
633624
Encoder {
634625
writer: w,
@@ -637,7 +628,15 @@ pub mod writer {
637628
}
638629

639630
// FIXME (#2741): Provide a function to write the standard ebml header.
640-
impl Encoder {
631+
impl<'a> Encoder<'a> {
632+
/// XXX(pcwalton): Workaround for badness in trans. DO NOT USE ME.
633+
pub unsafe fn unsafe_clone(&self) -> Encoder<'a> {
634+
Encoder {
635+
writer: cast::transmute_copy(&self.writer),
636+
size_positions: self.size_positions.clone(),
637+
}
638+
}
639+
641640
pub fn start_tag(&mut self, tag_id: uint) {
642641
debug!("Start tag {}", tag_id);
643642

@@ -739,7 +738,7 @@ pub mod writer {
739738
// Totally lame approach.
740739
static DEBUG: bool = true;
741740

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

760-
impl Encoder {
761758
pub fn emit_opaque(&mut self, f: |&mut Encoder|) {
762759
self.start_tag(EsOpaque as uint);
763760
f(self);
764761
self.end_tag();
765762
}
766763
}
767764

768-
impl ::serialize::Encoder for Encoder {
765+
impl<'a> ::serialize::Encoder for Encoder<'a> {
769766
fn emit_nil(&mut self) {}
770767

771768
fn emit_uint(&mut self, v: uint) {
@@ -820,7 +817,7 @@ pub mod writer {
820817
self.wr_tagged_str(EsStr as uint, v)
821818
}
822819

823-
fn emit_enum(&mut self, name: &str, f: |&mut Encoder|) {
820+
fn emit_enum(&mut self, name: &str, f: |&mut Encoder<'a>|) {
824821
self._emit_label(name);
825822
self.start_tag(EsEnum as uint);
826823
f(self);
@@ -831,98 +828,103 @@ pub mod writer {
831828
_: &str,
832829
v_id: uint,
833830
_: uint,
834-
f: |&mut Encoder|) {
831+
f: |&mut Encoder<'a>|) {
835832
self._emit_tagged_uint(EsEnumVid, v_id);
836833
self.start_tag(EsEnumBody as uint);
837834
f(self);
838835
self.end_tag();
839836
}
840837

841-
fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder|) {
838+
fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder<'a>|) {
842839
f(self)
843840
}
844841

845842
fn emit_enum_struct_variant(&mut self,
846843
v_name: &str,
847844
v_id: uint,
848845
cnt: uint,
849-
f: |&mut Encoder|) {
846+
f: |&mut Encoder<'a>|) {
850847
self.emit_enum_variant(v_name, v_id, cnt, f)
851848
}
852849

853850
fn emit_enum_struct_variant_field(&mut self,
854851
_: &str,
855852
idx: uint,
856-
f: |&mut Encoder|) {
853+
f: |&mut Encoder<'a>|) {
857854
self.emit_enum_variant_arg(idx, f)
858855
}
859856

860-
fn emit_struct(&mut self, _: &str, _len: uint, f: |&mut Encoder|) {
857+
fn emit_struct(&mut self,
858+
_: &str,
859+
_len: uint,
860+
f: |&mut Encoder<'a>|) {
861861
f(self)
862862
}
863863

864864
fn emit_struct_field(&mut self,
865865
name: &str,
866866
_: uint,
867-
f: |&mut Encoder|) {
867+
f: |&mut Encoder<'a>|) {
868868
self._emit_label(name);
869869
f(self)
870870
}
871871

872-
fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) {
872+
fn emit_tuple(&mut self, len: uint, f: |&mut Encoder<'a>|) {
873873
self.emit_seq(len, f)
874874
}
875-
fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) {
875+
fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
876876
self.emit_seq_elt(idx, f)
877877
}
878878

879879
fn emit_tuple_struct(&mut self,
880880
_: &str,
881881
len: uint,
882-
f: |&mut Encoder|) {
882+
f: |&mut Encoder<'a>|) {
883883
self.emit_seq(len, f)
884884
}
885-
fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) {
885+
fn emit_tuple_struct_arg(&mut self,
886+
idx: uint,
887+
f: |&mut Encoder<'a>|) {
886888
self.emit_seq_elt(idx, f)
887889
}
888890

889-
fn emit_option(&mut self, f: |&mut Encoder|) {
891+
fn emit_option(&mut self, f: |&mut Encoder<'a>|) {
890892
self.emit_enum("Option", f);
891893
}
892894
fn emit_option_none(&mut self) {
893895
self.emit_enum_variant("None", 0, 0, |_| ())
894896
}
895-
fn emit_option_some(&mut self, f: |&mut Encoder|) {
897+
fn emit_option_some(&mut self, f: |&mut Encoder<'a>|) {
896898
self.emit_enum_variant("Some", 1, 1, f)
897899
}
898900

899-
fn emit_seq(&mut self, len: uint, f: |&mut Encoder|) {
901+
fn emit_seq(&mut self, len: uint, f: |&mut Encoder<'a>|) {
900902
self.start_tag(EsVec as uint);
901903
self._emit_tagged_uint(EsVecLen, len);
902904
f(self);
903905
self.end_tag();
904906
}
905907

906-
fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder|) {
908+
fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
907909
self.start_tag(EsVecElt as uint);
908910
f(self);
909911
self.end_tag();
910912
}
911913

912-
fn emit_map(&mut self, len: uint, f: |&mut Encoder|) {
914+
fn emit_map(&mut self, len: uint, f: |&mut Encoder<'a>|) {
913915
self.start_tag(EsMap as uint);
914916
self._emit_tagged_uint(EsMapLen, len);
915917
f(self);
916918
self.end_tag();
917919
}
918920

919-
fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder|) {
921+
fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
920922
self.start_tag(EsMapKey as uint);
921923
f(self);
922924
self.end_tag();
923925
}
924926

925-
fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) {
927+
fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
926928
self.start_tag(EsMapVal as uint);
927929
f(self);
928930
self.end_tag();
@@ -948,9 +950,11 @@ mod tests {
948950
fn test_option_int() {
949951
fn test_v(v: Option<int>) {
950952
debug!("v == {:?}", v);
951-
let wr = @mut MemWriter::new();
952-
let mut ebml_w = writer::Encoder(wr);
953-
v.encode(&mut ebml_w);
953+
let mut wr = MemWriter::new();
954+
{
955+
let mut ebml_w = writer::Encoder(&mut wr);
956+
v.encode(&mut ebml_w);
957+
}
954958
let ebml_doc = reader::Doc(*wr.inner_ref());
955959
let mut deser = reader::Decoder(ebml_doc);
956960
let v1 = serialize::Decodable::decode(&mut deser);

src/librustc/back/archive.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ impl Archive {
187187

188188
let mut rustpath = filesearch::rust_path();
189189
rustpath.push(self.sess.filesearch.get_target_lib_path());
190-
let path = self.sess.opts.addl_lib_search_paths.iter();
190+
let addl_lib_search_paths = self.sess
191+
.opts
192+
.addl_lib_search_paths
193+
.borrow();
194+
let path = addl_lib_search_paths.get().iter();
191195
for path in path.chain(rustpath.iter()) {
192196
debug!("looking for {} inside {}", name, path.display());
193197
let test = path.join(oslibname.as_slice());

src/librustc/back/link.rs

+33-19
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ pub mod write {
208208
// Emit the bytecode if we're either saving our temporaries or
209209
// emitting an rlib. Whenever an rlib is create, the bytecode is
210210
// inserted into the archive in order to allow LTO against it.
211+
let outputs = sess.outputs.borrow();
211212
if sess.opts.save_temps ||
212-
sess.outputs.iter().any(|&o| o == session::OutputRlib) {
213+
outputs.get().iter().any(|&o| o == session::OutputRlib) {
213214
output.with_extension("bc").with_c_str(|buf| {
214215
llvm::LLVMWriteBitcodeToFile(llmod, buf);
215216
})
@@ -520,15 +521,20 @@ pub fn symbol_hash(tcx: ty::ctxt,
520521
hash.to_managed()
521522
}
522523

523-
pub fn get_symbol_hash(ccx: &mut CrateContext, t: ty::t) -> @str {
524-
match ccx.type_hashcodes.find(&t) {
525-
Some(&h) => h,
526-
None => {
527-
let hash = symbol_hash(ccx.tcx, &mut ccx.symbol_hasher, t, &ccx.link_meta);
528-
ccx.type_hashcodes.insert(t, hash);
529-
hash
530-
}
524+
pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> @str {
525+
{
526+
let type_hashcodes = ccx.type_hashcodes.borrow();
527+
match type_hashcodes.get().find(&t) {
528+
Some(&h) => return h,
529+
None => {}
530+
}
531531
}
532+
533+
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
534+
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
535+
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
536+
type_hashcodes.get().insert(t, hash);
537+
hash
532538
}
533539

534540

@@ -657,7 +663,7 @@ pub fn exported_name(sess: Session,
657663
mangle(sess, path, Some(hash), Some(vers.as_slice()))
658664
}
659665

660-
pub fn mangle_exported_name(ccx: &mut CrateContext,
666+
pub fn mangle_exported_name(ccx: &CrateContext,
661667
path: path,
662668
t: ty::t) -> ~str {
663669
let hash = get_symbol_hash(ccx, t);
@@ -666,7 +672,7 @@ pub fn mangle_exported_name(ccx: &mut CrateContext,
666672
ccx.link_meta.pkgid.version_or_default());
667673
}
668674

669-
pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
675+
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
670676
t: ty::t,
671677
name: &str) -> ~str {
672678
let s = ppaux::ty_to_short_str(ccx.tcx, t);
@@ -678,7 +684,7 @@ pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
678684
None);
679685
}
680686

681-
pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
687+
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
682688
t: ty::t,
683689
name: &str) -> ~str {
684690
let s = ppaux::ty_to_str(ccx.tcx, t);
@@ -690,15 +696,15 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
690696
None);
691697
}
692698

693-
pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
699+
pub fn mangle_internal_name_by_path_and_seq(ccx: &CrateContext,
694700
mut path: path,
695701
flav: &str) -> ~str {
696702
let (_, name) = gensym_name(flav);
697703
path.push(name);
698704
mangle(ccx.sess, path, None, None)
699705
}
700706

701-
pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
707+
pub fn mangle_internal_name_by_path(ccx: &CrateContext, path: path) -> ~str {
702708
mangle(ccx.sess, path, None, None)
703709
}
704710

@@ -740,7 +746,8 @@ pub fn link_binary(sess: Session,
740746
out_filename: &Path,
741747
lm: &LinkMeta) -> ~[Path] {
742748
let mut out_filenames = ~[];
743-
for &output in sess.outputs.iter() {
749+
let outputs = sess.outputs.borrow();
750+
for &output in outputs.get().iter() {
744751
let out_file = link_binary_output(sess, trans, output, obj_filename,
745752
out_filename, lm);
746753
out_filenames.push(out_file);
@@ -848,7 +855,9 @@ fn link_rlib(sess: Session,
848855
out_filename: &Path) -> Archive {
849856
let mut a = Archive::create(sess, out_filename, obj_filename);
850857

851-
for &(ref l, kind) in sess.cstore.get_used_libraries().iter() {
858+
let used_libraries = sess.cstore.get_used_libraries();
859+
let used_libraries = used_libraries.borrow();
860+
for &(ref l, kind) in used_libraries.get().iter() {
852861
match kind {
853862
cstore::NativeStatic => {
854863
a.add_native_library(l.as_slice());
@@ -1082,7 +1091,9 @@ fn link_args(sess: Session,
10821091
// Finally add all the linker arguments provided on the command line along
10831092
// with any #[link_args] attributes found inside the crate
10841093
args.push_all(sess.opts.linker_args);
1085-
for arg in sess.cstore.get_used_link_args().iter() {
1094+
let used_link_args = sess.cstore.get_used_link_args();
1095+
let used_link_args = used_link_args.borrow();
1096+
for arg in used_link_args.get().iter() {
10861097
args.push(arg.clone());
10871098
}
10881099
return args;
@@ -1100,7 +1111,8 @@ fn link_args(sess: Session,
11001111
// in the current crate. Upstream crates with native library dependencies
11011112
// may have their native library pulled in above.
11021113
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
1103-
for path in sess.opts.addl_lib_search_paths.iter() {
1114+
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
1115+
for path in addl_lib_search_paths.get().iter() {
11041116
// FIXME (#9639): This needs to handle non-utf8 paths
11051117
args.push("-L" + path.as_str().unwrap().to_owned());
11061118
}
@@ -1111,7 +1123,9 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
11111123
args.push("-L" + path.as_str().unwrap().to_owned());
11121124
}
11131125

1114-
for &(ref l, kind) in sess.cstore.get_used_libraries().iter() {
1126+
let used_libraries = sess.cstore.get_used_libraries();
1127+
let used_libraries = used_libraries.borrow();
1128+
for &(ref l, kind) in used_libraries.get().iter() {
11151129
match kind {
11161130
cstore::NativeUnknown | cstore::NativeStatic => {
11171131
args.push("-l" + *l);

src/librustc/back/lto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use std::libc;
2020
pub fn run(sess: session::Session, llmod: ModuleRef,
2121
tm: TargetMachineRef, reachable: &[~str]) {
2222
// Make sure we actually can run LTO
23-
for output in sess.outputs.iter() {
23+
let outputs = sess.outputs.borrow();
24+
for output in outputs.get().iter() {
2425
match *output {
2526
session::OutputExecutable | session::OutputStaticlib => {}
2627
_ => {

0 commit comments

Comments
 (0)