Skip to content

Commit 4b31b5b

Browse files
committed
Rollup merge of rust-lang#49030 - Zoxc:misc, r=michaelwoerister
Misc changes from my parallel rustc branch r? @michaelwoerister
2 parents f74d01c + e09c2ff commit 4b31b5b

File tree

13 files changed

+60
-65
lines changed

13 files changed

+60
-65
lines changed

src/librustc/middle/const_val.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use graphviz::IntoCow;
1919
use syntax_pos::Span;
2020

2121
use std::borrow::Cow;
22-
use std::rc::Rc;
22+
use rustc_data_structures::sync::Lrc;
2323

2424
pub type EvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, ConstEvalErr<'tcx>>;
2525

@@ -52,7 +52,7 @@ impl<'tcx> ConstVal<'tcx> {
5252
#[derive(Clone, Debug)]
5353
pub struct ConstEvalErr<'tcx> {
5454
pub span: Span,
55-
pub kind: Rc<ErrKind<'tcx>>,
55+
pub kind: Lrc<ErrKind<'tcx>>,
5656
}
5757

5858
#[derive(Clone, Debug)]

src/librustc/traits/query/dropck_outlives.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::iter::FromIterator;
1515
use traits::query::CanonicalTyGoal;
1616
use ty::{self, Ty, TyCtxt};
1717
use ty::subst::Kind;
18-
use std::rc::Rc;
18+
use rustc_data_structures::sync::Lrc;
1919

2020
impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
2121
/// Given a type `ty` of some value being dropped, computes a set
@@ -183,13 +183,13 @@ impl_stable_hash_for!(struct DropckOutlivesResult<'tcx> {
183183

184184
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, DropckOutlivesResult<'tcx>> {
185185
// we ought to intern this, but I'm too lazy just now
186-
type Canonicalized = Rc<Canonical<'gcx, QueryResult<'gcx, DropckOutlivesResult<'gcx>>>>;
186+
type Canonicalized = Lrc<Canonical<'gcx, QueryResult<'gcx, DropckOutlivesResult<'gcx>>>>;
187187

188188
fn intern(
189189
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
190190
value: Canonical<'gcx, Self::Lifted>,
191191
) -> Self::Canonicalized {
192-
Rc::new(value)
192+
Lrc::new(value)
193193
}
194194
}
195195

src/librustc/traits/query/normalize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use infer::at::At;
1717
use infer::canonical::{Canonical, Canonicalize, QueryResult};
1818
use middle::const_val::ConstVal;
1919
use mir::interpret::GlobalId;
20-
use std::rc::Rc;
20+
use rustc_data_structures::sync::Lrc;
2121
use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
2222
use traits::query::CanonicalProjectionGoal;
2323
use traits::project::Normalized;
@@ -259,13 +259,13 @@ impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, ty::Pr
259259

260260
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, NormalizationResult<'tcx>> {
261261
// we ought to intern this, but I'm too lazy just now
262-
type Canonicalized = Rc<Canonical<'gcx, QueryResult<'gcx, NormalizationResult<'gcx>>>>;
262+
type Canonicalized = Lrc<Canonical<'gcx, QueryResult<'gcx, NormalizationResult<'gcx>>>>;
263263

264264
fn intern(
265265
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
266266
value: Canonical<'gcx, Self::Lifted>,
267267
) -> Self::Canonicalized {
268-
Rc::new(value)
268+
Lrc::new(value)
269269
}
270270
}
271271

