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

Change a commit_if_ok call to probe #105292

Merged
merged 5 commits into from
Jan 9, 2023
Merged

Conversation

JulianKnodt
Copy link
Contributor

Removes an over-eager commit_if_ok which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes #105037

r? @BoxyUwU

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2022
@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors changed the title [WIP] Remove commit_if_ok [WIP] Remove a commit_if_ok call Dec 5, 2022
@JulianKnodt JulianKnodt changed the title [WIP] Remove a commit_if_ok call [WIP] Change a commit_if_ok call to probe Dec 5, 2022
@JulianKnodt JulianKnodt marked this pull request as ready for review December 5, 2022 19:28
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2022

Some changes occurred in const_evaluatable.rs

cc @lcnr

@JulianKnodt JulianKnodt changed the title [WIP] Change a commit_if_ok call to probe Change a commit_if_ok call to probe Dec 5, 2022
@bors
Copy link
Contributor

bors commented Dec 6, 2022

☔ The latest upstream changes (presumably #105365) made this pull request unmergeable. Please resolve the merge conflicts.

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 6, 2022

replacing this with a probe seems right, we dont want to constrain the infer vars in self.ct unless we're sure there are no other things that we could have unified with to consider it evaluatable. It's still not quite right though, we do have to actually constrain the infer vars that eq constraints at some point in order to ensure that the const is actually evaluatable.

What's needed is to have the visitor visit all the consts regardless of it succeeds in unifying with something, and if it succeed in unifying with something (in the probe) track that in Visitor. Once the visitor is finished you want to be able to see of all the consts that we were able to unify with, and if there was only one, redo the eq and select_all_or_error() outside of a probe.

@JulianKnodt JulianKnodt force-pushed the no_eager_commit branch 4 times, most recently from aaf7eb5 to 0bec1bb Compare December 13, 2022 10:59
@JulianKnodt
Copy link
Contributor Author

I updated to check for only a single match and commit the change if there is a single one, but somehow this results in an error for the original test case. Is this an issue with the way I implemented it?

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 15, 2022

the current code only works for a single ConstEvaluatable predicate in the paramenv, i.e. if you had where [(); N +1 + 1]: and were trying to prove ConstEvalutable(N + _) it'd avoid unifying with 1 + 1 or 1 because either would work.
The test case you're working with has two separate things in param env: ConstEvaluatable(Table1<D>) and ConstEvaluatable(Table2<D>) so you'll also have to update the for loop to make you a single Option<Result<Const<'tcx>>, ()> and do the ocx.eq stuff after the for loop instead of inside

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 20, 2022

I think all the CI failures are caused by cases where we have duplicate candidates, i.e. two N + 1 in the param env, you probably want to avoid setting single_match to Err instead of Ok if the candidate that matched is == to the existing Ok

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 21, 2022

Can you add the following as tests:


#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

fn foo<const N: usize>()
where
    [(); N + 1]:,
    [(); N + 1]:,
{
    bar::<N>();
}

fn bar<const N: usize>()
where
    [(); N + 1]:,
{
}

fn main() {}

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

const fn both(_: usize, b: usize) -> usize {
    b
}

fn foo<const N: usize>()
where
    [(); both(N + 1, N + 1)]:,
{
    bar::<N>();
}

fn bar<const N: usize>()
where
    [(); N + 1]:,
{
}

fn main() {}

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

const fn both(_: usize, b: usize) -> usize {
    b
}

fn foo<const N: usize, const M: usize>() -> [(); N + 2]
where
    [(); both(N + 1, M + 1)]:,
{
    bar()
}

fn bar<const N: usize>() -> [(); N]
where
    [(); N + 1]:,
{
    [(); N]
}

fn main() {}

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 9, 2023

will r+ this once its rebased

Instead of just switching to a probe, check for different matches, and see how many there are.
If one, unify it, otherwise return true and let it be unified later.
This prevents an ICE due to a value not actually being evaluatable later.
Simplify match statement

Add multiple tests
- 1 test for checking `N + 1 + 1` does not unify with `N+1`
- 2 tests for checking that a function that uses two parameters only returns the parameter that
  is actually used.
- Check exact repeat predicates
@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 9, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 9, 2023

📌 Commit 21c5ffe has been approved by BoxyUwU

It is now in the queue for this repository.

@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 9, 2023
JohnTitor pushed a commit to JohnTitor/rust that referenced this pull request Jan 9, 2023
…yUwU

Change a commit_if_ok call to probe

Removes an over-eager `commit_if_ok` which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes rust-lang#105037

r? `@BoxyUwU`
JohnTitor pushed a commit to JohnTitor/rust that referenced this pull request Jan 9, 2023
…yUwU

Change a commit_if_ok call to probe

Removes an over-eager `commit_if_ok` which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes rust-lang#105037

r? ``@BoxyUwU``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2023
…fee1-dead

Rollup of 10 pull requests

Successful merges:

 - rust-lang#105292 (Change a commit_if_ok call to probe)
 - rust-lang#105655 (Remove invalid case for mutable borrow suggestion)
 - rust-lang#106047 (Fix ui constant tests for big-endian platforms)
 - rust-lang#106061 (Enable Shadow Call Stack for Fuchsia on AArch64)
 - rust-lang#106164 (Move `check_region_obligations_and_report_errors` to `TypeErrCtxt`)
 - rust-lang#106291 (Fix incorrect suggestion for extra `&` in pattern)
 - rust-lang#106389 (Simplify some canonical type alias names)
 - rust-lang#106468 (Use FxIndexSet when updating obligation causes in `adjust_fulfillment_errors_for_expr_obligation`)
 - rust-lang#106549 (Use fmt named parameters in rustc_borrowck)
 - rust-lang#106614 (error-code docs improvements (No. 2))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b7587f1 into rust-lang:master Jan 9, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 9, 2023
@JulianKnodt JulianKnodt deleted the no_eager_commit branch January 9, 2023 21:53
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 20, 2023
…compiler-errors

Added const-generic ui test case for issue rust-lang#106419

This PR adds a test case for rust-lang#106419 which has been fixed in master by rust-lang#105292

I also ran the test on f769d34 (the commit before rust-lang#105292 was merged)
and it did fail there with the following output.
```
--- stderr -------------------------------
error[E0308]: mismatched types
  --> /home/patrikk/src/rust/src/test/ui/const-generics/issue-106419-struct-with-multiple-const-params.rs:5:10
   |
LL | #[derive(Clone)]
   |          ^^^^^
   |          |
   |          expected `A`, found `B`
   |          expected `Bar<A, B>` because of return type
   |
   = note: expected struct `Bar<A, _>`
              found struct `Bar<B, _>`
   = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
------------------------------------------
```
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad generic inference on very recent nightly
5 participants