Lifetime management: Make tracked peer storage the explicit codegen default + add storage-lint scaffolding - #11876
Open
Protik Biswas (protikbiswas100) wants to merge 1 commit into
Conversation
…lint scaffolding Storage correctness by construction: reference (peer) fields default to GC-visible tracked storage, opting out is explicit and greppable, and raw ComPtr<peer> fields become lintable. Codegen (authoring side): - Add TypeDefinition/TypeReference.IsTrackerTarget as the single authority for "reference types default to TrackerPtr storage" and make PropertyDefinition.FrameworkFieldTypeName select storage through an explicit ladder. Behavior-preserving: regenerating all codegen produces byte-identical output (verified: 1801 generated files unchanged, 0 diffs). - Add a [PropertyFlags(WeakRef=true)] opt-out that emits ctl::WeakRefPtr, the explicit alternative to the tracked default. UseComPtr (tied to AllowCrossThreadAccess) is preserved and checked ahead of the default. - Emit TrackerTargetTraits.g.h: one is_tracker_target<T> specialization per peer type, from the same predicate, so the storage default and the lint share one source of truth. Primary template in TrackerTargetTraits.h. Lint (enforcement side), under tools/clang-tidy: - New clang-tidy check xaml-peer-comptr-field (PeerComPtrFieldCheck) that errors on a raw ComPtr<T> field when is_tracker_target<T> is true, allowlisting TrackerPtr, ctl::WeakRefPtr and NonTracked<T>. - Module registration, CMake, a .clang-tidy.example (warning-as-error, scoped to peer dirs) and README. The module builds against an LLVM/clang-tidy tree and is not part of the product build; rollout is warn-only then error per the design phasing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1677a4a7-252f-4dae-82bb-c43c6e88340c
Protik Biswas (protikbiswas100)
requested a review
from a team
as a code owner
September 14, 2026 03:43
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
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.
What
Makes tracked (GC-visible) peer storage the explicit codegen default for XAML object fields, and adds storage-lint scaffolding to enforce it.
Fixes
https://task.ms/64051051
Why
XAML objects exist as a native/managed pair whose lifetimes must stay in sync. When a peer reference is stored in a way the GC walk cannot see (a plain pointer/ComPtr field), it becomes invisible to the peer-lifetime tracker and can leak or be released prematurely. Defaulting field storage to the tracked form — and adding a lint that flags untracked peer fields — closes that gap by construction.
Changes
TrackerTargetTraits).PeerComPtrFieldCheckstorage-lint scaffolding (tools/clang-tidy/XamlChecks/) to catch untracked peer fields.Net: 23 files changed, 2236 insertions (additive only, no deletions).
Notes
main; contains this single commit.