Skip to content

Commit

Permalink
Ensure properties are deoptimized by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 13, 2022
1 parent 8f4c4eb commit ae3658b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/ast/nodes/ObjectExpression.ts
Expand Up @@ -26,7 +26,6 @@ import { NodeBase } from './shared/Node';
import { ObjectEntity, type ObjectProperty } from './shared/ObjectEntity';
import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype';

// TODO Lukas ensure deoptimizations always happen twice in hasEffects and include
export default class ObjectExpression extends NodeBase implements DeoptimizableEntity {
declare properties: readonly (Property | SpreadElement)[];
declare type: NodeType.tObjectExpression;
Expand Down
21 changes: 19 additions & 2 deletions src/ast/nodes/shared/Node.ts
Expand Up @@ -12,6 +12,7 @@ import {
} from '../../ExecutionContext';
import { getAndCreateKeys, keys } from '../../keys';
import type ChildScope from '../../scopes/ChildScope';
import { UNKNOWN_PATH } from '../../utils/PathTracker';
import type Variable from '../../variables/Variable';
import * as NodeType from '../NodeType';
import { ExpressionEntity, InclusionOptions } from './Expression';
Expand All @@ -23,7 +24,6 @@ export interface GenericEsTreeNode extends acorn.Node {
export const INCLUDE_PARAMETERS = 'variables' as const;
export type IncludeChildren = boolean | typeof INCLUDE_PARAMETERS;

// TODO Lukas consider deoptimizing all properties by default unless explicitly overridden
export interface Node extends Entity {
annotations?: acorn.Comment[];
context: AstContext;
Expand Down Expand Up @@ -240,7 +240,24 @@ export class NodeBase extends ExpressionEntity implements ExpressionNode {
return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
}

protected applyDeoptimizations(): void {}
/**
* Just deoptimize everything by default so that when e.g. we do not track
* something properly, it is deoptimized.
* @protected
*/
protected applyDeoptimizations(): void {
for (const key of this.keys) {
const value = (this as GenericEsTreeNode)[key];
if (value === null) continue;
if (Array.isArray(value)) {
for (const child of value) {
child?.deoptimizePath(UNKNOWN_PATH);
}
} else {
value.deoptimizePath(UNKNOWN_PATH);
}
}
}
}

export { NodeBase as StatementBase };
Expand Down

0 comments on commit ae3658b

Please sign in to comment.