Add a cycle handler for check_representability#153470
Add a cycle handler for check_representability#153470Zoxc wants to merge 1 commit intorust-lang:mainfrom
check_representability#153470Conversation
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
This is heading in a good direction, I think. The custom handler calls in mk_cycle are a bit hacky but probably better than what we currently have.
Which other queries do you think would end up using this mechanism? The tricky thing is for some queries we just return a special value, for some we just print a custom error and abort, and for some we print a custom error and also return a special value.
| .is_some(); | ||
| if !applies { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Why is this new check needed?
There was a problem hiding this comment.
This code manually checks if it handles representability query by checking if all queries in a cycle are representability. Meanwhile currently we skip any non-representability queries in a cycle. However now representability_cycle_handler is directly called from mk_cycle and doesn't use value_from_cycle_error function pointer for specializing on Representability return type.
This is a very crude check to rely on IMO. To remove FromCycleError I would've first implemented a FallbackProvider for fallback queries to directly specialize value_from_cycle_error function pointer and not through a result type's FromCycleError trait impl. I did it in #149319 and Zoxc did something similar in #153028. In my surely very unbiased opinion my #149319 gets rid of FromCycleError (Value back then) more elegantly than Zoxc have demonstrated in #153028 so far. Per Zoxc's stated motivation:
This is a step towards removing query cycle recovery as the FromCycleError trait would be removed for that.
There was a problem hiding this comment.
Also AFAIK if any query is representability then every other query in a cycle is representability too. So we could add such assertion here if I'm correct.
There was a problem hiding this comment.
Oh, I didn't know about #149319. (I was CC'd, but last year, long before I started looking into the query system.) From a quick look it has a vtable function pointer (execute_fallback) but also requires specifying providers. My rough design below uses a query modifier (like cache_on_disk_if) without needing providers.
| ) -> C::Value { | ||
| // Try to handle the cycle error with our custom handlers. | ||
| // They will unwind if they handle the cycle. | ||
| representability_cycle_handler(tcx, &cycle_error); |
There was a problem hiding this comment.
So we are hard coding representability query cycle handling into query system. This code should be more general.
|
Thinking some more, here's a rough design that is general, eliminates |
|
I don't like macros and maybe we could consider moving it out of the macro invocation for the future, but ok. That should eliminate trait specialization, transmute and |
|
|
|
So this |
But that would mean moving these functions from |
Macros have their issues, yes, but the query system relies on them and that is unlikely to change. I think it's reasonable to use slightly more macro magic to get rid of other complexities.
It's Friday night here, I'm happy to let you try it out. (I hope it works! I think it will...)
Shouldn't be necessary. |
Just as I've said this didn't take much of my time. Done in #153493 |
|
I like the approach in #153493, it's a smallish change that cleans things up quite a bit and there is scope for some additional follow-up changes. It's similar in spirit to this PR, but is different enough that this PR won't be able to proceed. Sorry about that. But #153492 looks really promising and #153247 could also be really good with some changes. So there's plenty to keep working on :) |
This adds a cycle handler for
check_representabilityto avoid its use ofFromCycleError.This is an alternative to #153028. We'd only have 2 - 3 handlers (currently) so that PR might be overkill. This PR just calls the handlers directly from
mk_cycleinstead of and the handlers would decide if they apply to a cycle.I have kept the handler in
from_cycle_error.rsto keep changes smaller, and we could rename it if/when theFromCycleErrortrait ends up being removed.This is a step towards removing query cycle recovery as the
FromCycleErrortrait would be removed for that.