Skip to content

Add C_Cpp.intelliSenseModuleSearchPath for module import IntelliSense - #14894

Open
soroshsabz wants to merge 28 commits into
microsoft:mainfrom
soroshsabz:feature/modules-e2e
Open

soroshsabz wants to merge 28 commits into
microsoft:mainfrom
soroshsabz:feature/modules-e2e

Conversation

@soroshsabz

@soroshsabz soroshsabz commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Follow-up to #14837 (the CppModulesProject test scenario) and the extension-side part of #6302 (IntelliSense for C++20 modules importing in gcc/clang projects).

Module IntelliSense for gcc/clang-mode projects has been blocked by two things:

  1. Module interface file resolution. The IntelliSense engine (EDG-based, now open source at edgcpp/compiler) understands import directives in every mode, but GCC/Clang toolchains produce their own binary module formats (.gcm, .pcm) which the engine cannot read, and the MSVC-style search-dir compiler arguments are not processed in gcc/clang modes. The engine can, however, read its own .eifc module interface files in every mode, and it searches the directory named by the EDG_MODULES_PATH environment variable (inherited from the extension host by the language server process).
  2. Module interface file production. No compiler or build system emits .eifc files, so even with a search path there was nothing for the engine to find.

This PR adds the extension-side workflow that resolves both, in every IntelliSense mode.

What this PR adds

1. New setting C_Cpp.intelliSenseModuleSearchPath (string, ${workspaceFolder} supported, relative paths resolved against the workspace folder): the directory searched for module interface files when resolving import directives. It is passed to the language server through EDG_MODULES_PATH at server startup (composited with the existing sanitizer-env mechanism; inherited unchanged when unset).

2. New setting C_Cpp.intelliSenseModuleCompilerPath: a C/C++ front end command that compiles the workspace's module interface units (.cppm/.ixx/.ccm) into .eifc module interface files, so import resolution works without any manual per-module setup. Build the command from the open-source EDG front end (edgcpp/compiler; gnu emulation mode interfaces are supported since edgcpp/compiler#315). The extension:

  • finds the module interface units of the workspace folder,
  • (re)compiles the ones whose .eifc file is missing or older than the source or any of its dependencies (included headers, scanned recursively; imported module files; or the generation configuration — compiler, arguments, or standard change),
  • removes .eifc files whose sources were deleted (only those previously generated by the extension; user-supplied files are preserved),
  • compiles in multiple passes so that dependencies are available before importers are compiled,
  • uses a bounded process-tree timeout per compilation (a hung compiler wrapper or descendant cannot block IntelliSense startup),
  • writes the generated files into the module search path directory (C_Cpp.intelliSenseModuleSearchPath when set, otherwise a per-workspace cache directory under the extension's default cache root),
  • watches for changes to module interface units and headers, and regenerates (debounced, serialized) when they change,
  • points the engine's EDG_MODULES_PATH at that directory.

3. New setting C_Cpp.intelliSenseModuleCompilerArgs (string[], ${workspaceFolder} supported): additional front-end-compatible arguments (include directories via --include_directory/--sys_include, defines via --define_macro, etc.) so that module interfaces can include project headers and honor the project's preprocessing configuration.

This replaces the closed-source-only workflow with an open one: the module interface files that IntelliSense consumes are produced by the same open-source front end that anyone can build and audit.

4. Tests:

  • 33 unit tests for the settings resolution, target directory selection, module name parsing, standard mapping (including GNU spellings), staleness checking (headers, imported modules, transitive includes, missing dependencies), and path resolution.
  • An end-to-end scenario test in CppModulesProject (running first, before the language server starts): with a module interface compiler configured (a test fake that produces the checked-in .eifc files) and the search path set, the test asserts that the generated files appear in the target directory and that import math; / import geometry; resolve in gcc mode — hovering over an imported function and over a variable exported from inside a namespace works, and the "could not find module file" diagnostics are gone. The .eifc fixtures were produced with the open-source EDG front end. The test dynamically skips its semantic assertions (with a console warning) only when the language server reports it cannot read the checked-in fixtures (format churn); a "could not find module file" diagnostic fails the test (the files are verified to exist beforehand).
  • A regeneration test in the same scenario: deletes a generated module interface file, touches the interface source, and polls until the extension regenerates it through the module file watcher (debounced, serialized).

Validation

  • 8/8 CppModulesProject scenario tests pass against the shipped 1.36.0 binaries, including the end-to-end test with semantic assertions on both function and variable imports, and the regeneration-on-change test.
  • 33/33 module-related unit tests pass (189/189 total); TypeScript and ESLint clean.
  • The exported-variable import used by the test's namespace assertion required an engine fix: exported variables were silently dropped from module interface files (edgcpp/compiler#58). That fix is proposed in C++20 modules: write exported variables to IFC files [GH #58] edgcpp/compiler#631; the checked-in fixtures are generated with that fix.

Notes

Related: #6302, #14837, edgcpp/compiler#315, edgcpp/compiler#631

@soroshsabz

Copy link
Copy Markdown
Contributor Author

Sean McManus (@sean-mcmanus) can you please review this PR?

thanks :)

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.

🟡 Changes recommended

The compiler timeout kills only the direct child, so a descendant retaining stdout/stderr can leave generation unresolved and block IntelliSense startup indefinitely. Separately, generation can fail when dependencies have not yet been compiled, while missing change-triggered regeneration and dependency-aware cache invalidation can leave module outputs missing or stale.

10 open issues
What changed in this PR

Adds extension-side support for C++ module imports by generating EDG module interface files and configuring the language server’s search directory.

Changes:

  • Adds module compiler and search-path settings.
  • Generates missing or outdated .eifc files before server startup.
  • Adds unit tests and a fixture-backed module-import scenario.
File Description
Extension/​package.json Registers both settings.
Extension/​package.nls.json Documents settings and reload requirements.
Extension/​src/​LanguageServer/​settings.ts Exposes setting getters.
Extension/​src/​LanguageServer/​moduleSearchPath.ts Resolves search paths and cache directories.
Extension/​src/​LanguageServer/​moduleInterfaceCompiler.ts Implements module-file generation.
Extension/​src/​LanguageServer/​client.ts Connects generation and server environment setup.
Extension/​test/​unit/​moduleSearchPath.test.ts Tests path and environment helpers.
Extension/​test/​unit/​moduleInterfaceCompiler.test.ts Tests parsing, standards, and freshness checks.
Extension/​test/​scenarios/​CppModulesProject/​tests/​modules.integration.test.ts Exercises generation and imported-symbol resolution.
Extension/​test/​scenarios/​CppModulesProject/​assets/​.gitignore Ignores generated module files.

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
…ency-aware staleness, retry passes, gnu++ standards, relative paths, and test hardening
@soroshsabz

Copy link
Copy Markdown
Contributor Author

Sean McManus (@sean-mcmanus) The follow-up push (b1e8c2a) addresses all 10 review findings (all threads resolved with details). The CI workflows are in action_required state — could you approve them to run? The previous commit's Linux run failed in the MultirootDeadlockTest scenario, which passes locally on this branch (18/18 including the exact failing test "routes manual folding operations by URI during a workspace client switch").

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.

🟡 Changes recommended

The Windows-specific path assertion fails on Linux and macOS because host path resolution treats backslashes literally. Generation can also report success with stale importers when they compile against old dependency outputs before those dependencies rebuild. Separately, changing the compiler, arguments, or C++ standard does not invalidate cached outputs when timestamps are unchanged, and deleting an interface leaves its generated file available even after reload, allowing imports of removed modules to keep resolving.

4 open issues
10 resolved since last review

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
…-check generated units, platform-specific test

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.

🟡 Changes recommended

