Skip to content

fix(PC0031): reset partial state after a hand-off that can change it - #694

Merged
Arthurvdv merged 4 commits into
mainfrom
fix/pc0031-hand-off-suppression
Nov 27, 2026
Merged

Arthurvdv merged 4 commits into
mainfrom
fix/pc0031-hand-off-suppression

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Feasibility verdict for the PC0031 roadmap in #517 (globals, parameters, cross-procedure tracing, event tracing) plus one hardening change the investigation exposed.

Verdict: none of the four items is implemented.

  • Globals across procedures, parameters whose partial state comes from the caller, and event-subscriber parameters are not decidable statically: call order, the caller's load selection and the publisher's state are invisible in the analyzed body, and procedures from a dependency have no body in the compilation at all (ReferenceMethodSymbol.DeclaringSyntaxReference is null).
  • Globals and parameters whose load-fields call, read and write all sit in one body are decidable but occur 0 and about 1 time across the 1,663 load-fields call sites of the Base Application.
  • Cross-procedure tracing into same-app callees is possible but has one occurrence in the Base Application and costs a body bind per call site on every editor pass.

The full Investigation Report with corpus counts and examples is posted on #517; the reasons are recorded under Deliberate non-reports in the rule doc.

Hardening: PC0031 ignored hand-offs. A tracked local passed by var to a procedure or event publisher, handed to a built-in (Clear, Codeunit.Run, Page.Run, the TransferFields/Copy source) or used as the receiver of a table procedure can be reset by the callee (SetLoadFields(), Reset, a full read), so a full-field operation after the hand-off was a latent false positive. The walker now resets the variable's partial state on such hand-offs. By-value Record arguments do not reset: the callee works on a copy with its own load selection (Microsoft Learn, Using partial records, "Iterating over records"). A by-value RecordRef does reset, because it refers to the same table instance (Microsoft Learn, RecordRef data type).

Findings are now recorded at the write, per load-fields location: each SetLoadFields is charged only with the JIT-load writes that followed it on the path. So Delete(); OnAfterDelete(MyTable) (a var publisher after the write) and Delete(); Clear(MyTable) keep their report (the latter was a false negative before), and a SetLoadFields that no write follows is never reported (SetLoadFields(A); Get; Delete; SetLoadFields(B); Get; reported B before). The end-of-walk merge of write sets is gone.

Fixtures

NoDiagnostic (red before the change): VarPassedBetweenPartialReadAndWrite, TableProcedureBetweenPartialReadAndWrite, PassedToCodeunitRunBetweenPartialReadAndWrite, EventPublisherBetweenPartialReadAndWrite, NamespacedVarPassedBetweenPartialReadAndWrite, FirstSetLoadFieldsBeforeHandOff, SecondSetLoadFieldsAfterHandOffWithoutWrite, SecondSetLoadFieldsAfterWriteWithoutWrite, RecordRefByValuePassedBetweenPartialReadAndWrite, PassedToGetTableBetweenPartialReadAndWrite.
HasDiagnostic: ByValuePassedBetweenPartialReadAndWrite, VarPassedAfterWrite, NewSetLoadFieldsAfterHandOff, VarPassedInBranchBetweenPartialReadAndWrite (green before), ClearAfterWrite (red before), ResetAfterWrite, SetLoadFieldsNoArgsAfterWrite.

Verification

  • dotnet test PartialRecordsCauseJitLoad: 49 passed; UsePartialRecordsForLoops: 153 passed
  • dotnet build ALCops.sln, dotnet format --verify-no-changes: clean
  • PlatformCop Release build with ContinuousIntegrationBuild=true (netstandard2.1, net8.0, net10.0): 0 warnings
  • Validate-Rules.ps1: OK

Companion docs PR: ALCops/alcops.dev#245

Closes #517

🤖 Generated with Claude Code

A tracked local passed by var to a procedure or event publisher, handed
to a built-in such as Clear, Codeunit.Run or Page.Run, or used as the
receiver of a table procedure can be reset by the callee (SetLoadFields(),
Reset, a full read), so a full-field operation after the hand-off is no
longer reported. By-value arguments do not reset: the callee works on a
copy with its own load selection.

Findings made before a reset are committed first, so a var publisher
raised after the write (or a later Clear) no longer erases the report.

The rule doc records why globals, parameters, cross-procedure flows and
event subscribers stay deliberate non-reports.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Arthurvdv and others added 3 commits November 26, 2026 17:23
Charging every load-fields location with the variable's whole write set
reported a later SetLoadFields that no write followed. Each write now
charges only the locations that preceded it on the path, so a reset or
hand-off cannot erase a finding and the end-of-walk merge is gone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A RecordRef assigned or passed by value refers to the same table
instance, so only a by-value Record argument is exempt from the
hand-off reset.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Arthurvdv
Arthurvdv merged commit 5d72d0c into main Nov 27, 2026
55 checks passed
@Arthurvdv
Arthurvdv deleted the fix/pc0031-hand-off-suppression branch November 27, 2026 04:23
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.

PC0031: roadmap - global and parameter variables, cross-procedure and event tracing

1 participant