-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
-Ztrait-solver=next
: deduplicate region constraints in query responses
#109764
Comments
-Ztrait-solver=next
: deduplicate universes in query responses
|
Hey all, If nobody else is currently tackling this issue, could I take a shot at it? Also my apologies if the remainder of the post is really badly misinformed - if it's clear that this issue should be left to someone in the new trait solver working group, just let me know and I'll try something else instead. My first attempt at this was deduping all the placeholder region obligations (in eval_ctxt/canonical.rs, deduping the My idea for the snippet presented by compiler-errors is to do the deduping inside of Once again, if someone's already working on this, or if it's an issue best left to a dedicated working group, just lmk and I'll just go do something else :) |
@ndrewxie sure, go ahead. this is a fairly difficult issue to start with but it's also something nobody is working on right now and should be fairly interesting 😁 given that it's fairly complex, please do the following if you intend to keep working on this:
What I can say by taking a quick look at your description "two universes had the same Placeholders " is not enough. The actual name of placeholders is mostly moot. I would instead like to check that the region constraints involving different placeholders are equal. E.g. if you have |
@rustbot claim |
Aah ok, thanks! I opened the zulip thread here |
This issue is not specific to HRTB bounds and universes. This snippet, for example, generates a never-ending stream of struct Foo
where
Foo:,
(): 'static; Perhaps the title should be changed to "deduplicate region constraints" instead. |
Aah, I see. For the example you gave, all the constraints are identical, so I just added a quick dedup for 100% identical cases. Probably doesn't cover everything, but I'll keep working on it. The question I'm having right now is, how far can this deduplication go? Can all region constraints be deduplicated, or is it just restricted to placeholders? |
-Ztrait-solver=next
: deduplicate universes in query responses-Ztrait-solver=next
: deduplicate region constraints in query responses
all region constraints can get deduplicated (as long as we don't drop any meaningful information) |
👍 Thanks! Just to be clear - if I'm deduping the canonicalized Response, any variable that's not in the root universe is a variable created during solving, so they don't count as "meaningful information" (as in, they can't just be all deleted, but they can be deduplicated). I'm still ironing out a few final kinks - the trickiest case is if we have constraints that involve multiple variables that we can potentially deduplicate, but I think I've finally settled on a solution that would work (sorry that I've taken so long - took me a while to figure out what each part of the solver was doing and the best place to insert my changes) But just one question - what time complexity is permitted? My current implementation is very likely going to be O(n^2), as it relies on building a table of "which constraints are 'approximately equal' to each other", which is inherently O(n^2). I define 'approximately equal' as constraints that are identical except they differ in variables that we can re-write - e.g. one constraint involves placeholder var 1 and the other involves var 2, but they're otherwise identical. These 'approximately equal' constraints then get pruned - if merging 2 constraints by re-writing variables would impact other constraints in a way that doesn't map constraints onto already-existing constraints, then these 2 constraints are no longer considered 'approximately equal'. Continuing this way would yield constraints that we know can be merged, which should accomplish the dedup, right? But there's definitely no way this is faster than O(n^2). |
👍 O(n^2) should definitely be fine.
no worries 😁 this is currently not blocking any work and a complex issue. Happy that you're apparently able to make significant progress on this yourself |
results in overflow in the new solver when checking
WF(Bar)
or `for<'a> WF(&'a mut Bar). The issue is as follows:for<'a> WF(&'a mut Bar)
(attempt 0)WF(&'a.1 mut Bar)
outlives(Bar, 'a.1)
OK[Bar: 'a.1]
WF(Bar)
for<'a> WF(&'a mut Bar)
cycle OK[]
[Bar: 'a.1]
for<'a> WF(&'a mut Bar)
(attempt 1)WF(&'a.1 mut Bar)
outlives(Bar, 'a.1)
OK[Bar: 'a.1]
WF(Bar)
for<'a> WF(&'a mut Bar)
cycle OK[Bar: 'a.2]
(create new universe)[Bar: 'a.1, Bar: 'a.2]
for<'a> WF(&'a mut Bar)
(attempt 2)WF(&'a.1 mut Bar)
outlives(Bar, 'a.1)
OK[Bar: 'a.1]
WF(Bar)
for<'a> WF(&'a mut Bar)
cycle OK[Bar: 'a.2, Bar: 'a.3]
(create new universe)[Bar: 'a.1, Bar: 'a.2, Bar: 'a.3]
starting with
WF(BAR)
WF(Bar)
iteration 0for<'a> WF(&'a mut Bar)
WF(&'a.1 mut Bar)
outlives(Bar, 'a.1)
OK[Bar: 'a.1]
WF(Bar)
cycle OK[]
WF(Bar)
iteration 1for<'a> WF(&'a mut Bar)
WF(&'a.1 mut Bar)
outlives(Bar, 'a.1)
OK[Bar: 'a.1]
WF(Bar)
cycle OK[Bar: 'a.?]
a similar issue is:
WF(Foo)
iteration 0WF(Foo)
cycle OK[]
for<'a> WF(&'a ())
OK[(): 'a.1]
(new universe for unnameable placeholder)[(): 'a.1]
WF(Foo)
iteration 1 (in new infcx)WF(Foo)
cycle OK[(): 'a.1]
(new universe for unnameable placeholder)for<'a> WF(&'a ())
OK[(): 'a.2]
(new universe for unnameable placeholder)[(): 'a.1, (): 'a.2]
yikes (have to rerun again)The long term plan to solve this is to eagerly deal with new placeholders in the solver, short term
we probably want to somehow deduplicate new placeholder constraints when creating the query responsewe're going to ignore this because hopefully this pattern does not exist in user-code.The text was updated successfully, but these errors were encountered: