-
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
Avoid infinite loop in function arguments checking #100502
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
Thanks for finding this @chenyukang. Also remember to use "fixes" instead of "fixing" :) |
Aha, seems it's my habit😁 |
@chenyukang thanks for the PR. This indeed doesn't seem like the correct fix. I think this masks a different problem. There's an unstated assertion that if find_issue returns None, then we can eliminate at least some provided/expected args. The fact that this isn't the case seems like there is a discrepancy between Is the log that you provided for the test you added? The test seems to have 11 args and the log has 15/16? |
Just looking at the log and comparing it to the what would happen. There's actually a couple things we could change. But let's look going backwards at "most straightforward" fix.
We should detect this as a permutation, I think. Or that column 1 is extra, followed by row 5 extra. This suggests there's a bug in our permutation detection. Actually though, all the back towards the beginning, first call to
It would be nice to identify that column 1 is "extra", rather than that row 9 is "missing". |
I guess what you mean should be: column 0 is "missing", rather than that col 9 is "missing" ?since we lack an argument for a input. Yes, the first iteration is not good. // If we eliminate the last row, any left-over inputs are considered missing
if i >= mat.len() {
return Some(Issue::Missing(i)); // Fix to Issue::Missing(0)
} But this fix will broke another testcase, for function call in testcase https://github.com/rust-lang/rust/blob/master/src/test/ui/argument-suggestions/missing_arguments.rs#L30, this fix print the wrong type for missing arguments: --- a/src/test/ui/argument-suggestions/missing_arguments.stderr
+++ b/src/test/ui/argument-suggestions/missing_arguments.stderr
@@ -210,10 +210,7 @@ error[E0061]: this function takes 3 arguments but 1 argument was supplied
--> $DIR/missing_arguments.rs:30:3
|
LL | three_diff( 1.0 );
- | ^^^^^^^^^^-------------------------
- | | |
- | | an argument of type `i32` is missing
- | an argument of type `&str` is missing
+ | ^^^^^^^^^^------------------------- two arguments of type `i32` and `f32` are missing
|
note: function defined here
--> $DIR/missing_arguments.rs:5:4
@@ -222,8 +219,8 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
| ^^^^^^^^^^ ------- ------- --------
help: provide the arguments
|
-LL | three_diff(/* i32 */, 1.0, /* &str */);
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LL | three_diff(/* i32 */, /* f32 */, /* &str */);
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
oh, sorry, I minilized the test case later, droping some several extra parameters at the beginning. |
@jackh726 This part of checking will not find out the x| 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - I worked out another solution, By the way, I fixed some comments which didn't get right between the This is how the let compatibility_matrix = (0..provided_count)
.map(|i| {
(0..expected_input_count)
.map(|j| is_compatible(ProvidedIdx::from_usize(i), ExpectedIdx::from_usize(j)))
.collect()
})
.collect();
ArgMatrix {
provided_indices: (0..provided_count).map(ProvidedIdx::from_usize).collect(),
expected_indices: (0..expected_input_count).map(ExpectedIdx::from_usize).collect(),
compatibility_matrix,
} ... let ai = &self.expected_indices;
let ii = &self.provided_indices; This is not match with the comments in b6c87c5:
Anyway, I think we'd better keep the naming choice in the code now. |
r? @jackh726 it seems like you're already familiar with this code |
This comment has been minimized.
This comment has been minimized.
@jackh726 Debugging code FYI: https://github.com/chenyukang/rust/pull/1/files struct A;
struct B;
struct C;
struct D;
fn f(
a1: A,
a2: A,
b1: B,
b2: B,
c1: C,
c2: C,
) {}
fn main() {
f(C, C, A, A, B, B);
} The debug log is: ai: [ExpectedIdx(0), ExpectedIdx(1), ExpectedIdx(2), ExpectedIdx(3), ExpectedIdx(4), ExpectedIdx(5)]
ii: [ProvidedIdx(0), ProvidedIdx(1), ProvidedIdx(2), ProvidedIdx(3), ProvidedIdx(4), ProvidedIdx(5)]
================== find_issue: ==================
x| 0 1 2 3 4 5
-| - - - - - -
0| 0 0 0 0 1 1
1| 0 0 0 0 1 1
2| 1 1 0 0 0 0
3| 1 1 0 0 0 0
4| 0 0 1 1 0 0
5| 0 0 1 1 0 0
i: 0, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 1, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 2, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 3, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 4, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 5, is_input: true, is_arg: true, useless: false, unsatisfiable: false
loop i: 0 j: 0 compat: [4, 5]
permutation_found: false
now permutation: [Some(None), None, None, None, None, None]
loop i: 1 j: 1 compat: [4, 5]
permutation_found: false
now permutation: [Some(None), Some(None), None, None, None, None]
loop i: 2 j: 2 compat: [0, 1]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), None, None, None]
loop i: 3 j: 3 compat: [0, 1]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), None, None]
loop i: 4 j: 4 compat: [2, 3]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), Some(None), None]
loop i: 5 j: 5 compat: [2, 3]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), Some(None), Some(None)]
res: None
thread 'rustc' panicked at 'didn't eliminated any indice in this round', compiler/rustc_typeck/src/check/fn_ctxt/arg_matrix.rs:412:21 |
b9bdc01 |
Another similar case is: struct A;
struct B;
struct C;
struct D;
fn f(
a1: A,
a2: A,
b1: B,
b2: B,
c1: C,
c2: C,
) {}
fn main() {
f(C, A, A, A, B, B, C);
} with log: ai: [ExpectedIdx(0), ExpectedIdx(2), ExpectedIdx(3), ExpectedIdx(4), ExpectedIdx(5)]
ii: [ProvidedIdx(0), ProvidedIdx(2), ProvidedIdx(3), ProvidedIdx(4), ProvidedIdx(5), ProvidedIdx(6)]
================== find_issue: ==================
x| 0 1 2 3 4
-| - - - - -
0| 0 0 0 1 1
1| 1 0 0 0 0
2| 1 0 0 0 0
3| 0 1 1 0 0
4| 0 1 1 0 0
5| 0 0 0 1 1
i: 0, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 1, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 2, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 3, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 4, is_input: true, is_arg: true, useless: false, unsatisfiable: false
i: 5, is_input: true, is_arg: false, useless: false, unsatisfiable: true
loop i: 0 j: 0 compat: [3, 4]
permutation_found: false
now permutation: [Some(None), None, None, None, None, None]
loop i: 1 j: 1 compat: [0]
loop i: 1 j: 0 compat: [3, 4]
permutation_found: false
now permutation: [Some(None), None, None, None, None, None]
now permutation: [Some(None), Some(None), None, None, None, None]
loop i: 2 j: 2 compat: [0]
loop i: 2 j: 0 compat: [3, 4]
permutation_found: false
now permutation: [Some(None), Some(None), None, None, None, None]
now permutation: [Some(None), Some(None), Some(None), None, None, None]
loop i: 3 j: 3 compat: [1, 2]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), None, None]
loop i: 4 j: 4 compat: [1, 2]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), Some(None), None]
loop i: 5 j: 5 compat: [3, 4]
permutation_found: false
now permutation: [Some(None), Some(None), Some(None), Some(None), Some(None), Some(None)]
res: None
thread 'rustc' panicked at 'didn't eliminated any indice in this round', compiler/rustc_typeck/src/check/fn_ctxt/arg_matrix.rs:412:21 |
b9bdc01
to
5d81010
Compare
This comment has been minimized.
This comment has been minimized.
5d81010
to
7e7dfb8
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (56e7678): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Fixes #100478
Fixes #101097