Skip to content

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

@baronfel

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

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