Registry Mirror
Skip to content

Support the use of inref/outref/byref types in declarations for extern functions #12613

Closed

Description

@baronfel

Is your feature request related to a problem? Please describe.

A working binding to the QueryPerformanceCounter member in Kernel32.dll right now is:

open System.Runtime.InteropServices

[<DllImport("Kernel32.dll")>]
extern void public QueryPerformanceCounter (int64& ticks)

but this feels bad (and is harder to verify at the compiler-level!) because it doesn't allow us to specify the direction of the reference like we'd expect via inref (for read references), outref (for write references), and byref (for read/write references). I think this should be supported for correctness reasons.

Describe the solution you'd like

I'd like the parser to be able to accept inref/outref/byref generic types in the signature of an extern declaration (it seems that right now only simple type declarations are supported), and I'd like the typechecker to verify those access rules at callsites the way we already can with inref/outref/byref in other declarations.

For example, I'd like to write the above declaration as:

open System.Runtime.InteropServices

[<DllImport("Kernel32.dll")>]
extern void public QueryPerformanceCounter (inref<int64> ticks)

to signal to a caller that this value will be written to during the call, and so can be an uninitialized value.

Describe alternatives you've considered

Use references explicitly as in the example above.

Additional context

Related: #11481

Activity

  1. dsyme commented on Jan 21, 2022

    @dsyme
    Contributor

    Seems fine to me. I guess it should be tracked as a language suggestion but I consider it pre-approved

  2. dsyme commented on Jan 21, 2022

    @dsyme
    Contributor

    @baronfel I adjusted your permissions on fslang-suggestions and fslang-design to allow you to write to both those repositories in order to be able to add both approved suggestions and RFCs for things like this

  3. dsyme commented on Apr 20, 2022

    @dsyme
    Contributor

    Closing as this needs to be tracked by language suggestion

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions