Skip to content

Commit b64c640

Browse files
fishythefishCommit Queue
authored and
Commit Queue
committed
[dart2js] Remove asserts in ConstConditionalSimplifier
Fixes: b/349652368 Change-Id: I0d5cad6a55cba6b31d8a352d278daf844db95efb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373328 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mayank Patke <[email protected]>
1 parent a868b8d commit b64c640

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

pkg/compiler/lib/src/common/elements.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,22 @@ abstract class CommonElements {
719719
/// The class for native annotations defined in dart:_js_helper.
720720
late final ClassEntity nativeAnnotationClass = _findHelperClass('Native');
721721

722+
bool isAssertTest(MemberEntity member) =>
723+
member.name == 'assertTest' &&
724+
member.isFunction &&
725+
member.isTopLevel &&
726+
member.library == jsHelperLibrary;
727+
722728
late final assertTest = _findHelperFunction('assertTest');
723729

724730
late final assertThrow = _findHelperFunction('assertThrow');
725731

732+
bool isAssertHelper(MemberEntity member) =>
733+
member.name == 'assertHelper' &&
734+
member.isFunction &&
735+
member.isTopLevel &&
736+
member.library == jsHelperLibrary;
737+
726738
late final assertHelper = _findHelperFunction('assertHelper');
727739

728740
late final assertUnreachableMethod = _findHelperFunction('assertUnreachable');

pkg/compiler/lib/src/phase/load_kernel.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ void _simplifyConstConditionals(ir.Component component, CompilerOptions options,
144144
evaluationMode: options.useLegacySubtyping
145145
? fe.EvaluationMode.weak
146146
: fe.EvaluationMode.strong,
147-
shouldNotInline: shouldNotInline)
147+
shouldNotInline: shouldNotInline,
148+
removeAsserts: !options.enableUserAssertions)
148149
.run();
149150
}
150151

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,20 +1944,23 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
19441944
return argument;
19451945
}
19461946
}
1947-
} else if (element == commonElements.assertHelper ||
1948-
element == commonElements.assertTest) {
1949-
if (node.inputs.length == 1) {
1950-
HInstruction argument = node.inputs[0];
1951-
if (argument is HConstant) {
1952-
ConstantValue constant = argument.constant;
1953-
if (constant is BoolConstantValue) {
1954-
bool value = constant is TrueConstantValue;
1955-
if (element == commonElements.assertTest) {
1956-
// `assertTest(argument)` effectively negates the argument.
1957-
return _graph.addConstantBool(!value, _closedWorld);
1947+
} else {
1948+
final isAssertHelper = commonElements.isAssertHelper(element);
1949+
final isAssertTest = commonElements.isAssertTest(element);
1950+
if (isAssertHelper || isAssertTest) {
1951+
if (node.inputs.length == 1) {
1952+
HInstruction argument = node.inputs[0];
1953+
if (argument is HConstant) {
1954+
ConstantValue constant = argument.constant;
1955+
if (constant is BoolConstantValue) {
1956+
bool value = constant is TrueConstantValue;
1957+
if (isAssertTest) {
1958+
// `assertTest(argument)` effectively negates the argument.
1959+
return _graph.addConstantBool(!value, _closedWorld);
1960+
}
1961+
// `assertHelper(true)` is a no-op, other values throw.
1962+
if (value) return argument;
19581963
}
1959-
// `assertHelper(true)` is a no-op, other values throw.
1960-
if (value) return argument;
19611964
}
19621965
}
19631966
}

pkg/compiler/test/impact/impact_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ main(List<String> args) {
2424
print('Testing computation of WorldImpact through ImpactData');
2525
print('==================================================================');
2626
await checkTests(dataDir, const ImpactDataComputer(),
27-
args: args, testedConfigs: allSpecConfigs);
27+
options: const ['--enable-asserts'],
28+
args: args,
29+
testedConfigs: allSpecConfigs);
2830
});
2931
}
3032

0 commit comments

Comments
 (0)