Skip to content

Share type inference constraint matching through matching positions - #23067

Draft
hvitved wants to merge 4 commits into
mainfrom
hvitved-share-type-matching-logic
Draft

hvitved wants to merge 4 commits into
mainfrom
hvitved-share-type-matching-logic

Conversation

@hvitved

@hvitved hvitved commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Base-type matching and type-parameter-constraint matching implement the same inference steps through separate representations and predicates. This refactor shares those steps without adding tagged wrapper dispatch.

Introduce MatchingPosition for argument positions and constrained type arguments. Each position supplies its declared and inferred types, target, and candidate-selection rules. Both cases then use the same relevant-access representation, constraint matching, and baseTypeMatch path projection. Existing base-type candidate filtering and type-parameter-only disambiguation are preserved.

Validation: codeql test run --additional-packs=. unified/ql/test/library-tests/type-inference passes with unchanged expected results.

hvitved and others added 4 commits November 9, 2026 20:28
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
private import Input2

private predicate varianceEnabled() {
exists(TypeParameter tp | getTypeParameterVariance(tp) != 0)
}

private predicate canDescend(Tree tree) {
not exists(getTypePathLimit()) or tree.getDepth() < getTypePathLimit()

private predicate child(Tree parent, TypeParameter tp) {
exists(
Term term, Constraint constraint, Tree actual, Tree expected, int relation, Type root

private predicate child(Tree parent, TypeParameter tp) {
exists(
Term term, Constraint constraint, Tree actual, Tree expected, int relation, Type root

private predicate child(Tree parent, TypeParameter tp) {
exists(
Term term, Constraint constraint, Tree actual, Tree expected, int relation, Type root

private predicate projection(Tree tree, Type root) {
exists(
Term term, Constraint constraint, Tree actual, Tree expected, int relation, Type source

private predicate projection(Tree tree, Type root) {
exists(
Term term, Constraint constraint, Tree actual, Tree expected, int relation, Type source

pragma[nomagic]
private predicate relevantOrigin(Tree tree, TypePath path) {
exists(Term term, Constraint constraint, Tree expected, int relation |
/** Gets a contextual type for an unknown subtree of the original term. */
pragma[nomagic]
Type contextualType(Term term, Constraint constraint, TypePath path) {
exists(Tree actual, Tree expected, int relation, TypePath suffix |
private module Match = VarianceMatching<Actual, TypeMention, Input>;

query predicate bounds(string name, string parameter, int relation, string path, string type) {
exists(Actual actual, TypeMention constraint, TypeParameter tp, TypePath p, Type t |

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants