Skip to content

Commit 02a34dd

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Remove type and null checks in dart:_runtime
Only removing checks for common calls within the type system that we know are always safe. Added `@notNull` on arguments typed to be non-nullable (in the nnbd version) to avoid producing the null checks. Added `Object` type to arguments to match the return type and avoid casts when returning. Change-Id: I05de45a8d923497f7340348ef2c0b9f72da5414b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143862 Reviewed-by: Mark Zhou <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent e6e9370 commit 02a34dd

File tree

2 files changed

+20
-20
lines changed
  • sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime
  • sdk/lib/_internal/js_dev_runtime/private/ddc_runtime

2 files changed

+20
-20
lines changed

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ final _subtypeCache = JS('', 'Symbol("_subtypeCache")');
271271
/// normalization doc:
272272
/// https://github.com/dart-lang/language/blob/master/resources/type-system/normalization.md
273273
@notNull
274-
Object nullable(type) {
274+
Object nullable(@notNull Object type) {
275275
// Check if a nullable version of this type has already been created.
276276
var cached = JS<Object>('', '#[#]', type, _cachedNullable);
277277
if (JS<bool>('!', '# !== void 0', cached)) {
@@ -284,7 +284,7 @@ Object nullable(type) {
284284
return cachedType;
285285
}
286286

287-
Object _computeNullable(type) {
287+
Object _computeNullable(@notNull Object type) {
288288
// *? normalizes to ?.
289289
if (_jsInstanceOf(type, LegacyType)) {
290290
return nullable(JS<Object>('!', '#.type', type));
@@ -309,7 +309,7 @@ Object _computeNullable(type) {
309309
/// normalization doc:
310310
/// https://github.com/dart-lang/language/blob/master/resources/type-system/normalization.md
311311
@notNull
312-
Object legacy(type) {
312+
Object legacy(@notNull Object type) {
313313
// Check if a legacy version of this type has already been created.
314314
var cached = JS<Object>('', '#[#]', type, _cachedLegacy);
315315
if (JS<bool>('!', '# !== void 0', cached)) {
@@ -322,7 +322,7 @@ Object legacy(type) {
322322
return cachedType;
323323
}
324324

325-
Object _computeLegacy(type) {
325+
Object _computeLegacy(@notNull Object type) {
326326
// Note: ?* normalizes to ?, so we cache type? at type?[_cachedLegacy].
327327
if (_jsInstanceOf(type, LegacyType) ||
328328
_jsInstanceOf(type, NullableType) ||
@@ -337,7 +337,7 @@ Object _computeLegacy(type) {
337337
class NullableType extends DartType {
338338
final Type type;
339339

340-
NullableType(this.type);
340+
NullableType(@notNull this.type);
341341

342342
@override
343343
String get name => '$type?';
@@ -358,7 +358,7 @@ class NullableType extends DartType {
358358
class LegacyType extends DartType {
359359
final Type type;
360360

361-
LegacyType(this.type);
361+
LegacyType(@notNull this.type);
362362

363363
@override
364364
String get name => '$type';
@@ -1140,7 +1140,7 @@ String typeName(type) => JS('', '''(() => {
11401140
})()''');
11411141

11421142
/// Returns true if [ft1] <: [ft2].
1143-
_isFunctionSubtype(ft1, ft2, bool strictMode) => JS('', '''(() => {
1143+
_isFunctionSubtype(ft1, ft2, @notNull bool strictMode) => JS('', '''(() => {
11441144
let ret1 = $ft1.returnType;
11451145
let ret2 = $ft2.returnType;
11461146
@@ -1233,7 +1233,7 @@ _isFunctionSubtype(ft1, ft2, bool strictMode) => JS('', '''(() => {
12331233

12341234
/// Returns true if [t1] <: [t2].
12351235
@notNull
1236-
bool isSubtypeOf(Object t1, Object t2) {
1236+
bool isSubtypeOf(@notNull Object t1, @notNull Object t2) {
12371237
// TODO(jmesserly): we've optimized `is`/`as`/implicit type checks, so they're
12381238
// dispatched on the type. Can we optimize the subtype relation too?
12391239
var map = JS<Object>('!', '#[#]', t1, _subtypeCache);
@@ -1313,7 +1313,7 @@ bool _isFutureOr(type) {
13131313
}
13141314

13151315
@notNull
1316-
bool _isSubtype(t1, t2, bool strictMode) => JS<bool>('!', '''(() => {
1316+
bool _isSubtype(t1, t2, @notNull bool strictMode) => JS<bool>('!', '''(() => {
13171317
if (!$strictMode) {
13181318
// Strip nullable types when performing check in weak mode.
13191319
// TODO(nshahan) Investigate stripping off legacy types as well.
@@ -1504,7 +1504,7 @@ bool _isSubtype(t1, t2, bool strictMode) => JS<bool>('!', '''(() => {
15041504
return ${_isFunctionSubtype(t1, t2, strictMode)};
15051505
})()''');
15061506

1507-
bool _isInterfaceSubtype(t1, t2, strictMode) => JS('', '''(() => {
1507+
bool _isInterfaceSubtype(t1, t2, @notNull bool strictMode) => JS('', '''(() => {
15081508
// If we have lazy JS types, unwrap them. This will effectively
15091509
// reduce to a prototype check below.
15101510
if (${_jsInstanceOf(t1, LazyJSType)}) $t1 = $t1.rawJSTypeForCheck();

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ final _subtypeCache = JS('', 'Symbol("_subtypeCache")');
269269
/// normalization doc:
270270
/// https://github.com/dart-lang/language/blob/master/resources/type-system/normalization.md
271271
@notNull
272-
Object nullable(type) {
272+
Object nullable(@notNull Object type) {
273273
// Check if a nullable version of this type has already been created.
274274
var cached = JS<Object>('', '#[#]', type, _cachedNullable);
275275
if (JS<bool>('!', '# !== void 0', cached)) {
@@ -282,7 +282,7 @@ Object nullable(type) {
282282
return cachedType;
283283
}
284284

285-
Object _computeNullable(type) {
285+
Object _computeNullable(@notNull Object type) {
286286
// *? normalizes to ?.
287287
if (_jsInstanceOf(type, LegacyType)) {
288288
return nullable(JS<Object>('!', '#.type', type));
@@ -307,7 +307,7 @@ Object _computeNullable(type) {
307307
/// normalization doc:
308308
/// https://github.com/dart-lang/language/blob/master/resources/type-system/normalization.md
309309
@notNull
310-
Object legacy(type) {
310+
Object legacy(@notNull Object type) {
311311
// Check if a legacy version of this type has already been created.
312312
var cached = JS<Object>('', '#[#]', type, _cachedLegacy);
313313
if (JS<bool>('!', '# !== void 0', cached)) {
@@ -320,7 +320,7 @@ Object legacy(type) {
320320
return cachedType;
321321
}
322322

323-
Object _computeLegacy(type) {
323+
Object _computeLegacy(@notNull Object type) {
324324
// Note: ?* normalizes to ?, so we cache type? at type?[_cachedLegacy].
325325
if (_jsInstanceOf(type, LegacyType) ||
326326
_jsInstanceOf(type, NullableType) ||
@@ -335,7 +335,7 @@ Object _computeLegacy(type) {
335335
class NullableType extends DartType {
336336
final Type type;
337337

338-
NullableType(this.type);
338+
NullableType(@notNull this.type);
339339

340340
@override
341341
String get name => '$type?';
@@ -356,7 +356,7 @@ class NullableType extends DartType {
356356
class LegacyType extends DartType {
357357
final Type type;
358358

359-
LegacyType(this.type);
359+
LegacyType(@notNull this.type);
360360

361361
@override
362362
String get name => '$type';
@@ -1138,7 +1138,7 @@ String typeName(type) => JS('', '''(() => {
11381138
})()''');
11391139

11401140
/// Returns true if [ft1] <: [ft2].
1141-
_isFunctionSubtype(ft1, ft2, bool strictMode) => JS('', '''(() => {
1141+
_isFunctionSubtype(ft1, ft2, @notNull bool strictMode) => JS('', '''(() => {
11421142
let ret1 = $ft1.returnType;
11431143
let ret2 = $ft2.returnType;
11441144
@@ -1231,7 +1231,7 @@ _isFunctionSubtype(ft1, ft2, bool strictMode) => JS('', '''(() => {
12311231

12321232
/// Returns true if [t1] <: [t2].
12331233
@notNull
1234-
bool isSubtypeOf(Object t1, Object t2) {
1234+
bool isSubtypeOf(@notNull Object t1, @notNull Object t2) {
12351235
// TODO(jmesserly): we've optimized `is`/`as`/implicit type checks, so they're
12361236
// dispatched on the type. Can we optimize the subtype relation too?
12371237
var map = JS<Object>('!', '#[#]', t1, _subtypeCache);
@@ -1311,7 +1311,7 @@ bool _isFutureOr(type) {
13111311
}
13121312

13131313
@notNull
1314-
bool _isSubtype(t1, t2, bool strictMode) => JS<bool>('!', '''(() => {
1314+
bool _isSubtype(t1, t2, @notNull bool strictMode) => JS<bool>('!', '''(() => {
13151315
if (!$strictMode) {
13161316
// Strip nullable types when performing check in weak mode.
13171317
// TODO(nshahan) Investigate stripping off legacy types as well.
@@ -1502,7 +1502,7 @@ bool _isSubtype(t1, t2, bool strictMode) => JS<bool>('!', '''(() => {
15021502
return ${_isFunctionSubtype(t1, t2, strictMode)};
15031503
})()''');
15041504

1505-
bool _isInterfaceSubtype(t1, t2, strictMode) => JS('', '''(() => {
1505+
bool _isInterfaceSubtype(t1, t2, @notNull bool strictMode) => JS('', '''(() => {
15061506
// If we have lazy JS types, unwrap them. This will effectively
15071507
// reduce to a prototype check below.
15081508
if (${_jsInstanceOf(t1, LazyJSType)}) $t1 = $t1.rawJSTypeForCheck();

0 commit comments

Comments
 (0)