Skip to content

Conversation

@brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Oct 25, 2025

Description

Fixes #18993.
Fixes #6069.

  • Emit "error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation" for generic struct types that recursively reference themselves but (infinitely) lift their generic type parameter.

I don't know if "lifting" is the correct term for this; let me know if there is a more correct term or phrase that I should use to describe this in the comment and the tests. Maybe nested app ty/type application?

Checklist

  • Test cases added.
  • Release notes entry updated.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 25, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.0.md

// This type (type instance) has been seen before, so no need to collect the same edges again (and avoid loops!)
List.exists (typeEquiv g ty) doneTypes
// This tycon is the outer tycon with a lifted generic argument, e.g., `'a list`.
|| not (isNil doneTypes) && tryTcrefOfAppTy g ty |> ValueOption.bind _.TryDeref |> ValueOption.exists ((===) tycon)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only do this check when doneTypes is not empty because we need to collect the self-referential edge once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately, I don't think I fully understand when it is safe to access EntityRef.Deref. Tell me if TryDeref is unnecessary here and I will simplify it.

@brianrourkeboll brianrourkeboll marked this pull request as ready for review October 25, 2025 17:23
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner October 25, 2025 17:23
@edgarfgp
Copy link
Contributor

I think this PR might also fix #6069 ?

@brianrourkeboll
Copy link
Contributor Author

I think this PR might also fix #6069 ?

Hmm yes, probably. I will add a test/tests for mutually-recursive structs.

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.

Compilation fails to terminate for polymorphic recursion on value types Infinite loop on expanding cycle for struct types

2 participants