Repository navigation
Avoid redundant declaration traversals in DSLX v2 type inference. - #5297
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid redundant declaration traversals in DSLX v2 type inference.
When
TryConvertInvocationForUnificationconverts an invocation out of order during type variable unification,ConvertConstantsReferencedUndercollects referenced names and recursively converts enclosingletorconstdeclarations that do not yet have aConstExprvalue recorded inTypeInfo. However, non-constexprletbindings that depend on runtime values (such as function parameters) never produce aConstExprentry even after their declarations have been converted. Without checking whether a declaration has already been converted in the current parametric context,ConvertConstantsReferencedUnderrepeatedly walks the declaration's dependency DAG on every reference, causing quadratic to exponential blowup in functions with chainedletbindings feeding parametric invocations.Short-circuit
ConvertConstantsReferencedUnderwhen a node has already been visited for the active parametric context or when a referencedletorconstdeclaration already has type information or a converted subtree in that context, reducing traversal work to linear in the number of AST nodes.