Skip to content

quality: cut dead-code false positives across C++, C#, XAML, tests#190

Merged
RaghavChamadiya merged 1 commit into
mainfrom
quality/cpp-csharp-fp-cleanup
May 13, 2026
Merged

quality: cut dead-code false positives across C++, C#, XAML, tests#190
RaghavChamadiya merged 1 commit into
mainfrom
quality/cpp-csharp-fp-cleanup

Conversation

@RaghavChamadiya
Copy link
Copy Markdown
Member

Summary

Five complementary fixes targeting the dominant false-positive buckets observed on desktop .NET / Win32 repositories. Probed against PowerToys; expected reductions estimated read-only from the existing index.

Fix What it does Estimated FP reduction on PowerToys
A unused_export now treats an incoming calls / method_implements / reads edge on the symbol itself as evidence of life. Previously only file-level imported_names was checked. C++ functions: −1,417
B C++ void Foo::method() { … } now extracts with parent_name=Foo and kind=method. New cpp.scm pattern for two-level NS::Foo::method plus a parser helper that walks the qualified_identifier scope. Free functions unaffected. C++ functions converted to method (non-importable): −1,674
C dynamic_hints/dotnet.py learns typeof(TypeName) — covers [JsonConverter(typeof(X))], DataTemplate.DataType = typeof(X), manual DI registration. C# class FPs: −144
D dynamic_hints/xaml.py learns <prefix:TypeName …> element-tag references — catches converters, controls, templates declared as XAML elements. Property syntax (<Grid.Resources>) and bare built-in tags are excluded. C# class FPs: −94
E _NEVER_FLAG_PATTERNS adds test-project globs (*Tests/*.cs, *.UnitTests/*.cs, *FuzzTests/*.cs, *UITest*/*.cs, *Tests.cs, …) plus */unittests/*.cpp|.h. Cross-language: −274 findings

Projected post-fix on PowerToys:

  • C++ unused_export ≥0.7: 5,049 → ~1,200-1,500
  • C# class unused_export ≥0.7: 1,240 → ~735-800
  • Total dead-code findings: 9,015 → ~5,500

Test plan

  • 550 ingestion / dead_code / pipeline / git tests passing (2 xfailed unchanged)
  • New unit tests:
    • test_unused_export_skipped_when_symbol_has_incoming_calls
    • test_qualified_definition_binds_to_class (cpp Foo::DoOne, two-level NS::Bar::DoTwo)
    • test_typeof_type_emits_dynamic_uses, test_typeof_lowercase_local_ignored
    • test_element_tag_with_prefix_extracted, test_element_tag_property_syntax_skipped, test_bare_xaml_element_not_a_type_reference
  • PowerToys re-index to verify estimated reductions

Five complementary fixes targeting the dominant FP buckets observed in
the wild on desktop .NET / Win32 repositories.

- unused_export now treats an incoming `calls` / `method_implements`
  / `reads` edge on the symbol itself as evidence of life. The
  existing pass only checked file-level `imported_names`, which
  missed intra-file C++ helpers and qualified `Foo::method`
  definitions reached via call resolution rather than headers.
- C++ qualified definitions (`void Foo::method() { … }`) now extract
  with `parent_name=Foo` and `kind=method`. New cpp.scm pattern for
  two-level `NS::Foo::method` declarations plus a parser helper that
  walks the qualified_identifier scope to recover the immediate
  enclosing type. Free functions are unaffected.
- `dynamic_hints/dotnet.py` learned `typeof(TypeName)` — catches
  `[JsonConverter(typeof(X))]`, `[TypeConverter(...)]`,
  `DataTemplate.DataType = typeof(X)`, and manual DI registration.
- `dynamic_hints/xaml.py` learned `<prefix:TypeName …>` element-tag
  references — catches converters, controls, templates declared as
  XAML elements without a `using` directive on the C# side. Property
  syntax (`<Grid.Resources>`) and bare built-in tags are excluded.
- `_NEVER_FLAG_PATTERNS` adds standard test-project globs
  (`*Tests/*.cs`, `*.UnitTests/*.cs`, `*FuzzTests/*.cs`,
  `*UITest*/*.cs`, `*Tests.cs`, …) plus `*/unittests/*.cpp|.h`.
@RaghavChamadiya RaghavChamadiya requested a review from swati510 as a code owner May 13, 2026 14:48
@RaghavChamadiya RaghavChamadiya merged commit 44223d8 into main May 13, 2026
5 checks passed
@RaghavChamadiya RaghavChamadiya deleted the quality/cpp-csharp-fp-cleanup branch May 13, 2026 14:52
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.

2 participants