Skip to content

Commit 3272abc

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/aot/tfa] Replace assertx with assert in TFA
TFA used assertions which are always enabled (assertx utility function). As TFA became more mature, we can now turn them into ordinary asserts, effectively disabling them. During development assertions can be enabled using DART_VM_FLAGS environment variable, which is accepted by our precompiler2 and gen_kernel scripts: DART_VM_FLAGS=--enable-asserts pkg/vm/tool/precompiler2 foo.dart foo.snapshot This change may improve AOT compilation time of large applications. Fixes #43300 Change-Id: I8f52862e83a6db8c2f9041fcf6afa8101509324f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163121 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Aske Simon Christensen <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 26e5036 commit 3272abc

11 files changed

+187
-188
lines changed

pkg/vm/lib/transformations/type_flow/analysis.dart

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ abstract class _Invocation extends _DependencyTracker
114114
/// Result type may be saturated if this invocation was invalidated
115115
/// too many times.
116116
void setResult(TypeFlowAnalysis typeFlowAnalysis, Type type) {
117-
assertx(type != null);
117+
assert(type != null);
118118
result = type;
119119

120120
if (invalidatedResult != null) {
@@ -204,7 +204,7 @@ class _DirectInvocation extends _Invocation {
204204

205205
@override
206206
Type process(TypeFlowAnalysis typeFlowAnalysis) {
207-
assertx(typeFlowAnalysis.currentInvocation == this);
207+
assert(typeFlowAnalysis.currentInvocation == this);
208208

209209
if (selector.member is Field) {
210210
return _processField(typeFlowAnalysis);
@@ -220,16 +220,16 @@ class _DirectInvocation extends _Invocation {
220220

221221
switch (selector.callKind) {
222222
case CallKind.PropertyGet:
223-
assertx(args.values.length == firstParamIndex);
224-
assertx(args.names.isEmpty);
223+
assert(args.values.length == firstParamIndex);
224+
assert(args.names.isEmpty);
225225
fieldValue.isGetterUsed = true;
226226
return fieldValue.getValue(
227227
typeFlowAnalysis, field.isStatic ? null : args.values[0]);
228228

229229
case CallKind.PropertySet:
230230
case CallKind.SetFieldInConstructor:
231-
assertx(args.values.length == firstParamIndex + 1);
232-
assertx(args.names.isEmpty);
231+
assert(args.values.length == firstParamIndex + 1);
232+
assert(args.names.isEmpty);
233233
if (selector.callKind == CallKind.PropertySet) {
234234
fieldValue.isSetterUsed = true;
235235
}
@@ -253,8 +253,8 @@ class _DirectInvocation extends _Invocation {
253253
return new Type.nullableAny();
254254

255255
case CallKind.FieldInitializer:
256-
assertx(args.values.length == firstParamIndex);
257-
assertx(args.names.isEmpty);
256+
assert(args.values.length == firstParamIndex);
257+
assert(args.names.isEmpty);
258258
Type initializerResult = typeFlowAnalysis
259259
.getSummary(field)
260260
.apply(args, typeFlowAnalysis.hierarchyCache, typeFlowAnalysis);
@@ -290,27 +290,27 @@ class _DirectInvocation extends _Invocation {
290290
final summaryResult = summary.result;
291291
if (summaryResult is Type &&
292292
!typeFlowAnalysis.workList._isPending(this)) {
293-
assertx(result == null || result == summaryResult);
293+
assert(result == null || result == summaryResult);
294294
setResult(typeFlowAnalysis, summaryResult);
295295
}
296296
return summary.apply(
297297
args, typeFlowAnalysis.hierarchyCache, typeFlowAnalysis);
298298
} else {
299-
assertx(selector.callKind == CallKind.Method);
299+
assert(selector.callKind == CallKind.Method);
300300
return _processNoSuchMethod(args.receiver, typeFlowAnalysis);
301301
}
302302
} else {
303303
if (selector.callKind == CallKind.PropertyGet) {
304304
// Tear-off.
305305
// TODO(alexmarkov): capture receiver type
306-
assertx((member is Procedure) && !member.isGetter && !member.isSetter);
306+
assert((member is Procedure) && !member.isGetter && !member.isSetter);
307307
typeFlowAnalysis.addRawCall(new DirectSelector(member));
308308
typeFlowAnalysis._tearOffTaken.add(member);
309309
return new Type.nullableAny();
310310
} else {
311311
// Call via getter.
312312
// TODO(alexmarkov): capture receiver type
313-
assertx((selector.callKind == CallKind.Method) &&
313+
assert((selector.callKind == CallKind.Method) &&
314314
(member is Procedure) &&
315315
member.isGetter);
316316
typeFlowAnalysis.addRawCall(
@@ -325,7 +325,7 @@ class _DirectInvocation extends _Invocation {
325325

326326
bool _argumentsValid() {
327327
final function = selector.member.function;
328-
assertx(function != null);
328+
assert(function != null);
329329

330330
final int positionalArguments = args.positionalCount;
331331

@@ -378,12 +378,12 @@ class _DispatchableInvocation extends _Invocation {
378378

379379
_DispatchableInvocation(Selector selector, Args<Type> args)
380380
: super(selector, args) {
381-
assertx(selector is! DirectSelector);
381+
assert(selector is! DirectSelector);
382382
}
383383

384384
@override
385385
Type process(TypeFlowAnalysis typeFlowAnalysis) {
386-
assertx(typeFlowAnalysis.currentInvocation == this);
386+
assert(typeFlowAnalysis.currentInvocation == this);
387387

388388
// Collect all possible targets for this invocation,
389389
// along with more accurate receiver types for each target.
@@ -415,7 +415,7 @@ class _DispatchableInvocation extends _Invocation {
415415

416416
if (target == kNoSuchMethodMarker) {
417417
// Non-dynamic call-sites must hit NSM-forwarders in Dart 2.
418-
assertx(selector is DynamicSelector);
418+
assert(selector is DynamicSelector);
419419
type = _processNoSuchMethod(receiver, typeFlowAnalysis);
420420
} else {
421421
final directSelector =
@@ -430,7 +430,7 @@ class _DispatchableInvocation extends _Invocation {
430430
.getInvocation(directSelector, directArgs);
431431

432432
if (!_isPolymorphic) {
433-
assertx(target == _monomorphicTarget);
433+
assert(target == _monomorphicTarget);
434434
_monomorphicDirectInvocation = directInvocation;
435435
}
436436

@@ -479,20 +479,20 @@ class _DispatchableInvocation extends _Invocation {
479479
Type receiver,
480480
Map<Member, _ReceiverTypeBuilder> targets,
481481
TypeFlowAnalysis typeFlowAnalysis) {
482-
assertx(receiver != const EmptyType()); // should be filtered earlier
482+
assert(receiver != const EmptyType()); // should be filtered earlier
483483

484484
final bool isNullableReceiver = receiver is NullableType;
485485
if (isNullableReceiver) {
486486
receiver = (receiver as NullableType).baseType;
487-
assertx(receiver is! NullableType);
487+
assert(receiver is! NullableType);
488488
}
489489

490490
if (selector is InterfaceSelector) {
491491
final staticReceiverType = new ConeType(typeFlowAnalysis.hierarchyCache
492492
.getTFClass(selector.member.enclosingClass));
493493
receiver = receiver.intersection(
494494
staticReceiverType, typeFlowAnalysis.hierarchyCache);
495-
assertx(receiver is! NullableType);
495+
assert(receiver is! NullableType);
496496

497497
if (kPrintTrace) {
498498
tracePrint("Narrowed down receiver type: $receiver");
@@ -507,7 +507,7 @@ class _DispatchableInvocation extends _Invocation {
507507
.specializeTypeCone((receiver as ConeType).cls);
508508
}
509509

510-
assertx(targets.isEmpty);
510+
assert(targets.isEmpty);
511511

512512
if (receiver is ConcreteType) {
513513
_collectTargetsForConcreteType(receiver, targets, typeFlowAnalysis);
@@ -518,7 +518,7 @@ class _DispatchableInvocation extends _Invocation {
518518
} else if (receiver is AnyType) {
519519
_collectTargetsForSelector(targets, typeFlowAnalysis);
520520
} else {
521-
assertx(receiver is EmptyType);
521+
assert(receiver is EmptyType);
522522
}
523523

524524
if (isNullableReceiver) {
@@ -585,8 +585,8 @@ class _DispatchableInvocation extends _Invocation {
585585
if (selector is InterfaceSelector) {
586586
// TODO(alexmarkov): support generic types and make sure inferred types
587587
// are always same or better than static types.
588-
// assertx(selector.member.enclosingClass ==
589-
// _typeFlowAnalysis.environment.coreTypes.objectClass, details: selector);
588+
// assert(selector.member.enclosingClass ==
589+
// _typeFlowAnalysis.environment.coreTypes.objectClass);
590590
selector = new DynamicSelector(selector.callKind, selector.name);
591591
}
592592

@@ -596,7 +596,7 @@ class _DispatchableInvocation extends _Invocation {
596596

597597
dynamicTargetSet.addDependentInvocation(this);
598598

599-
assertx(targets.isEmpty);
599+
assert(targets.isEmpty);
600600
for (Member target in dynamicTargetSet.targets) {
601601
_getReceiverTypeBuilder(targets, target).addType(receiver);
602602
}
@@ -624,8 +624,8 @@ class _DispatchableInvocation extends _Invocation {
624624
}
625625

626626
void _setMonomorphicTarget(Member target) {
627-
assertx(!_isPolymorphic);
628-
assertx((_monomorphicTarget == null) || (_monomorphicTarget == target));
627+
assert(!_isPolymorphic);
628+
assert((_monomorphicTarget == null) || (_monomorphicTarget == target));
629629
_monomorphicTarget = target;
630630

631631
_notifyCallSites();
@@ -693,23 +693,23 @@ class _ReceiverTypeBuilder {
693693
return;
694694
}
695695

696-
assertx(_type is ConcreteType);
697-
assertx(_type != type);
696+
assert(_type is ConcreteType);
697+
assert(_type != type);
698698

699699
_list = new List<ConcreteType>();
700700
_list.add(_type);
701701

702702
_type = null;
703703
}
704704

705-
assertx(_list.last.cls.id < type.cls.id);
705+
assert(_list.last.cls.id < type.cls.id);
706706
_list.add(type);
707707
}
708708

709709
/// Appends an arbitrary Type. May be called only once.
710710
/// Should not be used in conjunction with [addConcreteType].
711711
void addType(Type type) {
712-
assertx(_type == null && _list == null);
712+
assert(_type == null && _list == null);
713713
_type = type;
714714
}
715715

@@ -728,7 +728,7 @@ class _ReceiverTypeBuilder {
728728
t = new SetType(_list);
729729
}
730730
} else {
731-
assertx(_list == null);
731+
assert(_list == null);
732732
}
733733

734734
if (_nullable) {
@@ -797,7 +797,7 @@ class _InvocationsCache {
797797
}
798798

799799
bool added = _invocations.add(invocation);
800-
assertx(added);
800+
assert(added);
801801
++Statistics.invocationsAddedToCache;
802802
return invocation;
803803
}
@@ -833,7 +833,7 @@ class _FieldValue extends _DependencyTracker {
833833
}
834834

835835
final enclosingClass = field.enclosingClass;
836-
assertx(enclosingClass != null);
836+
assert(enclosingClass != null);
837837

838838
// Default value is not observable if every generative constructor
839839
// is redirecting or initializes the field.
@@ -851,7 +851,7 @@ class _FieldValue extends _DependencyTracker {
851851

852852
void ensureInitialized(TypeFlowAnalysis typeFlowAnalysis, Type receiverType) {
853853
if (field.initializer != null) {
854-
assertx(field.isStatic == (receiverType == null));
854+
assert(field.isStatic == (receiverType == null));
855855
final args = !field.isStatic ? <Type>[receiverType] : const <Type>[];
856856
final initializerInvocation = typeFlowAnalysis._invocationsCache
857857
.getInvocation(
@@ -908,7 +908,7 @@ class _FieldValue extends _DependencyTracker {
908908
: newValue.specialize(hierarchy).intersection(staticType, hierarchy);
909909
Type newType =
910910
value.union(narrowedNewValue, hierarchy).specialize(hierarchy);
911-
assertx(newType.isSpecialized);
911+
assert(newType.isSpecialized);
912912

913913
if (newType != value) {
914914
if (kPrintTrace) {
@@ -1038,7 +1038,7 @@ class GenericInterfacesInfoImpl implements GenericInterfacesInfo {
10381038
result = new List<Type>(flattenedTypeArgs.length);
10391039
for (int i = 0; i < flattenedTypeArgs.length; ++i) {
10401040
final translated = closedTypeTranslator.translate(flattenedTypeArgs[i]);
1041-
assertx(translated is RuntimeType || translated is UnknownType);
1041+
assert(translated is RuntimeType || translated is UnknownType);
10421042
result[i] = translated;
10431043
}
10441044
cachedFlattenedTypeArgsForNonGeneric[klass] = result;
@@ -1076,7 +1076,7 @@ class _ClassHierarchyCache extends TypeHierarchy {
10761076
: objectNoSuchMethod = hierarchy.getDispatchTarget(
10771077
environment.coreTypes.objectClass, noSuchMethodName),
10781078
super(environment.coreTypes, nullSafety) {
1079-
assertx(objectNoSuchMethod != null);
1079+
assert(objectNoSuchMethod != null);
10801080
}
10811081

10821082
@override
@@ -1093,8 +1093,8 @@ class _ClassHierarchyCache extends TypeHierarchy {
10931093
}
10941094

10951095
ConcreteType addAllocatedClass(Class cl) {
1096-
assertx(!cl.isAbstract);
1097-
assertx(!_sealed);
1096+
assert(!cl.isAbstract);
1097+
assert(!_sealed);
10981098

10991099
final _TFClassImpl classImpl = getTFClass(cl);
11001100

@@ -1187,7 +1187,7 @@ class _ClassHierarchyCache extends TypeHierarchy {
11871187
}
11881188

11891189
void _addDynamicTarget(Class c, _DynamicTargetSet targetSet) {
1190-
assertx(!_sealed);
1190+
assert(!_sealed);
11911191
final selector = targetSet.selector;
11921192
final member = hierarchy.getDispatchTarget(c, selector.name,
11931193
setter: selector.isSetter);
@@ -1238,19 +1238,19 @@ class _WorkList {
12381238
bool _isPending(_Invocation invocation) => invocation.list != null;
12391239

12401240
void enqueueInvocation(_Invocation invocation) {
1241-
assertx(invocation.result == null);
1241+
assert(invocation.result == null);
12421242
if (_isPending(invocation)) {
12431243
// Re-add the invocation to the tail of the pending queue.
12441244
pending.remove(invocation);
1245-
assertx(!_isPending(invocation));
1245+
assert(!_isPending(invocation));
12461246
}
12471247
pending.add(invocation);
12481248
}
12491249

12501250
void invalidateInvocation(_Invocation invocation) {
12511251
Statistics.invocationsInvalidated++;
12521252
if (invocation.result != null) {
1253-
assertx(invocation.invalidatedResult == null);
1253+
assert(invocation.invalidatedResult == null);
12541254
invocation.invalidatedResult = invocation.result;
12551255
invocation.result = null;
12561256
}
@@ -1267,7 +1267,7 @@ class _WorkList {
12671267
}
12681268
// Protobuf handler replaced contents of static field initializers.
12691269
for (var field in fields) {
1270-
assertx(field.isStatic);
1270+
assert(field.isStatic);
12711271
// Reset summary in order to rebuild it.
12721272
_typeFlowAnalysis._summaries[field] = null;
12731273
// Invalidate (and enqueue) field initializer invocation.
@@ -1285,7 +1285,7 @@ class _WorkList {
12851285
if (pending.isEmpty && !invalidateProtobufFields()) {
12861286
break;
12871287
}
1288-
assertx(callStack.isEmpty && processing.isEmpty);
1288+
assert(callStack.isEmpty && processing.isEmpty);
12891289
Statistics.iterationsOverInvocationsWorkList++;
12901290
processInvocation(pending.first);
12911291
}
@@ -1328,9 +1328,9 @@ class _WorkList {
13281328
// same result.
13291329
invocation.typeChecksNeeded = true;
13301330
invalidateInvocation(invocation);
1331-
assertx(invocation.result == null);
1332-
assertx(invocation.invalidatedResult != null);
1333-
assertx(_isPending(invocation));
1331+
assert(invocation.result == null);
1332+
assert(invocation.invalidatedResult != null);
1333+
assert(_isPending(invocation));
13341334
if (kPrintTrace) {
13351335
tracePrint("Processing deferred due to deep call stack.");
13361336
tracePrint(
@@ -1360,7 +1360,7 @@ class _WorkList {
13601360
}
13611361

13621362
final last = callStack.removeLast();
1363-
assertx(identical(last, invocation));
1363+
assert(identical(last, invocation));
13641364

13651365
processing.remove(invocation);
13661366

@@ -1580,7 +1580,7 @@ class TypeFlowAnalysis implements EntryPointsListener, CallHandler {
15801580

15811581
return workList.processInvocation(invocation);
15821582
} else {
1583-
assertx(!isResultUsed);
1583+
assert(!isResultUsed);
15841584

15851585
if (invocation.result == null) {
15861586
workList.enqueueInvocation(invocation);
@@ -1613,7 +1613,7 @@ class TypeFlowAnalysis implements EntryPointsListener, CallHandler {
16131613
if (kPrintDebug) {
16141614
debugPrint("ADD RAW CALL: $selector");
16151615
}
1616-
assertx(selector is! DynamicSelector); // TODO(alexmarkov)
1616+
assert(selector is! DynamicSelector); // TODO(alexmarkov)
16171617

16181618
applyCall(null, selector, summaryCollector.rawArguments(selector),
16191619
isResultUsed: false, processImmediately: false);

0 commit comments

Comments
 (0)