Skip to content

Commit 96cf84e

Browse files
authored
Roll back parameter default tree shaking (#4520)
* Add more regression tests * Remove call parameter deoptimization * Remove includeWithoutParameterDefaults * Remove default parameter tree-shaking logic * Clean up deoptimizations * Clean up deoptimizations
1 parent 696ebd3 commit 96cf84e

File tree

46 files changed

+112
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+112
-533
lines changed

src/ast/nodes/ArrayExpression.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ export default class ArrayExpression extends NodeBase {
8585
if (element) {
8686
if (hasSpread || element instanceof SpreadElement) {
8787
hasSpread = true;
88-
// This also deoptimizes parameter defaults
8988
element.deoptimizePath(UNKNOWN_PATH);
90-
} else {
91-
// We do not track parameter defaults in arrays
92-
element.deoptimizeCallParameters();
9389
}
9490
}
9591
}

src/ast/nodes/ArrowFunctionExpression.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { type CallOptions } from '../CallOptions';
2-
import { type HasEffectsContext } from '../ExecutionContext';
2+
import { type HasEffectsContext, InclusionContext } from '../ExecutionContext';
33
import ReturnValueScope from '../scopes/ReturnValueScope';
44
import type Scope from '../scopes/Scope';
55
import { type ObjectPath } from '../utils/PathTracker';
66
import BlockStatement from './BlockStatement';
7+
import Identifier from './Identifier';
78
import * as NodeType from './NodeType';
89
import FunctionBase from './shared/FunctionBase';
9-
import { type ExpressionNode } from './shared/Node';
10+
import { type ExpressionNode, IncludeChildren } from './shared/Node';
1011
import { ObjectEntity } from './shared/ObjectEntity';
1112
import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype';
1213
import type { PatternNode } from './shared/Pattern';
@@ -48,6 +49,15 @@ export default class ArrowFunctionExpression extends FunctionBase {
4849
return false;
4950
}
5051

52+
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
53+
super.include(context, includeChildrenRecursively);
54+
for (const param of this.params) {
55+
if (!(param instanceof Identifier)) {
56+
param.include(context, includeChildrenRecursively);
57+
}
58+
}
59+
}
60+
5161
protected getObjectEntity(): ObjectEntity {
5262
if (this.objectEntity !== null) {
5363
return this.objectEntity;

src/ast/nodes/AssignmentPattern.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
3535
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
3636
}
3737

38-
// Note that FunctionBase may directly include .left and .right without
39-
// including the pattern itself. This is how default parameter tree-shaking
40-
// works at the moment.
4138
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
39+
if (!this.deoptimized) this.applyDeoptimizations();
4240
this.included = true;
4341
this.left.include(context, includeChildrenRecursively);
4442
this.right.include(context, includeChildrenRecursively);

src/ast/nodes/CallExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class CallExpression extends CallExpressionBase implements Deopti
9595
}
9696
} else {
9797
this.included = true;
98-
this.callee.include(context, false, { includeWithoutParameterDefaults: true });
98+
this.callee.include(context, false);
9999
}
100100
this.callee.includeCallArguments(context, this.arguments);
101101
const returnExpression = this.getReturnExpression();

src/ast/nodes/FunctionDeclaration.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import { InclusionContext } from '../ExecutionContext';
21
import type ChildScope from '../scopes/ChildScope';
32
import Identifier, { type IdentifierWithVariable } from './Identifier';
43
import type * as NodeType from './NodeType';
54
import FunctionNode from './shared/FunctionNode';
6-
import type { GenericEsTreeNode, IncludeChildren } from './shared/Node';
5+
import type { GenericEsTreeNode } from './shared/Node';
76

87
export default class FunctionDeclaration extends FunctionNode {
98
declare type: NodeType.tFunctionDeclaration;
109

11-
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) {
12-
super.include(context, includeChildrenRecursively, { includeWithoutParameterDefaults: true });
13-
}
14-
1510
initialise(): void {
1611
super.initialise();
1712
if (this.id !== null) {

src/ast/nodes/Identifier.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ export default class Identifier extends NodeBase implements PatternNode {
8686
return [(this.variable = variable)];
8787
}
8888

89-
deoptimizeCallParameters() {
90-
this.variable!.deoptimizeCallParameters();
91-
}
92-
9389
deoptimizePath(path: ObjectPath): void {
9490
if (path.length === 0 && !this.scope.contains(this.name)) {
9591
this.disallowImportReassignment();

src/ast/nodes/ObjectExpression.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,7 @@ export default class ObjectExpression extends NodeBase implements DeoptimizableE
102102
}
103103
}
104104

105-
protected applyDeoptimizations() {
106-
this.deoptimized = true;
107-
for (const property of this.properties) {
108-
if (property instanceof Property) {
109-
property.value.deoptimizeCallParameters();
110-
}
111-
}
112-
}
105+
protected applyDeoptimizations() {}
113106

114107
private getObjectEntity(): ObjectEntity {
115108
if (this.objectEntity !== null) {

src/ast/nodes/VariableDeclarator.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ export default class VariableDeclarator extends NodeBase {
3535

3636
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
3737
this.included = true;
38-
this.init?.include(context, includeChildrenRecursively, {
39-
includeWithoutParameterDefaults: true
40-
});
38+
this.init?.include(context, includeChildrenRecursively);
4139
this.id.markDeclarationReached();
4240
if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
4341
this.id.include(context, includeChildrenRecursively);

src/ast/nodes/YieldExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class YieldExpression extends NodeBase {
1111

1212
hasEffects(context: HasEffectsContext): boolean {
1313
if (!this.deoptimized) this.applyDeoptimizations();
14-
return !context.ignore.returnYield || !!this.argument?.hasEffects(context);
14+
return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
1515
}
1616

1717
render(code: MagicString, options: RenderOptions): void {

src/ast/nodes/shared/ClassNode.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type ClassBody from '../ClassBody';
1616
import Identifier from '../Identifier';
1717
import type Literal from '../Literal';
1818
import MethodDefinition from '../MethodDefinition';
19-
import PropertyDefinition from '../PropertyDefinition';
2019
import { type ExpressionEntity, type LiteralValueOrUnknown } from './Expression';
2120
import { type ExpressionNode, type IncludeChildren, NodeBase } from './Node';
2221
import { ObjectEntity, type ObjectProperty } from './ObjectEntity';
@@ -40,12 +39,6 @@ export default class ClassNode extends NodeBase implements DeoptimizableEntity {
4039

4140
deoptimizePath(path: ObjectPath): void {
4241
this.getObjectEntity().deoptimizePath(path);
43-
if (path.length === 1 && path[0] === UnknownKey) {
44-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
45-
// which means the constructor needs to be reassigned
46-
this.classConstructor?.deoptimizePath(UNKNOWN_PATH);
47-
this.superClass?.deoptimizePath(UNKNOWN_PATH);
48-
}
4942
}
5043

5144
deoptimizeThisOnEventAtPath(
@@ -150,11 +143,8 @@ export default class ClassNode extends NodeBase implements DeoptimizableEntity {
150143
) {
151144
// Calls to methods are not tracked, ensure that the return value is deoptimized
152145
definition.deoptimizePath(UNKNOWN_PATH);
153-
} else if (definition instanceof PropertyDefinition) {
154-
definition.value?.deoptimizeCallParameters();
155146
}
156147
}
157-
this.superClass?.deoptimizeCallParameters();
158148
this.context.requestTreeshakingPass();
159149
}
160150

0 commit comments

Comments
 (0)