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

Allocate HIR on an arena #57173

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,7 @@ name = "rustc_data_structures"
version = "0.0.0"
dependencies = [
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"graphviz 0.0.0",
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ fn main() {
{
cmd.arg("-Dwarnings");
cmd.arg("-Dbare_trait_objects");
cmd.arg("-Drust_2018_idioms");
// FIXME(@Zoxc): Turn back on
//cmd.arg("-Drust_2018_idioms");
}

if verbose > 1 {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ macro_rules! arena_types {
rustc::hir::def_id::DefId,
rustc::ty::subst::SubstsRef<$tcx>
)>,
[] lits: syntax::source_map::Spanned<syntax::ast::LitKind>,
[] attrs: syntax::ast::Attribute,
[few] token_streams: syntax::tokenstream::TokenStream,
[few] inline_asm: rustc::hir::InlineAsm,
[few] lowered_hir: rustc::hir::LoweredHir<$tcx>,
[few] hir_map: rustc::hir::map::Map<$tcx>,
[few, decode] mir_keys: rustc::util::nodemap::DefIdSet,
[decode] specialization_graph: rustc::traits::specialization_graph::Graph,
[] region_scope_tree: rustc::middle::region::ScopeTree,
Expand Down
52 changes: 25 additions & 27 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::cfg::*;
use crate::middle::region;
use rustc_data_structures::graph::implementation as graph;
use syntax::ptr::P;
use crate::ty::{self, TyCtxt};

use crate::hir::ptr::P;
use crate::hir::{self, PatKind};
use crate::hir::def_id::DefId;

Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG {
}

impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
fn block(&mut self, blk: &hir::Block, pred: CFGIndex) -> CFGIndex {
fn block(&mut self, blk: &hir::Block<'_>, pred: CFGIndex) -> CFGIndex {
if blk.targeted_by_break {
let expr_exit = self.add_ast_node(blk.hir_id.local_id, &[]);

Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}
}

fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
fn stmt(&mut self, stmt: &hir::Stmt<'_>, pred: CFGIndex) -> CFGIndex {
let exit = match stmt.node {
hir::StmtKind::Local(ref local) => {
let init_exit = self.opt_expr(&local.init, pred);
Expand All @@ -114,7 +114,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_ast_node(stmt.hir_id.local_id, &[exit])
}

fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
fn pat(&mut self, pat: &hir::Pat<'_>, pred: CFGIndex) -> CFGIndex {
match pat.node {
PatKind::Binding(.., None) |
PatKind::Path(_) |
Expand Down Expand Up @@ -149,16 +149,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}
}

fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(
&mut self,
pats: I,
pred: CFGIndex
) -> CFGIndex {
fn pats_all<'b, 'h: 'b, I: Iterator<Item=&'b P<'h, hir::Pat<'h>>>>(&mut self,
pats: I,
pred: CFGIndex) -> CFGIndex {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intrigued by this change, the previous formatting was correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few of these changes were formatting is reverted to the formatting at the time I created the commit. Totally could use some rustfmt help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clean the indenting back to what it was here?

//! Handles case where all of the patterns must match.
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
}

fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex {
fn expr(&mut self, expr: &hir::Expr<'_>, pred: CFGIndex) -> CFGIndex {
match expr.node {
hir::ExprKind::Block(ref blk, _) => {
let blk_exit = self.block(&blk, pred);
Expand Down Expand Up @@ -297,7 +295,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {

hir::ExprKind::Index(ref l, ref r) |
hir::ExprKind::Binary(_, ref l, ref r) if self.tables.is_method_call(expr) => {
self.call(expr, pred, &l, Some(&**r).into_iter())
self.call(expr, pred, &l, Some(&***r).into_iter())
}

hir::ExprKind::Unary(_, ref e) if self.tables.is_method_call(expr) => {
Expand All @@ -309,18 +307,18 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprKind::Struct(_, ref fields, ref base) => {
let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr));
let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &**f.expr));
self.opt_expr(base, field_cfg)
}

hir::ExprKind::Assign(ref l, ref r) |
hir::ExprKind::AssignOp(_, ref l, ref r) => {
self.straightline(expr, pred, [r, l].iter().map(|&e| &**e))
self.straightline(expr, pred, [r, l].iter().map(|&e| &***e))
}

hir::ExprKind::Index(ref l, ref r) |
hir::ExprKind::Binary(_, ref l, ref r) => { // N.B., && and || handled earlier
self.straightline(expr, pred, [l, r].iter().map(|&e| &**e))
self.straightline(expr, pred, [l, r].iter().map(|&e| &***e))
}

hir::ExprKind::Box(ref e) |
Expand All @@ -332,7 +330,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
hir::ExprKind::Field(ref e, _) |
hir::ExprKind::Yield(ref e) |
hir::ExprKind::Repeat(ref e, _) => {
self.straightline(expr, pred, Some(&**e).into_iter())
self.straightline(expr, pred, Some(&***e).into_iter())
}

hir::ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
Expand All @@ -350,10 +348,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}
}

fn call<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
call_expr: &hir::Expr,
fn call<'b, 'h: 'b, I: Iterator<Item=&'b hir::Expr<'h>>>(&mut self,
call_expr: &hir::Expr<'_>,
pred: CFGIndex,
func_or_rcvr: &hir::Expr,
func_or_rcvr: &hir::Expr<'_>,
args: I) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
Expand All @@ -365,22 +363,22 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}
}

fn exprs<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
fn exprs<'b, 'h: 'b, I: Iterator<Item=&'b hir::Expr<'h>>>(&mut self,
exprs: I,
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `exprs` evaluated in order
exprs.fold(pred, |p, e| self.expr(e, p))
}

fn opt_expr(&mut self,
opt_expr: &Option<P<hir::Expr>>,
opt_expr: &Option<P<'_, hir::Expr<'_>>>,
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `opt_expr` evaluated, if Some
opt_expr.iter().fold(pred, |p, e| self.expr(&e, p))
}

fn straightline<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
expr: &hir::Expr,
fn straightline<'b, 'h: 'b, I: Iterator<Item=&'b hir::Expr<'h>>>(&mut self,
expr: &hir::Expr<'_>,
pred: CFGIndex,
subexprs: I) -> CFGIndex {
//! Handles case of an expression that evaluates `subexprs` in order
Expand All @@ -389,8 +387,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_ast_node(expr.hir_id.local_id, &[subexprs_exit])
}

fn match_(&mut self, id: hir::ItemLocalId, discr: &hir::Expr,
arms: &[hir::Arm], pred: CFGIndex) -> CFGIndex {
fn match_(&mut self, id: hir::ItemLocalId, discr: &hir::Expr<'_>,
arms: &[hir::Arm<'_>], pred: CFGIndex) -> CFGIndex {
// The CFG for match expression is quite complex, so no ASCII
// art for it (yet).
//
Expand Down Expand Up @@ -495,7 +493,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

fn add_exiting_edge(&mut self,
from_expr: &hir::Expr,
from_expr: &hir::Expr<'_>,
from_index: CFGIndex,
target_scope: region::Scope,
to_index: CFGIndex) {
Expand All @@ -513,7 +511,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

fn add_returning_edge(&mut self,
_from_expr: &hir::Expr,
_from_expr: &hir::Expr<'_>,
from_index: CFGIndex) {
let data = CFGEdgeData {
exiting_scopes: self.loop_scopes.iter()
Expand All @@ -525,7 +523,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

fn find_scope_edge(&self,
expr: &hir::Expr,
expr: &hir::Expr<'_>,
destination: hir::Destination,
scope_cf_kind: ScopeCfKind) -> (region::Scope, CFGIndex) {

Expand Down
21 changes: 19 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ macro_rules! define_dep_nodes {
pub fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
if self.kind.can_reconstruct_query_key() {
let def_path_hash = DefPathHash(self.hash);
tcx.def_path_hash_to_def_id.as_ref()?
.get(&def_path_hash).cloned()
tcx.def_path_hash_to_def_id()?.get(&def_path_hash).cloned()
} else {
None
}
Expand Down Expand Up @@ -445,6 +444,12 @@ pub trait RecoverKey<'tcx>: Sized {
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
}

impl RecoverKey<'tcx> for () {
fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
Some(())
}
}

impl RecoverKey<'tcx> for CrateNum {
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx).map(|id| id.krate)
Expand Down Expand Up @@ -539,6 +544,18 @@ impl<'tcx> DepNodeParams<'tcx> for CrateNum {
}
}

impl<'tcx> DepNodeParams<'tcx> for () {
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;

fn to_fingerprint(&self, _: TyCtxt<'_>) -> Fingerprint {
Fingerprint::ZERO
}

fn to_debug_str(&self, _: TyCtxt<'tcx>) -> String {
"<no-params>".to_string()
}
}

impl<'tcx> DepNodeParams<'tcx> for (DefId, DefId) {
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;

Expand Down
44 changes: 22 additions & 22 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ struct DepGraphData {
loaded_from_cache: Lock<FxHashMap<DepNodeIndex, bool>>,
}

pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Option<Fingerprint>
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Fingerprint
where
R: for<'a> HashStable<StableHashingContext<'a>>,
{
let mut stable_hasher = StableHasher::new();
result.hash_stable(hcx, &mut stable_hasher);

Some(stable_hasher.finish())
stable_hasher.finish()
}

impl DepGraph {
Expand Down Expand Up @@ -193,7 +193,7 @@ impl DepGraph {
cx: C,
arg: A,
task: fn(C, A) -> R,
hash_result: impl FnOnce(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
hash_result: Option<impl FnOnce(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
) -> (R, DepNodeIndex)
where
C: DepGraphSafe + StableHashingContextProvider<'a>,
Expand Down Expand Up @@ -229,7 +229,8 @@ impl DepGraph {
|data, key, fingerprint, _| {
data.borrow_mut().alloc_node(key, SmallVec::new(), fingerprint)
},
hash_result::<R>)
Some(hash_result::<R>)
)
}

fn with_task_impl<'a, C, A, R>(
Expand All @@ -244,24 +245,21 @@ impl DepGraph {
DepNode,
Fingerprint,
Option<TaskDeps>) -> DepNodeIndex,
hash_result: impl FnOnce(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
hash_result: Option<impl FnOnce(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
) -> (R, DepNodeIndex)
where
C: DepGraphSafe + StableHashingContextProvider<'a>,
{
if let Some(ref data) = self.data {
let task_deps = create_task(key).map(|deps| Lock::new(deps));

// In incremental mode, hash the result of the task. We don't
// do anything with the hash yet, but we are computing it
// anyway so that
// - we make sure that the infrastructure works and
// - we can get an idea of the runtime cost.
let mut hcx = cx.get_stable_hashing_context();

if cfg!(debug_assertions) {
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
};
let hcx = hash_result.as_ref().map(|_| {
let hcx = cx.get_stable_hashing_context();
if cfg!(debug_assertions) {
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
};
hcx
});

let result = if no_tcx {
task(cx, arg)
Expand All @@ -279,10 +277,12 @@ impl DepGraph {
};

if cfg!(debug_assertions) {
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd)
hcx.as_ref().map(|hcx| profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd));
};

let current_fingerprint = hash_result(&mut hcx, &result);
let current_fingerprint = hash_result.map(|hash_result| {
hash_result(&mut hcx.unwrap(), &result)
});

let dep_node_index = finish_task_and_alloc_depnode(
&data.current,
Expand All @@ -291,7 +291,9 @@ impl DepGraph {
task_deps.map(|lock| lock.into_inner()),
);

let print_status = cfg!(debug_assertions) && hcx.sess().opts.debugging_opts.dep_tasks;
let print_status = cfg!(debug_assertions) && ty::tls::with_opt(|tcx| {
tcx.map(|tcx| tcx.sess.opts.debugging_opts.dep_tasks).unwrap_or(false)
});

// Determine the color of the new DepNode.
if let Some(prev_index) = data.previous.node_to_index_opt(&key) {
Expand Down Expand Up @@ -378,7 +380,7 @@ impl DepGraph {
cx: C,
arg: A,
task: fn(C, A) -> R,
hash_result: impl FnOnce(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
hash_result: Option<impl FnOnce(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
) -> (R, DepNodeIndex)
where
C: DepGraphSafe + StableHashingContextProvider<'a>,
Expand Down Expand Up @@ -674,8 +676,6 @@ impl DepGraph {
}
} else {
match dep_dep_node.kind {
DepKind::Hir |
DepKind::HirBody |
DepKind::CrateMetadata => {
if dep_dep_node.extract_def_id(tcx).is_none() {
// If the node does not exist anymore, we
Expand Down Expand Up @@ -719,7 +719,7 @@ impl DepGraph {
None => {
if !tcx.sess.has_errors() {
bug!("try_mark_previous_green() - Forcing the DepNode \
should have set its color")
should have set its color - dep node {:?}", dep_dep_node)
} else {
// If the query we just forced has resulted
// in some kind of compilation error, we
Expand Down
Loading