Experiment: Dependent contextual inference - #64092
Open
Devansh Jethmalani (devanshj) wants to merge 7 commits into
Open
Experiment: Dependent contextual inference#64092Devansh Jethmalani (devanshj) wants to merge 7 commits into
Devansh Jethmalani (devanshj) wants to merge 7 commits into
Conversation
…s immediately inside a call expression
Copilot started reviewing on behalf of
Devansh Jethmalani (devanshj)
August 29, 2026 13:31
View session
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds iterative dependent contextual inference to the compiler for self-referential generic constraints.
Changes:
- Rechecks context-sensitive expressions until inference stabilizes.
- Adds diagnostic staging and cache-reset infrastructure.
- Adds compiler tests and baselines for several library patterns and edge cases.
Reviewed changes
Copilot reviewed 38 out of 52 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Implements iterative contextual inference. |
tsc/internal/ast/diagnostic.go |
Adds staged diagnostic handling. |
tsc/internal/ast/utilities.go |
Adds recursive AST traversal. |
tsc/internal/diagnostics/diagnosticMessages.json |
Defines the pass-limit diagnostic. |
tsc/internal/diagnostics/diagnostics_generated.go |
Generates the new diagnostic binding. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceBasic.ts |
Tests basic dependent inference. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceMultiplePasses.ts |
Tests multi-pass inference. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceTooManyPasses.ts |
Tests the pass limit. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceCircular.ts |
Tests circular inference. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceZustand.ts |
Tests a Zustand-style API. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceXState.ts |
Tests an XState-style API. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceTanstackQuery.ts |
Tests a TanStack Query-style API. |
tsc/testdata/tests/cases/compiler/dependentContextualInferenceAiSdk.ts |
Tests an AI SDK-style API. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceBasic.js |
Records basic JavaScript emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceBasic.symbols |
Records basic symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceBasic.types |
Records basic inferred types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceMultiplePasses.js |
Records multi-pass emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceMultiplePasses.symbols |
Records multi-pass symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceMultiplePasses.types |
Records multi-pass types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTooManyPasses.js |
Records pass-limit emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTooManyPasses.symbols |
Records pass-limit symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTooManyPasses.types |
Records pass-limit types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTooManyPasses.errors.txt |
Records the pass-limit error. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceCircular.js |
Records circular-case emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceCircular.symbols |
Records circular-case symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceCircular.types |
Records circular-case types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceZustand.js |
Records Zustand-style emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceZustand.symbols |
Records Zustand-style symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceZustand.types |
Records Zustand-style types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceXState.js |
Records XState-style emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceXState.symbols |
Records XState-style symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceXState.types |
Records XState-style types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTanstackQuery.js |
Records TanStack-style emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTanstackQuery.symbols |
Records TanStack-style symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceTanstackQuery.types |
Records TanStack-style types. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceAiSdk.js |
Records AI SDK-style emit. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceAiSdk.symbols |
Records AI SDK-style symbols. |
tsc/testdata/baselines/reference/compiler/dependentContextualInferenceAiSdk.types |
Records AI SDK-style types. |
tsc/testdata/baselines/reference/compiler/circularMappedTypeConstraint.types |
Updates existing mapped-type inference output. |
Files not reviewed (1)
- tsc/internal/diagnostics/diagnostics_generated.go: Generated file
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| c.resetNodeCheck(node) | ||
| c.revertStagedDiagnostics() | ||
| previousValueType = valueType | ||
| valueType = c.checkExpressionWithContextualTypeWorker(node, contextualType, inferenceContext, CheckModeNormal) |
Comment on lines
+7575
to
+7577
| if contextualType.flags&TypeFlagsTypeParameter == 0 || !c.isTypeParameterDependent(contextualType.AsTypeParameter()) || checkMode&CheckModeContextual != 0 { | ||
| return c.checkExpressionWithContextualTypeWorker(node, contextualType, inferenceContext, checkMode) | ||
| } |
Comment on lines
+243
to
+244
| isStaging bool | ||
| stagingDiagnostics []*Diagnostic |
Comment on lines
+7590
to
+7593
| if passes >= 5 { | ||
| c.commitStagedDiagnostics() | ||
| c.error(node, diagnostics.Dependent_contextual_inference_requires_too_many_passes_and_possibly_infinite) | ||
| return valueType |
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.
Fixes #64091
Please see the linked issue for description and discussion, this is just a shabby implementation to play with the idea, the issue is more important than the pull request!