[Repo Assist] Fix IONIDE-012 code scanning alerts: add [(Struct)] to discriminated unions#1053
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Draft
Conversation
…ions Fix code scanning alerts IONIDE-012: add [<Struct>] attribute to improve performance by avoiding heap allocations for small discriminated unions. - LiterateCodeVisibility (Document.fs): simple enum-like DU with one case carrying a single string field, ideal for struct representation - EvalKey (Transformations.fs): two-case DU used as Map keys, benefits from value semantics Co-authored-by: Copilot <[email protected]>
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.
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Fixes two open code scanning alerts (IONIDE-012) by adding the
[(Struct)]attribute to two small discriminated unions inFSharp.Formatting.Literate.Changes
src/FSharp.Formatting.Literate/Document.fs[(Struct)]toLiterateCodeVisibility— a 3-case DU (VisibleCode,HiddenCode,NamedCode of string) that is a good fit for struct representation since it's small and used as a value.src/FSharp.Formatting.Literate/Transformations.fs[(Struct)]toEvalKey— a 2-case DU (OutputRef of string,ValueRef of string) used as keys in an F#Map. Named the fields explicitly (outputName,valueName) as required for struct DUs with fields.Motivation
Struct DUs avoid heap allocations for small types, improving GC pressure. The Ionide.Analyzers IONIDE-012 rule flags DUs that meet the criteria for struct representation.
Test Status
✅ Build:
dotnet build src/FSharp.Formatting.Literate/FSharp.Formatting.Literate.fsproj --configuration Release— passed with 0 warnings, 0 errorsFull test suite was not run (build-only validation performed as the change is purely additive). CI will run the full suite.