diff --git a/src/librustc/ty/ivar.rs b/src/librustc/ty/ivar.rs index 88327ab19a5cb66350a06e707fa9954766d62b55..634599406afb2fc49627a734559fccb5e0c4abc1 100644 --- a/src/librustc/ty/ivar.rs +++ b/src/librustc/ty/ivar.rs @@ -52,8 +52,10 @@ pub fn get(&self, dep_node: DepNode) -> Option> { self.untracked_get() } + /// Reads the ivar without registered a dep-graph read. Use with + /// caution. #[inline] - fn untracked_get(&self) -> Option> { + pub fn untracked_get(&self) -> Option> { match self.0.get() { None => None, // valid because of invariant (A) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 03e893727d1b58c7d88142ee72bb336dfe509cfd..a7c534198923b7a1183bb7f9b7f0a0d65dcd24bf 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1757,8 +1757,7 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'tcx, 'container> { /// Due to normalization being eager, this applies even if /// the associated type is behind a pointer, e.g. issue #31299. pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { - let dep_node = DepNode::SizedConstraint(self.did); - match self.sized_constraint.get(dep_node) { + match self.sized_constraint.get(DepNode::SizedConstraint(self.did)) { None => { let global_tcx = tcx.global_tcx(); let this = global_tcx.lookup_adt_def_master(self.did); @@ -1786,12 +1785,18 @@ impl<'a, 'tcx> AdtDefData<'tcx, 'tcx> { /// such. /// - a TyError, if a type contained itself. The representability /// check should catch this case. - fn calculate_sized_constraint_inner(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, + fn calculate_sized_constraint_inner(&'tcx self, + tcx: TyCtxt<'a, 'tcx, 'tcx>, stack: &mut Vec>) { - let dep_node = || DepNode::SizedConstraint(self.did); - if self.sized_constraint.get(dep_node()).is_some() { + + // Follow the memoization pattern: push the computation of + // DepNode::SizedConstraint as our current task. + let _task = tcx.dep_graph.in_task(dep_node()); + if self.sized_constraint.untracked_get().is_some() { + // --------------- + // can skip the dep-graph read since we just pushed the task return; }