Commit 57a1168
[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 <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Tess Strickland <[email protected]>1 parent 91d16af commit 57a1168
File tree
34 files changed
+4181
-167
lines changed- pkg
- front_end/lib/src/fasta/kernel
- vm
- lib
- transformations
- testcases/transformations/vm_constant_evaluator
- test
- transformations
- runtime/docs
34 files changed
+4181
-167
lines changedLines changed: 25 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
763 | 763 | | |
764 | 764 | | |
765 | 765 | | |
766 | | - | |
767 | | - | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
768 | 772 | | |
769 | 773 | | |
770 | 774 | | |
| |||
2443 | 2447 | | |
2444 | 2448 | | |
2445 | 2449 | | |
2446 | | - | |
| 2450 | + | |
| 2451 | + | |
2447 | 2452 | | |
2448 | 2453 | | |
2449 | 2454 | | |
| |||
2488 | 2493 | | |
2489 | 2494 | | |
2490 | 2495 | | |
| 2496 | + | |
2491 | 2497 | | |
2492 | 2498 | | |
2493 | 2499 | | |
| |||
3692 | 3698 | | |
3693 | 3699 | | |
3694 | 3700 | | |
| 3701 | + | |
3695 | 3702 | | |
3696 | 3703 | | |
3697 | 3704 | | |
| |||
4577 | 4584 | | |
4578 | 4585 | | |
4579 | 4586 | | |
4580 | | - | |
4581 | | - | |
4582 | | - | |
4583 | | - | |
4584 | | - | |
4585 | | - | |
4586 | | - | |
4587 | | - | |
4588 | | - | |
4589 | | - | |
4590 | | - | |
4591 | | - | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
| 4590 | + | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
4592 | 4594 | | |
4593 | 4595 | | |
4594 | | - | |
4595 | | - | |
4596 | | - | |
4597 | | - | |
4598 | | - | |
| 4596 | + | |
| 4597 | + | |
4599 | 4598 | | |
4600 | | - | |
| 4599 | + | |
| 4600 | + | |
| 4601 | + | |
| 4602 | + | |
| 4603 | + | |
4601 | 4604 | | |
4602 | 4605 | | |
4603 | 4606 | | |
| |||
5617 | 5620 | | |
5618 | 5621 | | |
5619 | 5622 | | |
| 5623 | + | |
5620 | 5624 | | |
5621 | 5625 | | |
5622 | 5626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
581 | 583 | | |
582 | 584 | | |
583 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
| |||
175 | 189 | | |
176 | 190 | | |
177 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
178 | 196 | | |
Lines changed: 16 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 51 | | |
68 | | - | |
69 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
70 | 55 | | |
71 | 56 | | |
72 | 57 | | |
| |||
219 | 204 | | |
220 | 205 | | |
221 | 206 | | |
222 | | - | |
223 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
224 | 211 | | |
| 212 | + | |
225 | 213 | | |
226 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
227 | 222 | | |
228 | 223 | | |
229 | 224 | | |
| |||
0 commit comments