-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
save-analysis: Nest typeck tables when processing functions/methods #64250
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
We can probably change the assertion to be a non-debug assertion? |
…es, r=<try> [DONT MERGE] Always validate HIR ID for TypeckTables ...and not only with `debug_assertions` compiled in - #64250 (comment). cc @Mark-Simulacrum @michaelwoerister Let's do a try run to see if this impacts perf anyhow? r? @ghost
Started a try->perf run over at #64262 |
…es, r=<try> [DONT MERGE] Always validate HIR ID for TypeckTables ...and not only with `debug_assertions` compiled in - #64250 (comment). cc @Mark-Simulacrum @michaelwoerister Let's do a try run to see if this impacts perf anyhow? r? @ghost
Performance shouldn't be impacted (see [1] for a perf run) and this should allow us to catch more bugs, e.g. [2] and [3]. [1]: rust-lang#64262 [2]: rust-lang#64250 [3]: rust-lang#57298
Perf run turned out to be okay, so I dropped the conditional compilation on debug assertions and added a test case. |
@bors r+ |
📌 Commit 7730ef1 has been approved by |
… r=varkor save-analysis: Nest typeck tables when processing functions/methods Fixes an issue where we did not nest tables correctly when resolving associated types in formal argument/return type positions. This was the minimized reproduction case that I tested the fix on: ```rust pub trait Trait { type Assoc; } pub struct A; pub fn func() { fn _inner1<U: Trait>(_: U::Assoc) {} fn _inner2<U: Trait>() -> U::Assoc { unimplemented!() } impl A { fn _inner1<U: Trait>(self, _: U::Assoc) {} fn _inner2<U: Trait>(self) -> U::Assoc { unimplemented!() } } } ``` using `debug_assertions`-enabled rustc and by additionally passing `-Zsave-analysis`. Unfortunately the original assertion fired is a *debug* one and from what I can tell we don't run the tests with these on, so I'm not adding a test here. If I missed it and there is a way to run tests with these on, I'd love to add a test case for this. Closes rust-lang#63663 Closes rust-lang#50328 Closes rust-lang#43982
Failed in #64366 (comment), @bors r- |
That's unfortunate, thanks for the heads up; will look into it tomorrow Failure:
Probably caused by rust/src/libcore/iter/adapters/mod.rs Line 544 in 34e82a7
EDIT: Minimized to: pub trait Trait {
type Assoc;
}
pub fn func() {
fn _inner<U: Trait>() -> impl Fn(U::Assoc) { |_| unimplemented!() }
} |
Fixes an issue where we did not nest tables correctly when resolving associated types in formal argument/return type positions
Performance shouldn't be impacted (see [1] for a perf run) and this should allow us to catch more bugs, e.g. [2] and [3]. [1]: rust-lang#64262 [2]: rust-lang#64250 [3]: rust-lang#57298
...since the code is literally the same and does the same thing.
7730ef1
to
0fafd61
Compare
This is updated and ready for review again. The last bug was uncovered when processing type paths in return type Specifically, this is because we try to resolve the qualified type path using the typeck tables but a debug assertion fires since the def id of the type path and that of the table don't share the same local id root. Unfortunately, the correct way under the current architecture would be to nest the tables further, however from what I can tell the newly lowered synthetic def path segment does not have typeck tables (probably rightly so? @nikomatsakis), so to prevent the underlying ICE and to enable the debug assertion for good now, I decided to only add explanatory comments and skip processing bounds in As a side note, the current save-analysis infrastructure is slowly becoming dated as we introduce more supporting infrastructure with time (e.g. cleaning up resolution, definition infra from incremental), so it might be worth thinking how to handle it in the medium-term (leverage HIR directly instead of AST? maybe use it as a way to somehow bridge/push for librarification of the frontend?). |
@bors r+ |
📌 Commit a946b8d has been approved by |
… r=varkor save-analysis: Nest typeck tables when processing functions/methods Fixes an issue where we did not nest tables correctly when resolving associated types in formal argument/return type positions. This was the minimized reproduction case that I tested the fix on: ```rust pub trait Trait { type Assoc; } pub struct A; pub fn func() { fn _inner1<U: Trait>(_: U::Assoc) {} fn _inner2<U: Trait>() -> U::Assoc { unimplemented!() } impl A { fn _inner1<U: Trait>(self, _: U::Assoc) {} fn _inner2<U: Trait>(self) -> U::Assoc { unimplemented!() } } } ``` using `debug_assertions`-enabled rustc and by additionally passing `-Zsave-analysis`. Unfortunately the original assertion fired is a *debug* one and from what I can tell we don't run the tests with these on, so I'm not adding a test here. If I missed it and there is a way to run tests with these on, I'd love to add a test case for this. Closes rust-lang#63663 Closes rust-lang#50328 Closes rust-lang#43982
Rollup of 3 pull requests Successful merges: - #63872 (Document platform-specific behavior of the iterator returned by std::fs::read_dir) - #64250 (save-analysis: Nest typeck tables when processing functions/methods) - #64472 (Don't mark expression with attributes as not needing parentheses) Failed merges: r? @ghost
b456c82 lets Clippy ICE, when calling Call stack: LateLintPass::check_struct_field(.., cx, field);
cx.tables.qpath_res(field.ty.node -> qpath, field.ty.hir_id); This seems weird to me, since we're checking the |
Left some explanation on why the assertion fires and how to fix it at rust-lang/rust-clippy#4545 (comment) |
Fixes an issue where we did not nest tables correctly when resolving
associated types in formal argument/return type positions.
This was the minimized reproduction case that I tested the fix on:
using
debug_assertions
-enabled rustc and by additionally passing-Zsave-analysis
.Unfortunately the original assertion fired is a debug one and from what I can tell we don't run the tests with these on, so I'm not adding a test here. If I missed it and there is a way to run tests with these on, I'd love to add a test case for this.
Closes #63663
Closes #50328
Closes #43982