-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pkg/vm] Create @pragma("vm:platform-const-if", <cond>) annotation
If a static field or getter is annotated with @pragma("vm:platform-const-if", <cond>) and <cond> const evaluates to true, then uses of the static field or getter are const evaluated when a target operating system is available. If <cond> const evaluates to any other value, then the annotation is ignored. For example, when runtime-only code is guarded like the following, using Flutter's kDebugMode constant, then debug mode Flutter programs can alter the defaultTargetPlatform for testing, but in release mode, the defaultTargetPlatform getter is const evaluated and code guarded with defaultTargetPlatform checks can be eliminated if unreachable: @pragma("vm:platform-const-if", !kDebugMode) TargetPlatform get defaultTargetPlatform { ... assert(() { if (Platform.environment.containsKey('FLUTTER_TEST')) { result = TestPlatform.android; } return true; }()); if (kDebugMode && platform.debugDefaultTargetPlatformOverride != null) { result = platform.debugDefaultTargetPlatformOverride; } ... } TEST=pkg/vm/test/transformations/vm_constant_evaluator Change-Id: I55b88502a908c56cf42a761dd06741f15c8a23d9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333220 Reviewed-by: Alexander Markov <alexmarkov@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com>
- Loading branch information
Showing
34 changed files
with
4,181 additions
and
167 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
Oops, something went wrong.