refactor: Replace ref-cell late-binding with let mutable in PreCompute#294
Open
dimension-zero wants to merge 1 commit into
Open
refactor: Replace ref-cell late-binding with let mutable in PreCompute#294dimension-zero wants to merge 1 commit into
dimension-zero wants to merge 1 commit into
Conversation
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.
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
The two parent-link slots in
PreCompute.fs(one inpreComputeUnionCaseArgInfo, one inpreComputeUnionArgInfoInner) usedlet current = ref Nonewith!currentandcurrent := .... Replace each withlet 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 mutableplus an invariant comment makes the intent obvious without changing semantics.Test plan
dotnet build -c Release— cleandotnet test -c Release— 112/112 pass