On a clean cache or configuration change, successfully compiled modules are repeatedly rebuilt, causing quadratic compiler work before startup and ultimately being reported as failed. Persisting changed configuration after failed rebuilds can also allow old outputs to be reused on the next run. Separately, claiming failed or skipped outputs as extension-owned risks deleting user-supplied .eifc files during orphan cleanup, while ignoring angle-bracket header dependencies resolved through --include_directory can leave cached exports stale after header edits, even after reload.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Track angle-bracket includes in dependency freshness checks

Extension/​src/​LanguageServer/​moduleInterfaceCompiler.ts:134

A module can now include <project/config.h> through --include_directory, but this dependency scan ignores angle-bracket includes. Editing that header can trigger regeneration without rebuilding the module, leaving cached exports stale even after reload. Resolve these includes through the configured include directories, or conservatively treat outputs as stale when dependency freshness cannot be established.

4 resolved since last review

Review effort: Balanced

…file ownership, metadata persistence on failure, and cross-platform test fixes

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.

🟡 Changes recommended

If an importer first compiles against an old dependency and then fails after that dependency is rebuilt, its earlier success keeps the later error out of result.failed, allowing the new configuration to be persisted despite the failed rebuild.

1 open issue
3 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

The test’s importer always fails and never compiles successfully, so the test would still pass with the earlier bug that ignored failures after an initial success. It therefore does not verify the failure scenario it needs to cover.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
… angle-bracket include resolution, watcher deletes, static generation chain, active config standard, metadata sentinel, and discovery limit removal
@soroshsabz
soroshsabz requested a balanced review from Copilot December 3, 2026 07:42
… invocations

GitHub's code scanning flagged the lock recovery and the asynchronous
Windows process cleanup as potentially allowing concurrent compiler
writes; both windows are now closed:

- The Windows kill tools (taskkill /T, the PowerShell orphan
  enumeration) are now AWAITED, bounded: a timed-out invocation settles
  -- and the generation lock is released -- only after both kill tools
  exited, so a descendant that is still being terminated cannot overlap
  with the next generation's writes. The timeout handler kills the tree
  first and only then starts the grace fallback.
- Each running invocation re-checks the generation lock ownership
  periodically (the check doubles as the heartbeat refresh for long
  compilations): when the lock was taken over mid-invocation, the
  compiler is killed immediately and the invocation fails with "the
  generation lock was lost" -- concurrent writes from a displaced holder
  are bounded to the monitoring interval (5 seconds) instead of running
  to completion.
- The lock ownership is additionally verified BEFORE each invocation, so
  a takeover that happened between invocations cannot let the run start
  another compiler.
- The abort path was extracted (abortOnLostLock) and shared by the pre-
  and post-invocation checks.
@soroshsabz

Copy link
Copy Markdown
Contributor Author

GitHub's code scanning flagged the lock recovery and the asynchronous Windows process cleanup as potentially allowing concurrent compiler writes. Both windows are closed in 1219d6c:

Asynchronous process cleanup: the Windows kill tools (taskkill /T, the PowerShell orphan enumeration by parent process id) are now awaited, bounded (5s per tool): a timed-out invocation settles — and the generation lock is released — only after both kill tools exited, so a descendant still being terminated cannot overlap with the next generation's writes. The timeout handler kills the process tree first and only then starts the grace fallback (which remains for the pathological case).

