Skip to content
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

Filter and test predicates using normalize_and_test_predicates for const-prop #68297

Merged
merged 4 commits into from
Jan 21, 2020

Conversation

Aaron1011
Copy link
Member

Fixes #68264

Previously, I attempted to use
substitute_normalize_and_test_predicates to detect unsatisfiable
bounds. Unfortunately, since const-prop runs in a generic environment
(we don't have any of the function's generic parameters substituted),
this could lead to cycle errors when attempting to normalize predicates.

This check is replaced with a more precise check. We now only call
normalize_and_test_predicates on predicates that have the possibility
of being proved unsatisfiable - that is, predicates that don't depend
on anything local to the function (e.g. generic parameters). This
ensures that we don't hit cycle errors when we normalize said
predicates, while still ensuring that we detect unsatisfiable
predicates.

I haven't been able to come up with a minimization of the Diesel issue - however, I've verified that it compiles successfully.

…const-prop

Fixes rust-lang#68264

Previously, I attempted to use
`substitute_normalize_and_test_predicates` to detect unsatisfiable
bounds. Unfortunately, since const-prop runs in a generic environment
(we don't have any of the function's generic parameters substituted),
this could lead to cycle errors when attempting to normalize predicates.

This check is replaced with a more precise check. We now only call
`normalize_and_test_predicates` on predicates that have the possibility
of being proved unsatisfiable - that is, predicates that don't depend
on anything local to the function (e.g. generic parameters). This
ensures that we don't hit cycle errors when we normalize said
predicates, while still ensuring that we detect unsatisfiable
predicates.
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 17, 2020
@petrochenkov
Copy link
Contributor

Not my area of expertise.
r? @oli-obk because const-prop, feel free to reassign.

src/librustc_mir/transform/const_prop.rs Outdated Show resolved Hide resolved
src/librustc_mir/transform/const_prop.rs Show resolved Hide resolved
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None })
.collect();
if !traits::normalize_and_test_predicates(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why call the function and not the query here?

Copy link
Member Author

@Aaron1011 Aaron1011 Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this was a query, lol.

EDIT: This isn't a query. Did you want me to query-ify this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well there's substitute_normalize_and_test_predicates which you used before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk: That would use all of the predicates, which I needed to filter beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... sorry for not reading the docs properly. You're totally right. Let's merge this PR for now and experiment with making it a query separately. Such a query could share a lot of evaluation time between the predicate elaborations of completely independent definitions if they have the same predicate list.

Co-Authored-By: Oliver Scherer <[email protected]>
@weiznich
Copy link
Contributor

It probably makes sense to add the test case I've provided in #68264 as regression test?

@Aaron1011
Copy link
Member Author

@weiznich: Added

}
}

fn main() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overflow only happens if the current crate is a library. It does not happen if it's a binary crate (containing a main function). That means this test tests something different.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing --emit=mir causes the issue to occur for a binary crate, since it forces optimized_mir (and therefore const-prop) to get run on the 'bad' function.

You can verify this locally with rustc +nightly src/test/ui/consts/issue-68264-overflow.rs --emit=mir

@Aaron1011
Copy link
Member Author

@oli-obk: Are there any other changes that you'd like me to make?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 20, 2020

Nope, this just fell of my radar. Thanks for the ping

@bors r+

@bors
Copy link
Contributor

bors commented Jan 20, 2020

📌 Commit 3fef3d8 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 20, 2020
…, r=oli-obk

 Filter and test predicates using `normalize_and_test_predicates` for const-prop

Fixes rust-lang#68264

Previously, I attempted to use
`substitute_normalize_and_test_predicates` to detect unsatisfiable
bounds. Unfortunately, since const-prop runs in a generic environment
(we don't have any of the function's generic parameters substituted),
this could lead to cycle errors when attempting to normalize predicates.

This check is replaced with a more precise check. We now only call
`normalize_and_test_predicates` on predicates that have the possibility
of being proved unsatisfiable - that is, predicates that don't depend
on anything local to the function (e.g. generic parameters). This
ensures that we don't hit cycle errors when we normalize said
predicates, while still ensuring that we detect unsatisfiable
predicates.

I haven't been able to come up with a minimization of the Diesel issue - however, I've verified that it compiles successfully.
bors added a commit that referenced this pull request Jan 20, 2020
Rollup of 8 pull requests

Successful merges:

 - #67734 (Remove appendix from Apache license)
 - #67795 (Cleanup formatting code)
 - #68290 (Fix some tests failing in `--pass check` mode)
 - #68297 ( Filter and test predicates using `normalize_and_test_predicates` for const-prop)
 - #68302 (Fix #[track_caller] and function pointers)
 - #68339 (Add `riscv64gc-unknown-linux-gnu` into target list in build-manifest)
 - #68381 (Added minor clarification to specification of GlobalAlloc::realloc.)
 - #68397 (rustdoc: Correct order of `async` and `unsafe` in `async unsafe fn`s)

Failed merges:

r? @ghost
@bors bors merged commit 3fef3d8 into rust-lang:master Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in diesel with 2020-01-15 nightly: overflow evaluating requirement
6 participants