Skip to content

Type inference: Filter away psuedo types in getTypeMentionRoot - #22694

Merged
hvitved merged 2 commits into
github:mainfrom
hvitved:type-inference-filter-pseudo
Sep 30, 2026
Merged

hvitved merged 2 commits into
github:mainfrom
hvitved:type-inference-filter-pseudo

Conversation

@hvitved

@hvitved hvitved commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes an issue uncovered by unified DCA nightly for the project soto-project/soto where we mistakenly matched TypeMentions that cannot resolve (in that case they are interpreted as "resolving" to UnknownType).

DCA cannot confirm that soto-project/soto now works because it already fails to analyze on the baseline, but I have verified that it works locally. It does show a significant speedup on signalapp/Signal-iOS though.

DCA for rust also shows a speedup.

@hvitved
hvitved force-pushed the type-inference-filter-pseudo branch from c2ae6ee to e0cd79a Compare September 29, 2026 10:07
@hvitved hvitved changed the title Type inference: Filter away psuedo types in more places Type inference: Filter away psuedo types in getTypeMentionRoot Sep 29, 2026
@hvitved
hvitved requested a balanced review from Copilot September 29, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The behavioral change lacks regression coverage, and its documentation is now inaccurate.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Filters pseudo types from root type mentions during shared type inference.

Changes:

  • Excludes PseudoType roots.
  • Limits instantiation candidates to transitive constraints.
File Description
shared/​typeinference/​codeql/​typeinference/​internal/​TypeInference.qll Refines root-type and constraint matching.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread shared/typeinference/codeql/typeinference/internal/TypeInference.qll Outdated
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Sep 29, 2026
@hvitved
hvitved marked this pull request as ready for review September 29, 2026 13:43
@hvitved
hvitved requested a review from a team as a code owner September 29, 2026 13:43
typeConstraint(type, constraint) and typeCondition(type, abs, condition)
)
) and
conditionSatisfiesConstraint(_, _, constraint, true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An unrelated small piece of manual magic; I suspect this is what causes the marginal Rust speedup.

@hvitved
hvitved requested a review from paldepind September 29, 2026 13:56
@paldepind

Copy link
Copy Markdown
Contributor

we mistakenly matched TypeMentions that cannot resolve (in that case they are interpreted as "resolving" to UnknownType).

Why do we not address that directly? I.e., make sure that no type mentions resolve to pseudo types to begin with, instead of filtering them out after the fact?

@hvitved

hvitved commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Why do we not address that directly? I.e., make sure that no type mentions resolve to pseudo types to begin with, instead of filtering them out after the fact?

Because we want to allow for cases where type annotated entities are allowed to have their types inferred from the context whenever the annotation cannot be resolved (for whatever reason). For example in

let x : Vec<Unresolved> = Vec::new();
x.push(foo());

we will allow for the element type to be inferred from the return type of foo (perhaps Unresolved can actually be resolved wherever foo is defined). I.e., we effectively treat unresolvable type mentions as _.

@paldepind

Copy link
Copy Markdown
Contributor

Thanks, that makes sense. I think it's worth adding that explanation in a comment before the added not result instanceof PseudoType as I don't think it's immediately clear why a type mention would have pseudo types to begin with.

@hvitved

hvitved commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I think it's worth adding that explanation in a comment before the added not result instanceof PseudoType as I don't think it's immediately clear why a type mention would have pseudo types to begin with.

Good idea, done.

@paldepind paldepind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM and I think the final version is much clearer and explicit 👍

@hvitved
hvitved merged commit 8a95291 into github:main Sep 30, 2026
106 of 108 checks passed
@hvitved
hvitved deleted the type-inference-filter-pseudo branch September 30, 2026 08:19
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.

3 participants