Skip to content

Commit 54595ec

Browse files
committed
use memoized pattern for SizedConstraint
I cannot figure out how to write a test for this, but I observed incorrect edges as a result of not using memoized pattern here (e.g., LateLintCheck -> SizedConstraint).
1 parent b13d504 commit 54595ec

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/librustc/ty/ivar.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ impl<'tcx, 'lt> TyIVar<'tcx, 'lt> {
5252
self.untracked_get()
5353
}
5454

55+
/// Reads the ivar without registered a dep-graph read. Use with
56+
/// caution.
5557
#[inline]
56-
fn untracked_get(&self) -> Option<Ty<'tcx>> {
58+
pub fn untracked_get(&self) -> Option<Ty<'tcx>> {
5759
match self.0.get() {
5860
None => None,
5961
// valid because of invariant (A)

src/librustc/ty/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,8 +1757,7 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'tcx, 'container> {
17571757
/// Due to normalization being eager, this applies even if
17581758
/// the associated type is behind a pointer, e.g. issue #31299.
17591759
pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
1760-
let dep_node = DepNode::SizedConstraint(self.did);
1761-
match self.sized_constraint.get(dep_node) {
1760+
match self.sized_constraint.get(DepNode::SizedConstraint(self.did)) {
17621761
None => {
17631762
let global_tcx = tcx.global_tcx();
17641763
let this = global_tcx.lookup_adt_def_master(self.did);
@@ -1786,12 +1785,18 @@ impl<'a, 'tcx> AdtDefData<'tcx, 'tcx> {
17861785
/// such.
17871786
/// - a TyError, if a type contained itself. The representability
17881787
/// check should catch this case.
1789-
fn calculate_sized_constraint_inner(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
1788+
fn calculate_sized_constraint_inner(&'tcx self,
1789+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
17901790
stack: &mut Vec<AdtDefMaster<'tcx>>)
17911791
{
1792-
17931792
let dep_node = || DepNode::SizedConstraint(self.did);
1794-
if self.sized_constraint.get(dep_node()).is_some() {
1793+
1794+
// Follow the memoization pattern: push the computation of
1795+
// DepNode::SizedConstraint as our current task.
1796+
let _task = tcx.dep_graph.in_task(dep_node());
1797+
if self.sized_constraint.untracked_get().is_some() {
1798+
// ---------------
1799+
// can skip the dep-graph read since we just pushed the task
17951800
return;
17961801
}
17971802

0 commit comments

Comments
 (0)