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

Add variable support for new DDC async lowering #2471

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

biggs0125
Copy link
Contributor

The Dart web team recently updated DDC's async lowering to be more similar to that of dart2js. The previous lowering did not correctly implement the Dart language's async/await semantics causing divergences in code's behavior between production and development.

The new lowering creates a state machine that simulates the control flow from the Dart code. This lowering flattens the async function's body removing the scopes established by the Dart code (normally JS's scopes act as a proxy for Dart's scopes). To get around this we introduce scope objects that we use to manually reconstruct the original scopes.

For debugging purposes we want to make all the variables in these scope objects available as they are all user-declared variables in the source code. So to achieve this we unpack the available scope objects into the set of available variables (and hide the scope objects). DDC ensures that the names of the properties within the scope object match those used in the source code.

Fixes #2469

// DDC's async lowering hoists variable declarations into scope objects. We
// create one scope object per Dart scope (skipping scopes containing no
// declarations). If a Dart scope is captured by a Dart closure the
// JS scope object will also be captued by the compiled JS closure.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ubernit: 'captured'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@biggs0125 biggs0125 merged commit 645a068 into dart-lang:main Aug 2, 2024
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test\variable_scope_test.dart: variable scope variables in function is failing
3 participants