Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Issue 2991853002: Fix duplicate context creation when closures appear in initializers. (Closed)

Created:
3 years, 4 months ago by sjindel
Modified:
3 years, 4 months ago
Reviewers:
Dmitry Stefantsov
CC:
reviews_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Fix duplicate context creation when closures appear in initializers. Summary: Previously, when a function parameter was captured both in an initializer and in the body of a constructor, we would create two contexts: one created in a local initializer and used by other initializers, and another in the body of the function. This is incorrect, as it means that changes to the parameter in the initializer's closure won't be visible in the body. Now, to work around this problem we re-use the context created for the initializers in the body of the constructor by moving the body into a new constructor, and redirecting the original constructor to that one, passing the context as an additional argument. This dance is necessary because local initializers aren't visible in the body of a constructor. Test Plan: A few of the existing closure conversion tests were changed or fixed by this revision. We also modify the 'closure_in_initializer.dart' test to hit this case directly. R=dmitryas@google.com Reviewers: dmitryas@google.com Committed: https://github.com/dart-lang/sdk/commit/454ab91576ffd071b2e6a9b54f67453f33b8ee21

Patch Set 1 #

Total comments: 22

Patch Set 2 : Review comments: don't use the redirecting technique unless necessary. #

Total comments: 25

Patch Set 3 : Review comments. #

Total comments: 16

Patch Set 4 : Review comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+169 lines, -53 lines) Patch
M pkg/kernel/lib/transformations/closure/converter.dart View 1 2 3 15 chunks +121 lines, -33 lines 0 comments Download
M pkg/kernel/lib/transformations/closure/info.dart View 1 2 3 3 chunks +32 lines, -5 lines 0 comments Download
M pkg/kernel/testcases/closures/closure_in_constructor.dart.expect View 1 1 chunk +1 line, -1 line 0 comments Download
M pkg/kernel/testcases/closures/closure_in_initializer.dart View 1 chunk +4 lines, -3 lines 0 comments Download
M pkg/kernel/testcases/closures/closure_in_initializer.dart.expect View 1 chunk +11 lines, -9 lines 0 comments Download
M pkg/kernel/testcases/closures/closure_in_initializer_closure.dart.expect View 1 1 chunk +0 lines, -2 lines 0 comments Download

Messages

Total messages: 11 (2 generated)
sjindel
3 years, 4 months ago (2017-07-27 12:23:34 UTC) #2
Dmitry Stefantsov
I have some questions. Please, find them below. https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart File pkg/kernel/lib/transformations/closure/converter.dart (right): https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart#newcode235 pkg/kernel/lib/transformations/closure/converter.dart:235: for ...
3 years, 4 months ago (2017-07-28 12:36:16 UTC) #3
sjindel
https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart File pkg/kernel/lib/transformations/closure/converter.dart (right): https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart#newcode235 pkg/kernel/lib/transformations/closure/converter.dart:235: for (var i = 1; i < node.initializers.length; ++i) ...
3 years, 4 months ago (2017-07-31 12:06:21 UTC) #4
Dmitry Stefantsov
Great to see the situation with closures in initializers improving. I have some questions about ...
3 years, 4 months ago (2017-07-31 15:05:36 UTC) #5
sjindel
https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart File pkg/kernel/lib/transformations/closure/converter.dart (right): https://codereview.chromium.org/2991853002/diff/1/pkg/kernel/lib/transformations/closure/converter.dart#newcode445 pkg/kernel/lib/transformations/closure/converter.dart:445: [Context reuse = null]) { On 2017/07/31 15:05:35, Dmitry ...
3 years, 4 months ago (2017-07-31 15:32:16 UTC) #6
Dmitry Stefantsov
I still have some questions :) Please, note that there are some new comments from ...
3 years, 4 months ago (2017-08-01 09:36:14 UTC) #7
sjindel
https://codereview.chromium.org/2991853002/diff/40001/pkg/kernel/lib/transformations/closure/converter.dart File pkg/kernel/lib/transformations/closure/converter.dart (right): https://codereview.chromium.org/2991853002/diff/40001/pkg/kernel/lib/transformations/closure/converter.dart#newcode75 pkg/kernel/lib/transformations/closure/converter.dart:75: // they are captured inside or outside an initializer. ...
3 years, 4 months ago (2017-08-01 14:58:25 UTC) #8
Dmitry Stefantsov
LGTM https://codereview.chromium.org/2991853002/diff/40001/pkg/kernel/lib/transformations/closure/info.dart File pkg/kernel/lib/transformations/closure/info.dart (right): https://codereview.chromium.org/2991853002/diff/40001/pkg/kernel/lib/transformations/closure/info.dart#newcode41 pkg/kernel/lib/transformations/closure/info.dart:41: final Map<VariableDeclaration, int> variables = <VariableDeclaration, int>{}; On ...
3 years, 4 months ago (2017-08-03 09:28:26 UTC) #9
sjindel
3 years, 4 months ago (2017-08-03 09:33:46 UTC) #11
Message was sent while issue was closed.
Committed patchset #4 (id:60001) manually as
454ab91576ffd071b2e6a9b54f67453f33b8ee21 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698