src/librustc/ty/context.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
161161
-> Ty<'tcx> {
162162
let ty = {
163163
let mut interner = self.type_.borrow_mut();
164-
let global_interner = global_interners.map(|interners| {
165-
interners.type_.borrow_mut()
166-
});
167164
if let Some(&Interned(ty)) = interner.get(&st) {
168165
return ty;
169166
}
167+
let global_interner = global_interners.map(|interners| {
168+
interners.type_.borrow_mut()
169+
});
170170
if let Some(ref interner) = global_interner {
171171
if let Some(&Interned(ty)) = interner.get(&st) {
172172
return ty;
@@ -1010,17 +1010,16 @@ impl<'tcx> InterpretInterner<'tcx> {
10101010
}
10111011
}
10121012

1013-
impl<'tcx> GlobalCtxt<'tcx> {
1013+
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10141014
/// Get the global TyCtxt.
1015-
pub fn global_tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
1015+
#[inline]
1016+
pub fn global_tcx(self) -> TyCtxt<'a, 'gcx, 'gcx> {
10161017
TyCtxt {
1017-
gcx: self,
1018-
interners: &self.global_interners
1018+
gcx: self.gcx,
1019+
interners: &self.gcx.global_interners,
10191020
}
10201021
}
1021-
}
10221022

1023-
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10241023
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
10251024
self.global_arenas.generics.alloc(generics)
10261025
}
@@ -1081,12 +1080,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10811080
self,
10821081
alloc: interpret::Allocation,
10831082
) -> &'gcx interpret::Allocation {
1084-
if let Some(alloc) = self.interpret_interner.inner.borrow().allocs.get(&alloc) {
1083+
let allocs = &mut self.interpret_interner.inner.borrow_mut().allocs;
1084+
if let Some(alloc) = allocs.get(&alloc) {
10851085
return alloc;
10861086
}
10871087

10881088
let interned = self.global_arenas.const_allocs.alloc(alloc);
1089-
if let Some(prev) = self.interpret_interner.inner.borrow_mut().allocs.replace(interned) {
1089+
if let Some(prev) = allocs.replace(interned) {
10901090
bug!("Tried to overwrite interned Allocation: {:#?}", prev)
10911091
}
10921092
interned
@@ -1113,24 +1113,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11131113
}
11141114

11151115
pub fn intern_stability(self, stab: attr::Stability) -> &'gcx attr::Stability {
1116-
if let Some(st) = self.stability_interner.borrow().get(&stab) {
1116+
let mut stability_interner = self.stability_interner.borrow_mut();
1117+
if let Some(st) = stability_interner.get(&stab) {
11171118
return st;
11181119
}
11191120

11201121
let interned = self.global_interners.arena.alloc(stab);
1121-
if let Some(prev) = self.stability_interner.borrow_mut().replace(interned) {
1122+
if let Some(prev) = stability_interner.replace(interned) {
11221123
bug!("Tried to overwrite interned Stability: {:?}", prev)
11231124
}
11241125
interned
11251126
}
11261127

11271128
pub fn intern_layout(self, layout: LayoutDetails) -> &'gcx LayoutDetails {
1128-
if let Some(layout) = self.layout_interner.borrow().get(&layout) {
1129+
let mut layout_interner = self.layout_interner.borrow_mut();
1130+
if let Some(layout) = layout_interner.get(&layout) {
11291131
return layout;
11301132
}
11311133

11321134
let interned = self.global_arenas.layout.alloc(layout);
1133-
if let Some(prev) = self.layout_interner.borrow_mut().replace(interned) {
1135+
if let Some(prev) = layout_interner.replace(interned) {
11341136
bug!("Tried to overwrite interned Layout: {:?}", prev)
11351137
}
11361138
interned

src/librustc/ty/structural_impls.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use ty::{self, Lift, Ty, TyCtxt};
1818
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1919
use rustc_data_structures::accumulate_vec::AccumulateVec;
2020
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
21+
use rustc_data_structures::sync::Lrc;
2122
use mir::interpret;
2223

2324
use std::rc::Rc;
@@ -465,7 +466,7 @@ impl<'a, 'tcx> Lift<'tcx> for ConstEvalErr<'a> {
465466
tcx.lift(&*self.kind).map(|kind| {
466467
ConstEvalErr {
467468
span: self.span,
468-
kind: Rc::new(kind),
469+
kind: Lrc::new(kind),
469470
}
470471
})
471472
}

src/librustc_data_structures/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ pub mod flock;
7676
pub mod sync;
7777
pub mod owning_ref;
7878

79+
pub struct OnDrop<F: Fn()>(pub F);
80+
81+
impl<F: Fn()> Drop for OnDrop<F> {
82+
fn drop(&mut self) {
83+
(self.0)();
84+
}
85+
}
86+
7987
// See comments in src/librustc/lib.rs
8088
#[doc(hidden)]
8189
pub fn __noop_fix_for_27438() {}

src/librustc_data_structures/sync.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
//!
2727
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
2828
//!
29-
//! `rustc_global!` gives us a way to declare variables which are intended to be
30-
//! global for the current rustc session. This currently maps to thread-locals,
31-
//! since rustdoc uses the rustc libraries in multiple threads.
32-
//! These globals should eventually be moved into the `Session` structure.
33-
//!
3429
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
3530
//! depending on the value of cfg!(parallel_queries).
3631
@@ -228,31 +223,6 @@ pub fn assert_sync<T: ?Sized + Sync>() {}
228223
pub fn assert_send_val<T: ?Sized + Send>(_t: &T) {}
229224
pub fn assert_send_sync_val<T: ?Sized + Sync + Send>(_t: &T) {}
230225

231-
#[macro_export]
232-
#[allow_internal_unstable]
233-
macro_rules! rustc_global {
234-
// empty (base case for the recursion)
235-
() => {};
236-
237-
// process multiple declarations
238-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
239-
thread_local!($(#[$attr])* $vis static $name: $t = $init);
240-
rustc_global!($($rest)*);
241-
);
242-
243-
// handle a single declaration
244-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
245-
thread_local!($(#[$attr])* $vis static $name: $t = $init);
246-
);
247-
}
248-
249-
#[macro_export]
250-
macro_rules! rustc_access_global {
251-
($name:path, $callback:expr) => {
252-
$name.with($callback)
253-
}
254-
}
255-
256226
impl<T: Copy + Debug> Debug for LockCell<T> {
257227
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
258228
f.debug_struct("LockCell")
@@ -363,6 +333,13 @@ impl<T> Lock<T> {
363333
}
364334
}
365335

336+
impl<T: Default> Default for Lock<T> {
337+
#[inline]
338+
fn default() -> Self {
339+
Lock::new(T::default())
340+
}
341+
}
342+
366343
// FIXME: Probably a bad idea
367344
impl<T: Clone> Clone for Lock<T> {
368345
#[inline]

src/librustc_mir/interpret/const_eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{Place, EvalContext, StackPopCleanup, ValTy, PlaceExtra, Memory};
1414

1515
use std::fmt;
1616
use std::error::Error;
17-
use std::rc::Rc;
17+
use rustc_data_structures::sync::Lrc;
1818

1919
pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
2020
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -485,7 +485,7 @@ pub fn const_eval_provider<'a, 'tcx>(
485485
// Do match-check before building MIR
486486
if tcx.check_match(def_id).is_err() {
487487
return Err(ConstEvalErr {
488-
kind: Rc::new(CheckMatchError),
488+
kind: Lrc::new(CheckMatchError),
489489
span,
490490
});
491491
}
@@ -497,7 +497,7 @@ pub fn const_eval_provider<'a, 'tcx>(
497497
// Do not continue into miri if typeck errors occurred; it will fail horribly
498498
if tables.tainted_by_errors {
499499
return Err(ConstEvalErr {
500-
kind: Rc::new(TypeckError),
500+
kind: Lrc::new(TypeckError),
501501
span,
502502
});
503503
}

src/librustc_traits/dropck_outlives.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use rustc::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResu
1616
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
1717
use rustc::ty::subst::Subst;
1818
use rustc::util::nodemap::FxHashSet;
19-
use std::rc::Rc;
19+
use rustc_data_structures::sync::Lrc;
2020
use syntax::codemap::{Span, DUMMY_SP};
2121
use util;
2222

2323
crate fn dropck_outlives<'tcx>(
2424
tcx: TyCtxt<'_, 'tcx, 'tcx>,
2525
goal: CanonicalTyGoal<'tcx>,
26-
) -> Result<Rc<Canonical<'tcx, QueryResult<'tcx, DropckOutlivesResult<'tcx>>>>, NoSolution> {
26+
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, DropckOutlivesResult<'tcx>>>>, NoSolution> {
2727
debug!("dropck_outlives(goal={:#?})", goal);
2828

2929
tcx.infer_ctxt().enter(|ref infcx| {

src/librustc_traits/normalize_projection_ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use rustc::traits::{self, FulfillmentContext, Normalized, ObligationCause,
1414
use rustc::traits::query::{CanonicalProjectionGoal, NoSolution, normalize::NormalizationResult};
1515
use rustc::ty::{ParamEnvAnd, TyCtxt};
1616
use rustc::util::common::CellUsizeExt;
17-
use std::rc::Rc;
17+
use rustc_data_structures::sync::Lrc;
1818
use syntax::ast::DUMMY_NODE_ID;
1919
use syntax_pos::DUMMY_SP;
2020
use util;
2121

2222
crate fn normalize_projection_ty<'tcx>(
2323
tcx: TyCtxt<'_, 'tcx, 'tcx>,
2424
goal: CanonicalProjectionGoal<'tcx>,
25-
) -> Result<Rc<Canonical<'tcx, QueryResult<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
25+
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
2626
debug!("normalize_provider(goal={:#?})", goal);
2727

2828
tcx.sess.perf_stats.normalize_projection_ty.increment();

src/libsyntax_pos/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@ impl SpanData {
184184
}
185185
}
186186

187-
// The interner in thread-local, so `Span` shouldn't move between threads.
187+
// The interner is pointed to by a thread local value which is only set on the main thread
188+
// with parallelization is disabled. So we don't allow Span to transfer between threads
189+
// to avoid panics and other errors, even though it would be memory safe to do so.
190+
#[cfg(not(parallel_queries))]
188191
impl !Send for Span {}
192+
#[cfg(not(parallel_queries))]
189193
impl !Sync for Span {}
190194

191195
impl PartialOrd for Span {

src/libsyntax_pos/symbol.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ impl Decodable for Ident {
8383
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8484
pub struct Symbol(u32);
8585

86-
// The interner in thread-local, so `Symbol` shouldn't move between threads.
86+
// The interner is pointed to by a thread local value which is only set on the main thread
87+
// with parallelization is disabled. So we don't allow Symbol to transfer between threads
88+
// to avoid panics and other errors, even though it would be memory safe to do so.
89+
#[cfg(not(parallel_queries))]
8790
impl !Send for Symbol { }
91+
#[cfg(not(parallel_queries))]
8892
impl !Sync for Symbol { }
8993

9094
impl Symbol {

src/test/run-pass-fulldeps/issue-35829.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use syntax::ext::expand::ExpansionConfig;
2020
use syntax::parse::ParseSess;
2121
use syntax::codemap::{FilePathMapping, dummy_spanned};
2222
use syntax::print::pprust::expr_to_string;
23-
use syntax::ast::{Expr, ExprKind, LitKind, StrStyle, RangeLimits};
24-
use syntax::symbol::Symbol;
23+
use syntax::ast::{ExprKind, LitKind, RangeLimits};
2524
use syntax::ptr::P;
2625

2726
use rustc_data_structures::sync::Lrc;

0 commit comments

Comments
 (0)