Skip to content

Commit b334ea8

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] new-rti: experiment - fault in '$is' test
Change-Id: Ie6d17e3439fb67fe79e9dec4dc7cb5437d1f6915 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121766 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Stephen Adams <sra@google.com>
1 parent 7a45228 commit b334ea8

File tree

3 files changed

+90
-8
lines changed

3 files changed

+90
-8
lines changed

pkg/compiler/lib/src/js_backend/namer.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,8 @@ abstract class ModularNamer {
25712571
return asName(fixedNames.deferredAction);
25722572
case JsGetName.OPERATOR_AS_PREFIX:
25732573
return asName(fixedNames.operatorAsPrefix);
2574+
case JsGetName.OPERATOR_IS_PREFIX:
2575+
return asName(fixedNames.operatorIsPrefix);
25742576
case JsGetName.SIGNATURE_NAME:
25752577
return asName(fixedNames.operatorSignature);
25762578
case JsGetName.RTI_NAME:

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ class Rti {
109109
rti._precomputed1 = precomputed;
110110
}
111111

112+
// Data value used by some tests.
113+
@pragma('dart2js:noElision')
114+
Object _specializedTestResource;
115+
116+
static Object _getSpecializedTestResource(Rti rti) {
117+
return rti._specializedTestResource;
118+
}
119+
120+
static void _setSpecializedTestResource(Rti rti, Object value) {
121+
rti._specializedTestResource = value;
122+
}
123+
112124
// The Type object corresponding to this Rti.
113125
Object _cachedRuntimeType;
114126
static _Type _getCachedRuntimeType(Rti rti) =>
@@ -549,6 +561,9 @@ _FunctionParameters _instantiateFunctionParameters(universe,
549561
return result;
550562
}
551563

564+
bool _isDartObject(object) => _Utils.instanceOf(object,
565+
JS_BUILTIN('depends:none;effects:none;', JsBuiltin.dartObjectConstructor));
566+
552567
bool _isClosure(object) => _Utils.instanceOf(object,
553568
JS_BUILTIN('depends:none;effects:none;', JsBuiltin.dartClosureConstructor));
554569

@@ -597,10 +612,7 @@ Rti instanceType(object) {
597612
// called, similar to a one-shot interceptor call. This would improve type
598613
// lookup in ListMixin code as the interceptor is JavaScript 'this'.
599614

600-
if (_Utils.instanceOf(
601-
object,
602-
JS_BUILTIN(
603-
'depends:none;effects:none;', JsBuiltin.dartObjectConstructor))) {
615+
if (_isDartObject(object)) {
604616
return _instanceType(object);
605617
}
606618

@@ -762,6 +774,16 @@ bool _installSpecializedIsTest(object) {
762774
isFn = RAW_DART_FUNCTION_REF(_isString);
763775
} else if (JS_GET_NAME(JsGetName.BOOL_RECIPE) == key) {
764776
isFn = RAW_DART_FUNCTION_REF(_isBool);
777+
} else {
778+
String name = Rti._getInterfaceName(testRti);
779+
var arguments = Rti._getInterfaceTypeArguments(testRti);
780+
if (JS(
781+
'bool', '#.every(#)', arguments, RAW_DART_FUNCTION_REF(isTopType))) {
782+
String propertyName =
783+
'${JS_GET_NAME(JsGetName.OPERATOR_IS_PREFIX)}${name}';
784+
Rti._setSpecializedTestResource(testRti, propertyName);
785+
isFn = RAW_DART_FUNCTION_REF(_isTestViaProperty);
786+
}
765787
}
766788
}
767789

@@ -778,6 +800,24 @@ bool _generalIsTestImplementation(object) {
778800
return isSubtype(_theUniverse(), objectRti, testRti);
779801
}
780802

803+
/// Called from generated code.
804+
bool _isTestViaProperty(object) {
805+
// This static method is installed on an Rti object as a JavaScript instance
806+
// method. The Rti object is 'this'.
807+
Rti testRti = _castToRti(JS('', 'this'));
808+
var tag = Rti._getSpecializedTestResource(testRti);
809+
810+
// This test is redundant with getInterceptor below, but getInterceptor does
811+
// the tests in the wrong order for most tags, so it is usually faster to have
812+
// this check.
813+
if (_isDartObject(object)) {
814+
return JS('bool', '!!#[#]', object, tag);
815+
}
816+
817+
var interceptor = getInterceptor(object);
818+
return JS('bool', '!!#[#]', interceptor, tag);
819+
}
820+
781821
/// Called from generated code.
782822
_generalAsCheckImplementation(object) {
783823
if (object == null) return object;

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ class Rti {
111111
rti._precomputed1 = precomputed;
112112
}
113113

114+
// Data value used by some tests.
115+
@pragma('dart2js:noElision')
116+
Object _specializedTestResource;
117+
118+
static Object _getSpecializedTestResource(Rti rti) {
119+
return rti._specializedTestResource;
120+
}
121+
122+
static void _setSpecializedTestResource(Rti rti, Object value) {
123+
rti._specializedTestResource = value;
124+
}
125+
114126
// The Type object corresponding to this Rti.
115127
Object _cachedRuntimeType;
116128
static _Type _getCachedRuntimeType(Rti rti) =>
@@ -551,6 +563,9 @@ _FunctionParameters _instantiateFunctionParameters(universe,
551563
return result;
552564
}
553565

566+
bool _isDartObject(object) => _Utils.instanceOf(object,
567+
JS_BUILTIN('depends:none;effects:none;', JsBuiltin.dartObjectConstructor));
568+
554569
bool _isClosure(object) => _Utils.instanceOf(object,
555570
JS_BUILTIN('depends:none;effects:none;', JsBuiltin.dartClosureConstructor));
556571

@@ -599,10 +614,7 @@ Rti instanceType(object) {
599614
// called, similar to a one-shot interceptor call. This would improve type
600615
// lookup in ListMixin code as the interceptor is JavaScript 'this'.
601616

602-
if (_Utils.instanceOf(
603-
object,
604-
JS_BUILTIN(
605-
'depends:none;effects:none;', JsBuiltin.dartObjectConstructor))) {
617+
if (_isDartObject(object)) {
606618
return _instanceType(object);
607619
}
608620

@@ -764,6 +776,16 @@ bool _installSpecializedIsTest(object) {
764776
isFn = RAW_DART_FUNCTION_REF(_isString);
765777
} else if (JS_GET_NAME(JsGetName.BOOL_RECIPE) == key) {
766778
isFn = RAW_DART_FUNCTION_REF(_isBool);
779+
} else {
780+
String name = Rti._getInterfaceName(testRti);
781+
var arguments = Rti._getInterfaceTypeArguments(testRti);
782+
if (JS(
783+
'bool', '#.every(#)', arguments, RAW_DART_FUNCTION_REF(isTopType))) {
784+
String propertyName =
785+
'${JS_GET_NAME(JsGetName.OPERATOR_IS_PREFIX)}${name}';
786+
Rti._setSpecializedTestResource(testRti, propertyName);
787+
isFn = RAW_DART_FUNCTION_REF(_isTestViaProperty);
788+
}
767789
}
768790
}
769791

@@ -780,6 +802,24 @@ bool _generalIsTestImplementation(object) {
780802
return isSubtype(_theUniverse(), objectRti, testRti);
781803
}
782804

805+
/// Called from generated code.
806+
bool _isTestViaProperty(object) {
807+
// This static method is installed on an Rti object as a JavaScript instance
808+
// method. The Rti object is 'this'.
809+
Rti testRti = _castToRti(JS('', 'this'));
810+
var tag = Rti._getSpecializedTestResource(testRti);
811+
812+
// This test is redundant with getInterceptor below, but getInterceptor does
813+
// the tests in the wrong order for most tags, so it is usually faster to have
814+
// this check.
815+
if (_isDartObject(object)) {
816+
return JS('bool', '!!#[#]', object, tag);
817+
}
818+
819+
var interceptor = getInterceptor(object);
820+
return JS('bool', '!!#[#]', interceptor, tag);
821+
}
822+
783823
/// Called from generated code.
784824
_generalAsCheckImplementation(object) {
785825
if (object == null) return object;

0 commit comments

Comments
 (0)