Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Lift byref generics restrictions for inline functions #688
Lift byref generics restrictions for inline functions
I propose to lift byref generics restrictions for inline functions.
Since all the new byref things have landed in 4.5 I've been playing quite a bit with Span. It's awesome it all works so well already and correctly prevents you from going off the rails.
F# already has ways to deal with other generics limitations by marking functions as
For instance lifting restrictions on byref for generic functions should allow the following contrived example to pass compilation:
Span<int>.Empty |> id
Making this change is neatly in line ;) with previous choices for inline to lift generics limitations and it greatly increases ergonomics working with byreflike types and byref arguments.
@TIHan has also quickly checked the feasibility of this and found a place to implement this inside
Pros and Cons
The advantages of making this adjustment to F# are increased language ergonomics and consistency as not being able to use byref in generics is purely a CLR restriction. This is opens up a lot of possibilities to add some sugar on interactions with Span and friends. And it might also help in performance scenarios where passing structs byref is preferred but where generic code is important too or used a lot. In the face of F# dissuading people from doing method overloading it is a good option to have.
The disadvantages of making this adjustment to F# are extra complexity in the compiler. A function marked as inline should, for byref call sites, not contain any calls to other generic functions that aren't marked inline as well.
Estimated cost (XS, S, M, L, XL, XXL): S (or M?)
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
Agreed on this. It's so commonplace to pipe data into another function that it's a guaranteed surprise to first-time users of
Another thing worth calling out is that an error message when applying a