Type inference: Simplify internal representation of type paths#19570
Merged
hvitved merged 1 commit intogithub:mainfrom May 26, 2025
Merged
Type inference: Simplify internal representation of type paths#19570hvitved merged 1 commit intogithub:mainfrom
hvitved merged 1 commit intogithub:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR switches the internal representation of type paths to always include a trailing dot, which streamlines segment counting and concatenation logic and yields a measurable speedup.
- Replaced the
lengthAtLeast2helper and simplifiedlength()to count trailing-dot separators via a regex. - Refactored
appendandstripPrefixto pure string concatenation under the new trailing-dot convention. - Updated
singletonto emit its encoded type parameter with a trailing dot.
Comments suppressed due to low confidence (2)
shared/typeinference/codeql/typeinference/internal/TypeInference.qll:194
- [nitpick] The doc for
appendcould note that boththisandsuffixinclude trailing dots, so no additional separator is added. Clarifying this will help maintainers understand the simplified concatenation.
/** Gets the path obtained by appending `suffix` onto this path. */
shared/typeinference/codeql/typeinference/internal/TypeInference.qll:216
- The revised
stripPrefixlogic should be covered by unit tests, especially edge cases like emptyprefixor whenprefixequals the full path, to guard against regressions.
TypePath stripPrefix(TypePath prefix) { this = prefix + result }
Comment on lines
+189
to
+190
| // `result = count(this.indexOf("."))` | ||
| // but performs better because it doesn't use an aggregate |
There was a problem hiding this comment.
The comment references count(this.indexOf(".")), but the implementation now uses regexpReplaceAll(...).length() to count separators. Consider updating the comment to clearly describe that it counts dots in the string.
Suggested change
| // `result = count(this.indexOf("."))` | |
| // but performs better because it doesn't use an aggregate | |
| // Counts the number of dots in the string by removing numeric characters | |
| // using a regular expression and calculating the length of the resulting string. |
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.
Adding a trailing
.to the internal representation of type paths greatly simplifies the logic for constructing and deconstructing type paths.DCA reports a small speedup.