fix(health): count Pascal for-in loops, add a performance dialect - #2233
Open
Laex wants to merge 9 commits into
Open
fix(health): count Pascal for-in loops, add a performance dialect#2233Laex wants to merge 9 commits into
Laex wants to merge 9 commits into
Conversation
…w dialects Adds a Pascal LanguageNodeMap (branch/loop/case/try/catch/boolean-op/CFG node kinds, derived from parsing real tree-sitter-pascal ASTs) so Pascal gets complexity/nesting, clone detection, and CFG-based dataflow markers. Class-level metrics (LCOM4/god-class) are deliberately left unmapped: Pascal splits a class into signature-only declarations and separate top-level qualified-method implementations, so there is no single node grouping a method's body the way class analysis expects (same posture as Go). Also fixes name/parameter extraction in ast_utils.py, which assumed fields Pascal's grammar doesn't use (name nested under a header field, params field named "args" not "parameters", grouped params like "A, B, C: Boolean"). Validated against the 150-file MTN2 Delphi codebase via repowise health.
feat(health): register Pascal in complexity, duplication, and dataflow dialects
…lpers _extract_pascal_heritage carried both the parent-list extraction and the class-helper's positional "for TFoo" lookup in one function (CCN 14, nesting 4 -- flagged by repowise health). Splits into _extract_parents and _extract_helper_extended_types, each a guard-clause loop with its own narrow job; the orchestrator now just wires them together. Behavior is unchanged (verified against the existing extends/implements test plus a new test covering the previously-uncovered class-helper branch).
# Conflicts: # packages/core/src/repowise/core/ingestion/extractors/heritage/pascal.py
# Conflicts: # docs/layers/LANGUAGE_SUPPORT.md
Pascal's `for x in collection do` parses as its own `foreach` grammar node, distinct from the counted `for`, and was missing from `loop_kinds` -- the complexity walker skipped it entirely, so any Pascal function using a for-in loop understated both CCN and nesting depth. Confirmed against a ~150-file Delphi codebase: 70 occurrences in one module alone. Also registers a Pascal PerfDialect (io_in_loop / hot_path_sync_io), closing the other visible gap: the performance pillar was completely silent for Pascal (0.8% LOC coverage on a real Delphi repo, now 100%). Scoped to filesystem and subprocess sinks matched by RTL/VCL/ FPC call name (CopyFile, TFileStream.SaveToFile, ShellExecute, ...); DB and network sinks are intentionally left out since Pascal's `uses` clause has no import-classification table behind it yet, so there is no evidence to disambiguate Open/Get/Post from an unrelated method of the same name. Bumps HEALTH_ANALYZER_VERSION to 12 so an existing index re-scores these findings on its next update, per the documented stamp convention.
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.
Summary
for x in collection doparses as its ownforeachgrammar node, distinct from the countedfor-- and it was missing fromloop_kinds, so the complexity walker skipped it entirely. Any Pascal function using a for-in loop understated both CCN and nesting depth. Confirmed against a real ~150-file Delphi codebase: 70 occurrences in one module alone.PerfDialect(io_in_loop/hot_path_sync_io), closing the other visible gap: the performance pillar was completely silent for Pascal (0.8% LOC coverage on a real Delphi repo's health report, 100% after this change). Scoped to filesystem and subprocess sinks matched by distinctive RTL/VCL/FPC call names (CopyFile,TFileStream.SaveToFile,ShellExecute,CreateProcess, ...). DB and network sinks are deliberately left out: Pascal'susesclause has no import-classification table behind it yet, so there is no evidence to disambiguateOpen/Get/Postfrom an unrelated method of the same name -- precision over recall.HEALTH_ANALYZER_VERSIONto 12 (documented stamp convention) so an existing index re-scores these findings on its next update.docs/CHANGELOG.md(+ the bundled mirror) anddocs/layers/LANGUAGE_SUPPORT.md.Test plan
foreachnesting/CCN undercount (test_pascal_foreach_counts_as_a_loop)test_perf_io_in_loop.py): bare filesystem call in a loop, attribute-call stream I/O in a loop, process spawn in a loop, and a negative case (Copythe built-in substring function vs.TFile.Copy)test_model_version_coupling.pypin updated to the new stamptests/unit/health/suite passes (1627 passed, 18 skipped)io_in_loophits surfaced (e.g. a retry-delete loop, recursive tree-copy/delete/list operations) with no false positives on theCopy-substring-builtin case