Skip to content

Preserve per-block Func vars during lazy scope cleanup (fix Benchmarks regression)#135

Merged
NikolayPianikov merged 6 commits intodevfrom
codex/review-test-shouldsupportoverrideinfactorywithlocalfunctiona-fugt1o
Feb 20, 2026
Merged

Preserve per-block Func vars during lazy scope cleanup (fix Benchmarks regression)#135
NikolayPianikov merged 6 commits intodevfrom
codex/review-test-shouldsupportoverrideinfactorywithlocalfunctiona-fugt1o

Conversation

@NikolayPianikov
Copy link
Member

Motivation

  • A recent cleanup started removing the active lazy/local-scope variable unconditionally for non-persistent lifetimes, which regressed ShouldSupportFuncWhenPerBlock by causing repeated constructions of Service3 instead of reusing the per-block factory value.
  • The intent is to keep the protection against leaking override-constructed temporary vars while preserving legitimate per-block Func<T> variables across lazy scope restoration.

Description

  • Tighten cleanup in VarsMap.RemoveNewNonPersistentVars so the current scope variable (the one identified by var.Declaration.Node.BindingId) is not removed for normal non-persistent lifetimes, and is only removed when it was created via an override construct (MdConstructKind.Override).
  • Maintain the existing snapshot behavior that excludes override-constructed nodes from state snapshots so override-created vars still do not leak across scopes; the change only relaxes removal for the active per-block factory var.
  • File changed: src/Pure.DI.Core/Core/Code/VarsMap.cs (logic in CreateState / RemoveNewNonPersistentVars).

Testing

  • Could not run dotnet test in this environment because the .NET SDK is unavailable, so no automated test execution was performed here (tooling error: dotnet: command not found).
  • Performed static validations and local inspections: examined VarsMap.cs lines around CreateState and RemoveNewNonPersistentVars, confirmed the logic now preserves per-block factory vars while still targeting override-constructed vars for removal.
  • Located the relevant failing tests (ShouldSupportFuncWhenPerBlock and ShouldSupportOverrideInFactoryWithLocalFunctionAndFuncArgs) and verified the change addresses the per-block reuse regression by reasoning over the generation/restoration code paths.

Codex Task

@NikolayPianikov NikolayPianikov merged commit 5ea85a4 into dev Feb 20, 2026
2 of 6 checks passed
@NikolayPianikov NikolayPianikov deleted the codex/review-test-shouldsupportoverrideinfactorywithlocalfunctiona-fugt1o branch February 20, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant