fix(es/minifier): Fix infinite loops (#4250)

- We now don't mark changes due to `negate_cost` as a change.
This commit is contained in:
Donny/강동윤 2022-04-05 16:29:10 +09:00 committed by GitHub
parent ea871e2879
commit 350a19587e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 245 additions and 3 deletions

View File

@ -0,0 +1,7 @@
{
"jsc": {
"minify": {
"compress": true
}
}
}

View File

@ -0,0 +1,17 @@
foo({
bar: function bar(data, baz) {
if (
!(baz ? data.quxA : data.quxB) &&
!(baz ? data.corgeA : data.corgeB) &&
(baz ? data.get("waldo") : data.waldo)
) {
pass();
} else if (
!(baz ? data.quxA : data.quxB) &&
!(baz ? data.get("waldo") : data.waldo) &&
(baz ? data.corgeA : data.corgeB)
) {
pass();
}
}
});

View File

@ -0,0 +1,5 @@
foo({
bar: function(data, baz) {
!(!(baz ? data.quxA : data.quxB) && !(baz ? data.corgeA : data.corgeB) && (baz ? data.get("waldo") : data.waldo)) ? (baz ? data.quxA : data.quxB) || (baz ? data.get("waldo") : data.waldo) || (baz ? !data.corgeA : !data.corgeB) || pass() : pass();
}
});

View File

@ -34,7 +34,6 @@ where
} }
if negate_cost(&stmt.test, true, false) < 0 { if negate_cost(&stmt.test, true, false) < 0 {
self.changed = true;
tracing::debug!("if_return: Negating `cond` of an if statement which has cons and alt"); tracing::debug!("if_return: Negating `cond` of an if statement which has cons and alt");
let ctx = Ctx { let ctx = Ctx {
in_bool_ctx: true, in_bool_ctx: true,

View File

@ -48,7 +48,6 @@ impl Pure<'_> {
return; return;
} }
tracing::debug!("bools: Optimizing `!(a && b)` as `!a || !b`"); tracing::debug!("bools: Optimizing `!(a && b)` as `!a || !b`");
self.changed = true;
self.negate(arg, false, false); self.negate(arg, false, false);
*e = *arg.take(); *e = *arg.take();
} }

View File

@ -129,7 +129,6 @@ impl Pure<'_> {
return; return;
} }
self.changed = true;
tracing::debug!("conditionals: `a ? foo : bar` => `!a ? bar : foo` (considered cost)"); tracing::debug!("conditionals: `a ? foo : bar` => `!a ? bar : foo` (considered cost)");
let start_str = dump(&*cond, false); let start_str = dump(&*cond, false);

View File

@ -0,0 +1,194 @@
TestSnapshot {
vars: [
(
(
Atom('bar' type=inline),
#2,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 0,
cond_init: false,
declared: false,
declared_count: 0,
declared_as_fn_param: false,
declared_as_fn_expr: true,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 0,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: false,
used_by_nested_fn: false,
executed_multiple_time: false,
used_in_cond: false,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('baz' type=inline),
#2,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 6,
cond_init: false,
declared: true,
declared_count: 1,
declared_as_fn_param: true,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 6,
usage_count: 6,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: true,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('data' type=inline),
#2,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 12,
cond_init: false,
declared: true,
declared_count: 1,
declared_as_fn_param: true,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 12,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: true,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('foo' type=inline),
#1,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 1,
cond_init: false,
declared: false,
declared_count: 0,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 1,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: true,
is_fn_local: true,
used_by_nested_fn: false,
executed_multiple_time: false,
used_in_cond: false,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: true,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('pass' type=inline),
#1,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 2,
cond_init: false,
declared: false,
declared_count: 0,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 2,
usage_count: 2,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: true,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: true,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: true,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
],
}

View File

@ -0,0 +1,17 @@
foo({
bar: function bar(data, baz) {
if (
!(baz ? data.quxA : data.quxB) &&
!(baz ? data.corgeA : data.corgeB) &&
(baz ? data.get("waldo") : data.waldo)
) {
pass();
} else if (
!(baz ? data.quxA : data.quxB) &&
!(baz ? data.get("waldo") : data.waldo) &&
(baz ? data.corgeA : data.corgeB)
) {
pass();
}
}
});

View File

@ -0,0 +1,5 @@
foo({
bar: function(data, baz) {
!(!(baz ? data.quxA : data.quxB) && !(baz ? data.corgeA : data.corgeB) && (baz ? data.get("waldo") : data.waldo)) ? (baz ? data.quxA : data.quxB) || (baz ? data.get("waldo") : data.waldo) || (baz ? !data.corgeA : !data.corgeB) || pass() : pass();
}
});