| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import { |
| 9 | ReactiveFunction, |
| 10 | ReactiveScopeBlock, |
| 11 | ReactiveStatement, |
| 12 | } from '../HIR/HIR'; |
| 13 | import { |
| 14 | ReactiveFunctionTransform, |
| 15 | Transformed, |
| 16 | visitReactiveFunction, |
| 17 | } from './visitors'; |
| 18 | |
| 19 | /* |
| 20 | * Removes *all* reactive scopes. Intended for experimentation only, to allow |
| 21 | * accurately removing memoization using the compiler pipeline to get a baseline |
| 22 | * for performance of a product without memoization applied. |
| 23 | */ |
| 24 | export function pruneAllReactiveScopes(fn: ReactiveFunction): void { |
| 25 | visitReactiveFunction(fn, new Transform(), undefined); |
| 26 | } |
| 27 | |
| 28 | class Transform extends ReactiveFunctionTransform<void> { |
| 29 | override transformScope( |
| 30 | scopeBlock: ReactiveScopeBlock, |
| 31 | state: void, |
| 32 | ): Transformed<ReactiveStatement> { |
| 33 | this.visitScope(scopeBlock, state); |
| 34 | return {kind: 'replace-many', value: scopeBlock.instructions}; |
| 35 | } |
| 36 | } |