Skip to content

Commit f635b2f

Browse files
committed
Auto merge of #26722 - arielb1:log-deadlock, r=eddyb
These are RefCell deadlocks that cause the rustc task to die with the stderr lock held, causing a real deadlock. Fixes #26717. r? @eddyb
2 parents 969d6ca + 2fc8571 commit f635b2f

File tree

6 files changed

+68
-56
lines changed

6 files changed

+68
-56
lines changed

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ fn decode_side_tables(dcx: &DecodeContext,
16551655
c::tag_table_tcache => {
16561656
let type_scheme = val_dsr.read_type_scheme(dcx);
16571657
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
1658-
dcx.tcx.tcache.borrow_mut().insert(lid, type_scheme);
1658+
dcx.tcx.register_item_type(lid, type_scheme);
16591659
}
16601660
c::tag_table_param_defs => {
16611661
let bounds = val_dsr.read_type_param_def(dcx);

src/librustc/middle/ty.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,10 +3180,10 @@ impl ClosureKind {
31803180

31813181
impl<'tcx> CommonTypes<'tcx> {
31823182
fn new(arena: &'tcx TypedArena<TyS<'tcx>>,
3183-
interner: &mut FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>)
3183+
interner: &RefCell<FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>>)
31843184
-> CommonTypes<'tcx>
31853185
{
3186-
let mut mk = |sty| ctxt::intern_ty(arena, interner, sty);
3186+
let mk = |sty| ctxt::intern_ty(arena, interner, sty);
31873187
CommonTypes {
31883188
bool: mk(TyBool),
31893189
char: mk(TyChar),
@@ -3412,12 +3412,12 @@ impl<'tcx> ctxt<'tcx> {
34123412
f: F) -> (Session, R)
34133413
where F: FnOnce(&ctxt<'tcx>) -> R
34143414
{
3415-
let mut interner = FnvHashMap();
3416-
let common_types = CommonTypes::new(&arenas.type_, &mut interner);
3415+
let interner = RefCell::new(FnvHashMap());
3416+
let common_types = CommonTypes::new(&arenas.type_, &interner);
34173417

34183418
tls::enter(ctxt {
34193419
arenas: arenas,
3420-
interner: RefCell::new(interner),
3420+
interner: interner,
34213421
substs_interner: RefCell::new(FnvHashMap()),
34223422
bare_fn_interner: RefCell::new(FnvHashMap()),
34233423
region_interner: RefCell::new(FnvHashMap()),
@@ -3545,35 +3545,37 @@ impl<'tcx> ctxt<'tcx> {
35453545
}
35463546

35473547
fn intern_ty(type_arena: &'tcx TypedArena<TyS<'tcx>>,
3548-
interner: &mut FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>,
3548+
interner: &RefCell<FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>>,
35493549
st: TypeVariants<'tcx>)
35503550
-> Ty<'tcx> {
3551-
match interner.get(&st) {
3552-
Some(ty) => return *ty,
3553-
_ => ()
3554-
}
3551+
let ty: Ty /* don't be &mut TyS */ = {
3552+
let mut interner = interner.borrow_mut();
3553+
match interner.get(&st) {
3554+
Some(ty) => return *ty,
3555+
_ => ()
3556+
}
35553557

3556-
let flags = FlagComputation::for_sty(&st);
3558+
let flags = FlagComputation::for_sty(&st);
3559+
3560+
let ty = match () {
3561+
() => type_arena.alloc(TyS { sty: st,
3562+
flags: Cell::new(flags.flags),
3563+
region_depth: flags.depth, }),
3564+
};
35573565

3558-
let ty = match () {
3559-
() => type_arena.alloc(TyS { sty: st,
3560-
flags: Cell::new(flags.flags),
3561-
region_depth: flags.depth, }),
3566+
interner.insert(InternedTy { ty: ty }, ty);
3567+
ty
35623568
};
35633569

35643570
debug!("Interned type: {:?} Pointer: {:?}",
35653571
ty, ty as *const TyS);
3566-
3567-
interner.insert(InternedTy { ty: ty }, ty);
3568-
35693572
ty
35703573
}
35713574

35723575
// Interns a type/name combination, stores the resulting box in cx.interner,
35733576
// and returns the box as cast to an unsafe ptr (see comments for Ty above).
35743577
pub fn mk_ty(&self, st: TypeVariants<'tcx>) -> Ty<'tcx> {
3575-
let mut interner = self.interner.borrow_mut();
3576-
ctxt::intern_ty(&self.arenas.type_, &mut *interner, st)
3578+
ctxt::intern_ty(&self.arenas.type_, &self.interner, st)
35773579
}
35783580

35793581
pub fn mk_mach_int(&self, tm: ast::IntTy) -> Ty<'tcx> {
@@ -5914,6 +5916,10 @@ impl<'tcx> ctxt<'tcx> {
59145916
.clone()
59155917
}
59165918

5919+
// Register a given item type
5920+
pub fn register_item_type(&self, did: ast::DefId, ty: TypeScheme<'tcx>) {
5921+
self.tcache.borrow_mut().insert(did, ty);
5922+
}
59175923

59185924
// If the given item is in an external crate, looks up its type and adds it to
59195925
// the type cache. Returns the type parameters and type.
@@ -5990,8 +5996,8 @@ impl<'tcx> ctxt<'tcx> {
59905996
if id.krate == ast::LOCAL_CRATE {
59915997
self.node_id_to_type(id.node)
59925998
} else {
5993-
let mut tcache = self.tcache.borrow_mut();
5994-
tcache.entry(id).or_insert_with(|| csearch::get_field_type(self, struct_id, id)).ty
5999+
memoized(&self.tcache, id,
6000+
|id| csearch::get_field_type(self, struct_id, id)).ty
59956001
}
59966002
}
59976003

src/librustc/util/ppaux.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,15 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
680680
TyError => write!(f, "[type error]"),
681681
TyParam(ref param_ty) => write!(f, "{}", param_ty),
682682
TyEnum(did, substs) | TyStruct(did, substs) => {
683-
parameterized(f, substs, did, &[],
684-
|tcx| tcx.lookup_item_type(did).generics)
683+
ty::tls::with(|tcx| {
684+
if did.krate == ast::LOCAL_CRATE &&
685+
!tcx.tcache.borrow().contains_key(&did) {
686+
write!(f, "{}<..>", tcx.item_path_str(did))
687+
} else {
688+
parameterized(f, substs, did, &[],
689+
|tcx| tcx.lookup_item_type(did).generics)
690+
}
691+
})
685692
}
686693
TyTrait(ref data) => write!(f, "{}", data),
687694
ty::TyProjection(ref data) => write!(f, "{}", data),

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
40014001
let inh = static_inherited_fields(ccx, &tables);
40024002
let rty = ccx.tcx.node_id_to_type(id);
40034003
let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id);
4004-
let declty = fcx.ccx.tcx.tcache.borrow().get(&local_def(id)).unwrap().ty;
4004+
let declty = fcx.ccx.tcx.lookup_item_type(local_def(id)).ty;
40054005
check_const_with_ty(&fcx, sp, e, declty);
40064006
}
40074007

src/librustc_typeck/coherence/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
214214
};
215215
debug!("new_polytype={:?}", new_polytype);
216216

217-
tcx.tcache.borrow_mut().insert(new_did, new_polytype);
217+
tcx.register_item_type(new_did, new_polytype);
218218
tcx.predicates.borrow_mut().insert(new_did, new_method_ty.predicates.clone());
219219
tcx.impl_or_trait_items
220220
.borrow_mut()

src/librustc_typeck/collect.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
596596
ty: result_ty
597597
};
598598

599-
tcx.tcache.borrow_mut().insert(variant_def_id, variant_scheme.clone());
599+
tcx.register_item_type(variant_def_id, variant_scheme.clone());
600600
tcx.predicates.borrow_mut().insert(variant_def_id, enum_predicates.clone());
601601
write_ty_to_tcx(tcx, variant.node.id, result_ty);
602602
}
@@ -635,7 +635,7 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
635635
ccx.tcx.mk_bare_fn(ty_method.fty.clone()));
636636
debug!("method {} (id {}) has type {:?}",
637637
ident, id, fty);
638-
ccx.tcx.tcache.borrow_mut().insert(def_id,TypeScheme {
638+
ccx.tcx.register_item_type(def_id, TypeScheme {
639639
generics: ty_method.generics.clone(),
640640
ty: fty
641641
});
@@ -661,11 +661,11 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
661661
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
662662

663663
/* add the field to the tcache */
664-
ccx.tcx.tcache.borrow_mut().insert(local_def(v.node.id),
665-
ty::TypeScheme {
666-
generics: struct_generics.clone(),
667-
ty: tt
668-
});
664+
ccx.tcx.register_item_type(local_def(v.node.id),
665+
ty::TypeScheme {
666+
generics: struct_generics.clone(),
667+
ty: tt
668+
});
669669
ccx.tcx.predicates.borrow_mut().insert(local_def(v.node.id),
670670
struct_predicates.clone());
671671

@@ -841,9 +841,9 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) {
841841
let selfty = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, &**selfty);
842842
write_ty_to_tcx(tcx, it.id, selfty);
843843

844-
tcx.tcache.borrow_mut().insert(local_def(it.id),
845-
TypeScheme { generics: ty_generics.clone(),
846-
ty: selfty });
844+
tcx.register_item_type(local_def(it.id),
845+
TypeScheme { generics: ty_generics.clone(),
846+
ty: selfty });
847847
tcx.predicates.borrow_mut().insert(local_def(it.id),
848848
ty_predicates.clone());
849849

@@ -863,11 +863,11 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) {
863863
if let ast::ConstImplItem(ref ty, ref expr) = impl_item.node {
864864
let ty = ccx.icx(&ty_predicates)
865865
.to_ty(&ExplicitRscope, &*ty);
866-
tcx.tcache.borrow_mut().insert(local_def(impl_item.id),
867-
TypeScheme {
868-
generics: ty_generics.clone(),
869-
ty: ty,
870-
});
866+
tcx.register_item_type(local_def(impl_item.id),
867+
TypeScheme {
868+
generics: ty_generics.clone(),
869+
ty: ty,
870+
});
871871
convert_associated_const(ccx, ImplContainer(local_def(it.id)),
872872
impl_item.ident, impl_item.id,
873873
impl_item.vis.inherit_from(parent_visibility),
@@ -954,11 +954,11 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) {
954954
ast::ConstTraitItem(ref ty, ref default) => {
955955
let ty = ccx.icx(&trait_predicates)
956956
.to_ty(&ExplicitRscope, ty);
957-
tcx.tcache.borrow_mut().insert(local_def(trait_item.id),
958-
TypeScheme {
959-
generics: trait_def.generics.clone(),
960-
ty: ty,
961-
});
957+
tcx.register_item_type(local_def(trait_item.id),
958+
TypeScheme {
959+
generics: trait_def.generics.clone(),
960+
ty: ty,
961+
});
962962
convert_associated_const(ccx, TraitContainer(local_def(it.id)),
963963
trait_item.ident, trait_item.id,
964964
ast::Public, ty, default.as_ref().map(|d| &**d));
@@ -1099,26 +1099,25 @@ fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10991099
// Enum-like.
11001100
write_ty_to_tcx(tcx, ctor_id, selfty);
11011101

1102-
tcx.tcache.borrow_mut().insert(local_def(ctor_id), scheme);
1102+
tcx.register_item_type(local_def(ctor_id), scheme);
11031103
tcx.predicates.borrow_mut().insert(local_def(ctor_id), predicates);
11041104
} else if struct_def.fields[0].node.kind.is_unnamed() {
11051105
// Tuple-like.
11061106
let inputs: Vec<_> =
11071107
struct_def.fields
11081108
.iter()
1109-
.map(|field| tcx.tcache.borrow().get(&local_def(field.node.id))
1110-
.unwrap()
1111-
.ty)
1109+
.map(|field| tcx.lookup_item_type(
1110+
local_def(field.node.id)).ty)
11121111
.collect();
11131112
let ctor_fn_ty = tcx.mk_ctor_fn(local_def(ctor_id),
11141113
&inputs[..],
11151114
selfty);
11161115
write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty);
1117-
tcx.tcache.borrow_mut().insert(local_def(ctor_id),
1118-
TypeScheme {
1119-
generics: scheme.generics,
1120-
ty: ctor_fn_ty
1121-
});
1116+
tcx.register_item_type(local_def(ctor_id),
1117+
TypeScheme {
1118+
generics: scheme.generics,
1119+
ty: ctor_fn_ty
1120+
});
11221121
tcx.predicates.borrow_mut().insert(local_def(ctor_id), predicates);
11231122
}
11241123
}

0 commit comments

Comments
 (0)