mirror of
https://github.com/dart-lang/sdk
synced 2024-09-30 04:48:37 +00:00
[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 <natebiggs@google.com> Commit-Queue: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
a868b8d9d6
commit
b64c64012f
|
@ -719,10 +719,22 @@ abstract class CommonElements {
|
|||
/// The class for native annotations defined in dart:_js_helper.
|
||||
late final ClassEntity nativeAnnotationClass = _findHelperClass('Native');
|
||||
|
||||
bool isAssertTest(MemberEntity member) =>
|
||||
member.name == 'assertTest' &&
|
||||
member.isFunction &&
|
||||
member.isTopLevel &&
|
||||
member.library == jsHelperLibrary;
|
||||
|
||||
late final assertTest = _findHelperFunction('assertTest');
|
||||
|
||||
late final assertThrow = _findHelperFunction('assertThrow');
|
||||
|
||||
bool isAssertHelper(MemberEntity member) =>
|
||||
member.name == 'assertHelper' &&
|
||||
member.isFunction &&
|
||||
member.isTopLevel &&
|
||||
member.library == jsHelperLibrary;
|
||||
|
||||
late final assertHelper = _findHelperFunction('assertHelper');
|
||||
|
||||
late final assertUnreachableMethod = _findHelperFunction('assertUnreachable');
|
||||
|
|
|
@ -144,7 +144,8 @@ void _simplifyConstConditionals(ir.Component component, CompilerOptions options,
|
|||
evaluationMode: options.useLegacySubtyping
|
||||
? fe.EvaluationMode.weak
|
||||
: fe.EvaluationMode.strong,
|
||||
shouldNotInline: shouldNotInline)
|
||||
shouldNotInline: shouldNotInline,
|
||||
removeAsserts: !options.enableUserAssertions)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -1944,20 +1944,23 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
|
|||
return argument;
|
||||
}
|
||||
}
|
||||
} else if (element == commonElements.assertHelper ||
|
||||
element == commonElements.assertTest) {
|
||||
if (node.inputs.length == 1) {
|
||||
HInstruction argument = node.inputs[0];
|
||||
if (argument is HConstant) {
|
||||
ConstantValue constant = argument.constant;
|
||||
if (constant is BoolConstantValue) {
|
||||
bool value = constant is TrueConstantValue;
|
||||
if (element == commonElements.assertTest) {
|
||||
// `assertTest(argument)` effectively negates the argument.
|
||||
return _graph.addConstantBool(!value, _closedWorld);
|
||||
} else {
|
||||
final isAssertHelper = commonElements.isAssertHelper(element);
|
||||
final isAssertTest = commonElements.isAssertTest(element);
|
||||
if (isAssertHelper || isAssertTest) {
|
||||
if (node.inputs.length == 1) {
|
||||
HInstruction argument = node.inputs[0];
|
||||
if (argument is HConstant) {
|
||||
ConstantValue constant = argument.constant;
|
||||
if (constant is BoolConstantValue) {
|
||||
bool value = constant is TrueConstantValue;
|
||||
if (isAssertTest) {
|
||||
// `assertTest(argument)` effectively negates the argument.
|
||||
return _graph.addConstantBool(!value, _closedWorld);
|
||||
}
|
||||
// `assertHelper(true)` is a no-op, other values throw.
|
||||
if (value) return argument;
|
||||
}
|
||||
// `assertHelper(true)` is a no-op, other values throw.
|
||||
if (value) return argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ main(List<String> args) {
|
|||
print('Testing computation of WorldImpact through ImpactData');
|
||||
print('==================================================================');
|
||||
await checkTests(dataDir, const ImpactDataComputer(),
|
||||
args: args, testedConfigs: allSpecConfigs);
|
||||
options: const ['--enable-asserts'],
|
||||
args: args,
|
||||
testedConfigs: allSpecConfigs);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue