rustc: Fix fallout of removing get()

This commit is contained in:
Alex Crichton 2014-03-20 19:49:20 -07:00
parent 9a37416dbe
commit 0dbb909bf7
74 changed files with 1347 additions and 2316 deletions

View File

@ -206,12 +206,8 @@ impl<'a> Archive<'a> {
let mut rustpath = filesearch::rust_path(); let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch().get_target_lib_path()); rustpath.push(self.sess.filesearch().get_target_lib_path());
let addl_lib_search_paths = self.sess let search = self.sess.opts.addl_lib_search_paths.borrow();
.opts for path in search.iter().chain(rustpath.iter()) {
.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()); debug!("looking for {} inside {}", name, path.display());
let test = path.join(oslibname.as_slice()); let test = path.join(oslibname.as_slice());
if test.exists() { return test } if test.exists() { return test }

View File

@ -209,9 +209,8 @@ pub mod write {
// Emit the bytecode if we're either saving our temporaries or // Emit the bytecode if we're either saving our temporaries or
// emitting an rlib. Whenever an rlib is created, the bytecode is // emitting an rlib. Whenever an rlib is created, the bytecode is
// inserted into the archive in order to allow LTO against it. // inserted into the archive in order to allow LTO against it.
let crate_types = sess.crate_types.borrow();
if sess.opts.cg.save_temps || 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)) { sess.opts.output_types.contains(&OutputTypeExe)) {
output.temp_path(OutputTypeBitcode).with_c_str(|buf| { output.temp_path(OutputTypeBitcode).with_c_str(|buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf); llvm::LLVMWriteBitcodeToFile(llmod, buf);
@ -550,15 +549,14 @@ fn symbol_hash(tcx: &ty::ctxt, symbol_hasher: &mut Sha256,
} }
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str { 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(), Some(h) => return h.to_str(),
None => {} None => {}
} }
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut(); let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
let hash = symbol_hash(ccx.tcx(), symbol_hasher.get(), t, &ccx.link_meta); let hash = symbol_hash(ccx.tcx(), &mut *symbol_hasher, t, &ccx.link_meta);
type_hashcodes.get().insert(t, hash.clone()); ccx.type_hashcodes.borrow_mut().insert(t, hash.clone());
hash hash
} }
@ -779,8 +777,7 @@ pub fn link_binary(sess: &Session,
outputs: &OutputFilenames, outputs: &OutputFilenames,
id: &CrateId) -> Vec<Path> { id: &CrateId) -> Vec<Path> {
let mut out_filenames = Vec::new(); let mut out_filenames = Vec::new();
let crate_types = sess.crate_types.borrow(); for &crate_type in sess.crate_types.borrow().iter() {
for &crate_type in crate_types.get().iter() {
let out_file = link_binary_output(sess, trans, crate_type, outputs, id); let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
out_filenames.push(out_file); out_filenames.push(out_file);
} }
@ -887,9 +884,7 @@ fn link_rlib<'a>(sess: &'a Session,
out_filename: &Path) -> Archive<'a> { out_filename: &Path) -> Archive<'a> {
let mut a = Archive::create(sess, out_filename, obj_filename); let mut a = Archive::create(sess, out_filename, obj_filename);
let used_libraries = sess.cstore.get_used_libraries(); for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
match kind { match kind {
cstore::NativeStatic => { cstore::NativeStatic => {
a.add_native_library(l.as_slice()).unwrap(); a.add_native_library(l.as_slice()).unwrap();
@ -1227,9 +1222,7 @@ fn link_args(sess: &Session,
// Finally add all the linker arguments provided on the command line along // Finally add all the linker arguments provided on the command line along
// with any #[link_args] attributes found inside the crate // with any #[link_args] attributes found inside the crate
args.push_all(sess.opts.cg.link_args.as_slice()); args.push_all(sess.opts.cg.link_args.as_slice());
let used_link_args = sess.cstore.get_used_link_args(); for arg in sess.cstore.get_used_link_args().borrow().iter() {
let used_link_args = used_link_args.borrow();
for arg in used_link_args.get().iter() {
args.push(arg.clone()); args.push(arg.clone());
} }
return args; return args;
@ -1247,8 +1240,7 @@ fn link_args(sess: &Session,
// in the current crate. Upstream crates with native library dependencies // in the current crate. Upstream crates with native library dependencies
// may have their native library pulled in above. // may have their native library pulled in above.
fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) { 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 sess.opts.addl_lib_search_paths.borrow().iter() {
for path in addl_lib_search_paths.get().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned()); args.push("-L" + path.as_str().unwrap().to_owned());
} }
@ -1259,9 +1251,7 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
args.push("-L" + path.as_str().unwrap().to_owned()); args.push("-L" + path.as_str().unwrap().to_owned());
} }
let used_libraries = sess.cstore.get_used_libraries(); for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
let used_libraries = used_libraries.borrow();
for &(ref l, kind) in used_libraries.get().iter() {
match kind { match kind {
cstore::NativeUnknown | cstore::NativeStatic => { cstore::NativeUnknown | cstore::NativeStatic => {
args.push("-l" + *l); args.push("-l" + *l);

View File

@ -27,8 +27,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
} }
// Make sure we actually can run LTO // Make sure we actually can run LTO
let crate_types = sess.crate_types.borrow(); for crate_type in sess.crate_types.borrow().iter() {
for crate_type in crate_types.get().iter() {
match *crate_type { match *crate_type {
session::CrateTypeExecutable | session::CrateTypeStaticlib => {} session::CrateTypeExecutable | session::CrateTypeStaticlib => {}
_ => { _ => {

View File

@ -512,8 +512,7 @@ fn write_out_deps(sess: &Session,
let file = outputs.path(*output_type); let file = outputs.path(*output_type);
match *output_type { match *output_type {
link::OutputTypeExe => { link::OutputTypeExe => {
let crate_types = sess.crate_types.borrow(); for output in sess.crate_types.borrow().iter() {
for output in crate_types.get().iter() {
let p = link::filename_for_input(sess, *output, &id, &file); let p = link::filename_for_input(sess, *output, &id, &file);
out_filenames.push(p); out_filenames.push(p);
} }
@ -542,7 +541,7 @@ fn write_out_deps(sess: &Session,
// Build a list of files used to compile the output and // Build a list of files used to compile the output and
// write Makefile-compatible dependency rules // 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| { .iter().filter_map(|fmap| {
if fmap.deref().is_real_file() { if fmap.deref().is_real_file() {
Some(fmap.deref().name.clone()) Some(fmap.deref().name.clone())

View File

@ -253,11 +253,11 @@ impl Session {
sp: Span, sp: Span,
msg: ~str) { msg: ~str) {
let mut lints = self.lints.borrow_mut(); 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; } Some(arr) => { arr.push((lint, sp, msg)); return; }
None => {} None => {}
} }
lints.get().insert(id, vec!((lint, sp, msg))); lints.insert(id, vec!((lint, sp, msg)));
} }
pub fn next_node_id(&self) -> ast::NodeId { pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1) self.reserve_node_ids(1)

View File

@ -88,10 +88,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
} }
fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> { fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
{ self.cx.path.borrow_mut().push(i.ident);
let mut path = self.cx.path.borrow_mut();
path.get().push(i.ident);
}
debug!("current path: {}", debug!("current path: {}",
ast_util::path_name_i(self.cx.path.get().as_slice())); ast_util::path_name_i(self.cx.path.get().as_slice()));
@ -112,10 +109,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
ignore: is_ignored(&self.cx, i), ignore: is_ignored(&self.cx, i),
should_fail: should_fail(i) should_fail: should_fail(i)
}; };
{ self.cx.testfns.borrow_mut().push(test);
let mut testfns = self.cx.testfns.borrow_mut();
testfns.get().push(test);
}
// debug!("have {} test/bench functions", // debug!("have {} test/bench functions",
// cx.testfns.len()); // cx.testfns.len());
} }
@ -123,10 +117,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
} }
let res = fold::noop_fold_item(i, self); let res = fold::noop_fold_item(i, self);
{ self.cx.path.borrow_mut().pop();
let mut path = self.cx.path.borrow_mut();
path.get().pop();
}
res res
} }
@ -414,12 +405,9 @@ fn is_test_crate(krate: &ast::Crate) -> bool {
fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr { fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
let mut descs = Vec::new(); let mut descs = Vec::new();
{ debug!("building test vector from {} tests", cx.testfns.borrow().len());
let testfns = cx.testfns.borrow(); for test in cx.testfns.borrow().iter() {
debug!("building test vector from {} tests", testfns.get().len()); descs.push(mk_test_desc_and_fn_rec(cx, test));
for test in testfns.get().iter() {
descs.push(mk_test_desc_and_fn_rec(cx, test));
}
} }
let inner_expr = @ast::Expr { let inner_expr = @ast::Expr {

View File

@ -1831,13 +1831,11 @@ impl TypeNames {
} }
pub fn associate_type(&self, s: &str, t: &Type) { pub fn associate_type(&self, s: &str, t: &Type) {
let mut named_types = self.named_types.borrow_mut(); assert!(self.named_types.borrow_mut().insert(s.to_owned(), t.to_ref()));
assert!(named_types.get().insert(s.to_owned(), t.to_ref()));
} }
pub fn find_type(&self, s: &str) -> Option<Type> { pub fn find_type(&self, s: &str) -> Option<Type> {
let named_types = self.named_types.borrow(); self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
named_types.get().find_equiv(&s).map(|x| Type::from_ref(*x))
} }
pub fn type_to_str(&self, ty: Type) -> ~str { pub fn type_to_str(&self, ty: Type) -> ~str {

View File

@ -51,11 +51,10 @@ pub fn read_crates(sess: &Session,
}; };
visit_crate(&e, krate); visit_crate(&e, krate);
visit::walk_crate(&mut e, krate, ()); visit::walk_crate(&mut e, krate, ());
let crate_cache = e.crate_cache.borrow(); dump_crates(e.crate_cache.borrow().as_slice());
dump_crates(crate_cache.get().as_slice());
warn_if_multiple_versions(&mut e, warn_if_multiple_versions(&mut e,
sess.diagnostic(), sess.diagnostic(),
crate_cache.get().as_slice()); e.crate_cache.borrow().as_slice());
} }
impl<'a> visit::Visitor<()> for Env<'a> { impl<'a> visit::Visitor<()> for Env<'a> {
@ -268,8 +267,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
fn existing_match(e: &Env, crate_id: &CrateId, fn existing_match(e: &Env, crate_id: &CrateId,
hash: Option<&Svh>) -> Option<ast::CrateNum> { hash: Option<&Svh>) -> Option<ast::CrateNum> {
let crate_cache = e.crate_cache.borrow(); for c in e.crate_cache.borrow().iter() {
for c in crate_cache.get().iter() {
if !crate_id.matches(&c.crate_id) { continue } if !crate_id.matches(&c.crate_id) { continue }
match hash { match hash {
Some(hash) if *hash != c.hash => {} Some(hash) if *hash != c.hash => {}
@ -309,15 +307,12 @@ fn resolve_crate(e: &mut Env,
// Claim this crate number and cache it // Claim this crate number and cache it
let cnum = e.next_crate_num; let cnum = e.next_crate_num;
{ e.crate_cache.borrow_mut().push(cache_entry {
let mut crate_cache = e.crate_cache.borrow_mut(); cnum: cnum,
crate_cache.get().push(cache_entry { span: span,
cnum: cnum, hash: hash,
span: span, crate_id: crate_id,
hash: hash, });
crate_id: crate_id,
});
}
e.next_crate_num += 1; e.next_crate_num += 1;
// Maintain a reference to the top most crate. // Maintain a reference to the top most crate.

View File

@ -89,8 +89,7 @@ impl CStore {
} }
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> @crate_metadata { pub fn get_crate_data(&self, cnum: ast::CrateNum) -> @crate_metadata {
let metas = self.metas.borrow(); *self.metas.borrow().get(&cnum)
*metas.get().get(&cnum)
} }
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh { pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
@ -104,33 +103,30 @@ impl CStore {
} }
pub fn set_crate_data(&self, cnum: ast::CrateNum, data: @crate_metadata) { pub fn set_crate_data(&self, cnum: ast::CrateNum, data: @crate_metadata) {
let mut metas = self.metas.borrow_mut(); self.metas.borrow_mut().insert(cnum, data);
metas.get().insert(cnum, data);
} }
pub fn have_crate_data(&self, cnum: ast::CrateNum) -> bool { pub fn have_crate_data(&self, cnum: ast::CrateNum) -> bool {
let metas = self.metas.borrow(); self.metas.borrow().contains_key(&cnum)
metas.get().contains_key(&cnum)
} }
pub fn iter_crate_data(&self, i: |ast::CrateNum, @crate_metadata|) { pub fn iter_crate_data(&self, i: |ast::CrateNum, @crate_metadata|) {
let metas = self.metas.borrow(); for (&k, &v) in self.metas.borrow().iter() {
for (&k, &v) in metas.get().iter() {
i(k, v); i(k, v);
} }
} }
pub fn add_used_crate_source(&self, src: CrateSource) { pub fn add_used_crate_source(&self, src: CrateSource) {
let mut used_crate_sources = self.used_crate_sources.borrow_mut(); let mut used_crate_sources = self.used_crate_sources.borrow_mut();
if !used_crate_sources.get().contains(&src) { if !used_crate_sources.contains(&src) {
used_crate_sources.get().push(src); used_crate_sources.push(src);
} }
} }
pub fn get_used_crate_source(&self, cnum: ast::CrateNum) pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
-> Option<CrateSource> { -> Option<CrateSource> {
let mut used_crate_sources = self.used_crate_sources.borrow_mut(); self.used_crate_sources.borrow_mut()
used_crate_sources.get().iter().find(|source| source.cnum == cnum) .iter().find(|source| source.cnum == cnum)
.map(|source| source.clone()) .map(|source| source.clone())
} }
@ -158,18 +154,17 @@ impl CStore {
ordering: &mut Vec<ast::CrateNum>) { ordering: &mut Vec<ast::CrateNum>) {
if ordering.as_slice().contains(&cnum) { return } if ordering.as_slice().contains(&cnum) { return }
let meta = cstore.get_crate_data(cnum); 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); visit(cstore, dep, ordering);
} }
ordering.push(cnum); ordering.push(cnum);
}; };
for (&num, _) in self.metas.borrow().get().iter() { for (&num, _) in self.metas.borrow().iter() {
visit(self, num, &mut ordering); visit(self, num, &mut ordering);
} }
ordering.as_mut_slice().reverse(); ordering.as_mut_slice().reverse();
let ordering = ordering.as_slice(); let ordering = ordering.as_slice();
let used_crate_sources = self.used_crate_sources.borrow(); let mut libs = self.used_crate_sources.borrow()
let mut libs = used_crate_sources.get()
.iter() .iter()
.map(|src| (src.cnum, match prefer { .map(|src| (src.cnum, match prefer {
RequireDynamic => src.dylib.clone(), RequireDynamic => src.dylib.clone(),
@ -184,8 +179,7 @@ impl CStore {
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) { pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {
assert!(!lib.is_empty()); assert!(!lib.is_empty());
let mut used_libraries = self.used_libraries.borrow_mut(); self.used_libraries.borrow_mut().push((lib, kind));
used_libraries.get().push((lib, kind));
} }
pub fn get_used_libraries<'a>(&'a self) pub fn get_used_libraries<'a>(&'a self)
@ -194,9 +188,8 @@ impl CStore {
} }
pub fn add_used_link_args(&self, args: &str) { 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(' ') { for s in args.split(' ') {
used_link_args.get().push(s.to_owned()); self.used_link_args.borrow_mut().push(s.to_owned());
} }
} }
@ -207,14 +200,12 @@ impl CStore {
pub fn add_extern_mod_stmt_cnum(&self, pub fn add_extern_mod_stmt_cnum(&self,
emod_id: ast::NodeId, emod_id: ast::NodeId,
cnum: ast::CrateNum) { cnum: ast::CrateNum) {
let mut extern_mod_crate_map = self.extern_mod_crate_map.borrow_mut(); self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
extern_mod_crate_map.get().insert(emod_id, cnum);
} }
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
-> Option<ast::CrateNum> { -> Option<ast::CrateNum> {
let extern_mod_crate_map = self.extern_mod_crate_map.borrow(); self.extern_mod_crate_map.borrow().find(&emod_id).map(|x| *x)
extern_mod_crate_map.get().find(&emod_id).map(|x| *x)
} }
} }

View File

@ -1187,8 +1187,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
return ast::DefId { krate: cdata.cnum, node: did.node }; return ast::DefId { krate: cdata.cnum, node: did.node };
} }
let cnum_map = cdata.cnum_map.borrow(); match cdata.cnum_map.borrow().find(&did.krate) {
match cnum_map.get().find(&did.krate) {
Some(&n) => { Some(&n) => {
ast::DefId { ast::DefId {
krate: n, krate: n,

View File

@ -270,8 +270,7 @@ fn encode_symbol(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
id: NodeId) { id: NodeId) {
ebml_w.start_tag(tag_items_data_item_symbol); ebml_w.start_tag(tag_items_data_item_symbol);
let item_symbols = ecx.item_symbols.borrow(); match ecx.item_symbols.borrow().find(&id) {
match item_symbols.get().find(&id) {
Some(x) => { Some(x) => {
debug!("encode_symbol(id={:?}, str={})", id, *x); debug!("encode_symbol(id={:?}, str={})", id, *x);
ebml_w.writer.write(x.as_bytes()); ebml_w.writer.write(x.as_bytes());
@ -334,13 +333,10 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
ast::DefId { krate: LOCAL_CRATE, node: id }); ast::DefId { krate: LOCAL_CRATE, node: id });
for variant in variants.iter() { for variant in variants.iter() {
let def_id = local_def(variant.node.id); let def_id = local_def(variant.node.id);
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: variant.node.id as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: variant.node.id as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
match variant.node.kind { match variant.node.kind {
@ -415,11 +411,9 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2) exp: &middle::resolve::Export2)
-> bool { -> bool {
let inherent_impls = ecx.tcx.inherent_impls.borrow(); match ecx.tcx.inherent_impls.borrow().find(&exp.def_id) {
match inherent_impls.get().find(&exp.def_id) {
Some(implementations) => { Some(implementations) => {
let implementations = implementations.borrow(); for &base_impl in implementations.borrow().iter() {
for &base_impl in implementations.get().iter() {
for &m in base_impl.methods.iter() { for &m in base_impl.methods.iter() {
if m.explicit_self == ast::SelfStatic { if m.explicit_self == ast::SelfStatic {
encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident); encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident);
@ -437,8 +431,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2) exp: &middle::resolve::Export2)
-> bool { -> bool {
let trait_methods_cache = ecx.tcx.trait_methods_cache.borrow(); match ecx.tcx.trait_methods_cache.borrow().find(&exp.def_id) {
match trait_methods_cache.get().find(&exp.def_id) {
Some(methods) => { Some(methods) => {
for &m in methods.iter() { for &m in methods.iter() {
if m.explicit_self == ast::SelfStatic { if m.explicit_self == ast::SelfStatic {
@ -538,8 +531,7 @@ fn encode_reexports(ecx: &EncodeContext,
id: NodeId, id: NodeId,
path: PathElems) { path: PathElems) {
debug!("(encoding info for module) encoding reexports for {}", id); debug!("(encoding info for module) encoding reexports for {}", id);
let reexports2 = ecx.reexports2.borrow(); match ecx.reexports2.borrow().find(&id) {
match reexports2.get().find(&id) {
Some(ref exports) => { Some(ref exports) => {
debug!("(encoding info for module) found reexports for {}", id); debug!("(encoding info for module) found reexports for {}", id);
for exp in exports.iter() { for exp in exports.iter() {
@ -703,13 +695,10 @@ fn encode_info_for_struct(ecx: &EncodeContext,
let id = field.node.id; let id = field.node.id;
index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()}); index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()});
{ global_index.borrow_mut().push(entry {
let mut global_index = global_index.borrow_mut(); val: id as i64,
global_index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: id as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
debug!("encode_info_for_struct: doing {} {}", debug!("encode_info_for_struct: doing {} {}",
token::get_ident(nm), id); token::get_ident(nm), id);
@ -728,13 +717,10 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
ctor_id: NodeId, ctor_id: NodeId,
index: @RefCell<Vec<entry<i64>> >, index: @RefCell<Vec<entry<i64>> >,
struct_id: NodeId) { struct_id: NodeId) {
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: ctor_id as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: ctor_id as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id)); encode_def_id(ebml_w, local_def(ctor_id));
@ -746,8 +732,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
ecx.tcx.map.with_path(ctor_id, |path| encode_path(ebml_w, path)); ecx.tcx.map.with_path(ctor_id, |path| encode_path(ebml_w, path));
encode_parent_item(ebml_w, local_def(struct_id)); encode_parent_item(ebml_w, local_def(struct_id));
let item_symbols = ecx.item_symbols.borrow(); if ecx.item_symbols.borrow().contains_key(&ctor_id) {
if item_symbols.get().contains_key(&ctor_id) {
encode_symbol(ecx, ebml_w, ctor_id); encode_symbol(ecx, ebml_w, ctor_id);
} }
@ -853,12 +838,10 @@ fn should_inline(attrs: &[Attribute]) -> bool {
fn encode_inherent_implementations(ecx: &EncodeContext, fn encode_inherent_implementations(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
def_id: DefId) { def_id: DefId) {
let inherent_impls = ecx.tcx.inherent_impls.borrow(); match ecx.tcx.inherent_impls.borrow().find(&def_id) {
match inherent_impls.get().find(&def_id) {
None => {} None => {}
Some(&implementations) => { Some(&implementations) => {
let implementations = implementations.borrow(); for implementation in implementations.borrow().iter() {
for implementation in implementations.get().iter() {
ebml_w.start_tag(tag_items_data_item_inherent_impl); ebml_w.start_tag(tag_items_data_item_inherent_impl);
encode_def_id(ebml_w, implementation.did); encode_def_id(ebml_w, implementation.did);
ebml_w.end_tag(); ebml_w.end_tag();
@ -871,12 +854,10 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
fn encode_extension_implementations(ecx: &EncodeContext, fn encode_extension_implementations(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
trait_def_id: DefId) { trait_def_id: DefId) {
let trait_impls = ecx.tcx.trait_impls.borrow(); match ecx.tcx.trait_impls.borrow().find(&trait_def_id) {
match trait_impls.get().find(&trait_def_id) {
None => {} None => {}
Some(&implementations) => { Some(&implementations) => {
let implementations = implementations.borrow(); for implementation in implementations.borrow().iter() {
for implementation in implementations.get().iter() {
ebml_w.start_tag(tag_items_data_item_extension_impl); ebml_w.start_tag(tag_items_data_item_extension_impl);
encode_def_id(ebml_w, implementation.did); encode_def_id(ebml_w, implementation.did);
ebml_w.end_tag(); ebml_w.end_tag();
@ -895,8 +876,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
fn add_to_index(item: &Item, ebml_w: &writer::Encoder, fn add_to_index(item: &Item, ebml_w: &writer::Encoder,
index: @RefCell<Vec<entry<i64>> >) { index: @RefCell<Vec<entry<i64>> >) {
let mut index = index.borrow_mut(); index.borrow_mut().push(entry {
index.get().push(entry {
val: item.id as i64, val: item.id as i64,
pos: ebml_w.writer.tell().unwrap(), pos: ebml_w.writer.tell().unwrap(),
}); });
@ -921,7 +901,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ebml_w, item.ident.name); encode_name(ebml_w, item.ident.name);
encode_path(ebml_w, path); encode_path(ebml_w, path);
let inlineable = !ecx.non_inlineable_statics.borrow().get().contains(&item.id); let inlineable = !ecx.non_inlineable_statics.borrow().contains(&item.id);
if inlineable { if inlineable {
(ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item));
@ -1065,7 +1045,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// We need to encode information about the default methods we // We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure. // have inherited, so we drive this based on the impl structure.
let impls = tcx.impls.borrow(); let impls = tcx.impls.borrow();
let imp = impls.get().get(&def_id); let imp = impls.get(&def_id);
add_to_index(item, ebml_w, index); add_to_index(item, ebml_w, index);
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
@ -1108,13 +1088,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
Some(*ast_methods.get(i)) Some(*ast_methods.get(i))
} else { None }; } else { None };
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: m.def_id.node as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: m.def_id.node as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
encode_info_for_method(ecx, encode_info_for_method(ecx,
ebml_w, ebml_w,
*m, *m,
@ -1169,13 +1146,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
let method_ty = ty::method(tcx, method_def_id); let method_ty = ty::method(tcx, method_def_id);
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: method_def_id.node as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: method_def_id.node as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
@ -1242,13 +1216,10 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
index: @RefCell<Vec<entry<i64>> >, index: @RefCell<Vec<entry<i64>> >,
path: PathElems, path: PathElems,
abi: AbiSet) { abi: AbiSet) {
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: nitem.id as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: nitem.id as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(nitem.id)); encode_def_id(ebml_w, local_def(nitem.id));
@ -1347,13 +1318,10 @@ fn encode_info_for_items(ecx: &EncodeContext,
-> Vec<entry<i64>> { -> Vec<entry<i64>> {
let index = @RefCell::new(Vec::new()); let index = @RefCell::new(Vec::new());
ebml_w.start_tag(tag_items_data); ebml_w.start_tag(tag_items_data);
{ index.borrow_mut().push(entry {
let mut index = index.borrow_mut(); val: CRATE_NODE_ID as i64,
index.get().push(entry { pos: ebml_w.writer.tell().unwrap(),
val: CRATE_NODE_ID as i64, });
pos: ebml_w.writer.tell().unwrap(),
});
}
encode_info_for_mod(ecx, encode_info_for_mod(ecx,
ebml_w, ebml_w,
&krate.module, &krate.module,
@ -1390,8 +1358,7 @@ fn create_index<T:Clone + Hash + 'static>(
} }
for elt in index.iter() { for elt in index.iter() {
let h = hash::hash(&elt.val) as uint; let h = hash::hash(&elt.val) as uint;
let mut bucket = buckets.get_mut(h % 256).borrow_mut(); buckets.get_mut(h % 256).borrow_mut().push((*elt).clone());
bucket.get().push((*elt).clone());
} }
let mut buckets_frozen = Vec::new(); let mut buckets_frozen = Vec::new();
@ -1584,9 +1551,8 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) { fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_native_libraries); ebml_w.start_tag(tag_native_libraries);
let used_libraries = ecx.tcx.sess.cstore.get_used_libraries(); for &(ref lib, kind) in ecx.tcx.sess.cstore.get_used_libraries()
let used_libraries = used_libraries.borrow(); .borrow().iter() {
for &(ref lib, kind) in used_libraries.get().iter() {
match kind { match kind {
cstore::NativeStatic => {} // these libraries are not propagated cstore::NativeStatic => {} // these libraries are not propagated
cstore::NativeFramework | cstore::NativeUnknown => { cstore::NativeFramework | cstore::NativeUnknown => {
@ -1609,8 +1575,7 @@ fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
} }
fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) { fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
let ptr = ecx.tcx.sess.macro_registrar_fn.borrow(); match *ecx.tcx.sess.macro_registrar_fn.borrow() {
match *ptr.get() {
Some(did) => { Some(did) => {
ebml_w.start_tag(tag_macro_registrar_fn); ebml_w.start_tag(tag_macro_registrar_fn);
encode_def_id(ebml_w, did); encode_def_id(ebml_w, did);
@ -1665,8 +1630,7 @@ impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> {
match item.node { match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => { ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = self.ecx.tcx.def_map; let def_map = self.ecx.tcx.def_map;
let def_map = def_map.borrow(); let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let trait_def = def_map.get().get_copy(&trait_ref.ref_id);
let def_id = ast_util::def_id_of_def(trait_def); let def_id = ast_util::def_id_of_def(trait_def);
// Load eagerly if this is an implementation of the Drop trait // Load eagerly if this is an implementation of the Drop trait

View File

@ -36,10 +36,9 @@ impl<'a> FileSearch<'a> {
let mut visited_dirs = HashSet::new(); let mut visited_dirs = HashSet::new();
let mut found = false; let mut found = false;
let addl_lib_search_paths = self.addl_lib_search_paths.borrow();
debug!("filesearch: searching additional lib search paths [{:?}]", debug!("filesearch: searching additional lib search paths [{:?}]",
addl_lib_search_paths.get().len()); self.addl_lib_search_paths.borrow().len());
for path in addl_lib_search_paths.get().iter() { for path in self.addl_lib_search_paths.borrow().iter() {
match f(path) { match f(path) {
FileMatches => found = true, FileMatches => found = true,
FileDoesntMatch => () FileDoesntMatch => ()

View File

@ -382,23 +382,17 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
pos: pos, pos: pos,
len: len }; len: len };
let tt_opt = { match st.tcx.rcache.borrow().find_copy(&key) {
let rcache = st.tcx.rcache.borrow();
rcache.get().find_copy(&key)
};
match tt_opt {
Some(tt) => return tt, Some(tt) => return tt,
None => { None => {}
let mut ps = PState {
pos: pos,
.. *st
};
let tt = parse_ty(&mut ps, |x,y| conv(x,y));
let mut rcache = st.tcx.rcache.borrow_mut();
rcache.get().insert(key, tt);
return tt;
}
} }
let mut ps = PState {
pos: pos,
.. *st
};
let tt = parse_ty(&mut ps, |x,y| conv(x,y));
st.tcx.rcache.borrow_mut().insert(key, tt);
return tt;
} }
'"' => { '"' => {
let _ = parse_def(st, TypeWithId, |x,y| conv(x,y)); let _ = parse_def(st, TypeWithId, |x,y| conv(x,y));

View File

@ -63,37 +63,27 @@ fn mywrite(w: &mut MemWriter, fmt: &fmt::Arguments) {
pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) { pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
match cx.abbrevs { match cx.abbrevs {
ac_no_abbrevs => { ac_no_abbrevs => {
let result_str_opt; let result_str_opt = cx.tcx.short_names_cache.borrow()
{ .find(&t)
let short_names_cache = cx.tcx.short_names_cache.borrow(); .map(|result| {
result_str_opt = short_names_cache.get() (*result).clone()
.find(&t) });
.map(|result| {
(*result).clone()
});
}
let result_str = match result_str_opt { let result_str = match result_str_opt {
Some(s) => s, Some(s) => s,
None => { None => {
let wr = &mut MemWriter::new(); let wr = &mut MemWriter::new();
enc_sty(wr, cx, &ty::get(t).sty); enc_sty(wr, cx, &ty::get(t).sty);
let s = str::from_utf8(wr.get_ref()).unwrap(); let s = str::from_utf8(wr.get_ref()).unwrap();
let mut short_names_cache = cx.tcx cx.tcx.short_names_cache.borrow_mut().insert(t, s.to_str());
.short_names_cache
.borrow_mut();
short_names_cache.get().insert(t, s.to_str());
s.to_str() s.to_str()
} }
}; };
w.write(result_str.as_bytes()); w.write(result_str.as_bytes());
} }
ac_use_abbrevs(abbrevs) => { ac_use_abbrevs(abbrevs) => {
{ match abbrevs.borrow_mut().find(&t) {
let mut abbrevs = abbrevs.borrow_mut(); Some(a) => { w.write(a.s.as_bytes()); return; }
match abbrevs.get().find(&t) { None => {}
Some(a) => { w.write(a.s.as_bytes()); return; }
None => {}
}
} }
let pos = w.tell().unwrap(); let pos = w.tell().unwrap();
enc_sty(w, cx, &ty::get(t).sty); enc_sty(w, cx, &ty::get(t).sty);
@ -112,10 +102,7 @@ pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
let a = ty_abbrev { pos: pos as uint, let a = ty_abbrev { pos: pos as uint,
len: len as uint, len: len as uint,
s: s }; s: s };
{ abbrevs.borrow_mut().insert(t, a);
let mut abbrevs = abbrevs.borrow_mut();
abbrevs.get().insert(t, a);
}
} }
return; return;
} }

View File

@ -958,89 +958,63 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
debug!("Encoding side tables for id {}", id); debug!("Encoding side tables for id {}", id);
{ for def in tcx.def_map.borrow().find(&id).iter() {
let def_map = tcx.def_map.borrow(); ebml_w.tag(c::tag_table_def, |ebml_w| {
let r = def_map.get().find(&id); ebml_w.id(id);
for def in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w));
ebml_w.tag(c::tag_table_def, |ebml_w| { })
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w));
})
}
} }
{ for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() {
let node_types = tcx.node_types.borrow(); ebml_w.tag(c::tag_table_node_type, |ebml_w| {
let r = node_types.get().find(&(id as uint)); ebml_w.id(id);
for &ty in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_node_type, |ebml_w| { ebml_w.emit_ty(ecx, *ty);
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_ty(ecx, *ty);
})
}) })
} })
} }
{ for tys in tcx.node_type_substs.borrow().find(&id).iter() {
let node_type_substs = tcx.node_type_substs.borrow(); ebml_w.tag(c::tag_table_node_type_subst, |ebml_w| {
let r = node_type_substs.get().find(&id); ebml_w.id(id);
for tys in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_node_type_subst, |ebml_w| { ebml_w.emit_tys(ecx, tys.as_slice())
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_tys(ecx, tys.as_slice())
})
}) })
} })
} }
{ for &fv in tcx.freevars.borrow().find(&id).iter() {
let freevars = tcx.freevars.borrow(); ebml_w.tag(c::tag_table_freevars, |ebml_w| {
let r = freevars.get().find(&id); ebml_w.id(id);
for &fv in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_freevars, |ebml_w| { ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| {
ebml_w.id(id); encode_freevar_entry(ebml_w, *fv_entry)
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| {
encode_freevar_entry(ebml_w, *fv_entry)
})
}) })
}) })
} })
} }
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
{ for &tpbt in tcx.tcache.borrow().find(&lid).iter() {
let tcache = tcx.tcache.borrow(); ebml_w.tag(c::tag_table_tcache, |ebml_w| {
let r = tcache.get().find(&lid); ebml_w.id(id);
for &tpbt in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_tcache, |ebml_w| { ebml_w.emit_tpbt(ecx, tpbt.clone());
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_tpbt(ecx, tpbt.clone());
})
}) })
} })
} }
{ for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
let r = { ebml_w.tag(c::tag_table_param_defs, |ebml_w| {
let ty_param_defs = tcx.ty_param_defs.borrow(); ebml_w.id(id);
ty_param_defs.get().find(&id).map(|def| *def) ebml_w.tag(c::tag_table_val, |ebml_w| {
}; ebml_w.emit_type_param_def(ecx, type_param_def)
for type_param_def in r.iter() {
ebml_w.tag(c::tag_table_param_defs, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_type_param_def(ecx, type_param_def)
})
}) })
} })
} }
let method_call = MethodCall::expr(id); let method_call = MethodCall::expr(id);
for &method in maps.method_map.borrow().get().find(&method_call).iter() { for &method in maps.method_map.borrow().find(&method_call).iter() {
ebml_w.tag(c::tag_table_method_map, |ebml_w| { ebml_w.tag(c::tag_table_method_map, |ebml_w| {
ebml_w.id(id); ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.tag(c::tag_table_val, |ebml_w| {
@ -1049,33 +1023,25 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}) })
} }
{ for &dr in maps.vtable_map.borrow().find(&id).iter() {
let vtable_map = maps.vtable_map.borrow(); ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
let r = vtable_map.get().find(&id); ebml_w.id(id);
for &dr in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { encode_vtable_res(ecx, ebml_w, *dr);
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
encode_vtable_res(ecx, ebml_w, *dr);
})
}) })
} })
} }
{ for adj in tcx.adjustments.borrow().find(&id).iter() {
let adjustments = tcx.adjustments.borrow(); ebml_w.tag(c::tag_table_adjustments, |ebml_w| {
let r = adjustments.get().find(&id); ebml_w.id(id);
for adj in r.iter() { ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.tag(c::tag_table_adjustments, |ebml_w| { ebml_w.emit_auto_adjustment(ecx, **adj);
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_auto_adjustment(ecx, **adj);
})
}) })
} })
} }
for &cap_vars in maps.capture_map.borrow().get().find(&id).iter() { for &cap_vars in maps.capture_map.borrow().find(&id).iter() {
ebml_w.tag(c::tag_table_capture_map, |ebml_w| { ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
ebml_w.id(id); ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.tag(c::tag_table_val, |ebml_w| {
@ -1343,71 +1309,54 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
match value { match value {
c::tag_table_def => { c::tag_table_def => {
let def = decode_def(xcx, val_doc); let def = decode_def(xcx, val_doc);
let mut def_map = dcx.tcx.def_map.borrow_mut(); dcx.tcx.def_map.borrow_mut().insert(id, def);
def_map.get().insert(id, def);
} }
c::tag_table_node_type => { c::tag_table_node_type => {
let ty = val_dsr.read_ty(xcx); let ty = val_dsr.read_ty(xcx);
debug!("inserting ty for node {:?}: {}", debug!("inserting ty for node {:?}: {}",
id, ty_to_str(dcx.tcx, ty)); id, ty_to_str(dcx.tcx, ty));
let mut node_types = dcx.tcx.node_types.borrow_mut(); dcx.tcx.node_types.borrow_mut().insert(id as uint, ty);
node_types.get().insert(id as uint, ty);
} }
c::tag_table_node_type_subst => { c::tag_table_node_type_subst => {
let tys = val_dsr.read_tys(xcx); let tys = val_dsr.read_tys(xcx);
let mut node_type_substs = dcx.tcx dcx.tcx.node_type_substs.borrow_mut().insert(id, tys);
.node_type_substs
.borrow_mut();
node_type_substs.get().insert(id, tys);
} }
c::tag_table_freevars => { c::tag_table_freevars => {
let fv_info = @val_dsr.read_to_vec(|val_dsr| { let fv_info = @val_dsr.read_to_vec(|val_dsr| {
@val_dsr.read_freevar_entry(xcx) @val_dsr.read_freevar_entry(xcx)
}).move_iter().collect(); }).move_iter().collect();
let mut freevars = dcx.tcx.freevars.borrow_mut(); dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
freevars.get().insert(id, fv_info);
} }
c::tag_table_tcache => { c::tag_table_tcache => {
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx); let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
let mut tcache = dcx.tcx.tcache.borrow_mut(); dcx.tcx.tcache.borrow_mut().insert(lid, tpbt);
tcache.get().insert(lid, tpbt);
} }
c::tag_table_param_defs => { c::tag_table_param_defs => {
let bounds = val_dsr.read_type_param_def(xcx); let bounds = val_dsr.read_type_param_def(xcx);
let mut ty_param_defs = dcx.tcx dcx.tcx.ty_param_defs.borrow_mut().insert(id, bounds);
.ty_param_defs
.borrow_mut();
ty_param_defs.get().insert(id, bounds);
} }
c::tag_table_method_map => { c::tag_table_method_map => {
let method = val_dsr.read_method_callee(xcx); let method = val_dsr.read_method_callee(xcx);
let method_call = MethodCall::expr(id); let method_call = MethodCall::expr(id);
dcx.maps.method_map.borrow_mut().get().insert(method_call, method); dcx.maps.method_map.borrow_mut().insert(method_call, method);
} }
c::tag_table_vtable_map => { c::tag_table_vtable_map => {
let vtable_res = let vtable_res =
val_dsr.read_vtable_res(xcx.dcx.tcx, val_dsr.read_vtable_res(xcx.dcx.tcx,
xcx.dcx.cdata); xcx.dcx.cdata);
let mut vtable_map = dcx.maps.vtable_map.borrow_mut(); dcx.maps.vtable_map.borrow_mut().insert(id, vtable_res);
vtable_map.get().insert(id, vtable_res);
} }
c::tag_table_adjustments => { c::tag_table_adjustments => {
let adj: @ty::AutoAdjustment = @val_dsr.read_auto_adjustment(xcx); let adj: @ty::AutoAdjustment = @val_dsr.read_auto_adjustment(xcx);
let mut adjustments = dcx.tcx dcx.tcx.adjustments.borrow_mut().insert(id, adj);
.adjustments
.borrow_mut();
adjustments.get().insert(id, adj);
} }
c::tag_table_capture_map => { c::tag_table_capture_map => {
let cvars = let cvars =
val_dsr.read_to_vec(|val_dsr| val_dsr.read_capture_var(xcx)) val_dsr.read_to_vec(|val_dsr| val_dsr.read_capture_var(xcx))
.move_iter() .move_iter()
.collect(); .collect();
let mut capture_map = dcx.maps dcx.maps.capture_map.borrow_mut().insert(id, Rc::new(cvars));
.capture_map
.borrow_mut();
capture_map.get().insert(id, Rc::new(cvars));
} }
_ => { _ => {
xcx.dcx.tcx.sess.bug( xcx.dcx.tcx.sess.bug(

View File

@ -378,11 +378,7 @@ impl<'a> CheckLoanCtxt<'a> {
pub fn check_assignment(&self, expr: &ast::Expr) { pub fn check_assignment(&self, expr: &ast::Expr) {
// We don't use cat_expr() here because we don't want to treat // We don't use cat_expr() here because we don't want to treat
// auto-ref'd parameters in overloaded operators as rvalues. // auto-ref'd parameters in overloaded operators as rvalues.
let adj = { let cmt = match self.bccx.tcx.adjustments.borrow().find_copy(&expr.id) {
let adjustments = self.bccx.tcx.adjustments.borrow();
adjustments.get().find_copy(&expr.id)
};
let cmt = match adj {
None => self.bccx.cat_expr_unadjusted(expr), None => self.bccx.cat_expr_unadjusted(expr),
Some(adj) => self.bccx.cat_expr_autoderefd(expr, adj) Some(adj) => self.bccx.cat_expr_autoderefd(expr, adj)
}; };
@ -452,10 +448,7 @@ impl<'a> CheckLoanCtxt<'a> {
cmt.repr(this.tcx())); cmt.repr(this.tcx()));
match cmt.cat { match cmt.cat {
mc::cat_local(id) | mc::cat_arg(id) => { mc::cat_local(id) | mc::cat_arg(id) => {
let mut used_mut_nodes = this.tcx() this.tcx().used_mut_nodes.borrow_mut().insert(id);
.used_mut_nodes
.borrow_mut();
used_mut_nodes.get().insert(id);
return; return;
} }
@ -839,11 +832,11 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
this.check_call(expr, None, expr.span, args.as_slice()); this.check_call(expr, None, expr.span, args.as_slice());
} }
ast::ExprIndex(_, rval) | ast::ExprBinary(_, _, rval) ast::ExprIndex(_, rval) | ast::ExprBinary(_, _, rval)
if method_map.get().contains_key(&MethodCall::expr(expr.id)) => { if method_map.contains_key(&MethodCall::expr(expr.id)) => {
this.check_call(expr, None, expr.span, [rval]); this.check_call(expr, None, expr.span, [rval]);
} }
ast::ExprUnary(_, _) | ast::ExprIndex(_, _) ast::ExprUnary(_, _) | ast::ExprIndex(_, _)
if method_map.get().contains_key(&MethodCall::expr(expr.id)) => { if method_map.contains_key(&MethodCall::expr(expr.id)) => {
this.check_call(expr, None, expr.span, []); this.check_call(expr, None, expr.span, []);
} }
ast::ExprInlineAsm(ref ia) => { ast::ExprInlineAsm(ref ia) => {

View File

@ -237,8 +237,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs}; let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
let root_info = RootInfo {scope: root_scope}; let root_info = RootInfo {scope: root_scope};
let mut root_map = self.bccx.root_map.borrow_mut(); self.bccx.root_map.borrow_mut().insert(rm_key, root_info);
root_map.get().insert(rm_key, root_info);
debug!("root_key: {:?} root_info: {:?}", rm_key, root_info); debug!("root_key: {:?} root_info: {:?}", rm_key, root_info);
Ok(()) Ok(())

View File

@ -195,7 +195,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
this.id_range.add(ex.id); this.id_range.add(ex.id);
// If this expression is borrowed, have to ensure it remains valid: // If this expression is borrowed, have to ensure it remains valid:
for &adjustments in tcx.adjustments.borrow().get().find(&ex.id).iter() { for &adjustments in tcx.adjustments.borrow().find(&ex.id).iter() {
this.guarantee_adjustments(ex, *adjustments); this.guarantee_adjustments(ex, *adjustments);
} }
@ -255,7 +255,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
ast::ExprIndex(_, arg) | ast::ExprIndex(_, arg) |
ast::ExprBinary(_, _, arg) ast::ExprBinary(_, _, arg)
if method_map.get().contains_key(&MethodCall::expr(ex.id)) => { if method_map.contains_key(&MethodCall::expr(ex.id)) => {
// Arguments in method calls are always passed by ref. // Arguments in method calls are always passed by ref.
// //
// Currently these do not use adjustments, so we have to // Currently these do not use adjustments, so we have to
@ -343,7 +343,7 @@ impl<'a> GatherLoanCtxt<'a> {
autoderefs: uint) { autoderefs: uint) {
let method_map = self.bccx.method_map.borrow(); let method_map = self.bccx.method_map.borrow();
for i in range(0, autoderefs) { for i in range(0, autoderefs) {
match method_map.get().find(&MethodCall::autoderef(expr.id, i as u32)) { match method_map.find(&MethodCall::autoderef(expr.id, i as u32)) {
Some(method) => { Some(method) => {
// Treat overloaded autoderefs as if an AutoRef adjustment // Treat overloaded autoderefs as if an AutoRef adjustment
// was applied on the base type, as that is always the case. // was applied on the base type, as that is always the case.
@ -466,8 +466,8 @@ impl<'a> GatherLoanCtxt<'a> {
// Lookup the kind of borrow the callee requires // Lookup the kind of borrow the callee requires
let upvar_id = ty::UpvarId { var_id: var_id, let upvar_id = ty::UpvarId { var_id: var_id,
closure_expr_id: closure_expr.id }; closure_expr_id: closure_expr.id };
let upvar_borrow_map = self.tcx().upvar_borrow_map.borrow(); let upvar_borrow = self.tcx().upvar_borrow_map.borrow()
let upvar_borrow = upvar_borrow_map.get().get_copy(&upvar_id); .get_copy(&upvar_id);
self.guarantee_valid_kind(closure_expr.id, self.guarantee_valid_kind(closure_expr.id,
closure_expr.span, closure_expr.span,
@ -750,10 +750,7 @@ impl<'a> GatherLoanCtxt<'a> {
match *loan_path { match *loan_path {
LpVar(local_id) => { LpVar(local_id) => {
let mut used_mut_nodes = self.tcx() self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
.used_mut_nodes
.borrow_mut();
used_mut_nodes.get().insert(local_id);
} }
LpExtend(base, mc::McInherited, _) => { LpExtend(base, mc::McInherited, _) => {
self.mark_loan_path_as_mutated(base); self.mark_loan_path_as_mutated(base);

View File

@ -574,7 +574,7 @@ impl<'a> BorrowckCtxt<'a> {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { let (expr_ty, expr_span) = match self.tcx.map.find(move.id) {
Some(ast_map::NodeExpr(expr)) => { Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr, (ty::expr_ty_adjusted(self.tcx, expr,
self.method_map.borrow().get()), expr.span) &*self.method_map.borrow()), expr.span)
} }
r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr", r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr",
move.id, r)) move.id, r))
@ -601,7 +601,7 @@ impl<'a> BorrowckCtxt<'a> {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { let (expr_ty, expr_span) = match self.tcx.map.find(move.id) {
Some(ast_map::NodeExpr(expr)) => { Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr, (ty::expr_ty_adjusted(self.tcx, expr,
self.method_map.borrow().get()), expr.span) &*self.method_map.borrow()), expr.span)
} }
r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr", r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr",
move.id, r)) move.id, r))
@ -942,16 +942,15 @@ impl<'a> mc::Typer for TcxTyper<'a> {
} }
fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t> { fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t> {
self.method_map.borrow().get().find(&method_call).map(|method| method.ty) self.method_map.borrow().find(&method_call).map(|method| method.ty)
} }
fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> { fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> {
let adjustments = self.tcx.adjustments.borrow(); self.tcx.adjustments.borrow().find_copy(&id)
adjustments.get().find_copy(&id)
} }
fn is_method_call(&mut self, id: ast::NodeId) -> bool { fn is_method_call(&mut self, id: ast::NodeId) -> bool {
self.method_map.borrow().get().contains_key(&typeck::MethodCall::expr(id)) self.method_map.borrow().contains_key(&typeck::MethodCall::expr(id))
} }
fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> { fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> {
@ -959,7 +958,6 @@ impl<'a> mc::Typer for TcxTyper<'a> {
} }
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
let upvar_borrow_map = self.tcx.upvar_borrow_map.borrow(); self.tcx.upvar_borrow_map.borrow().get_copy(&id)
upvar_borrow_map.get().get_copy(&id)
} }
} }

View File

@ -183,48 +183,40 @@ impl MoveData {
} }
fn path_loan_path(&self, index: MovePathIndex) -> @LoanPath { fn path_loan_path(&self, index: MovePathIndex) -> @LoanPath {
let paths = self.paths.borrow(); self.paths.borrow().get(index.get()).loan_path
paths.get().get(index.get()).loan_path
} }
fn path_parent(&self, index: MovePathIndex) -> MovePathIndex { fn path_parent(&self, index: MovePathIndex) -> MovePathIndex {
let paths = self.paths.borrow(); self.paths.borrow().get(index.get()).parent
paths.get().get(index.get()).parent
} }
fn path_first_move(&self, index: MovePathIndex) -> MoveIndex { fn path_first_move(&self, index: MovePathIndex) -> MoveIndex {
let paths = self.paths.borrow(); self.paths.borrow().get(index.get()).first_move
paths.get().get(index.get()).first_move
} }
fn path_first_child(&self, index: MovePathIndex) -> MovePathIndex { fn path_first_child(&self, index: MovePathIndex) -> MovePathIndex {
let paths = self.paths.borrow(); self.paths.borrow().get(index.get()).first_child
paths.get().get(index.get()).first_child
} }
fn path_next_sibling(&self, index: MovePathIndex) -> MovePathIndex { fn path_next_sibling(&self, index: MovePathIndex) -> MovePathIndex {
let paths = self.paths.borrow(); self.paths.borrow().get(index.get()).next_sibling
paths.get().get(index.get()).next_sibling
} }
fn set_path_first_move(&self, fn set_path_first_move(&self,
index: MovePathIndex, index: MovePathIndex,
first_move: MoveIndex) { first_move: MoveIndex) {
let mut paths = self.paths.borrow_mut(); self.paths.borrow_mut().get_mut(index.get()).first_move = first_move
paths.get().get_mut(index.get()).first_move = first_move
} }
fn set_path_first_child(&self, fn set_path_first_child(&self,
index: MovePathIndex, index: MovePathIndex,
first_child: MovePathIndex) { first_child: MovePathIndex) {
let mut paths = self.paths.borrow_mut(); self.paths.borrow_mut().get_mut(index.get()).first_child = first_child
paths.get().get_mut(index.get()).first_child = first_child
} }
fn move_next_move(&self, index: MoveIndex) -> MoveIndex { fn move_next_move(&self, index: MoveIndex) -> MoveIndex {
//! Type safe indexing operator //! Type safe indexing operator
let moves = self.moves.borrow(); self.moves.borrow().get(index.get()).next_move
moves.get().get(index.get()).next_move
} }
fn is_var_path(&self, index: MovePathIndex) -> bool { fn is_var_path(&self, index: MovePathIndex) -> bool {
@ -241,22 +233,18 @@ impl MoveData {
* base paths that do not yet have an index. * base paths that do not yet have an index.
*/ */
{ match self.path_map.borrow().find(&lp) {
let path_map = self.path_map.borrow(); Some(&index) => {
match path_map.get().find(&lp) { return index;
Some(&index) => {
return index;
}
None => {}
} }
None => {}
} }
let index = match *lp { let index = match *lp {
LpVar(..) => { LpVar(..) => {
let mut paths = self.paths.borrow_mut(); let index = MovePathIndex(self.paths.borrow().len());
let index = MovePathIndex(paths.get().len());
paths.get().push(MovePath { self.paths.borrow_mut().push(MovePath {
loan_path: lp, loan_path: lp,
parent: InvalidMovePathIndex, parent: InvalidMovePathIndex,
first_move: InvalidMoveIndex, first_move: InvalidMoveIndex,
@ -270,24 +258,18 @@ impl MoveData {
LpExtend(base, _, _) => { LpExtend(base, _, _) => {
let parent_index = self.move_path(tcx, base); let parent_index = self.move_path(tcx, base);
let index = { let index = MovePathIndex(self.paths.borrow().len());
let paths = self.paths.borrow();
MovePathIndex(paths.get().len())
};
let next_sibling = self.path_first_child(parent_index); let next_sibling = self.path_first_child(parent_index);
self.set_path_first_child(parent_index, index); self.set_path_first_child(parent_index, index);
{ self.paths.borrow_mut().push(MovePath {
let mut paths = self.paths.borrow_mut(); loan_path: lp,
paths.get().push(MovePath { parent: parent_index,
loan_path: lp, first_move: InvalidMoveIndex,
parent: parent_index, first_child: InvalidMovePathIndex,
first_move: InvalidMoveIndex, next_sibling: next_sibling,
first_child: InvalidMovePathIndex, });
next_sibling: next_sibling,
});
}
index index
} }
@ -297,19 +279,15 @@ impl MoveData {
lp.repr(tcx), lp.repr(tcx),
index); index);
let paths = self.paths.borrow(); assert_eq!(index.get(), self.paths.borrow().len() - 1);
assert_eq!(index.get(), paths.get().len() - 1); self.path_map.borrow_mut().insert(lp, index);
let mut path_map = self.path_map.borrow_mut();
path_map.get().insert(lp, index);
return index; return index;
} }
fn existing_move_path(&self, fn existing_move_path(&self,
lp: @LoanPath) lp: @LoanPath)
-> Option<MovePathIndex> { -> Option<MovePathIndex> {
let path_map = self.path_map.borrow(); self.path_map.borrow().find_copy(&lp)
path_map.get().find_copy(&lp)
} }
fn existing_base_paths(&self, fn existing_base_paths(&self,
@ -328,11 +306,7 @@ impl MoveData {
* paths of `lp` to `result`, but does not add new move paths * paths of `lp` to `result`, but does not add new move paths
*/ */
let index_opt = { match self.path_map.borrow().find_copy(&lp) {
let path_map = self.path_map.borrow();
path_map.get().find_copy(&lp)
};
match index_opt {
Some(index) => { Some(index) => {
self.each_base_path(index, |p| { self.each_base_path(index, |p| {
result.push(p); result.push(p);
@ -367,23 +341,17 @@ impl MoveData {
kind); kind);
let path_index = self.move_path(tcx, lp); let path_index = self.move_path(tcx, lp);
let move_index = { let move_index = MoveIndex(self.moves.borrow().len());
let moves = self.moves.borrow();
MoveIndex(moves.get().len())
};
let next_move = self.path_first_move(path_index); let next_move = self.path_first_move(path_index);
self.set_path_first_move(path_index, move_index); self.set_path_first_move(path_index, move_index);
{ self.moves.borrow_mut().push(Move {
let mut moves = self.moves.borrow_mut(); path: path_index,
moves.get().push(Move { id: id,
path: path_index, kind: kind,
id: id, next_move: next_move
kind: kind, });
next_move: next_move
});
}
} }
pub fn add_assignment(&self, pub fn add_assignment(&self,
@ -404,8 +372,7 @@ impl MoveData {
let path_index = self.move_path(tcx, lp); let path_index = self.move_path(tcx, lp);
if !is_also_move { if !is_also_move {
let mut assignee_ids = self.assignee_ids.borrow_mut(); self.assignee_ids.borrow_mut().insert(assignee_id);
assignee_ids.get().insert(assignee_id);
} }
let assignment = Assignment { let assignment = Assignment {
@ -415,19 +382,15 @@ impl MoveData {
}; };
if self.is_var_path(path_index) { if self.is_var_path(path_index) {
let mut var_assignments = self.var_assignments.borrow_mut();
debug!("add_assignment[var](lp={}, assignment={}, path_index={:?})", debug!("add_assignment[var](lp={}, assignment={}, path_index={:?})",
lp.repr(tcx), var_assignments.get().len(), path_index); lp.repr(tcx), self.var_assignments.borrow().len(), path_index);
var_assignments.get().push(assignment); self.var_assignments.borrow_mut().push(assignment);
} else { } else {
debug!("add_assignment[path](lp={}, path_index={:?})", debug!("add_assignment[path](lp={}, path_index={:?})",
lp.repr(tcx), path_index); lp.repr(tcx), path_index);
{ self.path_assignments.borrow_mut().push(assignment);
let mut path_assignments = self.path_assignments.borrow_mut();
path_assignments.get().push(assignment);
}
} }
} }
@ -443,60 +406,42 @@ impl MoveData {
* killed by scoping. See `doc.rs` for more details. * killed by scoping. See `doc.rs` for more details.
*/ */
{ for (i, move) in self.moves.borrow().iter().enumerate() {
let moves = self.moves.borrow(); dfcx_moves.add_gen(move.id, i);
for (i, move) in moves.get().iter().enumerate() {
dfcx_moves.add_gen(move.id, i);
}
} }
{ for (i, assignment) in self.var_assignments.borrow().iter().enumerate() {
let var_assignments = self.var_assignments.borrow(); dfcx_assign.add_gen(assignment.id, i);
for (i, assignment) in var_assignments.get().iter().enumerate() { self.kill_moves(assignment.path, assignment.id, dfcx_moves);
dfcx_assign.add_gen(assignment.id, i);
self.kill_moves(assignment.path, assignment.id, dfcx_moves);
}
} }
{ for assignment in self.path_assignments.borrow().iter() {
let path_assignments = self.path_assignments.borrow(); self.kill_moves(assignment.path, assignment.id, dfcx_moves);
for assignment in path_assignments.get().iter() {
self.kill_moves(assignment.path, assignment.id, dfcx_moves);
}
} }
// Kill all moves related to a variable `x` when it goes out // Kill all moves related to a variable `x` when it goes out
// of scope: // of scope:
{ for path in self.paths.borrow().iter() {
let paths = self.paths.borrow(); match *path.loan_path {
for path in paths.get().iter() { LpVar(id) => {
match *path.loan_path { let kill_id = tcx.region_maps.var_scope(id);
LpVar(id) => { let path = *self.path_map.borrow().get(&path.loan_path);
let kill_id = tcx.region_maps.var_scope(id); self.kill_moves(path, kill_id, dfcx_moves);
let path = {
let path_map = self.path_map.borrow();
*path_map.get().get(&path.loan_path)
};
self.kill_moves(path, kill_id, dfcx_moves);
}
LpExtend(..) => {}
} }
LpExtend(..) => {}
} }
} }
// Kill all assignments when the variable goes out of scope: // Kill all assignments when the variable goes out of scope:
{ for (assignment_index, assignment) in
let var_assignments = self.var_assignments.borrow(); self.var_assignments.borrow().iter().enumerate() {
for (assignment_index, assignment) in match *self.path_loan_path(assignment.path) {
var_assignments.get().iter().enumerate() { LpVar(id) => {
match *self.path_loan_path(assignment.path) { let kill_id = tcx.region_maps.var_scope(id);
LpVar(id) => { dfcx_assign.add_kill(kill_id, assignment_index);
let kill_id = tcx.region_maps.var_scope(id); }
dfcx_assign.add_kill(kill_id, assignment_index); LpExtend(..) => {
} tcx.sess.bug("var assignment for non var path");
LpExtend(..) => {
tcx.sess.bug("var assignment for non var path");
}
} }
} }
} }
@ -570,22 +515,18 @@ impl<'a> FlowedMoveData<'a> {
id_range: ast_util::IdRange, id_range: ast_util::IdRange,
body: &ast::Block) body: &ast::Block)
-> FlowedMoveData<'a> { -> FlowedMoveData<'a> {
let mut dfcx_moves = { let mut dfcx_moves =
let moves = move_data.moves.borrow();
DataFlowContext::new(tcx, DataFlowContext::new(tcx,
method_map, method_map,
MoveDataFlowOperator, MoveDataFlowOperator,
id_range, id_range,
moves.get().len()) move_data.moves.borrow().len());
}; let mut dfcx_assign =
let mut dfcx_assign = {
let var_assignments = move_data.var_assignments.borrow();
DataFlowContext::new(tcx, DataFlowContext::new(tcx,
method_map, method_map,
AssignDataFlowOperator, AssignDataFlowOperator,
id_range, id_range,
var_assignments.get().len()) move_data.var_assignments.borrow().len());
};
move_data.add_gen_kills(tcx, &mut dfcx_moves, &mut dfcx_assign); move_data.add_gen_kills(tcx, &mut dfcx_moves, &mut dfcx_assign);
dfcx_moves.propagate(body); dfcx_moves.propagate(body);
dfcx_assign.propagate(body); dfcx_assign.propagate(body);
@ -605,8 +546,8 @@ impl<'a> FlowedMoveData<'a> {
*/ */
self.dfcx_moves.each_gen_bit_frozen(id, |index| { self.dfcx_moves.each_gen_bit_frozen(id, |index| {
let moves = self.move_data.moves.borrow(); let move = self.move_data.moves.borrow();
let move = moves.get().get(index); let move = move.get(index);
let moved_path = move.path; let moved_path = move.path;
f(move, self.move_data.path_loan_path(moved_path)) f(move, self.move_data.path_loan_path(moved_path))
}) })
@ -644,8 +585,8 @@ impl<'a> FlowedMoveData<'a> {
let mut ret = true; let mut ret = true;
self.dfcx_moves.each_bit_on_entry_frozen(id, |index| { self.dfcx_moves.each_bit_on_entry_frozen(id, |index| {
let moves = self.move_data.moves.borrow(); let move = self.move_data.moves.borrow();
let move = moves.get().get(index); let move = move.get(index);
let moved_path = move.path; let moved_path = move.path;
if base_indices.iter().any(|x| x == &moved_path) { if base_indices.iter().any(|x| x == &moved_path) {
// Scenario 1 or 2: `loan_path` or some base path of // Scenario 1 or 2: `loan_path` or some base path of
@ -675,9 +616,7 @@ impl<'a> FlowedMoveData<'a> {
id: ast::NodeId) id: ast::NodeId)
-> bool { -> bool {
//! True if `id` is the id of the LHS of an assignment //! True if `id` is the id of the LHS of an assignment
self.move_data.assignee_ids.borrow().iter().any(|x| x == &id)
let assignee_ids = self.move_data.assignee_ids.borrow();
assignee_ids.get().iter().any(|x| x == &id)
} }
pub fn each_assignment_of(&self, pub fn each_assignment_of(&self,
@ -702,8 +641,8 @@ impl<'a> FlowedMoveData<'a> {
}; };
self.dfcx_assign.each_bit_on_entry_frozen(id, |index| { self.dfcx_assign.each_bit_on_entry_frozen(id, |index| {
let var_assignments = self.move_data.var_assignments.borrow(); let assignment = self.move_data.var_assignments.borrow();
let assignment = var_assignments.get().get(index); let assignment = assignment.get(index);
if assignment.path == loan_path_index && !f(assignment) { if assignment.path == loan_path_index && !f(assignment) {
false false
} else { } else {

View File

@ -497,8 +497,7 @@ impl<'a> CFGBuilder<'a> {
} }
Some(_) => { Some(_) => {
let def_map = self.tcx.def_map.borrow(); match self.tcx.def_map.borrow().find(&expr.id) {
match def_map.get().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => { Some(&ast::DefLabel(loop_id)) => {
for l in self.loop_scopes.iter() { for l in self.loop_scopes.iter() {
if l.loop_id == loop_id { if l.loop_id == loop_id {
@ -522,6 +521,6 @@ impl<'a> CFGBuilder<'a> {
fn is_method_call(&self, expr: &ast::Expr) -> bool { fn is_method_call(&self, expr: &ast::Expr) -> bool {
let method_call = typeck::MethodCall::expr(expr.id); let method_call = typeck::MethodCall::expr(expr.id);
self.method_map.borrow().get().contains_key(&method_call) self.method_map.borrow().contains_key(&method_call)
} }
} }

View File

@ -103,7 +103,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
ExprLit(lit) if ast_util::lit_is_str(lit) => {} ExprLit(lit) if ast_util::lit_is_str(lit) => {}
ExprBinary(..) | ExprUnary(..) => { ExprBinary(..) | ExprUnary(..) => {
let method_call = typeck::MethodCall::expr(e.id); let method_call = typeck::MethodCall::expr(e.id);
if v.method_map.borrow().get().contains_key(&method_call) { if v.method_map.borrow().contains_key(&method_call) {
v.tcx.sess.span_err(e.span, "user-defined operators are not \ v.tcx.sess.span_err(e.span, "user-defined operators are not \
allowed in constant expressions"); allowed in constant expressions");
} }
@ -127,7 +127,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
"paths in constants may only refer to \ "paths in constants may only refer to \
items without type parameters"); items without type parameters");
} }
match v.def_map.borrow().get().find(&e.id) { match v.def_map.borrow().find(&e.id) {
Some(&DefStatic(..)) | Some(&DefStatic(..)) |
Some(&DefFn(_, _)) | Some(&DefFn(_, _)) |
Some(&DefVariant(_, _, _)) | Some(&DefVariant(_, _, _)) |
@ -145,7 +145,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
} }
} }
ExprCall(callee, _) => { ExprCall(callee, _) => {
match v.def_map.borrow().get().find(&callee.id) { match v.def_map.borrow().find(&callee.id) {
Some(&DefStruct(..)) => {} // OK. Some(&DefStruct(..)) => {} // OK.
Some(&DefVariant(..)) => {} // OK. Some(&DefVariant(..)) => {} // OK.
_ => { _ => {
@ -221,8 +221,7 @@ impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> {
fn visit_expr(&mut self, e: &Expr, _: ()) { fn visit_expr(&mut self, e: &Expr, _: ()) {
match e.node { match e.node {
ExprPath(..) => { ExprPath(..) => {
let def_map = self.def_map.borrow(); match self.def_map.borrow().find(&e.id) {
match def_map.get().find(&e.id) {
Some(&DefStatic(def_id, _)) if Some(&DefStatic(def_id, _)) if
ast_util::is_local(def_id) => { ast_util::is_local(def_id) => {
self.visit_item(self.ast_map.expect_item(def_id.node), ()); self.visit_item(self.ast_map.expect_item(def_id.node), ());

View File

@ -121,10 +121,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
// Check that we do not match against a static NaN (#6804) // Check that we do not match against a static NaN (#6804)
let pat_matches_nan: |&Pat| -> bool = |p| { let pat_matches_nan: |&Pat| -> bool = |p| {
let opt_def = { let opt_def = cx.tcx.def_map.borrow().find_copy(&p.id);
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&p.id)
};
match opt_def { match opt_def {
Some(DefStatic(did, false)) => { Some(DefStatic(did, false)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap(); let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
@ -351,10 +348,7 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
match pat.node { match pat.node {
PatWild | PatWildMulti => { None } PatWild | PatWildMulti => { None }
PatIdent(_, _, _) | PatEnum(_, _) => { PatIdent(_, _, _) | PatEnum(_, _) => {
let opt_def = { let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat.id)
};
match opt_def { match opt_def {
Some(DefVariant(_, id, _)) => Some(variant(id)), Some(DefVariant(_, id, _)) => Some(variant(id)),
Some(DefStatic(did, false)) => { Some(DefStatic(did, false)) => {
@ -369,8 +363,7 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi))) Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi)))
} }
PatStruct(..) => { PatStruct(..) => {
let def_map = cx.tcx.def_map.borrow(); match cx.tcx.def_map.borrow().find(&pat.id) {
match def_map.get().find(&pat.id) {
Some(&DefVariant(_, id, _)) => Some(variant(id)), Some(&DefVariant(_, id, _)) => Some(variant(id)),
_ => Some(single) _ => Some(single)
} }
@ -392,8 +385,7 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
match pat.node { match pat.node {
PatWild | PatWildMulti => { true } PatWild | PatWildMulti => { true }
PatIdent(_, _, _) => { PatIdent(_, _, _) => {
let def_map = cx.tcx.def_map.borrow(); match cx.tcx.def_map.borrow().find(&pat.id) {
match def_map.get().find(&pat.id) {
Some(&DefVariant(_, _, _)) | Some(&DefStatic(..)) => { false } Some(&DefVariant(_, _, _)) | Some(&DefStatic(..)) => { false }
_ => { true } _ => { true }
} }
@ -575,10 +567,7 @@ fn specialize(cx: &MatchCheckCtxt,
r.tail())) r.tail()))
} }
PatIdent(_, _, _) => { PatIdent(_, _, _) => {
let opt_def = { let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id);
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat_id)
};
match opt_def { match opt_def {
Some(DefVariant(_, id, _)) => { Some(DefVariant(_, id, _)) => {
if variant(id) == *ctor_id { if variant(id) == *ctor_id {
@ -636,11 +625,8 @@ fn specialize(cx: &MatchCheckCtxt,
} }
} }
PatEnum(_, args) => { PatEnum(_, args) => {
let opt_def = { let def = cx.tcx.def_map.borrow().get_copy(&pat_id);
let def_map = cx.tcx.def_map.borrow(); match def {
def_map.get().get_copy(&pat_id)
};
match opt_def {
DefStatic(did, _) => { DefStatic(did, _) => {
let const_expr = let const_expr =
lookup_const_by_id(cx.tcx, did).unwrap(); lookup_const_by_id(cx.tcx, did).unwrap();
@ -701,11 +687,8 @@ fn specialize(cx: &MatchCheckCtxt,
} }
PatStruct(_, ref pattern_fields, _) => { PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant? // Is this a struct or an enum variant?
let opt_def = { let def = cx.tcx.def_map.borrow().get_copy(&pat_id);
let def_map = cx.tcx.def_map.borrow(); match def {
def_map.get().get_copy(&pat_id)
};
match opt_def {
DefVariant(_, variant_id, _) => { DefVariant(_, variant_id, _) => {
if variant(variant_id) == *ctor_id { if variant(variant_id) == *ctor_id {
let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id); let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id);
@ -891,10 +874,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
} }
fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool { fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
let opt_def = { let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat.id)
};
match opt_def { match opt_def {
Some(DefVariant(enum_id, _, _)) => { Some(DefVariant(enum_id, _, _)) => {
if ty::enum_variants(cx.tcx, enum_id).len() != 1u { if ty::enum_variants(cx.tcx, enum_id).len() != 1u {

View File

@ -83,10 +83,7 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
} }
pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> { pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> {
let opt_def = { let opt_def = tcx.def_map.borrow().find_copy(&e.id);
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&e.id)
};
match opt_def { match opt_def {
Some(ast::DefStatic(def_id, false)) => { Some(ast::DefStatic(def_id, false)) => {
lookup_const_by_id(tcx, def_id) lookup_const_by_id(tcx, def_id)
@ -125,7 +122,7 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
} }
} }
} else { } else {
match tcx.extern_const_variants.borrow().get().find(&variant_def) { match tcx.extern_const_variants.borrow().find(&variant_def) {
Some(&e) => return e, Some(&e) => return e,
None => {} None => {}
} }
@ -145,7 +142,7 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
}, },
_ => None _ => None
}; };
tcx.extern_const_variants.borrow_mut().get().insert(variant_def, e); tcx.extern_const_variants.borrow_mut().insert(variant_def, e);
return e; return e;
} }
} }
@ -166,12 +163,9 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
} }
} }
} else { } else {
{ match tcx.extern_const_statics.borrow().find(&def_id) {
let extern_const_statics = tcx.extern_const_statics.borrow(); Some(&e) => return e,
match extern_const_statics.get().find(&def_id) { None => {}
Some(&e) => return e,
None => {}
}
} }
let maps = astencode::Maps { let maps = astencode::Maps {
root_map: @RefCell::new(HashMap::new()), root_map: @RefCell::new(HashMap::new()),
@ -187,12 +181,8 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
}, },
_ => None _ => None
}; };
{ tcx.extern_const_statics.borrow_mut().insert(def_id, e);
let mut extern_const_statics = tcx.extern_const_statics return e;
.borrow_mut();
extern_const_statics.get().insert(def_id, e);
return e;
}
} }
} }

View File

@ -782,8 +782,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
} }
Some(_) => { Some(_) => {
let def_map = self.tcx().def_map.borrow(); match self.tcx().def_map.borrow().find(&expr.id) {
match def_map.get().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => { Some(&ast::DefLabel(loop_id)) => {
match loop_scopes.iter().position(|l| l.loop_id == loop_id) { match loop_scopes.iter().position(|l| l.loop_id == loop_id) {
Some(i) => i, Some(i) => i,
@ -809,7 +808,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
fn is_method_call(&self, expr: &ast::Expr) -> bool { fn is_method_call(&self, expr: &ast::Expr) -> bool {
let method_call = typeck::MethodCall::expr(expr.id); let method_call = typeck::MethodCall::expr(expr.id);
self.dfcx.method_map.borrow().get().contains_key(&method_call) self.dfcx.method_map.borrow().contains_key(&method_call)
} }
fn reset(&mut self, bits: &mut [uint]) { fn reset(&mut self, bits: &mut [uint]) {

View File

@ -75,8 +75,7 @@ impl<'a> MarkSymbolVisitor<'a> {
} }
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) { fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
let def_map = self.tcx.def_map.borrow(); let def = match self.tcx.def_map.borrow().find(id) {
let def = match def_map.get().find(id) {
Some(&def) => def, Some(&def) => def,
None => return None => return
}; };
@ -94,7 +93,7 @@ impl<'a> MarkSymbolVisitor<'a> {
fn lookup_and_handle_method(&mut self, id: ast::NodeId, fn lookup_and_handle_method(&mut self, id: ast::NodeId,
span: codemap::Span) { span: codemap::Span) {
let method_call = typeck::MethodCall::expr(id); let method_call = typeck::MethodCall::expr(id);
match self.method_map.borrow().get().find(&method_call) { match self.method_map.borrow().find(&method_call) {
Some(method) => { Some(method) => {
match method.origin { match method.origin {
typeck::MethodStatic(def_id) => { typeck::MethodStatic(def_id) => {
@ -342,12 +341,10 @@ impl<'a> DeadVisitor<'a> {
// method of a private type is used, but the type itself is never // method of a private type is used, but the type itself is never
// called directly. // called directly.
let def_id = local_def(id); let def_id = local_def(id);
let inherent_impls = self.tcx.inherent_impls.borrow(); match self.tcx.inherent_impls.borrow().find(&def_id) {
match inherent_impls.get().find(&def_id) {
None => (), None => (),
Some(ref impl_list) => { Some(ref impl_list) => {
let impl_list = impl_list.borrow(); for impl_ in impl_list.borrow().iter() {
for impl_ in impl_list.get().iter() {
for method in impl_.methods.iter() { for method in impl_.methods.iter() {
if self.live_symbols.contains(&method.def_id.node) { if self.live_symbols.contains(&method.def_id.node) {
return true; return true;

View File

@ -56,8 +56,7 @@ impl<'a> EffectCheckVisitor<'a> {
UnsafeBlock(block_id) => { UnsafeBlock(block_id) => {
// OK, but record this. // OK, but record this.
debug!("effect: recording unsafe block as used: {:?}", block_id); debug!("effect: recording unsafe block as used: {:?}", block_id);
let mut used_unsafe = self.tcx.used_unsafe.borrow_mut(); self.tcx.used_unsafe.borrow_mut().insert(block_id);
let _ = used_unsafe.get().insert(block_id);
} }
UnsafeFn => {} UnsafeFn => {}
} }
@ -139,7 +138,7 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> {
match expr.node { match expr.node {
ast::ExprMethodCall(_, _, _) => { ast::ExprMethodCall(_, _, _) => {
let method_call = MethodCall::expr(expr.id); let method_call = MethodCall::expr(expr.id);
let base_type = self.method_map.borrow().get().get(&method_call).ty; let base_type = self.method_map.borrow().get(&method_call).ty;
debug!("effect: method call case, base type is {}", debug!("effect: method call case, base type is {}",
ppaux::ty_to_str(self.tcx, base_type)); ppaux::ty_to_str(self.tcx, base_type));
if type_is_unsafe_function(base_type) { if type_is_unsafe_function(base_type) {

View File

@ -51,8 +51,7 @@ impl Visitor<int> for CollectFreevarsVisitor {
} }
ast::ExprPath(..) => { ast::ExprPath(..) => {
let mut i = 0; let mut i = 0;
let def_map = self.def_map.borrow(); match self.def_map.borrow().find(&expr.id) {
match def_map.get().find(&expr.id) {
None => fail!("path not found"), None => fail!("path not found"),
Some(&df) => { Some(&df) => {
let mut def = df; let mut def = df;
@ -141,8 +140,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, krate: &ast::Crate) ->
} }
pub fn get_freevars(tcx: &ty::ctxt, fid: ast::NodeId) -> freevar_info { pub fn get_freevars(tcx: &ty::ctxt, fid: ast::NodeId) -> freevar_info {
let freevars = tcx.freevars.borrow(); match tcx.freevars.borrow().find(&fid) {
match freevars.get().find(&fid) {
None => fail!("get_freevars: {} has no freevars", fid), None => fail!("get_freevars: {} has no freevars", fid),
Some(&d) => return d Some(&d) => return d
} }

View File

@ -117,18 +117,13 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
} }
fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_type: &Ty) { fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_type: &Ty) {
let def_map = cx.tcx.def_map.borrow(); let ast_trait_def = *cx.tcx.def_map.borrow()
let ast_trait_def = def_map.get() .find(&trait_ref.ref_id)
.find(&trait_ref.ref_id) .expect("trait ref not in def map!");
.expect("trait ref not in def map!"); let trait_def_id = ast_util::def_id_of_def(ast_trait_def);
let trait_def_id = ast_util::def_id_of_def(*ast_trait_def); let trait_def = *cx.tcx.trait_defs.borrow()
let trait_def; .find(&trait_def_id)
{ .expect("trait def not in trait-defs map!");
let trait_defs = cx.tcx.trait_defs.borrow();
trait_def = *trait_defs.get()
.find(&trait_def_id)
.expect("trait def not in trait-defs map!");
}
// If this trait has builtin-kind supertraits, meet them. // If this trait has builtin-kind supertraits, meet them.
let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id); let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id);
@ -147,7 +142,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
match self_type.node { match self_type.node {
TyPath(_, ref bounds, path_node_id) => { TyPath(_, ref bounds, path_node_id) => {
assert!(bounds.is_none()); assert!(bounds.is_none());
let struct_def = def_map.get().get_copy(&path_node_id); let struct_def = cx.tcx.def_map.borrow().get_copy(&path_node_id);
let struct_did = ast_util::def_id_of_def(struct_def); let struct_did = ast_util::def_id_of_def(struct_def);
check_struct_safe_for_destructor(cx, self_type.span, struct_did); check_struct_safe_for_destructor(cx, self_type.span, struct_did);
} }
@ -266,18 +261,17 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
// Handle any kind bounds on type parameters // Handle any kind bounds on type parameters
{ {
let method_map = cx.method_map.borrow(); let method_map = cx.method_map.borrow();
let method = method_map.get().find(&typeck::MethodCall::expr(e.id)); let method = method_map.find(&typeck::MethodCall::expr(e.id));
let node_type_substs = cx.tcx.node_type_substs.borrow(); let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = match method { let r = match method {
Some(method) => Some(&method.substs.tps), Some(method) => Some(&method.substs.tps),
None => node_type_substs.get().find(&e.id) None => node_type_substs.find(&e.id)
}; };
for ts in r.iter() { for ts in r.iter() {
let def_map = cx.tcx.def_map.borrow(); let def_map = cx.tcx.def_map.borrow();
let type_param_defs = match e.node { let type_param_defs = match e.node {
ExprPath(_) => { ExprPath(_) => {
let did = ast_util::def_id_of_def(def_map.get() let did = ast_util::def_id_of_def(def_map.get_copy(&e.id));
.get_copy(&e.id));
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs.clone() ty::lookup_item_type(cx.tcx, did).generics.type_param_defs.clone()
} }
_ => { _ => {
@ -334,14 +328,13 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
} }
// Search for auto-adjustments to find trait coercions. // Search for auto-adjustments to find trait coercions.
let adjustments = cx.tcx.adjustments.borrow(); match cx.tcx.adjustments.borrow().find(&e.id) {
match adjustments.get().find(&e.id) {
Some(adjustment) => { Some(adjustment) => {
match **adjustment { match **adjustment {
ty::AutoObject(..) => { ty::AutoObject(..) => {
let source_ty = ty::expr_ty(cx.tcx, e); let source_ty = ty::expr_ty(cx.tcx, e);
let target_ty = ty::expr_ty_adjusted(cx.tcx, e, let target_ty = ty::expr_ty_adjusted(cx.tcx, e,
cx.method_map.borrow().get()); &*cx.method_map.borrow());
check_trait_cast(cx, source_ty, target_ty, e.span); check_trait_cast(cx, source_ty, target_ty, e.span);
} }
ty::AutoAddEnv(..) | ty::AutoAddEnv(..) |
@ -368,10 +361,10 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node { match aty.node {
TyPath(_, _, id) => { TyPath(_, _, id) => {
let node_type_substs = cx.tcx.node_type_substs.borrow(); let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = node_type_substs.get().find(&id); let r = node_type_substs.find(&id);
for ts in r.iter() { for ts in r.iter() {
let def_map = cx.tcx.def_map.borrow(); let def_map = cx.tcx.def_map.borrow();
let did = ast_util::def_id_of_def(def_map.get().get_copy(&id)); let did = ast_util::def_id_of_def(def_map.get_copy(&id));
let generics = ty::lookup_item_type(cx.tcx, did).generics; let generics = ty::lookup_item_type(cx.tcx, did).generics;
let type_param_defs = generics.type_param_defs(); let type_param_defs = generics.type_param_defs();
for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) { for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) {

View File

@ -848,8 +848,7 @@ fn check_item_ctypes(cx: &Context, it: &ast::Item) {
fn check_ty(cx: &Context, ty: &ast::Ty) { fn check_ty(cx: &Context, ty: &ast::Ty) {
match ty.node { match ty.node {
ast::TyPath(_, _, id) => { ast::TyPath(_, _, id) => {
let def_map = cx.tcx.def_map.borrow(); match cx.tcx.def_map.borrow().get_copy(&id) {
match def_map.get().get_copy(&id) {
ast::DefPrimTy(ast::TyInt(ast::TyI)) => { ast::DefPrimTy(ast::TyInt(ast::TyI)) => {
cx.span_lint(CTypes, ty.span, cx.span_lint(CTypes, ty.span,
"found rust type `int` in foreign module, while \ "found rust type `int` in foreign module, while \
@ -1182,8 +1181,7 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) { fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
// Lint for constants that look like binding identifiers (#7526) // Lint for constants that look like binding identifiers (#7526)
let def_map = cx.tcx.def_map.borrow(); match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) {
match (&p.node, def_map.get().find(&p.id)) {
(&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => { (&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
// last identifier alone is right choice for this lint. // last identifier alone is right choice for this lint.
let ident = path.segments.last().unwrap().identifier; let ident = path.segments.last().unwrap().identifier;
@ -1198,10 +1196,9 @@ fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
} }
fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) { fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
let def_map = cx.tcx.def_map.borrow();
match &p.node { match &p.node {
&ast::PatIdent(_, ref path, _) => { &ast::PatIdent(_, ref path, _) => {
match def_map.get().find(&p.id) { match cx.tcx.def_map.borrow().find(&p.id) {
Some(&ast::DefLocal(_, _)) | Some(&ast::DefBinding(_, _)) | Some(&ast::DefLocal(_, _)) | Some(&ast::DefBinding(_, _)) |
Some(&ast::DefArg(_, _)) => { Some(&ast::DefArg(_, _)) => {
// last identifier alone is right choice for this lint. // last identifier alone is right choice for this lint.
@ -1279,9 +1276,8 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
match e.node { match e.node {
// Don't warn about generated blocks, that'll just pollute the output. // Don't warn about generated blocks, that'll just pollute the output.
ast::ExprBlock(ref blk) => { ast::ExprBlock(ref blk) => {
let used_unsafe = cx.tcx.used_unsafe.borrow();
if blk.rules == ast::UnsafeBlock(ast::UserProvided) && if blk.rules == ast::UnsafeBlock(ast::UserProvided) &&
!used_unsafe.get().contains(&blk.id) { !cx.tcx.used_unsafe.borrow().contains(&blk.id) {
cx.span_lint(UnusedUnsafe, blk.span, cx.span_lint(UnusedUnsafe, blk.span,
"unnecessary `unsafe` block"); "unnecessary `unsafe` block");
} }
@ -1315,8 +1311,8 @@ fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) {
of exactly one segment") of exactly one segment")
}; };
let used_mut_nodes = cx.tcx.used_mut_nodes.borrow(); if !initial_underscore &&
if !initial_underscore && !used_mut_nodes.get().contains(&p.id) { !cx.tcx.used_mut_nodes.borrow().contains(&p.id) {
cx.span_lint(UnusedMut, p.span, cx.span_lint(UnusedMut, p.span,
"variable does not need to be mutable"); "variable does not need to be mutable");
} }
@ -1353,11 +1349,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
cx.span_lint(UnnecessaryAllocation, e.span, msg); cx.span_lint(UnnecessaryAllocation, e.span, msg);
}; };
let adjustment = { match cx.tcx.adjustments.borrow().find_copy(&e.id) {
let adjustments = cx.tcx.adjustments.borrow();
adjustments.get().find_copy(&e.id)
};
match adjustment {
Some(adjustment) => { Some(adjustment) => {
match *adjustment { match *adjustment {
ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. }) => { ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. }) => {
@ -1439,13 +1431,7 @@ fn check_missing_doc_method(cx: &Context, m: &ast::Method) {
node: m.id node: m.id
}; };
let method_opt; match cx.tcx.methods.borrow().find(&did).map(|method| *method) {
{
let methods = cx.tcx.methods.borrow();
method_opt = methods.get().find(&did).map(|method| *method);
}
match method_opt {
None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"), None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"),
Some(md) => { Some(md) => {
match md.container { match md.container {
@ -1503,15 +1489,14 @@ fn check_missing_doc_variant(cx: &Context, v: &ast::Variant) {
fn check_stability(cx: &Context, e: &ast::Expr) { fn check_stability(cx: &Context, e: &ast::Expr) {
let id = match e.node { let id = match e.node {
ast::ExprPath(..) | ast::ExprStruct(..) => { ast::ExprPath(..) | ast::ExprStruct(..) => {
let def_map = cx.tcx.def_map.borrow(); match cx.tcx.def_map.borrow().find(&e.id) {
match def_map.get().find(&e.id) {
Some(&def) => ast_util::def_id_of_def(def), Some(&def) => ast_util::def_id_of_def(def),
None => return None => return
} }
} }
ast::ExprMethodCall(..) => { ast::ExprMethodCall(..) => {
let method_call = typeck::MethodCall::expr(e.id); let method_call = typeck::MethodCall::expr(e.id);
match cx.method_map.borrow().get().find(&method_call) { match cx.method_map.borrow().find(&method_call) {
Some(method) => { Some(method) => {
match method.origin { match method.origin {
typeck::MethodStatic(def_id) => { typeck::MethodStatic(def_id) => {
@ -1736,8 +1721,7 @@ impl<'a> Visitor<()> for Context<'a> {
impl<'a> IdVisitingOperation for Context<'a> { impl<'a> IdVisitingOperation for Context<'a> {
fn visit_id(&self, id: ast::NodeId) { fn visit_id(&self, id: ast::NodeId) {
let mut lints = self.tcx.sess.lints.borrow_mut(); match self.tcx.sess.lints.borrow_mut().pop(&id) {
match lints.get().pop(&id) {
None => {} None => {}
Some(l) => { Some(l) => {
for (lint, span, msg) in l.move_iter() { for (lint, span, msg) in l.move_iter() {
@ -1793,8 +1777,7 @@ pub fn check_crate(tcx: &ty::ctxt,
// If we missed any lints added to the session, then there's a bug somewhere // If we missed any lints added to the session, then there's a bug somewhere
// in the iteration code. // in the iteration code.
let lints = tcx.sess.lints.borrow(); for (id, v) in tcx.sess.lints.borrow().iter() {
for (id, v) in lints.get().iter() {
for &(lint, span, ref msg) in v.iter() { for &(lint, span, ref msg) in v.iter() {
tcx.sess.span_bug(span, format!("unprocessed lint {:?} at {}: {}", tcx.sess.span_bug(span, format!("unprocessed lint {:?} at {}: {}",
lint, tcx.map.node_to_str(*id), *msg)) lint, tcx.map.node_to_str(*id), *msg))

View File

@ -455,7 +455,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node { match expr.node {
// live nodes required for uses or definitions of variables: // live nodes required for uses or definitions of variables:
ExprPath(_) => { ExprPath(_) => {
let def = ir.tcx.def_map.borrow().get().get_copy(&expr.id); let def = ir.tcx.def_map.borrow().get_copy(&expr.id);
debug!("expr {}: path that leads to {:?}", expr.id, def); debug!("expr {}: path that leads to {:?}", expr.id, def);
if moves::moved_variable_node_id_from_def(def).is_some() { if moves::moved_variable_node_id_from_def(def).is_some() {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -707,7 +707,7 @@ impl<'a> Liveness<'a> {
Some(_) => { Some(_) => {
// Refers to a labeled loop. Use the results of resolve // Refers to a labeled loop. Use the results of resolve
// to find with one // to find with one
match self.ir.tcx.def_map.borrow().get().find(&id) { match self.ir.tcx.def_map.borrow().find(&id) {
Some(&DefLabel(loop_id)) => loop_id, Some(&DefLabel(loop_id)) => loop_id,
_ => self.ir.tcx.sess.span_bug(sp, "label on break/loop \ _ => self.ir.tcx.sess.span_bug(sp, "label on break/loop \
doesn't refer to a loop") doesn't refer to a loop")
@ -1274,7 +1274,7 @@ impl<'a> Liveness<'a> {
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint) fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode { -> LiveNode {
let def = self.ir.tcx.def_map.borrow().get().get_copy(&expr.id); let def = self.ir.tcx.def_map.borrow().get_copy(&expr.id);
match moves::moved_variable_node_id_from_def(def) { match moves::moved_variable_node_id_from_def(def) {
Some(nid) => { Some(nid) => {
let ln = self.live_node(expr.id, expr.span); let ln = self.live_node(expr.id, expr.span);
@ -1490,7 +1490,7 @@ impl<'a> Liveness<'a> {
fn check_lvalue(&mut self, expr: &Expr) { fn check_lvalue(&mut self, expr: &Expr) {
match expr.node { match expr.node {
ExprPath(_) => { ExprPath(_) => {
match self.ir.tcx.def_map.borrow().get().get_copy(&expr.id) { match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
DefLocal(nid, _) => { DefLocal(nid, _) => {
// Assignment to an immutable variable or argument: only legal // Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually // if there is no later assignment. If this local is actually

View File

@ -455,8 +455,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
} }
ast::ExprPath(_) => { ast::ExprPath(_) => {
let def_map = self.tcx().def_map.borrow(); let def = self.tcx().def_map.borrow().get_copy(&expr.id);
let def = def_map.get().get_copy(&expr.id);
self.cat_def(expr.id, expr.span, expr_ty, def) self.cat_def(expr.id, expr.span, expr_ty, def)
} }
@ -1010,8 +1009,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
// variant(..) // variant(..)
} }
ast::PatEnum(_, Some(ref subpats)) => { ast::PatEnum(_, Some(ref subpats)) => {
let def_map = self.tcx().def_map.borrow(); match self.tcx().def_map.borrow().find(&pat.id) {
match def_map.get().find(&pat.id) {
Some(&ast::DefVariant(enum_did, _, _)) => { Some(&ast::DefVariant(enum_did, _, _)) => {
// variant(x, y, z) // variant(x, y, z)
@ -1202,8 +1200,7 @@ pub fn field_mutbl(tcx: &ty::ctxt,
} }
} }
ty::ty_enum(..) => { ty::ty_enum(..) => {
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().get_copy(&node_id) {
match def_map.get().get_copy(&node_id) {
ast::DefVariant(_, variant_id, _) => { ast::DefVariant(_, variant_id, _) => {
let r = ty::lookup_struct_fields(tcx, variant_id); let r = ty::lookup_struct_fields(tcx, variant_id);
for fld in r.iter() { for fld in r.iter() {

View File

@ -275,7 +275,7 @@ impl<'a> VisitContext<'a> {
expr.repr(self.tcx)); expr.repr(self.tcx));
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr, let expr_ty = ty::expr_ty_adjusted(self.tcx, expr,
self.method_map.borrow().get()); &*self.method_map.borrow());
if ty::type_moves_by_default(self.tcx, expr_ty) { if ty::type_moves_by_default(self.tcx, expr_ty) {
self.move_maps.moves_map.insert(expr.id); self.move_maps.moves_map.insert(expr.id);
self.use_expr(expr, Move); self.use_expr(expr, Move);
@ -316,20 +316,17 @@ impl<'a> VisitContext<'a> {
// `expr_mode` refers to the post-adjustment value. If one of // `expr_mode` refers to the post-adjustment value. If one of
// those adjustments is to take a reference, then it's only // those adjustments is to take a reference, then it's only
// reading the underlying expression, not moving it. // reading the underlying expression, not moving it.
let comp_mode = { let comp_mode = match self.tcx.adjustments.borrow().find(&expr.id) {
let adjustments = self.tcx.adjustments.borrow(); Some(adjustment) => {
match adjustments.get().find(&expr.id) { match **adjustment {
Some(adjustment) => { ty::AutoDerefRef(ty::AutoDerefRef {
match **adjustment { autoref: Some(_),
ty::AutoDerefRef(ty::AutoDerefRef { ..
autoref: Some(_), }) => Read,
.. _ => expr_mode,
}) => Read,
_ => expr_mode,
}
} }
_ => expr_mode,
} }
_ => expr_mode,
}; };
debug!("comp_mode = {:?}", comp_mode); debug!("comp_mode = {:?}", comp_mode);
@ -338,8 +335,7 @@ impl<'a> VisitContext<'a> {
ExprPath(..) => { ExprPath(..) => {
match comp_mode { match comp_mode {
Move => { Move => {
let def_map = self.tcx.def_map.borrow(); let def = self.tcx.def_map.borrow().get_copy(&expr.id);
let def = def_map.get().get_copy(&expr.id);
let r = moved_variable_node_id_from_def(def); let r = moved_variable_node_id_from_def(def);
for &id in r.iter() { for &id in r.iter() {
self.move_maps.moved_variables_set.insert(id); self.move_maps.moved_variables_set.insert(id);
@ -581,7 +577,7 @@ impl<'a> VisitContext<'a> {
arg_exprs: &[@Expr]) arg_exprs: &[@Expr])
-> bool { -> bool {
let method_call = MethodCall::expr(expr.id); let method_call = MethodCall::expr(expr.id);
if !self.method_map.borrow().get().contains_key(&method_call) { if !self.method_map.borrow().contains_key(&method_call) {
return false; return false;
} }

View File

@ -31,8 +31,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: &Pat) -> PatIdMap {
pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: &Pat) -> bool { pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: &Pat) -> bool {
match pat.node { match pat.node {
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
let dm = dm.borrow(); match dm.borrow().find(&pat.id) {
match dm.get().find(&pat.id) {
Some(&DefVariant(..)) | Some(&DefStruct(..)) => true, Some(&DefVariant(..)) | Some(&DefStruct(..)) => true,
_ => false _ => false
} }
@ -44,8 +43,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_const(dm: resolve::DefMap, pat: &Pat) -> bool { pub fn pat_is_const(dm: resolve::DefMap, pat: &Pat) -> bool {
match pat.node { match pat.node {
PatIdent(_, _, None) | PatEnum(..) => { PatIdent(_, _, None) | PatEnum(..) => {
let dm = dm.borrow(); match dm.borrow().find(&pat.id) {
match dm.get().find(&pat.id) {
Some(&DefStatic(_, false)) => true, Some(&DefStatic(_, false)) => true,
_ => false _ => false
} }

View File

@ -252,8 +252,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
ast::ItemImpl(_, _, ref ty, ref methods) => { ast::ItemImpl(_, _, ref ty, ref methods) => {
let public_ty = match ty.node { let public_ty = match ty.node {
ast::TyPath(_, _, id) => { ast::TyPath(_, _, id) => {
let def_map = self.tcx.def_map.borrow(); match self.tcx.def_map.borrow().get_copy(&id) {
match def_map.get().get_copy(&id) {
ast::DefPrimTy(..) => true, ast::DefPrimTy(..) => true,
def => { def => {
let did = def_id_of_def(def); let did = def_id_of_def(def);
@ -328,8 +327,8 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
// crate module gets processed as well. // crate module gets processed as well.
if self.prev_exported { if self.prev_exported {
let exp_map2 = self.exp_map2.borrow(); let exp_map2 = self.exp_map2.borrow();
assert!(exp_map2.get().contains_key(&id), "wut {:?}", id); assert!(exp_map2.contains_key(&id), "wut {:?}", id);
for export in exp_map2.get().get(&id).iter() { for export in exp_map2.get(&id).iter() {
if is_local(export.def_id) { if is_local(export.def_id) {
self.reexports.insert(export.def_id.node); self.reexports.insert(export.def_id.node);
} }
@ -376,8 +375,7 @@ impl<'a> PrivacyVisitor<'a> {
} }
debug!("privacy - is {:?} a public method", did); debug!("privacy - is {:?} a public method", did);
let methods = self.tcx.methods.borrow(); return match self.tcx.methods.borrow().find(&did) {
return match methods.get().find(&did) {
Some(meth) => { Some(meth) => {
debug!("privacy - well at least it's a method: {:?}", meth); debug!("privacy - well at least it's a method: {:?}", meth);
match meth.container { match meth.container {
@ -639,8 +637,7 @@ impl<'a> PrivacyVisitor<'a> {
// Checks that a path is in scope. // Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) { fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
debug!("privacy - path {}", self.nodestr(path_id)); debug!("privacy - path {}", self.nodestr(path_id));
let def_map = self.tcx.def_map.borrow(); let orig_def = self.tcx.def_map.borrow().get_copy(&path_id);
let orig_def = def_map.get().get_copy(&path_id);
let ck = |tyname: &str| { let ck = |tyname: &str| {
let ck_public = |def: ast::DefId| { let ck_public = |def: ast::DefId| {
let name = token::get_ident(path.segments let name = token::get_ident(path.segments
@ -722,8 +719,7 @@ impl<'a> PrivacyVisitor<'a> {
// def map is not. Therefore the names we work out below will not always // def map is not. Therefore the names we work out below will not always
// be accurate and we can get slightly wonky error messages (but type // be accurate and we can get slightly wonky error messages (but type
// checking is always correct). // checking is always correct).
let def_map = self.tcx.def_map.borrow(); match self.tcx.def_map.borrow().get_copy(&path_id) {
match def_map.get().get_copy(&path_id) {
ast::DefStaticMethod(..) => ck("static method"), ast::DefStaticMethod(..) => ck("static method"),
ast::DefFn(..) => ck("function"), ast::DefFn(..) => ck("function"),
ast::DefStatic(..) => ck("static"), ast::DefStatic(..) => ck("static"),
@ -772,7 +768,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
match expr.node { match expr.node {
ast::ExprField(base, ident, _) => { ast::ExprField(base, ident, _) => {
match ty::get(ty::expr_ty_adjusted(self.tcx, base, match ty::get(ty::expr_ty_adjusted(self.tcx, base,
self.method_map.borrow().get())).sty { &*self.method_map.borrow())).sty {
ty::ty_struct(id, _) => { ty::ty_struct(id, _) => {
self.check_field(expr.span, id, ident, None); self.check_field(expr.span, id, ident, None);
} }
@ -781,7 +777,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
} }
ast::ExprMethodCall(ident, _, _) => { ast::ExprMethodCall(ident, _, _) => {
let method_call = MethodCall::expr(expr.id); let method_call = MethodCall::expr(expr.id);
match self.method_map.borrow().get().find(&method_call) { match self.method_map.borrow().find(&method_call) {
None => { None => {
self.tcx.sess.span_bug(expr.span, self.tcx.sess.span_bug(expr.span,
"method call not in \ "method call not in \
@ -802,8 +798,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
} }
} }
ty::ty_enum(_, _) => { ty::ty_enum(_, _) => {
let def_map = self.tcx.def_map.borrow(); match self.tcx.def_map.borrow().get_copy(&expr.id) {
match def_map.get().get_copy(&expr.id) {
ast::DefVariant(enum_id, variant_id, _) => { ast::DefVariant(enum_id, variant_id, _) => {
for field in fields.iter() { for field in fields.iter() {
self.check_field(expr.span, variant_id, self.check_field(expr.span, variant_id,
@ -877,8 +872,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
} }
} }
ty::ty_enum(_, _) => { ty::ty_enum(_, _) => {
let def_map = self.tcx.def_map.borrow(); match self.tcx.def_map.borrow().find(&pattern.id) {
match def_map.get().find(&pattern.id) {
Some(&ast::DefVariant(enum_id, variant_id, _)) => { Some(&ast::DefVariant(enum_id, variant_id, _)) => {
for field in fields.iter() { for field in fields.iter() {
self.check_field(pattern.span, variant_id, self.check_field(pattern.span, variant_id,
@ -1176,7 +1170,7 @@ struct CheckTypeForPrivatenessVisitor<'a, 'b> {
impl<'a> VisiblePrivateTypesVisitor<'a> { impl<'a> VisiblePrivateTypesVisitor<'a> {
fn path_is_private_type(&self, path_id: ast::NodeId) -> bool { fn path_is_private_type(&self, path_id: ast::NodeId) -> bool {
let did = match self.tcx.def_map.borrow().get().find_copy(&path_id) { let did = match self.tcx.def_map.borrow().find_copy(&path_id) {
// `int` etc. (None doesn't seem to occur.) // `int` etc. (None doesn't seem to occur.)
None | Some(ast::DefPrimTy(..)) => return false, None | Some(ast::DefPrimTy(..)) => return false,
Some(def) => def_id_of_def(def) Some(def) => def_id_of_def(def)

View File

@ -100,7 +100,7 @@ impl<'a> Visitor<()> for ReachableContext<'a> {
match expr.node { match expr.node {
ast::ExprPath(_) => { ast::ExprPath(_) => {
let def = match self.tcx.def_map.borrow().get().find(&expr.id) { let def = match self.tcx.def_map.borrow().find(&expr.id) {
Some(&def) => def, Some(&def) => def,
None => { None => {
self.tcx.sess.span_bug(expr.span, self.tcx.sess.span_bug(expr.span,
@ -133,7 +133,7 @@ impl<'a> Visitor<()> for ReachableContext<'a> {
} }
ast::ExprMethodCall(..) => { ast::ExprMethodCall(..) => {
let method_call = typeck::MethodCall::expr(expr.id); let method_call = typeck::MethodCall::expr(expr.id);
match self.method_map.borrow().get().get(&method_call).origin { match self.method_map.borrow().get(&method_call).origin {
typeck::MethodStatic(def_id) => { typeck::MethodStatic(def_id) => {
if is_local(def_id) { if is_local(def_id) {
if self.def_id_represents_local_inlined_item(def_id) { if self.def_id_represents_local_inlined_item(def_id) {
@ -330,7 +330,7 @@ impl<'a> ReachableContext<'a> {
// this properly would result in the necessity of computing *type* // this properly would result in the necessity of computing *type*
// reachability, which might result in a compile time loss. // reachability, which might result in a compile time loss.
fn mark_destructors_reachable(&mut self) { fn mark_destructors_reachable(&mut self) {
for (_, destructor_def_id) in self.tcx.destructor_for_type.borrow().get().iter() { for (_, destructor_def_id) in self.tcx.destructor_for_type.borrow().iter() {
if destructor_def_id.krate == ast::LOCAL_CRATE { if destructor_def_id.krate == ast::LOCAL_CRATE {
self.reachable_symbols.insert(destructor_def_id.node); self.reachable_symbols.insert(destructor_def_id.node);
} }

View File

@ -100,8 +100,7 @@ struct RegionResolutionVisitor<'a> {
impl RegionMaps { impl RegionMaps {
pub fn relate_free_regions(&self, sub: FreeRegion, sup: FreeRegion) { pub fn relate_free_regions(&self, sub: FreeRegion, sup: FreeRegion) {
let mut free_region_map = self.free_region_map.borrow_mut(); match self.free_region_map.borrow_mut().find_mut(&sub) {
match free_region_map.get().find_mut(&sub) {
Some(sups) => { Some(sups) => {
if !sups.iter().any(|x| x == &sup) { if !sups.iter().any(|x| x == &sup) {
sups.push(sup); sups.push(sup);
@ -112,32 +111,25 @@ impl RegionMaps {
} }
debug!("relate_free_regions(sub={:?}, sup={:?})", sub, sup); debug!("relate_free_regions(sub={:?}, sup={:?})", sub, sup);
self.free_region_map.borrow_mut().insert(sub, vec!(sup));
free_region_map.get().insert(sub, vec!(sup));
} }
pub fn record_encl_scope(&self, sub: ast::NodeId, sup: ast::NodeId) { pub fn record_encl_scope(&self, sub: ast::NodeId, sup: ast::NodeId) {
debug!("record_encl_scope(sub={}, sup={})", sub, sup); debug!("record_encl_scope(sub={}, sup={})", sub, sup);
assert!(sub != sup); assert!(sub != sup);
self.scope_map.borrow_mut().insert(sub, sup);
let mut scope_map = self.scope_map.borrow_mut();
scope_map.get().insert(sub, sup);
} }
pub fn record_var_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) { pub fn record_var_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) {
debug!("record_var_scope(sub={}, sup={})", var, lifetime); debug!("record_var_scope(sub={}, sup={})", var, lifetime);
assert!(var != lifetime); assert!(var != lifetime);
self.var_map.borrow_mut().insert(var, lifetime);
let mut var_map = self.var_map.borrow_mut();
var_map.get().insert(var, lifetime);
} }
pub fn record_rvalue_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) { pub fn record_rvalue_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) {
debug!("record_rvalue_scope(sub={}, sup={})", var, lifetime); debug!("record_rvalue_scope(sub={}, sup={})", var, lifetime);
assert!(var != lifetime); assert!(var != lifetime);
self.rvalue_scopes.borrow_mut().insert(var, lifetime);
let mut rvalue_scopes = self.rvalue_scopes.borrow_mut();
rvalue_scopes.get().insert(var, lifetime);
} }
pub fn mark_as_terminating_scope(&self, scope_id: ast::NodeId) { pub fn mark_as_terminating_scope(&self, scope_id: ast::NodeId) {
@ -149,22 +141,17 @@ impl RegionMaps {
*/ */
debug!("record_terminating_scope(scope_id={})", scope_id); debug!("record_terminating_scope(scope_id={})", scope_id);
let mut terminating_scopes = self.terminating_scopes.borrow_mut(); self.terminating_scopes.borrow_mut().insert(scope_id);
terminating_scopes.get().insert(scope_id);
} }
pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> { pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
//! Returns the narrowest scope that encloses `id`, if any. //! Returns the narrowest scope that encloses `id`, if any.
self.scope_map.borrow().find(&id).map(|x| *x)
let scope_map = self.scope_map.borrow();
scope_map.get().find(&id).map(|x| *x)
} }
pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId { pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId {
//! Returns the narrowest scope that encloses `id`, if any. //! Returns the narrowest scope that encloses `id`, if any.
match self.scope_map.borrow().find(&id) {
let scope_map = self.scope_map.borrow();
match scope_map.get().find(&id) {
Some(&r) => r, Some(&r) => r,
None => { fail!("no enclosing scope for id {}", id); } None => { fail!("no enclosing scope for id {}", id); }
} }
@ -174,9 +161,7 @@ impl RegionMaps {
/*! /*!
* Returns the lifetime of the local variable `var_id` * Returns the lifetime of the local variable `var_id`
*/ */
match self.var_map.borrow().find(&var_id) {
let var_map = self.var_map.borrow();
match var_map.get().find(&var_id) {
Some(&r) => r, Some(&r) => r,
None => { fail!("no enclosing scope for id {}", var_id); } None => { fail!("no enclosing scope for id {}", var_id); }
} }
@ -186,8 +171,7 @@ impl RegionMaps {
//! Returns the scope when temp created by expr_id will be cleaned up //! Returns the scope when temp created by expr_id will be cleaned up
// check for a designated rvalue scope // check for a designated rvalue scope
let rvalue_scopes = self.rvalue_scopes.borrow(); match self.rvalue_scopes.borrow().find(&expr_id) {
match rvalue_scopes.get().find(&expr_id) {
Some(&s) => { Some(&s) => {
debug!("temporary_scope({}) = {} [custom]", expr_id, s); debug!("temporary_scope({}) = {} [custom]", expr_id, s);
return Some(s); return Some(s);
@ -204,8 +188,7 @@ impl RegionMaps {
None => { return None; } None => { return None; }
}; };
let terminating_scopes = self.terminating_scopes.borrow(); while !self.terminating_scopes.borrow().contains(&id) {
while !terminating_scopes.get().contains(&id) {
match self.opt_encl_scope(id) { match self.opt_encl_scope(id) {
Some(p) => { Some(p) => {
id = p; id = p;
@ -249,8 +232,7 @@ impl RegionMaps {
let mut s = subscope; let mut s = subscope;
while superscope != s { while superscope != s {
let scope_map = self.scope_map.borrow(); match self.scope_map.borrow().find(&s) {
match scope_map.get().find(&s) {
None => { None => {
debug!("is_subscope_of({}, {}, s={})=false", debug!("is_subscope_of({}, {}, s={})=false",
subscope, superscope, s); subscope, superscope, s);
@ -286,8 +268,7 @@ impl RegionMaps {
let mut queue = vec!(sub); let mut queue = vec!(sub);
let mut i = 0; let mut i = 0;
while i < queue.len() { while i < queue.len() {
let free_region_map = self.free_region_map.borrow(); match self.free_region_map.borrow().find(queue.get(i)) {
match free_region_map.get().find(queue.get(i)) {
Some(parents) => { Some(parents) => {
for parent in parents.iter() { for parent in parents.iter() {
if *parent == sup { if *parent == sup {
@ -391,8 +372,7 @@ impl RegionMaps {
let mut result = vec!(scope); let mut result = vec!(scope);
let mut scope = scope; let mut scope = scope;
loop { loop {
let scope_map = this.scope_map.borrow(); match this.scope_map.borrow().find(&scope) {
match scope_map.get().find(&scope) {
None => return result, None => return result,
Some(&superscope) => { Some(&superscope) => {
result.push(superscope); result.push(superscope);

File diff suppressed because it is too large Load Diff

View File

@ -355,8 +355,8 @@ fn trans_opt<'a>(bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> {
fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt { fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt {
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let def_map = ccx.tcx.def_map.borrow(); let def = ccx.tcx.def_map.borrow().get_copy(&pat_id);
match def_map.get().get_copy(&pat_id) { match def {
ast::DefVariant(enum_id, var_id, _) => { ast::DefVariant(enum_id, var_id, _) => {
let variants = ty::enum_variants(ccx.tcx(), enum_id); let variants = ty::enum_variants(ccx.tcx(), enum_id);
for v in (*variants).iter() { for v in (*variants).iter() {
@ -636,10 +636,7 @@ fn enter_opt<'r,'b>(
let answer = match p.node { let answer = match p.node {
ast::PatEnum(..) | ast::PatEnum(..) |
ast::PatIdent(_, _, None) if pat_is_const(tcx.def_map, p) => { ast::PatIdent(_, _, None) if pat_is_const(tcx.def_map, p) => {
let const_def = { let const_def = tcx.def_map.borrow().get_copy(&p.id);
let def_map = tcx.def_map.borrow();
def_map.get().get_copy(&p.id)
};
let const_def_id = ast_util::def_id_of_def(const_def); let const_def_id = ast_util::def_id_of_def(const_def);
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) { if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
Some(Vec::new()) Some(Vec::new())
@ -678,11 +675,7 @@ fn enter_opt<'r,'b>(
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) { if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
// Look up the struct variant ID. // Look up the struct variant ID.
let struct_id; let struct_id;
let defn = { match tcx.def_map.borrow().get_copy(&p.id) {
let def_map = tcx.def_map.borrow();
def_map.get().get_copy(&p.id)
};
match defn {
ast::DefVariant(_, found_struct_id, _) => { ast::DefVariant(_, found_struct_id, _) => {
struct_id = found_struct_id; struct_id = found_struct_id;
} }
@ -964,10 +957,7 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
ast::PatIdent(..) => { ast::PatIdent(..) => {
// This is one of: an enum variant, a unit-like struct, or a // This is one of: an enum variant, a unit-like struct, or a
// variable binding. // variable binding.
let opt_def = { let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
let def_map = ccx.tcx.def_map.borrow();
def_map.get().find_copy(&cur.id)
};
match opt_def { match opt_def {
Some(ast::DefVariant(..)) => { Some(ast::DefVariant(..)) => {
add_to_set(ccx.tcx(), &mut found, add_to_set(ccx.tcx(), &mut found,
@ -987,10 +977,7 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
ast::PatEnum(..) | ast::PatStruct(..) => { ast::PatEnum(..) | ast::PatStruct(..) => {
// This could be one of: a tuple-like enum variant, a // This could be one of: a tuple-like enum variant, a
// struct-like enum variant, or a struct. // struct-like enum variant, or a struct.
let opt_def = { let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
let def_map = ccx.tcx.def_map.borrow();
def_map.get().find_copy(&cur.id)
};
match opt_def { match opt_def {
Some(ast::DefFn(..)) | Some(ast::DefFn(..)) |
Some(ast::DefVariant(..)) => { Some(ast::DefVariant(..)) => {
@ -1147,8 +1134,7 @@ fn pats_require_rooting(bcx: &Block, m: &[Match], col: uint) -> bool {
m.iter().any(|br| { m.iter().any(|br| {
let pat_id = br.pats.get(col).id; let pat_id = br.pats.get(col).id;
let key = root_map_key {id: pat_id, derefs: 0u }; let key = root_map_key {id: pat_id, derefs: 0u };
let root_map = bcx.ccx().maps.root_map.borrow(); bcx.ccx().maps.root_map.borrow().contains_key(&key)
root_map.get().contains_key(&key)
}) })
} }
@ -1184,8 +1170,7 @@ fn any_tuple_struct_pat(bcx: &Block, m: &[Match], col: uint) -> bool {
let pat = *br.pats.get(col); let pat = *br.pats.get(col);
match pat.node { match pat.node {
ast::PatEnum(_, Some(_)) => { ast::PatEnum(_, Some(_)) => {
let def_map = bcx.tcx().def_map.borrow(); match bcx.tcx().def_map.borrow().find(&pat.id) {
match def_map.get().find(&pat.id) {
Some(&ast::DefFn(..)) | Some(&ast::DefFn(..)) |
Some(&ast::DefStruct(..)) => true, Some(&ast::DefStruct(..)) => true,
_ => false _ => false
@ -1387,13 +1372,10 @@ fn insert_lllocals<'a>(bcx: &'a Block<'a>,
let datum = Datum(llval, binding_info.ty, Lvalue); let datum = Datum(llval, binding_info.ty, Lvalue);
fcx.schedule_drop_mem(cleanup_scope, llval, binding_info.ty); fcx.schedule_drop_mem(cleanup_scope, llval, binding_info.ty);
{ debug!("binding {:?} to {}",
debug!("binding {:?} to {}", binding_info.id,
binding_info.id, bcx.val_to_str(llval));
bcx.val_to_str(llval)); bcx.fcx.lllocals.borrow_mut().insert(binding_info.id, datum);
let mut llmap = bcx.fcx.lllocals.borrow_mut();
llmap.get().insert(binding_info.id, datum);
}
if bcx.sess().opts.debuginfo == FullDebugInfo { if bcx.sess().opts.debuginfo == FullDebugInfo {
debuginfo::create_match_binding_metadata(bcx, debuginfo::create_match_binding_metadata(bcx,
@ -1458,8 +1440,7 @@ fn compile_guard<'r,
} }
TrByRef => {} TrByRef => {}
} }
let mut lllocals = bcx.fcx.lllocals.borrow_mut(); bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
lllocals.get().remove(&binding_info.id);
} }
return bcx; return bcx;
} }
@ -2096,8 +2077,8 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>,
// already put it in a temporary alloca and gave it up, unless // already put it in a temporary alloca and gave it up, unless
// we emit extra-debug-info, which requires local allocas :(. // we emit extra-debug-info, which requires local allocas :(.
let arg_val = arg.add_clean(bcx.fcx, arg_scope); let arg_val = arg.add_clean(bcx.fcx, arg_scope);
let mut llmap = bcx.fcx.llargs.borrow_mut(); bcx.fcx.llargs.borrow_mut()
llmap.get().insert(pat.id, Datum(arg_val, arg_ty, Lvalue)); .insert(pat.id, Datum(arg_val, arg_ty, Lvalue));
bcx bcx
} else { } else {
mk_binding_alloca( mk_binding_alloca(
@ -2143,7 +2124,7 @@ fn mk_binding_alloca<'a,A>(bcx: &'a Block<'a>,
BindLocal => bcx.fcx.lllocals.borrow_mut(), BindLocal => bcx.fcx.lllocals.borrow_mut(),
BindArgument => bcx.fcx.llargs.borrow_mut() BindArgument => bcx.fcx.llargs.borrow_mut()
}; };
llmap.get().insert(p_id, datum); llmap.insert(p_id, datum);
bcx bcx
} }
@ -2219,9 +2200,9 @@ fn bind_irrefutable_pat<'a>(
} }
} }
ast::PatEnum(_, ref sub_pats) => { ast::PatEnum(_, ref sub_pats) => {
let def_map = bcx.tcx().def_map.borrow(); let opt_def = bcx.tcx().def_map.borrow().find_copy(&pat.id);
match def_map.get().find(&pat.id) { match opt_def {
Some(&ast::DefVariant(enum_id, var_id, _)) => { Some(ast::DefVariant(enum_id, var_id, _)) => {
let repr = adt::represent_node(bcx, pat.id); let repr = adt::represent_node(bcx, pat.id);
let vinfo = ty::enum_variant_with_id(ccx.tcx(), let vinfo = ty::enum_variant_with_id(ccx.tcx(),
enum_id, enum_id,
@ -2238,8 +2219,8 @@ fn bind_irrefutable_pat<'a>(
} }
} }
} }
Some(&ast::DefFn(..)) | Some(ast::DefFn(..)) |
Some(&ast::DefStruct(..)) => { Some(ast::DefStruct(..)) => {
match *sub_pats { match *sub_pats {
None => { None => {
// This is a unit-like struct. Nothing to do here. // This is a unit-like struct. Nothing to do here.
@ -2257,7 +2238,7 @@ fn bind_irrefutable_pat<'a>(
} }
} }
} }
Some(&ast::DefStatic(_, false)) => { Some(ast::DefStatic(_, false)) => {
} }
_ => { _ => {
// Nothing to do here. // Nothing to do here.

View File

@ -118,18 +118,14 @@ pub fn represent_node(bcx: &Block, node: ast::NodeId) -> @Repr {
/// Decides how to represent a given type. /// Decides how to represent a given type.
pub fn represent_type(cx: &CrateContext, t: ty::t) -> @Repr { pub fn represent_type(cx: &CrateContext, t: ty::t) -> @Repr {
debug!("Representing: {}", ty_to_str(cx.tcx(), t)); debug!("Representing: {}", ty_to_str(cx.tcx(), t));
{ match cx.adt_reprs.borrow().find(&t) {
let adt_reprs = cx.adt_reprs.borrow(); Some(repr) => return *repr,
match adt_reprs.get().find(&t) { None => {}
Some(repr) => return *repr,
None => {}
}
} }
let repr = @represent_type_uncached(cx, t); let repr = @represent_type_uncached(cx, t);
debug!("Represented as: {:?}", repr) debug!("Represented as: {:?}", repr)
let mut adt_reprs = cx.adt_reprs.borrow_mut(); cx.adt_reprs.borrow_mut().insert(t, repr);
adt_reprs.get().insert(t, repr);
return repr; return repr;
} }

View File

@ -161,12 +161,9 @@ impl<'a> Drop for StatRecorder<'a> {
let end = time::precise_time_ns(); let end = time::precise_time_ns();
let elapsed = ((end - self.start) / 1_000_000) as uint; let elapsed = ((end - self.start) / 1_000_000) as uint;
let iend = self.ccx.stats.n_llvm_insns.get(); let iend = self.ccx.stats.n_llvm_insns.get();
{ self.ccx.stats.fn_stats.borrow_mut().push((self.name.take_unwrap(),
let mut fn_stats = self.ccx.stats.fn_stats.borrow_mut(); elapsed,
fn_stats.get().push((self.name.take_unwrap(), iend - self.istart));
elapsed,
iend - self.istart));
}
self.ccx.stats.n_fns.set(self.ccx.stats.n_fns.get() + 1); self.ccx.stats.n_fns.set(self.ccx.stats.n_fns.get() + 1);
// Reset LLVM insn count to avoid compound costs. // Reset LLVM insn count to avoid compound costs.
self.ccx.stats.n_llvm_insns.set(self.istart); self.ccx.stats.n_llvm_insns.set(self.istart);
@ -232,12 +229,9 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef,
fn get_extern_rust_fn(ccx: &CrateContext, inputs: &[ty::t], output: ty::t, fn get_extern_rust_fn(ccx: &CrateContext, inputs: &[ty::t], output: ty::t,
name: &str, did: ast::DefId) -> ValueRef { name: &str, did: ast::DefId) -> ValueRef {
{ match ccx.externs.borrow().find_equiv(&name) {
let externs = ccx.externs.borrow(); Some(n) => return *n,
match externs.get().find_equiv(&name) { None => ()
Some(n) => return *n,
None => ()
}
} }
let f = decl_rust_fn(ccx, false, inputs, output, name); let f = decl_rust_fn(ccx, false, inputs, output, name);
@ -245,8 +239,7 @@ fn get_extern_rust_fn(ccx: &CrateContext, inputs: &[ty::t], output: ty::t,
set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f) set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f)
}); });
let mut externs = ccx.externs.borrow_mut(); ccx.externs.borrow_mut().insert(name.to_owned(), f);
externs.get().insert(name.to_owned(), f);
f f
} }
@ -448,19 +441,15 @@ pub fn get_tydesc_simple(ccx: &CrateContext, t: ty::t) -> ValueRef {
} }
pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info { pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
{ match ccx.tydescs.borrow().find(&t) {
let tydescs = ccx.tydescs.borrow(); Some(&inf) => return inf,
match tydescs.get().find(&t) { _ => { }
Some(&inf) => return inf,
_ => { }
}
} }
ccx.stats.n_static_tydescs.set(ccx.stats.n_static_tydescs.get() + 1u); ccx.stats.n_static_tydescs.set(ccx.stats.n_static_tydescs.get() + 1u);
let inf = glue::declare_tydesc(ccx, t); let inf = glue::declare_tydesc(ccx, t);
let mut tydescs = ccx.tydescs.borrow_mut(); ccx.tydescs.borrow_mut().insert(t, inf);
tydescs.get().insert(t, inf);
return inf; return inf;
} }
@ -519,11 +508,10 @@ pub fn set_no_split_stack(f: ValueRef) {
// Double-check that we never ask LLVM to declare the same symbol twice. It // Double-check that we never ask LLVM to declare the same symbol twice. It
// silently mangles such symbols, breaking our linkage model. // silently mangles such symbols, breaking our linkage model.
pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) { pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {
let mut all_llvm_symbols = ccx.all_llvm_symbols.borrow_mut(); if ccx.all_llvm_symbols.borrow().contains(&sym) {
if all_llvm_symbols.get().contains(&sym) {
ccx.sess().bug(~"duplicate LLVM symbol: " + sym); ccx.sess().bug(~"duplicate LLVM symbol: " + sym);
} }
all_llvm_symbols.get().insert(sym); ccx.all_llvm_symbols.borrow_mut().insert(sym);
} }
@ -561,11 +549,8 @@ pub fn get_res_dtor(ccx: &CrateContext,
ty::lookup_item_type(tcx, parent_id).ty); ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty); let llty = type_of_dtor(ccx, class_ty);
{ get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod, name,
let mut externs = ccx.externs.borrow_mut(); lib::llvm::CCallConv, llty, ty::mk_nil())
get_extern_fn(externs.get(), ccx.llmod, name,
lib::llvm::CCallConv, llty, ty::mk_nil())
}
} }
} }
@ -889,9 +874,8 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis); let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
let cconv = c.unwrap_or(lib::llvm::CCallConv); let cconv = c.unwrap_or(lib::llvm::CCallConv);
let llty = type_of_fn_from_ty(ccx, t); let llty = type_of_fn_from_ty(ccx, t);
let mut externs = ccx.externs.borrow_mut(); get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod,
get_extern_fn(externs.get(), ccx.llmod, name, name, cconv, llty, fn_ty.sig.output)
cconv, llty, fn_ty.sig.output)
} }
} }
} }
@ -904,8 +888,8 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
} }
_ => { _ => {
let llty = type_of(ccx, t); let llty = type_of(ccx, t);
let mut externs = ccx.externs.borrow_mut(); get_extern_const(&mut *ccx.externs.borrow_mut(), ccx.llmod, name,
get_extern_const(externs.get(), ccx.llmod, name, llty) llty)
} }
} }
} }
@ -1709,8 +1693,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
static"); static");
} }
let const_values = ccx.const_values.borrow(); let v = ccx.const_values.borrow().get_copy(&item.id);
let v = const_values.get().get_copy(&item.id);
unsafe { unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
ccx.sess().span_fatal(expr.span, "static assertion failed"); ccx.sess().span_fatal(expr.span, "static assertion failed");
@ -1766,7 +1749,7 @@ pub fn trans_mod(ccx: &CrateContext, m: &ast::Mod) {
fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: ~str, node_id: ast::NodeId, fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: ~str, node_id: ast::NodeId,
llfn: ValueRef) { llfn: ValueRef) {
ccx.item_symbols.borrow_mut().get().insert(node_id, sym); ccx.item_symbols.borrow_mut().insert(node_id, sym);
if !ccx.reachable.contains(&node_id) { if !ccx.reachable.contains(&node_id) {
lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage); lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage);
@ -1919,241 +1902,222 @@ fn exported_name(ccx: &CrateContext, id: ast::NodeId,
pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
debug!("get_item_val(id=`{:?}`)", id); debug!("get_item_val(id=`{:?}`)", id);
let val = { match ccx.item_vals.borrow().find_copy(&id) {
let item_vals = ccx.item_vals.borrow(); Some(v) => return v,
item_vals.get().find_copy(&id) None => {}
}; }
match val { let mut foreign = false;
Some(v) => v, let item = ccx.tcx.map.get(id);
None => { let val = match item {
let mut foreign = false; ast_map::NodeItem(i) => {
let item = ccx.tcx.map.get(id); let ty = ty::node_id_to_type(ccx.tcx(), i.id);
let val = match item { let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
ast_map::NodeItem(i) => {
let ty = ty::node_id_to_type(ccx.tcx(), i.id);
let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
let v = match i.node { let v = match i.node {
ast::ItemStatic(_, _, expr) => { ast::ItemStatic(_, _, expr) => {
// If this static came from an external crate, then // If this static came from an external crate, then
// we need to get the symbol from csearch instead of // we need to get the symbol from csearch instead of
// using the current crate's name/version // using the current crate's name/version
// information in the hash of the symbol // information in the hash of the symbol
debug!("making {}", sym); debug!("making {}", sym);
let (sym, is_local) = { let (sym, is_local) = {
let external_srcs = ccx.external_srcs match ccx.external_srcs.borrow().find(&i.id) {
.borrow(); Some(&did) => {
match external_srcs.get().find(&i.id) { debug!("but found in other crate...");
Some(&did) => { (csearch::get_symbol(&ccx.sess().cstore,
debug!("but found in other crate..."); did), false)
(csearch::get_symbol(&ccx.sess().cstore,
did), false)
}
None => (sym, true)
}
};
// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
let (v, inlineable) = consts::const_expr(ccx, expr, is_local);
{
let mut const_values = ccx.const_values
.borrow_mut();
const_values.get().insert(id, v);
}
let mut inlineable = inlineable;
unsafe {
let llty = llvm::LLVMTypeOf(v);
let g = sym.with_c_str(|buf| {
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
});
if !ccx.reachable.contains(&id) {
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
}
// Apply the `unnamed_addr` attribute if
// requested
if attr::contains_name(i.attrs.as_slice(),
"address_insignificant") {
if ccx.reachable.contains(&id) {
ccx.sess().span_bug(i.span,
"insignificant static is reachable");
}
lib::llvm::SetUnnamedAddr(g, true);
// This is a curious case where we must make
// all of these statics inlineable. If a
// global is tagged as
// address_insignificant, then LLVM won't
// coalesce globals unless they have an
// internal linkage type. This means that
// external crates cannot use this global.
// This is a problem for things like inner
// statics in generic functions, because the
// function will be inlined into another
// crate and then attempt to link to the
// static in the original crate, only to
// find that it's not there. On the other
// side of inlininig, the crates knows to
// not declare this static as
// available_externally (because it isn't)
inlineable = true;
}
if attr::contains_name(i.attrs.as_slice(),
"thread_local") {
lib::llvm::set_thread_local(g, true);
}
if !inlineable {
debug!("{} not inlined", sym);
let mut non_inlineable_statics =
ccx.non_inlineable_statics
.borrow_mut();
non_inlineable_statics.get().insert(id);
}
let mut item_symbols = ccx.item_symbols
.borrow_mut();
item_symbols.get().insert(i.id, sym);
g
} }
None => (sym, true)
} }
ast::ItemFn(_, purity, _, _, _) => {
let llfn = if purity != ast::ExternFn {
register_fn(ccx, i.span, sym, i.id, ty)
} else {
foreign::register_rust_fn_with_foreign_abi(ccx,
i.span,
sym,
i.id)
};
set_llvm_fn_attrs(i.attrs.as_slice(), llfn);
llfn
}
_ => fail!("get_item_val: weird result in table")
}; };
match attr::first_attr_value_str_by_name(i.attrs // We need the translated value here, because for enums the
.as_slice(), // LLVM type is not fully determined by the Rust type.
"link_section") { let (v, inlineable) = consts::const_expr(ccx, expr, is_local);
Some(sect) => unsafe { ccx.const_values.borrow_mut().insert(id, v);
sect.get().with_c_str(|buf| { let mut inlineable = inlineable;
llvm::LLVMSetSection(v, buf);
})
},
None => ()
}
v unsafe {
} let llty = llvm::LLVMTypeOf(v);
let g = sym.with_c_str(|buf| {
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
});
ast_map::NodeTraitMethod(trait_method) => { if !ccx.reachable.contains(&id) {
debug!("get_item_val(): processing a NodeTraitMethod"); lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
match *trait_method {
ast::Required(_) => {
ccx.sess().bug("unexpected variant: required trait method in \
get_item_val()");
} }
ast::Provided(m) => {
register_method(ccx, id, m) // Apply the `unnamed_addr` attribute if
// requested
if attr::contains_name(i.attrs.as_slice(),
"address_insignificant") {
if ccx.reachable.contains(&id) {
ccx.sess().span_bug(i.span,
"insignificant static is reachable");
}
lib::llvm::SetUnnamedAddr(g, true);
// This is a curious case where we must make
// all of these statics inlineable. If a
// global is tagged as
// address_insignificant, then LLVM won't
// coalesce globals unless they have an
// internal linkage type. This means that
// external crates cannot use this global.
// This is a problem for things like inner
// statics in generic functions, because the
// function will be inlined into another
// crate and then attempt to link to the
// static in the original crate, only to
// find that it's not there. On the other
// side of inlininig, the crates knows to
// not declare this static as
// available_externally (because it isn't)
inlineable = true;
} }
if attr::contains_name(i.attrs.as_slice(),
"thread_local") {
lib::llvm::set_thread_local(g, true);
}
if !inlineable {
debug!("{} not inlined", sym);
ccx.non_inlineable_statics.borrow_mut()
.insert(id);
}
ccx.item_symbols.borrow_mut().insert(i.id, sym);
g
} }
} }
ast_map::NodeMethod(m) => { ast::ItemFn(_, purity, _, _, _) => {
register_method(ccx, id, m) let llfn = if purity != ast::ExternFn {
} register_fn(ccx, i.span, sym, i.id, ty)
} else {
ast_map::NodeForeignItem(ni) => { foreign::register_rust_fn_with_foreign_abi(ccx,
foreign = true; i.span,
sym,
match ni.node { i.id)
ast::ForeignItemFn(..) => { };
let abis = ccx.tcx.map.get_foreign_abis(id); set_llvm_fn_attrs(i.attrs.as_slice(), llfn);
foreign::register_foreign_item_fn(ccx, abis, ni)
}
ast::ForeignItemStatic(..) => {
foreign::register_static(ccx, ni)
}
}
}
ast_map::NodeVariant(ref v) => {
let llfn;
match v.node.kind {
ast::TupleVariantKind(ref args) => {
assert!(args.len() != 0u);
let ty = ty::node_id_to_type(ccx.tcx(), id);
let parent = ccx.tcx.map.get_parent(id);
let enm = ccx.tcx.map.expect_item(parent);
let sym = exported_name(ccx,
id,
ty,
enm.attrs.as_slice());
llfn = match enm.node {
ast::ItemEnum(_, _) => {
register_fn(ccx, (*v).span, sym, id, ty)
}
_ => fail!("NodeVariant, shouldn't happen")
};
}
ast::StructVariantKind(_) => {
fail!("struct variant kind unexpected in get_item_val")
}
}
set_inline_hint(llfn);
llfn llfn
} }
ast_map::NodeStructCtor(struct_def) => { _ => fail!("get_item_val: weird result in table")
// Only register the constructor if this is a tuple-like struct.
match struct_def.ctor_id {
None => {
ccx.sess().bug("attempt to register a constructor of \
a non-tuple-like struct")
}
Some(ctor_id) => {
let parent = ccx.tcx.map.get_parent(id);
let struct_item = ccx.tcx.map.expect_item(parent);
let ty = ty::node_id_to_type(ccx.tcx(), ctor_id);
let sym = exported_name(ccx,
id,
ty,
struct_item.attrs
.as_slice());
let llfn = register_fn(ccx, struct_item.span,
sym, ctor_id, ty);
set_inline_hint(llfn);
llfn
}
}
}
ref variant => {
ccx.sess().bug(format!("get_item_val(): unexpected variant: {:?}",
variant))
}
}; };
// foreign items (extern fns and extern statics) don't have internal match attr::first_attr_value_str_by_name(i.attrs.as_slice(),
// linkage b/c that doesn't quite make sense. Otherwise items can "link_section") {
// have internal linkage if they're not reachable. Some(sect) => unsafe {
if !foreign && !ccx.reachable.contains(&id) { sect.get().with_c_str(|buf| {
lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage); llvm::LLVMSetSection(v, buf);
})
},
None => ()
} }
let mut item_vals = ccx.item_vals.borrow_mut(); v
item_vals.get().insert(id, val);
val
} }
ast_map::NodeTraitMethod(trait_method) => {
debug!("get_item_val(): processing a NodeTraitMethod");
match *trait_method {
ast::Required(_) => {
ccx.sess().bug("unexpected variant: required trait method in \
get_item_val()");
}
ast::Provided(m) => {
register_method(ccx, id, m)
}
}
}
ast_map::NodeMethod(m) => {
register_method(ccx, id, m)
}
ast_map::NodeForeignItem(ni) => {
foreign = true;
match ni.node {
ast::ForeignItemFn(..) => {
let abis = ccx.tcx.map.get_foreign_abis(id);
foreign::register_foreign_item_fn(ccx, abis, ni)
}
ast::ForeignItemStatic(..) => {
foreign::register_static(ccx, ni)
}
}
}
ast_map::NodeVariant(ref v) => {
let llfn;
let args = match v.node.kind {
ast::TupleVariantKind(ref args) => args,
ast::StructVariantKind(_) => {
fail!("struct variant kind unexpected in get_item_val")
}
};
assert!(args.len() != 0u);
let ty = ty::node_id_to_type(ccx.tcx(), id);
let parent = ccx.tcx.map.get_parent(id);
let enm = ccx.tcx.map.expect_item(parent);
let sym = exported_name(ccx,
id,
ty,
enm.attrs.as_slice());
llfn = match enm.node {
ast::ItemEnum(_, _) => {
register_fn(ccx, (*v).span, sym, id, ty)
}
_ => fail!("NodeVariant, shouldn't happen")
};
set_inline_hint(llfn);
llfn
}
ast_map::NodeStructCtor(struct_def) => {
// Only register the constructor if this is a tuple-like struct.
let ctor_id = match struct_def.ctor_id {
None => {
ccx.sess().bug("attempt to register a constructor of \
a non-tuple-like struct")
}
Some(ctor_id) => ctor_id,
};
let parent = ccx.tcx.map.get_parent(id);
let struct_item = ccx.tcx.map.expect_item(parent);
let ty = ty::node_id_to_type(ccx.tcx(), ctor_id);
let sym = exported_name(ccx,
id,
ty,
struct_item.attrs
.as_slice());
let llfn = register_fn(ccx, struct_item.span,
sym, ctor_id, ty);
set_inline_hint(llfn);
llfn
}
ref variant => {
ccx.sess().bug(format!("get_item_val(): unexpected variant: {:?}",
variant))
}
};
// foreign items (extern fns and extern statics) don't have internal
// linkage b/c that doesn't quite make sense. Otherwise items can
// have internal linkage if they're not reachable.
if !foreign && !ccx.reachable.contains(&id) {
lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage);
} }
ccx.item_vals.borrow_mut().insert(id, val);
val
} }
fn register_method(ccx: &CrateContext, id: ast::NodeId, fn register_method(ccx: &CrateContext, id: ast::NodeId,
@ -2542,11 +2506,10 @@ pub fn trans_crate(krate: ast::Crate,
println!("n_inlines: {}", ccx.stats.n_inlines.get()); println!("n_inlines: {}", ccx.stats.n_inlines.get());
println!("n_closures: {}", ccx.stats.n_closures.get()); println!("n_closures: {}", ccx.stats.n_closures.get());
println!("fn stats:"); println!("fn stats:");
let mut fn_stats = ccx.stats.fn_stats.borrow_mut(); ccx.stats.fn_stats.borrow_mut().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
fn_stats.get().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
insns_b.cmp(&insns_a) insns_b.cmp(&insns_a)
}); });
for tuple in fn_stats.get().iter() { for tuple in ccx.stats.fn_stats.borrow().iter() {
match *tuple { match *tuple {
(ref name, ms, insns) => { (ref name, ms, insns) => {
println!("{} insns, {} ms, {}", insns, ms, *name); println!("{} insns, {} ms, {}", insns, ms, *name);
@ -2555,8 +2518,7 @@ pub fn trans_crate(krate: ast::Crate,
} }
} }
if ccx.sess().count_llvm_insns() { if ccx.sess().count_llvm_insns() {
let llvm_insns = ccx.stats.llvm_insns.borrow(); for (k, v) in ccx.stats.llvm_insns.borrow().iter() {
for (k, v) in llvm_insns.get().iter() {
println!("{:7u} {}", *v, *k); println!("{:7u} {}", *v, *k);
} }
} }
@ -2566,7 +2528,7 @@ pub fn trans_crate(krate: ast::Crate,
let llmod = ccx.llmod; let llmod = ccx.llmod;
let mut reachable: Vec<~str> = ccx.reachable.iter().filter_map(|id| { let mut reachable: Vec<~str> = ccx.reachable.iter().filter_map(|id| {
ccx.item_symbols.borrow().get().find(id).map(|s| s.to_owned()) ccx.item_symbols.borrow().find(id).map(|s| s.to_owned())
}).collect(); }).collect();
// Make sure that some other crucial symbols are not eliminated from the // Make sure that some other crucial symbols are not eliminated from the

View File

@ -79,11 +79,11 @@ impl<'a> Builder<'a> {
s.push_char('/'); s.push_char('/');
s.push_str(category); s.push_str(category);
let n = match h.get().find(&s) { let n = match h.find(&s) {
Some(&n) => n, Some(&n) => n,
_ => 0u _ => 0u
}; };
h.get().insert(s, n+1u); h.insert(s, n+1u);
}) })
} }
} }

View File

@ -399,7 +399,7 @@ pub fn trans_fn_ref_with_vtables(
let ref_ty = match node { let ref_ty = match node {
ExprId(id) => node_id_type(bcx, id), ExprId(id) => node_id_type(bcx, id),
MethodCall(method_call) => { MethodCall(method_call) => {
let t = bcx.ccx().maps.method_map.borrow().get().get(&method_call).ty; let t = bcx.ccx().maps.method_map.borrow().get(&method_call).ty;
monomorphize_type(bcx, t) monomorphize_type(bcx, t)
} }
}; };
@ -482,7 +482,7 @@ pub fn trans_method_call<'a>(
let _icx = push_ctxt("trans_method_call"); let _icx = push_ctxt("trans_method_call");
debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx())); debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx()));
let method_call = MethodCall::expr(call_ex.id); let method_call = MethodCall::expr(call_ex.id);
let method_ty = bcx.ccx().maps.method_map.borrow().get().get(&method_call).ty; let method_ty = bcx.ccx().maps.method_map.borrow().get(&method_call).ty;
trans_call_inner( trans_call_inner(
bcx, bcx,
Some(common::expr_info(call_ex)), Some(common::expr_info(call_ex)),

View File

@ -194,8 +194,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
* Returns the id of the top-most loop scope * Returns the id of the top-most loop scope
*/ */
let scopes = self.scopes.borrow(); for scope in self.scopes.borrow().iter().rev() {
for scope in scopes.get().iter().rev() {
match scope.kind { match scope.kind {
LoopScopeKind(id, _) => { LoopScopeKind(id, _) => {
return id; return id;
@ -316,8 +315,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
debug!("schedule_clean_in_ast_scope(cleanup_scope={:?})", debug!("schedule_clean_in_ast_scope(cleanup_scope={:?})",
cleanup_scope); cleanup_scope);
let mut scopes = self.scopes.borrow_mut(); for scope in self.scopes.borrow_mut().mut_iter().rev() {
for scope in scopes.get().mut_iter().rev() {
if scope.kind.is_ast_with_id(cleanup_scope) { if scope.kind.is_ast_with_id(cleanup_scope) {
scope.cleanups.push(cleanup); scope.cleanups.push(cleanup);
scope.clear_cached_exits(); scope.clear_cached_exits();
@ -347,7 +345,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
assert!(self.is_valid_custom_scope(custom_scope)); assert!(self.is_valid_custom_scope(custom_scope));
let mut scopes = self.scopes.borrow_mut(); let mut scopes = self.scopes.borrow_mut();
let scope = scopes.get().get_mut(custom_scope.index); let scope = scopes.get_mut(custom_scope.index);
scope.cleanups.push(cleanup); scope.cleanups.push(cleanup);
scope.clear_cached_exits(); scope.clear_cached_exits();
} }
@ -358,8 +356,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
* execute on failure. * execute on failure.
*/ */
let scopes = self.scopes.borrow(); self.scopes.borrow().iter().rev().any(|s| s.needs_invoke())
scopes.get().iter().rev().any(|s| s.needs_invoke())
} }
fn get_landing_pad(&'a self) -> BasicBlockRef { fn get_landing_pad(&'a self) -> BasicBlockRef {
@ -405,8 +402,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
/*! /*!
* Returns the id of the current top-most AST scope, if any. * Returns the id of the current top-most AST scope, if any.
*/ */
let scopes = self.scopes.borrow(); for scope in self.scopes.borrow().iter().rev() {
for scope in scopes.get().iter().rev() {
match scope.kind { match scope.kind {
CustomScopeKind | LoopScopeKind(..) => {} CustomScopeKind | LoopScopeKind(..) => {}
AstScopeKind(i) => { AstScopeKind(i) => {
@ -418,20 +414,18 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
} }
fn top_nonempty_cleanup_scope(&self) -> Option<uint> { fn top_nonempty_cleanup_scope(&self) -> Option<uint> {
let scopes = self.scopes.borrow(); self.scopes.borrow().iter().rev().position(|s| !s.cleanups.is_empty())
scopes.get().iter().rev().position(|s| !s.cleanups.is_empty())
} }
fn is_valid_to_pop_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool { fn is_valid_to_pop_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool {
let scopes = self.scopes.borrow();
self.is_valid_custom_scope(custom_scope) && self.is_valid_custom_scope(custom_scope) &&
custom_scope.index == scopes.get().len() - 1 custom_scope.index == self.scopes.borrow().len() - 1
} }
fn is_valid_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool { fn is_valid_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool {
let scopes = self.scopes.borrow(); let scopes = self.scopes.borrow();
custom_scope.index < scopes.get().len() && custom_scope.index < scopes.len() &&
scopes.get().get(custom_scope.index).kind.is_temp() scopes.get(custom_scope.index).kind.is_temp()
} }
fn trans_scope_cleanups(&self, // cannot borrow self, will recurse fn trans_scope_cleanups(&self, // cannot borrow self, will recurse
@ -449,13 +443,11 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
} }
fn scopes_len(&self) -> uint { fn scopes_len(&self) -> uint {
let scopes = self.scopes.borrow(); self.scopes.borrow().len()
scopes.get().len()
} }
fn push_scope(&self, scope: CleanupScope<'a>) { fn push_scope(&self, scope: CleanupScope<'a>) {
let mut scopes = self.scopes.borrow_mut(); self.scopes.borrow_mut().push(scope)
scopes.get().push(scope);
} }
fn pop_scope(&self) -> CleanupScope<'a> { fn pop_scope(&self) -> CleanupScope<'a> {
@ -463,13 +455,11 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
self.top_scope(|s| s.block_name("")), self.top_scope(|s| s.block_name("")),
self.scopes_len() - 1); self.scopes_len() - 1);
let mut scopes = self.scopes.borrow_mut(); self.scopes.borrow_mut().pop().unwrap()
scopes.get().pop().unwrap()
} }
fn top_scope<R>(&self, f: |&CleanupScope<'a>| -> R) -> R { fn top_scope<R>(&self, f: |&CleanupScope<'a>| -> R) -> R {
let scopes = self.scopes.borrow(); f(self.scopes.borrow().last().unwrap())
f(scopes.get().last().unwrap())
} }
fn trans_cleanups_to_exit_scope(&'a self, fn trans_cleanups_to_exit_scope(&'a self,
@ -653,7 +643,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
// Check if a landing pad block exists; if not, create one. // Check if a landing pad block exists; if not, create one.
{ {
let mut scopes = self.scopes.borrow_mut(); let mut scopes = self.scopes.borrow_mut();
let last_scope = scopes.get().mut_last().unwrap(); let last_scope = scopes.mut_last().unwrap();
match last_scope.cached_landing_pad { match last_scope.cached_landing_pad {
Some(llbb) => { return llbb; } Some(llbb) => { return llbb; }
None => { None => {

View File

@ -317,10 +317,7 @@ fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
} }
let def_id = ast_util::def_id_of_def(cap_var.def); let def_id = ast_util::def_id_of_def(cap_var.def);
{ bcx.fcx.llupvars.borrow_mut().insert(def_id.node, upvarptr);
let mut llupvars = bcx.fcx.llupvars.borrow_mut();
llupvars.get().insert(def_id.node, upvarptr);
}
for &env_pointer_alloca in env_pointer_alloca.iter() { for &env_pointer_alloca in env_pointer_alloca.iter() {
debuginfo::create_captured_var_metadata( debuginfo::create_captured_var_metadata(
@ -395,7 +392,7 @@ pub fn trans_expr_fn<'a>(
// set an inline hint for all closures // set an inline hint for all closures
set_inline_hint(llfn); set_inline_hint(llfn);
let cap_vars = ccx.maps.capture_map.borrow().get().get_copy(&id); let cap_vars = ccx.maps.capture_map.borrow().get_copy(&id);
let ClosureResult {llbox, cdata_ty, bcx} = let ClosureResult {llbox, cdata_ty, bcx} =
build_closure(bcx, cap_vars.deref().as_slice(), sigil); build_closure(bcx, cap_vars.deref().as_slice(), sigil);
trans_closure(ccx, decl, body, llfn, trans_closure(ccx, decl, body, llfn,
@ -423,12 +420,9 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
} }
}; };
{ match ccx.closure_bare_wrapper_cache.borrow().find(&fn_ptr) {
let cache = ccx.closure_bare_wrapper_cache.borrow(); Some(&llval) => return llval,
match cache.get().find(&fn_ptr) { None => {}
Some(&llval) => return llval,
None => {}
}
} }
let tcx = ccx.tcx(); let tcx = ccx.tcx();
@ -457,10 +451,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
decl_rust_fn(ccx, true, f.sig.inputs.as_slice(), f.sig.output, name) decl_rust_fn(ccx, true, f.sig.inputs.as_slice(), f.sig.output, name)
}; };
{ ccx.closure_bare_wrapper_cache.borrow_mut().insert(fn_ptr, llfn);
let mut cache = ccx.closure_bare_wrapper_cache.borrow_mut();
cache.get().insert(fn_ptr, llfn);
}
// This is only used by statics inlined from a different crate. // This is only used by statics inlined from a different crate.
if !is_local { if !is_local {

View File

@ -465,8 +465,7 @@ impl<'a> Block<'a> {
} }
pub fn def(&self, nid: ast::NodeId) -> ast::Def { pub fn def(&self, nid: ast::NodeId) -> ast::Def {
let def_map = self.tcx().def_map.borrow(); match self.tcx().def_map.borrow().find(&nid) {
match def_map.get().find(&nid) {
Some(&v) => v, Some(&v) => v,
None => { None => {
self.tcx().sess.bug(format!( self.tcx().sess.bug(format!(
@ -584,12 +583,9 @@ pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef {
// our boxed-and-length-annotated strings. // our boxed-and-length-annotated strings.
pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef { pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
unsafe { unsafe {
{ match cx.const_cstr_cache.borrow().find(&s) {
let const_cstr_cache = cx.const_cstr_cache.borrow(); Some(&llval) => return llval,
match const_cstr_cache.get().find(&s) { None => ()
Some(&llval) => return llval,
None => ()
}
} }
let sc = llvm::LLVMConstStringInContext(cx.llcx, let sc = llvm::LLVMConstStringInContext(cx.llcx,
@ -605,8 +601,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
llvm::LLVMSetGlobalConstant(g, True); llvm::LLVMSetGlobalConstant(g, True);
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
let mut const_cstr_cache = cx.const_cstr_cache.borrow_mut(); cx.const_cstr_cache.borrow_mut().insert(s, g);
const_cstr_cache.get().insert(s, g);
g g
} }
} }
@ -795,7 +790,7 @@ pub fn expr_ty(bcx: &Block, ex: &ast::Expr) -> ty::t {
pub fn expr_ty_adjusted(bcx: &Block, ex: &ast::Expr) -> ty::t { pub fn expr_ty_adjusted(bcx: &Block, ex: &ast::Expr) -> ty::t {
let tcx = bcx.tcx(); let tcx = bcx.tcx();
let t = ty::expr_ty_adjusted(tcx, ex, bcx.ccx().maps.method_map.borrow().get()); let t = ty::expr_ty_adjusted(tcx, ex, &*bcx.ccx().maps.method_map.borrow());
monomorphize_type(bcx, t) monomorphize_type(bcx, t)
} }
@ -814,7 +809,7 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec<ty::t> {
let params = match node { let params = match node {
ExprId(id) => ty::node_id_to_type_params(tcx, id), ExprId(id) => ty::node_id_to_type_params(tcx, id),
MethodCall(method_call) => { MethodCall(method_call) => {
bcx.ccx().maps.method_map.borrow().get().get(&method_call).substs.tps.clone() bcx.ccx().maps.method_map.borrow().get(&method_call).substs.tps.clone()
} }
}; };
@ -837,7 +832,7 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec<ty::t> {
pub fn node_vtables(bcx: &Block, id: ast::NodeId) pub fn node_vtables(bcx: &Block, id: ast::NodeId)
-> Option<typeck::vtable_res> { -> Option<typeck::vtable_res> {
let vtable_map = bcx.ccx().maps.vtable_map.borrow(); let vtable_map = bcx.ccx().maps.vtable_map.borrow();
let raw_vtables = vtable_map.get().find(&id); let raw_vtables = vtable_map.find(&id);
raw_vtables.map(|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts)) raw_vtables.map(|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
} }

View File

@ -84,8 +84,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef { pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef {
unsafe { unsafe {
let b = llvm::LLVMConstPointerCast(a, t.ptr_to().to_ref()); let b = llvm::LLVMConstPointerCast(a, t.ptr_to().to_ref());
let mut const_globals = cx.const_globals.borrow_mut(); assert!(cx.const_globals.borrow_mut().insert(b as int, a));
assert!(const_globals.get().insert(b as int, a));
b b
} }
} }
@ -118,8 +117,7 @@ fn const_addr_of(cx: &CrateContext, cv: ValueRef) -> ValueRef {
} }
fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef { fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
let const_globals = cx.const_globals.borrow(); let v = match cx.const_globals.borrow().find(&(v as int)) {
let v = match const_globals.get().find(&(v as int)) {
Some(&v) => v, Some(&v) => v,
None => v None => v
}; };
@ -163,10 +161,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
pub fn get_const_val(cx: &CrateContext, pub fn get_const_val(cx: &CrateContext,
mut def_id: ast::DefId) -> (ValueRef, bool) { mut def_id: ast::DefId) -> (ValueRef, bool) {
let contains_key = { let contains_key = cx.const_values.borrow().contains_key(&def_id.node);
let const_values = cx.const_values.borrow();
const_values.get().contains_key(&def_id.node)
};
if !ast_util::is_local(def_id) || !contains_key { if !ast_util::is_local(def_id) || !contains_key {
if !ast_util::is_local(def_id) { if !ast_util::is_local(def_id) {
def_id = inline::maybe_instantiate_inline(cx, def_id); def_id = inline::maybe_instantiate_inline(cx, def_id);
@ -180,10 +175,8 @@ pub fn get_const_val(cx: &CrateContext,
} }
} }
let const_values = cx.const_values.borrow(); (cx.const_values.borrow().get_copy(&def_id.node),
let non_inlineable_statics = cx.non_inlineable_statics.borrow(); !cx.non_inlineable_statics.borrow().contains(&def_id.node))
(const_values.get().get_copy(&def_id.node),
!non_inlineable_statics.get().contains(&def_id.node))
} }
pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef, bool) { pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef, bool) {
@ -192,12 +185,9 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
let mut inlineable = inlineable; let mut inlineable = inlineable;
let ety = ty::expr_ty(cx.tcx(), e); let ety = ty::expr_ty(cx.tcx(), e);
let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e, let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e,
cx.maps.method_map.borrow().get()); &*cx.maps.method_map.borrow());
let adjustment = { let opt_adj = cx.tcx.adjustments.borrow().find_copy(&e.id);
let adjustments = cx.tcx.adjustments.borrow(); match opt_adj {
adjustments.get().find_copy(&e.id)
};
match adjustment {
None => { } None => { }
Some(adj) => { Some(adj) => {
match *adj { match *adj {
@ -424,7 +414,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
} }
ast::ExprField(base, field, _) => { ast::ExprField(base, field, _) => {
let bt = ty::expr_ty_adjusted(cx.tcx(), base, let bt = ty::expr_ty_adjusted(cx.tcx(), base,
cx.maps.method_map.borrow().get()); &*cx.maps.method_map.borrow());
let brepr = adt::represent_type(cx, bt); let brepr = adt::represent_type(cx, bt);
let (bv, inlineable) = const_expr(cx, base, is_local); let (bv, inlineable) = const_expr(cx, base, is_local);
expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| { expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| {
@ -435,7 +425,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
ast::ExprIndex(base, index) => { ast::ExprIndex(base, index) => {
let bt = ty::expr_ty_adjusted(cx.tcx(), base, let bt = ty::expr_ty_adjusted(cx.tcx(), base,
cx.maps.method_map.borrow().get()); &*cx.maps.method_map.borrow());
let (bv, inlineable) = const_expr(cx, base, is_local); let (bv, inlineable) = const_expr(cx, base, is_local);
let iv = match const_eval::eval_const_expr(cx.tcx(), index) { let iv = match const_eval::eval_const_expr(cx.tcx(), index) {
const_eval::const_int(i) => i as u64, const_eval::const_int(i) => i as u64,
@ -624,11 +614,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
// Assert that there are no type parameters in this path. // Assert that there are no type parameters in this path.
assert!(pth.segments.iter().all(|seg| seg.types.is_empty())); assert!(pth.segments.iter().all(|seg| seg.types.is_empty()));
let tcx = cx.tcx(); let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&e.id)
};
match opt_def { match opt_def {
Some(ast::DefFn(def_id, _purity)) => { Some(ast::DefFn(def_id, _purity)) => {
if !ast_util::is_local(def_id) { if !ast_util::is_local(def_id) {
@ -661,11 +647,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
} }
} }
ast::ExprCall(callee, ref args) => { ast::ExprCall(callee, ref args) => {
let tcx = cx.tcx(); let opt_def = cx.tcx().def_map.borrow().find_copy(&callee.id);
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&callee.id)
};
match opt_def { match opt_def {
Some(ast::DefStruct(_)) => { Some(ast::DefStruct(_)) => {
let ety = ty::expr_ty(cx.tcx(), e); let ety = ty::expr_ty(cx.tcx(), e);
@ -702,8 +684,7 @@ pub fn trans_const(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) {
let g = base::get_item_val(ccx, id); let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the // At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type. // constant's initializer to determine its LLVM type.
let const_values = ccx.const_values.borrow(); let v = ccx.const_values.borrow().get_copy(&id);
let v = const_values.get().get_copy(&id);
llvm::LLVMSetInitializer(g, v); llvm::LLVMSetInitializer(g, v);
if m != ast::MutMutable { if m != ast::MutMutable {
llvm::LLVMSetGlobalConstant(g, True); llvm::LLVMSetGlobalConstant(g, True);

View File

@ -273,8 +273,7 @@ pub fn trans_break_cont<'a>(bcx: &'a Block<'a>,
let loop_id = match opt_label { let loop_id = match opt_label {
None => fcx.top_loop_scope(), None => fcx.top_loop_scope(),
Some(_) => { Some(_) => {
let def_map = bcx.tcx().def_map.borrow(); match bcx.tcx().def_map.borrow().find(&expr_id) {
match def_map.get().find(&expr_id) {
Some(&ast::DefLabel(loop_id)) => loop_id, Some(&ast::DefLabel(loop_id)) => loop_id,
ref r => { ref r => {
bcx.tcx().sess.bug(format!("{:?} in def-map for label", r)) bcx.tcx().sess.bug(format!("{:?} in def-map for label", r))

View File

@ -294,15 +294,12 @@ pub fn create_local_var_metadata(bcx: &Block, local: &ast::Local) {
pat_util::pat_bindings(def_map, local.pat, |_, node_id, span, path_ref| { pat_util::pat_bindings(def_map, local.pat, |_, node_id, span, path_ref| {
let var_ident = ast_util::path_to_ident(path_ref); let var_ident = ast_util::path_to_ident(path_ref);
let datum = { let datum = match bcx.fcx.lllocals.borrow().find_copy(&node_id) {
let lllocals = bcx.fcx.lllocals.borrow(); Some(datum) => datum,
match lllocals.get().find_copy(&node_id) { None => {
Some(datum) => datum, bcx.sess().span_bug(span,
None => { format!("no entry in lllocals table for {:?}",
bcx.sess().span_bug(span, node_id));
format!("no entry in lllocals table for {:?}",
node_id));
}
} }
}; };
@ -436,15 +433,12 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) {
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata; let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata;
pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| { pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| {
let llarg = { let llarg = match bcx.fcx.llargs.borrow().find_copy(&node_id) {
let llargs = bcx.fcx.llargs.borrow(); Some(v) => v,
match llargs.get().find_copy(&node_id) { None => {
Some(v) => v, bcx.sess().span_bug(span,
None => { format!("no entry in llargs table for {:?}",
bcx.sess().span_bug(span, node_id));
format!("no entry in llargs table for {:?}",
node_id));
}
} }
}; };
@ -686,14 +680,11 @@ pub fn create_function_debug_context(cx: &CrateContext,
}; };
let arg_pats = fn_decl.inputs.map(|arg_ref| arg_ref.pat); let arg_pats = fn_decl.inputs.map(|arg_ref| arg_ref.pat);
{ populate_scope_map(cx,
let mut scope_map = fn_debug_context.scope_map.borrow_mut(); arg_pats.as_slice(),
populate_scope_map(cx, top_level_block,
arg_pats.as_slice(), fn_metadata,
top_level_block, &mut *fn_debug_context.scope_map.borrow_mut());
fn_metadata,
scope_map.get());
}
// Clear the debug location so we don't assign them in the function prelude // Clear the debug location so we don't assign them in the function prelude
set_debug_location(cx, UnknownLocation); set_debug_location(cx, UnknownLocation);
@ -1014,12 +1005,9 @@ fn declare_local(bcx: &Block,
} }
fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile { fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
{ match debug_context(cx).created_files.borrow().find_equiv(&full_path) {
let created_files = debug_context(cx).created_files.borrow(); Some(file_metadata) => return *file_metadata,
match created_files.get().find_equiv(&full_path) { None => ()
Some(file_metadata) => return *file_metadata,
None => ()
}
} }
debug!("file_metadata: {}", full_path); debug!("file_metadata: {}", full_path);
@ -1043,7 +1031,7 @@ fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
}); });
let mut created_files = debug_context(cx).created_files.borrow_mut(); let mut created_files = debug_context(cx).created_files.borrow_mut();
created_files.get().insert(full_path.to_owned(), file_metadata); created_files.insert(full_path.to_owned(), file_metadata);
return file_metadata; return file_metadata;
} }
@ -1053,9 +1041,7 @@ fn scope_metadata(fcx: &FunctionContext,
span: Span) span: Span)
-> DIScope { -> DIScope {
let scope_map = &fcx.debug_context.get_ref(fcx.ccx, span).scope_map; let scope_map = &fcx.debug_context.get_ref(fcx.ccx, span).scope_map;
let scope_map = scope_map.borrow(); match scope_map.borrow().find_copy(&node_id) {
match scope_map.get().find_copy(&node_id) {
Some(scope_metadata) => scope_metadata, Some(scope_metadata) => scope_metadata,
None => { None => {
let node = fcx.ccx.tcx.map.get(node_id); let node = fcx.ccx.tcx.map.get(node_id);
@ -1243,10 +1229,8 @@ impl RecursiveTypeDescription {
ref member_description_factory ref member_description_factory
} => { } => {
// Insert the stub into the cache in order to allow recursive references ... // Insert the stub into the cache in order to allow recursive references ...
{ debug_context(cx).created_types.borrow_mut()
let mut created_types = debug_context(cx).created_types.borrow_mut(); .insert(cache_id, metadata_stub);
created_types.get().insert(cache_id, metadata_stub);
}
// ... then create the member descriptions ... // ... then create the member descriptions ...
let member_descriptions = member_description_factory.create_member_descriptions(cx); let member_descriptions = member_description_factory.create_member_descriptions(cx);
@ -1649,12 +1633,12 @@ fn set_members_of_composite_type(cx: &CrateContext,
{ {
let mut composite_types_completed = let mut composite_types_completed =
debug_context(cx).composite_types_completed.borrow_mut(); debug_context(cx).composite_types_completed.borrow_mut();
if composite_types_completed.get().contains(&composite_type_metadata) { if composite_types_completed.contains(&composite_type_metadata) {
cx.sess().span_bug(definition_span, "debuginfo::set_members_of_composite_type() - \ cx.sess().span_bug(definition_span, "debuginfo::set_members_of_composite_type() - \
Already completed forward declaration \ Already completed forward declaration \
re-encountered."); re-encountered.");
} else { } else {
composite_types_completed.get().insert(composite_type_metadata); composite_types_completed.insert(composite_type_metadata);
} }
} }
@ -2035,12 +2019,9 @@ fn type_metadata(cx: &CrateContext,
-> DIType { -> DIType {
let cache_id = cache_id_for_type(t); let cache_id = cache_id_for_type(t);
{ match debug_context(cx).created_types.borrow().find(&cache_id) {
let created_types = debug_context(cx).created_types.borrow(); Some(type_metadata) => return *type_metadata,
match created_types.get().find(&cache_id) { None => ()
Some(type_metadata) => return *type_metadata,
None => ()
}
} }
fn create_pointer_to_box_metadata(cx: &CrateContext, fn create_pointer_to_box_metadata(cx: &CrateContext,
@ -2149,8 +2130,7 @@ fn type_metadata(cx: &CrateContext,
_ => cx.sess().bug(format!("debuginfo: unexpected type in type_metadata: {:?}", sty)) _ => cx.sess().bug(format!("debuginfo: unexpected type in type_metadata: {:?}", sty))
}; };
let mut created_types = debug_context(cx).created_types.borrow_mut(); debug_context(cx).created_types.borrow_mut().insert(cache_id, type_metadata);
created_types.get().insert(cache_id, type_metadata);
type_metadata type_metadata
} }
@ -2250,8 +2230,7 @@ fn fn_should_be_ignored(fcx: &FunctionContext) -> bool {
} }
fn assert_type_for_node_id(cx: &CrateContext, node_id: ast::NodeId, error_span: Span) { fn assert_type_for_node_id(cx: &CrateContext, node_id: ast::NodeId, error_span: Span) {
let node_types = cx.tcx.node_types.borrow(); if !cx.tcx.node_types.borrow().contains_key(&(node_id as uint)) {
if !node_types.get().contains_key(&(node_id as uint)) {
cx.sess().span_bug(error_span, "debuginfo: Could not find type for node id!"); cx.sess().span_bug(error_span, "debuginfo: Could not find type for node id!");
} }
} }
@ -2781,10 +2760,8 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> @NamespaceTreeNo
let name = path_element.name(); let name = path_element.name();
current_key.push(name); current_key.push(name);
let existing_node = { let existing_node = debug_context(cx).namespace_map.borrow()
let namespace_map = debug_context(cx).namespace_map.borrow(); .find_copy(&current_key);
namespace_map.get().find_copy(&current_key)
};
let current_node = match existing_node { let current_node = match existing_node {
Some(existing_node) => existing_node, Some(existing_node) => existing_node,
None => { None => {
@ -2813,11 +2790,8 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> @NamespaceTreeNo
parent: parent_node, parent: parent_node,
}; };
{ debug_context(cx).namespace_map.borrow_mut()
let mut namespace_map = debug_context(cx).namespace_map .insert(current_key.clone(), node);
.borrow_mut();
namespace_map.get().insert(current_key.clone(), node);
}
node node
} }

View File

@ -106,12 +106,7 @@ pub fn trans_into<'a>(bcx: &'a Block<'a>,
let mut bcx = bcx; let mut bcx = bcx;
let is_adjusted = { if bcx.tcx().adjustments.borrow().contains_key(&expr.id) {
let adjustments = bcx.tcx().adjustments.borrow();
adjustments.get().contains_key(&expr.id)
};
if is_adjusted {
// use trans, which may be less efficient but // use trans, which may be less efficient but
// which will perform the adjustments: // which will perform the adjustments:
let datum = unpack_datum!(bcx, trans(bcx, expr)); let datum = unpack_datum!(bcx, trans(bcx, expr));
@ -172,14 +167,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
let mut bcx = bcx; let mut bcx = bcx;
let mut datum = datum; let mut datum = datum;
let adjustment = { let adjustment = match bcx.tcx().adjustments.borrow().find_copy(&expr.id) {
let adjustments = bcx.tcx().adjustments.borrow(); None => {
match adjustments.get().find_copy(&expr.id) { return DatumBlock(bcx, datum);
None => {
return DatumBlock(bcx, datum);
}
Some(adj) => { adj }
} }
Some(adj) => { adj }
}; };
debug!("unadjusted datum for expr {}: {}", debug!("unadjusted datum for expr {}: {}",
expr.id, datum.to_str(bcx.ccx())); expr.id, datum.to_str(bcx.ccx()));
@ -210,7 +202,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
Some(AutoBorrowFn(..)) => { Some(AutoBorrowFn(..)) => {
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span, expr.id, datum.ty, let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span, expr.id, datum.ty,
Some(adjustment), |method_call| { Some(adjustment), |method_call| {
bcx.ccx().maps.method_map.borrow().get() bcx.ccx().maps.method_map.borrow()
.find(&method_call).map(|method| method.ty) .find(&method_call).map(|method| method.ty)
}); });
unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum)) unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum))
@ -222,7 +214,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
} }
AutoObject(..) => { AutoObject(..) => {
let adjusted_ty = ty::expr_ty_adjusted(bcx.tcx(), expr, let adjusted_ty = ty::expr_ty_adjusted(bcx.tcx(), expr,
bcx.ccx().maps.method_map.borrow().get()); &*bcx.ccx().maps.method_map.borrow());
let scratch = rvalue_scratch_datum(bcx, adjusted_ty, "__adjust"); let scratch = rvalue_scratch_datum(bcx, adjusted_ty, "__adjust");
bcx = meth::trans_trait_cast( bcx = meth::trans_trait_cast(
bcx, datum, expr.id, SaveIn(scratch.val)); bcx, datum, expr.id, SaveIn(scratch.val));
@ -567,13 +559,10 @@ fn trans_def<'a>(bcx: &'a Block<'a>,
let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to(); let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
PointerCast(bcx, val, pty) PointerCast(bcx, val, pty)
} else { } else {
{ match bcx.ccx().extern_const_values.borrow().find(&did) {
let extern_const_values = bcx.ccx().extern_const_values.borrow(); None => {} // Continue.
match extern_const_values.get().find(&did) { Some(llval) => {
None => {} // Continue. return *llval;
Some(llval) => {
return *llval;
}
} }
} }
@ -587,8 +576,8 @@ fn trans_def<'a>(bcx: &'a Block<'a>,
llty.to_ref(), llty.to_ref(),
buf) buf)
}); });
let mut extern_const_values = bcx.ccx().extern_const_values.borrow_mut(); bcx.ccx().extern_const_values.borrow_mut()
extern_const_values.get().insert(did, llval); .insert(did, llval);
llval llval
} }
} }
@ -898,8 +887,7 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
ast::DefUpvar(nid, _, _, _) => { ast::DefUpvar(nid, _, _, _) => {
// Can't move upvars, so this is never a ZeroMemLastUse. // Can't move upvars, so this is never a ZeroMemLastUse.
let local_ty = node_id_type(bcx, nid); let local_ty = node_id_type(bcx, nid);
let llupvars = bcx.fcx.llupvars.borrow(); match bcx.fcx.llupvars.borrow().find(&nid) {
match llupvars.get().find(&nid) {
Some(&val) => Datum(val, local_ty, Lvalue), Some(&val) => Datum(val, local_ty, Lvalue),
None => { None => {
bcx.sess().bug(format!( bcx.sess().bug(format!(
@ -908,12 +896,10 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
} }
} }
ast::DefArg(nid, _) => { ast::DefArg(nid, _) => {
let llargs = bcx.fcx.llargs.borrow(); take_local(bcx, &*bcx.fcx.llargs.borrow(), nid)
take_local(bcx, llargs.get(), nid)
} }
ast::DefLocal(nid, _) | ast::DefBinding(nid, _) => { ast::DefLocal(nid, _) | ast::DefBinding(nid, _) => {
let lllocals = bcx.fcx.lllocals.borrow(); take_local(bcx, &*bcx.fcx.lllocals.borrow(), nid)
take_local(bcx, lllocals.get(), nid)
} }
_ => { _ => {
bcx.sess().unimpl(format!( bcx.sess().unimpl(format!(
@ -965,11 +951,8 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
ty.repr(tcx))); ty.repr(tcx)));
} }
Some(node_id) => { Some(node_id) => {
let opt_def = { let def = tcx.def_map.borrow().get_copy(&node_id);
let def_map = tcx.def_map.borrow(); match def {
def_map.get().get_copy(&node_id)
};
match opt_def {
ast::DefVariant(enum_id, variant_id, _) => { ast::DefVariant(enum_id, variant_id, _) => {
let variant_info = ty::enum_variant_with_id( let variant_info = ty::enum_variant_with_id(
tcx, enum_id, variant_id); tcx, enum_id, variant_id);
@ -1159,7 +1142,7 @@ fn trans_unary<'a>(bcx: &'a Block<'a>,
// Otherwise, we should be in the RvalueDpsExpr path. // Otherwise, we should be in the RvalueDpsExpr path.
assert!( assert!(
op == ast::UnDeref || op == ast::UnDeref ||
!ccx.maps.method_map.borrow().get().contains_key(&method_call)); !ccx.maps.method_map.borrow().contains_key(&method_call));
let un_ty = expr_ty(bcx, expr); let un_ty = expr_ty(bcx, expr);
@ -1436,7 +1419,7 @@ fn trans_binary<'a>(bcx: &'a Block<'a>,
let ccx = bcx.ccx(); let ccx = bcx.ccx();
// if overloaded, would be RvalueDpsExpr // if overloaded, would be RvalueDpsExpr
assert!(!ccx.maps.method_map.borrow().get().contains_key(&MethodCall::expr(expr.id))); assert!(!ccx.maps.method_map.borrow().contains_key(&MethodCall::expr(expr.id)));
match op { match op {
ast::BiAnd => { ast::BiAnd => {
@ -1476,7 +1459,7 @@ fn trans_overloaded_op<'a, 'b>(
rhs: Option<(Datum<Expr>, ast::NodeId)>, rhs: Option<(Datum<Expr>, ast::NodeId)>,
dest: Option<Dest>) dest: Option<Dest>)
-> Result<'a> { -> Result<'a> {
let method_ty = bcx.ccx().maps.method_map.borrow().get().get(&method_call).ty; let method_ty = bcx.ccx().maps.method_map.borrow().get(&method_call).ty;
callee::trans_call_inner(bcx, callee::trans_call_inner(bcx,
Some(expr_info(expr)), Some(expr_info(expr)),
monomorphize_type(bcx, method_ty), monomorphize_type(bcx, method_ty),
@ -1644,7 +1627,7 @@ fn trans_assign_op<'a>(
debug!("trans_assign_op(expr={})", bcx.expr_to_str(expr)); debug!("trans_assign_op(expr={})", bcx.expr_to_str(expr));
// User-defined operator methods cannot be used with `+=` etc right now // User-defined operator methods cannot be used with `+=` etc right now
assert!(!bcx.ccx().maps.method_map.borrow().get().contains_key(&MethodCall::expr(expr.id))); assert!(!bcx.ccx().maps.method_map.borrow().contains_key(&MethodCall::expr(expr.id)));
// Evaluate LHS (destination), which should be an lvalue // Evaluate LHS (destination), which should be an lvalue
let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op")); let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op"));
@ -1722,7 +1705,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
expr_id: expr.id, expr_id: expr.id,
autoderef: derefs as u32 autoderef: derefs as u32
}; };
let method_ty = ccx.maps.method_map.borrow().get() let method_ty = ccx.maps.method_map.borrow()
.find(&method_call).map(|method| method.ty); .find(&method_call).map(|method| method.ty);
let datum = match method_ty { let datum = match method_ty {
Some(method_ty) => { Some(method_ty) => {

View File

@ -239,16 +239,12 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
// Create the LLVM value for the C extern fn // Create the LLVM value for the C extern fn
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys); let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
let llfn; let llfn = base::get_extern_fn(&mut *ccx.externs.borrow_mut(),
{
let mut externs = ccx.externs.borrow_mut();
llfn = base::get_extern_fn(externs.get(),
ccx.llmod, ccx.llmod,
lname.get(), lname.get(),
cc, cc,
llfn_ty, llfn_ty,
tys.fn_sig.output); tys.fn_sig.output);
};
add_argument_attributes(&tys, llfn); add_argument_attributes(&tys, llfn);
llfn llfn
@ -470,8 +466,8 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
} }
let lname = link_name(foreign_item); let lname = link_name(foreign_item);
let mut item_symbols = ccx.item_symbols.borrow_mut(); ccx.item_symbols.borrow_mut().insert(foreign_item.id,
item_symbols.get().insert(foreign_item.id, lname.get().to_owned()); lname.get().to_owned());
} }
} }

View File

@ -128,7 +128,7 @@ pub fn drop_ty_immediate<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef { pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
let t = get_drop_glue_type(ccx, t); let t = get_drop_glue_type(ccx, t);
match ccx.drop_glues.borrow().get().find(&t) { match ccx.drop_glues.borrow().find(&t) {
Some(&glue) => return glue, Some(&glue) => return glue,
_ => { } _ => { }
} }
@ -136,7 +136,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
let llfnty = Type::glue_fn(ccx, type_of(ccx, t).ptr_to()); let llfnty = Type::glue_fn(ccx, type_of(ccx, t).ptr_to());
let glue = declare_generic_glue(ccx, t, llfnty, "drop"); let glue = declare_generic_glue(ccx, t, llfnty, "drop");
ccx.drop_glues.borrow_mut().get().insert(t, glue); ccx.drop_glues.borrow_mut().insert(t, glue);
make_generic_glue(ccx, t, glue, make_drop_glue, "drop"); make_generic_glue(ccx, t, glue, make_drop_glue, "drop");
@ -476,8 +476,7 @@ pub fn emit_tydescs(ccx: &CrateContext) {
// As of this point, allow no more tydescs to be created. // As of this point, allow no more tydescs to be created.
ccx.finished_tydescs.set(true); ccx.finished_tydescs.set(true);
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to(); let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
let mut tyds = ccx.tydescs.borrow_mut(); for (_, &val) in ccx.tydescs.borrow().iter() {
for (_, &val) in tyds.get().iter() {
let ti = val; let ti = val;
// Each of the glue functions needs to be cast to a generic type // Each of the glue functions needs to be cast to a generic type

View File

@ -22,21 +22,18 @@ use syntax::attr;
pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
-> ast::DefId { -> ast::DefId {
let _icx = push_ctxt("maybe_instantiate_inline"); let _icx = push_ctxt("maybe_instantiate_inline");
{ match ccx.external.borrow().find(&fn_id) {
let external = ccx.external.borrow(); Some(&Some(node_id)) => {
match external.get().find(&fn_id) { // Already inline
Some(&Some(node_id)) => { debug!("maybe_instantiate_inline({}): already inline as node id {}",
// Already inline ty::item_path_str(ccx.tcx(), fn_id), node_id);
debug!("maybe_instantiate_inline({}): already inline as node id {}", return local_def(node_id);
ty::item_path_str(ccx.tcx(), fn_id), node_id); }
return local_def(node_id); Some(&None) => {
} return fn_id; // Not inlinable
Some(&None) => { }
return fn_id; // Not inlinable None => {
} // Not seen yet
None => {
// Not seen yet
}
} }
} }
@ -46,17 +43,12 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|a,b,c,d| astencode::decode_inlined_item(a, b, &ccx.maps, c, d)); |a,b,c,d| astencode::decode_inlined_item(a, b, &ccx.maps, c, d));
return match csearch_result { return match csearch_result {
csearch::not_found => { csearch::not_found => {
let mut external = ccx.external.borrow_mut(); ccx.external.borrow_mut().insert(fn_id, None);
external.get().insert(fn_id, None);
fn_id fn_id
} }
csearch::found(ast::IIItem(item)) => { csearch::found(ast::IIItem(item)) => {
{ ccx.external.borrow_mut().insert(fn_id, Some(item.id));
let mut external = ccx.external.borrow_mut(); ccx.external_srcs.borrow_mut().insert(item.id, fn_id);
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(item.id));
external_srcs.get().insert(item.id, fn_id);
}
ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1); ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1);
trans_item(ccx, item); trans_item(ccx, item);
@ -85,21 +77,13 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
local_def(item.id) local_def(item.id)
} }
csearch::found(ast::IIForeign(item)) => { csearch::found(ast::IIForeign(item)) => {
{ ccx.external.borrow_mut().insert(fn_id, Some(item.id));
let mut external = ccx.external.borrow_mut(); ccx.external_srcs.borrow_mut().insert(item.id, fn_id);
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(item.id));
external_srcs.get().insert(item.id, fn_id);
}
local_def(item.id) local_def(item.id)
} }
csearch::found_parent(parent_id, ast::IIItem(item)) => { csearch::found_parent(parent_id, ast::IIItem(item)) => {
{ ccx.external.borrow_mut().insert(parent_id, Some(item.id));
let mut external = ccx.external.borrow_mut(); ccx.external_srcs.borrow_mut().insert(item.id, parent_id);
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(parent_id, Some(item.id));
external_srcs.get().insert(item.id, parent_id);
}
let mut my_id = 0; let mut my_id = 0;
match item.node { match item.node {
@ -108,16 +92,14 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
let vs_there = ty::enum_variants(ccx.tcx(), parent_id); let vs_there = ty::enum_variants(ccx.tcx(), parent_id);
for (here, there) in vs_here.iter().zip(vs_there.iter()) { for (here, there) in vs_here.iter().zip(vs_there.iter()) {
if there.id == fn_id { my_id = here.id.node; } if there.id == fn_id { my_id = here.id.node; }
let mut external = ccx.external.borrow_mut(); ccx.external.borrow_mut().insert(there.id, Some(here.id.node));
external.get().insert(there.id, Some(here.id.node));
} }
} }
ast::ItemStruct(ref struct_def, _) => { ast::ItemStruct(ref struct_def, _) => {
match struct_def.ctor_id { match struct_def.ctor_id {
None => {} None => {}
Some(ctor_id) => { Some(ctor_id) => {
let mut external = ccx.external.borrow_mut(); ccx.external.borrow_mut().insert(fn_id, Some(ctor_id));
let _ = external.get().insert(fn_id, Some(ctor_id));
my_id = ctor_id; my_id = ctor_id;
} }
} }
@ -133,12 +115,8 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
with a non-item parent"); with a non-item parent");
} }
csearch::found(ast::IIMethod(impl_did, is_provided, mth)) => { csearch::found(ast::IIMethod(impl_did, is_provided, mth)) => {
{ ccx.external.borrow_mut().insert(fn_id, Some(mth.id));
let mut external = ccx.external.borrow_mut(); ccx.external_srcs.borrow_mut().insert(mth.id, fn_id);
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(mth.id));
external_srcs.get().insert(mth.id, fn_id);
}
ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1); ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1);

View File

@ -100,7 +100,7 @@ pub fn trans_method_callee<'a>(
let _icx = push_ctxt("meth::trans_method_callee"); let _icx = push_ctxt("meth::trans_method_callee");
let (origin, method_ty) = match bcx.ccx().maps.method_map let (origin, method_ty) = match bcx.ccx().maps.method_map
.borrow().get().find(&method_call) { .borrow().find(&method_call) {
Some(method) => { Some(method) => {
debug!("trans_method_callee({:?}, method={})", debug!("trans_method_callee({:?}, method={})",
method_call, method.repr(bcx.tcx())); method_call, method.repr(bcx.tcx()));
@ -208,7 +208,7 @@ pub fn trans_static_method_callee(bcx: &Block,
debug!("trans_static_method_callee: method_id={:?}, expr_id={:?}, \ debug!("trans_static_method_callee: method_id={:?}, expr_id={:?}, \
name={}", method_id, expr_id, token::get_name(mname)); name={}", method_id, expr_id, token::get_name(mname));
let vtbls = ccx.maps.vtable_map.borrow().get().get_copy(&expr_id); let vtbls = ccx.maps.vtable_map.borrow().get_copy(&expr_id);
let vtbls = resolve_vtables_in_fn_ctxt(bcx.fcx, vtbls); let vtbls = resolve_vtables_in_fn_ctxt(bcx.fcx, vtbls);
match vtbls.get(bound_index).get(0) { match vtbls.get(bound_index).get(0) {
@ -239,23 +239,18 @@ pub fn trans_static_method_callee(bcx: &Block,
pub fn method_with_name(ccx: &CrateContext, pub fn method_with_name(ccx: &CrateContext,
impl_id: ast::DefId, impl_id: ast::DefId,
name: ast::Name) -> ast::DefId { name: ast::Name) -> ast::DefId {
{ match ccx.impl_method_cache.borrow().find_copy(&(impl_id, name)) {
let impl_method_cache = ccx.impl_method_cache.borrow(); Some(m) => return m,
let meth_id_opt = impl_method_cache.get().find_copy(&(impl_id, name)); None => {}
match meth_id_opt {
Some(m) => return m,
None => {}
}
} }
let impls = ccx.tcx.impls.borrow(); let imp = ccx.tcx.impls.borrow();
let imp = impls.get().find(&impl_id) let imp = imp.find(&impl_id)
.expect("could not find impl while translating"); .expect("could not find impl while translating");
let meth = imp.methods.iter().find(|m| m.ident.name == name) let meth = imp.methods.iter().find(|m| m.ident.name == name)
.expect("could not find method while translating"); .expect("could not find method while translating");
let mut impl_method_cache = ccx.impl_method_cache.borrow_mut(); ccx.impl_method_cache.borrow_mut().insert((impl_id, name), meth.def_id);
impl_method_cache.get().insert((impl_id, name), meth.def_id);
meth.def_id meth.def_id
} }
@ -478,12 +473,9 @@ pub fn get_vtable(bcx: &Block,
// Check the cache. // Check the cache.
let hash_id = (self_ty, vtable_id(ccx, origins.get(0))); let hash_id = (self_ty, vtable_id(ccx, origins.get(0)));
{ match ccx.vtables.borrow().find(&hash_id) {
let vtables = ccx.vtables.borrow(); Some(&val) => { return val }
match vtables.get().find(&hash_id) { None => { }
Some(&val) => { return val }
None => { }
}
} }
// Not in the cache. Actually build it. // Not in the cache. Actually build it.
@ -507,8 +499,7 @@ pub fn get_vtable(bcx: &Block,
let drop_glue = glue::get_drop_glue(ccx, self_ty); let drop_glue = glue::get_drop_glue(ccx, self_ty);
let vtable = make_vtable(ccx, drop_glue, methods.as_slice()); let vtable = make_vtable(ccx, drop_glue, methods.as_slice());
let mut vtables = ccx.vtables.borrow_mut(); ccx.vtables.borrow_mut().insert(hash_id, vtable);
vtables.get().insert(hash_id, vtable);
return vtable; return vtable;
} }
@ -607,14 +598,9 @@ pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>,
// Store the vtable into the second half of pair. // Store the vtable into the second half of pair.
// This is structured a bit funny because of dynamic borrow failures. // This is structured a bit funny because of dynamic borrow failures.
let origins = { let res = *ccx.maps.vtable_map.borrow().get(&id);
let res = { let res = resolve_vtables_in_fn_ctxt(bcx.fcx, res);
let vtable_map = ccx.maps.vtable_map.borrow(); let origins = *res.get(0);
*vtable_map.get().get(&id)
};
let res = resolve_vtables_in_fn_ctxt(bcx.fcx, res);
*res.get(0)
};
let vtable = get_vtable(bcx, v_ty, origins); let vtable = get_vtable(bcx, v_ty, origins);
let llvtabledest = GEPi(bcx, lldest, [0u, abi::trt_field_vtable]); let llvtabledest = GEPi(bcx, lldest, [0u, abi::trt_field_vtable]);
let llvtabledest = PointerCast(bcx, llvtabledest, val_ty(vtable).ptr_to()); let llvtabledest = PointerCast(bcx, llvtabledest, val_ty(vtable).ptr_to());

View File

@ -74,16 +74,13 @@ pub fn monomorphic_fn(ccx: &CrateContext,
psubsts.repr(ccx.tcx()), psubsts.repr(ccx.tcx()),
hash_id); hash_id);
{ match ccx.monomorphized.borrow().find(&hash_id) {
let monomorphized = ccx.monomorphized.borrow(); Some(&val) => {
match monomorphized.get().find(&hash_id) {
Some(&val) => {
debug!("leaving monomorphic fn {}", debug!("leaving monomorphic fn {}",
ty::item_path_str(ccx.tcx(), fn_id)); ty::item_path_str(ccx.tcx(), fn_id));
return (val, must_cast); return (val, must_cast);
}
None => ()
} }
None => ()
} }
let tpt = ty::lookup_item_type(ccx.tcx(), fn_id); let tpt = ty::lookup_item_type(ccx.tcx(), fn_id);
@ -164,7 +161,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
let depth; let depth;
{ {
let mut monomorphizing = ccx.monomorphizing.borrow_mut(); let mut monomorphizing = ccx.monomorphizing.borrow_mut();
depth = match monomorphizing.get().find(&fn_id) { depth = match monomorphizing.find(&fn_id) {
Some(&d) => d, None => 0 Some(&d) => d, None => 0
}; };
@ -176,7 +173,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
"reached the recursion limit during monomorphization"); "reached the recursion limit during monomorphization");
} }
monomorphizing.get().insert(fn_id, depth + 1); monomorphizing.insert(fn_id, depth + 1);
} }
let s = ccx.tcx.map.with_path(fn_id.node, |path| { let s = ccx.tcx.map.with_path(fn_id.node, |path| {
@ -188,8 +185,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
let lldecl = decl_internal_rust_fn(ccx, false, let lldecl = decl_internal_rust_fn(ccx, false,
f.sig.inputs.as_slice(), f.sig.inputs.as_slice(),
f.sig.output, s); f.sig.output, s);
let mut monomorphized = ccx.monomorphized.borrow_mut(); ccx.monomorphized.borrow_mut().insert(hash_id, lldecl);
monomorphized.get().insert(hash_id, lldecl);
lldecl lldecl
}; };
@ -284,10 +280,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
} }
}; };
{ ccx.monomorphizing.borrow_mut().insert(fn_id, depth);
let mut monomorphizing = ccx.monomorphizing.borrow_mut();
monomorphizing.get().insert(fn_id, depth);
}
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id)); debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
(lldecl, must_cast) (lldecl, must_cast)

View File

@ -102,12 +102,9 @@ pub fn type_of_fn_from_ty(cx: &CrateContext, fty: ty::t) -> Type {
// recursive types. For example, enum types rely on this behavior. // recursive types. For example, enum types rely on this behavior.
pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type { pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
{ match cx.llsizingtypes.borrow().find_copy(&t) {
let llsizingtypes = cx.llsizingtypes.borrow(); Some(t) => return t,
match llsizingtypes.get().find_copy(&t) { None => ()
Some(t) => return t,
None => ()
}
} }
let llsizingty = match ty::get(t).sty { let llsizingty = match ty::get(t).sty {
@ -165,20 +162,16 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
} }
}; };
let mut llsizingtypes = cx.llsizingtypes.borrow_mut(); cx.llsizingtypes.borrow_mut().insert(t, llsizingty);
llsizingtypes.get().insert(t, llsizingty);
llsizingty llsizingty
} }
// NB: If you update this, be sure to update `sizing_type_of()` as well. // NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
// Check the cache. // Check the cache.
{ match cx.lltypes.borrow().find(&t) {
let lltypes = cx.lltypes.borrow(); Some(&llty) => return llty,
match lltypes.get().find(&t) { None => ()
Some(&llty) => return llty,
None => ()
}
} }
debug!("type_of {} {:?}", t.repr(cx.tcx()), t); debug!("type_of {} {:?}", t.repr(cx.tcx()), t);
@ -198,8 +191,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
t_norm.repr(cx.tcx()), t_norm.repr(cx.tcx()),
t_norm, t_norm,
cx.tn.type_to_str(llty)); cx.tn.type_to_str(llty));
let mut lltypes = cx.lltypes.borrow_mut(); cx.lltypes.borrow_mut().insert(t, llty);
lltypes.get().insert(t, llty);
return llty; return llty;
} }
@ -295,10 +287,8 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
t.repr(cx.tcx()), t.repr(cx.tcx()),
t, t,
cx.tn.type_to_str(llty)); cx.tn.type_to_str(llty));
{
let mut lltypes = cx.lltypes.borrow_mut(); cx.lltypes.borrow_mut().insert(t, llty);
lltypes.get().insert(t, llty);
}
// If this was an enum or struct, fill in the type now. // If this was an enum or struct, fill in the type now.
match ty::get(t).sty { match ty::get(t).sty {

View File

@ -34,8 +34,7 @@ pub fn root_and_write_guard<'a, K:KindOps>(datum: &Datum<K>,
// //
// (Note: root'd values are always boxes) // (Note: root'd values are always boxes)
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let root_map = ccx.maps.root_map.borrow(); match ccx.maps.root_map.borrow().find(&key) {
match root_map.get().find(&key) {
None => bcx, None => bcx,
Some(&root_info) => root(datum, bcx, span, key, root_info) Some(&root_info) => root(datum, bcx, span, key, root_info)
} }

View File

@ -1154,12 +1154,9 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
let key = intern_key { sty: &st }; let key = intern_key { sty: &st };
{ match cx.interner.borrow().find(&key) {
let mut interner = cx.interner.borrow_mut(); Some(t) => unsafe { return cast::transmute(&t.sty); },
match interner.get().find(&key) { _ => ()
Some(t) => unsafe { return cast::transmute(&t.sty); },
_ => ()
}
} }
let mut flags = 0u; let mut flags = 0u;
@ -1255,8 +1252,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
sty: sty_ptr, sty: sty_ptr,
}; };
let mut interner = cx.interner.borrow_mut(); cx.interner.borrow_mut().insert(key, t);
interner.get().insert(key, t);
cx.next_id.set(cx.next_id.get() + 1); cx.next_id.set(cx.next_id.get() + 1);
@ -1762,21 +1758,15 @@ pub fn type_needs_drop(cx: &ctxt, ty: t) -> bool {
// that only contain scalars and shared boxes can avoid unwind // that only contain scalars and shared boxes can avoid unwind
// cleanups. // cleanups.
pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool { pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool {
{ match cx.needs_unwind_cleanup_cache.borrow().find(&ty) {
let needs_unwind_cleanup_cache = cx.needs_unwind_cleanup_cache Some(&result) => return result,
.borrow(); None => ()
match needs_unwind_cleanup_cache.get().find(&ty) {
Some(&result) => return result,
None => ()
}
} }
let mut tycache = HashSet::new(); let mut tycache = HashSet::new();
let needs_unwind_cleanup = let needs_unwind_cleanup =
type_needs_unwind_cleanup_(cx, ty, &mut tycache, false); type_needs_unwind_cleanup_(cx, ty, &mut tycache, false);
let mut needs_unwind_cleanup_cache = cx.needs_unwind_cleanup_cache cx.needs_unwind_cleanup_cache.borrow_mut().insert(ty, needs_unwind_cleanup);
.borrow_mut();
needs_unwind_cleanup_cache.get().insert(ty, needs_unwind_cleanup);
return needs_unwind_cleanup; return needs_unwind_cleanup;
} }
@ -2094,19 +2084,15 @@ pub fn type_interior_is_unsafe(cx: &ctxt, t: ty::t) -> bool {
pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
let ty_id = type_id(ty); let ty_id = type_id(ty);
{ match cx.tc_cache.borrow().find(&ty_id) {
let tc_cache = cx.tc_cache.borrow(); Some(tc) => { return *tc; }
match tc_cache.get().find(&ty_id) { None => {}
Some(tc) => { return *tc; }
None => {}
}
} }
let mut cache = HashMap::new(); let mut cache = HashMap::new();
let result = tc_ty(cx, ty, &mut cache); let result = tc_ty(cx, ty, &mut cache);
let mut tc_cache = cx.tc_cache.borrow_mut(); cx.tc_cache.borrow_mut().insert(ty_id, result);
tc_cache.get().insert(ty_id, result);
return result; return result;
fn tc_ty(cx: &ctxt, fn tc_ty(cx: &ctxt,
@ -2139,12 +2125,9 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
Some(tc) => { return *tc; } Some(tc) => { return *tc; }
None => {} None => {}
} }
{ match cx.tc_cache.borrow().find(&ty_id) { // Must check both caches!
let tc_cache = cx.tc_cache.borrow(); Some(tc) => { return *tc; }
match tc_cache.get().find(&ty_id) { // Must check both caches! None => {}
Some(tc) => { return *tc; }
None => {}
}
} }
cache.insert(ty_id, TC::None); cache.insert(ty_id, TC::None);
@ -2243,7 +2226,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
assert_eq!(p.def_id.krate, ast::LOCAL_CRATE); assert_eq!(p.def_id.krate, ast::LOCAL_CRATE);
let ty_param_defs = cx.ty_param_defs.borrow(); let ty_param_defs = cx.ty_param_defs.borrow();
let tp_def = ty_param_defs.get().get(&p.def_id.node); let tp_def = ty_param_defs.get(&p.def_id.node);
kind_bounds_to_contents(cx, kind_bounds_to_contents(cx,
tp_def.bounds.builtin_bounds, tp_def.bounds.builtin_bounds,
tp_def.bounds.trait_bounds.as_slice()) tp_def.bounds.trait_bounds.as_slice())
@ -2686,7 +2669,7 @@ pub fn type_is_sized(cx: &ctxt, ty: ty::t) -> bool {
// FIXME(#6308) add trait, vec, str, etc here. // FIXME(#6308) add trait, vec, str, etc here.
ty_param(p) => { ty_param(p) => {
let ty_param_defs = cx.ty_param_defs.borrow(); let ty_param_defs = cx.ty_param_defs.borrow();
let param_def = ty_param_defs.get().get(&p.def_id.node); let param_def = ty_param_defs.get(&p.def_id.node);
if param_def.bounds.builtin_bounds.contains_elem(BoundSized) { if param_def.bounds.builtin_bounds.contains_elem(BoundSized) {
return true; return true;
} }
@ -2746,8 +2729,7 @@ pub fn index(t: t) -> Option<mt> {
} }
pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> @ty::TraitRef { pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> @ty::TraitRef {
let trait_refs = cx.trait_refs.borrow(); match cx.trait_refs.borrow().find(&id) {
match trait_refs.get().find(&id) {
Some(&t) => t, Some(&t) => t,
None => cx.sess.bug( None => cx.sess.bug(
format!("node_id_to_trait_ref: no trait ref for node `{}`", format!("node_id_to_trait_ref: no trait ref for node `{}`",
@ -2756,8 +2738,7 @@ pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> @ty::TraitRef {
} }
pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option<t> { pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option<t> {
let node_types = cx.node_types.borrow(); cx.node_types.borrow().find_copy(&(id as uint))
node_types.get().find_copy(&(id as uint))
} }
pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t { pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
@ -2770,9 +2751,7 @@ pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
} }
pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option<t> { pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option<t> {
let node_types = cx.node_types.borrow(); match cx.node_types.borrow().find(&(id as uint)) {
debug!("id: {:?}, node_types: {:?}", id, node_types);
match node_types.get().find(&(id as uint)) {
Some(&t) => Some(t), Some(&t) => Some(t),
None => None None => None
} }
@ -2780,16 +2759,14 @@ pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option<t> {
// FIXME(pcwalton): Makes a copy, bleh. Probably better to not do that. // FIXME(pcwalton): Makes a copy, bleh. Probably better to not do that.
pub fn node_id_to_type_params(cx: &ctxt, id: ast::NodeId) -> Vec<t> { pub fn node_id_to_type_params(cx: &ctxt, id: ast::NodeId) -> Vec<t> {
let node_type_substs = cx.node_type_substs.borrow(); match cx.node_type_substs.borrow().find(&id) {
match node_type_substs.get().find(&id) {
None => return Vec::new(), None => return Vec::new(),
Some(ts) => return (*ts).clone(), Some(ts) => return (*ts).clone(),
} }
} }
fn node_id_has_type_params(cx: &ctxt, id: ast::NodeId) -> bool { fn node_id_has_type_params(cx: &ctxt, id: ast::NodeId) -> bool {
let node_type_substs = cx.node_type_substs.borrow(); cx.node_type_substs.borrow().contains_key(&id)
node_type_substs.get().contains_key(&id)
} }
pub fn fn_is_variadic(fty: t) -> bool { pub fn fn_is_variadic(fty: t) -> bool {
@ -2970,7 +2947,7 @@ pub fn expr_ty_adjusted(cx: &ctxt,
*/ */
let unadjusted_ty = expr_ty(cx, expr); let unadjusted_ty = expr_ty(cx, expr);
let adjustment = cx.adjustments.borrow().get().find_copy(&expr.id); let adjustment = cx.adjustments.borrow().find_copy(&expr.id);
adjust_ty(cx, expr.span, expr.id, unadjusted_ty, adjustment, |method_call| { adjust_ty(cx, expr.span, expr.id, unadjusted_ty, adjustment, |method_call| {
method_map.find(&method_call).map(|method| method.ty) method_map.find(&method_call).map(|method| method.ty)
}) })
@ -3260,8 +3237,7 @@ pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
} }
pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def { pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def {
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&expr.id) {
match def_map.get().find(&expr.id) {
Some(&def) => def, Some(&def) => def,
None => { None => {
tcx.sess.span_bug(expr.span, format!( tcx.sess.span_bug(expr.span, format!(
@ -3294,7 +3270,7 @@ pub enum ExprKind {
pub fn expr_kind(tcx: &ctxt, pub fn expr_kind(tcx: &ctxt,
method_map: MethodMap, method_map: MethodMap,
expr: &ast::Expr) -> ExprKind { expr: &ast::Expr) -> ExprKind {
if method_map.borrow().get().contains_key(&MethodCall::expr(expr.id)) { if method_map.borrow().contains_key(&MethodCall::expr(expr.id)) {
// Overloaded operations are generally calls, and hence they are // Overloaded operations are generally calls, and hence they are
// generated via DPS, but there are two exceptions: // generated via DPS, but there are two exceptions:
return match expr.node { return match expr.node {
@ -3377,8 +3353,7 @@ pub fn expr_kind(tcx: &ctxt,
} }
ast::ExprCast(..) => { ast::ExprCast(..) => {
let node_types = tcx.node_types.borrow(); match tcx.node_types.borrow().find(&(expr.id as uint)) {
match node_types.get().find(&(expr.id as uint)) {
Some(&t) => { Some(&t) => {
if type_is_trait(t) { if type_is_trait(t) {
RvalueDpsExpr RvalueDpsExpr
@ -3426,8 +3401,7 @@ pub fn expr_kind(tcx: &ctxt,
ast::ExprBox(place, _) => { ast::ExprBox(place, _) => {
// Special case `~T` for now: // Special case `~T` for now:
let def_map = tcx.def_map.borrow(); let definition = match tcx.def_map.borrow().find(&place.id) {
let definition = match def_map.get().find(&place.id) {
Some(&def) => def, Some(&def) => def,
None => fail!("no def for place"), None => fail!("no def for place"),
}; };
@ -3709,8 +3683,7 @@ pub fn def_has_ty_params(def: ast::Def) -> bool {
} }
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> { pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
let provided_method_sources = cx.provided_method_sources.borrow(); cx.provided_method_sources.borrow().find(&id).map(|x| *x)
provided_method_sources.get().find(&id).map(|x| *x)
} }
pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<@Method> { pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<@Method> {
@ -3747,12 +3720,9 @@ pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<@Method> {
pub fn trait_supertraits(cx: &ctxt, id: ast::DefId) -> @Vec<@TraitRef> { pub fn trait_supertraits(cx: &ctxt, id: ast::DefId) -> @Vec<@TraitRef> {
// Check the cache. // Check the cache.
{ match cx.supertraits.borrow().find(&id) {
let supertraits = cx.supertraits.borrow(); Some(&trait_refs) => { return trait_refs; }
match supertraits.get().find(&id) { None => {} // Continue.
Some(&trait_refs) => { return trait_refs; }
None => {} // Continue.
}
} }
// Not in the cache. It had better be in the metadata, which means it // Not in the cache. It had better be in the metadata, which means it
@ -3762,8 +3732,7 @@ pub fn trait_supertraits(cx: &ctxt, id: ast::DefId) -> @Vec<@TraitRef> {
// Get the supertraits out of the metadata and create the // Get the supertraits out of the metadata and create the
// TraitRef for each. // TraitRef for each.
let result = @csearch::get_supertraits(cx, id); let result = @csearch::get_supertraits(cx, id);
let mut supertraits = cx.supertraits.borrow_mut(); cx.supertraits.borrow_mut().insert(id, result);
supertraits.get().insert(id, result);
return result; return result;
} }
@ -3808,42 +3777,38 @@ pub fn trait_method(cx: &ctxt, trait_did: ast::DefId, idx: uint) -> @Method {
pub fn trait_methods(cx: &ctxt, trait_did: ast::DefId) -> @Vec<@Method> { pub fn trait_methods(cx: &ctxt, trait_did: ast::DefId) -> @Vec<@Method> {
let mut trait_methods_cache = cx.trait_methods_cache.borrow_mut(); let mut trait_methods = cx.trait_methods_cache.borrow_mut();
match trait_methods_cache.get().find(&trait_did) { match trait_methods.find(&trait_did) {
Some(&methods) => methods, Some(&methods) => methods,
None => { None => {
let def_ids = ty::trait_method_def_ids(cx, trait_did); let def_ids = ty::trait_method_def_ids(cx, trait_did);
let methods = @def_ids.map(|d| ty::method(cx, *d)); let methods = @def_ids.map(|d| ty::method(cx, *d));
trait_methods_cache.get().insert(trait_did, methods); trait_methods.insert(trait_did, methods);
methods methods
} }
} }
} }
pub fn method(cx: &ctxt, id: ast::DefId) -> @Method { pub fn method(cx: &ctxt, id: ast::DefId) -> @Method {
let mut methods = cx.methods.borrow_mut(); lookup_locally_or_in_crate_store("methods", id,
lookup_locally_or_in_crate_store("methods", id, methods.get(), || { &mut *cx.methods.borrow_mut(), || {
@csearch::get_method(cx, id) @csearch::get_method(cx, id)
}) })
} }
pub fn trait_method_def_ids(cx: &ctxt, id: ast::DefId) -> @Vec<DefId> { pub fn trait_method_def_ids(cx: &ctxt, id: ast::DefId) -> @Vec<DefId> {
let mut trait_method_def_ids = cx.trait_method_def_ids.borrow_mut();
lookup_locally_or_in_crate_store("trait_method_def_ids", lookup_locally_or_in_crate_store("trait_method_def_ids",
id, id,
trait_method_def_ids.get(), &mut *cx.trait_method_def_ids.borrow_mut(),
|| { || {
@csearch::get_trait_method_def_ids(&cx.sess.cstore, id) @csearch::get_trait_method_def_ids(&cx.sess.cstore, id)
}) })
} }
pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<@TraitRef> { pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<@TraitRef> {
{ match cx.impl_trait_cache.borrow().find(&id) {
let mut impl_trait_cache = cx.impl_trait_cache.borrow_mut(); Some(&ret) => { return ret; }
match impl_trait_cache.get().find(&id) { None => {}
Some(&ret) => { return ret; }
None => {}
}
} }
let ret = if id.krate == ast::LOCAL_CRATE { let ret = if id.krate == ast::LOCAL_CRATE {
@ -3868,17 +3833,15 @@ pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<@TraitRef> {
csearch::get_impl_trait(cx, id) csearch::get_impl_trait(cx, id)
}; };
let mut impl_trait_cache = cx.impl_trait_cache.borrow_mut(); cx.impl_trait_cache.borrow_mut().insert(id, ret);
impl_trait_cache.get().insert(id, ret);
return ret; return ret;
} }
pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId { pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
let def_map = tcx.def_map.borrow(); let def = *tcx.def_map.borrow()
let def = def_map.get()
.find(&tr.ref_id) .find(&tr.ref_id)
.expect("no def-map entry for trait"); .expect("no def-map entry for trait");
ast_util::def_id_of_def(*def) ast_util::def_id_of_def(def)
} }
pub fn try_add_builtin_trait(tcx: &ctxt, pub fn try_add_builtin_trait(tcx: &ctxt,
@ -4021,8 +3984,7 @@ impl DtorKind {
/* If struct_id names a struct with a dtor, return Some(the dtor's id). /* If struct_id names a struct with a dtor, return Some(the dtor's id).
Otherwise return none. */ Otherwise return none. */
pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind { pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
let destructor_for_type = cx.destructor_for_type.borrow(); match cx.destructor_for_type.borrow().find(&struct_id) {
match destructor_for_type.get().find(&struct_id) {
Some(&method_def_id) => { Some(&method_def_id) => {
let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag"); let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag");
@ -4056,12 +4018,9 @@ pub fn type_is_empty(cx: &ctxt, t: t) -> bool {
} }
pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> @Vec<@VariantInfo> { pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> @Vec<@VariantInfo> {
{ match cx.enum_var_cache.borrow().find(&id) {
let enum_var_cache = cx.enum_var_cache.borrow(); Some(&variants) => return variants,
match enum_var_cache.get().find(&id) { _ => { /* fallthrough */ }
Some(&variants) => return variants,
_ => { /* fallthrough */ }
}
} }
let result = if ast::LOCAL_CRATE != id.krate { let result = if ast::LOCAL_CRATE != id.krate {
@ -4129,11 +4088,8 @@ pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> @Vec<@VariantInfo> {
} }
}; };
{ cx.enum_var_cache.borrow_mut().insert(id, result);
let mut enum_var_cache = cx.enum_var_cache.borrow_mut(); result
enum_var_cache.get().insert(id, result);
result
}
} }
@ -4160,25 +4116,23 @@ pub fn enum_variant_with_id(cx: &ctxt,
pub fn lookup_item_type(cx: &ctxt, pub fn lookup_item_type(cx: &ctxt,
did: ast::DefId) did: ast::DefId)
-> ty_param_bounds_and_ty { -> ty_param_bounds_and_ty {
let mut tcache = cx.tcache.borrow_mut();
lookup_locally_or_in_crate_store( lookup_locally_or_in_crate_store(
"tcache", did, tcache.get(), "tcache", did, &mut *cx.tcache.borrow_mut(),
|| csearch::get_type(cx, did)) || csearch::get_type(cx, did))
} }
pub fn lookup_impl_vtables(cx: &ctxt, pub fn lookup_impl_vtables(cx: &ctxt,
did: ast::DefId) did: ast::DefId)
-> typeck::impl_res { -> typeck::impl_res {
let mut impl_vtables = cx.impl_vtables.borrow_mut();
lookup_locally_or_in_crate_store( lookup_locally_or_in_crate_store(
"impl_vtables", did, impl_vtables.get(), "impl_vtables", did, &mut *cx.impl_vtables.borrow_mut(),
|| csearch::get_impl_vtables(cx, did) ) || csearch::get_impl_vtables(cx, did) )
} }
/// Given the did of a trait, returns its canonical trait ref. /// Given the did of a trait, returns its canonical trait ref.
pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> @ty::TraitDef { pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> @ty::TraitDef {
let mut trait_defs = cx.trait_defs.borrow_mut(); let mut trait_defs = cx.trait_defs.borrow_mut();
match trait_defs.get().find(&did) { match trait_defs.find(&did) {
Some(&trait_def) => { Some(&trait_def) => {
// The item is in this crate. The caller should have added it to the // The item is in this crate. The caller should have added it to the
// type cache already // type cache already
@ -4187,7 +4141,7 @@ pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> @ty::TraitDef {
None => { None => {
assert!(did.krate != ast::LOCAL_CRATE); assert!(did.krate != ast::LOCAL_CRATE);
let trait_def = @csearch::get_trait_def(cx, did); let trait_def = @csearch::get_trait_def(cx, did);
trait_defs.get().insert(did, trait_def); trait_defs.insert(did, trait_def);
return trait_def; return trait_def;
} }
} }
@ -4255,16 +4209,14 @@ pub fn lookup_field_type(tcx: &ctxt,
let t = if id.krate == ast::LOCAL_CRATE { let t = if id.krate == ast::LOCAL_CRATE {
node_id_to_type(tcx, id.node) node_id_to_type(tcx, id.node)
} else { } else {
{ let mut tcache = tcx.tcache.borrow_mut();
let mut tcache = tcx.tcache.borrow_mut(); match tcache.find(&id) {
match tcache.get().find(&id) { Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
Some(&ty_param_bounds_and_ty {ty, ..}) => ty, None => {
None => { let tpt = csearch::get_field_type(tcx, struct_id, id);
let tpt = csearch::get_field_type(tcx, struct_id, id); tcache.insert(id, tpt.clone());
tcache.get().insert(id, tpt.clone()); tpt.ty
tpt.ty }
}
}
} }
}; };
subst(tcx, substs, t) subst(tcx, substs, t)
@ -4444,23 +4396,14 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t {
fn tcx<'a>(&'a self) -> &'a ctxt { let TypeNormalizer(c) = *self; c } fn tcx<'a>(&'a self) -> &'a ctxt { let TypeNormalizer(c) = *self; c }
fn fold_ty(&mut self, t: ty::t) -> ty::t { fn fold_ty(&mut self, t: ty::t) -> ty::t {
let normalized_opt = { match self.tcx().normalized_cache.borrow().find_copy(&t) {
let normalized_cache = self.tcx().normalized_cache.borrow(); None => {}
normalized_cache.get().find_copy(&t) Some(u) => return u
};
match normalized_opt {
Some(u) => {
return u;
}
None => {
let t_norm = ty_fold::super_fold_ty(self, t);
let mut normalized_cache = self.tcx()
.normalized_cache
.borrow_mut();
normalized_cache.get().insert(t, t_norm);
return t_norm;
}
} }
let t_norm = ty_fold::super_fold_ty(self, t);
self.tcx().normalized_cache.borrow_mut().insert(t, t_norm);
return t_norm;
} }
fn fold_vstore(&mut self, vstore: vstore) -> vstore { fn fold_vstore(&mut self, vstore: vstore) -> vstore {
@ -4636,16 +4579,14 @@ pub fn count_traits_and_supertraits(tcx: &ctxt,
pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> { pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| { tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
let intrinsic_defs = tcx.intrinsic_defs.borrow(); tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item)
intrinsic_defs.get().find_copy(&tydesc_lang_item)
.expect("Failed to resolve TyDesc") .expect("Failed to resolve TyDesc")
}) })
} }
pub fn get_opaque_ty(tcx: &ctxt) -> Result<t, ~str> { pub fn get_opaque_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(OpaqueStructLangItem).map(|opaque_lang_item| { tcx.lang_items.require(OpaqueStructLangItem).map(|opaque_lang_item| {
let intrinsic_defs = tcx.intrinsic_defs.borrow(); tcx.intrinsic_defs.borrow().find_copy(&opaque_lang_item)
intrinsic_defs.get().find_copy(&opaque_lang_item)
.expect("Failed to resolve Opaque") .expect("Failed to resolve Opaque")
}) })
} }
@ -4672,9 +4613,8 @@ pub fn visitor_object_ty(tcx: &ctxt,
} }
pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> @ItemVariances { pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> @ItemVariances {
let mut item_variance_map = tcx.item_variance_map.borrow_mut();
lookup_locally_or_in_crate_store( lookup_locally_or_in_crate_store(
"item_variance_map", item_id, item_variance_map.get(), "item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),
|| @csearch::get_item_variances(&tcx.sess.cstore, item_id)) || @csearch::get_item_variances(&tcx.sess.cstore, item_id))
} }
@ -4684,18 +4624,17 @@ fn record_trait_implementation(tcx: &ctxt,
implementation: @Impl) { implementation: @Impl) {
let implementation_list; let implementation_list;
let mut trait_impls = tcx.trait_impls.borrow_mut(); let mut trait_impls = tcx.trait_impls.borrow_mut();
match trait_impls.get().find(&trait_def_id) { match trait_impls.find(&trait_def_id) {
None => { None => {
implementation_list = @RefCell::new(Vec::new()); implementation_list = @RefCell::new(Vec::new());
trait_impls.get().insert(trait_def_id, implementation_list); trait_impls.insert(trait_def_id, implementation_list);
} }
Some(&existing_implementation_list) => { Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list implementation_list = existing_implementation_list
} }
} }
let mut implementation_list = implementation_list.borrow_mut(); implementation_list.borrow_mut().push(implementation);
implementation_list.get().push(implementation);
} }
/// Populates the type context with all the implementations for the given type /// Populates the type context with all the implementations for the given type
@ -4705,11 +4644,8 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
if type_id.krate == LOCAL_CRATE { if type_id.krate == LOCAL_CRATE {
return return
} }
{ if tcx.populated_external_types.borrow().contains(&type_id) {
let populated_external_types = tcx.populated_external_types.borrow(); return
if populated_external_types.get().contains(&type_id) {
return
}
} }
csearch::each_implementation_for_type(&tcx.sess.cstore, type_id, csearch::each_implementation_for_type(&tcx.sess.cstore, type_id,
@ -4729,9 +4665,8 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
// the map. This is a bit unfortunate. // the map. This is a bit unfortunate.
for method in implementation.methods.iter() { for method in implementation.methods.iter() {
for source in method.provided_source.iter() { for source in method.provided_source.iter() {
let mut provided_method_sources = tcx.provided_method_sources.borrow_mut()
tcx.provided_method_sources.borrow_mut(); .insert(method.def_id, *source);
provided_method_sources.get().insert(method.def_id, *source);
} }
} }
@ -4739,30 +4674,23 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
if associated_traits.is_none() { if associated_traits.is_none() {
let implementation_list; let implementation_list;
let mut inherent_impls = tcx.inherent_impls.borrow_mut(); let mut inherent_impls = tcx.inherent_impls.borrow_mut();
match inherent_impls.get().find(&type_id) { match inherent_impls.find(&type_id) {
None => { None => {
implementation_list = @RefCell::new(Vec::new()); implementation_list = @RefCell::new(Vec::new());
inherent_impls.get().insert(type_id, implementation_list); inherent_impls.insert(type_id, implementation_list);
} }
Some(&existing_implementation_list) => { Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list; implementation_list = existing_implementation_list;
} }
} }
{ implementation_list.borrow_mut().push(implementation);
let mut implementation_list =
implementation_list.borrow_mut();
implementation_list.get().push(implementation);
}
} }
// Store the implementation info. // Store the implementation info.
let mut impls = tcx.impls.borrow_mut(); tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
impls.get().insert(implementation_def_id, implementation);
}); });
let mut populated_external_types = tcx.populated_external_types tcx.populated_external_types.borrow_mut().insert(type_id);
.borrow_mut();
populated_external_types.get().insert(type_id);
} }
/// Populates the type context with all the implementations for the given /// Populates the type context with all the implementations for the given
@ -4773,12 +4701,8 @@ pub fn populate_implementations_for_trait_if_necessary(
if trait_id.krate == LOCAL_CRATE { if trait_id.krate == LOCAL_CRATE {
return return
} }
{ if tcx.populated_external_traits.borrow().contains(&trait_id) {
let populated_external_traits = tcx.populated_external_traits return
.borrow();
if populated_external_traits.get().contains(&trait_id) {
return
}
} }
csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id, csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id,
@ -4792,20 +4716,16 @@ pub fn populate_implementations_for_trait_if_necessary(
// the map. This is a bit unfortunate. // the map. This is a bit unfortunate.
for method in implementation.methods.iter() { for method in implementation.methods.iter() {
for source in method.provided_source.iter() { for source in method.provided_source.iter() {
let mut provided_method_sources = tcx.provided_method_sources.borrow_mut()
tcx.provided_method_sources.borrow_mut(); .insert(method.def_id, *source);
provided_method_sources.get().insert(method.def_id, *source);
} }
} }
// Store the implementation info. // Store the implementation info.
let mut impls = tcx.impls.borrow_mut(); tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
impls.get().insert(implementation_def_id, implementation);
}); });
let mut populated_external_traits = tcx.populated_external_traits tcx.populated_external_traits.borrow_mut().insert(trait_id);
.borrow_mut();
populated_external_traits.get().insert(trait_id);
} }
/// Given the def_id of an impl, return the def_id of the trait it implements. /// Given the def_id of an impl, return the def_id of the trait it implements.
@ -4837,12 +4757,7 @@ pub fn trait_of_method(tcx: &ctxt, def_id: ast::DefId)
if def_id.krate != LOCAL_CRATE { if def_id.krate != LOCAL_CRATE {
return csearch::get_trait_of_method(&tcx.sess.cstore, def_id, tcx); return csearch::get_trait_of_method(&tcx.sess.cstore, def_id, tcx);
} }
let method; match tcx.methods.borrow().find(&def_id).map(|m| *m) {
{
let methods = tcx.methods.borrow();
method = methods.get().find(&def_id).map(|method| *method);
}
match method {
Some(method) => { Some(method) => {
match method.container { match method.container {
TraitContainer(def_id) => Some(def_id), TraitContainer(def_id) => Some(def_id),
@ -4861,14 +4776,10 @@ pub fn trait_of_method(tcx: &ctxt, def_id: ast::DefId)
/// Otherwise, return `None`. /// Otherwise, return `None`.
pub fn trait_method_of_method(tcx: &ctxt, pub fn trait_method_of_method(tcx: &ctxt,
def_id: ast::DefId) -> Option<ast::DefId> { def_id: ast::DefId) -> Option<ast::DefId> {
let method; let method = match tcx.methods.borrow().find(&def_id) {
{ Some(&m) => m,
let methods = tcx.methods.borrow(); None => return None,
match methods.get().find(&def_id) { };
Some(m) => method = *m,
None => return None,
}
}
let name = method.ident.name; let name = method.ident.name;
match trait_of_method(tcx, def_id) { match trait_of_method(tcx, def_id) {
Some(trait_did) => { Some(trait_did) => {

View File

@ -324,8 +324,7 @@ fn check_path_args(tcx: &ty::ctxt,
pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> { pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> {
match ast_ty.node { match ast_ty.node {
ast::TyPath(ref path, _, id) => { ast::TyPath(ref path, _, id) => {
let def_map = tcx.def_map.borrow(); let a_def = match tcx.def_map.borrow().find(&id) {
let a_def = match def_map.get().find(&id) {
None => tcx.sess.span_fatal( None => tcx.sess.span_fatal(
ast_ty.span, format!("unbound path {}", path_to_str(path))), ast_ty.span, format!("unbound path {}", path_to_str(path))),
Some(&d) => d Some(&d) => d
@ -430,8 +429,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
// Note that the "bounds must be empty if path is not a trait" // Note that the "bounds must be empty if path is not a trait"
// restriction is enforced in the below case for ty_path, which // restriction is enforced in the below case for ty_path, which
// will run after this as long as the path isn't a trait. // will run after this as long as the path isn't a trait.
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&id) {
match def_map.get().find(&id) {
Some(&ast::DefPrimTy(ast::TyStr)) if Some(&ast::DefPrimTy(ast::TyStr)) if
a_seq_ty.mutbl == ast::MutImmutable => { a_seq_ty.mutbl == ast::MutImmutable => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
@ -474,20 +472,19 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
let tcx = this.tcx(); let tcx = this.tcx();
{ let mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut();
let mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut(); match ast_ty_to_ty_cache.find(&ast_ty.id) {
match ast_ty_to_ty_cache.get().find(&ast_ty.id) { Some(&ty::atttce_resolved(ty)) => return ty,
Some(&ty::atttce_resolved(ty)) => return ty, Some(&ty::atttce_unresolved) => {
Some(&ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span,
tcx.sess.span_fatal(ast_ty.span, "illegal recursive type; insert an enum \
"illegal recursive type; insert an enum \ or struct in the cycle, if this is \
or struct in the cycle, if this is \ desired");
desired");
}
None => { /* go on */ }
} }
ast_ty_to_ty_cache.get().insert(ast_ty.id, ty::atttce_unresolved); None => { /* go on */ }
} }
ast_ty_to_ty_cache.insert(ast_ty.id, ty::atttce_unresolved);
drop(ast_ty_to_ty_cache);
let typ = ast_ty_to_prim_ty(tcx, ast_ty).unwrap_or_else(|| match ast_ty.node { let typ = ast_ty_to_prim_ty(tcx, ast_ty).unwrap_or_else(|| match ast_ty.node {
ast::TyNil => ty::mk_nil(), ast::TyNil => ty::mk_nil(),
@ -556,8 +553,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
ty::mk_closure(tcx, fn_decl) ty::mk_closure(tcx, fn_decl)
} }
ast::TyPath(ref path, ref bounds, id) => { ast::TyPath(ref path, ref bounds, id) => {
let def_map = tcx.def_map.borrow(); let a_def = match tcx.def_map.borrow().find(&id) {
let a_def = match def_map.get().find(&id) {
None => tcx.sess.span_fatal( None => tcx.sess.span_fatal(
ast_ty.span, format!("unbound path {}", path_to_str(path))), ast_ty.span, format!("unbound path {}", path_to_str(path))),
Some(&d) => d Some(&d) => d
@ -645,8 +641,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
} }
}); });
let mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut(); tcx.ast_ty_to_ty_cache.borrow_mut().insert(ast_ty.id, ty::atttce_resolved(typ));
ast_ty_to_ty_cache.get().insert(ast_ty.id, ty::atttce_resolved(typ));
return typ; return typ;
} }

View File

@ -364,8 +364,7 @@ pub fn check_struct_pat(pcx: &pat_ctxt, pat_id: ast::NodeId, span: Span,
let class_fields = ty::lookup_struct_fields(tcx, struct_id); let class_fields = ty::lookup_struct_fields(tcx, struct_id);
// Check to ensure that the struct is the one specified. // Check to ensure that the struct is the one specified.
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&pat_id) {
match def_map.get().find(&pat_id) {
Some(&ast::DefStruct(supplied_def_id)) Some(&ast::DefStruct(supplied_def_id))
if supplied_def_id == struct_id => { if supplied_def_id == struct_id => {
// OK. // OK.
@ -399,8 +398,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
let tcx = pcx.fcx.ccx.tcx; let tcx = pcx.fcx.ccx.tcx;
// Find the variant that was specified. // Find the variant that was specified.
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&pat_id) {
match def_map.get().find(&pat_id) {
Some(&ast::DefVariant(found_enum_id, variant_id, _)) Some(&ast::DefVariant(found_enum_id, variant_id, _))
if found_enum_id == enum_id => { if found_enum_id == enum_id => {
// Get the struct fields from this struct-like enum variant. // Get the struct fields from this struct-like enum variant.
@ -470,9 +468,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
} }
ast::PatEnum(..) | ast::PatEnum(..) |
ast::PatIdent(..) if pat_is_const(tcx.def_map, pat) => { ast::PatIdent(..) if pat_is_const(tcx.def_map, pat) => {
let def_map = tcx.def_map.borrow(); let const_did = ast_util::def_id_of_def(tcx.def_map.borrow()
let const_did = ast_util::def_id_of_def(def_map.get() .get_copy(&pat.id));
.get_copy(&pat.id));
let const_tpt = ty::lookup_item_type(tcx, const_did); let const_tpt = ty::lookup_item_type(tcx, const_did);
demand::suptype(fcx, pat.span, expected, const_tpt.ty); demand::suptype(fcx, pat.span, expected, const_tpt.ty);
fcx.write_ty(pat.id, const_tpt.ty); fcx.write_ty(pat.id, const_tpt.ty);
@ -548,8 +545,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
e, actual)})}, e, actual)})},
Some(expected), ~"a structure pattern", Some(expected), ~"a structure pattern",
None); None);
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&pat.id) {
match def_map.get().find(&pat.id) {
Some(&ast::DefStruct(supplied_def_id)) => { Some(&ast::DefStruct(supplied_def_id)) => {
check_struct_pat(pcx, check_struct_pat(pcx,
pat.id, pat.id,

View File

@ -466,8 +466,8 @@ impl<'a> LookupContext<'a> {
ty::populate_implementations_for_trait_if_necessary(self.tcx(), trait_did); ty::populate_implementations_for_trait_if_necessary(self.tcx(), trait_did);
// Look for explicit implementations. // Look for explicit implementations.
for impl_infos in self.tcx().trait_impls.borrow().get().find(&trait_did).iter() { for impl_infos in self.tcx().trait_impls.borrow().find(&trait_did).iter() {
for impl_info in impl_infos.borrow().get().iter() { for impl_info in impl_infos.borrow().iter() {
self.push_candidates_from_impl(*impl_info, true); self.push_candidates_from_impl(*impl_info, true);
} }
} }
@ -641,8 +641,8 @@ impl<'a> LookupContext<'a> {
// metadata if necessary. // metadata if necessary.
ty::populate_implementations_for_type_if_necessary(self.tcx(), did); ty::populate_implementations_for_type_if_necessary(self.tcx(), did);
for impl_infos in self.tcx().inherent_impls.borrow().get().find(&did).iter() { for impl_infos in self.tcx().inherent_impls.borrow().find(&did).iter() {
for impl_info in impl_infos.borrow().get().iter() { for impl_info in impl_infos.borrow().iter() {
self.push_candidates_from_impl(*impl_info, false); self.push_candidates_from_impl(*impl_info, false);
} }
} }
@ -1259,17 +1259,14 @@ impl<'a> LookupContext<'a> {
let bad; let bad;
match candidate.origin { match candidate.origin {
MethodStatic(method_id) => { MethodStatic(method_id) => {
let destructors = self.tcx().destructors.borrow(); bad = self.tcx().destructors.borrow().contains(&method_id);
bad = destructors.get().contains(&method_id);
} }
// FIXME: does this properly enforce this on everything now // FIXME: does this properly enforce this on everything now
// that self has been merged in? -sully // that self has been merged in? -sully
MethodParam(MethodParam { trait_id: trait_id, .. }) | MethodParam(MethodParam { trait_id: trait_id, .. }) |
MethodObject(MethodObject { trait_id: trait_id, .. }) => { MethodObject(MethodObject { trait_id: trait_id, .. }) => {
let destructor_for_type = self.tcx() bad = self.tcx().destructor_for_type.borrow()
.destructor_for_type .contains_key(&trait_id);
.borrow();
bad = destructor_for_type.get().contains_key(&trait_id);
} }
} }

View File

@ -355,13 +355,11 @@ impl<'a> GatherLocalsVisitor<'a> {
// infer the variable's type // infer the variable's type
let var_id = self.fcx.infcx().next_ty_var_id(); let var_id = self.fcx.infcx().next_ty_var_id();
let var_ty = ty::mk_var(self.fcx.tcx(), var_id); let var_ty = ty::mk_var(self.fcx.tcx(), var_id);
let mut locals = self.fcx.inh.locals.borrow_mut(); self.fcx.inh.locals.borrow_mut().insert(nid, var_ty);
locals.get().insert(nid, var_ty);
} }
Some(typ) => { Some(typ) => {
// take type that the user specified // take type that the user specified
let mut locals = self.fcx.inh.locals.borrow_mut(); self.fcx.inh.locals.borrow_mut().insert(nid, typ);
locals.get().insert(nid, typ);
} }
} }
} }
@ -375,13 +373,10 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> {
_ => Some(self.fcx.to_ty(local.ty)) _ => Some(self.fcx.to_ty(local.ty))
}; };
self.assign(local.id, o_ty); self.assign(local.id, o_ty);
{ debug!("Local variable {} is assigned type {}",
let locals = self.fcx.inh.locals.borrow(); self.fcx.pat_to_str(local.pat),
debug!("Local variable {} is assigned type {}", self.fcx.infcx().ty_to_str(
self.fcx.pat_to_str(local.pat), self.fcx.inh.locals.borrow().get_copy(&local.id)));
self.fcx.infcx().ty_to_str(
locals.get().get_copy(&local.id)));
}
visit::walk_local(self, local, ()); visit::walk_local(self, local, ());
} }
@ -391,13 +386,10 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> {
ast::PatIdent(_, ref path, _) ast::PatIdent(_, ref path, _)
if pat_util::pat_is_binding(self.fcx.ccx.tcx.def_map, p) => { if pat_util::pat_is_binding(self.fcx.ccx.tcx.def_map, p) => {
self.assign(p.id, None); self.assign(p.id, None);
{ debug!("Pattern binding {} is assigned to {}",
let locals = self.fcx.inh.locals.borrow(); token::get_ident(path.segments.get(0).identifier),
debug!("Pattern binding {} is assigned to {}", self.fcx.infcx().ty_to_str(
token::get_ident(path.segments.get(0).identifier), self.fcx.inh.locals.borrow().get_copy(&p.id)));
self.fcx.infcx().ty_to_str(
locals.get().get_copy(&p.id)));
}
} }
_ => {} _ => {}
} }
@ -1007,8 +999,7 @@ impl<'a> FnCtxt<'a> {
} }
pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> ty::t { pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> ty::t {
let locals = self.inh.locals.borrow(); match self.inh.locals.borrow().find(&nid) {
match locals.get().find(&nid) {
Some(&t) => t, Some(&t) => t,
None => { None => {
self.tcx().sess.span_bug( self.tcx().sess.span_bug(
@ -1026,8 +1017,7 @@ impl<'a> FnCtxt<'a> {
pub fn write_ty(&self, node_id: ast::NodeId, ty: ty::t) { pub fn write_ty(&self, node_id: ast::NodeId, ty: ty::t) {
debug!("write_ty({}, {}) in fcx {}", debug!("write_ty({}, {}) in fcx {}",
node_id, ppaux::ty_to_str(self.tcx(), ty), self.tag()); node_id, ppaux::ty_to_str(self.tcx(), ty), self.tag());
let mut node_types = self.inh.node_types.borrow_mut(); self.inh.node_types.borrow_mut().insert(node_id, ty);
node_types.get().insert(node_id, ty);
} }
pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::substs) { pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::substs) {
@ -1037,8 +1027,7 @@ impl<'a> FnCtxt<'a> {
ty::substs_to_str(self.tcx(), &substs), ty::substs_to_str(self.tcx(), &substs),
self.tag()); self.tag());
let mut node_type_substs = self.inh.node_type_substs.borrow_mut(); self.inh.node_type_substs.borrow_mut().insert(node_id, substs);
node_type_substs.get().insert(node_id, substs);
} }
} }
@ -1067,8 +1056,7 @@ impl<'a> FnCtxt<'a> {
node_id: ast::NodeId, node_id: ast::NodeId,
adj: @ty::AutoAdjustment) { adj: @ty::AutoAdjustment) {
debug!("write_adjustment(node_id={:?}, adj={:?})", node_id, adj); debug!("write_adjustment(node_id={:?}, adj={:?})", node_id, adj);
let mut adjustments = self.inh.adjustments.borrow_mut(); self.inh.adjustments.borrow_mut().insert(node_id, adj);
adjustments.get().insert(node_id, adj);
} }
pub fn write_nil(&self, node_id: ast::NodeId) { pub fn write_nil(&self, node_id: ast::NodeId) {
@ -1090,8 +1078,7 @@ impl<'a> FnCtxt<'a> {
} }
pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t { pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t {
let node_types = self.inh.node_types.borrow(); match self.inh.node_types.borrow().find(&ex.id) {
match node_types.get().find(&ex.id) {
Some(&t) => t, Some(&t) => t,
None => { None => {
self.tcx().sess.bug(format!("no type for expr in fcx {}", self.tcx().sess.bug(format!("no type for expr in fcx {}",
@ -1101,7 +1088,7 @@ impl<'a> FnCtxt<'a> {
} }
pub fn node_ty(&self, id: ast::NodeId) -> ty::t { pub fn node_ty(&self, id: ast::NodeId) -> ty::t {
match self.inh.node_types.borrow().get().find(&id) { match self.inh.node_types.borrow().find(&id) {
Some(&t) => t, Some(&t) => t,
None => { None => {
self.tcx().sess.bug( self.tcx().sess.bug(
@ -1113,7 +1100,7 @@ impl<'a> FnCtxt<'a> {
} }
pub fn node_ty_substs(&self, id: ast::NodeId) -> ty::substs { pub fn node_ty_substs(&self, id: ast::NodeId) -> ty::substs {
match self.inh.node_type_substs.borrow().get().find(&id) { match self.inh.node_type_substs.borrow().find(&id) {
Some(ts) => (*ts).clone(), Some(ts) => (*ts).clone(),
None => { None => {
self.tcx().sess.bug( self.tcx().sess.bug(
@ -1125,7 +1112,7 @@ impl<'a> FnCtxt<'a> {
} }
pub fn method_ty_substs(&self, id: ast::NodeId) -> ty::substs { pub fn method_ty_substs(&self, id: ast::NodeId) -> ty::substs {
match self.inh.method_map.borrow().get().find(&MethodCall::expr(id)) { match self.inh.method_map.borrow().find(&MethodCall::expr(id)) {
Some(method) => method.substs.clone(), Some(method) => method.substs.clone(),
None => { None => {
self.tcx().sess.bug( self.tcx().sess.bug(
@ -1140,8 +1127,7 @@ impl<'a> FnCtxt<'a> {
id: ast::NodeId, id: ast::NodeId,
f: |&ty::substs| -> bool) f: |&ty::substs| -> bool)
-> bool { -> bool {
let node_type_substs = self.inh.node_type_substs.borrow(); match self.inh.node_type_substs.borrow().find(&id) {
match node_type_substs.get().find(&id) {
Some(s) => f(s), Some(s) => f(s),
None => true None => true
} }
@ -1327,7 +1313,7 @@ fn try_overloaded_deref(fcx: &FnCtxt,
let ref_ty = ty::ty_fn_ret(method.ty); let ref_ty = ty::ty_fn_ret(method.ty);
match method_call { match method_call {
Some(method_call) => { Some(method_call) => {
fcx.inh.method_map.borrow_mut().get().insert(method_call, method); fcx.inh.method_map.borrow_mut().insert(method_call, method);
} }
None => {} None => {}
} }
@ -1908,7 +1894,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
Some(method) => { Some(method) => {
let method_ty = method.ty; let method_ty = method.ty;
let method_call = MethodCall::expr(expr.id); let method_call = MethodCall::expr(expr.id);
fcx.inh.method_map.borrow_mut().get().insert(method_call, method); fcx.inh.method_map.borrow_mut().insert(method_call, method);
method_ty method_ty
} }
None => { None => {
@ -1998,7 +1984,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
let method_ty = method.ty; let method_ty = method.ty;
// HACK(eddyb) Fully qualified path to work around a resolve bug. // HACK(eddyb) Fully qualified path to work around a resolve bug.
let method_call = ::middle::typeck::MethodCall::expr(op_ex.id); let method_call = ::middle::typeck::MethodCall::expr(op_ex.id);
fcx.inh.method_map.borrow_mut().get().insert(method_call, method); fcx.inh.method_map.borrow_mut().insert(method_call, method);
check_method_argument_types(fcx, op_ex.span, check_method_argument_types(fcx, op_ex.span,
method_ty, op_ex, method_ty, op_ex,
args, DoDerefArgs) args, DoDerefArgs)
@ -3131,8 +3117,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
} }
ast::ExprStruct(ref path, ref fields, base_expr) => { ast::ExprStruct(ref path, ref fields, base_expr) => {
// Resolve the path. // Resolve the path.
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&id) {
match def_map.get().find(&id) {
Some(&ast::DefStruct(type_def_id)) => { Some(&ast::DefStruct(type_def_id)) => {
check_struct_constructor(fcx, id, expr.span, type_def_id, check_struct_constructor(fcx, id, expr.span, type_def_id,
fields.as_slice(), base_expr); fields.as_slice(), base_expr);
@ -3323,8 +3308,8 @@ pub fn check_block_with_expected(fcx: &FnCtxt,
expected: Option<ty::t>) { expected: Option<ty::t>) {
let prev = { let prev = {
let mut fcx_ps = fcx.ps.borrow_mut(); let mut fcx_ps = fcx.ps.borrow_mut();
let purity_state = fcx_ps.get().recurse(blk); let purity_state = fcx_ps.recurse(blk);
replace(fcx_ps.get(), purity_state) replace(&mut *fcx_ps, purity_state)
}; };
fcx.with_region_lb(blk.id, || { fcx.with_region_lb(blk.id, || {
@ -3394,10 +3379,7 @@ pub fn check_const(ccx: &CrateCtxt,
let inh = blank_inherited_fields(ccx); let inh = blank_inherited_fields(ccx);
let rty = ty::node_id_to_type(ccx.tcx, id); let rty = ty::node_id_to_type(ccx.tcx, id);
let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id); let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id);
let declty = { let declty = fcx.ccx.tcx.tcache.borrow().get(&local_def(id)).ty;
let tcache = fcx.ccx.tcx.tcache.borrow();
tcache.get().get(&local_def(id)).ty
};
check_const_with_ty(&fcx, sp, e, declty); check_const_with_ty(&fcx, sp, e, declty);
} }
@ -3608,10 +3590,7 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
let variants = do_check(ccx, vs, id, hint); let variants = do_check(ccx, vs, id, hint);
// cache so that ty::enum_variants won't repeat this work // cache so that ty::enum_variants won't repeat this work
{ ccx.tcx.enum_var_cache.borrow_mut().insert(local_def(id), @variants);
let mut enum_var_cache = ccx.tcx.enum_var_cache.borrow_mut();
enum_var_cache.get().insert(local_def(id), @variants);
}
// Check that it is possible to represent this enum. // Check that it is possible to represent this enum.
check_representable(ccx.tcx, sp, id, "enum"); check_representable(ccx.tcx, sp, id, "enum");
@ -3958,8 +3937,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: ast::P<ast::Block>) -> bool
(block_query(b, |e| { (block_query(b, |e| {
match e.node { match e.node {
ast::ExprBreak(Some(_)) => { ast::ExprBreak(Some(_)) => {
let def_map = cx.def_map.borrow(); match cx.def_map.borrow().find(&e.id) {
match def_map.get().find(&e.id) {
Some(&ast::DefLabel(loop_id)) if id == loop_id => true, Some(&ast::DefLabel(loop_id)) if id == loop_id => true,
_ => false, _ => false,
} }

View File

@ -241,7 +241,7 @@ impl<'a> Rcx<'a> {
} }
fn resolve_method_type(&self, method_call: MethodCall) -> Option<ty::t> { fn resolve_method_type(&self, method_call: MethodCall) -> Option<ty::t> {
let method_ty = self.fcx.inh.method_map.borrow().get() let method_ty = self.fcx.inh.method_map.borrow()
.find(&method_call).map(|method| method.ty); .find(&method_call).map(|method| method.ty);
method_ty.map(|method_ty| self.resolve_type(method_ty)) method_ty.map(|method_ty| self.resolve_type(method_ty))
} }
@ -253,7 +253,7 @@ impl<'a> Rcx<'a> {
ty_unadjusted ty_unadjusted
} else { } else {
let tcx = self.fcx.tcx(); let tcx = self.fcx.tcx();
let adjustment = self.fcx.inh.adjustments.borrow().get().find_copy(&expr.id); let adjustment = self.fcx.inh.adjustments.borrow().find_copy(&expr.id);
ty::adjust_ty(tcx, expr.span, expr.id, ty_unadjusted, adjustment, ty::adjust_ty(tcx, expr.span, expr.id, ty_unadjusted, adjustment,
|method_call| self.resolve_method_type(method_call)) |method_call| self.resolve_method_type(method_call))
} }
@ -275,12 +275,11 @@ impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
} }
fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> { fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> {
let adjustments = self.fcx.inh.adjustments.borrow(); self.fcx.inh.adjustments.borrow().find_copy(&id)
adjustments.get().find_copy(&id)
} }
fn is_method_call(&mut self, id: ast::NodeId) -> bool { fn is_method_call(&mut self, id: ast::NodeId) -> bool {
self.fcx.inh.method_map.borrow().get().contains_key(&MethodCall::expr(id)) self.fcx.inh.method_map.borrow().contains_key(&MethodCall::expr(id))
} }
fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> { fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> {
@ -288,8 +287,7 @@ impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
} }
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
let upvar_borrow_map = self.fcx.inh.upvar_borrow_map.borrow(); self.fcx.inh.upvar_borrow_map.borrow().get_copy(&id)
upvar_borrow_map.get().get_copy(&id)
} }
} }
@ -403,7 +401,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
let has_method_map = rcx.fcx.inh.method_map.get().contains_key(&method_call); let has_method_map = rcx.fcx.inh.method_map.get().contains_key(&method_call);
// Check any autoderefs or autorefs that appear. // Check any autoderefs or autorefs that appear.
for &adjustment in rcx.fcx.inh.adjustments.borrow().get().find(&expr.id).iter() { for &adjustment in rcx.fcx.inh.adjustments.borrow().find(&expr.id).iter() {
debug!("adjustment={:?}", adjustment); debug!("adjustment={:?}", adjustment);
match **adjustment { match **adjustment {
ty::AutoDerefRef(ty::AutoDerefRef {autoderefs, autoref: opt_autoref}) => { ty::AutoDerefRef(ty::AutoDerefRef {autoderefs, autoref: opt_autoref}) => {
@ -678,8 +676,8 @@ fn check_expr_fn_block(rcx: &mut Rcx,
// immutable as dictated by the uses. // immutable as dictated by the uses.
let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow, let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow,
region: freevar_region }; region: freevar_region };
let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); rcx.fcx.inh.upvar_borrow_map.borrow_mut().insert(upvar_id,
upvar_borrow_map.get().insert(upvar_id, upvar_borrow); upvar_borrow);
// Guarantee that the closure does not outlive the variable itself. // Guarantee that the closure does not outlive the variable itself.
let en_region = region_of_def(rcx.fcx, def); let en_region = region_of_def(rcx.fcx, def);
@ -951,7 +949,7 @@ fn constrain_regions_in_type_of_node(
// is going to fail anyway, so just stop here and let typeck // is going to fail anyway, so just stop here and let typeck
// report errors later on in the writeback phase. // report errors later on in the writeback phase.
let ty0 = rcx.resolve_node_type(id); let ty0 = rcx.resolve_node_type(id);
let adjustment = rcx.fcx.inh.adjustments.borrow().get().find_copy(&id); let adjustment = rcx.fcx.inh.adjustments.borrow().find_copy(&id);
let ty = ty::adjust_ty(tcx, origin.span(), id, ty0, adjustment, let ty = ty::adjust_ty(tcx, origin.span(), id, ty0, adjustment,
|method_call| rcx.resolve_method_type(method_call)); |method_call| rcx.resolve_method_type(method_call));
debug!("constrain_regions_in_type_of_node(\ debug!("constrain_regions_in_type_of_node(\
@ -1204,9 +1202,8 @@ fn link_region(rcx: &mut Rcx,
// to use for each upvar. // to use for each upvar.
let cause = match base.cat { let cause = match base.cat {
mc::cat_upvar(ref upvar_id, _) => { mc::cat_upvar(ref upvar_id, _) => {
let mut upvar_borrow_map = match rcx.fcx.inh.upvar_borrow_map.borrow_mut()
rcx.fcx.inh.upvar_borrow_map.borrow_mut(); .find_mut(upvar_id) {
match upvar_borrow_map.get().find_mut(upvar_id) {
Some(upvar_borrow) => { Some(upvar_borrow) => {
debug!("link_region: {} <= {}", debug!("link_region: {} <= {}",
region_min.repr(rcx.tcx()), region_min.repr(rcx.tcx()),
@ -1324,7 +1321,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &mut Rcx,
// is inferred to mutable if necessary // is inferred to mutable if necessary
let mut upvar_borrow_map = let mut upvar_borrow_map =
rcx.fcx.inh.upvar_borrow_map.borrow_mut(); rcx.fcx.inh.upvar_borrow_map.borrow_mut();
let ub = upvar_borrow_map.get().get_mut(upvar_id); let ub = upvar_borrow_map.get_mut(upvar_id);
return adjust_upvar_borrow_kind(*upvar_id, ub, ty::MutBorrow); return adjust_upvar_borrow_kind(*upvar_id, ub, ty::MutBorrow);
} }
@ -1377,9 +1374,8 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &mut Rcx,
// upvar, then we need to modify the // upvar, then we need to modify the
// borrow_kind of the upvar to make sure it // borrow_kind of the upvar to make sure it
// is inferred to unique if necessary // is inferred to unique if necessary
let mut upvar_borrow_map = let mut ub = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
rcx.fcx.inh.upvar_borrow_map.borrow_mut(); let ub = ub.get_mut(upvar_id);
let ub = upvar_borrow_map.get().get_mut(upvar_id);
return adjust_upvar_borrow_kind(*upvar_id, ub, ty::UniqueImmBorrow); return adjust_upvar_borrow_kind(*upvar_id, ub, ty::UniqueImmBorrow);
} }
@ -1419,8 +1415,8 @@ fn link_upvar_borrow_kind_for_nested_closures(rcx: &mut Rcx,
inner_upvar_id, outer_upvar_id); inner_upvar_id, outer_upvar_id);
let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
let inner_borrow = upvar_borrow_map.get().get_copy(&inner_upvar_id); let inner_borrow = upvar_borrow_map.get_copy(&inner_upvar_id);
match upvar_borrow_map.get().find_mut(&outer_upvar_id) { match upvar_borrow_map.find_mut(&outer_upvar_id) {
Some(outer_borrow) => { Some(outer_borrow) => {
adjust_upvar_borrow_kind(outer_upvar_id, outer_borrow, inner_borrow.kind); adjust_upvar_borrow_kind(outer_upvar_id, outer_borrow, inner_borrow.kind);
} }

View File

@ -321,15 +321,10 @@ fn search_for_vtable(vcx: &VtableContext,
// FIXME: this is a bad way to do this, since we do // FIXME: this is a bad way to do this, since we do
// pointless allocations. // pointless allocations.
let impls = { let impls = tcx.trait_impls.borrow().find(&trait_ref.def_id)
let trait_impls = tcx.trait_impls.borrow(); .map_or(@RefCell::new(Vec::new()), |x| *x);
trait_impls.get()
.find(&trait_ref.def_id)
.map_or(@RefCell::new(Vec::new()), |x| *x)
};
// impls is the list of all impls in scope for trait_ref. // impls is the list of all impls in scope for trait_ref.
let impls = impls.borrow(); for im in impls.borrow().iter() {
for im in impls.get().iter() {
// im is one specific impl of trait_ref. // im is one specific impl of trait_ref.
// First, ensure we haven't processed this impl yet. // First, ensure we haven't processed this impl yet.
@ -524,7 +519,7 @@ fn connect_trait_tps(vcx: &VtableContext,
fn insert_vtables(fcx: &FnCtxt, expr_id: ast::NodeId, vtables: vtable_res) { fn insert_vtables(fcx: &FnCtxt, expr_id: ast::NodeId, vtables: vtable_res) {
debug!("insert_vtables(expr_id={}, vtables={:?})", debug!("insert_vtables(expr_id={}, vtables={:?})",
expr_id, vtables.repr(fcx.tcx())); expr_id, vtables.repr(fcx.tcx()));
fcx.inh.vtable_map.borrow_mut().get().insert(expr_id, vtables); fcx.inh.vtable_map.borrow_mut().insert(expr_id, vtables);
} }
pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
@ -640,8 +635,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
fcx.opt_node_ty_substs(ex.id, |substs| { fcx.opt_node_ty_substs(ex.id, |substs| {
debug!("vtable resolution on parameter bounds for expr {}", debug!("vtable resolution on parameter bounds for expr {}",
ex.repr(fcx.tcx())); ex.repr(fcx.tcx()));
let def_map = cx.tcx.def_map.borrow(); let def = cx.tcx.def_map.borrow().get_copy(&ex.id);
let def = def_map.get().get_copy(&ex.id);
let did = ast_util::def_id_of_def(def); let did = ast_util::def_id_of_def(def);
let item_ty = ty::lookup_item_type(cx.tcx, did); let item_ty = ty::lookup_item_type(cx.tcx, did);
debug!("early resolve expr: def {:?} {:?}, {:?}, {}", ex.id, did, def, debug!("early resolve expr: def {:?} {:?}, {:?}, {}", ex.id, did, def,
@ -667,7 +661,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
ast::ExprAssignOp(_, _, _) | ast::ExprAssignOp(_, _, _) |
ast::ExprIndex(_, _) | ast::ExprIndex(_, _) |
ast::ExprMethodCall(_, _, _) => { ast::ExprMethodCall(_, _, _) => {
match fcx.inh.method_map.borrow().get().find(&MethodCall::expr(ex.id)) { match fcx.inh.method_map.borrow().find(&MethodCall::expr(ex.id)) {
Some(method) => { Some(method) => {
debug!("vtable resolution on parameter bounds for method call {}", debug!("vtable resolution on parameter bounds for method call {}",
ex.repr(fcx.tcx())); ex.repr(fcx.tcx()));
@ -696,8 +690,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
} }
// Search for auto-adjustments to find trait coercions // Search for auto-adjustments to find trait coercions
let adjustments = fcx.inh.adjustments.borrow(); match fcx.inh.adjustments.borrow().find(&ex.id) {
match adjustments.get().find(&ex.id) {
Some(adjustment) => { Some(adjustment) => {
match **adjustment { match **adjustment {
AutoObject(ref sigil, AutoObject(ref sigil,
@ -779,8 +772,7 @@ pub fn resolve_impl(tcx: &ty::ctxt,
}; };
let impl_def_id = ast_util::local_def(impl_item.id); let impl_def_id = ast_util::local_def(impl_item.id);
let mut impl_vtables = tcx.impl_vtables.borrow_mut(); tcx.impl_vtables.borrow_mut().insert(impl_def_id, res);
impl_vtables.get().insert(impl_def_id, res);
} }
/// Resolve vtables for a method call after typeck has finished. /// Resolve vtables for a method call after typeck has finished.

View File

@ -67,7 +67,7 @@ fn resolve_method_map_entry(wbcx: &mut WbCtxt, sp: Span, method_call: MethodCall
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
// Resolve any method map entry // Resolve any method map entry
match fcx.inh.method_map.borrow().get().find(&method_call) { match fcx.inh.method_map.borrow().find(&method_call) {
Some(method) => { Some(method) => {
debug!("writeback::resolve_method_map_entry(call={:?}, entry={:?})", debug!("writeback::resolve_method_map_entry(call={:?}, entry={:?})",
method_call, method.repr(tcx)); method_call, method.repr(tcx));
@ -94,7 +94,7 @@ fn resolve_method_map_entry(wbcx: &mut WbCtxt, sp: Span, method_call: MethodCall
self_ty: None self_ty: None
} }
}; };
fcx.ccx.method_map.borrow_mut().get().insert(method_call, new_method); fcx.ccx.method_map.borrow_mut().insert(method_call, new_method);
} }
None => {} None => {}
} }
@ -102,10 +102,10 @@ fn resolve_method_map_entry(wbcx: &mut WbCtxt, sp: Span, method_call: MethodCall
fn resolve_vtable_map_entry(fcx: &FnCtxt, sp: Span, id: ast::NodeId) { fn resolve_vtable_map_entry(fcx: &FnCtxt, sp: Span, id: ast::NodeId) {
// Resolve any vtable map entry // Resolve any vtable map entry
match fcx.inh.vtable_map.borrow().get().find_copy(&id) { match fcx.inh.vtable_map.borrow().find_copy(&id) {
Some(origins) => { Some(origins) => {
let r_origins = resolve_origins(fcx, sp, origins); let r_origins = resolve_origins(fcx, sp, origins);
fcx.ccx.vtable_map.borrow_mut().get().insert(id, r_origins); fcx.ccx.vtable_map.borrow_mut().insert(id, r_origins);
debug!("writeback::resolve_vtable_map_entry(id={}, vtables={:?})", debug!("writeback::resolve_vtable_map_entry(id={}, vtables={:?})",
id, r_origins.repr(fcx.tcx())); id, r_origins.repr(fcx.tcx()));
} }
@ -141,8 +141,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
// Resolve any borrowings for the node with id `id` // Resolve any borrowings for the node with id `id`
let adjustment = fcx.inh.adjustments.borrow().get().find_copy(&id); match fcx.inh.adjustments.borrow().find_copy(&id) {
match adjustment {
None => (), None => (),
Some(adjustment) => { Some(adjustment) => {
@ -163,7 +162,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
// FIXME(eddyb) #2190 Allow only statically resolved // FIXME(eddyb) #2190 Allow only statically resolved
// bare functions to coerce to a closure to avoid // bare functions to coerce to a closure to avoid
// constructing (slower) indirect call wrappers. // constructing (slower) indirect call wrappers.
match tcx.def_map.borrow().get().find(&id) { match tcx.def_map.borrow().find(&id) {
Some(&ast::DefFn(..)) | Some(&ast::DefFn(..)) |
Some(&ast::DefStaticMethod(..)) | Some(&ast::DefStaticMethod(..)) |
Some(&ast::DefVariant(..)) | Some(&ast::DefVariant(..)) |
@ -175,7 +174,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
let resolved_adj = @ty::AutoAddEnv(r1, s); let resolved_adj = @ty::AutoAddEnv(r1, s);
debug!("Adjustments for node {}: {:?}", debug!("Adjustments for node {}: {:?}",
id, resolved_adj); id, resolved_adj);
tcx.adjustments.borrow_mut().get().insert(id, resolved_adj); tcx.adjustments.borrow_mut().insert(id, resolved_adj);
} }
} }
} }
@ -213,12 +212,12 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
autoref: resolved_autoref, autoref: resolved_autoref,
}); });
debug!("Adjustments for node {}: {:?}", id, resolved_adj); debug!("Adjustments for node {}: {:?}", id, resolved_adj);
tcx.adjustments.borrow_mut().get().insert(id, resolved_adj); tcx.adjustments.borrow_mut().insert(id, resolved_adj);
} }
ty::AutoObject(..) => { ty::AutoObject(..) => {
debug!("Adjustments for node {}: {:?}", id, adjustment); debug!("Adjustments for node {}: {:?}", id, adjustment);
tcx.adjustments.borrow_mut().get().insert(id, adjustment); tcx.adjustments.borrow_mut().insert(id, adjustment);
} }
} }
} }
@ -355,8 +354,7 @@ fn resolve_upvar_borrow_map(wbcx: &mut WbCtxt) {
let fcx = wbcx.fcx; let fcx = wbcx.fcx;
let tcx = fcx.tcx(); let tcx = fcx.tcx();
let upvar_borrow_map = fcx.inh.upvar_borrow_map.borrow(); for (upvar_id, upvar_borrow) in fcx.inh.upvar_borrow_map.borrow().iter() {
for (upvar_id, upvar_borrow) in upvar_borrow_map.get().iter() {
let r = upvar_borrow.region; let r = upvar_borrow.region;
match resolve_region(fcx.infcx(), r, resolve_all | force_all) { match resolve_region(fcx.infcx(), r, resolve_all | force_all) {
Ok(r) => { Ok(r) => {
@ -366,8 +364,8 @@ fn resolve_upvar_borrow_map(wbcx: &mut WbCtxt) {
}; };
debug!("Upvar borrow for {} resolved to {}", debug!("Upvar borrow for {} resolved to {}",
upvar_id.repr(tcx), new_upvar_borrow.repr(tcx)); upvar_id.repr(tcx), new_upvar_borrow.repr(tcx));
let mut tcx_upvar_borrow_map = tcx.upvar_borrow_map.borrow_mut(); tcx.upvar_borrow_map.borrow_mut().insert(*upvar_id,
tcx_upvar_borrow_map.get().insert(*upvar_id, new_upvar_borrow); new_upvar_borrow);
} }
Err(e) => { Err(e) => {
let span = ty::expr_span(tcx, upvar_id.closure_expr_id); let span = ty::expr_span(tcx, upvar_id.closure_expr_id);

View File

@ -306,8 +306,7 @@ impl<'a> CoherenceChecker<'a> {
} }
} }
let mut impls = tcx.impls.borrow_mut(); tcx.impls.borrow_mut().insert(implementation.did, implementation);
impls.get().insert(implementation.did, implementation);
} }
// Creates default method IDs and performs type substitutions for an impl // Creates default method IDs and performs type substitutions for an impl
@ -359,20 +358,13 @@ impl<'a> CoherenceChecker<'a> {
}; };
debug!("new_polytype={}", new_polytype.repr(tcx)); debug!("new_polytype={}", new_polytype.repr(tcx));
{ tcx.tcache.borrow_mut().insert(new_did, new_polytype);
let mut tcache = tcx.tcache.borrow_mut(); tcx.methods.borrow_mut().insert(new_did, new_method_ty);
tcache.get().insert(new_did, new_polytype);
}
let mut methods = tcx.methods.borrow_mut();
methods.get().insert(new_did, new_method_ty);
// Pair the new synthesized ID up with the // Pair the new synthesized ID up with the
// ID of the method. // ID of the method.
let mut provided_method_sources = self.crate_context.tcx.provided_method_sources.borrow_mut()
self.crate_context.tcx.provided_method_sources.borrow_mut(); .insert(new_did, trait_method.def_id);
provided_method_sources.get().insert(new_did,
trait_method.def_id);
} }
} }
@ -381,18 +373,17 @@ impl<'a> CoherenceChecker<'a> {
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
let implementation_list; let implementation_list;
let mut inherent_impls = tcx.inherent_impls.borrow_mut(); let mut inherent_impls = tcx.inherent_impls.borrow_mut();
match inherent_impls.get().find(&base_def_id) { match inherent_impls.find(&base_def_id) {
None => { None => {
implementation_list = @RefCell::new(Vec::new()); implementation_list = @RefCell::new(Vec::new());
inherent_impls.get().insert(base_def_id, implementation_list); inherent_impls.insert(base_def_id, implementation_list);
} }
Some(&existing_implementation_list) => { Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list; implementation_list = existing_implementation_list;
} }
} }
let mut implementation_list = implementation_list.borrow_mut(); implementation_list.borrow_mut().push(implementation);
implementation_list.get().push(implementation);
} }
fn add_trait_impl(&self, base_def_id: DefId, fn add_trait_impl(&self, base_def_id: DefId,
@ -400,23 +391,21 @@ impl<'a> CoherenceChecker<'a> {
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
let implementation_list; let implementation_list;
let mut trait_impls = tcx.trait_impls.borrow_mut(); let mut trait_impls = tcx.trait_impls.borrow_mut();
match trait_impls.get().find(&base_def_id) { match trait_impls.find(&base_def_id) {
None => { None => {
implementation_list = @RefCell::new(Vec::new()); implementation_list = @RefCell::new(Vec::new());
trait_impls.get().insert(base_def_id, implementation_list); trait_impls.insert(base_def_id, implementation_list);
} }
Some(&existing_implementation_list) => { Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list; implementation_list = existing_implementation_list;
} }
} }
let mut implementation_list = implementation_list.borrow_mut(); implementation_list.borrow_mut().push(implementation);
implementation_list.get().push(implementation);
} }
fn check_implementation_coherence(&self) { fn check_implementation_coherence(&self) {
let trait_impls = self.crate_context.tcx.trait_impls.borrow(); for &trait_id in self.crate_context.tcx.trait_impls.borrow().keys() {
for &trait_id in trait_impls.get().keys() {
self.check_implementation_coherence_of(trait_id); self.check_implementation_coherence_of(trait_id);
} }
} }
@ -476,11 +465,9 @@ impl<'a> CoherenceChecker<'a> {
} }
fn iter_impls_of_trait_local(&self, trait_def_id: DefId, f: |@Impl|) { fn iter_impls_of_trait_local(&self, trait_def_id: DefId, f: |@Impl|) {
let trait_impls = self.crate_context.tcx.trait_impls.borrow(); match self.crate_context.tcx.trait_impls.borrow().find(&trait_def_id) {
match trait_impls.get().find(&trait_def_id) {
Some(impls) => { Some(impls) => {
let impls = impls.borrow(); for &im in impls.borrow().iter() {
for &im in impls.get().iter() {
f(im); f(im);
} }
} }
@ -543,8 +530,7 @@ impl<'a> CoherenceChecker<'a> {
fn get_self_type_for_implementation(&self, implementation: @Impl) fn get_self_type_for_implementation(&self, implementation: @Impl)
-> ty_param_bounds_and_ty { -> ty_param_bounds_and_ty {
let tcache = self.crate_context.tcx.tcache.borrow(); self.crate_context.tcx.tcache.borrow().get_copy(&implementation.did)
return tcache.get().get_copy(&implementation.did);
} }
// Privileged scope checking // Privileged scope checking
@ -555,8 +541,7 @@ impl<'a> CoherenceChecker<'a> {
fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId { fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
let def_map = self.crate_context.tcx.def_map; let def_map = self.crate_context.tcx.def_map;
let def_map = def_map.borrow(); let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let trait_def = def_map.get().get_copy(&trait_ref.ref_id);
let trait_id = def_id_of_def(trait_def); let trait_id = def_id_of_def(trait_def);
return trait_id; return trait_id;
} }
@ -567,8 +552,7 @@ impl<'a> CoherenceChecker<'a> {
fn ast_type_is_defined_in_local_crate(&self, original_type: &ast::Ty) -> bool { fn ast_type_is_defined_in_local_crate(&self, original_type: &ast::Ty) -> bool {
match original_type.node { match original_type.node {
TyPath(_, _, path_id) => { TyPath(_, _, path_id) => {
let def_map = self.crate_context.tcx.def_map.borrow(); match self.crate_context.tcx.def_map.borrow().get_copy(&path_id) {
match def_map.get().get_copy(&path_id) {
DefTy(def_id) | DefStruct(def_id) => { DefTy(def_id) | DefStruct(def_id) => {
if def_id.krate != LOCAL_CRATE { if def_id.krate != LOCAL_CRATE {
return false; return false;
@ -666,14 +650,12 @@ impl<'a> CoherenceChecker<'a> {
// the map. This is a bit unfortunate. // the map. This is a bit unfortunate.
for method in implementation.methods.iter() { for method in implementation.methods.iter() {
for source in method.provided_source.iter() { for source in method.provided_source.iter() {
let mut provided_method_sources = tcx.provided_method_sources tcx.provided_method_sources.borrow_mut()
.borrow_mut(); .insert(method.def_id, *source);
provided_method_sources.get().insert(method.def_id, *source);
} }
} }
let mut impls = tcx.impls.borrow_mut(); tcx.impls.borrow_mut().insert(implementation.did, implementation);
impls.get().insert(implementation.did, implementation);
} }
// Adds implementations and traits from external crates to the coherence // Adds implementations and traits from external crates to the coherence
@ -701,15 +683,14 @@ impl<'a> CoherenceChecker<'a> {
}; };
let trait_impls = tcx.trait_impls.borrow(); let trait_impls = tcx.trait_impls.borrow();
let impls_opt = trait_impls.get().find(&drop_trait); let impls_opt = trait_impls.find(&drop_trait);
let impls; let impls;
match impls_opt { match impls_opt {
None => return, // No types with (new-style) dtors present. None => return, // No types with (new-style) dtors present.
Some(found_impls) => impls = found_impls Some(found_impls) => impls = found_impls
} }
let impls = impls.borrow(); for impl_info in impls.borrow().iter() {
for impl_info in impls.get().iter() {
if impl_info.methods.len() < 1 { if impl_info.methods.len() < 1 {
// We'll error out later. For now, just don't ICE. // We'll error out later. For now, just don't ICE.
continue; continue;
@ -720,12 +701,9 @@ impl<'a> CoherenceChecker<'a> {
match ty::get(self_type.ty).sty { match ty::get(self_type.ty).sty {
ty::ty_enum(type_def_id, _) | ty::ty_enum(type_def_id, _) |
ty::ty_struct(type_def_id, _) => { ty::ty_struct(type_def_id, _) => {
let mut destructor_for_type = tcx.destructor_for_type tcx.destructor_for_type.borrow_mut().insert(type_def_id,
.borrow_mut(); method_def_id);
destructor_for_type.get().insert(type_def_id, tcx.destructors.borrow_mut().insert(method_def_id);
method_def_id);
let mut destructors = tcx.destructors.borrow_mut();
destructors.get().insert(method_def_id);
} }
_ => { _ => {
// Destructors only work on nominal types. // Destructors only work on nominal types.

View File

@ -82,8 +82,7 @@ pub fn collect_item_types(ccx: &CrateCtxt, krate: &ast::Crate) {
lang_item: ast::DefId) { lang_item: ast::DefId) {
let ty::ty_param_bounds_and_ty { ty: ty, .. } = let ty::ty_param_bounds_and_ty { ty: ty, .. } =
ccx.get_item_ty(lang_item); ccx.get_item_ty(lang_item);
let mut intrinsic_defs = ccx.tcx.intrinsic_defs.borrow_mut(); ccx.tcx.intrinsic_defs.borrow_mut().insert(lang_item, ty);
intrinsic_defs.get().insert(lang_item, ty);
} }
match ccx.tcx.lang_items.ty_desc() { match ccx.tcx.lang_items.ty_desc() {
@ -180,10 +179,7 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
ty: result_ty ty: result_ty
}; };
{ tcx.tcache.borrow_mut().insert(local_def(variant.node.id), tpt);
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(variant.node.id), tpt);
}
write_ty_to_tcx(tcx, variant.node.id, result_ty); write_ty_to_tcx(tcx, variant.node.id, result_ty);
} }
@ -221,8 +217,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
&trait_ty_generics); &trait_ty_generics);
} }
let mut methods = tcx.methods.borrow_mut(); tcx.methods.borrow_mut().insert(ty_method.def_id,
methods.get().insert(ty_method.def_id, ty_method); ty_method);
} }
// Add an entry mapping // Add an entry mapping
@ -238,13 +234,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
}); });
let trait_def_id = local_def(trait_id); let trait_def_id = local_def(trait_id);
let mut trait_method_def_ids = tcx.trait_method_def_ids tcx.trait_method_def_ids.borrow_mut()
.borrow_mut(); .insert(trait_def_id, @method_def_ids.iter()
trait_method_def_ids.get() .map(|x| *x)
.insert(trait_def_id, .collect());
@method_def_ids.iter()
.map(|x| *x)
.collect());
} }
_ => {} // Ignore things that aren't traits. _ => {} // Ignore things that aren't traits.
} }
@ -372,8 +365,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
ty.repr(tcx), ty.repr(tcx),
substs.repr(tcx)); substs.repr(tcx));
let mut tcache = tcx.tcache.borrow_mut(); tcx.tcache.borrow_mut().insert(m.def_id,
tcache.get().insert(m.def_id,
ty_param_bounds_and_ty { ty_param_bounds_and_ty {
generics: ty::Generics { generics: ty::Generics {
type_param_defs: Rc::new(new_type_param_defs), type_param_defs: Rc::new(new_type_param_defs),
@ -423,10 +415,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
// Called only the first time trait_def_of_item is called. // Called only the first time trait_def_of_item is called.
// Supertraits are ensured at the same time. // Supertraits are ensured at the same time.
{ assert!(!tcx.supertraits.borrow().contains_key(&local_def(id)));
let supertraits = tcx.supertraits.borrow();
assert!(!supertraits.get().contains_key(&local_def(id)));
}
let self_ty = ty::mk_self(ccx.tcx, local_def(id)); let self_ty = ty::mk_self(ccx.tcx, local_def(id));
let mut ty_trait_refs: Vec<@ty::TraitRef> = Vec::new(); let mut ty_trait_refs: Vec<@ty::TraitRef> = Vec::new();
@ -451,8 +440,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
} }
} }
let mut supertraits = tcx.supertraits.borrow_mut(); tcx.supertraits.borrow_mut().insert(local_def(id), @ty_trait_refs);
supertraits.get().insert(local_def(id), @ty_trait_refs);
bounds bounds
} }
@ -462,8 +450,7 @@ pub fn convert_field(ccx: &CrateCtxt,
let tt = ccx.to_ty(&ExplicitRscope, v.node.ty); let tt = ccx.to_ty(&ExplicitRscope, v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt); write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */ /* add the field to the tcache */
let mut tcache = ccx.tcx.tcache.borrow_mut(); ccx.tcx.tcache.borrow_mut().insert(local_def(v.node.id),
tcache.get().insert(local_def(v.node.id),
ty::ty_param_bounds_and_ty { ty::ty_param_bounds_and_ty {
generics: struct_generics.clone(), generics: struct_generics.clone(),
ty: tt ty: tt
@ -499,32 +486,28 @@ fn convert_methods(ccx: &CrateCtxt,
m.ident.repr(ccx.tcx), m.ident.repr(ccx.tcx),
m.id, m.id,
fty.repr(ccx.tcx)); fty.repr(ccx.tcx));
{ tcx.tcache.borrow_mut().insert(
let mut tcache = tcx.tcache.borrow_mut(); local_def(m.id),
tcache.get().insert(
local_def(m.id),
// n.b.: the type of a method is parameterized by both // n.b.: the type of a method is parameterized by both
// the parameters on the receiver and those on the method // the parameters on the receiver and those on the method
// itself // itself
ty_param_bounds_and_ty { ty_param_bounds_and_ty {
generics: ty::Generics { generics: ty::Generics {
type_param_defs: Rc::new(vec::append( type_param_defs: Rc::new(vec::append(
Vec::from_slice( Vec::from_slice(
rcvr_ty_generics.type_param_defs()), rcvr_ty_generics.type_param_defs()),
m_ty_generics.type_param_defs())), m_ty_generics.type_param_defs())),
region_param_defs: Rc::new(vec::append( region_param_defs: Rc::new(vec::append(
Vec::from_slice(rcvr_ty_generics.region_param_defs()), Vec::from_slice(rcvr_ty_generics.region_param_defs()),
m_ty_generics.region_param_defs())), m_ty_generics.region_param_defs())),
}, },
ty: fty ty: fty
}); });
}
write_ty_to_tcx(tcx, m.id, fty); write_ty_to_tcx(tcx, m.id, fty);
let mut methods = tcx.methods.borrow_mut(); tcx.methods.borrow_mut().insert(mty.def_id, mty);
methods.get().insert(mty.def_id, mty);
} }
fn ty_of_method(ccx: &CrateCtxt, fn ty_of_method(ccx: &CrateCtxt,
@ -605,13 +588,10 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
let selfty = ccx.to_ty(&ExplicitRscope, selfty); let selfty = ccx.to_ty(&ExplicitRscope, selfty);
write_ty_to_tcx(tcx, it.id, selfty); write_ty_to_tcx(tcx, it.id, selfty);
{ tcx.tcache.borrow_mut().insert(local_def(it.id),
let mut tcache = tcx.tcache.borrow_mut(); ty_param_bounds_and_ty {
tcache.get().insert(local_def(it.id), generics: ty_generics.clone(),
ty_param_bounds_and_ty { ty: selfty});
generics: ty_generics.clone(),
ty: selfty});
}
// If there is a trait reference, treat the methods as always public. // If there is a trait reference, treat the methods as always public.
// This is to work around some incorrect behavior in privacy checking: // This is to work around some incorrect behavior in privacy checking:
@ -670,10 +650,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
let tpt = ty_of_item(ccx, it); let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty); write_ty_to_tcx(tcx, it.id, tpt.ty);
{ tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
}
convert_struct(ccx, struct_def, tpt, it.id); convert_struct(ccx, struct_def, tpt, it.id);
}, },
@ -719,32 +696,23 @@ pub fn convert_struct(ccx: &CrateCtxt,
// Enum-like. // Enum-like.
write_ty_to_tcx(tcx, ctor_id, selfty); write_ty_to_tcx(tcx, ctor_id, selfty);
{ tcx.tcache.borrow_mut().insert(local_def(ctor_id), tpt);
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(ctor_id), tpt);
}
} else if struct_def.fields.get(0).node.kind == } else if struct_def.fields.get(0).node.kind ==
ast::UnnamedField { ast::UnnamedField {
// Tuple-like. // Tuple-like.
let inputs = { let inputs = struct_def.fields.map(
let tcache = tcx.tcache.borrow(); |field| tcx.tcache.borrow().get(
struct_def.fields.map( &local_def(field.node.id)).ty);
|field| tcache.get().get(
&local_def(field.node.id)).ty)
};
let ctor_fn_ty = ty::mk_ctor_fn(tcx, let ctor_fn_ty = ty::mk_ctor_fn(tcx,
ctor_id, ctor_id,
inputs.as_slice(), inputs.as_slice(),
selfty); selfty);
write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty); write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty);
{ tcx.tcache.borrow_mut().insert(local_def(ctor_id),
let mut tcache = tcx.tcache.borrow_mut(); ty_param_bounds_and_ty {
tcache.get().insert(local_def(ctor_id), generics: tpt.generics,
ty_param_bounds_and_ty { ty: ctor_fn_ty
generics: tpt.generics, });
ty: ctor_fn_ty
});
}
} }
} }
} }
@ -764,8 +732,7 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::ForeignItem) {
let tpt = ty_of_foreign_item(ccx, i, abis); let tpt = ty_of_foreign_item(ccx, i, abis);
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty); write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
let mut tcache = ccx.tcx.tcache.borrow_mut(); ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), tpt);
tcache.get().insert(local_def(i.id), tpt);
} }
pub fn instantiate_trait_ref(ccx: &CrateCtxt, pub fn instantiate_trait_ref(ccx: &CrateCtxt,
@ -787,8 +754,8 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt,
astconv::ast_path_to_trait_ref( astconv::ast_path_to_trait_ref(
ccx, &rscope, trait_did, Some(self_ty), &ast_trait_ref.path); ccx, &rscope, trait_did, Some(self_ty), &ast_trait_ref.path);
let mut trait_refs = ccx.tcx.trait_refs.borrow_mut(); ccx.tcx.trait_refs.borrow_mut().insert(ast_trait_ref.ref_id,
trait_refs.get().insert(ast_trait_ref.ref_id, trait_ref); trait_ref);
return trait_ref; return trait_ref;
} }
_ => { _ => {
@ -815,12 +782,9 @@ fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> @ty::TraitDef {
pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> @ty::TraitDef { pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> @ty::TraitDef {
let def_id = local_def(it.id); let def_id = local_def(it.id);
let tcx = ccx.tcx; let tcx = ccx.tcx;
{ match tcx.trait_defs.borrow().find(&def_id) {
let trait_defs = tcx.trait_defs.borrow(); Some(&def) => return def,
match trait_defs.get().find(&def_id) { _ => {}
Some(&def) => return def,
_ => {}
}
} }
match it.node { match it.node {
@ -837,8 +801,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> @ty::TraitDef {
let trait_def = @ty::TraitDef {generics: ty_generics, let trait_def = @ty::TraitDef {generics: ty_generics,
bounds: bounds, bounds: bounds,
trait_ref: trait_ref}; trait_ref: trait_ref};
let mut trait_defs = tcx.trait_defs.borrow_mut(); tcx.trait_defs.borrow_mut().insert(def_id, trait_def);
trait_defs.get().insert(def_id, trait_def);
return trait_def; return trait_def;
} }
ref s => { ref s => {
@ -853,20 +816,16 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
let def_id = local_def(it.id); let def_id = local_def(it.id);
let tcx = ccx.tcx; let tcx = ccx.tcx;
{ match tcx.tcache.borrow().find(&def_id) {
let tcache = tcx.tcache.borrow(); Some(tpt) => return tpt.clone(),
match tcache.get().find(&def_id) { _ => {}
Some(tpt) => return tpt.clone(),
_ => {}
}
} }
match it.node { match it.node {
ast::ItemStatic(t, _, _) => { ast::ItemStatic(t, _, _) => {
let typ = ccx.to_ty(&ExplicitRscope, t); let typ = ccx.to_ty(&ExplicitRscope, t);
let tpt = no_params(typ); let tpt = no_params(typ);
let mut tcache = tcx.tcache.borrow_mut(); tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcache.get().insert(local_def(it.id), tpt.clone());
return tpt; return tpt;
} }
ast::ItemFn(decl, purity, abi, ref generics, _) => { ast::ItemFn(decl, purity, abi, ref generics, _) => {
@ -885,17 +844,13 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
it.id, it.id,
ppaux::ty_to_str(tcx, tpt.ty)); ppaux::ty_to_str(tcx, tpt.ty));
let mut tcache = ccx.tcx.tcache.borrow_mut(); ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcache.get().insert(local_def(it.id), tpt.clone());
return tpt; return tpt;
} }
ast::ItemTy(t, ref generics) => { ast::ItemTy(t, ref generics) => {
{ match tcx.tcache.borrow_mut().find(&local_def(it.id)) {
let mut tcache = tcx.tcache.borrow_mut(); Some(tpt) => return tpt.clone(),
match tcache.get().find(&local_def(it.id)) { None => { }
Some(tpt) => return tpt.clone(),
None => { }
}
} }
let tpt = { let tpt = {
@ -906,8 +861,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
} }
}; };
let mut tcache = tcx.tcache.borrow_mut(); tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcache.get().insert(local_def(it.id), tpt.clone());
return tpt; return tpt;
} }
ast::ItemEnum(_, ref generics) => { ast::ItemEnum(_, ref generics) => {
@ -920,8 +874,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
ty: t ty: t
}; };
let mut tcache = tcx.tcache.borrow_mut(); tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcache.get().insert(local_def(it.id), tpt.clone());
return tpt; return tpt;
} }
ast::ItemTrait(..) => { ast::ItemTrait(..) => {
@ -938,8 +891,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
ty: t ty: t
}; };
let mut tcache = tcx.tcache.borrow_mut(); tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcache.get().insert(local_def(it.id), tpt.clone());
return tpt; return tpt;
} }
ast::ItemImpl(..) | ast::ItemMod(_) | ast::ItemImpl(..) | ast::ItemMod(_) |
@ -997,7 +949,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
type_param_defs: Rc::new(ty_params.iter().enumerate().map(|(offset, param)| { type_param_defs: Rc::new(ty_params.iter().enumerate().map(|(offset, param)| {
let existing_def_opt = { let existing_def_opt = {
let ty_param_defs = ccx.tcx.ty_param_defs.borrow(); let ty_param_defs = ccx.tcx.ty_param_defs.borrow();
ty_param_defs.get().find(&param.id).map(|&def| def) ty_param_defs.find(&param.id).map(|&def| def)
}; };
existing_def_opt.unwrap_or_else(|| { existing_def_opt.unwrap_or_else(|| {
let param_ty = ty::param_ty {idx: base_index + offset, let param_ty = ty::param_ty {idx: base_index + offset,
@ -1011,8 +963,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
default: default default: default
}; };
debug!("def for param: {}", def.repr(ccx.tcx)); debug!("def for param: {}", def.repr(ccx.tcx));
let mut ty_param_defs = ccx.tcx.ty_param_defs.borrow_mut(); ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def);
ty_param_defs.get().insert(param.id, def);
def def
}) })
}).collect()), }).collect()),
@ -1100,8 +1051,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
ty: t_fn ty: t_fn
}; };
let mut tcache = ccx.tcx.tcache.borrow_mut(); ccx.tcx.tcache.borrow_mut().insert(def_id, tpt.clone());
tcache.get().insert(def_id, tpt.clone());
return tpt; return tpt;
} }

View File

@ -757,8 +757,7 @@ impl<'a> Rebuilder<'a> {
fn offset_cur_anon(&self) { fn offset_cur_anon(&self) {
let mut anon = self.cur_anon.get(); let mut anon = self.cur_anon.get();
let inserted_anons = self.inserted_anons.borrow(); while self.inserted_anons.borrow().contains(&anon) {
while inserted_anons.get().contains(&anon) {
anon += 1; anon += 1;
} }
self.cur_anon.set(anon); self.cur_anon.set(anon);
@ -770,8 +769,7 @@ impl<'a> Rebuilder<'a> {
} }
fn track_anon(&self, anon: uint) { fn track_anon(&self, anon: uint) {
let mut inserted_anons = self.inserted_anons.borrow_mut(); self.inserted_anons.borrow_mut().insert(anon);
inserted_anons.get().insert(anon);
} }
fn rebuild_generics(&self, fn rebuild_generics(&self,
@ -845,8 +843,7 @@ impl<'a> Rebuilder<'a> {
ty_queue.push(mut_ty.ty); ty_queue.push(mut_ty.ty);
} }
ast::TyPath(ref path, _, id) => { ast::TyPath(ref path, _, id) => {
let def_map = self.tcx.def_map.borrow(); let a_def = match self.tcx.def_map.borrow().find(&id) {
let a_def = match def_map.get().find(&id) {
None => self.tcx.sess.fatal(format!("unbound path {}", None => self.tcx.sess.fatal(format!("unbound path {}",
pprust::path_to_str(path))), pprust::path_to_str(path))),
Some(&d) => d Some(&d) => d
@ -1258,8 +1255,7 @@ impl LifeGiver {
if !self.taken.contains(&s) { if !self.taken.contains(&s) {
lifetime = name_to_dummy_lifetime( lifetime = name_to_dummy_lifetime(
token::str_to_ident(s.as_slice()).name); token::str_to_ident(s.as_slice()).name);
let mut generated = self.generated.borrow_mut(); self.generated.borrow_mut().push(lifetime);
generated.get().push(lifetime);
break; break;
} }
self.inc_counter(); self.inc_counter();

View File

@ -530,25 +530,21 @@ impl<'a> InferCtxt<'a> {
} }
pub fn start_snapshot(&self) -> Snapshot { pub fn start_snapshot(&self) -> Snapshot {
let ty_var_bindings = self.ty_var_bindings.borrow();
let int_var_bindings = self.int_var_bindings.borrow();
let float_var_bindings = self.float_var_bindings.borrow();
Snapshot { Snapshot {
ty_var_bindings_len: ty_var_bindings.get().bindings.len(), ty_var_bindings_len: self.ty_var_bindings.borrow().bindings.len(),
int_var_bindings_len: int_var_bindings.get().bindings.len(), int_var_bindings_len: self.int_var_bindings.borrow().bindings.len(),
float_var_bindings_len: float_var_bindings.get().bindings.len(), float_var_bindings_len: self.float_var_bindings.borrow().bindings.len(),
region_vars_snapshot: self.region_vars.start_snapshot(), region_vars_snapshot: self.region_vars.start_snapshot(),
} }
} }
pub fn rollback_to(&self, snapshot: &Snapshot) { pub fn rollback_to(&self, snapshot: &Snapshot) {
debug!("rollback!"); debug!("rollback!");
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut(); rollback_to(&mut *self.ty_var_bindings.borrow_mut(),
let mut int_var_bindings = self.int_var_bindings.borrow_mut(); snapshot.ty_var_bindings_len);
let mut float_var_bindings = self.float_var_bindings.borrow_mut(); rollback_to(&mut *self.int_var_bindings.borrow_mut(),
rollback_to(ty_var_bindings.get(), snapshot.ty_var_bindings_len); snapshot.int_var_bindings_len);
rollback_to(int_var_bindings.get(), snapshot.int_var_bindings_len); rollback_to(&mut *self.float_var_bindings.borrow_mut(),
rollback_to(float_var_bindings.get(),
snapshot.float_var_bindings_len); snapshot.float_var_bindings_len);
self.region_vars.rollback_to(snapshot.region_vars_snapshot); self.region_vars.rollback_to(snapshot.region_vars_snapshot);
@ -562,10 +558,8 @@ impl<'a> InferCtxt<'a> {
indent(|| { indent(|| {
let r = self.try(|| f()); let r = self.try(|| f());
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut(); self.ty_var_bindings.borrow_mut().bindings.truncate(0);
let mut int_var_bindings = self.int_var_bindings.borrow_mut(); self.int_var_bindings.borrow_mut().bindings.truncate(0);
ty_var_bindings.get().bindings.truncate(0);
int_var_bindings.get().bindings.truncate(0);
self.region_vars.commit(); self.region_vars.commit();
r r
}) })
@ -614,7 +608,7 @@ impl<'a> InferCtxt<'a> {
self.ty_var_counter.set(id + 1); self.ty_var_counter.set(id + 1);
{ {
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut(); let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
let vals = &mut ty_var_bindings.get().vals; let vals = &mut ty_var_bindings.vals;
vals.insert(id, Root(Bounds { lb: None, ub: None }, 0u)); vals.insert(id, Root(Bounds { lb: None, ub: None }, 0u));
} }
return TyVid(id); return TyVid(id);
@ -632,7 +626,7 @@ impl<'a> InferCtxt<'a> {
let mut int_var_counter = self.int_var_counter.get(); let mut int_var_counter = self.int_var_counter.get();
let mut int_var_bindings = self.int_var_bindings.borrow_mut(); let mut int_var_bindings = self.int_var_bindings.borrow_mut();
let result = IntVid(next_simple_var(&mut int_var_counter, let result = IntVid(next_simple_var(&mut int_var_counter,
int_var_bindings.get())); &mut *int_var_bindings));
self.int_var_counter.set(int_var_counter); self.int_var_counter.set(int_var_counter);
result result
} }
@ -645,7 +639,7 @@ impl<'a> InferCtxt<'a> {
let mut float_var_counter = self.float_var_counter.get(); let mut float_var_counter = self.float_var_counter.get();
let mut float_var_bindings = self.float_var_bindings.borrow_mut(); let mut float_var_bindings = self.float_var_bindings.borrow_mut();
let result = FloatVid(next_simple_var(&mut float_var_counter, let result = FloatVid(next_simple_var(&mut float_var_counter,
float_var_bindings.get())); &mut *float_var_bindings));
self.float_var_counter.set(float_var_counter); self.float_var_counter.set(float_var_counter);
result result
} }

View File

@ -160,78 +160,63 @@ pub fn RegionVarBindings<'a>(tcx: &'a ty::ctxt) -> RegionVarBindings<'a> {
impl<'a> RegionVarBindings<'a> { impl<'a> RegionVarBindings<'a> {
pub fn in_snapshot(&self) -> bool { pub fn in_snapshot(&self) -> bool {
let undo_log = self.undo_log.borrow(); self.undo_log.borrow().len() > 0
undo_log.get().len() > 0
} }
pub fn start_snapshot(&self) -> uint { pub fn start_snapshot(&self) -> uint {
debug!("RegionVarBindings: start_snapshot()"); debug!("RegionVarBindings: start_snapshot()");
if self.in_snapshot() { if self.in_snapshot() {
{ self.undo_log.borrow().len()
let undo_log = self.undo_log.borrow();
undo_log.get().len()
}
} else { } else {
{ self.undo_log.borrow_mut().push(Snapshot);
let mut undo_log = self.undo_log.borrow_mut(); 0
undo_log.get().push(Snapshot);
0
}
} }
} }
pub fn commit(&self) { pub fn commit(&self) {
debug!("RegionVarBindings: commit()"); debug!("RegionVarBindings: commit()");
let mut undo_log = self.undo_log.borrow_mut(); let mut undo_log = self.undo_log.borrow_mut();
while undo_log.get().len() > 0 { while undo_log.len() > 0 {
undo_log.get().pop().unwrap(); undo_log.pop().unwrap();
} }
} }
pub fn rollback_to(&self, snapshot: uint) { pub fn rollback_to(&self, snapshot: uint) {
debug!("RegionVarBindings: rollback_to({})", snapshot); debug!("RegionVarBindings: rollback_to({})", snapshot);
let mut undo_log = self.undo_log.borrow_mut(); let mut undo_log = self.undo_log.borrow_mut();
while undo_log.get().len() > snapshot { while undo_log.len() > snapshot {
let undo_item = undo_log.get().pop().unwrap(); let undo_item = undo_log.pop().unwrap();
debug!("undo_item={:?}", undo_item); debug!("undo_item={:?}", undo_item);
match undo_item { match undo_item {
Snapshot => {} Snapshot => {}
AddVar(vid) => { AddVar(vid) => {
let mut var_origins = self.var_origins.borrow_mut(); let mut var_origins = self.var_origins.borrow_mut();
assert_eq!(var_origins.get().len(), vid.to_uint() + 1); assert_eq!(var_origins.len(), vid.to_uint() + 1);
var_origins.get().pop().unwrap(); var_origins.pop().unwrap();
} }
AddConstraint(ref constraint) => { AddConstraint(ref constraint) => {
let mut constraints = self.constraints.borrow_mut(); self.constraints.borrow_mut().remove(constraint);
constraints.get().remove(constraint);
} }
AddCombination(Glb, ref regions) => { AddCombination(Glb, ref regions) => {
let mut glbs = self.glbs.borrow_mut(); self.glbs.borrow_mut().remove(regions);
glbs.get().remove(regions);
} }
AddCombination(Lub, ref regions) => { AddCombination(Lub, ref regions) => {
let mut lubs = self.lubs.borrow_mut(); self.lubs.borrow_mut().remove(regions);
lubs.get().remove(regions);
} }
} }
} }
} }
pub fn num_vars(&self) -> uint { pub fn num_vars(&self) -> uint {
let var_origins = self.var_origins.borrow(); self.var_origins.borrow().len()
var_origins.get().len()
} }
pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid { pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
let id = self.num_vars(); let id = self.num_vars();
let mut var_origins = self.var_origins.borrow_mut(); self.var_origins.borrow_mut().push(origin);
var_origins.get().push(origin);
let vid = RegionVid { id: id }; let vid = RegionVid { id: id };
if self.in_snapshot() { if self.in_snapshot() {
{ self.undo_log.borrow_mut().push(AddVar(vid));
let mut undo_log = self.undo_log.borrow_mut();
undo_log.get().push(AddVar(vid));
}
} }
debug!("created new region variable {:?} with origin {:?}", debug!("created new region variable {:?} with origin {:?}",
vid, origin.repr(self.tcx)); vid, origin.repr(self.tcx));
@ -274,8 +259,7 @@ impl<'a> RegionVarBindings<'a> {
} }
fn values_are_none(&self) -> bool { fn values_are_none(&self) -> bool {
let values = self.values.borrow(); self.values.borrow().is_none()
values.get().is_none()
} }
pub fn add_constraint(&self, pub fn add_constraint(&self,
@ -286,13 +270,9 @@ impl<'a> RegionVarBindings<'a> {
debug!("RegionVarBindings: add_constraint({:?})", constraint); debug!("RegionVarBindings: add_constraint({:?})", constraint);
let mut constraints = self.constraints.borrow_mut(); if self.constraints.borrow_mut().insert(constraint, origin) {
if constraints.get().insert(constraint, origin) {
if self.in_snapshot() { if self.in_snapshot() {
{ self.undo_log.borrow_mut().push(AddConstraint(constraint));
let mut undo_log = self.undo_log.borrow_mut();
undo_log.get().push(AddConstraint(constraint));
}
} }
} }
} }
@ -383,12 +363,10 @@ impl<'a> RegionVarBindings<'a> {
} }
pub fn resolve_var(&self, rid: RegionVid) -> ty::Region { pub fn resolve_var(&self, rid: RegionVid) -> ty::Region {
let values = self.values.borrow(); let v = match *self.values.borrow() {
let v = match *values.get() {
None => { None => {
let var_origins = self.var_origins.borrow();
self.tcx.sess.span_bug( self.tcx.sess.span_bug(
var_origins.get().get(rid.to_uint()).span(), self.var_origins.borrow().get(rid.to_uint()).span(),
format!("attempt to resolve region variable before \ format!("attempt to resolve region variable before \
values have been computed!")) values have been computed!"))
} }
@ -430,25 +408,16 @@ impl<'a> RegionVarBindings<'a> {
new_r: Region|) new_r: Region|)
-> Region { -> Region {
let vars = TwoRegions { a: a, b: b }; let vars = TwoRegions { a: a, b: b };
{ match self.combine_map(t).borrow().find(&vars) {
let map = self.combine_map(t).borrow(); Some(&c) => {
match map.get().find(&vars) { return ReInfer(ReVar(c));
Some(&c) => {
return ReInfer(ReVar(c));
}
None => {}
} }
None => {}
} }
let c = self.new_region_var(infer::MiscVariable(origin.span())); let c = self.new_region_var(infer::MiscVariable(origin.span()));
{ self.combine_map(t).borrow_mut().insert(vars, c);
let mut map = self.combine_map(t).borrow_mut();
map.get().insert(vars, c);
}
if self.in_snapshot() { if self.in_snapshot() {
{ self.undo_log.borrow_mut().push(AddCombination(t, vars));
let mut undo_log = self.undo_log.borrow_mut();
undo_log.get().push(AddCombination(t, vars));
}
} }
relate(self, a, ReInfer(ReVar(c))); relate(self, a, ReInfer(ReVar(c)));
relate(self, b, ReInfer(ReVar(c))); relate(self, b, ReInfer(ReVar(c)));
@ -458,8 +427,7 @@ impl<'a> RegionVarBindings<'a> {
pub fn vars_created_since_snapshot(&self, snapshot: uint) pub fn vars_created_since_snapshot(&self, snapshot: uint)
-> Vec<RegionVid> { -> Vec<RegionVid> {
let undo_log = self.undo_log.borrow(); self.undo_log.borrow().slice_from(snapshot).iter()
undo_log.get().slice_from(snapshot).iter()
.filter_map(|&elt| match elt { .filter_map(|&elt| match elt {
AddVar(vid) => Some(vid), AddVar(vid) => Some(vid),
_ => None _ => None
@ -479,10 +447,7 @@ impl<'a> RegionVarBindings<'a> {
debug!("tainted(snapshot={}, r0={:?})", snapshot, r0); debug!("tainted(snapshot={}, r0={:?})", snapshot, r0);
let _indenter = indenter(); let _indenter = indenter();
let undo_len = { let undo_len = self.undo_log.borrow().len();
let undo_log = self.undo_log.borrow();
undo_log.get().len()
};
// `result_set` acts as a worklist: we explore all outgoing // `result_set` acts as a worklist: we explore all outgoing
// edges and add any new regions we find to result_set. This // edges and add any new regions we find to result_set. This
@ -498,25 +463,22 @@ impl<'a> RegionVarBindings<'a> {
let mut undo_index = snapshot; let mut undo_index = snapshot;
while undo_index < undo_len { while undo_index < undo_len {
// nb: can't use uint::range() here as we move result_set // nb: can't use uint::range() here as we move result_set
let regs = { let regs = match self.undo_log.borrow().get(undo_index) {
let undo_log = self.undo_log.borrow(); &AddConstraint(ConstrainVarSubVar(ref a, ref b)) => {
match undo_log.get().get(undo_index) { Some((ReInfer(ReVar(*a)),
&AddConstraint(ConstrainVarSubVar(ref a, ref b)) => { ReInfer(ReVar(*b))))
Some((ReInfer(ReVar(*a)), }
ReInfer(ReVar(*b)))) &AddConstraint(ConstrainRegSubVar(ref a, ref b)) => {
} Some((*a, ReInfer(ReVar(*b))))
&AddConstraint(ConstrainRegSubVar(ref a, ref b)) => { }
Some((*a, ReInfer(ReVar(*b)))) &AddConstraint(ConstrainVarSubReg(ref a, ref b)) => {
} Some((ReInfer(ReVar(*a)), *b))
&AddConstraint(ConstrainVarSubReg(ref a, ref b)) => { }
Some((ReInfer(ReVar(*a)), *b)) &AddConstraint(ConstrainRegSubReg(a, b)) => {
} Some((a, b))
&AddConstraint(ConstrainRegSubReg(a, b)) => { }
Some((a, b)) _ => {
} None
_ => {
None
}
} }
}; };
@ -563,8 +525,7 @@ impl<'a> RegionVarBindings<'a> {
debug!("RegionVarBindings: resolve_regions()"); debug!("RegionVarBindings: resolve_regions()");
let mut errors = vec!(); let mut errors = vec!();
let v = self.infer_variable_values(&mut errors); let v = self.infer_variable_values(&mut errors);
let mut values = self.values.borrow_mut(); *self.values.borrow_mut() = Some(v);
*values.get() = Some(v);
errors errors
} }
} }
@ -595,9 +556,8 @@ impl<'a> RegionVarBindings<'a> {
} }
(ReInfer(ReVar(v_id)), _) | (_, ReInfer(ReVar(v_id))) => { (ReInfer(ReVar(v_id)), _) | (_, ReInfer(ReVar(v_id))) => {
let var_origins = self.var_origins.borrow();
self.tcx.sess.span_bug( self.tcx.sess.span_bug(
var_origins.get().get(v_id.to_uint()).span(), self.var_origins.borrow().get(v_id.to_uint()).span(),
format!("lub_concrete_regions invoked with \ format!("lub_concrete_regions invoked with \
non-concrete regions: {:?}, {:?}", a, b)); non-concrete regions: {:?}, {:?}", a, b));
} }
@ -700,9 +660,8 @@ impl<'a> RegionVarBindings<'a> {
(ReInfer(ReVar(v_id)), _) | (ReInfer(ReVar(v_id)), _) |
(_, ReInfer(ReVar(v_id))) => { (_, ReInfer(ReVar(v_id))) => {
let var_origins = self.var_origins.borrow();
self.tcx.sess.span_bug( self.tcx.sess.span_bug(
var_origins.get().get(v_id.to_uint()).span(), self.var_origins.borrow().get(v_id.to_uint()).span(),
format!("glb_concrete_regions invoked with \ format!("glb_concrete_regions invoked with \
non-concrete regions: {:?}, {:?}", a, b)); non-concrete regions: {:?}, {:?}", a, b));
} }
@ -1004,8 +963,7 @@ impl<'a> RegionVarBindings<'a> {
&self, &self,
errors: &mut Vec<RegionResolutionError>) errors: &mut Vec<RegionResolutionError>)
{ {
let constraints = self.constraints.borrow(); for (constraint, _) in self.constraints.borrow().iter() {
for (constraint, _) in constraints.get().iter() {
let (sub, sup) = match *constraint { let (sub, sup) = match *constraint {
ConstrainVarSubVar(..) | ConstrainVarSubVar(..) |
ConstrainRegSubVar(..) | ConstrainRegSubVar(..) |
@ -1023,7 +981,7 @@ impl<'a> RegionVarBindings<'a> {
debug!("ConcreteFailure: !(sub <= sup): sub={:?}, sup={:?}", debug!("ConcreteFailure: !(sub <= sup): sub={:?}, sup={:?}",
sub, sup); sub, sup);
let origin = constraints.get().get_copy(constraint); let origin = self.constraints.borrow().get_copy(constraint);
errors.push(ConcreteFailure(origin, sub, sup)); errors.push(ConcreteFailure(origin, sub, sup));
} }
} }
@ -1112,7 +1070,7 @@ impl<'a> RegionVarBindings<'a> {
let num_vars = self.num_vars(); let num_vars = self.num_vars();
let constraints = self.constraints.borrow(); let constraints = self.constraints.borrow();
let num_edges = constraints.get().len(); let num_edges = constraints.len();
let mut graph = graph::Graph::with_capacity(num_vars + 1, let mut graph = graph::Graph::with_capacity(num_vars + 1,
num_edges); num_edges);
@ -1122,7 +1080,7 @@ impl<'a> RegionVarBindings<'a> {
} }
let dummy_idx = graph.add_node(()); let dummy_idx = graph.add_node(());
for (constraint, _) in constraints.get().iter() { for (constraint, _) in constraints.iter() {
match *constraint { match *constraint {
ConstrainVarSubVar(a_id, b_id) => { ConstrainVarSubVar(a_id, b_id) => {
graph.add_edge(NodeIndex(a_id.to_uint()), graph.add_edge(NodeIndex(a_id.to_uint()),
@ -1174,23 +1132,19 @@ impl<'a> RegionVarBindings<'a> {
for upper_bound in upper_bounds.iter() { for upper_bound in upper_bounds.iter() {
if !self.is_subregion_of(lower_bound.region, if !self.is_subregion_of(lower_bound.region,
upper_bound.region) { upper_bound.region) {
{ errors.push(SubSupConflict(
let var_origins = self.var_origins.borrow(); *self.var_origins.borrow().get(node_idx.to_uint()),
errors.push(SubSupConflict( lower_bound.origin,
*var_origins.get().get(node_idx.to_uint()), lower_bound.region,
lower_bound.origin, upper_bound.origin,
lower_bound.region, upper_bound.region));
upper_bound.origin, return;
upper_bound.region));
return;
}
} }
} }
} }
let var_origins = self.var_origins.borrow();
self.tcx.sess.span_bug( self.tcx.sess.span_bug(
var_origins.get().get(node_idx.to_uint()).span(), self.var_origins.borrow().get(node_idx.to_uint()).span(),
format!("collect_error_for_expanding_node() could not find error \ format!("collect_error_for_expanding_node() could not find error \
for var {:?}, lower_bounds={}, upper_bounds={}", for var {:?}, lower_bounds={}, upper_bounds={}",
node_idx, node_idx,
@ -1222,9 +1176,8 @@ impl<'a> RegionVarBindings<'a> {
upper_bound_2.region) { upper_bound_2.region) {
Ok(_) => {} Ok(_) => {}
Err(_) => { Err(_) => {
let var_origins = self.var_origins.borrow();
errors.push(SupSupConflict( errors.push(SupSupConflict(
*var_origins.get().get(node_idx.to_uint()), *self.var_origins.borrow().get(node_idx.to_uint()),
upper_bound_1.origin, upper_bound_1.origin,
upper_bound_1.region, upper_bound_1.region,
upper_bound_2.origin, upper_bound_2.origin,
@ -1235,9 +1188,8 @@ impl<'a> RegionVarBindings<'a> {
} }
} }
let var_origins = self.var_origins.borrow();
self.tcx.sess.span_bug( self.tcx.sess.span_bug(
var_origins.get().get(node_idx.to_uint()).span(), self.var_origins.borrow().get(node_idx.to_uint()).span(),
format!("collect_error_for_contracting_node() could not find error \ format!("collect_error_for_contracting_node() could not find error \
for var {:?}, upper_bounds={}", for var {:?}, upper_bounds={}",
node_idx, node_idx,
@ -1317,10 +1269,9 @@ impl<'a> RegionVarBindings<'a> {
ConstrainRegSubVar(region, _) | ConstrainRegSubVar(region, _) |
ConstrainVarSubReg(_, region) => { ConstrainVarSubReg(_, region) => {
let constraints = this.constraints.borrow();
state.result.push(RegionAndOrigin { state.result.push(RegionAndOrigin {
region: region, region: region,
origin: constraints.get().get_copy(&edge.data) origin: this.constraints.borrow().get_copy(&edge.data)
}); });
} }
@ -1340,8 +1291,7 @@ impl<'a> RegionVarBindings<'a> {
changed = false; changed = false;
iteration += 1; iteration += 1;
debug!("---- {} Iteration \\#{}", tag, iteration); debug!("---- {} Iteration \\#{}", tag, iteration);
let constraints = self.constraints.borrow(); for (constraint, _) in self.constraints.borrow().iter() {
for (constraint, _) in constraints.get().iter() {
let edge_changed = body(constraint); let edge_changed = body(constraint);
if edge_changed { if edge_changed {
debug!("Updated due to constraint {}", debug!("Updated due to constraint {}",

View File

@ -75,8 +75,7 @@ impl<'a> UnifyInferCtxtMethods for InferCtxt<'a> {
let tcx = self.tcx; let tcx = self.tcx;
let vb = UnifyVid::appropriate_vals_and_bindings(self); let vb = UnifyVid::appropriate_vals_and_bindings(self);
let mut vb = vb.borrow_mut(); return helper(tcx, &mut *vb.borrow_mut(), vid);
return helper(tcx, vb.get(), vid);
fn helper<T:Clone, V:Clone+Eq+Vid>( fn helper<T:Clone, V:Clone+Eq+Vid>(
tcx: &ty::ctxt, tcx: &ty::ctxt,
@ -123,9 +122,9 @@ impl<'a> UnifyInferCtxtMethods for InferCtxt<'a> {
let vb = UnifyVid::appropriate_vals_and_bindings(self); let vb = UnifyVid::appropriate_vals_and_bindings(self);
let mut vb = vb.borrow_mut(); let mut vb = vb.borrow_mut();
let old_v = (*vb.get().vals.get(&vid.to_uint())).clone(); let old_v = (*vb.vals.get(&vid.to_uint())).clone();
vb.get().bindings.push((vid.clone(), old_v)); vb.bindings.push((vid.clone(), old_v));
vb.get().vals.insert(vid.to_uint(), new_v); vb.vals.insert(vid.to_uint(), new_v);
} }
fn unify<T:Clone + InferStr, fn unify<T:Clone + InferStr,

View File

@ -252,8 +252,7 @@ pub struct CrateCtxt<'a> {
pub fn write_ty_to_tcx(tcx: &ty::ctxt, node_id: ast::NodeId, ty: ty::t) { pub fn write_ty_to_tcx(tcx: &ty::ctxt, node_id: ast::NodeId, ty: ty::t) {
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_str(tcx, ty)); debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_str(tcx, ty));
assert!(!ty::type_needs_infer(ty)); assert!(!ty::type_needs_infer(ty));
let mut node_types = tcx.node_types.borrow_mut(); tcx.node_types.borrow_mut().insert(node_id as uint, ty);
node_types.get().insert(node_id as uint, ty);
} }
pub fn write_substs_to_tcx(tcx: &ty::ctxt, pub fn write_substs_to_tcx(tcx: &ty::ctxt,
node_id: ast::NodeId, node_id: ast::NodeId,
@ -263,8 +262,7 @@ pub fn write_substs_to_tcx(tcx: &ty::ctxt,
substs.map(|t| ppaux::ty_to_str(tcx, *t))); substs.map(|t| ppaux::ty_to_str(tcx, *t)));
assert!(substs.iter().all(|t| !ty::type_needs_infer(*t))); assert!(substs.iter().all(|t| !ty::type_needs_infer(*t)));
let mut node_type_substs = tcx.node_type_substs.borrow_mut(); tcx.node_type_substs.borrow_mut().insert(node_id, substs);
node_type_substs.get().insert(node_id, substs);
} }
} }
pub fn write_tpt_to_tcx(tcx: &ty::ctxt, pub fn write_tpt_to_tcx(tcx: &ty::ctxt,
@ -277,8 +275,7 @@ pub fn write_tpt_to_tcx(tcx: &ty::ctxt,
} }
pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def { pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def {
let def_map = tcx.def_map.borrow(); match tcx.def_map.borrow().find(&id) {
match def_map.get().find(&id) {
Some(&x) => x, Some(&x) => x,
_ => { _ => {
tcx.sess.span_fatal(sp, "internal error looking up a definition") tcx.sess.span_fatal(sp, "internal error looking up a definition")

View File

@ -359,10 +359,7 @@ impl<'a> Visitor<()> for TermsContext<'a> {
// "invalid item id" from "item id with no // "invalid item id" from "item id with no
// parameters". // parameters".
if self.num_inferred() == inferreds_on_entry { if self.num_inferred() == inferreds_on_entry {
let mut item_variance_map = self.tcx let newly_added = self.tcx.item_variance_map.borrow_mut().insert(
.item_variance_map
.borrow_mut();
let newly_added = item_variance_map.get().insert(
ast_util::local_def(item.id), ast_util::local_def(item.id),
self.empty_variances); self.empty_variances);
assert!(newly_added); assert!(newly_added);
@ -944,9 +941,8 @@ impl<'a> SolveContext<'a> {
tcx.sess.span_err(tcx.map.span(item_id), found); tcx.sess.span_err(tcx.map.span(item_id), found);
} }
let mut item_variance_map = tcx.item_variance_map.borrow_mut(); let newly_added = tcx.item_variance_map.borrow_mut()
let newly_added = item_variance_map.get().insert(item_def_id, .insert(item_def_id, @item_variances);
@item_variances);
assert!(newly_added); assert!(newly_added);
} }
} }

View File

@ -459,9 +459,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
ty_infer(infer_ty) => infer_ty.to_str(), ty_infer(infer_ty) => infer_ty.to_str(),
ty_err => ~"[type error]", ty_err => ~"[type error]",
ty_param(param_ty {idx: id, def_id: did}) => { ty_param(param_ty {idx: id, def_id: did}) => {
let ty_param_defs = cx.ty_param_defs.borrow(); let ident = match cx.ty_param_defs.borrow().find(&did.node) {
let param_def = ty_param_defs.get().find(&did.node);
let ident = match param_def {
Some(def) => token::get_ident(def.ident).get().to_str(), Some(def) => token::get_ident(def.ident).get().to_str(),
// This should not happen... // This should not happen...
None => format!("BUG[{:?}]", id) None => format!("BUG[{:?}]", id)