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

CFE sometimes pops flow analysis constructs out of order #43725

Closed
stereotype441 opened this issue Oct 8, 2020 · 5 comments
Closed

CFE sometimes pops flow analysis constructs out of order #43725

stereotype441 opened this issue Oct 8, 2020 · 5 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@stereotype441
Copy link
Member

When analyzing the following code:

f(int? i, List? l) => i ?? l?.length;

CFE makes the following calls to flow analysis (excluding calls to isReachable, isAssigned, and isUnassigned, which are not relevant to this bug):

declare(VariableDeclaration(int? i), true)
declare(VariableDeclaration(List<dynamic>? l), true)
variableRead(VariableGetImpl(i), VariableDeclaration(int? i))
ifNullExpression_rightBegin(VariableGetImpl(i), InterfaceType(int?))
variableRead(VariableGetImpl(l), VariableDeclaration(List<dynamic>? l))
nullAwareAccess_rightBegin(VariableGetImpl(l), InterfaceType(List<dynamic>?))
variableRead(VariableGet(#0), VariableDeclaration(final List<dynamic>? #0))
nullAwareAccess_rightBegin(VariableGet(#0), InterfaceType(List<dynamic>?))
ifNullExpression_end()
nullAwareAccess_end()
nullAwareAccess_end()
handleExit()
finish()

This is improperly nested. The call to ifNullExpression_end should occur after the two calls to nullAwareAccess_end.

Fortunately this is a benign bug, for now, because ifNullExpression_end and nullAwareAccess_end have identical behavior. But it's technical debt, because it limits our ability to change the behavior of those two methods in the future.

@stereotype441 stereotype441 added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Oct 8, 2020
@stereotype441
Copy link
Member Author

@johnniwinther FYI

@johnniwinther
Copy link
Member

I think this can be solved by moving calls to ifNullExpression_end to the end of the visit methods.

Given that nullAwareAccess_end is called implicitly when shorting is stopped by reading a subexpression as an expresssion (as opposed to a guard and an action) this might happen elsewhere.

dart-bot pushed a commit that referenced this issue Oct 8, 2020
Note that due to #43725 we
can't yet downcast to these subclasses in all cases; added a test case
that would fail if we did.

Change-Id: Idd498840484a6a4c60a0cf2f8e01092ba75e7d2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166722
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
dart-bot pushed a commit that referenced this issue Oct 8, 2020
… code.

Due to #43725 these have to be
updated in a single atomic CL.

Bug: #40009
Change-Id: Ifbd5fdee6379b7cbee5ab135f72a013134b70aa1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166601
Reviewed-by: Johnni Winther <johnniwinther@google.com>
@stereotype441
Copy link
Member Author

I think this can be solved by moving calls to ifNullExpression_end to the end of the visit methods.

Given that nullAwareAccess_end is called implicitly when shorting is stopped by reading a subexpression as an expresssion (as opposed to a guard and an action) this might happen elsewhere.

@johnniwinther as we discussed in our meeting today, I made an attempt along the lines of your suggestion. It didn't work out too well :(

https://dart-review.googlesource.com/c/sdk/+/167146

@johnniwinther
Copy link
Member

Thanks for trying. I'll take it from here.

@johnniwinther
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.
Projects
None yet
Development

No branches or pull requests

2 participants