-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[analyzer] analyzer starts leaking when typing a switch expression #52352
Comments
It would be nice if you provided snippets of code with your issues. |
Sure, will do! It happened on typing (at least that how it looked). So I'm not sure that tests can spot it. |
I tried to type something similar in the IDE, outside tests, but cannot get it into "sticky errors" when it cycles :-( void f(IfStatement node) {
final innerIf = switch (node.thenStatement) {
Block(statements: [IfStatement inner]) => inner,
_ => null,
};
print(innerIf);
} |
Interesting, now I also cant repro it in one go. I understood that when "dart.fix" added final: final innerIf = switch (node.thenStatement) {
Block(statements: [final IfStatement inner]) => inner,
}; will try again, maybe it has something to do with the order in which code is added. |
Yep, got it again. Trying to extract steps. |
As you can see on the second video analyzer is already slowed down, but it was not recorded instantly, probably after 2-3 GB leaked. |
After the process is killed manually, this code does not trigger the leak (not typing this code, but its presence). final innerIf = switch (node.thenStatement) {
Block(statements: [final IfStatement inner]) =>inner,
}; |
Let me know if you need anything else. |
It might be not obvious, but I cannot reproduce it. |
I'll try to extract the exact step, I think I'm close. |
final innerIf = switch (node.thenStatement) {
Block(statements: [if])
}; can you try this one? restarting analyzer here leads to immediate leak. |
Note: I got |
It seems to did it! y IDE does not update semantic highlighting, and the DAS process eats CPU. |
You're welcome! This one was very tricky. |
I cleaned it up to void f(Object? x) {
switch (x) {
case [if]
};
} This code cycles the unit test code above. |
@stereotype441 could you take a look? |
It even does not matter whether it's |
I'm able to reproduce this and I'm investigating. |
Thanks @incendial and @scheglov for tracking down such a small repro! It made it a lot easier to debug the problem. I've landed a fix in the main development branch, and I've requested approval too cherry-pick it into the 3.0.1 stable release (#52376). |
Thanks! Considering the fix was in |
The code that gets run under the hood when you're interacting with your editor is the code that's included in the Dart SDK, even if that code comes ultimately from the So far there's no published version of the SDK that includes the fix. Hopefully it will show up in the dev channel later today (dev channel builds have been happening about once every four hours recently). After that it will hopefully show up in the 3.0.1 stable hotfix (assuming my cherry-pick request gets approved). I'm currently checking whether there's a target date for 3.0.1 that I can share publicly. |
I work on a tool that uses So it matters to me 🙂. |
Ah, ok. In that case I'll defer to @scheglov, who usually does the releases of |
I'm not ready to publish yet, would like to wait a few days after a3956e4 https://dart-review.googlesource.com/c/sdk/+/303012 for now, not that it is much useful for you, but it record that this issue is fixed :-) |
There is a demand for a new analyzer version. #52352 (comment) I'm not ready to publish yet, lets wait for a couple of days after landing `InvalidType`. But I'd like to record issues fixed. Change-Id: I045ba904e3a229939fca5e37d63f16624cff8872 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303012 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
…es progress. In rare circumstances involving syntax errors, the `parsePattern` method inserts a synthetic token but does not consume any tokens. Usually when this happens it's not a problem, because whatever method is calling `parsePattern` consumes some tokens, so the parser always makes progress. However, when parsing list patterns, after calling `parsePattern`, the parser would look for a `,`, and if it didn't find one, it would supply a synthetic `,` and call `parsePattern` again, resulting in an infinite loop. A similar situation happened with map patterns, though the situation was more complex because in between the calls to `parsePattern`, the parser would also create synthetic key expressions and `:`s. To fix the problem, when parsing a list or map pattern, after the call to `parsePattern`, the parser checks whether any tokens were consumed. If no tokens were consumed, it ignores the next token from the input stream in order to make progress. I also investigated whether there were similar issues with parenthesized/record patterns and switch expressions, since those constructs also consist of a sequence of patterns separated by tokens and other things that could in principle be supplied synthetically. Fortunately, parser recovery doesn't get into an infinite loop in those cases, so I didn't make any further changes. But I did include test cases to make sure. Fixes: #52376 Bug: #52352 Change-Id: Ic9abf1bb82b8d7e1eb18e8a771a2ff9116fcfe21 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/302803 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303081 Reviewed-by: Jens Johansen <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
When I type the following code, analyzer memory usage just skyrockets. Restarting the process via VS Code does not kill the existing one.
Been able to repro this 2 times in a row.
Here is a video on produced errors.
Screen.Recording.2023-05-11.at.17.06.20.mov
Let me know what else I need to provide for this to be fixed.
The text was updated successfully, but these errors were encountered: