Skip to content

Type inference: Simplify internal representation of type paths #19570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented May 23, 2025

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.

@hvitved hvitved marked this pull request as ready for review May 23, 2025 14:37
@Copilot Copilot AI review requested due to automatic review settings May 23, 2025 14:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lengthAtLeast2 helper and simplified length() to count trailing-dot separators via a regex.
  • Refactored append and stripPrefix to pure string concatenation under the new trailing-dot convention.
  • Updated singleton to 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 append could note that both this and suffix include 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 stripPrefix logic should be covered by unit tests, especially edge cases like empty prefix or when prefix equals 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
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

@hvitved hvitved requested a review from paldepind May 23, 2025 15:09
@hvitved hvitved added the no-change-note-required This PR does not need a change note label May 23, 2025
Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 😎

@hvitved hvitved merged commit fcfe0a2 into github:main May 26, 2025
36 of 37 checks passed
@hvitved hvitved deleted the type-inference/simplify-type-path-repr branch May 26, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy