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

Replace TypeWalker usage with TypeVisitor in wf.rs #122150

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

ShoyuVanilla
Copy link
Member

Resolves #121693

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2024

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 7, 2024
@@ -20,6 +20,7 @@ where
//~^^^ ERROR: function takes 1 generic argument but 2 generic arguments were supplied
//~^^^^ ERROR: unconstrained generic constant
//~^^^^^ ERROR: unconstrained generic constant `{const expr}`
//~^^^^^^ ERROR: unconstrained generic constant `{const expr}`
Copy link
Member Author

Choose a reason for hiding this comment

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

The test output is changed, but I think that this would be correct because L + 1 + L is actually nested const expr.

The difference might be came from the difference in some recursive visiting behaviour between TypeWalker and Const::super_visit_with;

GenericArgKind::Const(parent_ct) => {
stack.push(parent_ct.ty().into());
match parent_ct.kind() {
ty::ConstKind::Infer(_)
| ty::ConstKind::Param(_)
| ty::ConstKind::Placeholder(_)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Value(_)
| ty::ConstKind::Error(_) => {}
ty::ConstKind::Expr(expr) => match expr {
ty::Expr::UnOp(_, v) => push_inner(stack, v.into()),
ty::Expr::Binop(_, l, r) => {
push_inner(stack, r.into());
push_inner(stack, l.into())
}
ty::Expr::FunctionCall(func, args) => {
for a in args.iter().rev() {
push_inner(stack, a.into());
}
push_inner(stack, func.into());
}
ty::Expr::Cast(_, c, t) => {
push_inner(stack, t.into());
push_inner(stack, c.into());
}
},
ty::ConstKind::Unevaluated(ct) => {
stack.extend(ct.args.iter().rev());
}
}

impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
try_visit!(self.ty().visit_with(visitor));
match self.kind() {
ConstKind::Param(p) => p.visit_with(visitor),
ConstKind::Infer(i) => i.visit_with(visitor),
ConstKind::Bound(d, b) => {
try_visit!(d.visit_with(visitor));
b.visit_with(visitor)
}
ConstKind::Placeholder(p) => p.visit_with(visitor),
ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
ConstKind::Value(v) => v.visit_with(visitor),
ConstKind::Error(e) => e.visit_with(visitor),
ConstKind::Expr(e) => e.visit_with(visitor),
}
}
}

the former doesn't track down some inner values.
It might possible to getting the same behaviour by changing implementation of impl TypeVisitor for WfPredicates, but it would be unintuitive and since this output seems better - at least I think so 😅 - I think that it would be good in this way.

@ShoyuVanilla ShoyuVanilla marked this pull request as ready for review March 7, 2024 17:38
@compiler-errors
Copy link
Member

r? lcnr

@rustbot rustbot assigned lcnr and unassigned davidtwco Mar 7, 2024
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

thanks, r=me after nits

}

debug!(?self.out);
match arg.unpack() {
Copy link
Contributor

Choose a reason for hiding this comment

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

arg.visit_with(self)

Comment on lines 769 to 770
// let the visitor iterate into the argument/return
// types appearing in the fn signature
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// let the visitor iterate into the argument/return
// types appearing in the fn signature
// Let the visitor iterate into the argument/return
// types appearing in the fn signature.

c.super_visit_with(self)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can you explicitly impl fn visit_predicate and ICE there? We should never check that predicates are well formed and handle wf for clauses separately

@lcnr
Copy link
Contributor

lcnr commented Mar 8, 2024

@bors try @rust-timer queue

checking for perf

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 8, 2024
@bors
Copy link
Contributor

bors commented Mar 8, 2024

⌛ Trying commit 6721b39 with merge 96b719d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
…try>

Replace `TypeWalker` usage with `TypeVisitor` in `wf.rs`

Resolves rust-lang#121693
@bors
Copy link
Contributor

bors commented Mar 8, 2024

☀️ Try build successful - checks-actions
Build commit: 96b719d (96b719dcf319bd0b616754be35dc7c575118e6ca)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (96b719d): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.2%, 1.3%] 6
Improvements ✅
(primary)
-0.3% [-0.5%, -0.2%] 34
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.3%] 4
All ❌✅ (primary) -0.3% [-0.5%, -0.2%] 34

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-7.8% [-7.8%, -7.8%] 1
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) -7.8% [-7.8%, -7.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 652.903s -> 648.597s (-0.66%)
Artifact size: 172.55 MiB -> 172.57 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 8, 2024
@lcnr
Copy link
Contributor

lcnr commented Mar 8, 2024

unlike the type walker, visitors don't use a cache by default. It feels likely that caching the walking part of wf is not necessary.

Given the mostly positive perf impact

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Mar 8, 2024

📌 Commit 6721b39 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2024
@bors
Copy link
Contributor

bors commented Mar 9, 2024

⌛ Testing commit 6721b39 with merge b054da8...

@bors
Copy link
Contributor

bors commented Mar 9, 2024

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing b054da8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 9, 2024
@bors bors merged commit b054da8 into rust-lang:master Mar 9, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 9, 2024
@ShoyuVanilla ShoyuVanilla deleted the replace-typewalker branch March 9, 2024 14:29
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b054da8): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.3%, 1.3%] 6
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 6
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.2%] 3
All ❌✅ (primary) -0.3% [-0.4%, -0.2%] 6

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 649.534s -> 649.076s (-0.07%)
Artifact size: 172.59 MiB -> 172.58 MiB (-0.00%)

@pnkfelix
Copy link
Member

pnkfelix commented Mar 12, 2024

visiting for weekly performance triage

  • six (secondary) regressions (to variants of unify-linearly and regression-31157) were anticipated during development
  • we were also expecting a broader set of 34 primary improvements. But the mean primary improvement we expected was -0.3%, which was unchanged when this actually landed.
  • so, marking as triaged

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change wf.rs to use a TypeVisitor instead of walk
8 participants