Skip to content

F# 10.0.400 breaks Aether optics — confirmed upstream compiler bug (dotnet/fsharp#20253) #450

Closed

Description

@7sharp9

Follow-up to #447.

Root cause confirmed

Not our code, not Aether-specific. Upstream F# compiler regression, filed independently the same day: dotnet/fsharp#20253, "SDK 10.0.400 regression: cross-assembly inline SRTP call throws in Release." Identical repro: Aether 8.3.1, Dynamic invocation of op_HatEquals is not supported at Aether.Optic.set. Broken on 10.0.400, works on 10.0.303. Open, Backlog, unassigned, no fix PR yet.

What we additionally verified locally

  • Not limited to Optic.set/^=. Optic.get/^. and lens composition >-> hit the same failure mode (repro'd in GenCORE.Lib/MinMax.fs and GenCORE.Lib/Patient.fs under 10.0.400).
  • Eta-expanding call sites does not fix it, the compiler still emits an internal curried closure that fails.
  • Bypassing Aether's dispatch and calling the Lens/Prism tuple's functions directly (fst/snd) does avoid it, verified against 10.0.400.

Current mitigation

PR #449 pins global.json to 10.0.302/latestPatch. Sufficient until upstream fixes #20253.

Optional follow-up (not urgent while the pin holds)

Replace Aether with a small hand-rolled, non-generic Lens/Prism module (get/set/compose as plain functions) across the affected files: MinMax.fs, GenCORE.Lib/Patient.fs, GenORDER.Lib/Patient.fs, ZForm.Lib/DoseRule.fs, PatientCategory.fs. To remove the dependency and this whole class of SRTP fragility. Track dotnet/fsharp#20253 before considering unpinning the SDK.

Activity

  1. halcwb commented on Aug 14, 2026

    @halcwb
    Collaborator

    I think we should even consider if and how we should use Aether. This is one of those places where I thought, this looks cool, but didn't really think over the broader consequences and consistent usage. This also was before the F# nested record fields accessors: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/copy-and-update-record-expressions.

  2. 7sharp9 commented on Aug 14, 2026

    @7sharp9
    CollaboratorAuthor

    We can patch this pretty easy for now by replacing:

            let getMin = Optic.get min_
            let setMin = Optic.set min_
    

    With

            let setMin v mm = (snd min_) v mm
            let getMin mm = (fst min_) mm
    

    Or going further, a tiny optics lib that doesn't use fragile SRTP.

    Or just factor out optic style and just use nested field accessors.

  3. halcwb commented on Aug 14, 2026

    @halcwb
    Collaborator

    We can patch this pretty easy for now by replacing:

            let getMin = Optic.get min_
            let setMin = Optic.set min_
    

    With

            let setMin v mm = (snd min_) v mm
            let getMin mm = (fst min_) mm
    

    Or going further, a tiny optics lib that doesn't use fragile SRTP.

    Or just factor out optic style and just use nested field accessors.

    I agree, this could be a typical case of YAGNI.

    That said. The ZForm lib makes quite extensive use of optics. But this is a typical case where AI could do a lot of the heavy lifting.

  4. 7sharp9 commented on Aug 14, 2026

    @7sharp9
    CollaboratorAuthor

    This is one of those Haskelisms that creep in where it looks like a good idea then you later just go with the simple option. Sometimes boilerplate is good. The awful use of SRTP etc lead me to build Myriad (Mryiad lenses) so no one has to put themselves through composing those monstrosities. I think people choose yo use optic's libs rather than gen them with Myriad though, sometime people like to shoot themselves through the foot for fun for a while though :-p .

  5. halcwb commented on Aug 14, 2026

    @halcwb
    Collaborator

    This is one of those Haskelisms that creep in where it looks like a good idea then you later just go with the simple option. Sometimes boilerplate is good. The awful use of SRTP etc lead me to build Myriad (Mryiad lenses) so no one has to put themselves through composing those monstrosities. I think people choose yo use optic's libs rather than gen them with Myriad though, sometime people like to shoot themselves through the foot for fun for a while though :-p .

    I think replacing this with Myriad lenses would be great! Again using AI this should be easy. Do you want to hand this over to me or would you rather want this resolved by yourself?

  6. added theissue type on Aug 21, 2026
  7. added
    refactor
    on Aug 21, 2026
  8. changed the issue type fromtoon Aug 21, 2026
  9. 7sharp9 commented on Aug 24, 2026

    @7sharp9
    CollaboratorAuthor

    For this a simple optics module will suffice, only the parts that benefit from optics will be applied like: ZForm.Lib/DoseRule.fs where there's 169 compositions that would be otherwise introduced, for other places where there is no advantage to using optics we can just factor usages out to simplify.

    We cant use Myriad unless the lens module is updated as Myriad only support optics with one element. Its trivial to extend but its an extra step where here, we just want to reduce risk and factor out that aspect. If there are other area where Myriad could help then it would make more sense to embrace Myriad but without analysis I simply don't know.

  10. halcwb commented on Aug 25, 2026

    @halcwb
    Collaborator

    Took this off the first MVP project as an issue, this can be handled later on.

  11. 7sharp9 commented on Aug 25, 2026

    @7sharp9
    CollaboratorAuthor

    Ah ok, I had started this one, I'll park the branch and come back to it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

refactor

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions