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();
rustpath.push(self.sess.filesearch().get_target_lib_path());
let addl_lib_search_paths = self.sess
.opts
.addl_lib_search_paths
.borrow();
let path = addl_lib_search_paths.get().iter();
for path in path.chain(rustpath.iter()) {
let search = self.sess.opts.addl_lib_search_paths.borrow();
for path in search.iter().chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
let test = path.join(oslibname.as_slice());
if test.exists() { return test }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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 };
}
let cnum_map = cdata.cnum_map.borrow();
match cnum_map.get().find(&did.krate) {
match cdata.cnum_map.borrow().find(&did.krate) {
Some(&n) => {
ast::DefId {
krate: n,

View file

@ -270,8 +270,7 @@ fn encode_symbol(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
id: NodeId) {
ebml_w.start_tag(tag_items_data_item_symbol);
let item_symbols = ecx.item_symbols.borrow();
match item_symbols.get().find(&id) {
match ecx.item_symbols.borrow().find(&id) {
Some(x) => {
debug!("encode_symbol(id={:?}, str={})", id, *x);
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 });
for variant in variants.iter() {
let def_id = local_def(variant.node.id);
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: variant.node.id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: variant.node.id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id);
match variant.node.kind {
@ -415,11 +411,9 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2)
-> bool {
let inherent_impls = ecx.tcx.inherent_impls.borrow();
match inherent_impls.get().find(&exp.def_id) {
match ecx.tcx.inherent_impls.borrow().find(&exp.def_id) {
Some(implementations) => {
let implementations = implementations.borrow();
for &base_impl in implementations.get().iter() {
for &base_impl in implementations.borrow().iter() {
for &m in base_impl.methods.iter() {
if m.explicit_self == ast::SelfStatic {
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,
exp: &middle::resolve::Export2)
-> bool {
let trait_methods_cache = ecx.tcx.trait_methods_cache.borrow();
match trait_methods_cache.get().find(&exp.def_id) {
match ecx.tcx.trait_methods_cache.borrow().find(&exp.def_id) {
Some(methods) => {
for &m in methods.iter() {
if m.explicit_self == ast::SelfStatic {
@ -538,8 +531,7 @@ fn encode_reexports(ecx: &EncodeContext,
id: NodeId,
path: PathElems) {
debug!("(encoding info for module) encoding reexports for {}", id);
let reexports2 = ecx.reexports2.borrow();
match reexports2.get().find(&id) {
match ecx.reexports2.borrow().find(&id) {
Some(ref exports) => {
debug!("(encoding info for module) found reexports for {}", id);
for exp in exports.iter() {
@ -703,13 +695,10 @@ fn encode_info_for_struct(ecx: &EncodeContext,
let id = field.node.id;
index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()});
{
let mut global_index = global_index.borrow_mut();
global_index.get().push(entry {
val: id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
global_index.borrow_mut().push(entry {
val: id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
ebml_w.start_tag(tag_items_data_item);
debug!("encode_info_for_struct: doing {} {}",
token::get_ident(nm), id);
@ -728,13 +717,10 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
ctor_id: NodeId,
index: @RefCell<Vec<entry<i64>> >,
struct_id: NodeId) {
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: ctor_id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: ctor_id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
ebml_w.start_tag(tag_items_data_item);
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));
encode_parent_item(ebml_w, local_def(struct_id));
let item_symbols = ecx.item_symbols.borrow();
if item_symbols.get().contains_key(&ctor_id) {
if ecx.item_symbols.borrow().contains_key(&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,
ebml_w: &mut writer::Encoder,
def_id: DefId) {
let inherent_impls = ecx.tcx.inherent_impls.borrow();
match inherent_impls.get().find(&def_id) {
match ecx.tcx.inherent_impls.borrow().find(&def_id) {
None => {}
Some(&implementations) => {
let implementations = implementations.borrow();
for implementation in implementations.get().iter() {
for implementation in implementations.borrow().iter() {
ebml_w.start_tag(tag_items_data_item_inherent_impl);
encode_def_id(ebml_w, implementation.did);
ebml_w.end_tag();
@ -871,12 +854,10 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
fn encode_extension_implementations(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
trait_def_id: DefId) {
let trait_impls = ecx.tcx.trait_impls.borrow();
match trait_impls.get().find(&trait_def_id) {
match ecx.tcx.trait_impls.borrow().find(&trait_def_id) {
None => {}
Some(&implementations) => {
let implementations = implementations.borrow();
for implementation in implementations.get().iter() {
for implementation in implementations.borrow().iter() {
ebml_w.start_tag(tag_items_data_item_extension_impl);
encode_def_id(ebml_w, implementation.did);
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,
index: @RefCell<Vec<entry<i64>> >) {
let mut index = index.borrow_mut();
index.get().push(entry {
index.borrow_mut().push(entry {
val: item.id as i64,
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_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 {
(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
// have inherited, so we drive this based on the impl structure.
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);
ebml_w.start_tag(tag_items_data_item);
@ -1108,13 +1088,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
Some(*ast_methods.get(i))
} else { None };
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: m.def_id.node as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: m.def_id.node as i64,
pos: ebml_w.writer.tell().unwrap(),
});
encode_info_for_method(ecx,
ebml_w,
*m,
@ -1169,13 +1146,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
let method_ty = ty::method(tcx, method_def_id);
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: method_def_id.node as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: method_def_id.node as i64,
pos: ebml_w.writer.tell().unwrap(),
});
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>> >,
path: PathElems,
abi: AbiSet) {
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: nitem.id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: nitem.id as i64,
pos: ebml_w.writer.tell().unwrap(),
});
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(nitem.id));
@ -1347,13 +1318,10 @@ fn encode_info_for_items(ecx: &EncodeContext,
-> Vec<entry<i64>> {
let index = @RefCell::new(Vec::new());
ebml_w.start_tag(tag_items_data);
{
let mut index = index.borrow_mut();
index.get().push(entry {
val: CRATE_NODE_ID as i64,
pos: ebml_w.writer.tell().unwrap(),
});
}
index.borrow_mut().push(entry {
val: CRATE_NODE_ID as i64,
pos: ebml_w.writer.tell().unwrap(),
});
encode_info_for_mod(ecx,
ebml_w,
&krate.module,
@ -1390,8 +1358,7 @@ fn create_index<T:Clone + Hash + 'static>(
}
for elt in index.iter() {
let h = hash::hash(&elt.val) as uint;
let mut bucket = buckets.get_mut(h % 256).borrow_mut();
bucket.get().push((*elt).clone());
buckets.get_mut(h % 256).borrow_mut().push((*elt).clone());
}
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) {
ebml_w.start_tag(tag_native_libraries);
let used_libraries = ecx.tcx.sess.cstore.get_used_libraries();
let used_libraries = used_libraries.borrow();
for &(ref lib, kind) in used_libraries.get().iter() {
for &(ref lib, kind) in ecx.tcx.sess.cstore.get_used_libraries()
.borrow().iter() {
match kind {
cstore::NativeStatic => {} // these libraries are not propagated
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) {
let ptr = ecx.tcx.sess.macro_registrar_fn.borrow();
match *ptr.get() {
match *ecx.tcx.sess.macro_registrar_fn.borrow() {
Some(did) => {
ebml_w.start_tag(tag_macro_registrar_fn);
encode_def_id(ebml_w, did);
@ -1665,8 +1630,7 @@ impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> {
match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = self.ecx.tcx.def_map;
let def_map = def_map.borrow();
let trait_def = def_map.get().get_copy(&trait_ref.ref_id);
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let def_id = ast_util::def_id_of_def(trait_def);
// 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 found = false;
let addl_lib_search_paths = self.addl_lib_search_paths.borrow();
debug!("filesearch: searching additional lib search paths [{:?}]",
addl_lib_search_paths.get().len());
for path in addl_lib_search_paths.get().iter() {
self.addl_lib_search_paths.borrow().len());
for path in self.addl_lib_search_paths.borrow().iter() {
match f(path) {
FileMatches => found = true,
FileDoesntMatch => ()

View file

@ -382,23 +382,17 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
pos: pos,
len: len };
let tt_opt = {
let rcache = st.tcx.rcache.borrow();
rcache.get().find_copy(&key)
};
match tt_opt {
match st.tcx.rcache.borrow().find_copy(&key) {
Some(tt) => return tt,
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;
}
None => {}
}
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));

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) {
match cx.abbrevs {
ac_no_abbrevs => {
let result_str_opt;
{
let short_names_cache = cx.tcx.short_names_cache.borrow();
result_str_opt = short_names_cache.get()
.find(&t)
.map(|result| {
(*result).clone()
});
}
let result_str_opt = cx.tcx.short_names_cache.borrow()
.find(&t)
.map(|result| {
(*result).clone()
});
let result_str = match result_str_opt {
Some(s) => s,
None => {
let wr = &mut MemWriter::new();
enc_sty(wr, cx, &ty::get(t).sty);
let s = str::from_utf8(wr.get_ref()).unwrap();
let mut short_names_cache = cx.tcx
.short_names_cache
.borrow_mut();
short_names_cache.get().insert(t, s.to_str());
cx.tcx.short_names_cache.borrow_mut().insert(t, s.to_str());
s.to_str()
}
};
w.write(result_str.as_bytes());
}
ac_use_abbrevs(abbrevs) => {
{
let mut abbrevs = abbrevs.borrow_mut();
match abbrevs.get().find(&t) {
Some(a) => { w.write(a.s.as_bytes()); return; }
None => {}
}
match abbrevs.borrow_mut().find(&t) {
Some(a) => { w.write(a.s.as_bytes()); return; }
None => {}
}
let pos = w.tell().unwrap();
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,
len: len as uint,
s: s };
{
let mut abbrevs = abbrevs.borrow_mut();
abbrevs.get().insert(t, a);
}
abbrevs.borrow_mut().insert(t, a);
}
return;
}

View file

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

View file

@ -378,11 +378,7 @@ impl<'a> CheckLoanCtxt<'a> {
pub fn check_assignment(&self, expr: &ast::Expr) {
// We don't use cat_expr() here because we don't want to treat
// auto-ref'd parameters in overloaded operators as rvalues.
let adj = {
let adjustments = self.bccx.tcx.adjustments.borrow();
adjustments.get().find_copy(&expr.id)
};
let cmt = match adj {
let cmt = match self.bccx.tcx.adjustments.borrow().find_copy(&expr.id) {
None => self.bccx.cat_expr_unadjusted(expr),
Some(adj) => self.bccx.cat_expr_autoderefd(expr, adj)
};
@ -452,10 +448,7 @@ impl<'a> CheckLoanCtxt<'a> {
cmt.repr(this.tcx()));
match cmt.cat {
mc::cat_local(id) | mc::cat_arg(id) => {
let mut used_mut_nodes = this.tcx()
.used_mut_nodes
.borrow_mut();
used_mut_nodes.get().insert(id);
this.tcx().used_mut_nodes.borrow_mut().insert(id);
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());
}
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]);
}
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, []);
}
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 root_info = RootInfo {scope: root_scope};
let mut root_map = self.bccx.root_map.borrow_mut();
root_map.get().insert(rm_key, root_info);
self.bccx.root_map.borrow_mut().insert(rm_key, root_info);
debug!("root_key: {:?} root_info: {:?}", rm_key, root_info);
Ok(())

View file

@ -195,7 +195,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
this.id_range.add(ex.id);
// 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);
}
@ -255,7 +255,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
ast::ExprIndex(_, 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.
//
// Currently these do not use adjustments, so we have to
@ -343,7 +343,7 @@ impl<'a> GatherLoanCtxt<'a> {
autoderefs: uint) {
let method_map = self.bccx.method_map.borrow();
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) => {
// Treat overloaded autoderefs as if an AutoRef adjustment
// 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
let upvar_id = ty::UpvarId { var_id: var_id,
closure_expr_id: closure_expr.id };
let upvar_borrow_map = self.tcx().upvar_borrow_map.borrow();
let upvar_borrow = upvar_borrow_map.get().get_copy(&upvar_id);
let upvar_borrow = self.tcx().upvar_borrow_map.borrow()
.get_copy(&upvar_id);
self.guarantee_valid_kind(closure_expr.id,
closure_expr.span,
@ -750,10 +750,7 @@ impl<'a> GatherLoanCtxt<'a> {
match *loan_path {
LpVar(local_id) => {
let mut used_mut_nodes = self.tcx()
.used_mut_nodes
.borrow_mut();
used_mut_nodes.get().insert(local_id);
self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
}
LpExtend(base, mc::McInherited, _) => {
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) {
Some(ast_map::NodeExpr(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",
move.id, r))
@ -601,7 +601,7 @@ impl<'a> BorrowckCtxt<'a> {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) {
Some(ast_map::NodeExpr(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",
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> {
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> {
let adjustments = self.tcx.adjustments.borrow();
adjustments.get().find_copy(&id)
self.tcx.adjustments.borrow().find_copy(&id)
}
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> {
@ -959,7 +958,6 @@ impl<'a> mc::Typer for TcxTyper<'a> {
}
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
let upvar_borrow_map = self.tcx.upvar_borrow_map.borrow();
upvar_borrow_map.get().get_copy(&id)
self.tcx.upvar_borrow_map.borrow().get_copy(&id)
}
}

View file

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

View file

@ -497,8 +497,7 @@ impl<'a> CFGBuilder<'a> {
}
Some(_) => {
let def_map = self.tcx.def_map.borrow();
match def_map.get().find(&expr.id) {
match self.tcx.def_map.borrow().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => {
for l in self.loop_scopes.iter() {
if l.loop_id == loop_id {
@ -522,6 +521,6 @@ impl<'a> CFGBuilder<'a> {
fn is_method_call(&self, expr: &ast::Expr) -> bool {
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) => {}
ExprBinary(..) | ExprUnary(..) => {
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 \
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 \
items without type parameters");
}
match v.def_map.borrow().get().find(&e.id) {
match v.def_map.borrow().find(&e.id) {
Some(&DefStatic(..)) |
Some(&DefFn(_, _)) |
Some(&DefVariant(_, _, _)) |
@ -145,7 +145,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
}
}
ExprCall(callee, _) => {
match v.def_map.borrow().get().find(&callee.id) {
match v.def_map.borrow().find(&callee.id) {
Some(&DefStruct(..)) => {} // OK.
Some(&DefVariant(..)) => {} // OK.
_ => {
@ -221,8 +221,7 @@ impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> {
fn visit_expr(&mut self, e: &Expr, _: ()) {
match e.node {
ExprPath(..) => {
let def_map = self.def_map.borrow();
match def_map.get().find(&e.id) {
match self.def_map.borrow().find(&e.id) {
Some(&DefStatic(def_id, _)) if
ast_util::is_local(def_id) => {
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)
let pat_matches_nan: |&Pat| -> bool = |p| {
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&p.id)
};
let opt_def = cx.tcx.def_map.borrow().find_copy(&p.id);
match opt_def {
Some(DefStatic(did, false)) => {
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 {
PatWild | PatWildMulti => { None }
PatIdent(_, _, _) | PatEnum(_, _) => {
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat.id)
};
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
match opt_def {
Some(DefVariant(_, id, _)) => Some(variant(id)),
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)))
}
PatStruct(..) => {
let def_map = cx.tcx.def_map.borrow();
match def_map.get().find(&pat.id) {
match cx.tcx.def_map.borrow().find(&pat.id) {
Some(&DefVariant(_, id, _)) => Some(variant(id)),
_ => Some(single)
}
@ -392,8 +385,7 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
match pat.node {
PatWild | PatWildMulti => { true }
PatIdent(_, _, _) => {
let def_map = cx.tcx.def_map.borrow();
match def_map.get().find(&pat.id) {
match cx.tcx.def_map.borrow().find(&pat.id) {
Some(&DefVariant(_, _, _)) | Some(&DefStatic(..)) => { false }
_ => { true }
}
@ -575,10 +567,7 @@ fn specialize(cx: &MatchCheckCtxt,
r.tail()))
}
PatIdent(_, _, _) => {
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat_id)
};
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id);
match opt_def {
Some(DefVariant(_, id, _)) => {
if variant(id) == *ctor_id {
@ -636,11 +625,8 @@ fn specialize(cx: &MatchCheckCtxt,
}
}
PatEnum(_, args) => {
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().get_copy(&pat_id)
};
match opt_def {
let def = cx.tcx.def_map.borrow().get_copy(&pat_id);
match def {
DefStatic(did, _) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).unwrap();
@ -701,11 +687,8 @@ fn specialize(cx: &MatchCheckCtxt,
}
PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant?
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().get_copy(&pat_id)
};
match opt_def {
let def = cx.tcx.def_map.borrow().get_copy(&pat_id);
match def {
DefVariant(_, variant_id, _) => {
if variant(variant_id) == *ctor_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 {
let opt_def = {
let def_map = cx.tcx.def_map.borrow();
def_map.get().find_copy(&pat.id)
};
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
match opt_def {
Some(DefVariant(enum_id, _, _)) => {
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> {
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&e.id)
};
let opt_def = tcx.def_map.borrow().find_copy(&e.id);
match opt_def {
Some(ast::DefStatic(def_id, false)) => {
lookup_const_by_id(tcx, def_id)
@ -125,7 +122,7 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
}
}
} else {
match tcx.extern_const_variants.borrow().get().find(&variant_def) {
match tcx.extern_const_variants.borrow().find(&variant_def) {
Some(&e) => return e,
None => {}
}
@ -145,7 +142,7 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
},
_ => None
};
tcx.extern_const_variants.borrow_mut().get().insert(variant_def, e);
tcx.extern_const_variants.borrow_mut().insert(variant_def, e);
return e;
}
}
@ -166,12 +163,9 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
}
}
} else {
{
let extern_const_statics = tcx.extern_const_statics.borrow();
match extern_const_statics.get().find(&def_id) {
Some(&e) => return e,
None => {}
}
match tcx.extern_const_statics.borrow().find(&def_id) {
Some(&e) => return e,
None => {}
}
let maps = astencode::Maps {
root_map: @RefCell::new(HashMap::new()),
@ -187,12 +181,8 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
},
_ => None
};
{
let mut extern_const_statics = tcx.extern_const_statics
.borrow_mut();
extern_const_statics.get().insert(def_id, e);
return e;
}
tcx.extern_const_statics.borrow_mut().insert(def_id, e);
return e;
}
}

View file

@ -782,8 +782,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
}
Some(_) => {
let def_map = self.tcx().def_map.borrow();
match def_map.get().find(&expr.id) {
match self.tcx().def_map.borrow().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => {
match loop_scopes.iter().position(|l| l.loop_id == loop_id) {
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 {
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]) {

View file

@ -75,8 +75,7 @@ impl<'a> MarkSymbolVisitor<'a> {
}
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
let def_map = self.tcx.def_map.borrow();
let def = match def_map.get().find(id) {
let def = match self.tcx.def_map.borrow().find(id) {
Some(&def) => def,
None => return
};
@ -94,7 +93,7 @@ impl<'a> MarkSymbolVisitor<'a> {
fn lookup_and_handle_method(&mut self, id: ast::NodeId,
span: codemap::Span) {
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) => {
match method.origin {
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
// called directly.
let def_id = local_def(id);
let inherent_impls = self.tcx.inherent_impls.borrow();
match inherent_impls.get().find(&def_id) {
match self.tcx.inherent_impls.borrow().find(&def_id) {
None => (),
Some(ref impl_list) => {
let impl_list = impl_list.borrow();
for impl_ in impl_list.get().iter() {
for impl_ in impl_list.borrow().iter() {
for method in impl_.methods.iter() {
if self.live_symbols.contains(&method.def_id.node) {
return true;

View file

@ -56,8 +56,7 @@ impl<'a> EffectCheckVisitor<'a> {
UnsafeBlock(block_id) => {
// OK, but record this.
debug!("effect: recording unsafe block as used: {:?}", block_id);
let mut used_unsafe = self.tcx.used_unsafe.borrow_mut();
let _ = used_unsafe.get().insert(block_id);
self.tcx.used_unsafe.borrow_mut().insert(block_id);
}
UnsafeFn => {}
}
@ -139,7 +138,7 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> {
match expr.node {
ast::ExprMethodCall(_, _, _) => {
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 {}",
ppaux::ty_to_str(self.tcx, base_type));
if type_is_unsafe_function(base_type) {

View file

@ -51,8 +51,7 @@ impl Visitor<int> for CollectFreevarsVisitor {
}
ast::ExprPath(..) => {
let mut i = 0;
let def_map = self.def_map.borrow();
match def_map.get().find(&expr.id) {
match self.def_map.borrow().find(&expr.id) {
None => fail!("path not found"),
Some(&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 {
let freevars = tcx.freevars.borrow();
match freevars.get().find(&fid) {
match tcx.freevars.borrow().find(&fid) {
None => fail!("get_freevars: {} has no freevars", fid),
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) {
let def_map = cx.tcx.def_map.borrow();
let ast_trait_def = def_map.get()
.find(&trait_ref.ref_id)
.expect("trait ref not in def map!");
let trait_def_id = ast_util::def_id_of_def(*ast_trait_def);
let trait_def;
{
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!");
}
let ast_trait_def = *cx.tcx.def_map.borrow()
.find(&trait_ref.ref_id)
.expect("trait ref not in def map!");
let trait_def_id = ast_util::def_id_of_def(ast_trait_def);
let trait_def = *cx.tcx.trait_defs.borrow()
.find(&trait_def_id)
.expect("trait def not in trait-defs map!");
// If this trait has builtin-kind supertraits, meet them.
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 {
TyPath(_, ref bounds, path_node_id) => {
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);
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
{
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 r = match method {
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() {
let def_map = cx.tcx.def_map.borrow();
let type_param_defs = match e.node {
ExprPath(_) => {
let did = ast_util::def_id_of_def(def_map.get()
.get_copy(&e.id));
let did = ast_util::def_id_of_def(def_map.get_copy(&e.id));
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.
let adjustments = cx.tcx.adjustments.borrow();
match adjustments.get().find(&e.id) {
match cx.tcx.adjustments.borrow().find(&e.id) {
Some(adjustment) => {
match **adjustment {
ty::AutoObject(..) => {
let source_ty = ty::expr_ty(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);
}
ty::AutoAddEnv(..) |
@ -368,10 +361,10 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node {
TyPath(_, _, id) => {
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() {
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 type_param_defs = generics.type_param_defs();
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) {
match ty.node {
ast::TyPath(_, _, id) => {
let def_map = cx.tcx.def_map.borrow();
match def_map.get().get_copy(&id) {
match cx.tcx.def_map.borrow().get_copy(&id) {
ast::DefPrimTy(ast::TyInt(ast::TyI)) => {
cx.span_lint(CTypes, ty.span,
"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) {
// Lint for constants that look like binding identifiers (#7526)
let def_map = cx.tcx.def_map.borrow();
match (&p.node, def_map.get().find(&p.id)) {
match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) {
(&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
// last identifier alone is right choice for this lint.
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) {
let def_map = cx.tcx.def_map.borrow();
match &p.node {
&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::DefArg(_, _)) => {
// 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 {
// Don't warn about generated blocks, that'll just pollute the output.
ast::ExprBlock(ref blk) => {
let used_unsafe = cx.tcx.used_unsafe.borrow();
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,
"unnecessary `unsafe` block");
}
@ -1315,8 +1311,8 @@ fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) {
of exactly one segment")
};
let used_mut_nodes = cx.tcx.used_mut_nodes.borrow();
if !initial_underscore && !used_mut_nodes.get().contains(&p.id) {
if !initial_underscore &&
!cx.tcx.used_mut_nodes.borrow().contains(&p.id) {
cx.span_lint(UnusedMut, p.span,
"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);
};
let adjustment = {
let adjustments = cx.tcx.adjustments.borrow();
adjustments.get().find_copy(&e.id)
};
match adjustment {
match cx.tcx.adjustments.borrow().find_copy(&e.id) {
Some(adjustment) => {
match *adjustment {
ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. }) => {
@ -1439,13 +1431,7 @@ fn check_missing_doc_method(cx: &Context, m: &ast::Method) {
node: m.id
};
let method_opt;
{
let methods = cx.tcx.methods.borrow();
method_opt = methods.get().find(&did).map(|method| *method);
}
match method_opt {
match cx.tcx.methods.borrow().find(&did).map(|method| *method) {
None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"),
Some(md) => {
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) {
let id = match e.node {
ast::ExprPath(..) | ast::ExprStruct(..) => {
let def_map = cx.tcx.def_map.borrow();
match def_map.get().find(&e.id) {
match cx.tcx.def_map.borrow().find(&e.id) {
Some(&def) => ast_util::def_id_of_def(def),
None => return
}
}
ast::ExprMethodCall(..) => {
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) => {
match method.origin {
typeck::MethodStatic(def_id) => {
@ -1736,8 +1721,7 @@ impl<'a> Visitor<()> for Context<'a> {
impl<'a> IdVisitingOperation for Context<'a> {
fn visit_id(&self, id: ast::NodeId) {
let mut lints = self.tcx.sess.lints.borrow_mut();
match lints.get().pop(&id) {
match self.tcx.sess.lints.borrow_mut().pop(&id) {
None => {}
Some(l) => {
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
// in the iteration code.
let lints = tcx.sess.lints.borrow();
for (id, v) in lints.get().iter() {
for (id, v) in tcx.sess.lints.borrow().iter() {
for &(lint, span, ref msg) in v.iter() {
tcx.sess.span_bug(span, format!("unprocessed lint {:?} at {}: {}",
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 {
// live nodes required for uses or definitions of variables:
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);
if moves::moved_variable_node_id_from_def(def).is_some() {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -707,7 +707,7 @@ impl<'a> Liveness<'a> {
Some(_) => {
// Refers to a labeled loop. Use the results of resolve
// 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,
_ => self.ir.tcx.sess.span_bug(sp, "label on break/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)
-> 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) {
Some(nid) => {
let ln = self.live_node(expr.id, expr.span);
@ -1490,7 +1490,7 @@ impl<'a> Liveness<'a> {
fn check_lvalue(&mut self, expr: &Expr) {
match expr.node {
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, _) => {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually

View file

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

View file

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

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 {
match pat.node {
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
let dm = dm.borrow();
match dm.get().find(&pat.id) {
match dm.borrow().find(&pat.id) {
Some(&DefVariant(..)) | Some(&DefStruct(..)) => true,
_ => 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 {
match pat.node {
PatIdent(_, _, None) | PatEnum(..) => {
let dm = dm.borrow();
match dm.get().find(&pat.id) {
match dm.borrow().find(&pat.id) {
Some(&DefStatic(_, false)) => true,
_ => false
}

View file

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

View file

@ -100,7 +100,7 @@ impl<'a> Visitor<()> for ReachableContext<'a> {
match expr.node {
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,
None => {
self.tcx.sess.span_bug(expr.span,
@ -133,7 +133,7 @@ impl<'a> Visitor<()> for ReachableContext<'a> {
}
ast::ExprMethodCall(..) => {
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) => {
if is_local(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*
// reachability, which might result in a compile time loss.
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 {
self.reachable_symbols.insert(destructor_def_id.node);
}

View file

@ -100,8 +100,7 @@ struct RegionResolutionVisitor<'a> {
impl RegionMaps {
pub fn relate_free_regions(&self, sub: FreeRegion, sup: FreeRegion) {
let mut free_region_map = self.free_region_map.borrow_mut();
match free_region_map.get().find_mut(&sub) {
match self.free_region_map.borrow_mut().find_mut(&sub) {
Some(sups) => {
if !sups.iter().any(|x| x == &sup) {
sups.push(sup);
@ -112,32 +111,25 @@ impl RegionMaps {
}
debug!("relate_free_regions(sub={:?}, sup={:?})", sub, sup);
free_region_map.get().insert(sub, vec!(sup));
self.free_region_map.borrow_mut().insert(sub, vec!(sup));
}
pub fn record_encl_scope(&self, sub: ast::NodeId, sup: ast::NodeId) {
debug!("record_encl_scope(sub={}, sup={})", sub, sup);
assert!(sub != sup);
let mut scope_map = self.scope_map.borrow_mut();
scope_map.get().insert(sub, sup);
self.scope_map.borrow_mut().insert(sub, sup);
}
pub fn record_var_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) {
debug!("record_var_scope(sub={}, sup={})", var, lifetime);
assert!(var != lifetime);
let mut var_map = self.var_map.borrow_mut();
var_map.get().insert(var, lifetime);
self.var_map.borrow_mut().insert(var, lifetime);
}
pub fn record_rvalue_scope(&self, var: ast::NodeId, lifetime: ast::NodeId) {
debug!("record_rvalue_scope(sub={}, sup={})", var, lifetime);
assert!(var != lifetime);
let mut rvalue_scopes = self.rvalue_scopes.borrow_mut();
rvalue_scopes.get().insert(var, lifetime);
self.rvalue_scopes.borrow_mut().insert(var, lifetime);
}
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);
let mut terminating_scopes = self.terminating_scopes.borrow_mut();
terminating_scopes.get().insert(scope_id);
self.terminating_scopes.borrow_mut().insert(scope_id);
}
pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
//! Returns the narrowest scope that encloses `id`, if any.
let scope_map = self.scope_map.borrow();
scope_map.get().find(&id).map(|x| *x)
self.scope_map.borrow().find(&id).map(|x| *x)
}
pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId {
//! Returns the narrowest scope that encloses `id`, if any.
let scope_map = self.scope_map.borrow();
match scope_map.get().find(&id) {
match self.scope_map.borrow().find(&id) {
Some(&r) => r,
None => { fail!("no enclosing scope for id {}", id); }
}
@ -174,9 +161,7 @@ impl RegionMaps {
/*!
* Returns the lifetime of the local variable `var_id`
*/
let var_map = self.var_map.borrow();
match var_map.get().find(&var_id) {
match self.var_map.borrow().find(&var_id) {
Some(&r) => r,
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
// check for a designated rvalue scope
let rvalue_scopes = self.rvalue_scopes.borrow();
match rvalue_scopes.get().find(&expr_id) {
match self.rvalue_scopes.borrow().find(&expr_id) {
Some(&s) => {
debug!("temporary_scope({}) = {} [custom]", expr_id, s);
return Some(s);
@ -204,8 +188,7 @@ impl RegionMaps {
None => { return None; }
};
let terminating_scopes = self.terminating_scopes.borrow();
while !terminating_scopes.get().contains(&id) {
while !self.terminating_scopes.borrow().contains(&id) {
match self.opt_encl_scope(id) {
Some(p) => {
id = p;
@ -249,8 +232,7 @@ impl RegionMaps {
let mut s = subscope;
while superscope != s {
let scope_map = self.scope_map.borrow();
match scope_map.get().find(&s) {
match self.scope_map.borrow().find(&s) {
None => {
debug!("is_subscope_of({}, {}, s={})=false",
subscope, superscope, s);
@ -286,8 +268,7 @@ impl RegionMaps {
let mut queue = vec!(sub);
let mut i = 0;
while i < queue.len() {
let free_region_map = self.free_region_map.borrow();
match free_region_map.get().find(queue.get(i)) {
match self.free_region_map.borrow().find(queue.get(i)) {
Some(parents) => {
for parent in parents.iter() {
if *parent == sup {
@ -391,8 +372,7 @@ impl RegionMaps {
let mut result = vec!(scope);
let mut scope = scope;
loop {
let scope_map = this.scope_map.borrow();
match scope_map.get().find(&scope) {
match this.scope_map.borrow().find(&scope) {
None => return result,
Some(&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 {
let ccx = bcx.ccx();
let def_map = ccx.tcx.def_map.borrow();
match def_map.get().get_copy(&pat_id) {
let def = ccx.tcx.def_map.borrow().get_copy(&pat_id);
match def {
ast::DefVariant(enum_id, var_id, _) => {
let variants = ty::enum_variants(ccx.tcx(), enum_id);
for v in (*variants).iter() {
@ -636,10 +636,7 @@ fn enter_opt<'r,'b>(
let answer = match p.node {
ast::PatEnum(..) |
ast::PatIdent(_, _, None) if pat_is_const(tcx.def_map, p) => {
let const_def = {
let def_map = tcx.def_map.borrow();
def_map.get().get_copy(&p.id)
};
let const_def = tcx.def_map.borrow().get_copy(&p.id);
let const_def_id = ast_util::def_id_of_def(const_def);
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
Some(Vec::new())
@ -678,11 +675,7 @@ fn enter_opt<'r,'b>(
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
// Look up the struct variant ID.
let struct_id;
let defn = {
let def_map = tcx.def_map.borrow();
def_map.get().get_copy(&p.id)
};
match defn {
match tcx.def_map.borrow().get_copy(&p.id) {
ast::DefVariant(_, 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(..) => {
// This is one of: an enum variant, a unit-like struct, or a
// variable binding.
let opt_def = {
let def_map = ccx.tcx.def_map.borrow();
def_map.get().find_copy(&cur.id)
};
let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
match opt_def {
Some(ast::DefVariant(..)) => {
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(..) => {
// This could be one of: a tuple-like enum variant, a
// struct-like enum variant, or a struct.
let opt_def = {
let def_map = ccx.tcx.def_map.borrow();
def_map.get().find_copy(&cur.id)
};
let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
match opt_def {
Some(ast::DefFn(..)) |
Some(ast::DefVariant(..)) => {
@ -1147,8 +1134,7 @@ fn pats_require_rooting(bcx: &Block, m: &[Match], col: uint) -> bool {
m.iter().any(|br| {
let pat_id = br.pats.get(col).id;
let key = root_map_key {id: pat_id, derefs: 0u };
let root_map = bcx.ccx().maps.root_map.borrow();
root_map.get().contains_key(&key)
bcx.ccx().maps.root_map.borrow().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);
match pat.node {
ast::PatEnum(_, Some(_)) => {
let def_map = bcx.tcx().def_map.borrow();
match def_map.get().find(&pat.id) {
match bcx.tcx().def_map.borrow().find(&pat.id) {
Some(&ast::DefFn(..)) |
Some(&ast::DefStruct(..)) => true,
_ => false
@ -1387,13 +1372,10 @@ fn insert_lllocals<'a>(bcx: &'a Block<'a>,
let datum = Datum(llval, binding_info.ty, Lvalue);
fcx.schedule_drop_mem(cleanup_scope, llval, binding_info.ty);
{
debug!("binding {:?} to {}",
binding_info.id,
bcx.val_to_str(llval));
let mut llmap = bcx.fcx.lllocals.borrow_mut();
llmap.get().insert(binding_info.id, datum);
}
debug!("binding {:?} to {}",
binding_info.id,
bcx.val_to_str(llval));
bcx.fcx.lllocals.borrow_mut().insert(binding_info.id, datum);
if bcx.sess().opts.debuginfo == FullDebugInfo {
debuginfo::create_match_binding_metadata(bcx,
@ -1458,8 +1440,7 @@ fn compile_guard<'r,
}
TrByRef => {}
}
let mut lllocals = bcx.fcx.lllocals.borrow_mut();
lllocals.get().remove(&binding_info.id);
bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
}
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
// we emit extra-debug-info, which requires local allocas :(.
let arg_val = arg.add_clean(bcx.fcx, arg_scope);
let mut llmap = bcx.fcx.llargs.borrow_mut();
llmap.get().insert(pat.id, Datum(arg_val, arg_ty, Lvalue));
bcx.fcx.llargs.borrow_mut()
.insert(pat.id, Datum(arg_val, arg_ty, Lvalue));
bcx
} else {
mk_binding_alloca(
@ -2143,7 +2124,7 @@ fn mk_binding_alloca<'a,A>(bcx: &'a Block<'a>,
BindLocal => bcx.fcx.lllocals.borrow_mut(),
BindArgument => bcx.fcx.llargs.borrow_mut()
};
llmap.get().insert(p_id, datum);
llmap.insert(p_id, datum);
bcx
}
@ -2219,9 +2200,9 @@ fn bind_irrefutable_pat<'a>(
}
}
ast::PatEnum(_, ref sub_pats) => {
let def_map = bcx.tcx().def_map.borrow();
match def_map.get().find(&pat.id) {
Some(&ast::DefVariant(enum_id, var_id, _)) => {
let opt_def = bcx.tcx().def_map.borrow().find_copy(&pat.id);
match opt_def {
Some(ast::DefVariant(enum_id, var_id, _)) => {
let repr = adt::represent_node(bcx, pat.id);
let vinfo = ty::enum_variant_with_id(ccx.tcx(),
enum_id,
@ -2238,8 +2219,8 @@ fn bind_irrefutable_pat<'a>(
}
}
}
Some(&ast::DefFn(..)) |
Some(&ast::DefStruct(..)) => {
Some(ast::DefFn(..)) |
Some(ast::DefStruct(..)) => {
match *sub_pats {
None => {
// 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.

View file

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

View file

@ -161,12 +161,9 @@ impl<'a> Drop for StatRecorder<'a> {
let end = time::precise_time_ns();
let elapsed = ((end - self.start) / 1_000_000) as uint;
let iend = self.ccx.stats.n_llvm_insns.get();
{
let mut fn_stats = self.ccx.stats.fn_stats.borrow_mut();
fn_stats.get().push((self.name.take_unwrap(),
elapsed,
iend - self.istart));
}
self.ccx.stats.fn_stats.borrow_mut().push((self.name.take_unwrap(),
elapsed,
iend - self.istart));
self.ccx.stats.n_fns.set(self.ccx.stats.n_fns.get() + 1);
// Reset LLVM insn count to avoid compound costs.
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,
name: &str, did: ast::DefId) -> ValueRef {
{
let externs = ccx.externs.borrow();
match externs.get().find_equiv(&name) {
Some(n) => return *n,
None => ()
}
match ccx.externs.borrow().find_equiv(&name) {
Some(n) => return *n,
None => ()
}
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)
});
let mut externs = ccx.externs.borrow_mut();
externs.get().insert(name.to_owned(), f);
ccx.externs.borrow_mut().insert(name.to_owned(), 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 {
{
let tydescs = ccx.tydescs.borrow();
match tydescs.get().find(&t) {
Some(&inf) => return inf,
_ => { }
}
match ccx.tydescs.borrow().find(&t) {
Some(&inf) => return inf,
_ => { }
}
ccx.stats.n_static_tydescs.set(ccx.stats.n_static_tydescs.get() + 1u);
let inf = glue::declare_tydesc(ccx, t);
let mut tydescs = ccx.tydescs.borrow_mut();
tydescs.get().insert(t, inf);
ccx.tydescs.borrow_mut().insert(t, 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
// silently mangles such symbols, breaking our linkage model.
pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {
let mut all_llvm_symbols = ccx.all_llvm_symbols.borrow_mut();
if all_llvm_symbols.get().contains(&sym) {
if ccx.all_llvm_symbols.borrow().contains(&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);
let llty = type_of_dtor(ccx, class_ty);
{
let mut externs = ccx.externs.borrow_mut();
get_extern_fn(externs.get(), ccx.llmod, name,
lib::llvm::CCallConv, llty, ty::mk_nil())
}
get_extern_fn(&mut *ccx.externs.borrow_mut(), 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 cconv = c.unwrap_or(lib::llvm::CCallConv);
let llty = type_of_fn_from_ty(ccx, t);
let mut externs = ccx.externs.borrow_mut();
get_extern_fn(externs.get(), ccx.llmod, name,
cconv, llty, fn_ty.sig.output)
get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod,
name, 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 mut externs = ccx.externs.borrow_mut();
get_extern_const(externs.get(), ccx.llmod, name, llty)
get_extern_const(&mut *ccx.externs.borrow_mut(), ccx.llmod, name,
llty)
}
}
}
@ -1709,8 +1693,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
static");
}
let const_values = ccx.const_values.borrow();
let v = const_values.get().get_copy(&item.id);
let v = ccx.const_values.borrow().get_copy(&item.id);
unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
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,
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) {
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 {
debug!("get_item_val(id=`{:?}`)", id);
let val = {
let item_vals = ccx.item_vals.borrow();
item_vals.get().find_copy(&id)
};
match ccx.item_vals.borrow().find_copy(&id) {
Some(v) => return v,
None => {}
}
match val {
Some(v) => v,
None => {
let mut foreign = false;
let item = ccx.tcx.map.get(id);
let val = match item {
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 mut foreign = false;
let item = ccx.tcx.map.get(id);
let val = match item {
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 {
ast::ItemStatic(_, _, expr) => {
// If this static came from an external crate, then
// we need to get the symbol from csearch instead of
// using the current crate's name/version
// information in the hash of the symbol
debug!("making {}", sym);
let (sym, is_local) = {
let external_srcs = ccx.external_srcs
.borrow();
match external_srcs.get().find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
(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
let v = match i.node {
ast::ItemStatic(_, _, expr) => {
// If this static came from an external crate, then
// we need to get the symbol from csearch instead of
// using the current crate's name/version
// information in the hash of the symbol
debug!("making {}", sym);
let (sym, is_local) = {
match ccx.external_srcs.borrow().find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
(csearch::get_symbol(&ccx.sess().cstore,
did), false)
}
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
.as_slice(),
"link_section") {
Some(sect) => unsafe {
sect.get().with_c_str(|buf| {
llvm::LLVMSetSection(v, buf);
})
},
None => ()
}
// 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);
ccx.const_values.borrow_mut().insert(id, v);
let mut inlineable = inlineable;
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) => {
debug!("get_item_val(): processing a NodeTraitMethod");
match *trait_method {
ast::Required(_) => {
ccx.sess().bug("unexpected variant: required trait method in \
get_item_val()");
if !ccx.reachable.contains(&id) {
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
}
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) => {
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;
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);
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
}
ast_map::NodeStructCtor(struct_def) => {
// 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))
}
_ => fail!("get_item_val: weird result in table")
};
// 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);
match attr::first_attr_value_str_by_name(i.attrs.as_slice(),
"link_section") {
Some(sect) => unsafe {
sect.get().with_c_str(|buf| {
llvm::LLVMSetSection(v, buf);
})
},
None => ()
}
let mut item_vals = ccx.item_vals.borrow_mut();
item_vals.get().insert(id, val);
val
v
}
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,
@ -2542,11 +2506,10 @@ pub fn trans_crate(krate: ast::Crate,
println!("n_inlines: {}", ccx.stats.n_inlines.get());
println!("n_closures: {}", ccx.stats.n_closures.get());
println!("fn stats:");
let mut fn_stats = ccx.stats.fn_stats.borrow_mut();
fn_stats.get().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
ccx.stats.fn_stats.borrow_mut().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
insns_b.cmp(&insns_a)
});
for tuple in fn_stats.get().iter() {
for tuple in ccx.stats.fn_stats.borrow().iter() {
match *tuple {
(ref name, ms, insns) => {
println!("{} insns, {} ms, {}", insns, ms, *name);
@ -2555,8 +2518,7 @@ pub fn trans_crate(krate: ast::Crate,
}
}
if ccx.sess().count_llvm_insns() {
let llvm_insns = ccx.stats.llvm_insns.borrow();
for (k, v) in llvm_insns.get().iter() {
for (k, v) in ccx.stats.llvm_insns.borrow().iter() {
println!("{:7u} {}", *v, *k);
}
}
@ -2566,7 +2528,7 @@ pub fn trans_crate(krate: ast::Crate,
let llmod = ccx.llmod;
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();
// 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_str(category);
let n = match h.get().find(&s) {
let n = match h.find(&s) {
Some(&n) => n,
_ => 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 {
ExprId(id) => node_id_type(bcx, id),
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)
}
};
@ -482,7 +482,7 @@ pub fn trans_method_call<'a>(
let _icx = push_ctxt("trans_method_call");
debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx()));
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(
bcx,
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
*/
let scopes = self.scopes.borrow();
for scope in scopes.get().iter().rev() {
for scope in self.scopes.borrow().iter().rev() {
match scope.kind {
LoopScopeKind(id, _) => {
return id;
@ -316,8 +315,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
debug!("schedule_clean_in_ast_scope(cleanup_scope={:?})",
cleanup_scope);
let mut scopes = self.scopes.borrow_mut();
for scope in scopes.get().mut_iter().rev() {
for scope in self.scopes.borrow_mut().mut_iter().rev() {
if scope.kind.is_ast_with_id(cleanup_scope) {
scope.cleanups.push(cleanup);
scope.clear_cached_exits();
@ -347,7 +345,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
assert!(self.is_valid_custom_scope(custom_scope));
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.clear_cached_exits();
}
@ -358,8 +356,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
* execute on failure.
*/
let scopes = self.scopes.borrow();
scopes.get().iter().rev().any(|s| s.needs_invoke())
self.scopes.borrow().iter().rev().any(|s| s.needs_invoke())
}
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.
*/
let scopes = self.scopes.borrow();
for scope in scopes.get().iter().rev() {
for scope in self.scopes.borrow().iter().rev() {
match scope.kind {
CustomScopeKind | LoopScopeKind(..) => {}
AstScopeKind(i) => {
@ -418,20 +414,18 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
}
fn top_nonempty_cleanup_scope(&self) -> Option<uint> {
let scopes = self.scopes.borrow();
scopes.get().iter().rev().position(|s| !s.cleanups.is_empty())
self.scopes.borrow().iter().rev().position(|s| !s.cleanups.is_empty())
}
fn is_valid_to_pop_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool {
let scopes = self.scopes.borrow();
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 {
let scopes = self.scopes.borrow();
custom_scope.index < scopes.get().len() &&
scopes.get().get(custom_scope.index).kind.is_temp()
custom_scope.index < scopes.len() &&
scopes.get(custom_scope.index).kind.is_temp()
}
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 {
let scopes = self.scopes.borrow();
scopes.get().len()
self.scopes.borrow().len()
}
fn push_scope(&self, scope: CleanupScope<'a>) {
let mut scopes = self.scopes.borrow_mut();
scopes.get().push(scope);
self.scopes.borrow_mut().push(scope)
}
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.scopes_len() - 1);
let mut scopes = self.scopes.borrow_mut();
scopes.get().pop().unwrap()
self.scopes.borrow_mut().pop().unwrap()
}
fn top_scope<R>(&self, f: |&CleanupScope<'a>| -> R) -> R {
let scopes = self.scopes.borrow();
f(scopes.get().last().unwrap())
f(self.scopes.borrow().last().unwrap())
}
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.
{
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 {
Some(llbb) => { return llbb; }
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 mut llupvars = bcx.fcx.llupvars.borrow_mut();
llupvars.get().insert(def_id.node, upvarptr);
}
bcx.fcx.llupvars.borrow_mut().insert(def_id.node, upvarptr);
for &env_pointer_alloca in env_pointer_alloca.iter() {
debuginfo::create_captured_var_metadata(
@ -395,7 +392,7 @@ pub fn trans_expr_fn<'a>(
// set an inline hint for all closures
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} =
build_closure(bcx, cap_vars.deref().as_slice(), sigil);
trans_closure(ccx, decl, body, llfn,
@ -423,12 +420,9 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
}
};
{
let cache = ccx.closure_bare_wrapper_cache.borrow();
match cache.get().find(&fn_ptr) {
Some(&llval) => return llval,
None => {}
}
match ccx.closure_bare_wrapper_cache.borrow().find(&fn_ptr) {
Some(&llval) => return llval,
None => {}
}
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)
};
{
let mut cache = ccx.closure_bare_wrapper_cache.borrow_mut();
cache.get().insert(fn_ptr, llfn);
}
ccx.closure_bare_wrapper_cache.borrow_mut().insert(fn_ptr, llfn);
// This is only used by statics inlined from a different crate.
if !is_local {

View file

@ -465,8 +465,7 @@ impl<'a> Block<'a> {
}
pub fn def(&self, nid: ast::NodeId) -> ast::Def {
let def_map = self.tcx().def_map.borrow();
match def_map.get().find(&nid) {
match self.tcx().def_map.borrow().find(&nid) {
Some(&v) => v,
None => {
self.tcx().sess.bug(format!(
@ -584,12 +583,9 @@ pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef {
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
unsafe {
{
let const_cstr_cache = cx.const_cstr_cache.borrow();
match const_cstr_cache.get().find(&s) {
Some(&llval) => return llval,
None => ()
}
match cx.const_cstr_cache.borrow().find(&s) {
Some(&llval) => return llval,
None => ()
}
let sc = llvm::LLVMConstStringInContext(cx.llcx,
@ -605,8 +601,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
llvm::LLVMSetGlobalConstant(g, True);
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
let mut const_cstr_cache = cx.const_cstr_cache.borrow_mut();
const_cstr_cache.get().insert(s, g);
cx.const_cstr_cache.borrow_mut().insert(s, 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 {
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)
}
@ -814,7 +809,7 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec<ty::t> {
let params = match node {
ExprId(id) => ty::node_id_to_type_params(tcx, id),
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)
-> Option<typeck::vtable_res> {
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))
}

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 {
unsafe {
let b = llvm::LLVMConstPointerCast(a, t.ptr_to().to_ref());
let mut const_globals = cx.const_globals.borrow_mut();
assert!(const_globals.get().insert(b as int, a));
assert!(cx.const_globals.borrow_mut().insert(b as int, a));
b
}
}
@ -118,8 +117,7 @@ fn const_addr_of(cx: &CrateContext, cv: ValueRef) -> ValueRef {
}
fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
let const_globals = cx.const_globals.borrow();
let v = match const_globals.get().find(&(v as int)) {
let v = match cx.const_globals.borrow().find(&(v as int)) {
Some(&v) => 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,
mut def_id: ast::DefId) -> (ValueRef, bool) {
let contains_key = {
let const_values = cx.const_values.borrow();
const_values.get().contains_key(&def_id.node)
};
let contains_key = cx.const_values.borrow().contains_key(&def_id.node);
if !ast_util::is_local(def_id) || !contains_key {
if !ast_util::is_local(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();
let non_inlineable_statics = cx.non_inlineable_statics.borrow();
(const_values.get().get_copy(&def_id.node),
!non_inlineable_statics.get().contains(&def_id.node))
(cx.const_values.borrow().get_copy(&def_id.node),
!cx.non_inlineable_statics.borrow().contains(&def_id.node))
}
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 ety = ty::expr_ty(cx.tcx(), e);
let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e,
cx.maps.method_map.borrow().get());
let adjustment = {
let adjustments = cx.tcx.adjustments.borrow();
adjustments.get().find_copy(&e.id)
};
match adjustment {
&*cx.maps.method_map.borrow());
let opt_adj = cx.tcx.adjustments.borrow().find_copy(&e.id);
match opt_adj {
None => { }
Some(adj) => {
match *adj {
@ -424,7 +414,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
}
ast::ExprField(base, field, _) => {
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 (bv, inlineable) = const_expr(cx, base, is_local);
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) => {
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 iv = match const_eval::eval_const_expr(cx.tcx(), index) {
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!(pth.segments.iter().all(|seg| seg.types.is_empty()));
let tcx = cx.tcx();
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&e.id)
};
let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
match opt_def {
Some(ast::DefFn(def_id, _purity)) => {
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) => {
let tcx = cx.tcx();
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&callee.id)
};
let opt_def = cx.tcx().def_map.borrow().find_copy(&callee.id);
match opt_def {
Some(ast::DefStruct(_)) => {
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);
// At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type.
let const_values = ccx.const_values.borrow();
let v = const_values.get().get_copy(&id);
let v = ccx.const_values.borrow().get_copy(&id);
llvm::LLVMSetInitializer(g, v);
if m != ast::MutMutable {
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 {
None => fcx.top_loop_scope(),
Some(_) => {
let def_map = bcx.tcx().def_map.borrow();
match def_map.get().find(&expr_id) {
match bcx.tcx().def_map.borrow().find(&expr_id) {
Some(&ast::DefLabel(loop_id)) => loop_id,
ref 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| {
let var_ident = ast_util::path_to_ident(path_ref);
let datum = {
let lllocals = bcx.fcx.lllocals.borrow();
match lllocals.get().find_copy(&node_id) {
Some(datum) => datum,
None => {
bcx.sess().span_bug(span,
format!("no entry in lllocals table for {:?}",
node_id));
}
let datum = match bcx.fcx.lllocals.borrow().find_copy(&node_id) {
Some(datum) => datum,
None => {
bcx.sess().span_bug(span,
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;
pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| {
let llarg = {
let llargs = bcx.fcx.llargs.borrow();
match llargs.get().find_copy(&node_id) {
Some(v) => v,
None => {
bcx.sess().span_bug(span,
format!("no entry in llargs table for {:?}",
node_id));
}
let llarg = match bcx.fcx.llargs.borrow().find_copy(&node_id) {
Some(v) => v,
None => {
bcx.sess().span_bug(span,
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 mut scope_map = fn_debug_context.scope_map.borrow_mut();
populate_scope_map(cx,
arg_pats.as_slice(),
top_level_block,
fn_metadata,
scope_map.get());
}
populate_scope_map(cx,
arg_pats.as_slice(),
top_level_block,
fn_metadata,
&mut *fn_debug_context.scope_map.borrow_mut());
// Clear the debug location so we don't assign them in the function prelude
set_debug_location(cx, UnknownLocation);
@ -1014,12 +1005,9 @@ fn declare_local(bcx: &Block,
}
fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
{
let created_files = debug_context(cx).created_files.borrow();
match created_files.get().find_equiv(&full_path) {
Some(file_metadata) => return *file_metadata,
None => ()
}
match debug_context(cx).created_files.borrow().find_equiv(&full_path) {
Some(file_metadata) => return *file_metadata,
None => ()
}
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();
created_files.get().insert(full_path.to_owned(), file_metadata);
created_files.insert(full_path.to_owned(), file_metadata);
return file_metadata;
}
@ -1053,9 +1041,7 @@ fn scope_metadata(fcx: &FunctionContext,
span: Span)
-> DIScope {
let scope_map = &fcx.debug_context.get_ref(fcx.ccx, span).scope_map;
let scope_map = scope_map.borrow();
match scope_map.get().find_copy(&node_id) {
match scope_map.borrow().find_copy(&node_id) {
Some(scope_metadata) => scope_metadata,
None => {
let node = fcx.ccx.tcx.map.get(node_id);
@ -1243,10 +1229,8 @@ impl RecursiveTypeDescription {
ref member_description_factory
} => {
// Insert the stub into the cache in order to allow recursive references ...
{
let mut created_types = debug_context(cx).created_types.borrow_mut();
created_types.get().insert(cache_id, metadata_stub);
}
debug_context(cx).created_types.borrow_mut()
.insert(cache_id, metadata_stub);
// ... then create the member descriptions ...
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 =
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() - \
Already completed forward declaration \
re-encountered.");
} 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 {
let cache_id = cache_id_for_type(t);
{
let created_types = debug_context(cx).created_types.borrow();
match created_types.get().find(&cache_id) {
Some(type_metadata) => return *type_metadata,
None => ()
}
match debug_context(cx).created_types.borrow().find(&cache_id) {
Some(type_metadata) => return *type_metadata,
None => ()
}
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))
};
let mut created_types = debug_context(cx).created_types.borrow_mut();
created_types.get().insert(cache_id, type_metadata);
debug_context(cx).created_types.borrow_mut().insert(cache_id, 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) {
let node_types = cx.tcx.node_types.borrow();
if !node_types.get().contains_key(&(node_id as uint)) {
if !cx.tcx.node_types.borrow().contains_key(&(node_id as uint)) {
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();
current_key.push(name);
let existing_node = {
let namespace_map = debug_context(cx).namespace_map.borrow();
namespace_map.get().find_copy(&current_key)
};
let existing_node = debug_context(cx).namespace_map.borrow()
.find_copy(&current_key);
let current_node = match existing_node {
Some(existing_node) => existing_node,
None => {
@ -2813,11 +2790,8 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> @NamespaceTreeNo
parent: parent_node,
};
{
let mut namespace_map = debug_context(cx).namespace_map
.borrow_mut();
namespace_map.get().insert(current_key.clone(), node);
}
debug_context(cx).namespace_map.borrow_mut()
.insert(current_key.clone(), node);
node
}

View file

@ -106,12 +106,7 @@ pub fn trans_into<'a>(bcx: &'a Block<'a>,
let mut bcx = bcx;
let is_adjusted = {
let adjustments = bcx.tcx().adjustments.borrow();
adjustments.get().contains_key(&expr.id)
};
if is_adjusted {
if bcx.tcx().adjustments.borrow().contains_key(&expr.id) {
// use trans, which may be less efficient but
// which will perform the adjustments:
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 datum = datum;
let adjustment = {
let adjustments = bcx.tcx().adjustments.borrow();
match adjustments.get().find_copy(&expr.id) {
None => {
return DatumBlock(bcx, datum);
}
Some(adj) => { adj }
let adjustment = match bcx.tcx().adjustments.borrow().find_copy(&expr.id) {
None => {
return DatumBlock(bcx, datum);
}
Some(adj) => { adj }
};
debug!("unadjusted datum for expr {}: {}",
expr.id, datum.to_str(bcx.ccx()));
@ -210,7 +202,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
Some(AutoBorrowFn(..)) => {
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span, expr.id, datum.ty,
Some(adjustment), |method_call| {
bcx.ccx().maps.method_map.borrow().get()
bcx.ccx().maps.method_map.borrow()
.find(&method_call).map(|method| method.ty)
});
unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum))
@ -222,7 +214,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
}
AutoObject(..) => {
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");
bcx = meth::trans_trait_cast(
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();
PointerCast(bcx, val, pty)
} else {
{
let extern_const_values = bcx.ccx().extern_const_values.borrow();
match extern_const_values.get().find(&did) {
None => {} // Continue.
Some(llval) => {
return *llval;
}
match bcx.ccx().extern_const_values.borrow().find(&did) {
None => {} // Continue.
Some(llval) => {
return *llval;
}
}
@ -587,8 +576,8 @@ fn trans_def<'a>(bcx: &'a Block<'a>,
llty.to_ref(),
buf)
});
let mut extern_const_values = bcx.ccx().extern_const_values.borrow_mut();
extern_const_values.get().insert(did, llval);
bcx.ccx().extern_const_values.borrow_mut()
.insert(did, llval);
llval
}
}
@ -898,8 +887,7 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
ast::DefUpvar(nid, _, _, _) => {
// Can't move upvars, so this is never a ZeroMemLastUse.
let local_ty = node_id_type(bcx, nid);
let llupvars = bcx.fcx.llupvars.borrow();
match llupvars.get().find(&nid) {
match bcx.fcx.llupvars.borrow().find(&nid) {
Some(&val) => Datum(val, local_ty, Lvalue),
None => {
bcx.sess().bug(format!(
@ -908,12 +896,10 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
}
}
ast::DefArg(nid, _) => {
let llargs = bcx.fcx.llargs.borrow();
take_local(bcx, llargs.get(), nid)
take_local(bcx, &*bcx.fcx.llargs.borrow(), nid)
}
ast::DefLocal(nid, _) | ast::DefBinding(nid, _) => {
let lllocals = bcx.fcx.lllocals.borrow();
take_local(bcx, lllocals.get(), nid)
take_local(bcx, &*bcx.fcx.lllocals.borrow(), nid)
}
_ => {
bcx.sess().unimpl(format!(
@ -965,11 +951,8 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
ty.repr(tcx)));
}
Some(node_id) => {
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().get_copy(&node_id)
};
match opt_def {
let def = tcx.def_map.borrow().get_copy(&node_id);
match def {
ast::DefVariant(enum_id, variant_id, _) => {
let variant_info = ty::enum_variant_with_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.
assert!(
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);
@ -1436,7 +1419,7 @@ fn trans_binary<'a>(bcx: &'a Block<'a>,
let ccx = bcx.ccx();
// 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 {
ast::BiAnd => {
@ -1476,7 +1459,7 @@ fn trans_overloaded_op<'a, 'b>(
rhs: Option<(Datum<Expr>, ast::NodeId)>,
dest: Option<Dest>)
-> 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,
Some(expr_info(expr)),
monomorphize_type(bcx, method_ty),
@ -1644,7 +1627,7 @@ fn trans_assign_op<'a>(
debug!("trans_assign_op(expr={})", bcx.expr_to_str(expr));
// 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
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,
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);
let datum = match 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
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
let llfn;
{
let mut externs = ccx.externs.borrow_mut();
llfn = base::get_extern_fn(externs.get(),
let llfn = base::get_extern_fn(&mut *ccx.externs.borrow_mut(),
ccx.llmod,
lname.get(),
cc,
llfn_ty,
tys.fn_sig.output);
};
add_argument_attributes(&tys, llfn);
llfn
@ -470,8 +466,8 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
}
let lname = link_name(foreign_item);
let mut item_symbols = ccx.item_symbols.borrow_mut();
item_symbols.get().insert(foreign_item.id, lname.get().to_owned());
ccx.item_symbols.borrow_mut().insert(foreign_item.id,
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 {
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,
_ => { }
}
@ -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 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");
@ -476,8 +476,7 @@ pub fn emit_tydescs(ccx: &CrateContext) {
// As of this point, allow no more tydescs to be created.
ccx.finished_tydescs.set(true);
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
let mut tyds = ccx.tydescs.borrow_mut();
for (_, &val) in tyds.get().iter() {
for (_, &val) in ccx.tydescs.borrow().iter() {
let ti = val;
// 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)
-> ast::DefId {
let _icx = push_ctxt("maybe_instantiate_inline");
{
let external = ccx.external.borrow();
match external.get().find(&fn_id) {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx(), fn_id), node_id);
return local_def(node_id);
}
Some(&None) => {
return fn_id; // Not inlinable
}
None => {
// Not seen yet
}
match ccx.external.borrow().find(&fn_id) {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx(), fn_id), node_id);
return local_def(node_id);
}
Some(&None) => {
return fn_id; // Not inlinable
}
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));
return match csearch_result {
csearch::not_found => {
let mut external = ccx.external.borrow_mut();
external.get().insert(fn_id, None);
ccx.external.borrow_mut().insert(fn_id, None);
fn_id
}
csearch::found(ast::IIItem(item)) => {
{
let mut external = ccx.external.borrow_mut();
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.external.borrow_mut().insert(fn_id, Some(item.id));
ccx.external_srcs.borrow_mut().insert(item.id, fn_id);
ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1);
trans_item(ccx, item);
@ -85,21 +77,13 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
local_def(item.id)
}
csearch::found(ast::IIForeign(item)) => {
{
let mut external = ccx.external.borrow_mut();
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.external.borrow_mut().insert(fn_id, Some(item.id));
ccx.external_srcs.borrow_mut().insert(item.id, fn_id);
local_def(item.id)
}
csearch::found_parent(parent_id, ast::IIItem(item)) => {
{
let mut external = ccx.external.borrow_mut();
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);
}
ccx.external.borrow_mut().insert(parent_id, Some(item.id));
ccx.external_srcs.borrow_mut().insert(item.id, parent_id);
let mut my_id = 0;
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);
for (here, there) in vs_here.iter().zip(vs_there.iter()) {
if there.id == fn_id { my_id = here.id.node; }
let mut external = ccx.external.borrow_mut();
external.get().insert(there.id, Some(here.id.node));
ccx.external.borrow_mut().insert(there.id, Some(here.id.node));
}
}
ast::ItemStruct(ref struct_def, _) => {
match struct_def.ctor_id {
None => {}
Some(ctor_id) => {
let mut external = ccx.external.borrow_mut();
let _ = external.get().insert(fn_id, Some(ctor_id));
ccx.external.borrow_mut().insert(fn_id, Some(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");
}
csearch::found(ast::IIMethod(impl_did, is_provided, mth)) => {
{
let mut external = ccx.external.borrow_mut();
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.external.borrow_mut().insert(fn_id, Some(mth.id));
ccx.external_srcs.borrow_mut().insert(mth.id, fn_id);
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 (origin, method_ty) = match bcx.ccx().maps.method_map
.borrow().get().find(&method_call) {
.borrow().find(&method_call) {
Some(method) => {
debug!("trans_method_callee({:?}, method={})",
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={:?}, \
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);
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,
impl_id: ast::DefId,
name: ast::Name) -> ast::DefId {
{
let impl_method_cache = ccx.impl_method_cache.borrow();
let meth_id_opt = impl_method_cache.get().find_copy(&(impl_id, name));
match meth_id_opt {
Some(m) => return m,
None => {}
}
match ccx.impl_method_cache.borrow().find_copy(&(impl_id, name)) {
Some(m) => return m,
None => {}
}
let impls = ccx.tcx.impls.borrow();
let imp = impls.get().find(&impl_id)
.expect("could not find impl while translating");
let imp = ccx.tcx.impls.borrow();
let imp = imp.find(&impl_id)
.expect("could not find impl while translating");
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();
impl_method_cache.get().insert((impl_id, name), meth.def_id);
ccx.impl_method_cache.borrow_mut().insert((impl_id, name), meth.def_id);
meth.def_id
}
@ -478,12 +473,9 @@ pub fn get_vtable(bcx: &Block,
// Check the cache.
let hash_id = (self_ty, vtable_id(ccx, origins.get(0)));
{
let vtables = ccx.vtables.borrow();
match vtables.get().find(&hash_id) {
Some(&val) => { return val }
None => { }
}
match ccx.vtables.borrow().find(&hash_id) {
Some(&val) => { return val }
None => { }
}
// 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 vtable = make_vtable(ccx, drop_glue, methods.as_slice());
let mut vtables = ccx.vtables.borrow_mut();
vtables.get().insert(hash_id, vtable);
ccx.vtables.borrow_mut().insert(hash_id, 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.
// This is structured a bit funny because of dynamic borrow failures.
let origins = {
let res = {
let vtable_map = ccx.maps.vtable_map.borrow();
*vtable_map.get().get(&id)
};
let res = resolve_vtables_in_fn_ctxt(bcx.fcx, res);
*res.get(0)
};
let res = *ccx.maps.vtable_map.borrow().get(&id);
let res = resolve_vtables_in_fn_ctxt(bcx.fcx, res);
let origins = *res.get(0);
let vtable = get_vtable(bcx, v_ty, origins);
let llvtabledest = GEPi(bcx, lldest, [0u, abi::trt_field_vtable]);
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()),
hash_id);
{
let monomorphized = ccx.monomorphized.borrow();
match monomorphized.get().find(&hash_id) {
Some(&val) => {
match ccx.monomorphized.borrow().find(&hash_id) {
Some(&val) => {
debug!("leaving monomorphic fn {}",
ty::item_path_str(ccx.tcx(), fn_id));
ty::item_path_str(ccx.tcx(), fn_id));
return (val, must_cast);
}
None => ()
}
None => ()
}
let tpt = ty::lookup_item_type(ccx.tcx(), fn_id);
@ -164,7 +161,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
let depth;
{
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
};
@ -176,7 +173,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
"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| {
@ -188,8 +185,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
let lldecl = decl_internal_rust_fn(ccx, false,
f.sig.inputs.as_slice(),
f.sig.output, s);
let mut monomorphized = ccx.monomorphized.borrow_mut();
monomorphized.get().insert(hash_id, lldecl);
ccx.monomorphized.borrow_mut().insert(hash_id, lldecl);
lldecl
};
@ -284,10 +280,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
}
};
{
let mut monomorphizing = ccx.monomorphizing.borrow_mut();
monomorphizing.get().insert(fn_id, depth);
}
ccx.monomorphizing.borrow_mut().insert(fn_id, depth);
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
(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.
pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
{
let llsizingtypes = cx.llsizingtypes.borrow();
match llsizingtypes.get().find_copy(&t) {
Some(t) => return t,
None => ()
}
match cx.llsizingtypes.borrow().find_copy(&t) {
Some(t) => return t,
None => ()
}
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();
llsizingtypes.get().insert(t, llsizingty);
cx.llsizingtypes.borrow_mut().insert(t, llsizingty);
llsizingty
}
// NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
// Check the cache.
{
let lltypes = cx.lltypes.borrow();
match lltypes.get().find(&t) {
Some(&llty) => return llty,
None => ()
}
match cx.lltypes.borrow().find(&t) {
Some(&llty) => return llty,
None => ()
}
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,
cx.tn.type_to_str(llty));
let mut lltypes = cx.lltypes.borrow_mut();
lltypes.get().insert(t, llty);
cx.lltypes.borrow_mut().insert(t, llty);
return llty;
}
@ -295,10 +287,8 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
t.repr(cx.tcx()),
t,
cx.tn.type_to_str(llty));
{
let mut lltypes = cx.lltypes.borrow_mut();
lltypes.get().insert(t, llty);
}
cx.lltypes.borrow_mut().insert(t, llty);
// If this was an enum or struct, fill in the type now.
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)
let ccx = bcx.ccx();
let root_map = ccx.maps.root_map.borrow();
match root_map.get().find(&key) {
match ccx.maps.root_map.borrow().find(&key) {
None => bcx,
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 mut interner = cx.interner.borrow_mut();
match interner.get().find(&key) {
Some(t) => unsafe { return cast::transmute(&t.sty); },
_ => ()
}
match cx.interner.borrow().find(&key) {
Some(t) => unsafe { return cast::transmute(&t.sty); },
_ => ()
}
let mut flags = 0u;
@ -1255,8 +1252,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
sty: sty_ptr,
};
let mut interner = cx.interner.borrow_mut();
interner.get().insert(key, t);
cx.interner.borrow_mut().insert(key, t);
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
// cleanups.
pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool {
{
let needs_unwind_cleanup_cache = cx.needs_unwind_cleanup_cache
.borrow();
match needs_unwind_cleanup_cache.get().find(&ty) {
Some(&result) => return result,
None => ()
}
match cx.needs_unwind_cleanup_cache.borrow().find(&ty) {
Some(&result) => return result,
None => ()
}
let mut tycache = HashSet::new();
let needs_unwind_cleanup =
type_needs_unwind_cleanup_(cx, ty, &mut tycache, false);
let mut needs_unwind_cleanup_cache = cx.needs_unwind_cleanup_cache
.borrow_mut();
needs_unwind_cleanup_cache.get().insert(ty, needs_unwind_cleanup);
cx.needs_unwind_cleanup_cache.borrow_mut().insert(ty, 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 {
let ty_id = type_id(ty);
{
let tc_cache = cx.tc_cache.borrow();
match tc_cache.get().find(&ty_id) {
Some(tc) => { return *tc; }
None => {}
}
match cx.tc_cache.borrow().find(&ty_id) {
Some(tc) => { return *tc; }
None => {}
}
let mut cache = HashMap::new();
let result = tc_ty(cx, ty, &mut cache);
let mut tc_cache = cx.tc_cache.borrow_mut();
tc_cache.get().insert(ty_id, result);
cx.tc_cache.borrow_mut().insert(ty_id, result);
return result;
fn tc_ty(cx: &ctxt,
@ -2139,12 +2125,9 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
Some(tc) => { return *tc; }
None => {}
}
{
let tc_cache = cx.tc_cache.borrow();
match tc_cache.get().find(&ty_id) { // Must check both caches!
Some(tc) => { return *tc; }
None => {}
}
match cx.tc_cache.borrow().find(&ty_id) { // Must check both caches!
Some(tc) => { return *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);
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,
tp_def.bounds.builtin_bounds,
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.
ty_param(p) => {
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) {
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 {
let trait_refs = cx.trait_refs.borrow();
match trait_refs.get().find(&id) {
match cx.trait_refs.borrow().find(&id) {
Some(&t) => t,
None => cx.sess.bug(
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> {
let node_types = cx.node_types.borrow();
node_types.get().find_copy(&(id as uint))
cx.node_types.borrow().find_copy(&(id as uint))
}
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> {
let node_types = cx.node_types.borrow();
debug!("id: {:?}, node_types: {:?}", id, node_types);
match node_types.get().find(&(id as uint)) {
match cx.node_types.borrow().find(&(id as uint)) {
Some(&t) => Some(t),
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.
pub fn node_id_to_type_params(cx: &ctxt, id: ast::NodeId) -> Vec<t> {
let node_type_substs = cx.node_type_substs.borrow();
match node_type_substs.get().find(&id) {
match cx.node_type_substs.borrow().find(&id) {
None => return Vec::new(),
Some(ts) => return (*ts).clone(),
}
}
fn node_id_has_type_params(cx: &ctxt, id: ast::NodeId) -> bool {
let node_type_substs = cx.node_type_substs.borrow();
node_type_substs.get().contains_key(&id)
cx.node_type_substs.borrow().contains_key(&id)
}
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 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| {
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 {
let def_map = tcx.def_map.borrow();
match def_map.get().find(&expr.id) {
match tcx.def_map.borrow().find(&expr.id) {
Some(&def) => def,
None => {
tcx.sess.span_bug(expr.span, format!(
@ -3294,7 +3270,7 @@ pub enum ExprKind {
pub fn expr_kind(tcx: &ctxt,
method_map: MethodMap,
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
// generated via DPS, but there are two exceptions:
return match expr.node {
@ -3377,8 +3353,7 @@ pub fn expr_kind(tcx: &ctxt,
}
ast::ExprCast(..) => {
let node_types = tcx.node_types.borrow();
match node_types.get().find(&(expr.id as uint)) {
match tcx.node_types.borrow().find(&(expr.id as uint)) {
Some(&t) => {
if type_is_trait(t) {
RvalueDpsExpr
@ -3426,8 +3401,7 @@ pub fn expr_kind(tcx: &ctxt,
ast::ExprBox(place, _) => {
// Special case `~T` for now:
let def_map = tcx.def_map.borrow();
let definition = match def_map.get().find(&place.id) {
let definition = match tcx.def_map.borrow().find(&place.id) {
Some(&def) => def,
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> {
let provided_method_sources = cx.provided_method_sources.borrow();
provided_method_sources.get().find(&id).map(|x| *x)
cx.provided_method_sources.borrow().find(&id).map(|x| *x)
}
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> {
// Check the cache.
{
let supertraits = cx.supertraits.borrow();
match supertraits.get().find(&id) {
Some(&trait_refs) => { return trait_refs; }
None => {} // Continue.
}
match cx.supertraits.borrow().find(&id) {
Some(&trait_refs) => { return trait_refs; }
None => {} // Continue.
}
// 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
// TraitRef for each.
let result = @csearch::get_supertraits(cx, id);
let mut supertraits = cx.supertraits.borrow_mut();
supertraits.get().insert(id, result);
cx.supertraits.borrow_mut().insert(id, 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> {
let mut trait_methods_cache = cx.trait_methods_cache.borrow_mut();
match trait_methods_cache.get().find(&trait_did) {
let mut trait_methods = cx.trait_methods_cache.borrow_mut();
match trait_methods.find(&trait_did) {
Some(&methods) => methods,
None => {
let def_ids = ty::trait_method_def_ids(cx, trait_did);
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
}
}
}
pub fn method(cx: &ctxt, id: ast::DefId) -> @Method {
let mut methods = cx.methods.borrow_mut();
lookup_locally_or_in_crate_store("methods", id, methods.get(), || {
lookup_locally_or_in_crate_store("methods", id,
&mut *cx.methods.borrow_mut(), || {
@csearch::get_method(cx, id)
})
}
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",
id,
trait_method_def_ids.get(),
&mut *cx.trait_method_def_ids.borrow_mut(),
|| {
@csearch::get_trait_method_def_ids(&cx.sess.cstore, id)
})
}
pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<@TraitRef> {
{
let mut impl_trait_cache = cx.impl_trait_cache.borrow_mut();
match impl_trait_cache.get().find(&id) {
Some(&ret) => { return ret; }
None => {}
}
match cx.impl_trait_cache.borrow().find(&id) {
Some(&ret) => { return ret; }
None => {}
}
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)
};
let mut impl_trait_cache = cx.impl_trait_cache.borrow_mut();
impl_trait_cache.get().insert(id, ret);
cx.impl_trait_cache.borrow_mut().insert(id, ret);
return ret;
}
pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
let def_map = tcx.def_map.borrow();
let def = def_map.get()
let def = *tcx.def_map.borrow()
.find(&tr.ref_id)
.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,
@ -4021,8 +3984,7 @@ impl DtorKind {
/* If struct_id names a struct with a dtor, return Some(the dtor's id).
Otherwise return none. */
pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
let destructor_for_type = cx.destructor_for_type.borrow();
match destructor_for_type.get().find(&struct_id) {
match cx.destructor_for_type.borrow().find(&struct_id) {
Some(&method_def_id) => {
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> {
{
let enum_var_cache = cx.enum_var_cache.borrow();
match enum_var_cache.get().find(&id) {
Some(&variants) => return variants,
_ => { /* fallthrough */ }
}
match cx.enum_var_cache.borrow().find(&id) {
Some(&variants) => return variants,
_ => { /* fallthrough */ }
}
let result = if ast::LOCAL_CRATE != id.krate {
@ -4129,11 +4088,8 @@ pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> @Vec<@VariantInfo> {
}
};
{
let mut enum_var_cache = cx.enum_var_cache.borrow_mut();
enum_var_cache.get().insert(id, result);
result
}
cx.enum_var_cache.borrow_mut().insert(id, result);
result
}
@ -4160,25 +4116,23 @@ pub fn enum_variant_with_id(cx: &ctxt,
pub fn lookup_item_type(cx: &ctxt,
did: ast::DefId)
-> ty_param_bounds_and_ty {
let mut tcache = cx.tcache.borrow_mut();
lookup_locally_or_in_crate_store(
"tcache", did, tcache.get(),
"tcache", did, &mut *cx.tcache.borrow_mut(),
|| csearch::get_type(cx, did))
}
pub fn lookup_impl_vtables(cx: &ctxt,
did: ast::DefId)
-> typeck::impl_res {
let mut impl_vtables = cx.impl_vtables.borrow_mut();
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) )
}
/// Given the did of a trait, returns its canonical trait ref.
pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> @ty::TraitDef {
let mut trait_defs = cx.trait_defs.borrow_mut();
match trait_defs.get().find(&did) {
match trait_defs.find(&did) {
Some(&trait_def) => {
// The item is in this crate. The caller should have added it to the
// type cache already
@ -4187,7 +4141,7 @@ pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> @ty::TraitDef {
None => {
assert!(did.krate != ast::LOCAL_CRATE);
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;
}
}
@ -4255,16 +4209,14 @@ pub fn lookup_field_type(tcx: &ctxt,
let t = if id.krate == ast::LOCAL_CRATE {
node_id_to_type(tcx, id.node)
} else {
{
let mut tcache = tcx.tcache.borrow_mut();
match tcache.get().find(&id) {
Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
None => {
let tpt = csearch::get_field_type(tcx, struct_id, id);
tcache.get().insert(id, tpt.clone());
tpt.ty
}
}
let mut tcache = tcx.tcache.borrow_mut();
match tcache.find(&id) {
Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
None => {
let tpt = csearch::get_field_type(tcx, struct_id, id);
tcache.insert(id, tpt.clone());
tpt.ty
}
}
};
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 fold_ty(&mut self, t: ty::t) -> ty::t {
let normalized_opt = {
let normalized_cache = self.tcx().normalized_cache.borrow();
normalized_cache.get().find_copy(&t)
};
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;
}
match self.tcx().normalized_cache.borrow().find_copy(&t) {
None => {}
Some(u) => return u
}
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 {
@ -4636,16 +4579,14 @@ pub fn count_traits_and_supertraits(tcx: &ctxt,
pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
let intrinsic_defs = tcx.intrinsic_defs.borrow();
intrinsic_defs.get().find_copy(&tydesc_lang_item)
tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item)
.expect("Failed to resolve TyDesc")
})
}
pub fn get_opaque_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(OpaqueStructLangItem).map(|opaque_lang_item| {
let intrinsic_defs = tcx.intrinsic_defs.borrow();
intrinsic_defs.get().find_copy(&opaque_lang_item)
tcx.intrinsic_defs.borrow().find_copy(&opaque_lang_item)
.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 {
let mut item_variance_map = tcx.item_variance_map.borrow_mut();
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))
}
@ -4684,18 +4624,17 @@ fn record_trait_implementation(tcx: &ctxt,
implementation: @Impl) {
let implementation_list;
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 => {
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) => {
implementation_list = existing_implementation_list
}
}
let mut implementation_list = implementation_list.borrow_mut();
implementation_list.get().push(implementation);
implementation_list.borrow_mut().push(implementation);
}
/// 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 {
return
}
{
let populated_external_types = tcx.populated_external_types.borrow();
if populated_external_types.get().contains(&type_id) {
return
}
if tcx.populated_external_types.borrow().contains(&type_id) {
return
}
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.
for method in implementation.methods.iter() {
for source in method.provided_source.iter() {
let mut provided_method_sources =
tcx.provided_method_sources.borrow_mut();
provided_method_sources.get().insert(method.def_id, *source);
tcx.provided_method_sources.borrow_mut()
.insert(method.def_id, *source);
}
}
@ -4739,30 +4674,23 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
if associated_traits.is_none() {
let implementation_list;
let mut inherent_impls = tcx.inherent_impls.borrow_mut();
match inherent_impls.get().find(&type_id) {
match inherent_impls.find(&type_id) {
None => {
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) => {
implementation_list = existing_implementation_list;
}
}
{
let mut implementation_list =
implementation_list.borrow_mut();
implementation_list.get().push(implementation);
}
implementation_list.borrow_mut().push(implementation);
}
// Store the implementation info.
let mut impls = tcx.impls.borrow_mut();
impls.get().insert(implementation_def_id, implementation);
tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
});
let mut populated_external_types = tcx.populated_external_types
.borrow_mut();
populated_external_types.get().insert(type_id);
tcx.populated_external_types.borrow_mut().insert(type_id);
}
/// 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 {
return
}
{
let populated_external_traits = tcx.populated_external_traits
.borrow();
if populated_external_traits.get().contains(&trait_id) {
return
}
if tcx.populated_external_traits.borrow().contains(&trait_id) {
return
}
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.
for method in implementation.methods.iter() {
for source in method.provided_source.iter() {
let mut provided_method_sources =
tcx.provided_method_sources.borrow_mut();
provided_method_sources.get().insert(method.def_id, *source);
tcx.provided_method_sources.borrow_mut()
.insert(method.def_id, *source);
}
}
// Store the implementation info.
let mut impls = tcx.impls.borrow_mut();
impls.get().insert(implementation_def_id, implementation);
tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
});
let mut populated_external_traits = tcx.populated_external_traits
.borrow_mut();
populated_external_traits.get().insert(trait_id);
tcx.populated_external_traits.borrow_mut().insert(trait_id);
}
/// 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 {
return csearch::get_trait_of_method(&tcx.sess.cstore, def_id, tcx);
}
let method;
{
let methods = tcx.methods.borrow();
method = methods.get().find(&def_id).map(|method| *method);
}
match method {
match tcx.methods.borrow().find(&def_id).map(|m| *m) {
Some(method) => {
match method.container {
TraitContainer(def_id) => Some(def_id),
@ -4861,14 +4776,10 @@ pub fn trait_of_method(tcx: &ctxt, def_id: ast::DefId)
/// Otherwise, return `None`.
pub fn trait_method_of_method(tcx: &ctxt,
def_id: ast::DefId) -> Option<ast::DefId> {
let method;
{
let methods = tcx.methods.borrow();
match methods.get().find(&def_id) {
Some(m) => method = *m,
None => return None,
}
}
let method = match tcx.methods.borrow().find(&def_id) {
Some(&m) => m,
None => return None,
};
let name = method.ident.name;
match trait_of_method(tcx, def_id) {
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> {
match ast_ty.node {
ast::TyPath(ref path, _, id) => {
let def_map = tcx.def_map.borrow();
let a_def = match def_map.get().find(&id) {
let a_def = match tcx.def_map.borrow().find(&id) {
None => tcx.sess.span_fatal(
ast_ty.span, format!("unbound path {}", path_to_str(path))),
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"
// restriction is enforced in the below case for ty_path, which
// will run after this as long as the path isn't a trait.
let def_map = tcx.def_map.borrow();
match def_map.get().find(&id) {
match tcx.def_map.borrow().find(&id) {
Some(&ast::DefPrimTy(ast::TyStr)) if
a_seq_ty.mutbl == ast::MutImmutable => {
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 mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut();
match ast_ty_to_ty_cache.get().find(&ast_ty.id) {
Some(&ty::atttce_resolved(ty)) => return ty,
Some(&ty::atttce_unresolved) => {
tcx.sess.span_fatal(ast_ty.span,
"illegal recursive type; insert an enum \
or struct in the cycle, if this is \
desired");
}
None => { /* go on */ }
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) {
Some(&ty::atttce_resolved(ty)) => return ty,
Some(&ty::atttce_unresolved) => {
tcx.sess.span_fatal(ast_ty.span,
"illegal recursive type; insert an enum \
or struct in the cycle, if this is \
desired");
}
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 {
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)
}
ast::TyPath(ref path, ref bounds, id) => {
let def_map = tcx.def_map.borrow();
let a_def = match def_map.get().find(&id) {
let a_def = match tcx.def_map.borrow().find(&id) {
None => tcx.sess.span_fatal(
ast_ty.span, format!("unbound path {}", path_to_str(path))),
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();
ast_ty_to_ty_cache.get().insert(ast_ty.id, ty::atttce_resolved(typ));
tcx.ast_ty_to_ty_cache.borrow_mut().insert(ast_ty.id, ty::atttce_resolved(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);
// Check to ensure that the struct is the one specified.
let def_map = tcx.def_map.borrow();
match def_map.get().find(&pat_id) {
match tcx.def_map.borrow().find(&pat_id) {
Some(&ast::DefStruct(supplied_def_id))
if supplied_def_id == struct_id => {
// OK.
@ -399,8 +398,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
let tcx = pcx.fcx.ccx.tcx;
// Find the variant that was specified.
let def_map = tcx.def_map.borrow();
match def_map.get().find(&pat_id) {
match tcx.def_map.borrow().find(&pat_id) {
Some(&ast::DefVariant(found_enum_id, variant_id, _))
if found_enum_id == enum_id => {
// 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::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(def_map.get()
.get_copy(&pat.id));
let const_did = ast_util::def_id_of_def(tcx.def_map.borrow()
.get_copy(&pat.id));
let const_tpt = ty::lookup_item_type(tcx, const_did);
demand::suptype(fcx, pat.span, expected, 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)})},
Some(expected), ~"a structure pattern",
None);
let def_map = tcx.def_map.borrow();
match def_map.get().find(&pat.id) {
match tcx.def_map.borrow().find(&pat.id) {
Some(&ast::DefStruct(supplied_def_id)) => {
check_struct_pat(pcx,
pat.id,

View file

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

View file

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

View file

@ -241,7 +241,7 @@ impl<'a> Rcx<'a> {
}
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);
method_ty.map(|method_ty| self.resolve_type(method_ty))
}
@ -253,7 +253,7 @@ impl<'a> Rcx<'a> {
ty_unadjusted
} else {
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,
|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> {
let adjustments = self.fcx.inh.adjustments.borrow();
adjustments.get().find_copy(&id)
self.fcx.inh.adjustments.borrow().find_copy(&id)
}
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> {
@ -288,8 +287,7 @@ impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
}
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
let upvar_borrow_map = self.fcx.inh.upvar_borrow_map.borrow();
upvar_borrow_map.get().get_copy(&id)
self.fcx.inh.upvar_borrow_map.borrow().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);
// 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);
match **adjustment {
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.
let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow,
region: freevar_region };
let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
upvar_borrow_map.get().insert(upvar_id, upvar_borrow);
rcx.fcx.inh.upvar_borrow_map.borrow_mut().insert(upvar_id,
upvar_borrow);
// Guarantee that the closure does not outlive the variable itself.
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
// report errors later on in the writeback phase.
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,
|method_call| rcx.resolve_method_type(method_call));
debug!("constrain_regions_in_type_of_node(\
@ -1204,9 +1202,8 @@ fn link_region(rcx: &mut Rcx,
// to use for each upvar.
let cause = match base.cat {
mc::cat_upvar(ref upvar_id, _) => {
let mut upvar_borrow_map =
rcx.fcx.inh.upvar_borrow_map.borrow_mut();
match upvar_borrow_map.get().find_mut(upvar_id) {
match rcx.fcx.inh.upvar_borrow_map.borrow_mut()
.find_mut(upvar_id) {
Some(upvar_borrow) => {
debug!("link_region: {} <= {}",
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
let mut upvar_borrow_map =
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);
}
@ -1377,9 +1374,8 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &mut Rcx,
// upvar, then we need to modify the
// borrow_kind of the upvar to make sure it
// is inferred to unique if necessary
let mut upvar_borrow_map =
rcx.fcx.inh.upvar_borrow_map.borrow_mut();
let ub = upvar_borrow_map.get().get_mut(upvar_id);
let mut ub = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
let ub = ub.get_mut(upvar_id);
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);
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);
match upvar_borrow_map.get().find_mut(&outer_upvar_id) {
let inner_borrow = upvar_borrow_map.get_copy(&inner_upvar_id);
match upvar_borrow_map.find_mut(&outer_upvar_id) {
Some(outer_borrow) => {
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
// pointless allocations.
let impls = {
let trait_impls = tcx.trait_impls.borrow();
trait_impls.get()
.find(&trait_ref.def_id)
.map_or(@RefCell::new(Vec::new()), |x| *x)
};
let impls = tcx.trait_impls.borrow().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.
let impls = impls.borrow();
for im in impls.get().iter() {
for im in impls.borrow().iter() {
// im is one specific impl of trait_ref.
// 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) {
debug!("insert_vtables(expr_id={}, vtables={:?})",
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) {
@ -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| {
debug!("vtable resolution on parameter bounds for expr {}",
ex.repr(fcx.tcx()));
let def_map = cx.tcx.def_map.borrow();
let def = def_map.get().get_copy(&ex.id);
let def = cx.tcx.def_map.borrow().get_copy(&ex.id);
let did = ast_util::def_id_of_def(def);
let item_ty = ty::lookup_item_type(cx.tcx, did);
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::ExprIndex(_, _) |
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) => {
debug!("vtable resolution on parameter bounds for method call {}",
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
let adjustments = fcx.inh.adjustments.borrow();
match adjustments.get().find(&ex.id) {
match fcx.inh.adjustments.borrow().find(&ex.id) {
Some(adjustment) => {
match **adjustment {
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 mut impl_vtables = tcx.impl_vtables.borrow_mut();
impl_vtables.get().insert(impl_def_id, res);
tcx.impl_vtables.borrow_mut().insert(impl_def_id, res);
}
/// 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;
// 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) => {
debug!("writeback::resolve_method_map_entry(call={:?}, entry={:?})",
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
}
};
fcx.ccx.method_map.borrow_mut().get().insert(method_call, new_method);
fcx.ccx.method_map.borrow_mut().insert(method_call, new_method);
}
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) {
// 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) => {
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={:?})",
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;
// Resolve any borrowings for the node with id `id`
let adjustment = fcx.inh.adjustments.borrow().get().find_copy(&id);
match adjustment {
match fcx.inh.adjustments.borrow().find_copy(&id) {
None => (),
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
// bare functions to coerce to a closure to avoid
// 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::DefStaticMethod(..)) |
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);
debug!("Adjustments for node {}: {:?}",
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,
});
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(..) => {
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 tcx = fcx.tcx();
let upvar_borrow_map = fcx.inh.upvar_borrow_map.borrow();
for (upvar_id, upvar_borrow) in upvar_borrow_map.get().iter() {
for (upvar_id, upvar_borrow) in fcx.inh.upvar_borrow_map.borrow().iter() {
let r = upvar_borrow.region;
match resolve_region(fcx.infcx(), r, resolve_all | force_all) {
Ok(r) => {
@ -366,8 +364,8 @@ fn resolve_upvar_borrow_map(wbcx: &mut WbCtxt) {
};
debug!("Upvar borrow for {} resolved to {}",
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.get().insert(*upvar_id, new_upvar_borrow);
tcx.upvar_borrow_map.borrow_mut().insert(*upvar_id,
new_upvar_borrow);
}
Err(e) => {
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();
impls.get().insert(implementation.did, implementation);
tcx.impls.borrow_mut().insert(implementation.did, implementation);
}
// 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));
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(new_did, new_polytype);
}
let mut methods = tcx.methods.borrow_mut();
methods.get().insert(new_did, new_method_ty);
tcx.tcache.borrow_mut().insert(new_did, new_polytype);
tcx.methods.borrow_mut().insert(new_did, new_method_ty);
// Pair the new synthesized ID up with the
// ID of the method.
let mut provided_method_sources =
self.crate_context.tcx.provided_method_sources.borrow_mut();
provided_method_sources.get().insert(new_did,
trait_method.def_id);
self.crate_context.tcx.provided_method_sources.borrow_mut()
.insert(new_did, trait_method.def_id);
}
}
@ -381,18 +373,17 @@ impl<'a> CoherenceChecker<'a> {
let tcx = self.crate_context.tcx;
let implementation_list;
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 => {
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) => {
implementation_list = existing_implementation_list;
}
}
let mut implementation_list = implementation_list.borrow_mut();
implementation_list.get().push(implementation);
implementation_list.borrow_mut().push(implementation);
}
fn add_trait_impl(&self, base_def_id: DefId,
@ -400,23 +391,21 @@ impl<'a> CoherenceChecker<'a> {
let tcx = self.crate_context.tcx;
let implementation_list;
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 => {
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) => {
implementation_list = existing_implementation_list;
}
}
let mut implementation_list = implementation_list.borrow_mut();
implementation_list.get().push(implementation);
implementation_list.borrow_mut().push(implementation);
}
fn check_implementation_coherence(&self) {
let trait_impls = self.crate_context.tcx.trait_impls.borrow();
for &trait_id in trait_impls.get().keys() {
for &trait_id in self.crate_context.tcx.trait_impls.borrow().keys() {
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|) {
let trait_impls = self.crate_context.tcx.trait_impls.borrow();
match trait_impls.get().find(&trait_def_id) {
match self.crate_context.tcx.trait_impls.borrow().find(&trait_def_id) {
Some(impls) => {
let impls = impls.borrow();
for &im in impls.get().iter() {
for &im in impls.borrow().iter() {
f(im);
}
}
@ -543,8 +530,7 @@ impl<'a> CoherenceChecker<'a> {
fn get_self_type_for_implementation(&self, implementation: @Impl)
-> ty_param_bounds_and_ty {
let tcache = self.crate_context.tcx.tcache.borrow();
return tcache.get().get_copy(&implementation.did);
self.crate_context.tcx.tcache.borrow().get_copy(&implementation.did)
}
// Privileged scope checking
@ -555,8 +541,7 @@ impl<'a> CoherenceChecker<'a> {
fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
let def_map = self.crate_context.tcx.def_map;
let def_map = def_map.borrow();
let trait_def = def_map.get().get_copy(&trait_ref.ref_id);
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let trait_id = def_id_of_def(trait_def);
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 {
match original_type.node {
TyPath(_, _, path_id) => {
let def_map = self.crate_context.tcx.def_map.borrow();
match def_map.get().get_copy(&path_id) {
match self.crate_context.tcx.def_map.borrow().get_copy(&path_id) {
DefTy(def_id) | DefStruct(def_id) => {
if def_id.krate != LOCAL_CRATE {
return false;
@ -666,14 +650,12 @@ impl<'a> CoherenceChecker<'a> {
// the map. This is a bit unfortunate.
for method in implementation.methods.iter() {
for source in method.provided_source.iter() {
let mut provided_method_sources = tcx.provided_method_sources
.borrow_mut();
provided_method_sources.get().insert(method.def_id, *source);
tcx.provided_method_sources.borrow_mut()
.insert(method.def_id, *source);
}
}
let mut impls = tcx.impls.borrow_mut();
impls.get().insert(implementation.did, implementation);
tcx.impls.borrow_mut().insert(implementation.did, implementation);
}
// 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 impls_opt = trait_impls.get().find(&drop_trait);
let impls_opt = trait_impls.find(&drop_trait);
let impls;
match impls_opt {
None => return, // No types with (new-style) dtors present.
Some(found_impls) => impls = found_impls
}
let impls = impls.borrow();
for impl_info in impls.get().iter() {
for impl_info in impls.borrow().iter() {
if impl_info.methods.len() < 1 {
// We'll error out later. For now, just don't ICE.
continue;
@ -720,12 +701,9 @@ impl<'a> CoherenceChecker<'a> {
match ty::get(self_type.ty).sty {
ty::ty_enum(type_def_id, _) |
ty::ty_struct(type_def_id, _) => {
let mut destructor_for_type = tcx.destructor_for_type
.borrow_mut();
destructor_for_type.get().insert(type_def_id,
method_def_id);
let mut destructors = tcx.destructors.borrow_mut();
destructors.get().insert(method_def_id);
tcx.destructor_for_type.borrow_mut().insert(type_def_id,
method_def_id);
tcx.destructors.borrow_mut().insert(method_def_id);
}
_ => {
// 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) {
let ty::ty_param_bounds_and_ty { ty: ty, .. } =
ccx.get_item_ty(lang_item);
let mut intrinsic_defs = ccx.tcx.intrinsic_defs.borrow_mut();
intrinsic_defs.get().insert(lang_item, ty);
ccx.tcx.intrinsic_defs.borrow_mut().insert(lang_item, ty);
}
match ccx.tcx.lang_items.ty_desc() {
@ -180,10 +179,7 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
ty: result_ty
};
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(variant.node.id), tpt);
}
tcx.tcache.borrow_mut().insert(local_def(variant.node.id), tpt);
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);
}
let mut methods = tcx.methods.borrow_mut();
methods.get().insert(ty_method.def_id, ty_method);
tcx.methods.borrow_mut().insert(ty_method.def_id,
ty_method);
}
// 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 mut trait_method_def_ids = tcx.trait_method_def_ids
.borrow_mut();
trait_method_def_ids.get()
.insert(trait_def_id,
@method_def_ids.iter()
.map(|x| *x)
.collect());
tcx.trait_method_def_ids.borrow_mut()
.insert(trait_def_id, @method_def_ids.iter()
.map(|x| *x)
.collect());
}
_ => {} // Ignore things that aren't traits.
}
@ -372,8 +365,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
ty.repr(tcx),
substs.repr(tcx));
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(m.def_id,
tcx.tcache.borrow_mut().insert(m.def_id,
ty_param_bounds_and_ty {
generics: ty::Generics {
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.
// Supertraits are ensured at the same time.
{
let supertraits = tcx.supertraits.borrow();
assert!(!supertraits.get().contains_key(&local_def(id)));
}
assert!(!tcx.supertraits.borrow().contains_key(&local_def(id)));
let self_ty = ty::mk_self(ccx.tcx, local_def(id));
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();
supertraits.get().insert(local_def(id), @ty_trait_refs);
tcx.supertraits.borrow_mut().insert(local_def(id), @ty_trait_refs);
bounds
}
@ -462,8 +450,7 @@ pub fn convert_field(ccx: &CrateCtxt,
let tt = ccx.to_ty(&ExplicitRscope, v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */
let mut tcache = ccx.tcx.tcache.borrow_mut();
tcache.get().insert(local_def(v.node.id),
ccx.tcx.tcache.borrow_mut().insert(local_def(v.node.id),
ty::ty_param_bounds_and_ty {
generics: struct_generics.clone(),
ty: tt
@ -499,32 +486,28 @@ fn convert_methods(ccx: &CrateCtxt,
m.ident.repr(ccx.tcx),
m.id,
fty.repr(ccx.tcx));
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(
local_def(m.id),
tcx.tcache.borrow_mut().insert(
local_def(m.id),
// n.b.: the type of a method is parameterized by both
// the parameters on the receiver and those on the method
// itself
ty_param_bounds_and_ty {
generics: ty::Generics {
type_param_defs: Rc::new(vec::append(
Vec::from_slice(
rcvr_ty_generics.type_param_defs()),
m_ty_generics.type_param_defs())),
region_param_defs: Rc::new(vec::append(
Vec::from_slice(rcvr_ty_generics.region_param_defs()),
m_ty_generics.region_param_defs())),
},
ty: fty
});
}
// n.b.: the type of a method is parameterized by both
// the parameters on the receiver and those on the method
// itself
ty_param_bounds_and_ty {
generics: ty::Generics {
type_param_defs: Rc::new(vec::append(
Vec::from_slice(
rcvr_ty_generics.type_param_defs()),
m_ty_generics.type_param_defs())),
region_param_defs: Rc::new(vec::append(
Vec::from_slice(rcvr_ty_generics.region_param_defs()),
m_ty_generics.region_param_defs())),
},
ty: fty
});
write_ty_to_tcx(tcx, m.id, fty);
let mut methods = tcx.methods.borrow_mut();
methods.get().insert(mty.def_id, mty);
tcx.methods.borrow_mut().insert(mty.def_id, mty);
}
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);
write_ty_to_tcx(tcx, it.id, selfty);
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id),
ty_param_bounds_and_ty {
generics: ty_generics.clone(),
ty: selfty});
}
tcx.tcache.borrow_mut().insert(local_def(it.id),
ty_param_bounds_and_ty {
generics: ty_generics.clone(),
ty: selfty});
// If there is a trait reference, treat the methods as always public.
// 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);
write_ty_to_tcx(tcx, it.id, tpt.ty);
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
}
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
convert_struct(ccx, struct_def, tpt, it.id);
},
@ -719,32 +696,23 @@ pub fn convert_struct(ccx: &CrateCtxt,
// Enum-like.
write_ty_to_tcx(tcx, ctor_id, selfty);
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(ctor_id), tpt);
}
tcx.tcache.borrow_mut().insert(local_def(ctor_id), tpt);
} else if struct_def.fields.get(0).node.kind ==
ast::UnnamedField {
// Tuple-like.
let inputs = {
let tcache = tcx.tcache.borrow();
struct_def.fields.map(
|field| tcache.get().get(
&local_def(field.node.id)).ty)
};
let inputs = struct_def.fields.map(
|field| tcx.tcache.borrow().get(
&local_def(field.node.id)).ty);
let ctor_fn_ty = ty::mk_ctor_fn(tcx,
ctor_id,
inputs.as_slice(),
selfty);
write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty);
{
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(ctor_id),
ty_param_bounds_and_ty {
generics: tpt.generics,
ty: ctor_fn_ty
});
}
tcx.tcache.borrow_mut().insert(local_def(ctor_id),
ty_param_bounds_and_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);
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
let mut tcache = ccx.tcx.tcache.borrow_mut();
tcache.get().insert(local_def(i.id), tpt);
ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), tpt);
}
pub fn instantiate_trait_ref(ccx: &CrateCtxt,
@ -787,8 +754,8 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt,
astconv::ast_path_to_trait_ref(
ccx, &rscope, trait_did, Some(self_ty), &ast_trait_ref.path);
let mut trait_refs = ccx.tcx.trait_refs.borrow_mut();
trait_refs.get().insert(ast_trait_ref.ref_id, trait_ref);
ccx.tcx.trait_refs.borrow_mut().insert(ast_trait_ref.ref_id,
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 {
let def_id = local_def(it.id);
let tcx = ccx.tcx;
{
let trait_defs = tcx.trait_defs.borrow();
match trait_defs.get().find(&def_id) {
Some(&def) => return def,
_ => {}
}
match tcx.trait_defs.borrow().find(&def_id) {
Some(&def) => return def,
_ => {}
}
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,
bounds: bounds,
trait_ref: trait_ref};
let mut trait_defs = tcx.trait_defs.borrow_mut();
trait_defs.get().insert(def_id, trait_def);
tcx.trait_defs.borrow_mut().insert(def_id, trait_def);
return trait_def;
}
ref s => {
@ -853,20 +816,16 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
-> ty::ty_param_bounds_and_ty {
let def_id = local_def(it.id);
let tcx = ccx.tcx;
{
let tcache = tcx.tcache.borrow();
match tcache.get().find(&def_id) {
Some(tpt) => return tpt.clone(),
_ => {}
}
match tcx.tcache.borrow().find(&def_id) {
Some(tpt) => return tpt.clone(),
_ => {}
}
match it.node {
ast::ItemStatic(t, _, _) => {
let typ = ccx.to_ty(&ExplicitRscope, t);
let tpt = no_params(typ);
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
}
ast::ItemFn(decl, purity, abi, ref generics, _) => {
@ -885,17 +844,13 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
it.id,
ppaux::ty_to_str(tcx, tpt.ty));
let mut tcache = ccx.tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
}
ast::ItemTy(t, ref generics) => {
{
let mut tcache = tcx.tcache.borrow_mut();
match tcache.get().find(&local_def(it.id)) {
Some(tpt) => return tpt.clone(),
None => { }
}
match tcx.tcache.borrow_mut().find(&local_def(it.id)) {
Some(tpt) => return tpt.clone(),
None => { }
}
let tpt = {
@ -906,8 +861,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
}
};
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
}
ast::ItemEnum(_, ref generics) => {
@ -920,8 +874,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
ty: t
};
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
}
ast::ItemTrait(..) => {
@ -938,8 +891,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
ty: t
};
let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(it.id), tpt.clone());
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
}
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)| {
let existing_def_opt = {
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(|| {
let param_ty = ty::param_ty {idx: base_index + offset,
@ -1011,8 +963,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
default: default
};
debug!("def for param: {}", def.repr(ccx.tcx));
let mut ty_param_defs = ccx.tcx.ty_param_defs.borrow_mut();
ty_param_defs.get().insert(param.id, def);
ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def);
def
})
}).collect()),
@ -1100,8 +1051,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
ty: t_fn
};
let mut tcache = ccx.tcx.tcache.borrow_mut();
tcache.get().insert(def_id, tpt.clone());
ccx.tcx.tcache.borrow_mut().insert(def_id, tpt.clone());
return tpt;
}

View file

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

View file

@ -530,25 +530,21 @@ impl<'a> InferCtxt<'a> {
}
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 {
ty_var_bindings_len: ty_var_bindings.get().bindings.len(),
int_var_bindings_len: int_var_bindings.get().bindings.len(),
float_var_bindings_len: float_var_bindings.get().bindings.len(),
ty_var_bindings_len: self.ty_var_bindings.borrow().bindings.len(),
int_var_bindings_len: self.int_var_bindings.borrow().bindings.len(),
float_var_bindings_len: self.float_var_bindings.borrow().bindings.len(),
region_vars_snapshot: self.region_vars.start_snapshot(),
}
}
pub fn rollback_to(&self, snapshot: &Snapshot) {
debug!("rollback!");
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
let mut int_var_bindings = self.int_var_bindings.borrow_mut();
let mut float_var_bindings = self.float_var_bindings.borrow_mut();
rollback_to(ty_var_bindings.get(), snapshot.ty_var_bindings_len);
rollback_to(int_var_bindings.get(), snapshot.int_var_bindings_len);
rollback_to(float_var_bindings.get(),
rollback_to(&mut *self.ty_var_bindings.borrow_mut(),
snapshot.ty_var_bindings_len);
rollback_to(&mut *self.int_var_bindings.borrow_mut(),
snapshot.int_var_bindings_len);
rollback_to(&mut *self.float_var_bindings.borrow_mut(),
snapshot.float_var_bindings_len);
self.region_vars.rollback_to(snapshot.region_vars_snapshot);
@ -562,10 +558,8 @@ impl<'a> InferCtxt<'a> {
indent(|| {
let r = self.try(|| f());
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
let mut int_var_bindings = self.int_var_bindings.borrow_mut();
ty_var_bindings.get().bindings.truncate(0);
int_var_bindings.get().bindings.truncate(0);
self.ty_var_bindings.borrow_mut().bindings.truncate(0);
self.int_var_bindings.borrow_mut().bindings.truncate(0);
self.region_vars.commit();
r
})
@ -614,7 +608,7 @@ impl<'a> InferCtxt<'a> {
self.ty_var_counter.set(id + 1);
{
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));
}
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_bindings = self.int_var_bindings.borrow_mut();
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);
result
}
@ -645,7 +639,7 @@ impl<'a> InferCtxt<'a> {
let mut float_var_counter = self.float_var_counter.get();
let mut float_var_bindings = self.float_var_bindings.borrow_mut();
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);
result
}

View file

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

View file

@ -75,8 +75,7 @@ impl<'a> UnifyInferCtxtMethods for InferCtxt<'a> {
let tcx = self.tcx;
let vb = UnifyVid::appropriate_vals_and_bindings(self);
let mut vb = vb.borrow_mut();
return helper(tcx, vb.get(), vid);
return helper(tcx, &mut *vb.borrow_mut(), vid);
fn helper<T:Clone, V:Clone+Eq+Vid>(
tcx: &ty::ctxt,
@ -123,9 +122,9 @@ impl<'a> UnifyInferCtxtMethods for InferCtxt<'a> {
let vb = UnifyVid::appropriate_vals_and_bindings(self);
let mut vb = vb.borrow_mut();
let old_v = (*vb.get().vals.get(&vid.to_uint())).clone();
vb.get().bindings.push((vid.clone(), old_v));
vb.get().vals.insert(vid.to_uint(), new_v);
let old_v = (*vb.vals.get(&vid.to_uint())).clone();
vb.bindings.push((vid.clone(), old_v));
vb.vals.insert(vid.to_uint(), new_v);
}
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) {
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_str(tcx, ty));
assert!(!ty::type_needs_infer(ty));
let mut node_types = tcx.node_types.borrow_mut();
node_types.get().insert(node_id as uint, ty);
tcx.node_types.borrow_mut().insert(node_id as uint, ty);
}
pub fn write_substs_to_tcx(tcx: &ty::ctxt,
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)));
assert!(substs.iter().all(|t| !ty::type_needs_infer(*t)));
let mut node_type_substs = tcx.node_type_substs.borrow_mut();
node_type_substs.get().insert(node_id, substs);
tcx.node_type_substs.borrow_mut().insert(node_id, substs);
}
}
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 {
let def_map = tcx.def_map.borrow();
match def_map.get().find(&id) {
match tcx.def_map.borrow().find(&id) {
Some(&x) => x,
_ => {
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
// parameters".
if self.num_inferred() == inferreds_on_entry {
let mut item_variance_map = self.tcx
.item_variance_map
.borrow_mut();
let newly_added = item_variance_map.get().insert(
let newly_added = self.tcx.item_variance_map.borrow_mut().insert(
ast_util::local_def(item.id),
self.empty_variances);
assert!(newly_added);
@ -944,9 +941,8 @@ impl<'a> SolveContext<'a> {
tcx.sess.span_err(tcx.map.span(item_id), found);
}
let mut item_variance_map = tcx.item_variance_map.borrow_mut();
let newly_added = item_variance_map.get().insert(item_def_id,
@item_variances);
let newly_added = tcx.item_variance_map.borrow_mut()
.insert(item_def_id, @item_variances);
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_err => ~"[type error]",
ty_param(param_ty {idx: id, def_id: did}) => {
let ty_param_defs = cx.ty_param_defs.borrow();
let param_def = ty_param_defs.get().find(&did.node);
let ident = match param_def {
let ident = match cx.ty_param_defs.borrow().find(&did.node) {
Some(def) => token::get_ident(def.ident).get().to_str(),
// This should not happen...
None => format!("BUG[{:?}]", id)