Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #70198

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0bf5cae
Remove __query_compute module.
cjgillot Mar 6, 2020
fc82376
Make QueryAccessor::dep_kind an associated const.
cjgillot Mar 6, 2020
cf238fd
Inline QueryAccessor::query.
cjgillot Mar 7, 2020
1249032
Move impl of Queries with its definition.
cjgillot Mar 7, 2020
b089433
Unpack type arguments for QueryStateShard.
cjgillot Mar 6, 2020
486a082
Unpack type arguments for QueryLookup.
cjgillot Mar 6, 2020
a0f57e2
Unpack type arguments for QueryState.
cjgillot Mar 6, 2020
fa02dca
Remove Q parameter from QueryCache::lookup.
cjgillot Mar 6, 2020
a18aa81
Remove Q parameter from alloc_self_profile_query_strings_for_query_ca…
cjgillot Mar 6, 2020
d125bbb
Remove Q parameter from query stats.
cjgillot Mar 6, 2020
fa0794d
Remove Q parameter from JobOwner.
cjgillot Mar 7, 2020
5dc7c2e
Remove Q parameter from try_get_cached.
cjgillot Mar 7, 2020
7d84f4f
Offload try_collect_active_jobs.
cjgillot Mar 7, 2020
7309b3c
Simplify type aliases.
cjgillot Mar 7, 2020
57b1e7a
Remove the call that makes miri fail
DutchGhost Mar 16, 2020
3abd475
Make QueryCache parameters associated types.
cjgillot Mar 7, 2020
5557407
Remove QueryState type alias.
cjgillot Mar 7, 2020
dcc2321
The const_forget_box was unused, and doesns't add anything to test by…
DutchGhost Mar 16, 2020
0760803
rather than removing const_forget_box, stick an attribute on it and e…
DutchGhost Mar 16, 2020
8aa1328
Make stuff private.
cjgillot Mar 15, 2020
4c363e3
Move the const-forget test into ui tests
DutchGhost Mar 18, 2020
58c2388
Make the `type_of` return a generic type for generators
Zoxc Jan 14, 2020
13344e5
Update tests
Zoxc Feb 6, 2020
bd6deaa
Derive PartialEq, Eq and Hash for RangeInclusive
Mar 19, 2020
6570e27
Removed unused `Hasher` import.
Mar 19, 2020
fd0e15b
Make std::sync::Arc compatible with ThreadSanitizer
tmiasko Mar 20, 2020
d6f3a43
Update const_forget.rs
DutchGhost Mar 20, 2020
3f6236e
Fix oudated comment for NamedRegionMap
bjorn3 Mar 20, 2020
32670dd
Clean up E0439 explanation
GuillaumeGomez Mar 20, 2020
8044d41
Rollup merge of #65097 - tmiasko:arc, r=Amanieu
Dylan-DPC Mar 20, 2020
7ebc693
Rollup merge of #68884 - Zoxc:gen-type, r=nikomatsakis
Dylan-DPC Mar 20, 2020
0bd02f7
Rollup merge of #69910 - cjgillot:polym, r=Zoxc
Dylan-DPC Mar 20, 2020
d30217c
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
Dylan-DPC Mar 20, 2020
cb57aeb
Rollup merge of #70166 - CDirkx:range-inclusive-derives, r=cramertj
Dylan-DPC Mar 20, 2020
7dcf300
Rollup merge of #70177 - bjorn3:patch-2, r=Dylan-DPC
Dylan-DPC Mar 20, 2020
a416d29
Rollup merge of #70188 - GuillaumeGomez:cleanup-e0439, r=Dylan-DPC
Dylan-DPC Mar 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#![feature(box_into_raw_non_null)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![feature(coerce_unsized)]
#![feature(const_generic_impls_guard)]
Expand Down
25 changes: 21 additions & 4 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ mod tests;
/// necessarily) at _exactly_ `MAX_REFCOUNT + 1` references.
const MAX_REFCOUNT: usize = (isize::MAX) as usize;

#[cfg(not(sanitize = "thread"))]
macro_rules! acquire {
($x:expr) => {
atomic::fence(Acquire)
};
}

// ThreadSanitizer does not support memory fences. To avoid false positive
// reports in Arc / Weak implementation use atomic loads for synchronization
// instead.
#[cfg(sanitize = "thread")]
macro_rules! acquire {
($x:expr) => {
$x.load(Acquire)
};
}

/// A thread-safe reference-counting pointer. 'Arc' stands for 'Atomically
/// Reference Counted'.
///
Expand Down Expand Up @@ -402,7 +419,7 @@ impl<T> Arc<T> {
return Err(this);
}

atomic::fence(Acquire);
acquire!(this.inner().strong);

unsafe {
let elem = ptr::read(&this.ptr.as_ref().data);
Expand Down Expand Up @@ -739,7 +756,7 @@ impl<T: ?Sized> Arc<T> {
ptr::drop_in_place(&mut self.ptr.as_mut().data);

if self.inner().weak.fetch_sub(1, Release) == 1 {
atomic::fence(Acquire);
acquire!(self.inner().weak);
Global.dealloc(self.ptr.cast(), Layout::for_value(self.ptr.as_ref()))
}
}
Expand Down Expand Up @@ -1243,7 +1260,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
//
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
// [2]: (https://github.com/rust-lang/rust/pull/41714)
atomic::fence(Acquire);
acquire!(self.inner().strong);

unsafe {
self.drop_slow();
Expand Down Expand Up @@ -1701,7 +1718,7 @@ impl<T: ?Sized> Drop for Weak<T> {
let inner = if let Some(inner) = self.inner() { inner } else { return };

if inner.weak.fetch_sub(1, Release) == 1 {
atomic::fence(Acquire);
acquire!(inner.weak);
unsafe { Global.dealloc(self.ptr.cast(), Layout::for_value(self.ptr.as_ref())) }
}
}
Expand Down
24 changes: 2 additions & 22 deletions src/libcore/ops/range.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::fmt;
use crate::hash::{Hash, Hasher};
use crate::hash::Hash;

/// An unbounded range (`..`).
///
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
/// ```
#[doc(alias = "..=")]
#[derive(Clone)] // not Copy -- see #27186
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "inclusive_range", since = "1.26.0")]
pub struct RangeInclusive<Idx> {
// Note that the fields here are not public to allow changing the
Expand All @@ -350,26 +350,6 @@ pub struct RangeInclusive<Idx> {
pub(crate) exhausted: bool,
}

#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.start == other.start && self.end == other.end && self.exhausted == other.exhausted
}
}

#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: Eq> Eq for RangeInclusive<Idx> {}

#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: Hash> Hash for RangeInclusive<Idx> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.start.hash(state);
self.end.hash(state);
self.exhausted.hash(state);
}
}

impl<Idx> RangeInclusive<Idx> {
/// Creates a new inclusive range. Equivalent to writing `start..=end`.
///
Expand Down
18 changes: 0 additions & 18 deletions src/libcore/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,3 @@ fn test_discriminant_send_sync() {
is_send_sync::<Discriminant<Regular>>();
is_send_sync::<Discriminant<NotSendSync>>();
}

#[test]
fn test_const_forget() {
const _: () = forget(0i32);
const _: () = forget(Vec::<Vec<Box<i32>>>::new());

// Writing this function signature without const-forget
// triggers compiler errors:
// 1) That we use a non-const fn inside a const fn
// 2) without the forget, it complains about the destructor of Box
const fn const_forget_box<T>(x: Box<T>) {
forget(x);
}

// Call the forget_box at runtime,
// as we can't const-construct a box yet.
const_forget_box(Box::new(0i32));
}
56 changes: 34 additions & 22 deletions src/librustc/ty/query/caches.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,94 @@
use crate::dep_graph::DepNodeIndex;
use crate::ty::query::config::QueryAccessors;
use crate::ty::query::plumbing::{QueryLookup, QueryState, QueryStateShard};
use crate::ty::TyCtxt;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sharded::Sharded;
use std::default::Default;
use std::hash::Hash;
use std::marker::PhantomData;

pub(crate) trait CacheSelector<K, V> {
type Cache: QueryCache<K, V>;
type Cache: QueryCache<Key = K, Value = V>;
}

pub(crate) trait QueryCache<K, V>: Default {
pub(crate) trait QueryCache: Default {
type Key;
type Value;
type Sharded: Default;

/// Checks if the query is already computed and in the cache.
/// It returns the shard index and a lock guard to the shard,
/// which will be used if the query is not in the cache and we need
/// to compute it.
fn lookup<'tcx, R, GetCache, OnHit, OnMiss, Q>(
fn lookup<'tcx, R, GetCache, OnHit, OnMiss>(
&self,
state: &'tcx QueryState<'tcx, Q>,
state: &'tcx QueryState<'tcx, Self>,
get_cache: GetCache,
key: K,
key: Self::Key,
// `on_hit` can be called while holding a lock to the query state shard.
on_hit: OnHit,
on_miss: OnMiss,
) -> R
where
Q: QueryAccessors<'tcx>,
GetCache: for<'a> Fn(&'a mut QueryStateShard<'tcx, Q>) -> &'a mut Self::Sharded,
OnHit: FnOnce(&V, DepNodeIndex) -> R,
OnMiss: FnOnce(K, QueryLookup<'tcx, Q>) -> R;
GetCache: for<'a> Fn(
&'a mut QueryStateShard<'tcx, Self::Key, Self::Sharded>,
) -> &'a mut Self::Sharded,
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
OnMiss: FnOnce(Self::Key, QueryLookup<'tcx, Self::Key, Self::Sharded>) -> R;

fn complete(
&self,
tcx: TyCtxt<'tcx>,
lock_sharded_storage: &mut Self::Sharded,
key: K,
value: V,
key: Self::Key,
value: Self::Value,
index: DepNodeIndex,
);

fn iter<R, L>(
&self,
shards: &Sharded<L>,
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
f: impl for<'a> FnOnce(
Box<dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)> + 'a>,
) -> R,
) -> R;
}

