Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

T-Gro
Copy link
Member

@T-Gro T-Gro commented Jan 28, 2025

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.
and TryOptimizeRecordFieldGet cenv _env (e1info, (RecdFieldRef (rtcref, _) as r), _tinst, m) =
    let g = 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 ->
            let n = r.Index
            if n >= finfos.Length then errorR(InternalError( "TryOptimizeRecordFieldGet: term argument out of range", m))
            Some finfos[n]

Copy link
Contributor

❗ Release notes required

@T-Gro,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.300.md No release notes found or release notes format is not correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

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