Auto merge of #46709 - Zoxc:par-merge, r=arielb1
Add sync module to rustc_data_structures This PR is split out from https://github.com/rust-lang/rust/pull/45912, since github apparently can't handle such large PRs. r? @arielb1
This commit is contained in:
commit
af57acef1c
38
src/Cargo.lock
generated
38
src/Cargo.lock
generated
@ -1313,6 +1313,27 @@ dependencies = [
|
||||
"unwind 0.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot_core 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "1.0.1"
|
||||
@ -1649,7 +1670,6 @@ dependencies = [
|
||||
"graphviz 0.0.0",
|
||||
"jobserver 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_apfloat 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
"rustc_const_math 0.0.0",
|
||||
@ -1773,8 +1793,12 @@ dependencies = [
|
||||
name = "rustc_data_structures"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot_core 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serialize 0.0.0",
|
||||
"stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1786,7 +1810,6 @@ dependencies = [
|
||||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"graphviz 0.0.0",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc_allocator 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
@ -1874,7 +1897,6 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc_macro 0.0.0",
|
||||
"rustc 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
@ -1993,7 +2015,6 @@ dependencies = [
|
||||
"jobserver 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_allocator 0.0.0",
|
||||
@ -2020,7 +2041,6 @@ dependencies = [
|
||||
"ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
@ -2228,6 +2248,11 @@ name = "smallvec"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.2.4"
|
||||
@ -2820,6 +2845,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum openssl-sys 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5483bdc56756041ba6aa37c9cb59cc2219f012a2a1377d97ad35556ac6676ee7"
|
||||
"checksum os_pipe 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "998bfbb3042e715190fe2a41abfa047d7e8cb81374d2977d7f100eacd8619cb1"
|
||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||
"checksum parking_lot 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3e7f7c9857874e54afeb950eebeae662b1e51a2493666d2ea4c0a5d91dcf0412"
|
||||
"checksum parking_lot_core 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "12d20aac4f67aa75f681aded784bac91f910ba3f2af1812573cdcf687414e122"
|
||||
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
|
||||
"checksum pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6dda33d67c26f0aac90d324ab2eb7239c819fc7b2552fe9faa4fe88441edc8"
|
||||
"checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc"
|
||||
@ -2871,6 +2898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum shell-escape 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dd5cc96481d54583947bfe88bf30c23d53f883c6cd0145368b69989d97b84ef8"
|
||||
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
|
||||
"checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e"
|
||||
"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9"
|
||||
"checksum socket2 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "36b4896961171cd3317c7e9603d88f379f8c6e45342212235d356496680c68fd"
|
||||
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
|
||||
"checksum string_cache 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "413fc7852aeeb5472f1986ef755f561ddf0c789d3d796e65f0b6fe293ecd4ef8"
|
||||
|
@ -265,6 +265,10 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() {
|
||||
cmd.arg("--cfg").arg("parallel_queries");
|
||||
}
|
||||
|
||||
let color = match env::var("RUSTC_COLOR") {
|
||||
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
|
||||
Err(_) => 0,
|
||||
|
@ -561,6 +561,9 @@ pub fn rustc_cargo(build: &Build,
|
||||
if let Some(ref s) = build.config.rustc_default_linker {
|
||||
cargo.env("CFG_DEFAULT_LINKER", s);
|
||||
}
|
||||
if build.config.rustc_parallel_queries {
|
||||
cargo.env("RUSTC_PARALLEL_QUERIES", "1");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -87,6 +87,7 @@ pub struct Config {
|
||||
pub rust_debuginfo_lines: bool,
|
||||
pub rust_debuginfo_only_std: bool,
|
||||
pub rust_rpath: bool,
|
||||
pub rustc_parallel_queries: bool,
|
||||
pub rustc_default_linker: Option<String>,
|
||||
pub rust_optimize_tests: bool,
|
||||
pub rust_debuginfo_tests: bool,
|
||||
@ -266,6 +267,7 @@ struct Rust {
|
||||
debuginfo: Option<bool>,
|
||||
debuginfo_lines: Option<bool>,
|
||||
debuginfo_only_std: Option<bool>,
|
||||
experimental_parallel_queries: Option<bool>,
|
||||
debug_jemalloc: Option<bool>,
|
||||
use_jemalloc: Option<bool>,
|
||||
backtrace: Option<bool>,
|
||||
@ -474,6 +476,7 @@ impl Config {
|
||||
set(&mut config.rust_dist_src, rust.dist_src);
|
||||
set(&mut config.quiet_tests, rust.quiet_tests);
|
||||
set(&mut config.test_miri, rust.test_miri);
|
||||
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
|
||||
config.rustc_default_linker = rust.default_linker.clone();
|
||||
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
|
||||
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
|
||||
|
@ -15,7 +15,6 @@ fmt_macros = { path = "../libfmt_macros" }
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
jobserver = "0.1"
|
||||
log = "0.3"
|
||||
owning_ref = "0.3.3"
|
||||
rustc_apfloat = { path = "../librustc_apfloat" }
|
||||
rustc_back = { path = "../librustc_back" }
|
||||
rustc_const_math = { path = "../librustc_const_math" }
|
||||
|
@ -77,7 +77,6 @@ extern crate getopts;
|
||||
extern crate graphviz;
|
||||
#[cfg(windows)]
|
||||
extern crate libc;
|
||||
extern crate owning_ref;
|
||||
extern crate rustc_back;
|
||||
#[macro_use] extern crate rustc_data_structures;
|
||||
extern crate serialize;
|
||||
|
@ -38,7 +38,7 @@ use std::any::Any;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::Rc;
|
||||
use owning_ref::ErasedBoxRef;
|
||||
use rustc_data_structures::owning_ref::ErasedBoxRef;
|
||||
use syntax::ast;
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
use syntax::symbol::Symbol;
|
||||
|
@ -11,3 +11,10 @@ crate-type = ["dylib"]
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
serialize = { path = "../libserialize" }
|
||||
cfg-if = "0.1.2"
|
||||
stable_deref_trait = "1.0.0"
|
||||
parking_lot_core = "0.2.8"
|
||||
|
||||
[dependencies.parking_lot]
|
||||
version = "0.5"
|
||||
features = ["nightly"]
|
@ -31,7 +31,10 @@
|
||||
#![feature(i128)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(specialization)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(underscore_lifetimes)]
|
||||
#![feature(macro_vis_matcher)]
|
||||
#![feature(allow_internal_unstable)]
|
||||
|
||||
#![cfg_attr(unix, feature(libc))]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
@ -42,6 +45,10 @@ extern crate log;
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
#[cfg(unix)]
|
||||
extern crate libc;
|
||||
extern crate parking_lot;
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
extern crate stable_deref_trait;
|
||||
|
||||
pub use rustc_serialize::hex::ToHex;
|
||||
|
||||
@ -67,6 +74,8 @@ pub mod tuple_slice;
|
||||
pub mod veccell;
|
||||
pub mod control_flow_graph;
|
||||
pub mod flock;
|
||||
pub mod sync;
|
||||
pub mod owning_ref;
|
||||
|
||||
// See comments in src/librustc/lib.rs
|
||||
#[doc(hidden)]
|
||||
|
21
src/librustc_data_structures/owning_ref/LICENSE
Normal file
21
src/librustc_data_structures/owning_ref/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marvin Löbel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1902
src/librustc_data_structures/owning_ref/mod.rs
Normal file
1902
src/librustc_data_structures/owning_ref/mod.rs
Normal file
File diff suppressed because it is too large
Load Diff
403
src/librustc_data_structures/sync.rs
Normal file
403
src/librustc_data_structures/sync.rs
Normal file
@ -0,0 +1,403 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! This mdoule defines types which are thread safe if cfg!(parallel_queries) is true.
|
||||
//!
|
||||
//! `Lrc` is an alias of either Rc or Arc.
|
||||
//!
|
||||
//! `Lock` is a mutex.
|
||||
//! It internally uses `parking_lot::Mutex` if cfg!(parallel_queries) is true,
|
||||
//! `RefCell` otherwise.
|
||||
//!
|
||||
//! `RwLock` is a read-write lock.
|
||||
//! It internally uses `parking_lot::RwLock` if cfg!(parallel_queries) is true,
|
||||
//! `RefCell` otherwise.
|
||||
//!
|
||||
//! `LockCell` is a thread safe version of `Cell`, with `set` and `get` operations.
|
||||
//! It can never deadlock. It uses `Cell` when
|
||||
//! cfg!(parallel_queries) is false, otherwise it is a `Lock`.
|
||||
//!
|
||||
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
|
||||
//!
|
||||
//! `rustc_global!` gives us a way to declare variables which are intended to be
|
||||
//! global for the current rustc session. This currently maps to thread-locals,
|
||||
//! since rustdoc uses the rustc libraries in multiple threads.
|
||||
//! These globals should eventually be moved into the `Session` structure.
|
||||
//!
|
||||
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
|
||||
//! depending on the value of cfg!(parallel_queries).
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Formatter;
|
||||
use std::fmt;
|
||||
use owning_ref::{Erased, OwningRef};
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(not(parallel_queries))] {
|
||||
pub auto trait Send {}
|
||||
pub auto trait Sync {}
|
||||
|
||||
impl<T: ?Sized> Send for T {}
|
||||
impl<T: ?Sized> Sync for T {}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rustc_erase_owner {
|
||||
($v:expr) => {
|
||||
$v.erase_owner()
|
||||
}
|
||||
}
|
||||
|
||||
pub type MetadataRef = OwningRef<Box<Erased>, [u8]>;
|
||||
|
||||
pub use std::rc::Rc as Lrc;
|
||||
pub use std::cell::Ref as ReadGuard;
|
||||
pub use std::cell::RefMut as WriteGuard;
|
||||
pub use std::cell::RefMut as LockGuard;
|
||||
|
||||
pub use std::cell::RefCell as RwLock;
|
||||
use std::cell::RefCell as InnerLock;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MTLock<T>(T);
|
||||
|
||||
impl<T> MTLock<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
MTLock(inner)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn lock(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow_mut(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Probably a bad idea (in the threaded case)
|
||||
impl<T: Clone> Clone for MTLock<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
MTLock(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LockCell<T>(Cell<T>);
|
||||
|
||||
impl<T> LockCell<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
LockCell(Cell::new(inner))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0.into_inner()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set(&self, new_inner: T) {
|
||||
self.0.set(new_inner);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get(&self) -> T where T: Copy {
|
||||
self.0.get()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_mut(&mut self, new_inner: T) {
|
||||
self.0.set(new_inner);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&mut self) -> T where T: Copy {
|
||||
self.0.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> LockCell<Option<T>> {
|
||||
#[inline(always)]
|
||||
pub fn take(&self) -> Option<T> {
|
||||
unsafe { (*self.0.as_ptr()).take() }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pub use std::marker::Send as Send;
|
||||
pub use std::marker::Sync as Sync;
|
||||
|
||||
pub use parking_lot::RwLockReadGuard as ReadGuard;
|
||||
pub use parking_lot::RwLockWriteGuard as WriteGuard;
|
||||
|
||||
pub use parking_lot::MutexGuard as LockGuard;
|
||||
|
||||
use parking_lot;
|
||||
|
||||
pub use std::sync::Arc as Lrc;
|
||||
|
||||
pub use self::Lock as MTLock;
|
||||
|
||||
use parking_lot::Mutex as InnerLock;
|
||||
|
||||
pub type MetadataRef = OwningRef<Box<Erased + Send + Sync>, [u8]>;
|
||||
|
||||
/// This makes locks panic if they are already held.
|
||||
/// It is only useful when you are running in a single thread
|
||||
const ERROR_CHECKING: bool = false;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rustc_erase_owner {
|
||||
($v:expr) => {{
|
||||
let v = $v;
|
||||
::rustc_data_structures::sync::assert_send_sync_val(&v);
|
||||
v.erase_send_sync_owner()
|
||||
}}
|
||||
}
|
||||
|
||||
pub struct LockCell<T>(Lock<T>);
|
||||
|
||||
impl<T> LockCell<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
LockCell(Lock::new(inner))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0.into_inner()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set(&self, new_inner: T) {
|
||||
*self.0.lock() = new_inner;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get(&self) -> T where T: Copy {
|
||||
*self.0.lock()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_mut(&mut self, new_inner: T) {
|
||||
*self.0.get_mut() = new_inner;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&mut self) -> T where T: Copy {
|
||||
*self.0.get_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> LockCell<Option<T>> {
|
||||
#[inline(always)]
|
||||
pub fn take(&self) -> Option<T> {
|
||||
self.0.lock().take()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RwLock<T>(parking_lot::RwLock<T>);
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
RwLock(parking_lot::RwLock::new(inner))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow(&self) -> ReadGuard<T> {
|
||||
if ERROR_CHECKING {
|
||||
self.0.try_read().expect("lock was already held")
|
||||
} else {
|
||||
self.0.read()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow_mut(&self) -> WriteGuard<T> {
|
||||
if ERROR_CHECKING {
|
||||
self.0.try_write().expect("lock was already held")
|
||||
} else {
|
||||
self.0.write()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Probably a bad idea
|
||||
impl<T: Clone> Clone for RwLock<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
RwLock::new(self.borrow().clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_sync<T: ?Sized + Sync>() {}
|
||||
pub fn assert_send_sync_val<T: ?Sized + Sync + Send>(_t: &T) {}
|
||||
|
||||
#[macro_export]
|
||||
#[allow_internal_unstable]
|
||||
macro_rules! rustc_global {
|
||||
// empty (base case for the recursion)
|
||||
() => {};
|
||||
|
||||
// process multiple declarations
|
||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
|
||||
thread_local!($(#[$attr])* $vis static $name: $t = $init);
|
||||
rustc_global!($($rest)*);
|
||||
);
|
||||
|
||||
// handle a single declaration
|
||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
|
||||
thread_local!($(#[$attr])* $vis static $name: $t = $init);
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rustc_access_global {
|
||||
($name:path, $callback:expr) => {
|
||||
$name.with($callback)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Debug> Debug for LockCell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
f.debug_struct("LockCell")
|
||||
.field("value", &self.get())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Default> Default for LockCell<T> {
|
||||
/// Creates a `LockCell<T>`, with the `Default` value for T.
|
||||
#[inline]
|
||||
fn default() -> LockCell<T> {
|
||||
LockCell::new(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:PartialEq + Copy> PartialEq for LockCell<T> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &LockCell<T>) -> bool {
|
||||
self.get() == other.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Eq + Copy> Eq for LockCell<T> {}
|
||||
|
||||
impl<T:PartialOrd + Copy> PartialOrd for LockCell<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &LockCell<T>) -> Option<Ordering> {
|
||||
self.get().partial_cmp(&other.get())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn lt(&self, other: &LockCell<T>) -> bool {
|
||||
self.get() < other.get()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn le(&self, other: &LockCell<T>) -> bool {
|
||||
self.get() <= other.get()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn gt(&self, other: &LockCell<T>) -> bool {
|
||||
self.get() > other.get()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ge(&self, other: &LockCell<T>) -> bool {
|
||||
self.get() >= other.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Ord + Copy> Ord for LockCell<T> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &LockCell<T>) -> Ordering {
|
||||
self.get().cmp(&other.get())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Lock<T>(InnerLock<T>);
|
||||
|
||||
impl<T> Lock<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
Lock(InnerLock::new(inner))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0.into_inner()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
self.0.get_mut()
|
||||
}
|
||||
|
||||
#[cfg(parallel_queries)]
|
||||
#[inline(always)]
|
||||
pub fn lock(&self) -> LockGuard<T> {
|
||||
if ERROR_CHECKING {
|
||||
self.0.try_lock().expect("lock was already held")
|
||||
} else {
|
||||
self.0.lock()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(parallel_queries))]
|
||||
#[inline(always)]
|
||||
pub fn lock(&self) -> LockGuard<T> {
|
||||
self.0.borrow_mut()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow(&self) -> LockGuard<T> {
|
||||
self.lock()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow_mut(&self) -> LockGuard<T> {
|
||||
self.lock()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Probably a bad idea
|
||||
impl<T: Clone> Clone for Lock<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
Lock::new(self.borrow().clone())
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ crate-type = ["dylib"]
|
||||
arena = { path = "../libarena" }
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
log = { version = "0.3", features = ["release_max_level_info"] }
|
||||
owning_ref = "0.3.3"
|
||||
env_logger = { version = "0.4", default-features = false }
|
||||
rustc = { path = "../librustc" }
|
||||
rustc_allocator = { path = "../librustc_allocator" }
|
||||
|
@ -11,7 +11,6 @@ crate-type = ["dylib"]
|
||||
[dependencies]
|
||||
flate2 = "0.2"
|
||||
log = "0.3"
|
||||
owning_ref = "0.3.3"
|
||||
proc_macro = { path = "../libproc_macro" }
|
||||
rustc = { path = "../librustc" }
|
||||
rustc_back = { path = "../librustc_back" }
|
||||
|
@ -24,7 +24,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet, NodeMap};
|
||||
|
||||
use std::cell::{RefCell, Cell};
|
||||
use std::rc::Rc;
|
||||
use owning_ref::ErasedBoxRef;
|
||||
use rustc_data_structures::owning_ref::ErasedBoxRef;
|
||||
use syntax::{ast, attr};
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
use syntax::symbol::Symbol;
|
||||
|
@ -31,7 +31,6 @@ extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
extern crate flate2;
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
extern crate owning_ref;
|
||||
extern crate rustc_errors as errors;
|
||||
extern crate syntax_ext;
|
||||
extern crate proc_macro;
|
||||
|
@ -243,7 +243,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
|
||||
use flate2::read::DeflateDecoder;
|
||||
use owning_ref::{ErasedBoxRef, OwningRef};
|
||||
use rustc_data_structures::owning_ref::{ErasedBoxRef, OwningRef};
|
||||
|
||||
pub struct CrateMismatch {
|
||||
path: PathBuf,
|
||||
|
@ -15,7 +15,6 @@ flate2 = "0.2"
|
||||
jobserver = "0.1.5"
|
||||
log = "0.3"
|
||||
num_cpus = "1.0"
|
||||
owning_ref = "0.3.3"
|
||||
rustc = { path = "../librustc" }
|
||||
rustc-demangle = "0.1.4"
|
||||
rustc_allocator = { path = "../librustc_allocator" }
|
||||
|
@ -40,7 +40,6 @@ use syntax_pos::symbol::Symbol;
|
||||
extern crate bitflags;
|
||||
extern crate flate2;
|
||||
extern crate libc;
|
||||
extern crate owning_ref;
|
||||
#[macro_use] extern crate rustc;
|
||||
extern crate jobserver;
|
||||
extern crate num_cpus;
|
||||
|
@ -15,7 +15,7 @@ use llvm;
|
||||
use llvm::{False, ObjectFile, mk_section_iter};
|
||||
use llvm::archive_ro::ArchiveRO;
|
||||
|
||||
use owning_ref::{ErasedBoxRef, OwningRef};
|
||||
use rustc_data_structures::owning_ref::{ErasedBoxRef, OwningRef};
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
|
@ -12,7 +12,6 @@ test = false
|
||||
[dependencies]
|
||||
ar = "0.3.0"
|
||||
flate2 = "0.2"
|
||||
owning_ref = "0.3.3"
|
||||
log = "0.3"
|
||||
|
||||
syntax = { path = "../libsyntax" }
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
extern crate ar;
|
||||
extern crate flate2;
|
||||
extern crate owning_ref;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
|
@ -28,7 +28,7 @@ use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::sync::mpsc;
|
||||
|
||||
use owning_ref::{ErasedBoxRef, OwningRef};
|
||||
use rustc_data_structures::owning_ref::{ErasedBoxRef, OwningRef};
|
||||
use ar::{Archive, Builder, Header};
|
||||
use flate2::Compression;
|
||||
use flate2::write::DeflateEncoder;
|
||||
|
@ -56,6 +56,7 @@ fn filter_dirs(path: &Path) -> bool {
|
||||
"src/llvm",
|
||||
"src/libbacktrace",
|
||||
"src/libcompiler_builtins",
|
||||
"src/librustc_data_structures/owning_ref",
|
||||
"src/compiler-rt",
|
||||
"src/liblibc",
|
||||
"src/vendor",
|
||||
|
Loading…
x
Reference in New Issue
Block a user