Skip to content

Commit 57d877f

Browse files
mkustermannCommit Queue
authored and
Commit Queue
committed
[dart2wasm] Omit details in TypeErrors in --minify mode
This avoids passing down information to slow paths, making type checks smaller. Change-Id: I7071849b5bf08bb0744c8d5592fb258b78cbcc05 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404565 Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 358ae88 commit 57d877f

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

sdk/lib/_internal/wasm/lib/core_patch.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "dart:_internal"
1414
jsonEncode,
1515
ListIterator,
1616
Lists,
17+
minify,
1718
mix64,
1819
patch,
1920
POWERS_OF_TEN,

sdk/lib/_internal/wasm/lib/error_utils.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,15 @@ class _ErrorWithoutDetails implements Error {
185185

186186
String toString() => _message;
187187
}
188+
189+
const _TypeErrorWithoutDetails typeErrorWithoutDetails =
190+
_TypeErrorWithoutDetails();
191+
192+
class _TypeErrorWithoutDetails implements TypeError {
193+
const _TypeErrorWithoutDetails();
194+
195+
StackTrace? get stackTrace => null;
196+
197+
String toString() =>
198+
'Runtime type check failed (details omitted due to --minify)';
199+
}

sdk/lib/_internal/wasm/lib/type.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ void _asSubtype(Object? o, bool onlyNullabilityCheck, _Type t) {
15081508
? _isNullabilityCheck(o, t.isDeclaredNullable)
15091509
: _isSubtype(o, t);
15101510
if (success) return;
1511-
_TypeError._throwAsCheckError(o, t);
1511+
_throwAsCheckError(o, t);
15121512
}
15131513

15141514
@pragma("wasm:entry-point")
@@ -1592,11 +1592,12 @@ void _asInterfaceSubtype2(
15921592
}
15931593

15941594
@pragma('wasm:never-inline')
1595-
void _throwInterfaceTypeAsCheckError0(
1595+
Never _throwInterfaceTypeAsCheckError0(
15961596
Object? o,
15971597
bool isDeclaredNullable,
15981598
WasmI32 tId,
15991599
) {
1600+
if (minify) throw typeErrorWithoutDetails;
16001601
final typeArguments = const WasmArray<_Type>.literal([]);
16011602
_TypeError._throwAsCheckError(
16021603
o,
@@ -1606,12 +1607,13 @@ void _throwInterfaceTypeAsCheckError0(
16061607

16071608
@pragma("wasm:entry-point")
16081609
@pragma('wasm:never-inline')
1609-
void _throwInterfaceTypeAsCheckError1(
1610+
Never _throwInterfaceTypeAsCheckError1(
16101611
Object? o,
16111612
bool isDeclaredNullable,
16121613
WasmI32 tId,
16131614
_Type typeArgument0,
16141615
) {
1616+
if (minify) throw typeErrorWithoutDetails;
16151617
final typeArguments = WasmArray<_Type>.literal([typeArgument0]);
16161618
_TypeError._throwAsCheckError(
16171619
o,
@@ -1621,13 +1623,14 @@ void _throwInterfaceTypeAsCheckError1(
16211623

16221624
@pragma("wasm:entry-point")
16231625
@pragma('wasm:never-inline')
1624-
void _throwInterfaceTypeAsCheckError2(
1626+
Never _throwInterfaceTypeAsCheckError2(
16251627
Object? o,
16261628
bool isDeclaredNullable,
16271629
WasmI32 tId,
16281630
_Type typeArgument0,
16291631
_Type typeArgument1,
16301632
) {
1633+
if (minify) throw typeErrorWithoutDetails;
16311634
final typeArguments = WasmArray<_Type>.literal([
16321635
typeArgument0,
16331636
typeArgument1,
@@ -1640,18 +1643,26 @@ void _throwInterfaceTypeAsCheckError2(
16401643

16411644
@pragma("wasm:entry-point")
16421645
@pragma('wasm:never-inline')
1643-
void _throwInterfaceTypeAsCheckError(
1646+
Never _throwInterfaceTypeAsCheckError(
16441647
Object? o,
16451648
bool isDeclaredNullable,
16461649
WasmI32 tId,
16471650
WasmArray<_Type> typeArguments,
16481651
) {
1652+
if (minify) throw typeErrorWithoutDetails;
16491653
_TypeError._throwAsCheckError(
16501654
o,
16511655
_InterfaceType(tId, isDeclaredNullable, typeArguments),
16521656
);
16531657
}
16541658

1659+
@pragma("wasm:entry-point")
1660+
@pragma('wasm:never-inline')
1661+
Never _throwAsCheckError(Object? o, _Type type) {
1662+
if (minify) throw typeErrorWithoutDetails;
1663+
_TypeError._throwAsCheckError(o, type);
1664+
}
1665+
16551666
@pragma("wasm:entry-point")
16561667
bool _verifyOptimizedTypeCheck(
16571668
bool result,

0 commit comments

Comments
 (0)