Lock recovery: each running invocation now re-checks the generation lock ownership every 5 seconds (the check doubles as the heartbeat refresh for long compilations, which also shrinks the false-staleness window): when the lock is taken over mid-invocation, the compiler is killed immediately and the invocation fails with "the generation lock was lost" — concurrent writes from a displaced holder are bounded to the monitoring interval instead of running to completion. The ownership is additionally verified before each invocation, and the ownership-checked heartbeat/release (pid in the lock's owner file) and the verified rename takeover (with rollback) from the earlier rounds remain.

A unit test drives the mid-invocation takeover end to end: a compiler that steals the lock and then lingers is killed before writing anything, and the run aborts as contended (math.eifc is never written). All 236 unit tests and the 9 scenario tests pass.

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.

🟡 Changes recommended

On Windows, timeout and lock-loss handling can release the generation lock before process-tree termination finishes, allowing compiler descendants to keep writing. Independently, after a lock takeover, the losing generator can delete the new owner's output because failure cleanup runs before the ownership check.

2 open issues

Review effort: Balanced

…re failure cleanup

Two follow-up hardenings on the lock monitor and kill paths:

- The child's "close" event can fire (the direct child exiting closes the
  output pipes) while the Windows process-tree termination is still
  running -- descendants can still write. The termination promise is now
  tracked, and the close handler settles the invocation only after it
  finished, for both the timeout and the lock-loss paths; the grace
  fallback still bounds the case where "close" never fires.
- The post-invocation lock ownership check now runs BEFORE the
  invocation's result is processed: a run whose lock was taken over
  during the invocation aborts without recording the output and without
  running the failure cleanup -- the new owner may already have
  rewritten the expected output, and mistaking that file for this run's
  partial output would have deleted the new owner's output. A unit whose
  compilation straddled the takeover is therefore no longer reported as
  generated (its output belongs to the new owner's timeline; the
  lock-contended retry regenerates it).

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

Shared-cache locking and dependency invalidation may leave generated interfaces stale or importers unrefreshed, so cache freshness and concurrent-window behavior need human review.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Comment thread Extension/package.json Resolved
…ity, duplicate module failures, dead-pid heartbeat bound, success-path created-or-changed, machine-overridable scopes, and scenario asset restoration

- The unit record now keeps the set of includes that were unresolved at
  the last successful compilation: a STABLE set (typically system headers
  like <vector> in the global module fragment, whose directories are the
  compiler's built-in paths and are not visible to the scanner) no longer
  makes the unit stale on the first check of every run -- only a change in
  the set does. Previously such a unit was recompiled on every startup and
  every watched header save, each paying a compile plus an IntelliSense
  restart of all open documents.
- The unit record now also stores the produced file's identity (size and
  mtime): outputs are named only by module name, so an output rewritten by
  a different generator (another workspace sharing the directory with the
  same module name) is detected as not this unit's output and regenerated,
  instead of silently skipping the unit while it consumes the other
  workspace's module.
- Duplicate module names within a workspace are reported as failures for
  all but the first declaring unit (which is generated): importing code
  cannot distinguish same-named outputs, and the failure message names
  both units so the user can see why an importer resolves the wrong
  module.
- The dead-pid lock takeover now also requires the heartbeat to have aged
  past a bound (60s, comfortably more than a compilation timeout plus
  per-invocation bookkeeping): process.kill(pid, 0) only sees the caller's
  PID namespace, so a live holder in another container or on another host
  sharing the directory looks dead -- its fresh heartbeat now keeps the
  lock safe while it is actively generating (a crash still stops the
  heartbeat, so recovery is not delayed beyond the bound).
- The success-path produced check now requires the file to have been
  created or changed by the invocation (mtime OR size), removing the
  "mtime >= invocation start" disjunct that accepted a pre-existing
  future-mtime file (clock skew, copied or extracted files) when a
  wrapper exited 0 without writing.
- The three new settings are now machine-overridable, matching
  C_Cpp.default.compilerPath/compilerArgs and C_Cpp.intelliSenseCachePath
  (VS Code's Settings Sync excludes machine-scoped settings, so
  machine-specific paths are not synced to machines where they do not
  exist), and the compiler-args description now also states that the
  value is only read at language server startup.
- The recovery scenario restores the modified math.ixx asset in a finally
  block, so a failed assertion or timeout cannot leave the checked-in
  asset modified for the remaining tests and local runs.

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.

🟡 Changes recommended

A stale generator resuming after lock takeover can overwrite or delete the new owner’s lock, allowing concurrent generators. Independently, deleting a source can remove its recorded .eifc output even after a user or another workspace has replaced that file, because cleanup does not verify the output’s identity or whether a live owner still needs it.

