Skip to content

fix(contexts): compare again when a file either compile read changes - #1179

Open
16bit-ykiko wants to merge 5 commits into
mainfrom
fix/host-context-choice
Open

16bit-ykiko wants to merge 5 commits into
mainfrom
fix/host-context-choice

Conversation

@16bit-ykiko

@16bit-ykiko 16bit-ykiko commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Why

A file with no database entry of its own — a unity build's part, another included .cpp, a header that is not self-contained — compiles either alone or in its host's context, whichever has fewer errors. That decision depended on both compiles, but the open document was tied only to the compile it last ran. In a unity build where unity.cpp includes b.cpp and then a.cpp:

  1. Commenting out #include <string> in b.cpp makes a.cpp's std::string an error whichever way it compiles. That is a tie, and on a tie a.cpp switched to compiling alone.
  2. Compiled alone, a.cpp reads nothing of b.cpp. Restoring the include and saving never compiled a.cpp again, so its error stayed until a.cpp itself was edited.

What changed

  • What a decision depends on. A file's command now depends on everything the self-containment check's compiles read, together with the chain of includes it was already tied to (SelectedCommand::inputs, moved there from Resolution). This holds whether the result comes from the store (Project::self_contained hands out the stored result's inputs) or was just found by the attempt (CompileAttempt::found). The sends after the check compile under that result rather than reading the store again, which a change during the compile could have cleared. An open document therefore compiles again, and compares again, when any file either compile read changes.
  • A tie keeps the current mode. A tie leaves the document as its latest compile ran (DocumentCompile::in_context). A file that has not yet compiled in the context still compiles alone on a tie, as clice inspect does.
  • The redundant first flag of the compile attempt is gone. The design page (en and zh) states the tie rule and what the result depends on.

Tests

  • New case contexts/self_containment/22_earlier_part, a unity build whose part uses a name declared by the part included before it:
    • declared later: a tie, then the earlier part declares the name.
    • declared after typing: the same, with the part edited in between so it compiles under the stored result.
    • tie keeps context: the reported scenario, in context, then a tie, then the fix.
    • On main, all three fail at their checks: the part stays compiled alone, or leaves the context on the tie.
  • On boxes, at this head: Linux x64 RelWithDebInfo and Debug (ASan), and Windows x64 (cross-built, run on Windows). Unit tests and cases pass on each.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T06:53:47.527432Z 1c15564 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The self-containment check now applies tie handling based on whether compilation has used host context. Inputs read by the check are tracked through command resolution and compilation. A unity-build test fixture covers changes to declarations in the host context.

Changes: Self-containment checks

Layer / File(s) Summary
Track self-containment inputs
src/project/command/command.cppm, src/project/command/resolve.cpp, src/project/command/self_contained.cpp, src/project/project.cppm, src/driver/inspect.cc
Command selection and resolution collect inputs read by self-containment checks and synthesized host contexts.
Compare compilation contexts
src/server/served_project/compile.cpp, src/server/served_project/served_project.cppm
Compilation records whether it used synthesized context. The comparison applies strict or non-strict error-count checks based on that context, and carries check inputs into resolution and document inputs.
Test and document self-containment behavior
tests/contexts/self_containment/22_earlier_part/*, docs/en/design/compilation-context.md, docs/zh/design/compilation-context.md, docs/meta/translations/design/compilation-context.json
The unity-build tests cover diagnostics and synthesized-context counts as declarations change. The design documentation describes the comparison and cache rules.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Merge Risk: Minimal · up to 1c155

Open documents now recompile and compare contexts again when a file read by either self-containment compile changes. The unity-build fixture covers the new behavior. No merge-blocking defect was found. Debug and Windows CI results were still pending in the PR status.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(contexts): compare again when a file either compile read changes" follows the conventional commits format and names the main change. The change makes an open document's command depend o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template's Why, What changed, and Tests sections. The Why section explains the bug with a concrete unity-build reproduction. The What changed section describes the decision…
Full details: Title check

Explanation

The title "fix(contexts): compare again when a file either compile read changes" follows the conventional commits format and names the main change. The change makes an open document's command depend on the inputs read by both self-containment compiles, so it recompiles and compares again when any of those inputs change. The title is specific and matches the changeset and the PR objectives.

Full details: Description check

Explanation

The description follows the template's Why, What changed, and Tests sections. The Why section explains the bug with a concrete unity-build reproduction. The What changed section describes the decision inputs, the tie rule, and removal of the redundant first flag, and it notes the design page updates. The Tests section names the new case contexts/self_containment/22_earlier_part with its three scenarios, states that all three fail on main, and lists the platforms verified at this head. The template's Related issue section is absent. The template marks this section as optional, so its absence does not block the check. The description does not link PR #1179 or any issue, and the objectives describe the PR as reporting Debug and Windows results still in progress, which conflicts with the description's claim that those runs passed. The author should reconcile this claim before merge.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b071a9c and 1c15564.

Files selected for processing: 16

  • docs/en/design/compilation-context.md
  • docs/meta/translations/design/compilation-context.json
  • docs/zh/design/compilation-context.md
  • src/driver/inspect.cc
  • src/project/command/command.cppm
  • src/project/command/resolve.cpp
  • src/project/command/self_contained.cpp
  • src/project/project.cppm
  • src/server/served_project/compile.cpp
  • src/server/served_project/served_project.cppm
  • tests/contexts/self_containment/22_earlier_part/a.cpp
  • tests/contexts/self_containment/22_earlier_part/b.cpp
  • tests/contexts/self_containment/22_earlier_part/project.toml
  • tests/contexts/self_containment/22_earlier_part/snap.toml
  • tests/contexts/self_containment/22_earlier_part/test.ts
  • tests/contexts/self_containment/22_earlier_part/unity.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant