-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer analysis of closure arguments when
inference-update-1
is enab…
…led. In order to address dart-lang/language#731 (improved type inference for `fold` etc.) we're going to need to sometimes defer analysis of invocation arguments that are closures, so that closure parameters can have their types inferred based on other parameters. To avoid annoying the user with inconsistent behaviors, we defer analysis of closures in all circumstances, even if it's not necessary to do so for type inference purposes. This has a minor user-visible effect: if an invocation contains some closures and some non-closures, any demotions that happen due to write captures in the closures are postponed until the end of the invocation; this means that the write-captured variables remain promoted for other invocation arguments, even if those arguments appear after the closure. This is safe because there is no way for the closure to be called until after all of the other invocation arguments are evaluated. See the language tests in tests/language/inference_update_1/write_capture_deferral_enabled_test.dart for details. Note that this change only has an effect when the experimental feature `inference-update-1` is enabled. Change-Id: If7bb38e361755180c033ecb2108fc4fffa7570b1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241864 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
- Loading branch information
1 parent
edb7fb4
commit 08c6045
Showing
12 changed files
with
444 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,6 +341,7 @@ implemen | |
implementor | ||
implementors | ||
imprecision | ||
improvement | ||
inclosure | ||
inconsistencies | ||
increasing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--enable-experiment=inference-update-1 |
66 changes: 66 additions & 0 deletions
66
pkg/front_end/testcases/inference_update_1/write_capture_deferral.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Tests that when the feature is enabled, if an invocation argument is a | ||
// closure, write captures made by that closure do not take effect until after | ||
// the invocation. This is a minor improvement to flow analysis that falls | ||
// naturally out of the fact that closures are analyzed last (so that their | ||
// types can depend on the types of other arguments). | ||
|
||
withUnnamedArguments(int? i, void Function(void Function(), Object?) f) { | ||
if (i != null) { | ||
f(() { | ||
i = null; | ||
}, i); | ||
i; | ||
} | ||
} | ||
|
||
withNamedArguments( | ||
int? i, void Function({required void Function() g, Object? x}) f) { | ||
if (i != null) { | ||
f( | ||
g: () { | ||
i = null; | ||
}, | ||
x: i); | ||
i; | ||
} | ||
} | ||
|
||
withIdentical_lhs(int? i) { | ||
if (i != null) { | ||
i; | ||
identical(() { | ||
i = null; | ||
}, i); | ||
i; | ||
} | ||
} | ||
|
||
withIdentical_rhs(int? i) { | ||
if (i != null) { | ||
identical(i, () { | ||
i = null; | ||
}); | ||
i; | ||
} | ||
} | ||
|
||
class B { | ||
B(Object? x, void Function() g, Object? y); | ||
B.redirectingConstructorInvocation(int? i) | ||
: this(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
class C extends B { | ||
C.superConstructorInvocation(int? i) | ||
: super(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
main() {} |
22 changes: 22 additions & 0 deletions
22
...front_end/testcases/inference_update_1/write_capture_deferral.dart.textual_outline.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
withUnnamedArguments(int? i, void Function(void Function(), Object?) f) {} | ||
withNamedArguments( | ||
int? i, void Function({required void Function() g, Object? x}) f) {} | ||
withIdentical_lhs(int? i) {} | ||
withIdentical_rhs(int? i) {} | ||
|
||
class B { | ||
B(Object? x, void Function() g, Object? y); | ||
B.redirectingConstructorInvocation(int? i) | ||
: this(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
class C extends B { | ||
C.superConstructorInvocation(int? i) | ||
: super(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
main() {} |
21 changes: 21 additions & 0 deletions
21
.../testcases/inference_update_1/write_capture_deferral.dart.textual_outline_modelled.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class B { | ||
B(Object? x, void Function() g, Object? y); | ||
B.redirectingConstructorInvocation(int? i) | ||
: this(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
class C extends B { | ||
C.superConstructorInvocation(int? i) | ||
: super(i!, () { | ||
i = null; | ||
}, i); | ||
} | ||
|
||
main() {} | ||
withIdentical_lhs(int? i) {} | ||
withIdentical_rhs(int? i) {} | ||
withNamedArguments( | ||
int? i, void Function({required void Function() g, Object? x}) f) {} | ||
withUnnamedArguments(int? i, void Function(void Function(), Object?) f) {} |
Oops, something went wrong.