Skip to content

Commit

Permalink
auto merge of #13053 : alexcrichton/rust/removing-ref-cell-get, r=huonw
Browse files Browse the repository at this point in the history
This commit removes the `get()` method from `Ref` and `RefMut` in favor of the `*` operator, and removes all usage of the `deref()` function manually from rustc, favoring using `*` instead.

Some of the code is a little wacky, but that's due to either #13044 or #13042
  • Loading branch information
bors committed Mar 22, 2014
2 parents 5e8e1b5 + 9dc357b commit 403e869
Show file tree
Hide file tree
Showing 107 changed files with 1,587 additions and 2,639 deletions.
4 changes: 2 additions & 2 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ struct Chunk {
}
impl Chunk {
fn capacity(&self) -> uint {
self.data.deref().borrow().get().capacity()
self.data.borrow().capacity()
}

unsafe fn as_ptr(&self) -> *u8 {
self.data.deref().borrow().get().as_ptr()
self.data.borrow().as_ptr()
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,8 @@ impl<'a> Archive<'a> {

let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch().get_target_lib_path());
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()) {
let search = self.sess.opts.addl_lib_search_paths.borrow();
for path in search.iter().chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
let test = path.join(oslibname.as_slice());
if test.exists() { return test }
Expand Down
28 changes: 9 additions & 19 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ pub mod write {
// Emit the bytecode if we're either saving our temporaries or
// emitting an rlib. Whenever an rlib is created, the bytecode is
// inserted into the archive in order to allow LTO against it.
let crate_types = sess.crate_types.borrow();
if sess.opts.cg.save_temps ||
(crate_types.get().contains(&session::CrateTypeRlib) &&
(sess.crate_types.borrow().contains(&session::CrateTypeRlib) &&
sess.opts.output_types.contains(&OutputTypeExe)) {
output.temp_path(OutputTypeBitcode).with_c_str(|buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
Expand Down Expand Up @@ -550,15 +549,14 @@ fn symbol_hash(tcx: &ty::ctxt, symbol_hasher: &mut Sha256,
}

fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
match ccx.type_hashcodes.borrow().get().find(&t) {
match ccx.type_hashcodes.borrow().find(&t) {
Some(h) => return h.to_str(),
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.clone());
let hash = symbol_hash(ccx.tcx(), &mut *symbol_hasher, t, &ccx.link_meta);
ccx.type_hashcodes.borrow_mut().insert(t, hash.clone());
hash
}

Expand Down Expand Up @@ -779,8 +777,7 @@ pub fn link_binary(sess: &Session,
outputs: &OutputFilenames,
id: &CrateId) -> Vec<Path> {
let mut out_filenames = Vec::new();
let crate_types = sess.crate_types.borrow();
for &crate_type in crate_types.get().iter() {
for &crate_type in sess.crate_types.borrow().iter() {
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
out_filenames.push(out_file);
}
Expand Down Expand Up @@ -887,9 +884,7 @@ fn link_rlib<'a>(sess: &'a Session,
out_filename: &Path) -> Archive<'a> {
let mut a = Archive::create(sess, out_filename, obj_filename);

let used_libraries = sess.cstore.get_used_libraries();
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
match kind {
cstore::NativeStatic => {
a.add_native_library(l.as_slice()).unwrap();
Expand Down Expand Up @@ -1227,9 +1222,7 @@ 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.cg.link_args.as_slice());
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() {
for arg in sess.cstore.get_used_link_args().borrow().iter() {
args.push(arg.clone());
}
return args;
Expand All @@ -1247,8 +1240,7 @@ 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 Vec<~str>, sess: &Session) {
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
for path in addl_lib_search_paths.get().iter() {
for path in sess.opts.addl_lib_search_paths.borrow().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned());
}
Expand All @@ -1259,9 +1251,7 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
args.push("-L" + path.as_str().unwrap().to_owned());
}

let used_libraries = sess.cstore.get_used_libraries();
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
match kind {
cstore::NativeUnknown | cstore::NativeStatic => {
args.push("-l" + *l);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
}

// Make sure we actually can run LTO
let crate_types = sess.crate_types.borrow();
for crate_type in crate_types.get().iter() {
for crate_type in sess.crate_types.borrow().iter() {
match *crate_type {
session::CrateTypeExecutable | session::CrateTypeStaticlib => {}
_ => {
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ fn write_out_deps(sess: &Session,
let file = outputs.path(*output_type);
match *output_type {
link::OutputTypeExe => {
let crate_types = sess.crate_types.borrow();
for output in crate_types.get().iter() {
for output in sess.crate_types.borrow().iter() {
let p = link::filename_for_input(sess, *output, &id, &file);
out_filenames.push(p);
}
Expand Down Expand Up @@ -542,10 +541,10 @@ fn write_out_deps(sess: &Session,

// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: Vec<~str> = sess.codemap().files.borrow().get()
let files: Vec<~str> = sess.codemap().files.borrow()
.iter().filter_map(|fmap| {
if fmap.deref().is_real_file() {
Some(fmap.deref().name.clone())
if fmap.is_real_file() {
Some(fmap.name.clone())
} else {
None
}
Expand Down Expand Up @@ -683,7 +682,7 @@ pub fn pretty_print_input(sess: Session,
};

let src_name = source_name(input);
let src = sess.codemap().get_filemap(src_name).deref().src.as_bytes().to_owned();
let src = sess.codemap().get_filemap(src_name).src.as_bytes().to_owned();
let mut rdr = MemReader::new(src);

match ppm {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ impl Session {
sp: Span,
msg: ~str) {
let mut lints = self.lints.borrow_mut();
match lints.get().find_mut(&id) {
match lints.find_mut(&id) {
Some(arr) => { arr.push((lint, sp, msg)); return; }
None => {}
}
lints.get().insert(id, vec!((lint, sp, msg)));
lints.insert(id, vec!((lint, sp, msg)));
}
pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1)
Expand Down
24 changes: 6 additions & 18 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
}

fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
{
let mut path = self.cx.path.borrow_mut();
path.get().push(i.ident);
}
self.cx.path.borrow_mut().push(i.ident);
debug!("current path: {}",
ast_util::path_name_i(self.cx.path.get().as_slice()));

Expand All @@ -112,21 +109,15 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
ignore: is_ignored(&self.cx, i),
should_fail: should_fail(i)
};
{
let mut testfns = self.cx.testfns.borrow_mut();
testfns.get().push(test);
}
self.cx.testfns.borrow_mut().push(test);
// debug!("have {} test/bench functions",
// cx.testfns.len());
}
}
}

let res = fold::noop_fold_item(i, self);
{
let mut path = self.cx.path.borrow_mut();
path.get().pop();
}
self.cx.path.borrow_mut().pop();
res
}

Expand Down Expand Up @@ -414,12 +405,9 @@ fn is_test_crate(krate: &ast::Crate) -> bool {

fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
let mut descs = Vec::new();
{
let testfns = cx.testfns.borrow();
debug!("building test vector from {} tests", testfns.get().len());
for test in testfns.get().iter() {
descs.push(mk_test_desc_and_fn_rec(cx, test));
}
debug!("building test vector from {} tests", cx.testfns.borrow().len());
for test in cx.testfns.borrow().iter() {
descs.push(mk_test_desc_and_fn_rec(cx, test));
}

let inner_expr = @ast::Expr {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,13 +1831,11 @@ impl TypeNames {
}

pub fn associate_type(&self, s: &str, t: &Type) {
let mut named_types = self.named_types.borrow_mut();
assert!(named_types.get().insert(s.to_owned(), t.to_ref()));
assert!(self.named_types.borrow_mut().insert(s.to_owned(), t.to_ref()));
}

pub fn find_type(&self, s: &str) -> Option<Type> {
let named_types = self.named_types.borrow();
named_types.get().find_equiv(&s).map(|x| Type::from_ref(*x))
self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
}

pub fn type_to_str(&self, ty: Type) -> ~str {
Expand Down
23 changes: 9 additions & 14 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ pub fn read_crates(sess: &Session,
};
visit_crate(&e, krate);
visit::walk_crate(&mut e, krate, ());
let crate_cache = e.crate_cache.borrow();
dump_crates(crate_cache.get().as_slice());
dump_crates(e.crate_cache.borrow().as_slice());
warn_if_multiple_versions(&mut e,
sess.diagnostic(),
crate_cache.get().as_slice());
e.crate_cache.borrow().as_slice());
}

impl<'a> visit::Visitor<()> for Env<'a> {
Expand Down Expand Up @@ -268,8 +267,7 @@ fn visit_item(e: &Env, i: &ast::Item) {

fn existing_match(e: &Env, crate_id: &CrateId,
hash: Option<&Svh>) -> Option<ast::CrateNum> {
let crate_cache = e.crate_cache.borrow();
for c in crate_cache.get().iter() {
for c in e.crate_cache.borrow().iter() {
if !crate_id.matches(&c.crate_id) { continue }
match hash {
Some(hash) if *hash != c.hash => {}
Expand Down Expand Up @@ -309,15 +307,12 @@ fn resolve_crate(e: &mut Env,

// Claim this crate number and cache it
let cnum = e.next_crate_num;
{
let mut crate_cache = e.crate_cache.borrow_mut();
crate_cache.get().push(cache_entry {
cnum: cnum,
span: span,
hash: hash,
crate_id: crate_id,
});
}
e.crate_cache.borrow_mut().push(cache_entry {
cnum: cnum,
span: span,
hash: hash,
crate_id: crate_id,
});
e.next_crate_num += 1;

// Maintain a reference to the top most crate.
Expand Down
39 changes: 15 additions & 24 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ impl CStore {
}

pub fn get_crate_data(&self, cnum: ast::CrateNum) -> @crate_metadata {
let metas = self.metas.borrow();
*metas.get().get(&cnum)
*self.metas.borrow().get(&cnum)
}

pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
Expand All @@ -104,33 +103,30 @@ impl CStore {
}

pub fn set_crate_data(&self, cnum: ast::CrateNum, data: @crate_metadata) {
let mut metas = self.metas.borrow_mut();
metas.get().insert(cnum, data);
self.metas.borrow_mut().insert(cnum, data);
}

pub fn have_crate_data(&self, cnum: ast::CrateNum) -> bool {
let metas = self.metas.borrow();
metas.get().contains_key(&cnum)
self.metas.borrow().contains_key(&cnum)
}

pub fn iter_crate_data(&self, i: |ast::CrateNum, @crate_metadata|) {
let metas = self.metas.borrow();
for (&k, &v) in metas.get().iter() {
for (&k, &v) in self.metas.borrow().iter() {
i(k, v);
}
}

pub fn add_used_crate_source(&self, src: CrateSource) {
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
if !used_crate_sources.get().contains(&src) {
used_crate_sources.get().push(src);
if !used_crate_sources.contains(&src) {
used_crate_sources.push(src);
}
}

pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
-> Option<CrateSource> {
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
used_crate_sources.get().iter().find(|source| source.cnum == cnum)
self.used_crate_sources.borrow_mut()
.iter().find(|source| source.cnum == cnum)
.map(|source| source.clone())
}

Expand Down Expand Up @@ -158,18 +154,17 @@ impl CStore {
ordering: &mut Vec<ast::CrateNum>) {
if ordering.as_slice().contains(&cnum) { return }
let meta = cstore.get_crate_data(cnum);
for (_, &dep) in meta.cnum_map.borrow().get().iter() {
for (_, &dep) in meta.cnum_map.borrow().iter() {
visit(cstore, dep, ordering);
}
ordering.push(cnum);
};
for (&num, _) in self.metas.borrow().get().iter() {
for (&num, _) in self.metas.borrow().iter() {
visit(self, num, &mut ordering);
}
ordering.as_mut_slice().reverse();
let ordering = ordering.as_slice();
let used_crate_sources = self.used_crate_sources.borrow();
let mut libs = used_crate_sources.get()
let mut libs = self.used_crate_sources.borrow()
.iter()
.map(|src| (src.cnum, match prefer {
RequireDynamic => src.dylib.clone(),
Expand All @@ -184,8 +179,7 @@ impl CStore {

pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {
assert!(!lib.is_empty());
let mut used_libraries = self.used_libraries.borrow_mut();
used_libraries.get().push((lib, kind));
self.used_libraries.borrow_mut().push((lib, kind));
}

pub fn get_used_libraries<'a>(&'a self)
Expand All @@ -194,9 +188,8 @@ impl CStore {
}

pub fn add_used_link_args(&self, args: &str) {
let mut used_link_args = self.used_link_args.borrow_mut();
for s in args.split(' ') {
used_link_args.get().push(s.to_owned());
self.used_link_args.borrow_mut().push(s.to_owned());
}
}

Expand All @@ -207,14 +200,12 @@ impl CStore {
pub fn add_extern_mod_stmt_cnum(&self,
emod_id: ast::NodeId,
cnum: ast::CrateNum) {
let mut extern_mod_crate_map = self.extern_mod_crate_map.borrow_mut();
extern_mod_crate_map.get().insert(emod_id, cnum);
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
}

pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
-> Option<ast::CrateNum> {
let extern_mod_crate_map = self.extern_mod_crate_map.borrow();
extern_mod_crate_map.get().find(&emod_id).map(|x| *x)
self.extern_mod_crate_map.borrow().find(&emod_id).map(|x| *x)
}
}

Expand Down
Loading

0 comments on commit 403e869

Please sign in to comment.