Skipping borrowck because of trivial const#149468
Skipping borrowck because of trivial const#149468chenyukang wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
I'm okay with this change, but I would like @lcnr's opinion on whether this sort of whack-a-mole approach is sustainable. (I don't want to have an ever-growing number of |
|
What are the requirements for something to be a trivial const, are they written down somewhere? E.g. is I personally feel quite... unhappy about this change. @BoxyUwU has been changing lowering of some constants for const generics to never actually get lowered to HIR expression but instead eagerly convert them into type system constants. That means we don't have a body for them and don't even try to call any of the Having both of these impls seems fairly bad to me. It seems like ideally there should only be one way to get constants without corresponding MIR body. I don't have the time to engage with that area myself right now :x I think we should not have both systems and ideally you'd chat with @BoxyUwU to figure out whether you can unify the two somehow |
|
Well, that's why I asked. I agree that Boxy's approach seems better. If you wanted to know the semantics I implemented, they're all in here: https://github.com/rust-lang/rust/blob/2fb805367dd3012ce5c50865d03c86e70bf10f0f/compiler/rustc_mir_transform/src/trivial_const.rs |
so this ends up as a trivial const? we never check that the type of the const is not an opaque. This code would start to fail/misbehave with this PR because MIR borrowck doesn't return the defining use anymore, would it not (at least with the new solver)? |
|
Would definitely be interested in chatting about things here 🤔 @saethlin if you wanna reach out on zulip at some point that'd be cool :) |
|
Checking for progress. Did a conversation happen about this? What's the current status? thanks for an update :) |
is this an issue with this PR? |
31c3857 to
ec79af9
Compare
This comment has been minimized.
This comment has been minimized.
I rebased the code with latest upstream. For |
|
r? lcnr This optimization is unfortunately hard to unify with the work by Boxy. Given that we bail if there are any opaques,
I would expect that the current check isn't sufficient with the new solver here? Because in the new solver we actually normalize Can you test it with |
|
This has a borrowck error on nightly. Is it occurring in a trivial const? struct Thing<'a>(&'a ());
impl<'a: 'static> Thing<'a> {
const X: i32 = 1;
}
impl<'a> Thing<'a> {
const C: i32 = Thing::<'a>::X;
} |
I agree. I started looking into what Boxy is doing, and I found it rather difficult to connect that logic to the optimization I was looking to implement. @lcnr If you think the existing trivial_const logic is unsustainable, I trust your judgement and have no objection to reverting it. |
|
Sorry, marked this as read without seeing your question. I do think this optimization has a very high complexity cost. Having a new kind of body and making sure it's always handled correctly feels brittle to me. I would prefer removing that change :/ I don't remember the perf improvements we get from this and maybe they justify the added complexity 🤔
|
|
The post-merge perf run is here: #148040 (comment) I think some level of complexity is warranted. |
|
yeah :/ i feel conflicted here, which is why I am kind of avoiding this PR 😅
we can fix this by instead checking whether the constant is the defining scope of any opaque. I guess I am fine with this PR if we add such a test and make sure it works |
ec79af9 to
3c65785
Compare
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
I changed the trivial-const check so that we do not treat a const as trivial if it is the defining scope of any opaque ( I also added a |
r? @saethlin
the assertion is added in PR: #148040
I think we also need to skip trvial const in
mir_borrowck.