Skip to content

refactor: Replace ref-cell late-binding with let mutable in PreCompute#294

Open
dimension-zero wants to merge 1 commit into
fsprojects:masterfrom
dimension-zero:pr/02-ref-mutable
Open

refactor: Replace ref-cell late-binding with let mutable in PreCompute#294
dimension-zero wants to merge 1 commit into
fsprojects:masterfrom
dimension-zero:pr/02-ref-mutable

Conversation

@dimension-zero
Copy link
Copy Markdown
Contributor

Summary

The two parent-link slots in PreCompute.fs (one in preComputeUnionCaseArgInfo, one in preComputeUnionArgInfoInner) used let current = ref None with !current and current := .... Replace each with let mutable current : ... = ... and add a comment spelling out the invariant: written exactly once after the parent record is built, read by children via a closure.

Why

The ref-cell mutation pattern obscures what's happening — readers have to recognise the idiom before they can follow the parent/child late-binding. let mutable plus an invariant comment makes the intent obvious without changing semantics.

Test plan

  • dotnet build -c Release — clean
  • dotnet test -c Release — 112/112 pass

The two parent-link slots in `PreCompute.fs` used `let current = ref None`
plus `!current` / `current := …`, which:

- relies on the deprecated bang/colon-equals ref operator syntax (the
  source of the prior file-level `#nowarn 44` is unrelated, but
  `ref`-based mutation is no longer idiomatic);
- forces the reader to recognise the pattern before understanding
  what's being done.

Replace each with `let mutable current : … = …` plus a one-paragraph
comment explaining the invariant — written exactly once after the
parent record is built, read by children via the closure. Semantics
unchanged.
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.

1 participant