Skip to content

Commit 5492cfd

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Never elide _Enum.index
This ensures that `_Enum.index` is always available for switch strength reduction optimizations. Most real programs use the index of at least one `enum`, so the field is not usually elided. This change makes small tests and benchmarks behave more like real programs where these optimizations happen. Bug: #51657 CoreLibraryReviewExempt: dart2js specific annotation Change-Id: If98e483d7cce265e823fd574565089e328215cca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446481 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 5072ac8 commit 5492cfd

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

benchmarks/SwitchFSM/dart/SwitchFSM.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ class Benchmark extends BenchmarkBase {
136136
enum SomeEnum { element }
137137

138138
void main() {
139-
// TODO(http://dartbug.com/51657): dart2js will remove `_Enum.index` in simple
140-
// programs that don't appear to use the field. This defeats the enum-switch
141-
// optimization that works more reliably in larger programs. Remove this code
142-
// that marks `_Enum.index` as used when #51657 is fixed.
143-
Expect.equals(0, SomeEnum.element.index);
144-
145139
final benchmarks = [
146140
Benchmark('enum', match_enum.match),
147141
Benchmark('int', match_int.match),

pkg/compiler/test/codegen/model_data/effectively_constant_state.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
enum Enum { a, b, c }
66

7-
/*member: tester1:params=0*/
8-
@pragma('dart2js:noInline')
7+
@pragma('dart2js:never-inline')
98
tester1() {}
109

1110
/*member: tester2:params=0*/
12-
@pragma('dart2js:noInline')
11+
@pragma('dart2js:never-inline')
1312
tester2() {}
1413

1514
/*member: tester3:params=0*/
16-
@pragma('dart2js:noInline')
15+
@pragma('dart2js:never-inline')
1716
tester3() {}
1817

1918
class Class {
@@ -26,7 +25,7 @@ class Class {
2625
Class({this.state1 = 1, this.state2 = Enum.c});
2726

2827
/*member: Class.method1a:calls=[tester2(0)],params=0*/
29-
@pragma('dart2js:noInline')
28+
@pragma('dart2js:never-inline')
3029
method1a() {
3130
if (state1 == 0) {
3231
return tester1();
@@ -39,7 +38,7 @@ class Class {
3938

4039
// TODO(johnniwinther): Inline switch cases with constant expressions.
4140
/*member: Class.method1b:calls=[tester2(0)],params=0,switch*/
42-
@pragma('dart2js:noInline')
41+
@pragma('dart2js:never-inline')
4342
method1b() {
4443
switch (state1) {
4544
case 0:
@@ -52,7 +51,7 @@ class Class {
5251
}
5352

5453
/*member: Class.method2a:calls=[tester3(0)],params=0*/
55-
@pragma('dart2js:noInline')
54+
@pragma('dart2js:never-inline')
5655
method2a() {
5756
if (state2 == Enum.a) {
5857
return tester1();
@@ -63,10 +62,9 @@ class Class {
6362
}
6463
}
6564

66-
/*member: Class.method2b:calls=[tester1(0),tester2(0),tester3(0)],params=0,switch*/
67-
@pragma('dart2js:noInline')
65+
/*member: Class.method2b:calls=[tester3(0)],params=0,switch*/
66+
@pragma('dart2js:never-inline')
6867
method2b() {
69-
// TODO(johnniwinther): Eliminate dead code in enum switch.
7068
switch (state2) {
7169
case Enum.a:
7270
return tester1();

sdk/lib/core/enum.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ abstract interface class Enum {
102102
/// Superclass of all enum class implementations.
103103
@pragma('dyn-module:language-impl:extendable')
104104
abstract class _Enum implements Enum {
105+
// See http://dartbug.com/51657 for discussion of dart2js pragma.
106+
@pragma('dart2js:noElision')
105107
final int index;
106108

107109
@pragma('dyn-module:language-impl:callable')

0 commit comments

Comments
 (0)