Skip to content

Commit b1db663

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
[dart2js] New RTI: Use precomputed1 to access first type argument of
interface types. Change-Id: I167bb9be3f07dd3734993a46283a9d6eea56ac92 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119960 Commit-Queue: Mayank Patke <fishythefish@google.com> Reviewed-by: Stephen Adams <sra@google.com>
1 parent 0122901 commit b1db663

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

pkg/compiler/lib/src/common_elements.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ abstract class CommonElements {
499499
FieldEntity get rtiCheckField;
500500
FieldEntity get rtiIsField;
501501
FieldEntity get rtiRestField;
502+
FieldEntity get rtiPrecomputed1Field;
502503
FunctionEntity get rtiEvalMethod;
503504
FunctionEntity get rtiBindMethod;
504505
FunctionEntity get rtiAddRulesMethod;
@@ -1914,6 +1915,11 @@ class CommonElementsImpl
19141915
@override
19151916
FieldEntity get rtiRestField => _rtiRestField ??= _findRtiClassField('_rest');
19161917

1918+
FieldEntity _rtiPrecomputed1Field;
1919+
@override
1920+
FieldEntity get rtiPrecomputed1Field =>
1921+
_rtiPrecomputed1Field ??= _findRtiClassField('_precomputed1');
1922+
19171923
FunctionEntity _rtiEvalMethod;
19181924
@override
19191925
FunctionEntity get rtiEvalMethod =>

pkg/compiler/lib/src/ssa/codegen.dart

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,14 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
22122212
}
22132213
}
22142214

2215+
js.Expression _loadField(js.Expression receiver, FieldEntity field,
2216+
SourceInformation sourceInformation) {
2217+
_registry.registerStaticUse(StaticUse.fieldGet(field));
2218+
js.Name name = _namer.instanceFieldPropertyName(field);
2219+
return js.PropertyAccess(receiver, name)
2220+
.withSourceInformation(sourceInformation);
2221+
}
2222+
22152223
@override
22162224
visitFieldGet(HFieldGet node) {
22172225
use(node.receiver);
@@ -2222,11 +2230,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
22222230
push(new js.PropertyAccess.field(pop(), 'toString')
22232231
.withSourceInformation(node.sourceInformation));
22242232
} else {
2225-
FieldEntity field = node.element;
2226-
js.Name name = _namer.instanceFieldPropertyName(field);
2227-
push(new js.PropertyAccess(pop(), name)
2228-
.withSourceInformation(node.sourceInformation));
2229-
_registry.registerStaticUse(new StaticUse.fieldGet(field));
2233+
push(_loadField(pop(), node.element, node.sourceInformation));
22302234
}
22312235
}
22322236

@@ -3492,13 +3496,20 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
34923496
// its length (i.e. into its base), since in that case, we could
34933497
// eval against the base directly.
34943498
assert(index <= bindings.length);
3499+
} else {
3500+
// If the environment is an interface RTI, use precomputed fields
3501+
// for common accesses.
3502+
if (index == 1) {
3503+
push(_loadField(environment, _commonElements.rtiPrecomputed1Field,
3504+
node.sourceInformation));
3505+
return;
3506+
}
34953507
}
3496-
js.Expression access = js.js('#.#[#]', [
3497-
environment,
3498-
_namer.instanceFieldPropertyName(_commonElements.rtiRestField),
3499-
js.number(index - 1),
3500-
]);
3501-
push(access.withSourceInformation(node.sourceInformation));
3508+
3509+
js.Expression rest = _loadField(environment,
3510+
_commonElements.rtiRestField, node.sourceInformation);
3511+
push(js.PropertyAccess.indexed(rest, index - 1)
3512+
.withSourceInformation(node.sourceInformation));
35023513
return;
35033514
}
35043515
}

sdk/lib/_internal/js_runtime/lib/rti.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class Rti {
9898
dynamic _precomputed3;
9999
dynamic _precomputed4;
100100

101+
static Rti _getPrecomputed1(Rti rti) => _castToRti(rti._precomputed1);
102+
static void _setPrecomputed1(Rti rti, Rti precomputed) {
103+
rti._precomputed1 = precomputed;
104+
}
105+
101106
// The Type object corresponding to this Rti.
102107
Object _cachedRuntimeType;
103108
static _Type _getCachedRuntimeType(Rti rti) =>
@@ -1495,6 +1500,10 @@ class _Universe {
14951500
Rti._setKind(rti, Rti.kindInterface);
14961501
Rti._setPrimary(rti, name);
14971502
Rti._setRest(rti, typeArguments);
1503+
int length = _Utils.arrayLength(typeArguments);
1504+
if (length > 0) {
1505+
Rti._setPrecomputed1(rti, _castToRti(_Utils.arrayAt(typeArguments, 0)));
1506+
}
14981507
Rti._setCanonicalRecipe(rti, key);
14991508
return _finishRti(universe, rti);
15001509
}
@@ -2077,6 +2086,7 @@ class _Parser {
20772086
if (kind != Rti.kindInterface) {
20782087
throw AssertionError('Indexed base must be an interface type');
20792088
}
2089+
if (index == 1) return Rti._getPrecomputed1(environment);
20802090
var typeArguments = Rti._getInterfaceTypeArguments(environment);
20812091
int len = _Utils.arrayLength(typeArguments);
20822092
if (index <= len) {

sdk_nnbd/lib/_internal/js_runtime/lib/rti.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class Rti {
100100
dynamic _precomputed3;
101101
dynamic _precomputed4;
102102

103+
static Rti _getPrecomputed1(Rti rti) => _castToRti(rti._precomputed1);
104+
static void _setPrecomputed1(Rti rti, Rti precomputed) {
105+
rti._precomputed1 = precomputed;
106+
}
107+
103108
// The Type object corresponding to this Rti.
104109
Object _cachedRuntimeType;
105110
static _Type _getCachedRuntimeType(Rti rti) =>
@@ -1497,6 +1502,10 @@ class _Universe {
14971502
Rti._setKind(rti, Rti.kindInterface);
14981503
Rti._setPrimary(rti, name);
14991504
Rti._setRest(rti, typeArguments);
1505+
int length = _Utils.arrayLength(typeArguments);
1506+
if (length > 0) {
1507+
Rti._setPrecomputed1(rti, _castToRti(_Utils.arrayAt(typeArguments, 0)));
1508+
}
15001509
Rti._setCanonicalRecipe(rti, key);
15011510
return _finishRti(universe, rti);
15021511
}
@@ -2079,6 +2088,7 @@ class _Parser {
20792088
if (kind != Rti.kindInterface) {
20802089
throw AssertionError('Indexed base must be an interface type');
20812090
}
2091+
if (index == 1) return Rti._getPrecomputed1(environment);
20822092
var typeArguments = Rti._getInterfaceTypeArguments(environment);
20832093
int len = _Utils.arrayLength(typeArguments);
20842094
if (index <= len) {

0 commit comments

Comments
 (0)