Skip to content

Preserve captured-dependent branches during query precompilation - #39479

Merged
AndriySvyryd merged 3 commits into
mainfrom
copilot/fix-precompiler-conditional-folding
Nov 13, 2026
Merged

AndriySvyryd merged 3 commits into
mainfrom
copilot/fix-precompiler-conditional-folding

Conversation

Copilot AI commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Query precompilation folds ?:, &&, ||, and ?? using placeholder captured values, dropping branches that depend on runtime values. For example, Where(e => all || e.IsActive) can incorrectly retain the IsActive filter when all is true.

  • Branch folding: Prevent captured-dependent simplification during both parameter extraction and extractor-path calculation. Preserve ordinary runtime folding and generation-time folding of noncaptured values.
  • Regression coverage: Add shared synchronous/asynchronous cases for both conditional arms, both logical operand positions, and null/non-null coalescing, with SQL Server baselines.

Copilot AI changed the title [WIP] Fix query precompiler conditionals on captured variables Preserve captured-dependent branches during query precompilation Oct 30, 2026
Copilot AI requested a review from AndriySvyryd October 30, 2026 22:48
@github-actions

Copy link
Copy Markdown
Contributor

Agent harness evaluation deferred

This PR affects: query-pipeline. Automatic evaluation is deferred because this PR is currently marked as draft. Once it is ready for review, the usual author authorization rules apply. A contributor with write access can comment /eval or /eval component-name, or run the workflow manually for pull request #39479.

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.

🔵 Needs a closer look

The change modifies core query precompilation in both runtime parameter extraction and generated extractor-path calculation, so maintainer validation is needed for additional captured-dependent short-circuit shapes beyond the new end-to-end cases.

No open issues 🎉

What changed in this PR

This pull request prevents query precompilation from incorrectly folding branches that depend on captured runtime values, while preserving safe folding for noncaptured expressions and ordinary runtime queries.

Changes:

  • Prevent captured-dependent simplification of conditional, logical, and coalescing expressions during precompilation.
  • Add synchronous and asynchronous regression coverage.
  • Add SQL Server baselines for the new scenarios.
  • Document the branch-preservation invariant in the query-pipeline skill.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrecompiledQuerySqlServerTest.cs Adds SQL Server baselines for the new synchronous and asynchronous scenarios.
test/​EFCore.Relational.Specification.Tests/​Query/​PrecompiledQueryRelationalTestBase.cs Adds shared regression coverage for conditional, logical, and coalescing expressions.
src/​EFCore/​Query/​Internal/​ExpressionTreeFuncletizer.cs Preserves captured-dependent branches during precompiled query processing and extractor-path calculation.
.agents/​skills/​query-pipeline/​SKILL.md Documents the captured-value branch-preservation invariant.

Review effort: Lite

Comment thread .agents/skills/query-pipeline/SKILL.md Resolved
@github-code-quality

github-code-quality Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main ed0b576 copilot/fix-precompi... 69e87d7 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main ed0b576 copilot/fix-precompi... 69e87d7 +/-
src/EFCore.Rela...CommandCache.cs 100% 98% -2%
src/EFCore/Quer...eFuncletizer.cs 87% 87% 0%
src/EFCore.Abst...erExtensions.cs 100% 100% 0%
src/EFCore.Anal...icSuppressor.cs 96% 96% 0%
src/EFCore.Desi...onExtensions.cs 100% 100% 0%
src/EFCore.Desi...viderFactory.cs 95% 95% 0%
src/EFCore.Desi...CSharpHelper.cs 96% 96% 0%
src/EFCore.Desi...eportHandler.cs 47% 47% 0%
src/EFCore.Desi...mnExtensions.cs 100% 100% 0%
src/Microsoft.D...nnectionPool.cs 97% 100% +3%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 30, 2026 23:53 UTC

Copilot AI requested a review from AndriySvyryd October 30, 2026 23:26
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 30, 2026 23:26
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 30, 2026 23:26
@AndriySvyryd
AndriySvyryd requested review from cincuranet and a lite review from Copilot October 30, 2026 23:26

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.

🔵 Needs a closer look

The change modifies central ExpressionTreeFuncletizer behavior across both precompilation modes and providers, so broader human validation is needed beyond the targeted regressions.

No open issues 🎉

Review effort: Lite

@AndriySvyryd
AndriySvyryd merged commit 62d1746 into main Nov 13, 2026
25 of 26 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-precompiler-conditional-folding branch November 13, 2026 05:35
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query precompiler folds conditionals on captured variables using fake defaults and drops a SQL branch

4 participants