-
Notifications
You must be signed in to change notification settings - Fork 13.3k
incr.comp.: Remove DepGraph::write() and its callers #42192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig}; | ||
use dep_graph::{DepNode, DepTrackingMapConfig}; | ||
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE}; | ||
use hir::def::Def; | ||
use hir; | ||
|
@@ -27,9 +27,11 @@ use ty::fast_reject::SimplifiedType; | |
use util::nodemap::{DefIdSet, NodeSet}; | ||
|
||
use rustc_data_structures::indexed_vec::IndexVec; | ||
use rustc_data_structures::fx::FxHashMap; | ||
use std::cell::{RefCell, RefMut}; | ||
use std::fmt::Debug; | ||
use std::hash::Hash; | ||
use std::marker::PhantomData; | ||
use std::mem; | ||
use std::collections::BTreeMap; | ||
use std::ops::Deref; | ||
|
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName { | |
} | ||
} | ||
|
||
struct QueryMap<D: QueryDescription> { | ||
phantom: PhantomData<D>, | ||
map: FxHashMap<D::Key, D::Value>, | ||
} | ||
|
||
impl<M: QueryDescription> QueryMap<M> { | ||
fn new() -> QueryMap<M> { | ||
QueryMap { | ||
phantom: PhantomData, | ||
map: FxHashMap(), | ||
} | ||
} | ||
} | ||
|
||
pub struct CycleError<'a, 'tcx: 'a> { | ||
span: Span, | ||
cycle: RefMut<'a, [(Span, Query<'tcx>)]>, | ||
|
@@ -463,13 +479,12 @@ macro_rules! define_maps { | |
} | ||
|
||
impl<$tcx> Maps<$tcx> { | ||
pub fn new(dep_graph: DepGraph, | ||
providers: IndexVec<CrateNum, Providers<$tcx>>) | ||
pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>) | ||
-> Self { | ||
Maps { | ||
providers, | ||
query_stack: RefCell::new(vec![]), | ||
$($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),* | ||
$($name: RefCell::new(QueryMap::new())),* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if there's a way to get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The advantage being that we would get rid of the runtime check? Sounds intriguing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always expected it to be possible, it's just a matter of reducing the footprint to introduce a sound abstraction. |
||
} | ||
} | ||
} | ||
|
@@ -521,7 +536,7 @@ macro_rules! define_maps { | |
key, | ||
span); | ||
|
||
if let Some(result) = tcx.maps.$name.borrow().get(&key) { | ||
if let Some(result) = tcx.maps.$name.borrow().map.get(&key) { | ||
return Ok(f(result)); | ||
} | ||
|
||
|
@@ -539,21 +554,19 @@ macro_rules! define_maps { | |
provider(tcx.global_tcx(), key) | ||
})?; | ||
|
||
Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result))) | ||
Ok(f(tcx.maps.$name.borrow_mut().map.entry(key).or_insert(result))) | ||
} | ||
|
||
pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) | ||
-> Result<$V, CycleError<'a, $tcx>> { | ||
// We register the `read` here, but not in `force`, since | ||
// `force` does not give access to the value produced (and thus | ||
// we actually don't read it). | ||
tcx.dep_graph.read(Self::to_dep_node(&key)); | ||
Self::try_get_with(tcx, span, key, Clone::clone) | ||
} | ||
|
||
pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) { | ||
// FIXME(eddyb) Move away from using `DepTrackingMap` | ||
// so we don't have to explicitly ignore a false edge: | ||
// we can't observe a value dependency, only side-effects, | ||
// through `force`, and once everything has been updated, | ||
// perhaps only diagnostics, if those, will remain. | ||
let _ignore = tcx.dep_graph.in_ignore(); | ||
match Self::try_get_with(tcx, span, key, |_| ()) { | ||
Ok(()) => {} | ||
Err(e) => tcx.report_cycle(e) | ||
|
@@ -644,7 +657,7 @@ macro_rules! define_map_struct { | |
tcx: $tcx, | ||
input: $input, | ||
output: ($($output)* | ||
$(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,) | ||
$(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,) | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use
FxHashMap
directly in the macro and perhaps even avoid having a trait forKey
/Value
altogether?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea but that would complicate the
define_map_struct
macro. Since all of this will be refactored in the near future anyway, I think it's OK to do this in a later PR.