Skip to content

Instantly share code, notes, and snippets.

@TIHan
Last active July 22, 2020 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TIHan/7ebb210774f75d5c5a230f1998cb43b5 to your computer and use it in GitHub Desktop.
Save TIHan/7ebb210774f75d5c5a230f1998cb43b5 to your computer and use it in GitHub Desktop.

WIP F# 5.x Proposal Main Theme - Struct, ByRef, and Span updates

Language

  • Implicit conversion to inref<_> on method calls
  • Static local functions via static let
  • Local functions can have a byref-like parameter type
  • Unmanaged constraint relaxation
  • Add implicit conversion of types to Span / ReadOnlySpan on method calls. - needs proposal
  • Function pointer (delegate pointer) support - needs proposal - needed to support native and C# interop - might require FSharp.Core additions
  • Finish reverse slicing - maybe by interoping with System.Index / System.Range - needs modified proposal
  • SRTP aware of type extension members
  • Add read-only analysis on members marked with [<System.Runtime.CompilerServices.IsReadOnly>] - needs proposal
  • Stack allocated spans with analysis - requires FSharp.Core addition

FSharp.Core

  • Span API - allow ability to create a stack allocated Span - needs proposal - requires a small compiler change to enable stack allocated span analysis (we did the work in 2018 with tests)
  • Add type ReadOnlyAttribute = System.Runtime.CompilerServices.IsReadOnlyAttribute and type ByRefAttribute = System.Runtime.CompilerServices.IsByRefLikeAttribute - needs proposal - may not be possible in netstandard2.0. or we could just add new attributes instead of abbreviations.
  • DelegatePtr API - support function pointer language feature - needs proposal

Miscellaneous Cleanup

  • Move Span optimizations on for loops out of type checker (does not belong)
  • Fix intellisense tooling on Span / ReadOnlySpan - compiler should be better aware of the specific [<Absolute(..)>] attribute with certain text
  • Emit [<Obsolete("Types with embedded references are not supported in this version of your compiler.", true)>] on types marked with [<System.Runtime.CompilerServices.IsByRefLike>]
  • Emit [<System.Runtime.CompilerServices.IsReadOnly>] on F# struct types we know are immutable.
  • Emit [<System.Runtime.CompilerServices.IsReadOnly>] on F# struct types' properties representing a backing field that is not mutable if the entire F# struct type itself is not considered fully immutable.
  • Fix issues when using union types that are marked with [<System.Runtime.CompilerServices.IsByRefLike>].
  • More optimization / warning considerations when using a .NET struct types marked with [<System.Runtime.CompilerServices.IsReadOnly>].

Other Thoughts

  • Allow nativeptr and byref types, including their corresponding address of syntax '&' and '&&' respectively, and to be used in code quotations?
  • Should nativeptr<byte> compile down to byte* and vice versa for interop ? Breaking change? F# has no way to create a byte* as well as others.
  • Efficient representation of struct union types - sharing properties with the same type?
  • We already have implicit addition of an IL representation of a module suffix when a module's name collides with a type's name in the same path - Is this ok? It might be unexpected for a user because if someone ever moves the type elsewhere, the IL compiled representation of the module name is different. Do we want to have implicit name changes for compiled representations? Should it be predictable?
    • If we want it to be predictable, perhaps a warning would be sufficient making the user aware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment