8000 Avoid redundant declaration traversals in DSLX v2 type inference. by copybara-service[bot] · Pull Request #5297 · google/xls · GitHub
[go: up one dir, main page]

Skip to content

Avoid redundant declaration traversals in DSLX v2 type inference. - #5297

Draft
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1016061488
Draft

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1016061488

Conversation

@copybara-service
Copy link
Copy Markdown

Avoid redundant declaration traversals in DSLX v2 type inference.

When TryConvertInvocationForUnification converts an invocation out of order during type variable unification, ConvertConstantsReferencedUnder collects referenced names and recursively converts enclosing let or const declarations that do not yet have a ConstExpr value recorded in TypeInfo. However, non-constexpr let bindings that depend on runtime values (such as function parameters) never produce a ConstExpr entry even after their declarations have been converted. Without checking whether a declaration has already been converted in the current parametric context, ConvertConstantsReferencedUnder repeatedly walks the declaration's dependency DAG on every reference, causing quadratic to exponential blowup in functions with chained let bindings feeding parametric invocations.

Short-circuit ConvertConstantsReferencedUnder when a node has already been visited for the active parametric context or when a referenced let or const declaration already has type information or a converted subtree in that context, reducing traversal work to linear in the number of AST nodes.

When `TryConvertInvocationForUnification` converts an invocation out of order during type variable unification, `ConvertConstantsReferencedUnder` collects referenced names and recursively converts enclosing `let` or `const` declarations that do not yet have a `ConstExpr` value recorded in `TypeInfo`. However, non-constexpr `let` bindings that depend on runtime values (such as function parameters) never produce a `ConstExpr` entry even after their declarations have been converted. Without checking whether a declaration has already been converted in the current parametric context, `ConvertConstantsReferencedUnder` repeatedly walks the declaration's dependency DAG on every reference, causing quadratic to exponential blowup in functions with chained `let` bindings feeding parametric invocations.

Short-circuit `ConvertConstantsReferencedUnder` when a node has already been visited for the active parametric context or when a referenced `let` or `const` declaration already has type information or a converted subtree in that context, reducing traversal work to linear in the number of AST nodes.

PiperOrigin-RevId: 1016061488

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0