-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use r? to explicitly pick a reviewer |
@@ -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}` |
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.
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
;
rust/compiler/rustc_middle/src/ty/walk.rs
Lines 205 to 236 in 52f8aec
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()); | |
} | |
} |
rust/compiler/rustc_middle/src/ty/structural_impls.rs
Lines 762 to 779 in 52f8aec
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.
r? lcnr |
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.
thanks, r=me after nits
} | ||
|
||
debug!(?self.out); | ||
match arg.unpack() { |
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.
arg.visit_with(self)
// let the visitor iterate into the argument/return | ||
// types appearing in the fn signature |
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.
// 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) | ||
} | ||
} | ||
|
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 you explicitly impl fn visit_predicate
and ICE there? We should never check that predicates are well formed and handle wf for clauses separately
dfdf227
to
6721b39
Compare
@bors try @rust-timer queue checking for perf |
This comment has been minimized.
This comment has been minimized.
…try> Replace `TypeWalker` usage with `TypeVisitor` in `wf.rs` Resolves rust-lang#121693
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (96b719d): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking 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 @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 652.903s -> 648.597s (-0.66%) |
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 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b054da8): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 649.534s -> 649.076s (-0.07%) |
visiting for weekly performance triage
@rustbot label: +perf-regression-triaged |
Resolves #121693