pub struct DefaultCacheSelector;

impl<K: Eq + Hash, V: Clone> CacheSelector<K, V> for DefaultCacheSelector {
type Cache = DefaultCache;
type Cache = DefaultCache<K, V>;
}

#[derive(Default)]
pub struct DefaultCache;
pub struct DefaultCache<K, V>(PhantomData<(K, V)>);

impl<K, V> Default for DefaultCache<K, V> {
fn default() -> Self {
DefaultCache(PhantomData)
}
}

impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
impl<K: Eq + Hash, V: Clone> QueryCache for DefaultCache<K, V> {
type Key = K;
type Value = V;
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;

#[inline(always)]
fn lookup<'tcx, R, GetCache, OnHit, OnMiss, Q>(
fn lookup<'tcx, R, GetCache, OnHit, OnMiss>(
&self,
state: &'tcx QueryState<'tcx, Q>,
state: &'tcx QueryState<'tcx, Self>,
get_cache: GetCache,
key: K,
on_hit: OnHit,
on_miss: OnMiss,
) -> R
where
Q: QueryAccessors<'tcx>,
GetCache: for<'a> Fn(&'a mut QueryStateShard<'tcx, Q>) -> &'a mut Self::Sharded,
GetCache:
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
OnHit: FnOnce(&V, DepNodeIndex) -> R,
OnMiss: FnOnce(K, QueryLookup<'tcx, Q>) -> R,
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R,
{
let mut lookup = state.get_lookup(&key);
let lock = &mut *lookup.lock;
Expand Down
16 changes: 5 additions & 11 deletions src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::dep_graph::SerializedDepNodeIndex;
use crate::dep_graph::{DepKind, DepNode};
use crate::ty::query::caches::QueryCache;
use crate::ty::query::plumbing::CycleError;
use crate::ty::query::{Query, QueryState};
use crate::ty::query::QueryState;
use crate::ty::TyCtxt;
use rustc_data_structures::profiling::ProfileCategory;
use rustc_hir::def_id::DefId;
Expand All @@ -28,18 +28,15 @@ pub trait QueryConfig<'tcx> {
pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
const ANON: bool;
const EVAL_ALWAYS: bool;
const DEP_KIND: DepKind;

type Cache: QueryCache<Self::Key, Self::Value>;

fn query(key: Self::Key) -> Query<'tcx>;
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: TyCtxt<'tcx>) -> &'a QueryState<'tcx, Self>;
fn query_state<'a>(tcx: TyCtxt<'tcx>) -> &'a QueryState<'tcx, Self::Cache>;

fn to_dep_node(tcx: TyCtxt<'tcx>, key: &Self::Key) -> DepNode;

fn dep_kind() -> DepKind;

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value;

Expand All @@ -62,10 +59,7 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
}
}

impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M
where
<M as QueryAccessors<'tcx>>::Cache: QueryCache<DefId, <M as QueryConfig<'tcx>>::Value>,
{
impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M {
default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> {
if !tcx.sess.verbose() {
format!("processing `{}`", tcx.def_path_str(def_id)).into()
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::ops::Deref;
use std::sync::Arc;

#[macro_use]
mod plumbing;
pub use self::plumbing::CycleError;
pub(crate) use self::plumbing::CycleError;
use self::plumbing::*;

mod stats;
Expand Down
Loading