未验证 提交 edae1ba2 编写于 作者: L Lukas Taegert-Atkinson 提交者: GitHub

Always request a new tree-shaking pass when deoptimizations of a node are first included (#4111)

上级 8a02af14
......@@ -109,6 +109,7 @@ export interface AstContext {
moduleContext: string;
nodeConstructors: { [name: string]: typeof NodeBase };
options: NormalizedInputOptions;
requestTreeshakingPass: () => void;
traceExport: (name: string) => Variable | null;
traceVariable: (name: string) => Variable | null;
usesTopLevelAwait: boolean;
......@@ -726,6 +727,7 @@ export default class Module {
moduleContext: this.context,
nodeConstructors,
options: this.options,
requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
traceExport: this.getVariableForExportName.bind(this),
traceVariable: this.traceVariable.bind(this),
usesTopLevelAwait: false,
......
......@@ -126,5 +126,6 @@ export default class AssignmentExpression extends NodeBase {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
......@@ -48,5 +48,6 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
......@@ -298,6 +298,7 @@ export default class CallExpression extends NodeBase implements DeoptimizableEnt
// This will make sure all properties of parameters behave as "unknown"
argument.deoptimizePath(UNKNOWN_PATH);
}
this.context.requestTreeshakingPass();
}
private getReturnExpression(
......
......@@ -65,5 +65,6 @@ export default class ForInStatement extends StatementBase {
protected applyDeoptimizations(): void {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.context.requestTreeshakingPass();
}
}
......@@ -50,5 +50,6 @@ export default class ForOfStatement extends StatementBase {
protected applyDeoptimizations(): void {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.context.requestTreeshakingPass();
}
}
......@@ -178,6 +178,7 @@ export default class Identifier extends NodeBase implements PatternNode {
this.deoptimized = true;
if (this.variable !== null && this.variable instanceof LocalVariable) {
this.variable.consolidateInitializers();
this.context.requestTreeshakingPass();
}
}
......
......@@ -329,6 +329,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
SHARED_RECURSION_TRACKER
);
}
this.context.requestTreeshakingPass();
}
}
......
......@@ -46,5 +46,6 @@ export default class NewExpression extends NodeBase {
// This will make sure all properties of parameters behave as "unknown"
argument.deoptimizePath(UNKNOWN_PATH);
}
this.context.requestTreeshakingPass();
}
}
......@@ -46,6 +46,7 @@ export default class Property extends MethodBase implements PatternNode {
this.deoptimized = true;
if (this.declarationInit !== null) {
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
this.context.requestTreeshakingPass();
}
}
}
......@@ -37,6 +37,7 @@ export default class RestElement extends NodeBase implements PatternNode {
this.deoptimized = true;
if (this.declarationInit !== null) {
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
this.context.requestTreeshakingPass();
}
}
}
......@@ -30,5 +30,6 @@ export default class SpreadElement extends NodeBase {
// Only properties of properties of the argument could become subject to reassignment
// This will also reassign the return values of iterators
this.argument.deoptimizePath([UnknownKey, UnknownKey]);
this.context.requestTreeshakingPass();
}
}
......@@ -59,6 +59,7 @@ export default class UnaryExpression extends NodeBase {
this.deoptimized = true;
if (this.operator === 'delete') {
this.argument.deoptimizePath(EMPTY_PATH);
this.context.requestTreeshakingPass();
}
}
}
......@@ -87,5 +87,6 @@ export default class UpdateExpression extends NodeBase {
const variable = this.scope.findVariable(this.argument.name);
variable.isReassigned = true;
}
this.context.requestTreeshakingPass();
}
}
......@@ -30,6 +30,10 @@ export default class YieldExpression extends NodeBase {
protected applyDeoptimizations(): void {
this.deoptimized = true;
this.argument?.deoptimizePath(UNKNOWN_PATH);
const { argument } = this;
if (argument) {
argument.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
}
const assert = require('assert');
const result = { value: 0 };
module.exports = {
description: 'makes sure to request additional passes when a variable is deoptimized',
context: { result },
exports() {
assert.strictEqual(result.value, 2);
}
};
function heisenbug() {
var a = false;
function f(b) {
if (a) a === b.c ? result.value++ : result.value--;
a = b.c;
}
function g() {}
function h() {
f({
c: g
});
}
h();
h();
}
heisenbug();
heisenbug();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册