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

FS-1053 update :: Support instantiation of C#-defined "allows ref struct" generics with ByrefLike types #787

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

Conversation

T-Gro
Copy link
Contributor

@T-Gro T-Gro commented Aug 26, 2024

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

FSharp-4.5/FS-1053-span.md Show resolved Hide resolved
@@ -336,6 +336,8 @@ in some situations where capture must be avoided.
* Cannot be static or instance members of a class or normal struct
* Cannot be captured by any closure construct (async methods or lambda expressions)
* Cannot be used as a generic parameter
- In F# 9 and higher, this restriction is relaxed if the generic parameter is defined in C# using the `allows ref struct` anti-constraint. F# can instantiate such generics in types and methods with byref-like types. As a few examples, this affects BCL delegate types (`Action<>`,`Func<>`), interfaces (`IEnumerable<>`,`IComparable<>`) and generic arguments with a user-provided accumulator function (`String.string Create<TState>(int length, TState state, SpanAction<char, TState> action)`)
- It is impossible to author generic code supporting byref-like types in F#.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth expanding on this here? E.g., to mention that the allows ref struct anti-constraint is not automatically propagated in the same way as normal generic constraints, with some examples.

let a : Action<'T> =let f (x : 'T) = a.Invoke x // Can 'T be ReadOnlySpan<int> here? Presumably not?
let f (g : Action<'T>) (x : 'T) = g.Invoke x // Can 'T be ReadOnlySpan<int> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not automatically propagated, this makes sense to expand on - thanks for checking this.

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

Successfully merging this pull request may close these issues.

3 participants