8 open issues

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
…content hashing, macro-include conservatism, hover cache invalidation, external-generation refresh, glob dots, orphan identity, and failure-cleanup size

- The generation lock is now an instance: the acquisition returns a handle
  (pid + acquisition time, unique per acquisition), and heartbeat updates
  and the release are bound to it. The heartbeat refreshes the owner
  file's MODIFICATION time only (never its content), and only after
  verifying the file still records this exact instance: a stale holder
  that resumes after a takeover cannot overwrite a replacement owner's
  identity -- the worst a raced refresh can do is make the replacement's
  lock look fresher, which only delays an abandonment takeover (the safe
  direction). The release renames the lock away and verifies the RENAMED
  directory still belongs to this instance before removing it (rolling a
  replacement lock back otherwise), so a stale holder can no longer delete
  a replacement lock between its ownership check and the removal.
- Imported module interface files are now hashed into the input
  fingerprint: a replaced user-supplied or cross-workspace module file --
  even a timestamp-preserving copy -- invalidates the importer
  independently of modification times.
- Macro includes ("#include API_HEADER") and dependency scans cut off by
  the depth limit are marked as unknown dependencies: they make the unit
  conservatively stale on the first check of EVERY run (editing the
  macro's header must actually recompile), unlike a stable set of
  unresolved ordinary include names (system headers), which no longer
  forces a recompile.
- The hover provider's cached content is discarded before the
  post-generation IntelliSense restart: a Copilot re-invocation at the
  same document/position no longer returns the pre-restart hover (an
  unchanged importer keeps showing the old signature after its module
  changed).
- The client detects externally completed generations: the metadata
  content hash is observed after each run, and a change (with a zero
  compile count -- an all-skip run writes back an identical content)
  means another window generated the modules while this run waited for
  the lock, and the open documents are refreshed even though this run
  compiled nothing.
- The watched header glob keeps the dots in the brace alternatives
  (headerFileGlob and the module file watcher's combined pattern):
  without them, arbitrary filenames merely ending in "h", "hp", etc.
  (e.g. "build/graph") scheduled discovery and dependency scans.
- Orphan cleanup no longer deletes a REPLACED output: when the file no
  longer matches the recorded output identity (rewritten by the user or
  another workspace after the source was deleted), the obsolete
  ownership record is discarded but the replacement file is left alone.
- The failure cleanup also compares the output's SIZE (not only its
  mtime): a failed compiler that changes the file size without changing
  its timestamp (a timestamp-preserving wrapper or copy) no longer leaves
  a partial .eifc available to IntelliSense.

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.

🟡 Changes recommended

Lock takeover and release can displace a fresh lock before verifying ownership, allowing multiple compilers to write concurrently; separately, output identity checks based only on size and mtime can mistake different replacement contents for the original output, causing orphan cleanup to delete the replacement when the original source is removed.

8 open issues
8 resolved since last review

Review effort: Balanced

…, include_next conservatism, conditional declaration adoption, output content digests, pre-rename lock verification, include-directory watchers, and scenario quiescence

- The uppercase module interface extensions (.CPPM/.IXX -- accepted by the
  "eccp" driver's suffix handling) are included in the discovery glob, the
  extension list, and therefore the workspace watcher: those units are
  generated and watched like the lowercase ones.
- An ABSOLUTE include name is its own candidate (the EDG front end accepts
  absolute names directly, without the include search order), so a header
  reached through an absolute angle include is tracked and watched even
  with no include directories configured.
- #include_next directives are recognized: their search-after-current-
  directory semantics cannot be reproduced without knowing the including
  header, so the unit is marked as having unknown dependencies
  (conservatively stale on every run).
- Conditionally ambiguous module declarations (#ifdef A / export module
  x; / #else / export module y; / #endif) no longer select the first
  potentially-active candidate: the predicted output is the RECORDED one
  when the record's name is among the candidates, and when the compiler
  produces a different candidate's file, that freshly produced .eifc is
  ADOPTED as the unit's output (the compiler's preprocessing configuration
  is the authority). A successful compilation is no longer misreported as
  failed, the record tracks the actual output, and later runs are stable.
- The output identity now includes a CONTENT DIGEST (SHA-1): a replacement
  with different contents preserving both the size and the mtime no longer
  passes the freshness or orphan-cleanup checks -- the unit regenerates,
  and a replaced orphan's ownership record is discarded without deleting
  the replacement.
- The takeover and the release re-verify the lock's owner IMMEDIATELY
  before the rename (shrinking the "potentially replaced lock" window to
  the sub-millisecond read-to-rename gap), and a rollback failure leaves
  the renamed directory in place (never deleted -- it is someone's lock):
  the displaced holder's lock-loss monitor aborts it within one monitoring
  interval, so at most one generator continues.
- Units with unknowable dependencies (macro includes, #include_next,
  depth-limited scans) now cause the CONFIGURED INCLUDE DIRECTORIES to be
  watched (recursively): editing a header behind a macro include schedules
  a regeneration instead of only recompiling at the next scheduled run.
- The regeneration scenario test waits for the generation's QUIESCENCE
  (the output's timestamp stable for longer than the debounce) before
  returning, so a later invocation of the still-running generation cannot
  recreate the file the next test deletes.

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.

🟡 Changes recommended

Output adoption can claim an unchanged, unrelated user-supplied .eifc file when an ambiguous source’s compiler succeeds without writing output, allowing later source deletion to delete that user file. Separately, macro-include watchers can react to generator output and bookkeeping writes when an include directory contains the output directory, causing endless compilation and IntelliSense restarts. Dependency watching can also cause endless regeneration when it excludes only the first conditional candidate rather than the adopted output and the producing module has a macro include.

6 open issues
8 resolved since last review

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
… adoption, all-candidate failure cleanup, superseded-output removal, own-output exclusion, and target-dir event filtering

- Module declaration candidates now use the file-name spelling
  (partitions map to the "m-p" form, like parseModuleFileName):
  "export module math:parts;" expects "math-parts.eifc" instead of
  rejecting the successful compilation.
- Output adoption is restricted to the source's PARSED candidates and
  verified against a pre-invocation snapshot: only a candidate file the
  invocation CREATED or CHANGED (mtime or size) is adopted, so a
  recent/future timestamp alone never establishes production, and an
  unrelated user-supplied file is never adopted (its ownership is never
  recorded).
- The failure cleanup examines ALL candidate outputs, not only the
  predicted one: whichever candidate files the failed invocation changed
  are removed (a partial file for a different branch's candidate no longer
  stays in the search directory).
- After a verified branch switch, the previously owned output is removed
  only when its recorded identity still matches and no other source owns
  it -- it would otherwise stay importable and untrackable, since the
  adoption replaces its sole ownership record.
- The dependency watchers exclude EVERY candidate output (plus the
  recorded output's name) from the watched set: an importer of the
  adopted (non-first-candidate) output no longer watches the generator's
  own output, which would schedule an endless run loop for a unit with a
  macro include.
- The recursive include-directory watchers ignore events inside the
  generation's own output directory: when an include directory contains
  the output directory (e.g. ${workspaceFolder} with an in-workspace
  output directory), the generation's own module interface, metadata, and
  lock writes no longer schedule another generation.

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.

🟡 Changes recommended

An absolute search path ending in a separator can make the generator watch its own .eifc outputs, causing endless regeneration when an imported module uses a macro include. Separately, quoted macro includes beside sources can go unwatched, while edits to compilation inputs under targetDir are discarded, leaving modules stale. Duplicate detection can also skip a valid unit by comparing predicted names before resolving ambiguous declarations. Finally, size-and-timestamp-only output checks can reject valid rebuilds or retain corrupt outputs for IntelliSense when a wrapper replaces an .eifc with same-sized content while preserving its timestamp.

5 open issues
6 resolved since last review

Review effort: Balanced

Comment thread Extension/src/LanguageServer/client.ts Resolved
Comment thread Extension/src/LanguageServer/client.ts Resolved
… duplicate detection, precise artifact filtering, source/header directory watches, and normalized target-dir comparisons

- The pre-invocation snapshots of the candidate output files now capture
  content digests (size, mtime, and SHA-1), and both comparisons -- the
  success verification and the failure cleanup -- use them
  (outputFileChanged): a timestamp-preserving wrapper that replaces an
  existing .eifc with different, same-sized content is recognized as a
  valid rebuild on success and removed as a partial output on failure.
- Duplicate detection considers only CERTAIN names up front: a unit whose
  declaration is conditionally ambiguous resolves to its actual output
  name only after compilation, so two units sharing a name only in an
  inactive #ifdef branch (with distinct active #else names) are both
  generated. Resolved names are tracked across the run
  (resolvedModuleFileNames), and a collision that only appears once an
  ambiguous declaration resolves is reported for the later unit.
- Of two units resolving to the same module file, the first declaration
  in file order wins -- the up-front rule -- whichever compiled first
  ("first to resolve" depended on which units were up to date and could
  flip the reported duplicate between runs). A duplicate cannot leave its
  interface behind: when it compiled after its owner, the owner's output
  (which the duplicate's compilation overwrote) is regenerated in the
  next pass (outputOverwritten); when the owner compiled after it, the
  duplicate's earlier successful compilation is undone; and when a
  duplicate's compilation fails after overwriting the owner's output,
  the partial output is removed, the duplicate is reported once (not
  retried within the run -- each retry would destroy the owner's
  regenerated output again), and the owner is regenerated. Both stages
  share one message (duplicateModuleError).
- The directory watchers exclude only the generator's own artifacts from
  the events that schedule a regeneration (isGeneratorArtifact: its
  module interface files, the metadata, and the lock directories including
  their renamed variants) instead of the entire output directory: a
  compilation input living there (e.g. a macro-included api.inc when the
  search directory is also an include directory) still schedules a run.
- When dependencies are unknowable, the directories searched for quoted
  includes are watched as well -- the interface sources' directories and
  every resolved header's directory -- so a macro-included header beside a
  .cppm triggers a regeneration even without include-directory arguments
  (the workspace extension glob covers only known header extensions).
- The own-output comparison in the dependency tracker normalizes the
  target directory on both sides: an absolute search path ending in a
  separator (preserved by the search-path resolution) no longer defeats
  the comparison, which would have turned the generator's own .eifc
  outputs into watched dependencies (scheduling a run after every
  regeneration for an imported module with a macro include).

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.

🟡 Changes recommended

Retained recursive watchers keep stale output filters after a macro-including module is added or renamed, allowing new .eifc writes to trigger endless rebuilds. Separately, unfiltered object files from the recommended eccp --module_interface command can cause another rebuild loop when a macro include is present and a recursive watcher covers the output directory. The previous-failure retry test also lacks existing unit metadata, so it can pass even if retries for failed units with unchanged configurations are broken.

3 open issues
5 resolved since last review

Review effort: Balanced

Comment on lines +3165 to +3167
if (this.moduleFileDependencyWatchers.has(dependency)) {
continue;
}
Comment on lines +3198 to +3199
if (isGeneratorArtifact(uri.fsPath, targetDir, ownOutputFiles)) {
return;
Comment on lines +1499 to +1508
// A module interface file that looks up to date (newer than the
// source) but is the partial output of a previous failed
// compilation, and a metadata recording that failure with the same
// configuration.
await new Promise(r => setTimeout(r, 10));
fs.writeFileSync(path.join(dir, "math.eifc"), "partial");
fs.writeFileSync(path.join(dir, ".cpptools-module-generation.json"), JSON.stringify({
units: {},
failedSources: [source]
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

3 participants