Skip to content

Bugfix :: Fix optimizer bug where field.Index included compiler generated static fields - #18280

Merged
psfinaki merged 3 commits into
mainfrom
18165-compiler-throws-internal-error-when-using-record-with-construct-on-type-with-static-let
Feb 3, 2025
Merged

Bugfix :: Fix optimizer bug where field.Index included compiler generated static fields#18280
psfinaki merged 3 commits into
mainfrom
18165-compiler-throws-internal-error-when-using-record-with-construct-on-type-with-static-let

Conversation

@T-Gro

Copy link
Copy Markdown
Member

Fixes#18165

The issue was caused by optimizer using a recordField.Index member which was also increment with compiler generated static fields, like init@5. Those should not be part of Index calculation.

There are two usages of the .Index member (I am putting them here, since GH text based diff will not show that)

  • To sort fields. This remains the same if compiler generated static fields are excluded: let sortedRecdFields = unsortedRecdFields |> List.indexed |> Array.ofList |> Array.sortBy (fun (_, r) -> r.Index)
  • In the optimizer path for optimizing away field get => this is the one which this fix targets and where the reported issue was coming from.
andTryOptimizeRecordFieldGet cenv _env (e1info,(RecdFieldRef (rtcref,_)as r),_tinst,m)=letg= cenv.g
match destRecdValue e1info.Info with| Some finfos when cenv.settings.EliminateRecdFieldGet &&not e1info.HasEffect ->match TryFindFSharpAttribute g g.attrib_CLIMutableAttribute rtcref.Attribs with| Some _-> None
| None ->letn= r.Index
if n >= finfos.Length then errorR(InternalError("TryOptimizeRecordFieldGet: term argument out of range", m))
Some finfos[n]

@dotnetdotnet deleted a comment from github-actionsBotFeb 3, 2025
@T-Gro
T-Gro marked this pull request as ready for review February 3, 2025 10:32
@T-Gro
T-Gro requested a review from a team as a code ownerFebruary 3, 2025 10:32
…ing-record-with-construct-on-type-with-static-let
@github-actions

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/9.0.300.md

0101
0101 approved these changes Feb 3, 2025
@psfinaki
psfinaki merged commit 5b910af into mainFeb 3, 2025
@T-Gro
T-Gro deleted the 18165-compiler-throws-internal-error-when-using-record-with-construct-on-type-with-static-let branch February 4, 2025 13:03
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Compiler throws internal error when using record 'with' construct on type with static let

4 participants

@T-Gro@0101@KevinRansom@psfinaki